<?php include "layouts/menu.php"; ?> 
    <?php $idd=$_REQUEST['id'];?>
  <?php $mfin2=$_REQUEST['mfin2'];?>
  <!--  page-wrapper -->
  <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: 100%;
    height: 100%;
       border: 4px solid #ff3d39;
    background-color: #69f7db;
	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>

         <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">
                            Customer Details
                        </div>
                        <div class="panel-body">
                            <div class="row">
      <!--  <div id="mydiv">
  <input type="button" value="Print" onclick="PrintElem('#mydiv')"  style="margin:20px;">
   <form name="form1" method="post" action="" enctype="multipart/form-data"> -->
<?php
						$qry=mysqli_query($conn, "select * from customerdetails where id='$idd'");
						$row=mysqli_fetch_array($qry);
						$mfin2 = $row['mfin'];  $hpl = $row['hpl'];
						$qry1=mysqli_query($conn, "select * from user where mfin='$mfin2' &&  hpl='$hpl'");
					$n1=mysqli_num_rows($qry1);
					$row1=mysqli_fetch_array($qry1);
				$remarks = $row['remarks'];
		if($remarks!=NULL){
echo '<script language="javascript">';
echo 'alert("'.$remarks.'")';
echo '</script>'; } 	?>
<div class="col-md-12 div1">
<div class="col-md-3">
<font color="brown" size="3"><b>A/C No : <?php echo $row['hpl'];?></b></font></br>
<?php
$sql22 = mysqli_query($conn, "select * from addr where hpl='$hpl' && mfin='$mfin2' order by id asc");
$row3 = mysqli_fetch_array($sql22);
$nn = mysqli_num_rows($sql22);
$iddf = $row3['id'];

if($nn>0) {

$iddf = $row3['id'];
for($i=1;$i<=7;$i++){
	
$sql223 = mysqli_query($conn, "select * from addr where id='$iddf'");
$row33 = mysqli_fetch_array($sql223); $iddf++;
?>
<b><font size="3" color="blue"><?php echo $row33['addr']; ?></font></b></br>
<?php } }
else { ?>
	<b><font size="3" color="blue">S/O <?php echo $row1['fname']; ?></font></br>
	<b><font size="3" color="blue"><?php echo $row1['address']; ?></font></br>
	<b><font size="3" color="blue"><?php echo $row1['lmark']; ?></font></br>
	
<?php } ?> 
 
 <font color="brown" size="3"><b><u>Co Obligant :</u></b></font></br>
<?php
$sql22 = mysqli_query($conn, "select * from addr where hpl='$hpl' && mfin='$mfin2' order by id asc");
$row3 = mysqli_fetch_array($sql22);
$nn = mysqli_num_rows($sql22);
$iddf = $row3['id'];

if($nn>0) {

$iddf = $row3['id'];
for($i=1;$i<=7;$i++){
	
$sql223 = mysqli_query($conn, "select * from addr where id='$iddf'");
$row33 = mysqli_fetch_array($sql223); $iddf++;
?>
<b><font size="3" color="blue"><?php echo $row33['co']; ?></b></br>
<?php } }
else { ?>
	<b><font size="3" color="blue">S/O <?php echo $row1['fname']; ?> </font> </br>
	<b><font size="3" color="blue"><?php echo $row1['address']; ?> </font> </br>
	<b><font size="3" color="blue"><?php echo $row1['lmark']; ?> </font> 
	
<?php } ?> </font>

</div>



<div class="col-md-2">
<font color="black" size="3"><b>
Hp Date </br>
Hp Amt</br>
Hire Charges</br>
Tot Dues</br>
Due Amt</br>
Principal</br>
Interest</br>
Def % </br>
Broker </br> 
Phone </br>
Veh Value 
</b></font>
</div>

<div class="col-md-2">
<font color="red" size="3"><b>
<?php echo $row['hpdate'];?></br>
<?php echo $row['hpamount'];?></br>
<?php echo $row['hireamt'];?></br>
<?php echo $row['duemnt'];?></br>
<?php echo $row['total'];?></br>
<?php echo $row['dueamt'];?></br>
<?php echo $row['interest'];?></br>
<?php	$defamt2 = $row['defamt'];	
			if($defamt2<1) {
		 	$defamt2 = 	$defamt2 * 12;   
		}
	echo $defamt = (($damt*$defamt2)/100)/30; ?> </br>
<?php echo $row['bname'];?> </br> 
<?php echo $row['pno'];?> </br>
<?php echo $row['vehval'];?>
</b></font>
</div>
<div class="col-md-2">

<font color="black" size="3"><b>
Model </br>
Reg No</br>
Mfg Year</br>
Chasis No</br>
Engine No</br>
Ins date </br>
Remark </br></br>
Mobile No </br>
Promis Date
<?php $imgg = $row['uimg']; 
if($imgg != NULL) { 
?>
<img src="user/<?php echo $row['uimg']; ?>" width="75px" height="75px" >
<?php } ?>
</b></font>
</div>

<div class="col-md-3">

<font color="orange" size="3"><b>
<?php echo $row['vname'];?></br>
<?php echo $row['vno'];?></br>
<?php echo $row['model'];?></br>
<?php echo $row['cno'];?></br>
<?php echo $row['eno'];?></br>
<?php echo $row['idate'];?> </br>
<?php echo $row['remarks'];?></br></br>
<?php echo $row['pnoresi'];?> </br>
-
<?php $imgg = $row['img']; 
if($imgg != NULL) { 
?>
<img src="user/<?php echo $row['img']; ?>" width="75px" height="75px" >
<?php } ?>
</b></font>
<?php if($postt == 'MD')   { ?>
<a href="canled.php?id=<?php echo $row['id'];?>" class="btn btn-primary btn-xs" onclick="return confirm('Are you sure WANT TO CANCEL?');">Cancel</a>
<?php } ?>
</div>

</div>
<div>
 <form name="form1" class="form-horizontal" method="post" action="" enctype="multipart/form-data">
 <textarea cols="9"  rows="2" name="remarks"><?php echo $row['remarks']; ?></textarea>
 <input type="hidden" value="<?php echo $idd; ?>" name="idd">
  <button type="submit" class="btn btn-primary" name="s3">Update</button>
	<?php if(isset($_POST['s3']))
							{
								extract($_POST);  $insert=mysqli_query($conn, "update customerdetails set remarks='$remarks' where id='$idd'");
							header("Location:udelete.php?id=$idd");	}		
								?>
 </form>
</div>
						<div class="">Customer Dues Details</div>
					   <?php
  $rrow4=0; $rrow42=0; $rrow43=0;$rrow44=0;$rrow45=0; $rrow46=0;$rrow47=0;$rrow48=0;
  
  
  									$sql = "SELECT SUM(fine) FROM user where mfin='$mfin2' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql);
                                    $row4 = mysqli_fetch_array($q);	
                                    $rrow4 = $row4[0] + $rrow4;
									$sql = "SELECT SUM(rno) FROM user where mfin='$mfin2' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql);
                                    $row41 = mysqli_fetch_array($q);	
                                    $rrow42 = $row41[0] + $rrow42;
									
									$sql = "SELECT SUM(amt) FROM user where mfin='$mfin2' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql);
                                    $row51 = mysqli_fetch_array($q);	
                                    $rrow43 = $row51[0] + $rrow43;
									
									$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;	
									
									$sql022 = "SELECT SUM(tot) FROM net where mfin='$mfin2' &&  hpl='$hpl'";
                                    $q022 = mysqli_query($conn, $sql022);
                                    $c022 = mysqli_fetch_array($q022);
									$rrow46 = $c022[0] + $rrow46;
									
									$sql0223 = "SELECT SUM(amt) FROM net where mfin='$mfin2' &&  hpl='$hpl'";
                                    $q0223 = mysqli_query($conn, $sql0223);
                                    $c0223= mysqli_fetch_array($q0223);
									$rrow47 = $c0223[0] + $rrow47;
									
									$sql02233 = "SELECT SUM(fine) FROM net where mfin='$mfin2' &&  hpl='$hpl'";
                                    $q02233 = mysqli_query($conn, $sql02233);
                                    $c02234= mysqli_fetch_array($q02233);
									$rrow48 = $c02234[0] + $rrow48;
									
									$rrow49 = $rrow46 - $rrow47 - $rrow48;
									$rrow422 = $rrow42 + $rrow47;
									$rrow433 = $rrow43 + $rrow46;
									 $rrow445= $rrow44 - $rrow45 - $rrow49;
									$rrow4456=(($rrow46-$rrow47) + $rrow45) ;
									 ?>&nbsp;&nbsp;&nbsp;&nbsp;
									<?php 
									echo 'Interest Received: ' . $rrow422;?>&nbsp;&nbsp;&nbsp;&nbsp;
									<?php
									echo 'Fine: ' . $rrow4;?>&nbsp;&nbsp;&nbsp;&nbsp;
									<?php
									echo 'Total Payed Amt: ' . $rrow433;?>&nbsp;&nbsp;&nbsp;&nbsp;
									<?php
									echo 'Total Payed Principal: ' . $rrow4456;?>&nbsp;&nbsp;&nbsp;&nbsp;
									<?php
									echo 'Total OutStanding Balance(principal) : ' . $rrow445;?>&nbsp;&nbsp;&nbsp;&nbsp;
									<?php
									
									
									?>
 <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 Amount</th>
						<!-- <th>Principle</th>
						<th>Interest</th> -->
						<th>Paid Due</th>
						<th>Def Days</th><th>Penalty</th><th>Paid Fine</th>
						<th>Hloan Paid</th>
				
					
						
					</tr></thead>
					<tbody>
		<?php $qdue = 0; $qdue25 = 0;
			$ttp = 0;	$tti  = 0; $ttdue = 0;	$ttdd = 0;	$ttfine = 0;	$ttpf = 0;	$tthl = 0;	
				$tttot = 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 = 1;
 
$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'];
$urname1 = $row5['urname'];
$hloan = $row5['hloan'];
$fine1 = $row5['fine'];
$dmm = $urname1 - $hloan - $fine1;
$rcptno = $row5['roll'];
$fidd = $row5['fid'];
$gi = 0;

	$gi++; $rr++;
$rno1 = $row5['rno'];
$rno = $rno1/$duemnt;
$pass1 = $row5['pass'];

$pass = $pass1/$duemnt;
$urname1 = $row5['urname'];
$hloan = $row5['hloan'];
$fine1 = $row5['fine'];
$urname = $urname1 - $hloan - $fine1;
$urname55 = $urname;
while($dmm>0) {
$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 * $i6; }
if($fine2 < 0) {
	$fine2 = 0;
}
if($qdue>0){ $rg22 = 1;  $urname = $urname - $qdue - $qdue25;
$qdue2 =$qdue - $qdue25;
$qdue = 0;
$qdue25 = 0;
$urname1 = $urname1 - $qdue2;

//echo $dmm;
 $d11 = strtotime($pddate);
$d22 = strtotime($pday);
$min_date1 = min($d11, $d22);
$max_date1 = max($d11, $d22);
$i66 = 0;

while (($min_date1 = strtotime("+1 DAY", $min_date1)) <= $max_date1) {
    $i66++;
}
$fine20 = (($defamt/$damt)*($i66 * $qdue2));
$ttfine = $ttfine + $fine20;
$ttdd = $ttdd + $i66;	//$dmm = $dmm - $qdue2;
if( $qdue2<0) {
	
$urname55 = $urname55 - $dmm -  $urname;
	?>
<tr>
					<td><?php echo $ii; ?></td>
					<td> 
					110<?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 $damt5; ?></td>
				<!--	<td><?php //echo $pass; ?></td>
					<td><?php //echo $rno; ?></td> -->
					<td><?php echo $dmm; ?></td>
				<td><?php echo $i6;?></td>	<td><?php echo round($fine2,0);?></td>	
				<?php if($gi==1) { ?> <td><?php echo $fine1;?></td> <?php } else { ?>
<td></td>
				<?php } ?>
					<td><?php echo $hloan;?></td> 
			
</tr>
<?php $dmm = $dmm - $dmm; } else { ?>
<tr>
					<td></td>
					<td></td>	<td></td>
					<td>1<?php echo $pday; ?></td>
					<td></td>
				<!--	<td><?php //echo $pass; ?></td>
					<td><?php //echo $rno; ?></td> -->
					<td><?php echo $qdue2; ?></td>
				<td><?php echo $i66; ?></td>	
				<td><?php echo round($fine20,0); ?></td>	
				<?php if($gi==1) { ?> <td></td> <?php } else { ?>
<td></td>
				<?php } ?>
					<td></td> 
				
</tr>
<tr>
					<td><?php echo $ii; ?></td>
					<td> 
					11<?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 $damt5; ?></td>
				<!--	<td><?php //echo $pass; ?></td>
					<td><?php //echo $rno; ?></td> -->
					<td><?php echo $urname; ?></td>
				<td><?php echo $i6;?></td>	<td><?php echo round($fine2,0);?></td>	
				<?php if($gi==1) { ?> <td><?php echo $fine1;?></td> <?php } else { ?>
<td></td>
				<?php } ?>
					<td><?php echo $hloan;?></td> 
			
</tr>
<?php }  $ii++;  }



elseif($qdue<0){  $urname = $urname - abs($qdue);
$qdue2 =abs($qdue);
$qdue25 =abs($qdue);
$qdue = 0;
$urname1 = $urname1 - $qdue2;
//$dmm = $dmm - $qdue2 -  $urname;
 $d11 = strtotime($pddate);
$d22 = strtotime($pday);
$min_date1 = min($d11, $d22);
$max_date1 = max($d11, $d22);
$i66 = 0;

while (($min_date1 = strtotime("+1 DAY", $min_date1)) <= $max_date1) {
    $i66++;
}
$fine20 = (($defamt/$damt)*($i66 * $qdue2));
$ttfine = $ttfine + $fine20;
$ttdd = $ttdd + $i66;	
$rg22 = 0;
if($qdue2>$damt) { $dmm = $dmm - $damt;
$urname55 = $urname55 - $damt;
	$qdue = $qdue2 - $damt;
	?>
<tr>
					<td><?php echo $ii; ?></td>
				<td>
					2<?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></td>
				<!--	<td><?php //echo $pass; ?></td>
					<td><?php //echo $rno; ?></td> -->
					<td><?php echo $damt; ?></td>
				<td><?php echo $i66; ?></td>	
				<td><?php echo round($fine20,0); ?></td>	
				<?php if($gi==1) { ?> <td></td> <?php } else { ?>
<td></td>
				<?php } ?>
					<td></td> 
				
</tr> <?php } else { $dmm = $dmm - $qdue2;
$urname55 = $urname55 - $qdue2;
 ?>
<tr>
					<td><?php echo $ii; ?></td>
				<td>
					2<?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></td>
				<!--	<td><?php //echo $pass; ?></td>
					<td><?php //echo $rno; ?></td> -->
					<td><?php echo $qdue2; ?></td>
				<td><?php echo $i66; ?></td>	
				<td><?php echo round($fine20,0); ?></td>	
				<?php if($gi==1) { ?> <td></td> <?php } else { ?>
<td></td>
				<?php } ?>
					<td></td> 
				
</tr> 
<?php } ?>



<?php if($dmm >0){
if($dmm > $damt5){ 
 ?>
<tr>
					<td><?php echo $ii; ?></td>
					<td>
					222<?php $tdue = $urname - $hloan - $fine1; 
					$dmm = $dmm - $damt;
$urname55 = $urname55 - $damt;
					?>
						<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 $damt5; ?></td>
				<!--	<td><?php //echo $pass; ?></td>
					<td><?php //echo $rno; ?></td> -->
					<td><?php echo $damt; ?></td>
				<td><?php echo $i6;?></td>	<td><?php echo round($fine2,0);?></td>	
				<?php if($gi==1) { ?> <td><?php echo $fine1;?></td> <?php } else { ?>
<td></td>
				<?php } ?>
					<td><?php echo $hloan;?></td> 
			
</tr>
<?php   $ii++;  } 
else { ?>
<tr>
					<td><?php echo $ii; ?></td>
					<td>
					22<?php $tdue = $urname - $hloan - $fine1; 
					$dmm = $dmm - $urname;
$urname55 = $urname55 - $urname;
					?>
						<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 $damt5; ?></td>
				<!--	<td><?php //echo $pass; ?></td>
					<td><?php //echo $rno; ?></td> -->
					<td><?php echo $urname; ?></td>
				<td><?php echo $i6;?></td>	<td><?php echo round($fine2,0);?></td>	
				<?php if($gi==1) { ?> <td><?php echo $fine1;?></td> <?php } else { ?>
<td></td>
				<?php } ?>
					<td><?php echo $hloan;?></td> 
			
</tr>
<?php }     } }




 else { 
 $urname = $urname - $qdue - $qdue25;
$qdue2 =$urname - $qdue25;

$rg22 = 1;
$qdue = 0;
$qdue25 = 0;

?>
<tr>
					<td><?php echo $ii; ?></td>
					<td>
					3<?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> -->
					<?php if($urname > $damt){ 
					$dmm = $dmm - $damt;
					$urname55 = $urname55 - $damt;
					?>
					<td><?php echo $damt; ?></td> <?php } else { 
					$dmm = $dmm - $urname;
					$urname55 = $urname55 - $urname;
					?>
					<td><?php echo $urname; ?></td>
					<?php } ?>
				<td><?php echo $i6;?></td>	<td><?php echo round($fine2,0);?></td>	
				<?php if($gi==1) { ?> <td><?php echo $fine1;?></td> <?php } else { ?>
<td></td>
				<?php } ?>
					<td><?php echo $hloan;?></td> 
		
</tr>
<?php  $ii++;  }
//if($duemnt == 1)
//{
	
	$qdue = $damt - $urname55;
	$pddate = $duedat;
//}

$ttp = $ttp + $pass; $tti = $tti + $rno; $ttdue = $ttdue + $urname;	$ttdd = $ttdd + $i6;	
$ttfine = $ttfine + $fine2;	
$ttpf = $fine1 + $ttpf;	$tthl = $tthl + $hloan;	$tttot = $tttot + $urname1;
				
 }
  } 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 $i6;?></td><td><?php echo round($fine2,0);?></td><td>-</td>
					<td>-</td>
			
</tr> 

<?php  $ii++; 
$ttdd = $ttdd + $i6;	
$ttfine = $ttfine + $fine2;	

}  ?>	
<tr>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
					<!--	<td><?php //echo $ttp; ?></td>
					<td><?php //echo $tti; ?></td> -->
						<td><?php echo $ttdue; ?></td>
						<td><?php echo $ttdd; ?></td>
						<td><?php echo $ttfine; ?></td>
						<td><?php echo $ttpf; ?></td>
						<td><?php echo $tthl; ?></td>
				
						
						
					</tr>		
					</tbody></table>
  

					      <?php
						$qry=mysqli_query($conn, "select * from net where mfin='$mfin2' &&  hpl='$hpl'");
						$n=mysqli_num_rows($qry);
						if($n==0)
						{
							echo "Nothing To Display";
						}
						else
					{ 
						?></p>
					<div class="table-responsive">
  <table class="table table-bordered table-hover"><thead>
  <tr class="info">
						<th>Receipt No</th>
						<th>Name</th>
						<th>Loan No</th>
						<th>Duemonth</th>
						<th>Duedate</th>
						<th>Dueamount</th>
						<th>Paid month</th>
						<th>Balance Month</th>
						<th>Total</th>
						<th>Paydate</th>
						<th>Delete</th>
						<th>More Info</th>
					</tr></thead>
					<?php 
					while($row=mysqli_fetch_array($qry))
						{
					?>
					<tbody><tr class="warning">
					
						<td><?php echo $row['rrno'];?></td>
						<td><?php echo $row['name'];?></td>
						<td><?php echo $row['hpl'];?></td>
						<td><?php echo $row['no'];?></td>
						<td><?php echo $row['duedate'];?></td>
						<td><?php echo $row['dueamount'];?></td>
						<td><?php echo $row['paid'];?></td>
						<td><?php echo $row['bmnt'];?></td>
						<td><?php echo $row['tot'];?></td>
						<td><?php echo $row['paydate'];?></td>
						<td><a href="deletecls.php?hpl=<?php echo $row['hpl'];?>&rrno=<?php echo $row['rrno'];?>">Delete</a></td>
						<td><a href="fdelete.php?hpl=<?php echo $row['hpl'];?>&name=<?php echo $row['name'];?>">More Info</a></td>
					</tr></tbody>
					<?php
						}
					}
					?>				
					</table>
						</div > </br> <B><H5>HAND LOAN PAYMENTS</H5></B>
						
						 <div class="table-responsive">
  <table class="table table-bordered table-hover"><thead>
  <tr class="info">
						<th>Date</th>
						
						<th>Type</th><th>Remarks</th>
						<th>Agent</th>
						<th>Credit</th>
						<th>Debit</th>
						
					</tr></thead><tbody>
  
                    <?php
					$cr = 0; $dr = 0;
						$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin2' &&  hpl='$hpl'");
						
						$n=mysqli_num_rows($qry);
						if($n==0)
						{
							
						}
						else
					{ 
						?></p>
					
					<?php 
					while($row=mysqli_fetch_array($qry))
						{ $cr = $cr + $row['hlamt'];
					?>
					<tr class="warning">
					<col width="100px">
						<td><?php echo $row['hpdate'];?></td>
						<td>Receipt</td>
						<td><?php echo $row['hlreturn'];?></td>
						<td>-</td>
						<td><?php echo $row['hlamt'];?></td>
						
						<td></td>
						</tr></tbody>
					<?php
						}
					}
				
						$qry=mysqli_query($conn, "select * from hloan where mfin='$mfin2' &&  hpl='$hpl'");
						
						$n=mysqli_num_rows($qry);
						if($n==0)
						{
							
						}
						else
					{ 
						?></p>
					
					<?php 
					while($row=mysqli_fetch_array($qry))
						{ 
						$ggh = $row['reslt']; if($ggh == NULL) {
						$dr = $dr + $row['actamt2'];
					?>
					<tr class="warning">
					<col width="100px">
						<td><?php echo $row['postdate'];?></td>
						<td>HL-<?php echo $row['reslt'];?></td>
						<td><?php echo $row['remarks'];?></td>
						<td><?php echo $row['agent'];?></td>
						<td></td>
						<td><?php echo $row['actamt2'];?></td>
						
						
						</tr></tbody>
					<?php
						} }
					}
					
					$qry=mysqli_query($conn, "select * from otherentry where mfin='$mfin2' &&  hpl='$hpl'");
						
						$n=mysqli_num_rows($qry);
						if($n==0)
						{
							
						}
						else
					{ 
						?></p>
					
					<?php 
					while($row=mysqli_fetch_array($qry))
						{ $dr = $dr + $row['postamt2'];
					?>
					<tr class="warning">
					<col width="100px">
						<td><?php echo $row['postdate'];?></td>
						<td>OE - <?php echo $row['result'];?></td>
						<td><?php echo $row['remark'];?></td>
						<td><?php echo $row['agentname'];?></td>
						<td></td>
						<td><?php echo $row['postamt2'];?></td>
						
						
						</tr></tbody>
					<?php
						}
					}
				
					$qry=mysqli_query($conn, "select * from user where mfin='$mfin2' &&  hpl='$hpl'");
						
						$n=mysqli_num_rows($qry);
						if($n==0)
						{
							
						}
						else
					{ 
						?></p>
					
					<?php 
					while($row=mysqli_fetch_array($qry))
						{ $vv = $row['hloan'];
					if($vv != NULL) { $cr = $cr + $row['hloan'];
					?>
					<tr class="warning">
						<td><?php echo $row['paydate'];?></td>
						<td>Recpt</td>
						<td></td>
						<td>-</td>
						
						<td><?php echo $row['hloan'];?></td>
						<td></td>
						
						</tr>
					<?php
					} }
					}
				
					?>
					<tr class="succes">
					<col width="100px">
						<td></td>
						<td>Total</td>
						<td></td>
						<td>-</td>
						
						<td><?php echo $cr;?></td>
						<td><?php echo $dr;?></td>
						
						</tr>
						<tr class="warning">
					<col width="100px">
						<td></td>
						<td>Balance</td>
						<td></td>
						<td>-</td>
						<td></td>
						<td><b><h4><?php $ccc = $dr - $cr;  echo $ccc;?></h4></b></td>
						
						
						</tr>
						</tbody>
					</table>
					</form>
					
</div>
</div></div>
		  
		  
		  </div>     </div>
                <!-- end of weather widget -->
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->

        <!-- footer content -->
   
	   <?php include "layouts/footer.php"; ?>
  </body>
</html>
