<?php include "layouts/menu.php"; ?> 
    <?php $hpl=$_REQUEST['hpl'];?>
 <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 x = document.getElementById("txt1").value; 
var y = document.getElementById("tx2").value; 
document.getElementById("txt2").value =parseInt(((x/100)*0.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 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); 

}
</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 Daily Collection</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 
$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'];
						}
						}
$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)
{
$qry7=mysqli_query($conn, "select * from duedate where mfin='$mfin' &&  hpl='$hpl'");
				
	while($row = mysqli_fetch_array($qry7)) {
	
	$as = "due".$sql6."";
	$duedat = $row[$as];
	}}
	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'];?></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">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">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" 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="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']; ?>" 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">
    </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()">
    </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);
								$insert=mysqli_query($conn, "insert into duser(mfin,scode,hpl,uid,vno,name,no,duedate,bal,dueamount,rno,paydate,paymnt,payyr,dfaultdate,fine,amt,urname,pass)
											 values('$mfin','$scode','$hpl','$hpl','$vno','$name','$no','$duedate','$bal','$dueamount','$rno','$paydate','$paymnt','$payyr','$dfaultdate','$fine','$amt','$urname','$pass')");
								
								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 duser 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 Weekly Due Dates</div>
 <p style="color:red;"><?php
					
						
						$qry=mysqli_query($conn, "select * from duedate where mfin='$mfin' &&  hpl='$hpl'");
						$n=mysqli_num_rows($qry);
						if($n==0)
						{
							echo "Nothing To Display";
						}
						else
					{ 
						?></p>
								<table table border="0" align="center" cellspacing="0" cellpadding="10" width="150">
						
					<?php 
					while($row=mysqli_fetch_array($qry))
						{
						$mnts = $sad;
						$qazq = $sql5+1;
						for($i=1; $i <= $sql5; $i++) {
						$as = "due".$i."";
	                     $duedat = $row[$as];
					?>
					
						<button class="btn btn-warning text-center">
                        <i class="fa  fa-pencil fa-1x"></i><b><?php echo $duedat;?></b>
                    </button><?php }
	                for($i=$qazq; $i <= $mnts; $i++) {
						$as = "due".$i."";
	                     $duedat = $row[$as];
					?>
					
						<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/fooder.php"; ?></div></div>
 <!-- end wrapper -->

    <!-- Core Scripts - Include with every page -->
    <script src="assets/plugins/jquery-1.10.2.js"></script>
    <script src="assets/plugins/bootstrap/bootstrap.min.js"></script>
    <script src="assets/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="assets/plugins/pace/pace.js"></script>
    <script src="assets/scripts/siminta.js"></script>
    <!-- Page-Level Plugin Scripts-->
    <script src="assets/plugins/morris/raphael-2.1.0.min.js"></script>
    <script src="assets/plugins/morris/morris.js"></script>
    <script src="assets/scripts/dashboard-demo.js"></script>

</body>

</html>
