<?php include "layouts/menu.php"; ?>
    <?php $hpl=$_REQUEST['hpl'];?>
	<?php  $mfin2=$_REQUEST['mfin2']; ?>
	
<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:#ec9e66;
	float:left;
}

.div2 {
    width: 380px;
    height: 240px;    
background-color:#ec9e66;
    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 =((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 flat() 
{ 
var a = document.getElementById("ttflat").value; 

document.getElementById("amt").value =(a*1); 
document.getElementById("fine").value =(0*1); 
var d = document.getElementById("amt").value; 
var dd = document.getElementById("pass").value; 
var e = document.getElementById("hloan").value; 
var f = document.getElementById("fine").value; 
var al = document.getElementById("addless").value; 

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

<script> 
function nor() 
{ 
var a = document.getElementById("amt222").value; 
var b = document.getElementById("fine2").value; 
document.getElementById("amt").value =(a*1); 
document.getElementById("fine").value =(b*1); 
var d = document.getElementById("amt").value; 
var dd = document.getElementById("pass").value; 
var e = document.getElementById("hloan").value; 
var f = document.getElementById("fine").value; 
var al = document.getElementById("addless").value; 

document.getElementById("urname").value = ((d*1)+(dd*1)+(e*1)+(f*1)-(al*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; 
var al = document.getElementById("addless").value; 

document.getElementById("urname").value = ((d*1)+(dd*1)+(e*1)+(f*1)-(al*1)); 
 
} 
</script>
<style>
/* The container */
.container1 {
  display: block;
  position: relative;
  padding-left: 35px;
  margin-bottom: 12px;
  cursor: pointer;
  font-size: 17px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Hide the browser's default radio button */
.container1 input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

/* Create a custom radio button */
.checkmark1 {
  position: absolute;
  top: 0;
  left: 0;
  height: 18px;
  width: 18px;
  background-color: #ec9e66;
  border-radius: 50%;
}

/* On mouse-over, add a grey background color */
.container1:hover input ~ .checkmark1 {
  background-color: #ccc;
}

/* When the radio button is checked, add a blue background */
.container1 input:checked ~ .checkmark1 {
  background-color: #2196F3;
}

/* Create the indicator (the dot/circle - hidden when not checked) */
.checkmark1:after {
  content: "";
  position: absolute;
  display: none;
}

/* Show the indicator (dot/circle) when checked */
.container1 input:checked ~ .checkmark1:after {
  display: block;
}

/* Style the indicator (dot/circle) */
.container1 .checkmark1:after {
 	top: 9px;
	left: 9px;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: white;
}
</style>
  <!--  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 $rrno2 = 0; $fflat = 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='$mfin2'");
$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='$mfin2' &&  hpl='$hpl'";
$qt55 = mysqli_query($conn, $sql155);
$row155 = mysqli_fetch_array($qt55);
$hlbal2=$row155[0];

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


$sql1552 = "select sum(hloan) from user where mfin='$mfin2' &&  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;
$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='$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 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='$mfin2' &&  hpl='$hpl'";
$qt55 = mysqli_query($conn, $sql155);
$row155 = mysqli_fetch_array($qt55);
$hlbal2=$row155[0];

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

$sql1552 = "select sum(hloan) from user 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 customerdetails where mfin='$mfin2' &&  hpl='$hpl'");			
$row = mysqli_fetch_array($qry);
	   $duedat = str_replace('/', '-', $row['hpdate']);
	      $hhh = str_replace('/', '-', $row['hpdate']);
						$pp = $row['duemnt'];
						$addr = $row['address'];
							$hpat = $row['hpamount'];
			$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($d1<=$d2) {
//while (($min_date1 = strtotime("+1 DAY", $min_date)) <= $max_date) {
   // $fflat++;
//}
//}

$datediff = $d2 - $d1;

$fflat =  round($datediff / (60 * 60 * 24));

$tflat22 = (($hpat * $fflat * 50)/36500);
$tflat = round($tflat22,0);
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++;
$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;
}
else {	
$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/$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 );
if((($day==30)&&($month==01)) || (($day==29)&&($month==01)) || (($day==31)&&($month==01)))	
{
$duedat = "28-02-".$yyyy;
}
else {	
$duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " 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;
}  $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 net 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 . " 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;
} $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 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']; 
$ttflat = $tflat - $p2int;
?>


<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['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=""  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-3">
<label class="container1">Normal
  <input type="radio" onclick="nor()" checked="checked" id="nor1" name="nor1" value="nor" >
  <span class="checkmark1"></span>
</label> </div>
<div class="col-md-3">
<label class="container1"> Due Red
  <input type="radio" onclick="nor()" id="nor" name="nor11" value="nor" >
  <span class="checkmark1"></span>
</label> </div>
<div class="col-md-3">
<label class="container1">Flat(50) (<?php echo $fflat; ?>Days<?php echo $tflat; ?>)
  <input type="radio"  onclick="flat()" id="nor" name="nor" value="flat" >
  <span class="checkmark1"></span>
</label> </div>
<div class="col-md-3">
<label class="container1">Diminish(50)
  <input type="radio" id="nor" name="nor" value="dim" >
  <span class="checkmark1"></span>
</label> </div>
</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" readonly 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="hidden" class="form-control" id="tflat" name="tflat" value="<?php echo $tflat;?>"  >   
 <input type="hidden" class="form-control" id="ttflat" name="ttflat" value="<?php echo $ttflat;?>"  >  
 <input type="hidden" class="form-control" id="fflat" name="fflat" value="<?php echo $fflat;?>"  > 
<input type="text" class="form-control" id="amt" name="amt" value="<?php echo $iiii;?>" onkeyup="add02()"  placeholder="E.g 1008" required>   
<input type="hidden" class="form-control" id="amt222" name="amt222" 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; ?>" readonly target="_blank"><input type="text" readonly 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="text" class="form-control" id="fine" name="fine" value="<?php echo round($fine55,0);?>" onkeyup="add02()" placeholder=""  required>  
<input type="hidden" class="form-control" id="fine2" name="fine2" 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="text" class="form-control" id="urname" name="urname" value="<?php $caa = round($fine55,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">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>
   </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 net(paydate2,createdate,addless,remarks,dueamount,hlrmk,hloan,mfin,scode,hpl,name,dueamt,amt,fine,tot,rno,rrno,mode,paydate,bmnt)
								 values('$paydate2','$ddate','$addless','$remarks','$urname','$hlrmk','$hloan','$mfin2','$scode','$hpl','$name','$pass','$amt','$fine','$urname','$roll','$roll','$mode','$paydate','$paydate')");
								$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='Closed' where hpl='$hpl' && mfin='$mfin2'");		
									echo "Registered Successfully";
								$qry5=mysqli_query($conn, "select * from net where hpl='$hpl' && mfin='$mfin2' order by id desc");
								$n5=mysqli_num_rows($qry5);
						$row5=mysqli_fetch_array($qry5);
					
						$fid = $row5['id'];
		$insert55 = 	mysqli_query($conn, "DELETE FROM pending where hpl='$hpl' && mfin='$mfin2'");
							header("Location:indexsettle1.php?hpl=$hpl&fid=$fid&mfin2=$mfin2");								
							}
								else
								{
									echo "Failure";
								}
							}
?>
	  </div>
</form>
 <?php
$damt = $row['total'];			
	$defamt2 = $row['defamt'];	
	$defamt = (($damt*$defamt2)/100)/30;	
?>			<center><h6><b>Default Per Day : <?php echo round($defamt,0); ?></b></h6></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;	 $sppp = 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 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'];
$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++;
$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;
}
else {	
$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/$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 );
if((($day==30)&&($month==01)) || (($day==29)&&($month==01)) || (($day==31)&&($month==01)))	
{
$duedat = "28-02-".$yyyy;
}
else {	
$duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " 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;?></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 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 = $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 . " 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-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>