<?php include "layouts/menu.php"; ?>
    <?php $hpl=$_REQUEST['hpl'];?>
	<?php  $mfin2=$mfin; ?>
	
<style> 
input[type=text] {
    width: 100%;
   
    box-sizing: border-box;
    border: 1px solid #555;
    outline: Gray;
	
}

input[type=text]:focus {
    background-color: #d1e0e3;
}

.div1 {
    width: 750px;
    height: 100%;
    border: 4px solid #376ca1;
	background-color:#00BCD4;
	float:left;
}

.div2 {
    width: 380px;
    height: 100%;    
background-color:#00BCD4;
    border: 4px solid #376ca1;
	float:right;
}
label {
  
  color: black;
  font-weight: bold;
  
}
td,th{
  
  color: black;
  font-weight: bold;
  
}

</style>

	 <script> 
function add() 
{ 
var x = document.getElementById("txt1").value; 
var y = document.getElementById("txt2").value; 
var z = document.getElementById("obc").value; 
var w = document.getElementById("jkjk").value;
document.getElementById("tot").value =((x*w)+(y*1)+(z*1)); 
} 

</script>
 <script> 
function add1() 
{ 
var	no1=Number(document.getElementById("tx2").value);

if(no1 <= -1 )
{
document.getElementById("txt2").value =parseInt(0); 
	
	
}else{
var x = document.getElementById("dqw").value; 
var y = document.getElementById("tx2").value; 
document.getElementById("txt2").value =parseInt((x*1)*(y*1)); 
} 
} 
</script>
<script> 
function nnow() 
{ 
var x = document.getElementById("qx").value; 
var y = document.getElementById("jkjk").value; 
document.getElementById("ax").value =parseInt((x*1)+(y*1)); 

} 
</script>
 <script> 
function sum() 
{ 
var z = document.getElementById("tot").value; 
var q = document.getElementById("payment").value; 
document.getElementById("balance").value =((z*1)-(q*1));  
} 
</script>
<script> 
function asal() 
{ 
var z = document.getElementById("asa").value; 
var q = document.getElementById("jkjk").value; 
document.getElementById("asa").value =((z*1)*(q*1)); 
var x = document.getElementById("rno").value; 
var y = document.getElementById("jkjk").value; 
document.getElementById("rno").value =((x*1)*(y*1));

var xx = document.getElementById("qx").value; 
var yy = document.getElementById("jkjk").value; 
document.getElementById("ax").value =parseInt((xx*1)+(yy*1)); 

} 
</script>
<script> 
function iasal() 
{ 
var z = document.getElementById("rno").value; 
var q = document.getElementById("jkjk").value; 
document.getElementById("rno").value =((z*1)*(q*1));  
} 
</script>
<script>
function diff()
{
var	no=Number(document.getElementById("jkjk").value);
if ( no == 1) {
	var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("kk").value;
	
	var date11 = date14.split("-").reverse().join("-");
	var date22 = date15.split("-").reverse().join("-");

    var one_day=1000*60*60*24;

    var date1 = new Date(date11);
    var date2 = new Date(date22);

      // Convert both dates to milliseconds
      var date1_ms = date1.getTime();
      var date2_ms = date2.getTime();

      // Calculate the difference in milliseconds
      var difference_ms = date2_ms - date1_ms;

      // Convert back to days and return
	      document.getElementById("tx2").value =  Math.round(difference_ms/one_day); 
} else if (no == 2) {
	var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("kk").value;
	
	var date11 = date14.split("-").reverse().join("-");
	var date22 = date15.split("-").reverse().join("-");

    var one_day=1000*60*60*24;

    var date1 = new Date(date11);
    var date2 = new Date(date22);

      // Convert both dates to milliseconds
      var date1_ms = date1.getTime();
      var date2_ms = date2.getTime();

      // Calculate the difference in milliseconds
      var difference_ms = date2_ms - date1_ms;

      // Convert back to days and return
	      document.getElementById("tx2").value =  Math.round(difference_ms/one_day)+(Math.round(difference_ms/one_day)-30); 

}else if (no == 2) {
	var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("kk").value;
	
	var date11 = date14.split("-").reverse().join("-");
	var date22 = date15.split("-").reverse().join("-");

    var one_day=1000*60*60*24;

    var date1 = new Date(date11);
    var date2 = new Date(date22);

      // Convert both dates to milliseconds
      var date1_ms = date1.getTime();
      var date2_ms = date2.getTime();

      // Calculate the difference in milliseconds
      var difference_ms = date2_ms - date1_ms;

      // Convert back to days and return
	      document.getElementById("tx2").value =  Math.round(difference_ms/one_day)+(Math.round(difference_ms/one_day)-30); 

}else if (no == 3) {
	var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("kk").value;
	
	var date11 = date14.split("-").reverse().join("-");
	var date22 = date15.split("-").reverse().join("-");

    var one_day=1000*60*60*24;

    var date1 = new Date(date11);
    var date2 = new Date(date22);

      // Convert both dates to milliseconds
      var date1_ms = date1.getTime();
      var date2_ms = date2.getTime();

      // Calculate the difference in milliseconds
      var difference_ms = date2_ms - date1_ms;

      // Convert back to days and return

		document.getElementById("tx2").value =  Math.round(difference_ms/one_day)+(Math.round(difference_ms/one_day)-30)+(Math.round(difference_ms/one_day)-60); 


}else if (no == 4) {
	var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("kk").value;
	
	var date11 = date14.split("-").reverse().join("-");
	var date22 = date15.split("-").reverse().join("-");

    var one_day=1000*60*60*24;

    var date1 = new Date(date11);
    var date2 = new Date(date22);

      // Convert both dates to milliseconds
      var date1_ms = date1.getTime();
      var date2_ms = date2.getTime();

      // Calculate the difference in milliseconds
      var difference_ms = date2_ms - date1_ms;

      // Convert back to days and return

		document.getElementById("tx2").value =  Math.round(difference_ms/one_day)+(Math.round(difference_ms/one_day)-30)+(Math.round(difference_ms/one_day)-60)+(Math.round(difference_ms/one_day)-90); 


}
else if (no == 5) {
	var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("kk").value;
	
	var date11 = date14.split("-").reverse().join("-");
	var date22 = date15.split("-").reverse().join("-");

    var one_day=1000*60*60*24;

    var date1 = new Date(date11);
    var date2 = new Date(date22);

      // Convert both dates to milliseconds
      var date1_ms = date1.getTime();
      var date2_ms = date2.getTime();

      // Calculate the difference in milliseconds
      var difference_ms = date2_ms - date1_ms;

      // Convert back to days and return

		document.getElementById("tx2").value =  Math.round(difference_ms/one_day)+(Math.round(difference_ms/one_day)-30)+(Math.round(difference_ms/one_day)-60)+(Math.round(difference_ms/one_day)-90)+(Math.round(difference_ms/one_day)-120); 


}
else if (no == 6) {
	var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("kk").value;
	
	var date11 = date14.split("-").reverse().join("-");
	var date22 = date15.split("-").reverse().join("-");

    var one_day=1000*60*60*24;

    var date1 = new Date(date11);
    var date2 = new Date(date22);

      // Convert both dates to milliseconds
      var date1_ms = date1.getTime();
      var date2_ms = date2.getTime();

      // Calculate the difference in milliseconds
      var difference_ms = date2_ms - date1_ms;

      // Convert back to days and return

		document.getElementById("tx2").value =  Math.round(difference_ms/one_day)+(Math.round(difference_ms/one_day)-30)+(Math.round(difference_ms/one_day)-60)+(Math.round(difference_ms/one_day)-90)+(Math.round(difference_ms/one_day)-120)+(Math.round(difference_ms/one_day)-150); 
}

else if (no == 7) {
	var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("kk").value;
	
	var date11 = date14.split("-").reverse().join("-");
	var date22 = date15.split("-").reverse().join("-");

    var one_day=1000*60*60*24;

    var date1 = new Date(date11);
    var date2 = new Date(date22);

      // Convert both dates to milliseconds
      var date1_ms = date1.getTime();
      var date2_ms = date2.getTime();

      // Calculate the difference in milliseconds
      var difference_ms = date2_ms - date1_ms;

      // Convert back to days and return

		document.getElementById("tx2").value =  Math.round(difference_ms/one_day)+(Math.round(difference_ms/one_day)-30)+(Math.round(difference_ms/one_day)-60)+(Math.round(difference_ms/one_day)-90)+(Math.round(difference_ms/one_day)-120)+(Math.round(difference_ms/one_day)-150)+(Math.round(difference_ms/one_day)-180); 
}
else if (no == 8) {
	var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("kk").value;
	
	var date11 = date14.split("-").reverse().join("-");
	var date22 = date15.split("-").reverse().join("-");

    var one_day=1000*60*60*24;

    var date1 = new Date(date11);
    var date2 = new Date(date22);

      // Convert both dates to milliseconds
      var date1_ms = date1.getTime();
      var date2_ms = date2.getTime();

      // Calculate the difference in milliseconds
      var difference_ms = date2_ms - date1_ms;

      // Convert back to days and return

		document.getElementById("tx2").value =  Math.round(difference_ms/one_day)+(Math.round(difference_ms/one_day)-30)+(Math.round(difference_ms/one_day)-60)+(Math.round(difference_ms/one_day)-90)+(Math.round(difference_ms/one_day)-120)+(Math.round(difference_ms/one_day)-150)+(Math.round(difference_ms/one_day)-180)+(Math.round(difference_ms/one_day)-210); 
}

else if (no == 9) {
	var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("kk").value;
	
	var date11 = date14.split("-").reverse().join("-");
	var date22 = date15.split("-").reverse().join("-");

    var one_day=1000*60*60*24;

    var date1 = new Date(date11);
    var date2 = new Date(date22);

      // Convert both dates to milliseconds
      var date1_ms = date1.getTime();
      var date2_ms = date2.getTime();

      // Calculate the difference in milliseconds
      var difference_ms = date2_ms - date1_ms;

      // Convert back to days and return

		document.getElementById("tx2").value =  Math.round(difference_ms/one_day)+(Math.round(difference_ms/one_day)-30)+(Math.round(difference_ms/one_day)-60)+(Math.round(difference_ms/one_day)-90)+(Math.round(difference_ms/one_day)-120)+(Math.round(difference_ms/one_day)-150)+(Math.round(difference_ms/one_day)-180)+(Math.round(difference_ms/one_day)-210)+(Math.round(difference_ms/one_day)-240); 
}

else if (no == 10) {
	var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("kk").value;
	
	var date11 = date14.split("-").reverse().join("-");
	var date22 = date15.split("-").reverse().join("-");

    var one_day=1000*60*60*24;

    var date1 = new Date(date11);
    var date2 = new Date(date22);

      // Convert both dates to milliseconds
      var date1_ms = date1.getTime();
      var date2_ms = date2.getTime();

      // Calculate the difference in milliseconds
      var difference_ms = date2_ms - date1_ms;

      // Convert back to days and return

		document.getElementById("tx2").value =  Math.round(difference_ms/one_day)+(Math.round(difference_ms/one_day)-30)+(Math.round(difference_ms/one_day)-60)+(Math.round(difference_ms/one_day)-90)+(Math.round(difference_ms/one_day)-120)+(Math.round(difference_ms/one_day)-150)+(Math.round(difference_ms/one_day)-180)+(Math.round(difference_ms/one_day)-210)+(Math.round(difference_ms/one_day)-240)+(Math.round(difference_ms/one_day)-270); 
}
else if (no == 11) {
	var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("kk").value;
	
	var date11 = date14.split("-").reverse().join("-");
	var date22 = date15.split("-").reverse().join("-");

    var one_day=1000*60*60*24;

    var date1 = new Date(date11);
    var date2 = new Date(date22);

      // Convert both dates to milliseconds
      var date1_ms = date1.getTime();
      var date2_ms = date2.getTime();

      // Calculate the difference in milliseconds
      var difference_ms = date2_ms - date1_ms;

      // Convert back to days and return

		document.getElementById("tx2").value =  Math.round(difference_ms/one_day)+(Math.round(difference_ms/one_day)-30)+(Math.round(difference_ms/one_day)-60)+(Math.round(difference_ms/one_day)-90)+(Math.round(difference_ms/one_day)-120)+(Math.round(difference_ms/one_day)-150)+(Math.round(difference_ms/one_day)-180)+(Math.round(difference_ms/one_day)-210)+(Math.round(difference_ms/one_day)-240)+(Math.round(difference_ms/one_day)-270)+(Math.round(difference_ms/one_day)-300); 
}
else if (no == 12) {
	var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("kk").value;
	
	var date11 = date14.split("-").reverse().join("-");
	var date22 = date15.split("-").reverse().join("-");

    var one_day=1000*60*60*24;

    var date1 = new Date(date11);
    var date2 = new Date(date22);

      // Convert both dates to milliseconds
      var date1_ms = date1.getTime();
      var date2_ms = date2.getTime();

      // Calculate the difference in milliseconds
      var difference_ms = date2_ms - date1_ms;

      // Convert back to days and return

		document.getElementById("tx2").value =  Math.round(difference_ms/one_day)+(Math.round(difference_ms/one_day)-30)+(Math.round(difference_ms/one_day)-60)+(Math.round(difference_ms/one_day)-90)+(Math.round(difference_ms/one_day)-120)+(Math.round(difference_ms/one_day)-150)+(Math.round(difference_ms/one_day)-180)+(Math.round(difference_ms/one_day)-210)+(Math.round(difference_ms/one_day)-240)+(Math.round(difference_ms/one_day)-270)+(Math.round(difference_ms/one_day)-300)+(Math.round(difference_ms/one_day)-330); 
}
}
</script>
<script> 
function add01() 
{ 
var a = document.getElementById("paymnt").value; 
var b = document.getElementById("dueamount").value; 
document.getElementById("dueamt").value =((a*1)*(b*1)); 

var c = document.getElementById("paymnt").value; 
var d = document.getElementById("dueamt").value; 
var e = document.getElementById("hloan").value; 
var f = document.getElementById("fine").value; 

document.getElementById("urname").value =((c*1)+(d*1)+(e*1)+(f*1)); 
 
} 
</script>
<script> 
function add03() 
{ 
var a = document.getElementById("paymnt").value; 
var b = document.getElementById("dueamount").value; 
var x = document.getElementById("dueamt").value; 
var y = ((x*1)/(b*1)); 
document.getElementById("paymnt").value = Math.floor(y); 

var d = document.getElementById("dueamt").value; 
var e = document.getElementById("hloan").value; 
var f = document.getElementById("fine").value; 

document.getElementById("urname").value =((d*1)+(e*1)+(f*1)); 
 
} 
</script>

<script> 
function add02() 
{ 

var d = document.getElementById("amt").value; 
var dd = document.getElementById("pass").value; 
var e = document.getElementById("hloan").value; 
var f = document.getElementById("fine").value; 

document.getElementById("urname").value =((d*1)+(dd*1)+(e*1)+(f*1)); 
 
}

function add55() 
{ 

var a = document.getElementById("urname").value; 
var b = document.getElementById("pamt").value; 

document.getElementById("reloan").value =((a*1)-(b*1)); 
 
} 
</script>
  <!--  page-wrapper -->
         <div class="right_col" role="main">
         
            <div class="row">
                <div class="col-lg-12">
                    <!-- Form Elements -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Pay Due
                        </div>
                        <div class="panel-body">
                            <div class="row">
  <div class="col-xs-12 col-md-12"> 
    <form name="form1" class="form-horizontal" method="post" action="" enctype="multipart/form-data">

<?php $rrow44=0;$rrow45=0;
										
									$sql = "SELECT SUM(hpamount) FROM customerdetails where mfin='$mfin2' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql);
                                    $row52 = mysqli_fetch_array($q);	
                                    $rrow44 = $row52[0] + $rrow44;								
									
									$sql = "SELECT SUM(pass) FROM user where mfin='$mfin2' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql);
                                    $row53 = mysqli_fetch_array($q);	
                                    $rrow45 = $row53[0] + $rrow45;																			
									
									
									 $rrow445= $rrow44 - $rrow45; ?>
<?php $rrno2 = 0;
$qry5=mysqli_query($conn, "select * from user ORDER BY id DESC");
$n5=mysqli_num_rows($qry5);
$row5=mysqli_fetch_array($qry5);
$result = mysqli_query($conn, "SELECT MAX(rno) FROM roll where mfin='$mfin'");
$row = mysqli_fetch_array($result);
$rrno2 =  $row[0];

//$qry6=mysqli_query($conn, "select * from roll where mfin='$mfin' ORDER BY id DESC");
//$n6=mysqli_num_rows($qry6);
//$row6=mysqli_fetch_array($qry6);
						//	$rrno2 = $row6['rno'];
						 $rrno = $rrno2 + 1;
						if($n5==0)
						{
							$fid = 0;
						}
						else
					    {	
						$fidd = $row5['fid'];
						$prno=$row5['fid']+1;
						$fid = $fidd + 1;
						}
											
$qry=mysqli_query($conn, "select * from user where mfin='$mfin2' && hpl='$hpl' ORDER BY fid DESC");
						$n=mysqli_num_rows($qry);
						
						if($n==0)
						{
							$sss = 0;
						}
						else
					    {
						$row=mysqli_fetch_array($qry);
						$lddate = $row['paydate'];
						$sss = $row['bal'];
						$newsss = $row['bal'];
						
						}
$sql1 = "select sum(paymnt) from user where mfin='$mfin2' &&  hpl='$hpl'";
$qt = mysqli_query($conn, $sql1);
$row1 = mysqli_fetch_array($qt);
$sql5=$row1[0];
$sql6=$sql5 + 1;
$nuserpay = $sql5;
$hlbal20 = 0;
$sql155 = "select sum(actamt2) from hloan where mfin='$mfin2' && type!='COLLECTION' && hpl='$hpl'";
$qt55 = mysqli_query($conn, $sql155);
$row155 = mysqli_fetch_array($qt55); 
	$hlbal20= $row155[0]; 
$sql155 = "select sum(postamt2) from otherentry where mfin='$mfin' &&  hpl='$hpl'";
$qt55 = mysqli_query($conn, $sql155);
$row155 = mysqli_fetch_array($qt55);
$hlbal2=$row155[0];

$sql1551 = "select sum(hlamt) from customerdetails where mfin='$mfin' &&  hpl='$hpl'";
$qt551 = mysqli_query($conn, $sql1551);
$row1551 = mysqli_fetch_array($qt551);
$hlbal1=$row1551[0];

$sql1552 = "select sum(hloan) from user where mfin='$mfin' &&  hpl='$hpl'";
$qt552 = mysqli_query($conn, $sql1552);
$row1552 = mysqli_fetch_array($qt552);
$hlbal3=$row1552[0];
$hlbal = $hlbal20 + $hlbal2 - $hlbal1 - $hlbal3;

$sql15526 = "select sum(pass) from user where mfin='$mfin2' &&  hpl='$hpl'";
$qt5526 = mysqli_query($conn, $sql15526);
$row15526 = mysqli_fetch_array($qt5526);
$p2damt=$row15526[0];

$sql15527 = "select sum(rno) from user where mfin='$mfin2' &&  hpl='$hpl'";
$qt5527 = mysqli_query($conn, $sql15527);
$row15527 = mysqli_fetch_array($qt5527);
$p2int=$row15527[0];

$sql1552 = "select sum(urname) from user where mfin='$mfin2' &&  hpl='$hpl'";
$qt552 = mysqli_query($conn, $sql1552);
$row1552 = mysqli_fetch_array($qt552);
$p2tot=$row1552[0];


?> 
 <?php
		$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin2' &&  hpl='$hpl'");		
	$row = mysqli_fetch_array($qry);
$tyty=$row['duemnt'];
$pdamt=$row['dueamt'];
$pinter=$row['interest'];
   $u = $row['total'];
	   $row = str_replace('/', '-', $row['hpdate']);
  $d1 = strtotime($row);
$d2 = strtotime("today");
$min_date = min($d1, $d2);
$max_date = max($d1, $d2);
$i = 0;
while (($min_date = strtotime("+1 DAY", $min_date)) <= $max_date) {
    $i++;
}
$min_date = min($d1, $d2);
$max_date = max($d1, $d2);
$i5 = 0;
while (($min_date = strtotime("+1 MONTH", $min_date)) <= $max_date) {
    $i5++;
}
$iii = $i;
$sql1 = "select sum(paymnt) from user where mfin='$mfin2' &&  hpl='$hpl'";
$qt = mysqli_query($conn, $sql1);
$row1 = mysqli_fetch_array($qt);
if($i5>$tyty)
{$i5=$tyty;}
$n444=$row1[0];

$sql12 = "select sum(rno) from user where mfin='$mfin2' &&  hpl='$hpl'";
$qt2 = mysqli_query($conn, $sql12);
$row12 = mysqli_fetch_array($qt2);
$crno=$row12[0];
$sql13 = "select sum(pass) from user where mfin='$mfin2' &&  hpl='$hpl'";
$qt3 = mysqli_query($conn, $sql13);
$row13 = mysqli_fetch_array($qt3);
$cpass=$row13[0];
$ctot = $crno + $cpass;
$cpaid=$n444;
$cxta = $u * $cpaid;
$cvv = $cxta - $ctot;
$e = $i5 - $n444;
$f = $u * $e + $cvv;

$e55 = $tyty - $n444;
$f55 = $u * $e55 + $cvv;


$a1damt = $pdamt * $tyty;
$a1inter = $pinter * $tyty;

$ppp = $a1damt - $p2damt;
$iiii = $a1inter - $p2int;

if($e<0){
	$e = 1;
    $f = $u;
}
if($sql6<$tyty)
{
$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin2' &&  hpl='$hpl'");			
$row = mysqli_fetch_array($qry);
	   $duedat = str_replace('/', '-', $row['hpdate']);
$duedat = date("d-m-Y", strtotime("$duedat + " . $sql6 . " month"));	
	}
	else{$duedat = "Account Clossed";}
	
	
							$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin2' &&  hpl='$hpl'");			
$row = mysqli_fetch_array($qry);
	   $duedat = str_replace('/', '-', $row['hpdate']);
						$pp = $row['duemnt'];
						$addr = $row['address'];
			$damt = $row['total'];		
$intt = $row['inter'];
$prin = $row['dueamt'];			
	$defamt2 = $row['defamt'];	
	$defamt = (($damt*$defamt2)/100)/30;	
  $d1 = strtotime($duedat);
$d2 = strtotime("today");
$min_date = min($d1, $d2);
$max_date = max($d1, $d2);

if($iii>$pp)
{ $iii=$pp; }
$rc = $iii - $sql5 ;
$sql9 = $sql5 + $rc ; $vv = 1; $ii = 1;
 $finep = 0;   $finepp = 0;
$qry5=mysqli_query($conn, "select * from user where mfin='$mfin2' && hpl='$hpl'");			
while($row5 = mysqli_fetch_array($qry5)) { $rr = 0;
$duemnt = $row5['paymnt'];
while($rr<$duemnt) { $rr++;
$rno1 = $row5['rno'];
$rno = $rno1/$duemnt;
$pass1 = $row5['pass'];

$pass = $pass1/$duemnt;
$urname1 = $row5['urname'];
$hloan = $row5['hloan'];
$fine1 = $row5['fine'];
$urname = ($urname1 - $hloan - $fine1) /$duemnt;
$duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " month"));
$pday = $row5['paydate'];


  $d11 = strtotime($duedat);
$d22 = strtotime($pday);
$min_date1 = min($d11, $d22);
$max_date1 = max($d11, $d22);
$i6 = 0;
if($d11<=$d22) {
while (($min_date1 = strtotime("+1 DAY", $min_date1)) <= $max_date1) {
    $i6++;
}
}
if($i6 <= 3){
    
$fine2 = 0;
} else {
$fine2 = $defamt * $i6; }
$finep = $finep + $fine2;
$finepp = $finepp + $fine1;
 $ii++; } } while($ii<=$pp) {
	 $duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " month")); 
  $d11 = strtotime($duedat);
$d22 = strtotime("today");
$min_date1 = min($d11, $d22);
$max_date1 = max($d11, $d22);
$i6 = 0;
if($d11<=$d22) {
while (($min_date1 = strtotime("+1 DAY", $min_date1)) <= $max_date1) {
    $i6++;
} }
$i6 = $i6 - 3;
if($i6 < 0) {
	$i6 = 0;
}
if($i6 <= 3){
    
$fine2 = 0;
} else {
$fine2 = $defamt * $i6; }
if($fine2 < 0) {
	$fine2 = 0;
}
$finep = $finep + $fine2;
  $ii++; }  
  
$fineppp = $finep - $finepp;  
  if($fineppp<0) {
	  $fineppp = 0;
  }
$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin2' &&  hpl='$hpl'");
$row=mysqli_fetch_array($qry);
	$sad = $row['duemnt'];
	$remarks = $row['remarks'];
	if($remarks!=NULL){
echo '<script language="javascript">';
echo 'alert("'.$remarks.'")';
echo '</script>'; }
$dd = $row['uimg'];	?>


<div class="col-md-12">
	<div class="col-md-3">
   <div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">HPL NO</label>
    <div class="col-sm-4">
     <input type="text" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="hpl" width="48" value="<?php echo $row['hpl'];?>" placeholder=""  required>  
	 <input type="hidden" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="hpl" width="48" value="<?php echo $row['vno'];?>" placeholder=""  >  
	  <input type="hidden" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="no" width="48" value="<?php echo $row['duemnt'];?>" placeholder=""  >  
	  <input type="hidden" class="form-control" style="width:170px; height:29px " id="dueamount" name="dueamount" width="48" value="<?php echo $row['total'];?>" placeholder=""  >  
	  <input type="hidden" class="form-control" style="width:170px; height:29px " id="ddamt" name="ddamt" width="48" value="<?php echo $row['dueamt'];?>" placeholder=""  >  
    </div>
   </div>
 </div>
 	<div class="col-md-3">
   <div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">REG NO </label>
    <div class="col-sm-4">
     <input type="text" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="hpl" value="<?php echo $row['hpl'];?>" placeholder=""  required>  
    </div>
   </div>
 </div>
 	<div class="col-md-3">
   <div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">RECPNO</label>
    <div class="col-sm-4">
     <input type="text" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="roll" value="<?php echo $rrno;?>" placeholder=""  required>  
	  <input type="hidden" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="roll55" value="<?php echo $rrno;?>" placeholder=""  required>  
    </div>
   </div>
 </div>
 	<div class="col-md-3">
   <div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">Date </label>
    <div class="col-sm-4">
     <input type="text" class="form-control"  style="width:170px; height:29px " id="inputPassword3" name="paydate" value="<?php echo date("d-m-Y");?>" placeholder=""  required>  
    </div>
   </div>
 </div>
 </div>
 <div class="col-md-12">
	<div class="col-md-3">
   <div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">PartyName</label>
    <div class="col-sm-4">
     <input type="text" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="name" width="10" value="<?php echo $row['name'];?>" placeholder=""  required>  
   </div>
 </div>
 </div>
 <div class="col-md-6"> &nbsp;</div>
 </div>
<div> &nbsp;</div>
<div class="col-md-12">
<div class="col-md-6 div1">
<div class="form-group">
<br>
<label for="inputPassword3" class="col-sm-2 control-label">Principle</label>
<div class="col-sm-4">
<input type="hidden" class="form-control" id="dueamt2" name="dueamt2" value="<?php echo $u;?>" placeholder=""  >  
<input type="hidden" class="form-control" id="paymnt" name="paymnt" value="<?php echo $e55;?>" placeholder="" onkeyup="add01()" >  
<input type="text" class="form-control" id="pass" name="pass" value="<?php echo $ppp;?>" placeholder="" onkeyup="add02()" required>  
</div>
<label for="inputPassword3" class="col-sm-2 control-label">Interest</label>
<div class="col-sm-4">
<input type="hidden" class="form-control" id="dueamt" name="dueamt" value="<?php echo $f55;?>" onkeyup="add03()"  placeholder="E.g 1008" >   
<input type="text" class="form-control" id="amt" name="amt" value="<?php echo $iiii;?>" onkeyup="add02()"  placeholder="E.g 1008" required>   
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Hand Loan</label>
<div class="col-sm-4">
<input type="hidden" class="form-control" STYLE="color: #ff5521; font-family: Verdana; font-weight: bold; font-size: 14px; background-color: #9bc7ef;"  id="hlbal" name="hlbal" value="<?php echo $hlbal; ?>" placeholder="" required>

<a href="viewhl.php?hpl=<?php echo $hpl; ?>&mfin2=<?php echo $mfin2; ?>" target="_blank"><input type="text" class="form-control" STYLE="color: #ff5521; font-family: Verdana; font-weight: bold; font-size: 14px; background-color: #9bc7ef;"  onkeyup="add02()" id="hloan" name="hloan" value="<?php echo $hlbal; ?>" placeholder="" required></a>

</div>
<label for="inputPassword3" class="col-sm-2 control-label">HL REMARK</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="hlrmk" name="hlrmk" value="" placeholder=""  >  
</div>

</div>
 
 
 
   <div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Add/ Less</label>
    <div class="col-sm-4">
     <input type="text" class="form-control" id="addless" name="addless" value="0"  onkeyup="add02()" placeholder=""  required>  
    </div>
<label for="inputPassword3" class="col-sm-2 control-label">Remark</label>
    <div class="col-sm-4">
    
  <input type="text" class="form-control" id="remarks" name="remarks" value="" placeholder="E.g gg" >   
   </div>
 </div>	
 <div class="form-group">
  <label for="inputPassword3" class="col-sm-2 control-label">Def. Amount</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="fine" name="fine" value="<?php echo round($fineppp,0);?>" onkeyup="add02()" placeholder=""  required>  
</div>

	<label for="inputPassword3" class="col-sm-2 control-label">Total</label>
    <div class="col-sm-4">
    
  <input type="text" class="form-control" id="urname" name="urname" value="<?php $caa = round($fineppp,0); $tottt = $ppp + $hlbal + $iiii + $caa; echo $tottt; ?>" placeholder="E.g 1008" required>   
   </div>
 </div>	
 
  <div class="form-group">
  <label for="inputPassword3" class="col-sm-2 control-label">Paid. Amount</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="pamt" name="pamt" value="" onkeyup="add55()" placeholder=""  required>  
</div>

	<label for="inputPassword3" class="col-sm-2 control-label">Reloan Amt</label>
    <div class="col-sm-4">
    
  <input type="text" class="form-control" id="reloan" name="reloan" value="<?php $caa = round($fineppp,0); $tottt = $ppp + $hlbal + $iiii + $caa; echo $tottt; ?>" placeholder="E.g 1008" required>   
   </div>
 </div>	
 
   <div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Pay Mode</label>
    <div class="col-sm-4">
     <select type="text" class="form-control"  style="width:200px; height:29px " id="inputPassword3" name="mode" width="48" value="" placeholder=""  required>  
 <option></option>
 <option>Cash A/C</option>
<?php $abank = mysqli_query($conn, "select * from ledger where under='Bank Accounts' && mfin='$mfin2'");
	while($bbank = mysqli_fetch_array($abank)) { ?>
	<option><?php echo $bbank['ledger']; ?></option>
	<?php } ?>
	  </select>   
   </div>
   </div>

 
 </div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 


 <div class="col-md-6 div2"> <br>
 <table >
 <tr>
 <td>
 Loan Amount/Dt 
 </td>
 <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
<?php echo $row['hpamount']; ?> / <?php echo $row['hpdate']; ?>
 </td>
 </tr>
  <tr>
 <td>
 Total Dues
 </td> <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
 <?php echo $row['duemnt']; ?>
 </td>
 </tr>
 
  <tr>
 <td>
 Paid Dues
 </td> <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
<?php echo $sql5;?>
 </td>
 </tr>
 
  <tr>
 <td>
Last Recpt Date
 </td> <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
 <?php echo $lddate; ?>
 </td>
 </tr>
 
  <tr>
 <td>
Ins Expiry Date
 </td> <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
-
 </td>
 </tr>
 
  <tr>
 <td>
 Coln Visit 
 </td> <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
 -
 </td>
 </tr>
 
  <tr>
 <td>
Visit Result
 </td> <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
 -
 </td>
 </tr>
 
 </table>
 </div>
 </div>

 <input type="hidden" class="form-control" id="inputPassword3" name="hpl" value="<?php echo $row['hpl'];?>" placeholder="E.g 1008" readonly required>
 
   </div> <div> &nbsp;</div><div>
      <button type="submit" class="btn btn-warning btn-block" name="s1">Register Due</button>  </div>
       <div>
	<?php
							if(isset($_POST['s1']))
							{
								extract($_POST);
								if($roll == $roll55){
								$result = mysqli_query($conn, "SELECT MAX(rno) FROM roll where mfin='$mfin2'");
$row = mysqli_fetch_array($result);
$rrno2 =  $row[0];
								$roll = $rrno2 + 1; }
								date_default_timezone_set('Asia/Kolkata');
$date = date('h:i:s a m/d/y');
$ddate =  date('h:i:s a d/m/y', strtotime($date));		
	$paydate2 = date('Y-m-d', strtotime($paydate));
$insert=mysqli_query($conn, "insert into user(createdate,status,remarks,hlrmk,hloan,mfin,scode,hpl,uid,name,paydate,paydate2,fine,urname,roll,pass,rno,bil,mode,rloan)
values('$ddate','Reloan','$remarks','$hlrmk','$hloan','$mfin','$scode','$hpl','$hpl','$name','$paydate','$paydate2','$fine','$pamt','$roll','$pass','$amt','$roll','$mode','$reloan')");

$qry3=mysqli_query($conn, "select * from customerdetails where hpl='$hpl' && mfin='$mfin'");
						$row3=mysqli_fetch_array($qry3);
$qry33=mysqli_query($conn, "select * from customerdetails where hpl='$hpl' && mfin='$mfin'");
$nn=mysqli_num_rows($qry3);
$hplg = $row3['hpl'];
$rduemnt = $row3['duemnt'];
$rinter = $row3['inter'];
$hplg = $row3['hpl'];
$rhpamt = $reloan;
$rdueamt1 = $rhpamt / $rduemnt;
$rdueamt = round($rdueamt1,0);
$rinterest1 = ($rhpamt*($rinter/100));
$rinterest = round($rinterest1,0);
$rtotal = $rdueamt + $rinterest;
if($nn == 1){
		$hpll = $hplg."R";
}
else{
	$hpll = $hplg."F";
}

$insert3=mysqli_query($conn, "insert into customerdetails(status,coaland,coaland2,hname,lmark,cofname,cofname2,pmode,cow,cow2,oaddress,fname,eno,cno,area,hlamt,hlreturn,hpdate2,cobname2,cobpno2,co2,pnooffice,pnoresi,profession,dealer,chqamt,defamt,irr,remarks,imgveh,mfin,scode,hpl,hplt,lat,lang,uimg,vno,model,vname,color,hpamount,inter,hpdate,duemnt,dueamt,interest,total,name,pno,address,address1,address2,oaddress1,oaddress2,co01,co02,co201,co202,cobname,cobpno,co,img,bname,bcommission,document,totalhpamt,g1,g2,g3,gi1,gi2,gi3,b1,b2,b3,bi1,bi2,bi3,nname,dd,mm,yy)
values('Active','".$row3['coaland']."','".$row3['coaland2']."','".$row3['hname']."','".$row3['lmark']."','".$row3['cofname']."','".$row3['cofname2']."','".$row3['pmode']."','".$row3['cow']."','".$row3['cow2']."','".$row3['oaddress']."','".$row3['fname']."','".$row3['eno']."','".$row3['cno']."','".$row3['area']."','0','".$row3['hlreturn']."','$paydate','".$row3['cobname2']."','".$row3['cobpno2']."','".$row3['co2']."','".$row3['pnooffice']."','".$row3['pnoresi']."','".$row3['profession']."','".$row3['dealer']."','".$row3['chqamt']."','".$row3['defamt']."','".$row3['irr']."','".$row3['remarks']."','".$row3['imgveh']."','".$row3['mfin']."','".$row3['scode']."','$hpll','$hplg','".$row3['lat']."','".$row3['lang']."','".$row3['uimg']."','".$row3['vno']."','".$row3['model']."','".$row3['vname']."','".$row3['color']."','$rhpamt','".$row3['inter']."','$paydate','".$row3['duemnt']."','$rdueamt','$rinterest','$rtotal','".$row3['name']."','".$row3['pno']."','".$row3['address']."','".$row3['address1']."','".$row3['address2']."','".$row3['oaddress1']."','".$row3['oaddress2']."','".$row3['co01']."','".$row3['co02']."','".$row3['co201']."','".$row3['co202']."','".$row3['cobname']."','".$row3['cobpno']."','".$row3['co']."','".$row3['img']."','".$row3['bname']."','".$row3['bcommission']."','0','$rhpamt','".$row3['g1']."','".$row3['g2']."','".$row3['g3']."','".$row3['gi1']."','".$row3['gi2']."','".$row3['gi3']."','".$row3['b1']."','".$row3['b2']."','".$row3['b3']."','".$row3['bi1']."','".$row3['bi2']."','".$row3['bi3']."','".$row3['nnamef']."','".$row3['dd']."','".$row3['mm']."','".$row3['yy']."')");	
	
										 $insert2=mysqli_query($conn, "insert into roll(rno,mfin,scode)value('$roll','$mfin2','$scode')");
								if($insert)
								{
								//	$sql1 = mysqli_query($conn, "select sum(pass) from user where mfin='$mfin2' &&  hpl='$hpl'");
									//$row5 = mysqli_fetch_array($sql1);
								//	$dd = $row5[0];
									//if($hpamt <= $dd)
									//{
									//	$insert = mysqli_query($conn, "insert into net(mfin,scode,hpl,bmnt)values('$mfin2','$scode','$hpl','$paydate')");
										
									//}
				$update=mysqli_query($conn, "update customerdetails set status='Reloan' where hpl='$hpl' && mfin='$mfin2'");		
									echo "Registered Successfully";
							$qry5=mysqli_query($conn, "select * from customerdetails where hpl='$hpll' && mfin='$mfin2' && paydate='$paydate' order by fid desc");
								$n5=mysqli_num_rows($qry5);
						$row5=mysqli_fetch_array($qry5);
					
						$idd = $row5['id'];
						
			$insert55 = mysqli_query($conn, "DELETE FROM pending where hpl='$hpl' && mfin='$mfin2'");
						//	header("Location:editled.php?id=$idd&mfin=$mfin2");		
						header("Location:search6666.php?hpl=$hpl&fid=$fid");						
							}
								else
								{
									echo "Failure";
								}
							}
?>
	  </div>
</form>

<center><h3><b>Default Per Day : <?php echo round($defamt,0); ?>/=</b></h3></center>

 <table id="datatable-buttons" id="datatable-buttons" class="table table-striped table-bordered"  border="1px" color="solid black">
					<thead>
						<tr>
						<th>Due</th>
						<th>Due Date</th>
						<th>Rcpt No</th><th>Rcpt Date</th>
						<th>Due Amt</th><th>Due Rcvd</th><th>Due Bal</th>
				        <th>Def Days</th><th>Penalty</th><th>Payed Fine</th>
						<th>Hloan Paid</th>
					
					
						
					</tr></thead>
					<tbody>
		<?php $noo = 0; $less = 0; $spdue= 0 ; $spfine = 0; $spdd = 0;
			$ttp = 0;	$tti = 0; $ttdue = 0;	$ttdd = 0;	$ttfine = 0;	$ttpf = 0;	$tthl = 0;	
				$tttot = 0;	$zz = 1;
				$qdue = 0; $qdue25 = 0;
			$ttp = 0;	$tti  = 0; $ttdue = 0;	$ttdd = 0;	$ttfine = 0;	$ttpf = 0;	$tthl = 0;	
				$tttot = 0;	$dmm = 0; $sts = 0;
						$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin2' &&  hpl='$hpl'");			
$row = mysqli_fetch_array($qry);
	   $duedat = str_replace('/', '-', $row['hpdate']);
	    $hpdate = str_replace('/', '-', $row['hpdate']);
						$pp = $row['duemnt'];
						$addr = $row['address'];
			$damt = $row['total'];		
$intt = $row['inter'];
$intt2 = $row['interest'];
$prin = $row['dueamt'];			
	$defamt2 = $row['defamt'];	
	$defamt = (($damt*$defamt2)/100)/30;	
  $d1 = strtotime($duedat);
$d2 = strtotime("today");
$min_date = min($d1, $d2);
$max_date = max($d1, $d2);

if($iii>$pp)
{ $iii=$pp; }
$rc = $iii - $sql5 ;
$sql9 = $sql5 + $rc ; $vv = 1; $ii = 0;
 
$qry5=mysqli_query($conn, "select * from user where mfin='$mfin2' && hpl='$hpl' order by paydate2 asc");			
while($row5 = mysqli_fetch_array($qry5)) { $rr = 0;
$duemnt = $row5['paymnt'];
$rcptno = $row5['roll'];
$fidd = $row5['fid'];
$gi = 0;
$rno1 = $row5['rno'];
$rno = $rno1/$duemnt;
$pass1 = $row5['pass'];
$pday = $row5['paydate'];
$pass = $pass1/$duemnt;
$urname1 = $row5['urname'];
$hloan = $row5['hloan'];
$fine1 = $row5['fine'];
$urname = ($urname1 - $hloan - $fine1) /$duemnt;
$dmm = $urname1 - $hloan - $fine1;
$ff55 = 0;
while($dmm>0) { $gi++; $rr++;
if($ff55 == 0){
	$fine18 = $fine1;
	$hloan8 = $hloan;
}
else {
	$fine18 = 0;
	$hloan8 = 0;
}
$ff55++;
if($sts==0) {
if($dmm>$damt){
	$sts = 1; $less = 0;
	$pamt = $damt;
	$noo++;
}
elseif($dmm==$damt){
	$sts = 0; $less = 0;
	$pamt = $damt;
	$noo++;
}
else{
	$sts = 2;
	$pamt = $dmm;
	$less = $damt - $dmm;
}
$ii++; $zzzz++;
$selected_date=$duedat;
		  	$selected_date=strtotime( $selected_date );
			$mysqldate = date( 'd-m-Y', $selected_date );
			$month = date( 'm', $selected_date );
			$day = date( 'd', $selected_date );
			$yyyy = date( 'Y', $selected_date );
if((($day==30)&&($month==01)) || (($day==29)&&($month==01)) || (($day==31)&&($month==01)))	
{
$duedat = "28-02-".$yyyy;
}
elseif((($day==31)&&($month==10)) || (($day==31)&&($month=='08')) || (($day==31)&&($month=='08')) || (($day==31)&&($month=='05')) || (($day==31)&&($month=='03')) || (($day==31)&&($month=='05')) || (($day==31)&&($month=='03')))	
{ 
	$hpdate55 =  "20-".$month."-".$yyyy;
	$duedat55 = date("d-m-Y", strtotime("$hpdate55 + " . 1 . " month"));
	$selected_date55=$duedat55;
		  	$selected_date55=strtotime( $selected_date55 );
			$mysqldate55 = date( 'd-m-Y', $selected_date55 );
			$month55 = date( 'm', $selected_date55 );
$duedat = "30-".$month55."-".$yyyy;
}
else {	
$duedat = date("d-m-Y", strtotime("$hpdate + " . $zz . " month"));
}
$pday = $row5['paydate'];


  $d11 = strtotime($duedat);
$d22 = strtotime($pday);
$min_date1 = min($d11, $d22);
$max_date1 = max($d11, $d22);
$i6 = 0;
if($d11<=$d22) {
while (($min_date1 = strtotime("+1 DAY", $min_date1)) <= $max_date1) {
    $i6++;
}
}
if($i6 <= 3){
    
$fine2 = 0;
} else {
$fine2 = (($defamt/$damt)*($i6 * $pamt)); }
if($fine2 < 0) {
	$fine2 = 0;
}

	?>
<tr>
					<td><?php echo $ii; ?></td>
					<td> 
					<?php $tdue = $urname - $hloan - $fine1; ?>
						<a href="editrcpt.php?fid=<?php echo $fidd; ?>"<button class="btn btn-default text-center">
                        <i class="fa  fa-pencil fa-1x"></i><b><?php echo $duedat; $zz++; ?></b>
                    </button></a></td><td><?php echo $rcptno; ?></td>
					<td><?php echo $pday; ?></td>
					<td><?php echo $damt; ?></td>
				<!--	<td><?php //echo $pass; ?></td>
					<td><?php //echo $rno; ?></td> -->
					<td><?php echo $pamt; ?></td><td></td>
				<td><?php echo $i6;?></td>	<td><?php echo round($fine2,0);?></td>	
				 <td><?php echo $fine18;?></td> 
					<td><?php echo $hloan8;?></td> 
			
</tr>
<?php $dmm = $dmm - $pamt;
$spfine = $spfine + $fine2;
$spdd = $spdd + $i6; $spdue = $spdue + $pamt;
$spff = $spff + $fine18;
$sphl = $sphl + $hloan8;
 } 

elseif($sts == 1) {
	if($dmm>$damt){
	$sts = 1; $less = 0;
	$pamt = $damt;
	$noo++;
}
elseif($dmm==$damt){
	$sts = 0; $less = 0;
	$pamt = $damt;
	$noo++;
}
else{
	$sts = 2;
	$pamt = $dmm;
	$less = $damt - $dmm;
} $ii++; $zzzz++;
$selected_date=$duedat;
		  	$selected_date=strtotime( $selected_date );
			$mysqldate = date( 'd-m-Y', $selected_date );
			$month = date( 'm', $selected_date );
			$day = date( 'd', $selected_date );
			$yyyy = date( 'Y', $selected_date );
if((($day==30)&&($month==01)) || (($day==29)&&($month==01)) || (($day==31)&&($month==01)))	
{
$duedat = "28-02-".$yyyy;
}
elseif((($day==31)&&($month==10)) || (($day==31)&&($month=='08')) || (($day==31)&&($month=='08')) || (($day==31)&&($month=='05')) || (($day==31)&&($month=='03')) || (($day==31)&&($month=='05')) || (($day==31)&&($month=='03')))	
{ 
	$hpdate55 =  "20-".$month."-".$yyyy;
	$duedat55 = date("d-m-Y", strtotime("$hpdate55 + " . 1 . " month"));
	$selected_date55=$duedat55;
		  	$selected_date55=strtotime( $selected_date55 );
			$mysqldate55 = date( 'd-m-Y', $selected_date55 );
			$month55 = date( 'm', $selected_date55 );
$duedat = "30-".$month55."-".$yyyy;
}
else {	
$duedat = date("d-m-Y", strtotime("$hpdate + " . $zz . " month"));
}



  $d11 = strtotime($duedat);
$d22 = strtotime($pday);
$min_date1 = min($d11, $d22);
$max_date1 = max($d11, $d22);
$i6 = 0;
if($d11<=$d22) {
while (($min_date1 = strtotime("+1 DAY", $min_date1)) <= $max_date1) {
    $i6++;
}
}
if($i6 <= 3){
    
$fine2 = 0;
} else {
$fine2 = (($defamt/$damt)*($i6 * $pamt)); }
if($fine2 < 0) {
	$fine2 = 0;
} 
	?>
<tr>
					<td><?php echo $ii; ?></td>
					<td> 
					<?php $tdue = $urname - $hloan - $fine1; ?>
						<a href="editrcpt.php?fid=<?php echo $fidd; ?>"<button class="btn btn-default text-center">
                        <i class="fa  fa-pencil fa-1x"></i><b><?php echo $duedat; $zz++;?></b>
                    </button></a></td><td><?php echo $rcptno; ?></td>
					<td><?php echo $pday; ?></td>
					<td><?php echo $damt; ?></td>
				<!--	<td><?php //echo $pass; ?></td>
					<td><?php //echo $rno; ?></td> -->
					<td><?php echo $pamt; ?></td><td></td>
				<td><?php echo $i6;?></td>	<td><?php echo round($fine2,0);?></td>	
			<td><?php echo $fine18;?></td> 
					<td><?php echo $hloan8;?></td> 
			
</tr>

<?php $dmm = $dmm - $pamt;
$spfine = $spfine + $fine2;
$spdd = $spdd + $i6; $spdue = $spdue + $pamt;
$spff = $spff + $fine18;
$sphl = $sphl + $hloan8;
 } 
else { 
  $d11 = strtotime($duedat);
$d22 = strtotime($pday);
$min_date1 = min($d11, $d22);
$max_date1 = max($d11, $d22);
$i6 = 0;
if($d11<=$d22) {
while (($min_date1 = strtotime("+1 DAY", $min_date1)) <= $max_date1) {
    $i6++;
}
}
if($i6 < 3){
    
$fine2 = 0;
} else {
$fine2 = (($defamt/$damt)*($i6 * $less));
 }
if($fine2 < 0) {
	$fine2 = 0;
}
if($less>$dmm){
$dmm2 = $less - $dmm; $noo++;
$less2 = $less  - $dmm2; 
$spdue = $spdue + $less;
$dmm = 0;
///////////////////////////////////////////////// checkit	?><tr>
					<td></td>
					<td></td>	
				<?php if($gi==1) { ?>  <td><?php echo $rcptno; ?></td>  <?php } else { ?>
<td></td>
				<?php } ?>
					<td><?php echo $pday; ?></td>
					<td></td>
				<!--	<td><?php //echo $pass; ?></td>
					<td><?php //echo $rno; ?></td> -->
					<td><?php echo $less2; ?></td><td></td>
				<td><?php echo $i6; ?></td>	
				<td><?php echo round($fine2,0); ?></td>	
				<?php if($gi==1) { ?>  <td><?php echo $fine18;?></td>  <?php } else { ?>
<td></td>
				<?php } ?>
				<td><?php echo $hloan8;?></td>  
				
</tr> <?php
if($dmm>$damt){
	$sts = 1;
	$less = 0;
	$pamt = $damt;
	$noo++;
}
elseif($dmm==$damt){
	$sts = 0; $less = 0;
	$pamt = $damt;
	$noo++;
}
else{
	
	$sts = 2;
	$pamt = $less2;
	$less = $dmm2;
}
$pamt = $less2;	
}
else{
$dmm = $dmm - $less; $noo++;
$spdue = $spdue + $less;
///////////////////////////////////////////// checkit	?><tr>
					<td></td>
					<td></td>	
				<?php if($gi==1) { ?>  <td><?php echo $rcptno; ?></td>  <?php } else { ?>
<td></td>
				<?php } ?>
					<td><?php echo $pday; ?></td>
					<td></td>
				<!--	<td><?php //echo $pass; ?></td>
					<td><?php //echo $rno; ?></td> -->
					<td><?php echo $less; ?></td><td></td>
				<td><?php echo $i6; ?></td>	
				<td><?php echo round($fine2,0); ?></td>	
				<?php if($gi==1) { ?>  <td><?php echo $fine18;?></td>  <?php } else { ?>
<td></td>
				<?php } ?>
				<td><?php echo $hloan8;?></td>  
				
</tr> <?php
if($dmm>$damt){
	$sts = 1;
	$less = 0;
	$pamt = $damt;
	$noo++;
}
elseif($dmm==$damt){
	$sts = 0; $less = 0;
	$pamt = $damt;
	$noo++;
}
else{
	
	$sts = 0;
	$pamt = $dmm;
	$less = 0;
}
$pamt = $dmm; }
?>

<?php $dmm = $dmm;
$spfine = $spfine + $fine2;
$spdd = $spdd + $i6; $spff = $spff + $fine18;  
$sphl = $sphl + $hloan8;
 }  
$ttp = $ttp + $pass; $tti = $tti + $rno; $ttdue = $ttdue + $urname;	$ttdd = $ttdd + $i6;	
$ttfine = $ttfine + $fine2;	
$ttpf = $fine1 + $ttpf;	$tthl = $tthl + $hloan;	$tttot = $tttot + $urname1;
				
} } 





$qry51=mysqli_query($conn, "select * from net where mfin='$mfin2' &&  hpl='$hpl'");
					$n51=mysqli_num_rows($qry51);
					$row51 = mysqli_fetch_array($qry51);
					if($n51>0){ ?>
			<tr>
					<td></td>
					<td> 
					<?php $tdue = $row51['tot'] - $row51['hloan'] - $row51['fine'];
$spff = $spff + $row51['fine'];  
$sphl = $sphl + $row51['hloan'];
					?>
						<a href="editrcpt.php?fid=<?php echo $fidd; ?>"<button class="btn btn-success text-center">
                        A/C Closed
                    </button></a></td><td><?php echo $row51['roll']; ?></td>
					<td><?php echo $row51['paydate']; ?></td>
					<td></td>
				<!--	<td><?php //echo $pass; ?></td>
					<td><?php //echo $rno; ?></td> -->
					<td><?php echo $row51['tot']; ?></td><td></td>
				<td></td>	<td></td>	
				 <td><?php echo $row51['fine']; ?></td> 
					<td><?php echo $row51['hloan']; ?></td> 
			
</tr>			
				<?php $ttt = $row51['tot'];  $spdue = $spdue + $ttt;	}
else { 
if($less > 0){
	$tday = date('d-m-Y');
  $d11 = strtotime($duedat);
$d22 = strtotime($tday);
$min_date1 = min($d11, $d22);
$max_date1 = max($d11, $d22);
$i6 = 0;
if($d11<=$d22) {
while (($min_date1 = strtotime("+1 DAY", $min_date1)) <= $max_date1) {
    $i6++;
}
}
if($i6 < 3){
    
$fine2 = 0;
} else {
$fine2 = (($defamt/$damt)*($i6 * $less));
 }
if($fine2 < 0) {
	$fine2 = 0;
}

$dmm = 0;
	?><tr>
					<td></td>
					<td></td>	
					<td></td>
					<td></td>
					<td></td>
				<!--	<td><?php //echo $pass; ?></td>
					<td><?php //echo $rno; ?></td> -->
					<td></td><td><?php echo $less; ?></td>
				<td><?php echo $i6; ?></td>	
				<td><?php echo round($fine2,0); ?></td>	
				<?php if($gi==1) { ?> <td></td> <?php } else { ?>
<td></td>
				<?php } ?>
				<td><?php echo $hloan8;?></td>  
				
</tr>  <?php	
$spfine = $spfine + $fine2;
$spdd = $spdd + $i6;
$sppp = $sppp + $less;
}
$ii++;
while($ii<=$pp) {
	$zzzz++;
	$selected_date=$duedat;
		  	$selected_date=strtotime( $selected_date );
			$mysqldate = date( 'd-m-Y', $selected_date );
			$month = date( 'm', $selected_date );
			$day = date( 'd', $selected_date );
			$yyyy = date( 'Y', $selected_date );
if((($day==30)&&($month==01)) || (($day==29)&&($month==01)) || (($day==31)&&($month==01)))	
{
$duedat = "28-02-".$yyyy;
}
elseif((($day==31)&&($month==10)) || (($day==31)&&($month=='08')) || (($day==31)&&($month=='08')) || (($day==31)&&($month=='05')) || (($day==31)&&($month=='03')) || (($day==31)&&($month=='05')) || (($day==31)&&($month=='03')))	
{ 
	$hpdate55 =  "20-".$month."-".$yyyy;
	$duedat55 = date("d-m-Y", strtotime("$hpdate55 + " . 1 . " month"));
	$selected_date55=$duedat55;
		  	$selected_date55=strtotime( $selected_date55 );
			$mysqldate55 = date( 'd-m-Y', $selected_date55 );
			$month55 = date( 'm', $selected_date55 );
$duedat = "30-".$month55."-".$yyyy;
}
else {	
$duedat = date("d-m-Y", strtotime("$hpdate + " . $zz . " month"));
}
  $d11 = strtotime($duedat);
$d22 = strtotime("today");
$min_date1 = min($d11, $d22);
$max_date1 = max($d11, $d22);
$i6 = 0;
if($d11<=$d22) {
while (($min_date1 = strtotime("+1 DAY", $min_date1)) <= $max_date1) {
    $i6++;
} }

if($i6 <= 3){
    
$fine2 = 0;
} else {
$fine2 = $defamt * $i6; }
if($fine2 < 0) {
	$fine2 = 0;
}
	?>
<tr>
					<td><?php echo $ii; ?></td>
						<?php if($i6 > 0){ ?>
					<td><button class="btn btn-danger text-center"><i class="fa  fa-pencil fa-1x"></i><b><?php echo $duedat; $zz++;?></b>
                    </button></td>
					<?php } else { ?>
					<td><button class="btn btn-success text-center"><i class="fa  fa-pencil fa-1x"></i><b><?php echo $duedat; $zz++;?></b>
                    </button></td> <?php } ?><td></td><td></td>
					<td><?php echo $damt; ?></td>
					<!--<td><?php //echo $prin; ?></td>
					<td><?php //echo $intt2; ?></td> -->
					<td></td><td><?php echo $damt; ?></td>
						<td><?php echo $i6;?></td><td><?php echo round($fine2,0);?></td><td>-</td>
					<td>-</td>
				
</tr> 

<?php  $ii++; 
$ttdd = $ttdd + $i6;	
$ttfine = $ttfine + $fine2;	
$spfine = $spfine + $fine2;
$spdd = $spdd + $i6;
$sppp = $sppp + $damt;
} } ?>	
<tr>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td><b><?php $ccc = $spdue + $sppp; echo $ccc; ?></b></td>
					<!--	<td><?php //echo $ttp; ?></td>
					<td><?php //echo $tti; ?></td> -->
						<td><b><?php echo $spdue; ?></b></td>
						<td><b><font color="red"><?php echo $sppp; ?></font></b></td>
						<td><b><?php echo $spdd; ?></b></td>
						<td><b><?php echo round($spfine,0); ?></b></td>
						<td><b><?php echo $spff; ?></b></td>
						<td><b><?php echo $sphl; ?></b></td>
		</tr>		
					</tbody></table>
   <?php $a1 = 0;  $a2 = 0;   $a3 = 0;   $a4 = 0;   $a5 = 0; 
		$qry1=mysqli_query($conn, "select * from user  where mfin='$mfin2' &&  hpl='$hpl' order by paydate2 asc");
					if($n1==0)
						{
							echo "Nothing To Display";
						}
						else
					{ 
						?></p>
					<table class="table table-striped" table class="table" border="0" align="center" cellspacing="0" cellpadding="10" >
					<col width="100px">
					 <tr class="alert alert-info">
					<th style="width:7%">Rcpt No</th>	
							<th style="width:10%">Status</th>
						
						
						<th>Pay Date</th>
							<th>Total</th>
						<th>Due Amt</th>
						<th>Princ</th>
						<th>Intst</th>
						<th>Fine</th>
						<th>HLoan</th>	<th>Reloan</th>
				<th>#Edit</th>
			
						<th>Create </th>
							<th>Altered</th>
					
					</tr>
					
					<?php $i = 0; 
					
				while($row=mysqli_fetch_array($qry1)) 	
					{ 
					$i++;
					 $aaa  = $row['urname'];
					 $sts = $row['status'];
$sts2 = "Reloan";
?>				<tr>
					<td><b><?php echo $row['roll'];?></b></td>
						
						 <?php if($sts == $sts2){ ?>
<td><b><a href="editrcpt.php?fid=<?php echo $row['fid'];?>"><button class="btn btn-warning">Reloan</button></a></b></td>
						 <?php } else { ?>
			<td><b><a href="editrcpt.php?fid=<?php echo $row['fid'];?>"><button class="btn btn-success">Due</button></a></b></td>			 
						 <?php } ?>
				
						
						<td><b><?php echo $row['paydate'];?></b></td>
							<td><b><?php echo $aaa;?></b></td>
						<td><b><?php echo $row['dueamount'];?></b></td>
						<td><b><?php echo $row['pass'];?></b></td>
						<td><b><?php echo $row['rno'];?></b></td>
						<td><b><?php echo $row['fine'];?></b></td>
						<td><b><?php echo $row['hloan'];?></b></td>
					
					<td><b><?php echo $row['rloan'];?></b></td>
						<?php $damt = $damt + $row['dueamount']; $pass = $pass + $row['pass']; $rno = $rno + $row['rno']; 
						$fine = $fine + $row['fine']; $hll = $hll + $row['hloan']; $bal = $bal + $row['bal'];$a22 = $a22 + $a2; $urname = $urname + $aaa; ?>
					    
				<td><b>
<a href="editrcpt.php?fid=<?php echo $row['fid'];?>" class="btn btn-danger btn-xs" onclick="return confirm('Are you sure WANT TO Edit?');">Edit</a>				

</br><a href="cancel.php?fid=<?php echo $row['fid'];?>" class="btn btn-primary btn-xs" onclick="return confirm('Are you sure WANT TO CANCEL?');">Cancel</a></b></td>	

						<td><b><font size="1"><?php echo $row['createdate'];?></br>
						<?php echo $row['scode'];?></font>
						</b></td>
						<td><b><font size="1"><?php echo $row['altdate'];?></br><?php echo $row['altby'];?></b></font></td>
		</tr>  <?php 
					}
					}
					?>
				
						</table>
					
</div>
</div></div>
</div></div></div> <?php include "layouts/footer.php"; ?> </body></html>