<?php ob_start(); ?>
<!DOCTYPE html>
<html>

<?php include "layouts/db_connect.php";
error_reporting(0);
date_default_timezone_set('Africa/Lagos');
 ?>

   <?php $hpl=$_REQUEST['hpl'];?>
   <script> 
function add() 
{ 
var x = document.getElementById("int2").value; 
var y = document.getElementById("t2").value; 
var z = document.getElementById("1").value;
var w = document.getElementById("totam").value;
var a = document.getElementById("jaf").value;
document.getElementById("totot").value =(x*1)*(y*1)+(z*1)-(w*1)+(a*1); 
} 
</script>
<script> 
function add1() 
{ 
var x = document.getElementById("t1").value; 
var y = document.getElementById("t2").value; 
document.getElementById("totam").value =(x*1)*(y*1); 
} 
</script>
<script>
function add2()
{
var x1 = document.getElementById("1").value;
var y1 = document.getElementById("2").value;
document.getElementById("int2").value =(x1*1)*(y1/100);
}
</script>
<script> 
function add3() 
{ 
var x = document.getElementById("no").value; 
var y = document.getElementById("t2").value; 
document.getElementById("bm1").value =(x*1)-(y*1); 
} 
</script>
<script> 
function add4() 
{ 
var x = document.getElementById("totot").value; 
var y = document.getElementById("bm1").value; 
document.getElementById("tamt").value =(x*1)*(y*1); 
} 
</script>
<script> 
function qqq() 
{ 
var x = document.getElementById("2").value; 
var y = document.getElementById("bm1").value; 
document.getElementById("int2").value =(x*1)*(y*1); 
} 
</script>
<script> 
function hhh() 
{ 
var x = document.getElementById("bm1").value; 
var y = document.getElementById("t1").value; 
var z = document.getElementById("fine").value;
document.getElementById("totot").value =((x*1)*(y*1))+(z*1); 
} 
</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">Net Amount Dues</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 where mfin='$mfin'");
						$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">Due Date</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="inputPassword3" 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</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">Pay Date</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="bm1q" name="bmnt"  value="" placeholder="Pay Date" onfocus="insertDate(this,'DD-MM-YYYY')">
    </div>
 
    <label for="inputPassword3" class="col-sm-2 control-label">Interest/Month</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="2" name="inttt" value="<?php echo $row['interest']; ?>" placeholder="Interest">
	 
    </div>
    </div>
	<div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Bal Month</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="bm1" name="tdays" value="" placeholder="Balance Month"  onClick="add3()";>
    </div>
 
    <label for="inputPassword3" class="col-sm-2 control-label">Interest Amount</label>
    <div class="col-sm-4">
    <input type="text" class="form-control" id="int2" name="amt" value="" placeholder="Amount" Onclick="qqq()";>
    </div>
    </div>
	<div class="form-group">
    
    <label for="inputPassword3" class="col-sm-2 control-label">Fine</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="fine" name="fin" value="" placeholder="Penalty">
    </div>
    <label for="inputPassword3" class="col-sm-2 control-label">Total</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="totot" name="tot" value="" placeholder="Total" Onclick="hhh()";>
	  	  	  
    </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>
	<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">
    <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 net(mfin,scode,hpl,name,no,duedate,dueamount,paid,tamount,dueamt,inttt,amt,bmnt,tot,rno,paydate,fin)
											 values('$mfin','$scode','$hpl','$name','$no','$duedate','$dueamount','$paid','$tamount','$dueamt','$inttt','$amt','$bmnt','$tot','$rno','$paydate','$fin')");
								
								if($insert)
								{
									
									echo "Registered Successfully";
								header("Location:fdelete.php?hpl=$hpl");	
								}
								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-default" 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>
</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>