<?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">Monthly Net-amount Chasing</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 user2 where mfin='$mfin' &&  hpl='$hpl'");
						$n=mysqli_num_rows($qry);
						
						if($n==0)
						{$qa = 0;
						$qryy=mysqli_query($conn, "select * from customer where mfin='$mfin' &&  hpl='$hpl'");
                          $row2=mysqli_fetch_array($qryy);
							$nn = $row2['hpdate'];
						}
						else
					    {
						while($row=mysqli_fetch_array($qry))
						{
						$qa = $row['bal'];
						$nn = $row['paymnt'];
						}
						
						}
	$x=$hpl; 
  $qry2 = "SELECT * FROM customer 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 user2 where mfin='$mfin' &&  hpl='$x'");
$nnc=mysqli_num_rows($qry);
$e = $i - $nnc;
			
				}
	 
				$qry=mysqli_query($conn, "select * from customer where mfin='$mfin' &&  hpl='$hpl'");
				$query=mysqli_query($conn, "select * from user2 where mfin='$mfin' &&  hpl='$hpl'");
				$row=mysqli_fetch_array($qry);
				$row1=mysqli_fetch_array($query);
				/*$nn=mysqli_num_rows($query);
				echo $nn;
				 $roww = str_replace('/', '-', $row['hpdate']);
  $d1 = strtotime($roww);
$d2 = strtotime("today");
$min_date = min($d1, $d2);
$max_date = max($d1, $d2);
$ip = 0;
while (($min_date = strtotime("+1 MONTH", $min_date)) <= $max_date) {
    $ip++;
}
$e = $ip - $nn;	*/
$qe = $row['interest'];$qer = $qe/30;
				      ?>
	
	<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="inputPassword3" class="col-sm-2 control-label">HP 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>
  
    <label for="inputPassword3" class="col-sm-2 control-label">Interest/Day</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="t1" name="dueamount" value="<?php echo $qer;?>" placeholder="Due Amount">
    </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 $qa;?>" >
    </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">INTEREST</label>
    <div class="col-sm-4">
    <input type="text" class="form-control" id="int2" name="amt" value="" placeholder="Amount">
  
   </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">
	  	  	  
    </div>
  </div>
    <div class="form-group">
    <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="" placeholder="Recipt Number">
    </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="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-default" name="s1">Register</button>
    </div>
  </div>
      <div class="alert alert-success">
	  <?php
							if(isset($_POST['s1']))
							{
								extract($_POST);
								$insert=mysqli_query($conn, "insert into vnet2(mfin,scode,hpl,name,duedate,dueamount,dueamt,amt,tot,rno,paydate)
											 values('$mfin','$scode','$hpl','$name','$duedate','$dueamount','$dueamt','$amt','$tot','$rno','$paydate')");
								
								if($insert)
								{
									
									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-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 user2 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>
</div></div>
</div></div></div> <?php include "layouts/footer.php"; ?></body></html>
