<?php include "layouts/menu.php"; ?>
    <?php $hpl=$_REQUEST['hpl']; $mfin2=$_REQUEST['mfin2'];
	?>
	<?php /*$vno=$_REQUEST['vno'];*/?>
	
<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: 240px;
    border: 4px solid #376ca1;
	background-color:#f4f6df;
	float:left;
}

.div2 {
    width: 380px;
    height: 240px;    
background-color:#f4f6df;
    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 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 =((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("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>
  <!--  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 customerdetailsw where mfin='$mfin2' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql);
                                    $row52 = mysqli_fetch_array($q);	
                                    $rrow44 = $row52[0] + $rrow44;								
									
									$sql = "SELECT SUM(pass) FROM userw 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 userw 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='$mfin2'");
$row = mysqli_fetch_array($result);
$rrno2 =  $row[0];

//$qry6=mysqli_query($conn, "select * from roll where mfin='$mfin2' 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 userw 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 userw where mfin='$mfin2' &&  hpl='$hpl'";
$qt = mysqli_query($conn, $sql1);
$row1 = mysqli_fetch_array($qt);
$sql5=$row1[0];
$sql6=$sql5 + 1;
$nuserwpay = $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='$mfin2' &&  hpl='$hpl'";
$qt55 = mysqli_query($conn, $sql155);
$row155 = mysqli_fetch_array($qt55);
$hlbal2=$row155[0];

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

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

 $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;	
				$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 customerdetailsw 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'];
$g1 = $row['g1'];
$b1 = $row['b1'];
$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 userw 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++;
$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 );
$duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " week"));
$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;
}
 $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++; 
$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 );
$duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " week"));



  $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;
}  $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;
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;
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; }
 $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 netw where mfin='$mfin2' &&  hpl='$hpl'");
					$n51=mysqli_num_rows($qry51);
					$row51 = mysqli_fetch_array($qry51);
					if($n51>0){  $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;	
$spfine = $spfine + $fine2;
$spdd = $spdd + $i6;
$sppp = $sppp + $less;
}
$ii++; $ni = 0;
while($ii<=$pp) {
	 $duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " week")); 
  $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;
} $ii++; 
$ttdd = $ttdd + $i6;	
$ttfine = $ttfine + $fine2;	
$spfine = $spfine + $fine2;
$spdd = $spdd + $i6;
if($i6>0){
	$ni++;
	$sppdue = $sppdue + $damt;
}
} }
$fine55 = $spfine - $spff;
$spddd = $less + $sppdue;
$qry=mysqli_query($conn, "select * from customerdetailsw 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'];	
$g1 = $row['g1'];
$b1 = $row['b1'];
?>


<div class="col-md-12">
<?php if($g1 == NULL) { ?> <blink><center><b><font color="red"><h3>Update Customer Aadhar No</h3></center></b></blink></font> <?php }
if($b1 == NULL) { ?> <blink><center><b><font color="red"><h3>Update Co-Applicant Aadhar No</h3></center></blink></b></font> <?php } ?>
	<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="vno" width="48" value="<?php echo $row['vno'];?>" placeholder=""  >  
 <input type="hidden" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="hpdate" width="48" value="<?php echo $row['hpdate'];?>" 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=""  >  
 <input type="hidden" class="form-control" style="width:170px; height:29px " id="interest" name="interest" width="48" value="<?php echo $row['interest'];?>" 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="vno" value="<?php echo $row['vno'];?>" 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=""  >  
    </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">Dues</label>
<div class="col-sm-4">

<input type="hidden" class="form-control" id="payyy" name="payyy" value="<?php echo $sql5;?>" placeholder=""  required> 
<input type="hidden" class="form-control" id="dueamt2" name="dueamt2" value="<?php echo $u;?>" placeholder=""  required>  
<input type="hidden" class="form-control" id="paymnt11" name="paymnt11" value="<?php echo $ni;?>" placeholder="">  
<input type="text" class="form-control" id="paymnt" name="paymnt" value="<?php echo $ni;?>" placeholder="" onkeyup="add01()" required>  
</div>
<label for="inputPassword3" class="col-sm-2 control-label">Due Amount</label>
<div class="col-sm-4">
<input type="hidden" class="form-control" id="dueamt11" name="dueamt11" value="<?php echo $spddd;?>"  placeholder="E.g 1008" >  
<input type="text" class="form-control" id="dueamt" name="dueamt" value="<?php echo $spddd;?>" onkeyup="add03()"  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>
<input type="hidden" class="form-control" id="hloan11" name="hloan11" value="<?php echo $hlbal; ?>" placeholder="" >

<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">Def. Amount</label>
<div class="col-sm-4">
<input type="hidden" class="form-control" id="fine11" name="fine11" value="<?php echo round($fine55,0);?>" placeholder=""  >  

<input type="text" class="form-control" id="fine" name="fine" value="<?php echo round($fine55,0);?>" onkeyup="add02()" placeholder=""  required>  
</div>

	<label for="inputPassword3" class="col-sm-2 control-label">Total</label>
    <div class="col-sm-4">
      <input type="hidden" class="form-control" id="urname11" name="urname11" value="<?php $caa = round($fine55,0); $tottt = $spddd + $caa + $hlbal; echo $tottt; ?>" placeholder="E.g 1008" >   

  <input type="text" class="form-control" id="urname" name="urname" value="<?php $caa = round($fine55,0); $tottt = $spddd + $caa + $hlbal; echo $tottt; ?>" placeholder="E.g 1008" required>   
   </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">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
$sen = 'SENTHOOR MOTOR FINANCE';
$sor = 'SOORYA MOTOR FINANCE';
$mat = 'MAATHOOR FINANCE';
 if($mfin2==$sor) { ?>
	    <option>Cub A/C No- 510909010029003</option>
		  <option>I.O.B A/C No- 013002000006220</option>  <option>K V B A/C No- 1674135000000062</option> -->
	  <?php  } 
	  if($mfin2==$sen) { ?>
	    <option>Cub A/C No- 510909010029001</option>
		  <option>I.O.B A/C No- 013002000005633</option>  <option>K V B A/C No- 1674135000000050</option>
	  <?php } 
	  if($mfin2==$mat) { ?>
	    <option>Cub A/C No- -</option>
		  <option>I.O.B A/C No- -</option>  <option>K V B A/C No- -</option>
	  <?php } ?>
	  </select>   
   </div>
  
	  <input type="hidden" class="form-control" name="sss" value="" placeholder="" >
     
</div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </div>
 <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>
 <tr>
 <td colspan="2"> <?php  if(($postt == 'MD') || ($postt == 'Office All')) { ?>
 <select class="form-control" style="width:170px; height:29px " id="inputPassword3" name="rolll" value="" placeholder="" >  
 <option value="0">Normal RCPT</option>
 <option value="1">RCPT No Not Reflect</option></select>
 <?php } else { ?>

 <input type="hidden" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="rolll" value="555" placeholder="" > 
 <?php } ?>
 </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">Save & Print</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; }
								$duemnt2 = $no;
								$hpamt = $hpamount;
								$ddamt = $ddamt;
								$fddue = $dueamount * $paymnt;
								$dueamt11 = $dueamt11;
								$dueamt = $dueamt;
								//$cpass = $ddamt * $paymnt;
								$crno = $interest * $paymnt;
								$cpass = $dueamt - $crno;
								$sql1 = "select sum(paymnt) from userw where mfin='$mfin2' &&  hpl='$hpl'";
                                $qt = mysqli_query($conn, $sql1);
                                $row1 = mysqli_fetch_array($qt);
                                $payyyf=$row1[0];
								$sql11 = "select sum(pass) from userw where mfin='$mfin2' &&  hpl='$hpl'";
                                $qt1 = mysqli_query($conn, $sql11);
                                $row11 = mysqli_fetch_array($qt1);
                                $dddd=$row11[0];
								$sql112 = "select sum(rno) from userw where mfin='$mfin2' &&  hpl='$hpl'";
                                $qt13 = mysqli_query($conn, $sql112);
                                $row113 = mysqli_fetch_array($qt13);
                                $fff=$row113[0];
								$gffdd =  $dddd + $fff;
								$ffddd = $dueamount * $payyyf;
								$hpdate = $hpdate;
								$totpay = $payyyf + $paymnt + 1;
								$status = "-";
							
								$nddate = date("d-m-Y", strtotime("$hpdate + " . $totpay . " week"));
								if($paymnt == 0){
									if($ffddd == $gffdd) {
									$pyo1 = $payyyf + 1;
									$status = $pyo1."P Due ";
									}
									elseif($ffddd > $gffdd){
										$pyo1  = $payyyf;
										$pyo21 = $payyyf + 1;
											$totpay = $payyyf + $paymnt + 2;
										$nddate = date("d-m-Y", strtotime("$hpdate + " . $totpay . " week"));
									$status = $pyo1."B & ".$pyo21."P Due ";
									}
									else{
										$pyo1 = $payyyf;
									$status = $pyo1."B Due ";
									}
								//if($interest<=$dueamt)	{	
								//$crno = $interest;
								//$cpass = $dueamt - $crno;
								//}
								//else {
								//	$crno = $dueamt;
								//$cpass = 0;
							//	}
								
								}
								if($paymnt == 1){
									if($dueamt==$fddue){
									$py1 = $payyyf + 1;
									if($py1==1){
									$status = $py1."st Due"; }
									elseif($py1==2){
									$status = $py1."nd Due"; }
									elseif($py1==3){
									$status = $py1."rd Due"; }
									else{
									$status = $py1."th Due"; } 
									}
									
									elseif($dueamt11>$dueamt) {
									$py1 = $payyyf + 1;
									if($py1==1){
									$status = $py1."st Due"; }
									elseif($py1==2){
									$status = "1st P & ".$py1." nd Due"; }
									elseif($py1==3){
									$status = "2nd P & ".$py1."rd Due"; }
									else{
									$status = $payyyf."P & ".$py1."st Due"; } 
									}
									
										else {
									$py1 = $payyyf + 1;
									$py12 = $payyyf + 2;
									$status = $py1." & ".$py12."P Due"; 
									}
									
								}
								if($paymnt == 2){
									$py1 = $payyyf + 1;
									$py2 = $payyyf + 2;
									$status = $py1."&".$py2."th Dues";
								}
								if($paymnt == 3){
									$py1 = $payyyf + 1;
									$py2 = $payyyf + 2;
									$py3 = $payyyf + 3;
									$status = $py1.",".$py2."&".$py3."th Dues";
								}
								if($paymnt == 4){
									$py1 = $payyyf + 1;
									$py2 = $payyyf + 2;
									$py3 = $payyyf + 3;
									$py4 = $payyyf + 4;
									$status = $py1.",".$py2.",".$py3."&".$py4."th Dues";
								}
								if($paymnt == 5){
									$py1 = $payyyf + 1;
									$py2 = $payyyf + 2;
									$py3 = $payyyf + 3;
									$py4 = $payyyf + 4; $py4 = $payyyf + 5;
									$status = $py1.",".$py2.",".$py3.",".$py4."&".$py5."th Dues";
								}
				
									$paydate2 = date('Y-m-d', strtotime($paydate));
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));	
								$insert=mysqli_query($conn, "insert into userw(createdate,paydate2,status,nddate,remarks,vno,hlrmk,hloan,mfin,scode,hpl,uid,name,no,dueamount,paydate,paymnt,fine,urname,roll,pass,rno,bil,mode)
											 values('$ddate','$paydate2','$status','$nddate','$remarks','$vno','$hlrmk','$hloan','$mfin2','$scode','$hpl','$hpl','$name','$no','$dueamount','$paydate','$paymnt','$fine','$urname','$roll','$cpass','$crno','$roll','$mode')");
						
						if($rolll == 1) {
	}
	else {
								$insert33=mysqli_query($conn, "insert into roll(rno,mfin,scode)value('$roll','$mfin2','$scode')");
	}
								
								if($insert)
								{
if($sss=='Yes')
										{
											mysqli_query($conn, "DELETE FROM sizzing where hpl='$hpl' && mfin='$mfin2'");
$insert224=mysqli_query($conn, "update customerdetailsw set status='Active' where hpl='$hpl' && mfin='$mfin2'");											
										}
							$opaymnt = $paymnt;
									$sql5 = mysqli_query($conn, "select * from pending where hpl='$hpl' && mfin='$mfin2'");
									$row5 = mysqli_fetch_array($sql5);
										
										$bpaymnt = $row5['pendmnt'];

$paymnt112 = $paymnt11 - $paymnt;
$dueamt112 = $dueamt11 - $dueamt;
$hloan112 = $hloan11  - $hloan;
$fine112 = $fine11 - $fine;
$urname112 = $urname11 - $urname;
$insert22=mysqli_query($conn, "update pending set pendmnt='$paymnt112',penamt='$urname112',dueamt='$dueamt112',hloan='$hloan112',defday='$fine112' where hpl='$hpl' && mfin='$mfin2'");

									
								//	$sql1 = mysqli_query($conn, "select sum(pass) from userw where mfin='$mfin2' &&  hpl='$hpl'");
									//$row5 = mysqli_fetch_array($sql1);
								//	$dd = $row5[0];
									//if($hpamt <= $dd)
									//{
									//	$insert = mysqli_query($conn, "insert into netw(mfin,scode,hpl,bmnt)values('$mfin2','$scode','$hpl','$paydate')");
										
									//}
									echo "Registered Successfully";
								$qry5=mysqli_query($conn, "select * from userw where hpl='$hpl' && mfin='$mfin2' && paydate='$paydate' order by fid desc");
								$n5=mysqli_num_rows($qry5);
						$row5=mysqli_fetch_array($qry5);
					
						$fid = $row5['fid'];
		
							header("Location:search66.php?hpl=$hpl&fid=$fid");								
							}
								else
								{
									echo "Failure";
								}
							}
?>
	  </div>
</form> <?php
$damt = $row['total'];			
	$defamt2 = $row['defamt'];	
	$defamt = (($damt*$defamt2)/100)/30;	
?>			<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>Paid 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;	 $less = 0; $pamt = 0; $sppp = 0;
				$qdue = 0; $qdue25 = 0; $i6 = 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 customerdetailsw 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'];
$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 userw 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++;
$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 );
$duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " week"));
$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;?></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++; 
$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 );
$duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " week"));



  $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;?></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;
	?><tr>
					<td></td>
					<td></td>	
					<td></td>
					<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></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;
	?><tr>
					<td></td>
					<td></td>	
					<td></td>
					<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></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 netw where mfin='$mfin2' &&  hpl='$hpl'");
					$n51=mysqli_num_rows($qry51);
					$row51 = mysqli_fetch_array($qry51);
					if($n51>0){ ?>
			<tr>
					<td></td>
					<td> 
					<?php $tdue = $urname - $hloan - $fine1; ?>
						<a href="editrcpt.php?fid=<?php echo $fidd; ?>"<button class="btn btn-danger 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 $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) {
	 $duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " week")); 
  $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-info text-center"><i class="fa  fa-pencil fa-1x"></i><b><?php echo $duedat;?></b>
                    </button></td>
					<?php } else { ?>
					<td><button class="btn btn-danger text-center"><i class="fa  fa-pencil fa-1x"></i><b><?php echo $duedat;?></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>
					
</div>
</div></div>
</div></div></div> <?php include "layouts/footer.php"; ?> </body></html>