<?php include "layouts/menu.php"; ?> 
    <?php $hpl=$_REQUEST['hpl'];?>
  <!--  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">Chasing for vehicle Loan</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">
                            Details
                        </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	$qry=mysqli_query($conn, "select * from net");
						$n=mysqli_num_rows($qry);
						if($n==0)
						{
							$rty = 1;
						}
						else
					    {
						while($row=mysqli_fetch_array($qry))
						{
						$sss = $row['rno'];
						}
						$rty = $sss + 1;
						} ?>	
	<?php
	$x=$hpl; 
  $qry2 = "SELECT * FROM customerdetails where mfin='$mfin' &&  hpl='$x'";
  $result = mysqli_query($conn, $qry2);
	if (mysqli_num_rows($result) >= 1) 
				{ 
	  $rs = mysqli_query($conn, $qry2);
	  // Loop the recordset $rs
	// Each row will be made into an array ($row) using mysqli_fetch_array
	while($row2 = mysqli_fetch_array($rs)) {

	    $row2 = str_replace('/', '-', $row2['hpdate']);
  $d1 = strtotime($row2);
$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++;
}}
$qry=mysqli_query($conn, "select * from user where mfin='$mfin' &&  hpl=$x");
$nn=mysqli_num_rows($qry);
$e = $i - $nn;
			
				}
				$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin' &&  hpl='$hpl'");
				$query=mysqli_query($conn, "select * from user where mfin='$mfin' &&  hpl='$hpl'");
				$row=mysqli_fetch_array($qry);
				$row1=mysqli_fetch_array($query);
				$pp = $row['duemnt'];
			$sad = $row['duemnt'];

$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;


?> 

	<div class="alert alert-info">Welcome <?php echo $row['name'];?></div>
	<img style="margin-left:150px;margin-bottom:20px;"" src="user/<?php echo $row['uimg'];?>" height="100" width="100"/>
   <div class="form-group">
    <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" required>
    </div>
    <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'];?>" placeholder="" required>
    </div>
  </div>	
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Due Month</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="no" name="no" value="<?php echo $pp; ?>" placeholder=""> 
    </div>
    <label for="inputPassword3" class="col-sm-2 control-label">H.p Date</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="gh" name="duedate" value=" <?php echo $row['hpdate'];?>" placeholder="Due Date" onfocus="insertDate(this,'<?php echo $row['hpdate'];?>--/MM/YYYY')">
    </div>
  </div>
    <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Due Amount</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="t1" name="dueamount" value="<?php echo $row['total'];?>" placeholder="Due Amount">
    </div>
  
    <label for="inputPassword3" class="col-sm-2 control-label">Paid Month</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="t2" name="paid" value="<?php echo $sql5;?>" placeholder="Paid Month">	   
    </div>
  </div>
 <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Total Amount Paid</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="totam" name="tamount" value="" placeholder="Total Amount" onclick="add1()">

    </div>
    <label for="inputPassword3" class="col-sm-2 control-label">H.P Amount</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="1" name="dueamt" value="<?php echo $row['hpamount'];?>" placeholder="H.P Amount">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Chasing Date</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="bm1" name="bmnt"  value="" placeholder="Pay Date" onfocus="insertDate(this,'DD-MM-YYYY')">
    </div>
   
    <label for="inputPassword3" class="col-sm-2 control-label">Interest(total)</label>
    <div class="col-sm-4">
    <input type="text" class="form-control" id="int3" name="amt" value="" placeholder="Amount" onclick="adds()">
    </div>
    </div>
	
       <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Total(Amount)</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="totot" name="tot" value="" placeholder="Total" onclick="addss()">
	  	  	  
    </div>
    <label for="inputPassword3" class="col-sm-2 control-label">Recipt Number</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="inputPassword3" name="rno" value="<?php echo $rty;?>" placeholder="Recipt Number">
    </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="datepicker" name="paydate"  value="" placeholder="Pay Date" onfocus="insertDate(this,'<?php echo"Account Closed";?>-DD/MM/YYYY')">
    </div>
  </div>
    
        <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-primary  btn-lg btn-block" name="s11">Register</button>
    </div>
  </div>
													<div class="alert alert-warning">
							<?php
							if(isset($_POST['s11']))
							{
								extract($_POST);
								$insert=mysqli_query($conn, "insert into vnet(hpl,name,no,duedate,dueamount,paid,tamount,dueamt,amt,bmnt,tot,rno,paydate)
											 values('$mfin','$scode','$hpl','$name','$no','$duedate','$dueamount','$paid','$tamount','$dueamt','$amt','$bmnt','$tot','$rno','$paydate')");
								$update=mysqli_query($conn, "update user set duedate='$paydate' where mfin='$mfin' &&  hpl=$hpl");
								if($insert&&$update)
								{
									
									echo "Registered Successfully";
								
								}
								else
								{
									echo "Failure";
								}
							}		
							
						   
								
?>	
	  </div>
</form>
</div>
 <div class="col-xs-6 col-md-4">
 <div class="alert alert-info">Get user paid details</div>
  <form name="form2" class="form-horizontal" method="post" action="" enctype="multipart/form-data">
  <div class="form-group">
    Actual Interest
    <div class="col-sm-4">
      <b><p style="color:red;"><?php echo $row['inter'];?>%</b>
    </div>
  </div>
  <div class="form-group">
    <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="uid"  value="<?php echo $row['hpl'];?>" placeholder="Enter HPL">
    </div>
  </div>
  
        <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-primary" name="s2">Get Month</button>
    </div>
  </div>
      <div class="alert alert-success">
	  <?php
							if(isset($_POST['s2']))
							{
								extract($_POST);
								$qry=mysqli_query($conn, "select * from user where mfin='$mfin' &&  uid='$uid'");
								$n=mysqli_num_rows($qry);
								if($n==0)
									{
										echo"Noting he has to pay";
									}
								else		
									{
										$aa = $n;
										echo"$n months";
										
									}
							}			
							
						   
								
?><div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
     <i class="fa fa-edit fa-fw"></i><a  href="netamtd.php?hpl=<?php echo $hpl?>"><b>Via Balance Dues</b></a>
    </div>
  </div>

	  </div>
</form>
  <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']);}
						?></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-warning text-center">
                        <i class="fa  fa-pencil fa-1x"></i><b><?php echo $duedat;?></b>
                    </button><?php }
	                for($i=$sql6; $i <= $sad; $i++) {
						$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>
</div></div>
</div></div></div> <?php include "layouts/footer.php"; ?></body></html>