<?php include "layouts/menu.php"; ?> 
    <?php $hpl=$_REQUEST['hpl'];?> 
	<script> 
function add() 
{ 
var x = document.getElementById("t1").value; 
var y = document.getElementById("bm1").value; 
document.getElementById("int2").value =(x*1)*(y*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("1").value; 
var y = document.getElementById("int3").value; 
document.getElementById("totot").value =(x*1)+(y*1); 
} 
</script>
<script> 
function mul() 
{ 
var x = document.getElementById("t1").value; 

var z = document.getElementById("obc").value; 
var w = document.getElementById("int2").value; 
document.getElementById("int3").value =(((x*1)*(1*w))+(z*1));  
} 
</script>
<script>
    function diff()
{
    var date14 = document.getElementById("dd").value;
    var date15 = document.getElementById("ddd").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("tot").value =  Math.round(difference_ms/one_day); 

}
</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 ayg() 
{ 
var z = document.getElementById("t1").value; 
var q = document.getElementById("1").value; 
document.getElementById("t1").value =((z*1)*(q*1))/3000;  
} 
</script>
<SCRIPT>
function diff()
{
    var date14 = document.getElementById("t2").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("int2").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">Monthly Net-amount</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 customer where mfin='$mfin' &&  hpl='$hpl'");
$row=mysqli_fetch_array($qry);
$hp=$row['hpamount'];
	 $qry=mysqli_query($conn, "select * from net2");
						$n=mysqli_num_rows($qry);
						if($n==0)
						{
							$rty = 1;
						}
						else
					    {
						while($row=mysqli_fetch_array($qry))
						{
						$sss = $row['rno'];
						}
						$rty = $sss + 1;
						} ?>	
	<?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 $row['inter'];?>" 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">Last Paid Date</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="t2" name="paid" value="<?php echo $nn;?>" placeholder="Paid Month">   
    </div>
  </div>
  
  <div class="form-group">
    
   <?php 
 $qry1=mysqli_query($conn, "select * from user2 where mfin='$mfin' &&  hpl='$hpl'");
  $row1=mysqli_fetch_array($qry1);
 $n=mysqli_num_rows($qry1);

 if($n==0)
 {
$amount=$hp;
 }
 else if($n==1)
 {
 $amount=$hp-$row1['cre']+$row1['deb'];
 }
 else
 {  
while($row1=mysqli_fetch_array($qry1))
{
$s1=$row1['cre'];
$s2=$row1['deb'];
 $hp1=$row1['pass'];

}
$amount=$hp1-$s1+$s2;
 }
 ?>
    <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 $amount;?>" placeholder="H.P Amount">
    </div>
	<label for="inputPassword3" class="col-sm-2 control-label">Today Date</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="kk" name="bmnt" value="" placeholder="Today" onfocus="insertDate(this,'DD-MM-YYYY')" onclick="ayg()">
    </div>
  </div>
    <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Total Days</label>
    <div class="col-sm-4">
    <input type="text" class="form-control" id="int2" name="amthh" value="" placeholder="Amount" onclick="diff()">
 
   </div>
   <label for="inputPassword3" class="col-sm-2 control-label">INTEREST</label>
    <div class="col-sm-4">
    <input type="text" class="form-control" id="int3" name="amt" value="" placeholder="Amount" onclick="mul()">
 
   </div>
    </div>
    <div class="form-group">
    <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="add3()"> 	  	  
    </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>

   
      <button type="submit" class="btn btn-success  btn-lg" name="s1">Register</button>

  </div>
      <div class="alert alert-success">
	  <?php include "programs/m.net.php"; ?>
	  	  </div><div class="alert alert-warning"><?php include "programs/mdel.php"; ?></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>
