
<?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));
} 
</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">
                 <!-- page header -->
                <div class="col-lg-12">
                    <h1 class="page-header  alert alert-info">Pay Due for Vehicle Loans</h1>
                </div>
                <!--end page header -->
            </div>
            <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-8">
    <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' order by id desc");
$n5=mysqli_num_rows($qry5);
$row5 = mysqli_fetch_array($qry5);
$qry6=mysqli_query($conn, "select * from roll order by id desc");
$n6=mysqli_num_rows($qry6);
						if($n5==0)
						{
							$fid = 0;
						}
						else
					    {	
						$fidd = $row5['fid'];
						$prno=$row5['fid']+1;
						$fid = $fidd + 1;
						
						}
						$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)
						{
							$sss = 0;
						}
						else
					    {
						while($row=mysqli_fetch_array($qry))
						{
						$sss = $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;
?> 
 <?php
		$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin' &&  hpl='$hpl' order by id desc");		
$row = mysqli_fetch_array($qry);
$tyty=$row['duemnt'];
 $duedat = str_replace('/', '-', $row['hpdate']);
	   $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++;
}
if($sql6<$tyty)
{
$duedat = date("d-m-Y", strtotime("$duedat + " . $sql6 . " month"));	
	}
	else{$duedat = "Account Clossed";}
	$sad = $row['duemnt'];
	?>

	<div class="alert alert-info">Welcome <?php echo $row['name'];?> Fid <?php echo $fid; ?> Receipt <?php echo $prno; ?></div>
	<div class="form-group">
	<img style="margin-left:150px;margin-bottom:20px;" src="user/<?php echo $row['uimg'];?>" height="100" width="100"/>
	<label for="inputPassword3" class="col-sm-2 control-label">HPL</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="inputPassword3" name="hpl" value="<?php echo $row['hpl'];?>" placeholder="E.g 1008" readonly required>
    </div>
	</div>
   <div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Vehicle No</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="inputPassword3" name="vno" value="<?php echo $row['vno'];?>" placeholder="Vehicle No" readonly required>
    </div>
	<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>
 </div>
    <div class="form-group">
	<label for="inputPassword3" class="col-sm-2 control-label">Principal(O/S)</label>
	    <div class="col-sm-4">
		      <input type="text" class="form-control" id="" name="pri" readonly value="<?php echo $rrow445;?>" placeholder="E.g 1008" required>

		</div>
	<label for="inputPassword3" class="col-sm-2 control-label">Default Amt</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>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">HP Amount</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="inputPassword3"  name="hpamount" value="<?php echo $row['hpamount'];?>" placeholder="E.g 1008" readonly required>
    </div>
	 <label for="inputPassword3" class="col-sm-2 control-label">HP Date</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="inputPassword3" name="hpdate" value="<?php echo $row['hpdate'];?>" readonly placeholder="Vehicle No" required>
    </div>
	</div>
 <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Name</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="inputPassword3" name="name" value="<?php echo $row['name'];?>" readonly placeholder="" required>
    </div>
  	
  
    <label for="inputEmail3" class="col-sm-2 control-label">Due Month</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="duemonth" name="no" value="<?php echo $row['duemnt']; ?>" readonly placeholder=""> 
    </div>
 </div>
 
  <?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">DueAmount w/t intr</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 class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Paid Months Before</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="qx" name="pavbd"  value="<?php echo $sql5;?>" placeholder="Dont give any values" >
    </div>
 
    <label for="inputPassword3" class="col-sm-2 control-label">Paid Months Now</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="ax" name="payyr"  value="" onclick="nnow()">
    </div>
  </div>
  <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="" 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="balance"  name="nname" value="<?php echo $nname; ?>" placeholder=""  onclick="sum()">
    </div>
 
 
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-warning btn-lg btn-block" name="s1">Register Due</button>
    </div>
  </div>
      <div class="alert alert-success">
	<?php
							if(isset($_POST['s1']))
							{
								extract($_POST);
								$duemnt2 = $no;
								$hpamt = $hpamount;
								$insert=mysqli_query($conn, "insert into user(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('$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 class="col-xs-6 col-md-4">
 <div class="alert alert-warning"><?php echo "Total Paid Due  ".$sql5;?></div>
 <!-- <div class="alert alert-success">INSURANCE FC TAX DATES</div>
  <?php
					
						
						$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin' &&  hpl='$hpl'");
						$n=mysqli_num_rows($qry);
						if($n==0)
						{
							echo "Nothing To Display";
						}
						else
					{ 
					
	
					while($row=mysqli_fetch_array($qry))
						{ 
						
						$id = $row['idate'];
						$ud = $row['uname'];
						$pd = $row['pwd'];}
						$idd = date("d-m-Y", strtotime("$id + " . 12 . " month"));
						$udd = date("d-m-Y", strtotime("$ud + " . 12 . " month"));
						$pdd = date("d-m-Y", strtotime("$pd + " . 12 . " month"));
			
						if(strtotime($idd) <= strtotime("now"))
						{
						echo "INSURANCE DATE";
						echo '<center><div><font size="6" color="red">'.$id.'</font></div></center>';					
						}
						else
						{
						echo "INSURANCE DATE"; 
						echo '<center><div><font size="6" color="green">'.$id.'</font></div></center>';

						}
							if(strtotime($udd) <= strtotime("now"))
						{
						echo "FC DATE";
						echo '<center><div><font size="6" color="red">'.$ud.'</font></div></center>';						
						}
						else
						{echo "FC DATE";
						echo '<center><div><font size="6" color="green">'.$ud.'</font></div></center>';

						}
							if(strtotime($pdd) <= strtotime("now"))
						{
						echo "TAX DATE";
						echo '<center><div><font size="6" color="red">'.$pd.'</font></div></center>';					
						}
						else
						{
						echo "TAX DATE";
						echo '<center><div><font size="6" color="green">'.$pd.'</font></div></center>';

						}
												
						} ?>-->
						<div class="alert alert-info">Other Due Details</div>
				 <?php
					
						$qry=mysqli_query($conn, "select * from customer where mfin='$mfin' &&  hpl='$hpl'");
						$n=mysqli_num_rows($qry);
						$qry2=mysqli_query($conn, "select * from net2 where mfin='$mfin' &&  hpl='$hpl'");
						$nn=mysqli_num_rows($qry2);
						if($n==0)
						{
							echo "Nothing To Display";
						}
						elseif($nn==0)
					{ 
						?>
					<table table class="table" border="0" align="center" cellspacing="0" cellpadding="10" width="50%" style="table-layout: fixed;">
					<col width="50px">
						<tr class="danger" style="color:purple;">
						<th>Name</th>
						<th></th>
						<th>Loan No</th>
						<th>Amount</th>
					</tr>
					<?php 
					$row=mysqli_fetch_array($qry)
					?>
					<tr class="warning">
					<col width="100px">
						<td><?php echo $row['name'];?></td>
						<td></td>
						<td><?php echo $row['hpl'];?></td>
						<td><?php echo $row['hpamount'];?></td>
						</tr>
					<?php
					}
				else
				{
				echo "Due Closssed";
				}
					?>
					</table>
<div class="alert alert-info">Your Monthly Due Dates</div>
 <p style="color:red;"><?php
					
						
						$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin' &&  hpl='$hpl'");			
	while($row = mysqli_fetch_array($qry)) {
	   $duedat = str_replace('/', '-', $row['hpdate']);
						$pp = $row['duemnt'];
						$addr = $row['address'];
						
						}
	
  $d1 = strtotime($duedat);
$d2 = strtotime("today");
$min_date = min($d1, $d2);
$max_date = max($d1, $d2);
$i = 0;
while (($min_date = strtotime("+1 MONTH", $min_date)) <= $max_date) {
    $i++;
}
if($i>$pp)
{ $i=$pp; }
$rc = $i - $sql5 ;
$sql9 = $sql5 + $rc ;
echo $rc;

				
						?></p>
			<table table border="0" align="center" cellspacing="0" cellpadding="10" width="150">
						
					<?php 
					for($y=0;$y<$sql5;$y++)
						{
						$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><?php 
					}
	                for($j=1; $j <= $rc; $j++) {
						$duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " month"));
					?>
					
						<button class="btn btn-danger text-center">
                        <i class="fa  fa-pencil fa-1x"></i><b><?php echo $duedat;?></b>
                    </button>
						<?php
						}
					for($j=$sql9; $j < $sad; $j++) {
						$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>
						<?php
						}
					?>
					</table>
					<div class="alert alert-success">Customer Address</div>
					<font size="3" color="green"><strong><?php echo $addr;?></strong></font>
</div>
</div></div>
</div></div></div>  </body></html>