<?php include "layouts/menu.php"; ?>
    <?php  $fid=$_REQUEST['fid'];
 $qry4=mysqli_query($conn, "select * from net where id='$fid'");
$row=mysqli_fetch_array($qry4);
$hpl = $row['hpl']; ?>
	<?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:#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>


  <!--  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
 $fid=$_REQUEST['fid'];
 $qry4=mysqli_query($conn, "select * from net where id='$fid'");
$row=mysqli_fetch_array($qry4);
$hpl = $row['hpl'];
$mfin2 = $row['mfin'];
 $qry22=mysqli_query($conn, "select * from customerdetails where hpl='$hpl' && mfin='$mfin'");
$row22=mysqli_fetch_array($qry22);
?>


<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 " readonly id="inputPassword3" name="hpl" width="48" 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">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=""  >  
    </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="rrno" value="<?php echo $row['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 $row['paydate'];?>" 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">Party Name</label>
    <div class="col-sm-4">
     <input type="text" class="form-control" style="width:170px; height:29px " readonly 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="text" class="form-control" id="dueamt" name="dueamt" value="<?php echo $row['dueamt'];?>" placeholder="" onkeyup="add02()" required>  
</div>
<label for="inputPassword3" class="col-sm-2 control-label">Interest</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="amt" name="amt" value="<?php echo $row['amt'];?>" 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">

<a href="viewhl.php?hpl=<?php echo $hpl; ?>" 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 $row['hloan'];?>" 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="hloanrmk" value="<?php echo $row['hloanrmk'];?>" 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 $row['fine'];?>" 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" readonly name="urname" value="<?php echo $row['tot'];?>" 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="<?php echo $row['addless'];?>"  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="<?php echo $row['remarks'];?>" 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><?php echo $row['mode'];?></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 $row22['hpamount']; ?> / <?php echo $row22['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 $row22['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);
								
								date_default_timezone_set('Asia/Kolkata');
$date = date('h:i:s a m/d/y');
$ddate =  date('h:i:s a m/d/y', strtotime($date));
$ddate2 =  date('Y-m-d', strtotime($paydate));
$insert = mysqli_query($conn, "update net set rrno='$rrno',rno='$rrno',mode='$mode',addless='$addless',amt='$amt',dueamt='$dueamt',fine='$fine',hloan='$hloan',paydate='$paydate',bmnt='$paydate',paydate2='$ddate2',hloanrmk='$hlrmk',remarks='$remarks',altby='$scode',altdate='$ddate' where id='$fid'");
	if($insert)
								{
								//	$sql1 = mysqli_query($conn, "select sum(pass) from user where mfin='$mfin' &&  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('$mfin','$scode','$hpl','$paydate')");
										
									//}
									echo "Registered Successfully";
														
							}
								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>