<?php include "layouts/menu.php"; ?>
    <?php $hpl=$_REQUEST['hpl'];?>
	<?php /*$vno=$_REQUEST['vno'];*/?>
  <!--  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 
$qry5=mysqli_query($conn, "select * from vuser where mfin='$mfin'");
$n5=mysqli_num_rows($qry5);
						if($n5==0)
						{
						$fid = 0;
						}
						else
					    {
						while($row5=mysqli_fetch_array($qry5))
						{
						$fidd = $row5['fid'];
						}
						$fid = $fidd + 1;
						}
$qry=mysqli_query($conn, "select * from vuser 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'];
						}
						}
$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'");
				
	while($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++;
}}if($sql6<$tyty)
{
$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin' &&  hpl='$hpl'");			
	while($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'];
	?>

	<div class="alert alert-info">Welcome <?php echo $row['name'];?> Fid <?php echo $fid; ?></div>
	<div class="form-group">
	<img style="margin-left:150px;margin-bottom:20px;"" src="user/<?php echo $row['uimg'];?>" height="100" width="100"/>
	</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="hpl" value=" <?php echo $row['hpl'];?>" placeholder="E.g 1008" required>
    </div>
  
  
    <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" 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'];?>" placeholder="" required>
    </div>
    <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="<?php echo date("d-m-Y"); ?>" placeholder="Pay Date" onfocus="insertDate(this,'DD-MM-YYYY')">
    </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="txt1" name="rno"  value="<?php echo $sss;?>" >
    </div>


  
    <label for="inputPassword3" class="col-sm-2 control-label">Credit-Pay</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="txt2" name="dfaultdate" value="" placeholder="">

    </div>
	</div>
   <div class="form-group">
 
    <label for="inputPassword3" class="col-sm-2 control-label">Debit-give</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="txt3" name="fine" value="" placeholder="">

    </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()">
    </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="s4">Register Due</button>
    </div>
  </div>
      <div class="alert alert-success">
	 <?php
							if(isset($_POST['s4']))
							{
								extract($_POST);
								$insert=mysqli_query($conn, "insert into vuser(hpl,vno,name,bal,paydate,dfaultdate,fine,amt,urname,rno)
											 values('$mfin','$scode','$hpl','$vno','$name','$bal','$paydate','$dfaultdate','$fine','$amt','$urname','$rno')");
								
								if($insert)
								{
									
									echo "Registered Successfully";
									
								}
								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 customerdetails where mfin='$mfin' &&  hpl='$hpl'");
						$n=mysqli_num_rows($qry);
						$qry2=mysqli_query($conn, "select * from net 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>Hpl</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">Monthly 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>Hpl</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']);}
						?></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>