<?php include "layouts/menu.php"; ?>
    <?php $hpl=$_REQUEST['hpl'];?>
	<?php /*$vno=$_REQUEST['vno'];*/?>
	 
	 <script> 
function add() 
{ 
var x = document.getElementById("txt1").value; 
var y = document.getElementById("txt2").value; 
var z = document.getElementById("obc").value; 
var w = document.getElementById("jkjk").value;
document.getElementById("tot").value =((x*w)+(y*1)+(z*1)); 
} 

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

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

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

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

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

    var one_day=1000*60*60*24;

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

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

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

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

    var one_day=1000*60*60*24;

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

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

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

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

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

    var one_day=1000*60*60*24;

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

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

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

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

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

    var one_day=1000*60*60*24;

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

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

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

      // Convert back to days and return

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


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

    var one_day=1000*60*60*24;

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

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

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

      // Convert back to days and return

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


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

    var one_day=1000*60*60*24;

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

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

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

      // Convert back to days and return

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


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

    var one_day=1000*60*60*24;

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

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

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

      // Convert back to days and return

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

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

    var one_day=1000*60*60*24;

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

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

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

      // Convert back to days and return

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

    var one_day=1000*60*60*24;

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

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

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

      // Convert back to days and return

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

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

    var one_day=1000*60*60*24;

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

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

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

      // Convert back to days and return

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

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

    var one_day=1000*60*60*24;

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

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

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

      // Convert back to days and return

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

    var one_day=1000*60*60*24;

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

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

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

      // Convert back to days and return

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

    var one_day=1000*60*60*24;

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

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

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

      // Convert back to days and return

		document.getElementById("tx2").value =  Math.round(difference_ms/one_day)+(Math.round(difference_ms/one_day)-30)+(Math.round(difference_ms/one_day)-60)+(Math.round(difference_ms/one_day)-90)+(Math.round(difference_ms/one_day)-120)+(Math.round(difference_ms/one_day)-150)+(Math.round(difference_ms/one_day)-180)+(Math.round(difference_ms/one_day)-210)+(Math.round(difference_ms/one_day)-240)+(Math.round(difference_ms/one_day)-270)+(Math.round(difference_ms/one_day)-300)+(Math.round(difference_ms/one_day)-330); 
}
}
</script>
  <!--  page-wrapper -->
         <div class="right_col" role="main">
         
            <div class="row">
                <div class="col-lg-12">
                    <!-- Form Elements -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Pay Due
                        </div>
                        <div class="panel-body">
                            <div class="row">
  <div class="col-xs-12 col-md-12"> 
    <form name="form1" class="form-horizontal" method="post" action="" enctype="multipart/form-data">

<?php $rrow44=0;$rrow45=0;
										
									$sql = "SELECT SUM(hpamount) FROM customerdetails where mfin='$mfin' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql);
                                    $row52 = mysqli_fetch_array($q);	
                                    $rrow44 = $row52[0] + $rrow44;								
									
									$sql = "SELECT SUM(pass) FROM user where mfin='$mfin' &&  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 where mfin='$mfin'");
$n5=mysqli_num_rows($qry5);
$qry6=mysqli_query($conn, "select * from roll");
$n6=mysqli_num_rows($qry6);
						if($n5==0)
						{
							$fid = 0;
						}
						else
					    {
						while($row5=mysqli_fetch_array($qry5))
						{
							
						$fidd = $row5['fid'];
						$prno=$row5['fid']+1;
						}
						$fid = $fidd + 1;
						
						}
						while($row6=mysqli_fetch_array($qry6))
							{
							$rrno2 = $row6['rno'];
						}  $rrno = $rrno2 + 1;
						
$qry=mysqli_query($conn, "select * from user where mfin='$mfin' &&  hpl='$hpl'");
						$n=mysqli_num_rows($qry);
						
						if($n==0)
						{
						$qryy=mysqli_query($conn, "select * from customer where mfin='$mfin' &&  hpl='$hpl'");
                          $row2=mysqli_fetch_array($qryy);
							$sss = 0;
						}
						else
					    {
						while($row=mysqli_fetch_array($qry))
						{
						$sss = $row['bal'];
						$newsss = $row['bal'];
						}
						}
$sql1 = "select sum(paymnt) from user where mfin='$mfin' &&  hpl='$hpl'";
$qt = mysqli_query($conn, $sql1);
$row1 = mysqli_fetch_array($qt);
$sql5=$row1[0];
$sql6=$sql5 + 1;
$nuserpay = $sql5;

$sql155 = "select sum(actamt2) from hloan where mfin='$mfin' &&  hpl='$hpl'";
$qt55 = mysqli_query($conn, $sql155);
$row155 = mysqli_fetch_array($qt55);
$hlbal2=$row155[0];

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

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

?> 
 <?php
		$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin' &&  hpl='$hpl'");		
	$row = mysqli_fetch_array($qry);
$tyty=$row['duemnt'];
	   $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++;
}
$iii = $i;
if($sql6<$tyty)
{
$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin' &&  hpl='$hpl'");			
$row = mysqli_fetch_array($qry);
	   $duedat = str_replace('/', '-', $row['hpdate']);
$duedat = date("d-m-Y", strtotime("$duedat + " . $sql6 . " month"));	
	}
	else{$duedat = "Account Clossed";}
$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin' &&  hpl='$hpl'");
$row=mysqli_fetch_array($qry);
	$sad = $row['duemnt'];
$dd = $row['uimg'];	?>

	  <div class="col-md-12">
	<div class="col-md-6"><table border="0"><tr><td><h5><b>HPL&nbsp;&nbsp;</b></h5></td><td><b><h5><?php echo $row['hpl'];?></h5></b></td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><h5><b>Vehicle No&nbsp;&nbsp;</b></h5></td><td><h5><b><?php echo $row['vno'];?></b></h5></td>
	<td><h5><b>Principle OS&nbsp;&nbsp;</b></h5></td><td><h5><b><?php echo $rrow445;?></b></h5></td>
	</tr>
	<tr><td><h5><b>HP Amount&nbsp;&nbsp;</b></h5></td><td><h5><b><?php echo $row['hpamount'];?></b></h5></b></td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><h5><b>Name&nbsp;&nbsp;</td><td><h5><b><?php echo $row['name'];?> - <?php echo $row['duemnt'];?> Dues&nbsp;&nbsp;</b></h5></td></tr>
</table> </div>
	<div class="col-md-6"> 
	<?php if($dd != NULL) { ?>
	<img style="margin-left:150px;margin-bottom:20px;" src="user/<?php echo $row['uimg'];?>" height="50" width="50"/></div>
	</div><?php } else { ?>
		<img style="margin-left:150px;margin-bottom:20px;" src="ii.png" height="50" width="50"/></div>
	  </div> <?php
	} ?>

	
      <input type="hidden" class="form-control" id="inputPassword3" name="hpl" value="<?php echo $row['hpl'];?>" placeholder="E.g 1008" readonly required>
 <div class="col-md-12">
	<div class="col-md-6">
   <div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Receipt No</label>
    <div class="col-sm-4">
     <input type="text" class="form-control" id="inputPassword3" name="roll" value="<?php echo $rrno;?>" placeholder=""  required>  
    </div>
	<label for="inputPassword3" class="col-sm-2 control-label">Default/day</label>
    <div class="col-sm-4">
    
  <input type="text" class="form-control" id="dqw" name="amtr" value="3" placeholder="E.g 1008" required>   
   </div>
 </div>
<input type="hidden" class="form-control" id="" name="pri" readonly value="<?php echo $rrow445;?>" placeholder="E.g 1008" required>
<input type="hidden" class="form-control" id="inputPassword3" name="vno" value="<?php echo $row['vno'];?>" placeholder="Vehicle No" readonly required>
      <input type="hidden" class="form-control" id="inputPassword3"  name="hpamount" value="<?php echo $row['hpamount'];?>" placeholder="E.g 1008" readonly required>
      <input type="hidden" class="form-control" id="inputPassword3" name="hpdate" value="<?php echo $row['hpdate'];?>" readonly placeholder="Vehicle No" required>
      <input type="hidden" class="form-control" id="inputPassword3" name="name" value="<?php echo $row['name'];?>" readonly placeholder="" required>
      <input type="hidden" class="form-control" id="duemonth" name="no" value="<?php echo $row['duemnt']; ?>" readonly placeholder=""> 

 
  <?php
				$qry=mysqli_query($conn, "select * from net where mfin='$mfin' &&  hpl='$hpl'");
	$n=mysqli_num_rows($qry);
						
						if($n==0)
						{?>
 <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Due Date</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="dd" name="duedate" value="<?php echo $duedat;?>" placeholder="Due Date">
      <input type="hidden" class="form-control" id="dd" name="duedate1" value="<?php echo $duedat;?>" placeholder="Due Date">
    </div>
  <?php }
   else
{?>
<div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Due Date</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="dd" name="duedate" value="<?php echo "Account Clossed";?>" placeholder="Due Date">
    </div><?php
}   ?>
    
    <label for="inputPassword3" class="col-sm-2 control-label">Due Amount</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="txt1" name="dueamount" value="<?php echo $row['total'];?>" placeholder="Due Amount">
    </div>
	
</div>
<div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Interest</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="rno" name="rno" value="<?php echo $row['interest'];?>" placeholder="Recipt Number">
    </div>
	   <label for="inputPassword3" class="col-sm-2 control-label">Principal</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="asa" name="pass" value="<?php echo $row['dueamt'];?>" placeholder="" required>
    </div>
  </div>
  
   <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Pay Date</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="kk" name="paydate"  value="" placeholder="Pay Date" onfocus="insertDate(this,'DD-MM-YYYY')">
    </div>
 
    <label for="inputPassword3" class="col-sm-2 control-label">Pay Months</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="jkjk" name="paymnt"  value="1" onchange="asal()">
    </div>
  </div>
  </div>
	<div class="col-md-6">
      <input type="hidden" class="form-control" id="qx" name="pavbd"  value="<?php echo $sql5;?>" placeholder="Dont give any values" >
      <input type="hidden" class="form-control" id="ax" name="payyr"  value="" onclick="nnow()">
   
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Old Balance</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="obc" name="obc"  value="<?php echo $sss;?>" >
    </div>


  
    <label for="inputPassword3" class="col-sm-2 control-label">D-fault Day</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="tx2" name="dfaultdate" value="" placeholder="DfaultDay" onclick="diff()">

    </div>
	</div>
   <div class="form-group">
 
    <label for="inputPassword3" class="col-sm-2 control-label">Penalty</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="txt2" name="fine" value="" placeholder="Penalty" onclick="add1()">

    </div>
  
    <label for="inputPassword3" class="col-sm-2 control-label">Payable Amount</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="tot" name="amt" value="" STYLE="color: #ff5521; font-family: Verdana; font-weight: bold; font-size: 14px; background-color: #9bc7ef;"  placeholder="Amount"  onclick="add()">
    </div>
 </div>
   <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Payment</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="payment" name="urname" value="" placeholder="" required>

	</div>
 
    <label for="inputPassword3" class="col-sm-2 control-label">Balance</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="balance"  name="bal" value="" placeholder=""  onclick="sum()">
	    <input type="hidden" class="form-control" id="balance7"  name="nname" value="<?php echo $nname; ?>" placeholder=""  onclick="sum()">
    </div>
 
 
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">HL BALANCE</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;"  id="hlbal" name="hlbal" value="<?php echo $hlbal; ?>" placeholder="" required></a>

	</div>
 
    <label for="inputPassword3" class="col-sm-2 control-label">HL PAYMENT</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="hloan"  name="hloan" value="" placeholder="" >
	       </div>
 
 
  </div>
 
 
   </div> 
      <button type="submit" class="btn btn-warning btn-block" name="s1">Register Due</button>
       <div>
	<?php
							if(isset($_POST['s1']))
							{
								extract($_POST);
								$duemnt2 = $no;
								$hpamt = $hpamount;
								$insert=mysqli_query($conn, "insert into user(hlbal,hloan,mfin,scode,hpl,uid,vno,name,no,duedate,duedate1,bal,dueamount,rno,paydate,paymnt,payyr,dfaultdate,fine,amt,urname,pass,paybefore,roll,pri,nname)
											 values('$hlbal','$hloan','$mfin','$scode','$hpl','$hpl','$vno','$name','$no','$duedate','$duedate1','$bal','$dueamount','$rno','$paydate','$paymnt','$payyr','$dfaultdate','$fine','$amt','$urname','$pass','$pavbd','$roll','$pri','$nname')");
								$insert=mysqli_query($conn, "insert into roll(rno)value('$roll')");
								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";
								$qry5=mysqli_query($conn, "select * from user");
								$n5=mysqli_num_rows($qry5);
						if($n5==0)
						{
						$fid = 0;
						}
						else
					    {
						while($row5=mysqli_fetch_array($qry5))
						{
						$fid = $row5['fid'];
						}
						}	
							header("Location:search6.php?hpl=$hpl&fid=$fid");								}
								else
								{
									echo "Failure";
								}
							}
?>
	  </div>
</form>
</div></div>
 <div class="col-xs-12 col-md-12">
 <table id="datatable-buttons" id="datatable-buttons" class="table table-striped table-bordered">
					<thead>
						<tr>
						<th>Due</th>
						<th>Due Date</th>
						<th>Due Amount</th>
						<th>Principle</th>
						<th>Interest</th>
						<th>Penalty</th>
						<th>Hloan</th>
						<th>Total</th>
						<th>--</th>
						
					</tr></thead>
					<tbody>
		<?php
					
						
						$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin' &&  hpl='$hpl'");			
$row = mysqli_fetch_array($qry);
	   $duedat = str_replace('/', '-', $row['hpdate']);
						$pp = $row['duemnt'];
						$addr = $row['address'];
			$damt = $row['total'];		
$intt = $row['inter'];
$prin = $row['dueamt'];			
	
  $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='$mfin' && hpl='$hpl'");			
while($row5 = mysqli_fetch_array($qry5)) { $rr = 0;
$duemnt = $row5['paymnt'];
while($rr<$duemnt) { $rr++;
$rno1 = $row5['rno'];
$rno = $rno1/$duemnt;
$pass1 = $row5['pass'];
$pass = $pass1/$duemnt;
$urname1 = $row5['urname'];
$hloan = $row5['hloan'];
$fine1 = $row5['fine'];
$urname = ($urname1 - $hloan - $fine1) /$duemnt;
?>
<tr>
					<td><?php echo $ii; ?></td>
					<td><?php $duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " month")); ?>
					
						<button class="btn btn-success text-center">
                        <i class="fa  fa-pencil fa-1x"></i><b><?php echo $duedat;?></b>
                    </button></td>
					<td><?php echo $damt; ?></td>
					<td><?php echo $pass; ?></td>
					<td><?php echo $rno; ?></td>
					<td><?php echo $fine1;?></td>
					<td><?php echo $hloan;?></td>
					<td><?php echo $urname;?></td>
<td>-</td></tr> <?php $ii++; } } while($ii<=$pp) {  ?>
<tr>
					<td><?php echo $ii; ?></td>
					<td><?php $duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " month")); ?>
					
						<button class="btn btn-info text-center">
                        <i class="fa  fa-pencil fa-1x"></i><b><?php echo $duedat;?></b>
                    </button></td>
					<td><?php echo $damt; ?></td>
					<td><?php echo $prin; ?></td>
					<td><?php echo $intt; ?></td>
					<td>-</td>
					<td>-</td>
					<td>-</td>
<td>-</td></tr> 

<?php  $ii++; }  ?>				
					</tbody></table>
					
</div>
</div></div>
</div></div></div> <?php include "layouts/footer.php"; ?> </body></html>