<?php include "layouts/menu.php"; ?>
    <?php $hpl=$_REQUEST['hpl']; $mfin2=$_REQUEST['mfin2'];
	?>
	<?php /*$vno=$_REQUEST['vno'];*/?>
	
<style> 
input[type=text] {
    width: 100%;
   
    box-sizing: border-box;
    border: 1px solid #555;
    outline: Gray;
	
}

input[type=text]:focus {
    background-color: #d1e0e3;
}

.div1 {
    width: 750px;
    height: 240px;
    border: 4px solid #376ca1;
	background-color:#f4f6df;
	float:left;
}

.div2 {
    width: 380px;
    height: 240px;    
background-color:#f4f6df;
    border: 4px solid #376ca1;
	float:right;
}
label {
  
  color: black;
  font-weight: bold;
  
}
td,th{
  
  color: black;
  font-weight: bold;
  
}

</style>

	 <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	no1=Number(document.getElementById("tx2").value);

if(no1 <= -1 )
{
document.getElementById("txt2").value =parseInt(0); 
	
	
}else{
var x = document.getElementById("dqw").value; 
var y = document.getElementById("tx2").value; 
document.getElementById("txt2").value =parseInt((x*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));

var xx = document.getElementById("qx").value; 
var yy = document.getElementById("jkjk").value; 
document.getElementById("ax").value =parseInt((xx*1)+(yy*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 add01() 
{ 
var a = document.getElementById("paymnt").value; 
var b = document.getElementById("dueamount").value; 
document.getElementById("dueamt").value =((a*1)*(b*1)); 

var c = document.getElementById("paymnt").value; 
var d = document.getElementById("dueamt").value; 
var e = document.getElementById("hloan").value; 
var f = document.getElementById("fine").value; 

document.getElementById("urname").value =((d*1)+(e*1)+(f*1)); 
 
} 
</script>
<script> 
function add03() 
{ 
var a = document.getElementById("paymnt").value; 
var b = document.getElementById("dueamount").value; 
var x = document.getElementById("dueamt").value; 
var y = ((x*1)/(b*1)); 
document.getElementById("paymnt").value = Math.floor(y); 

var d = document.getElementById("dueamt").value; 
var e = document.getElementById("hloan").value; 
var f = document.getElementById("fine").value; 

document.getElementById("urname").value =((d*1)+(e*1)+(f*1)); 
 
} 
</script>

<script> 
function add02() 
{ 
var a = document.getElementById("pass").value; 
var b = document.getElementById("inttt").value; 
var c = document.getElementById("tds").value; 
var d = document.getElementById("addless").value; 
var e = document.getElementById("hloan").value; 
var f = document.getElementById("fine").value; 

document.getElementById("urname").value =((a*1)+(b*1)-(c*1)+(e*1)+(f*1)-(d*1)); 
} 
</script>
<script>
    function onch()
{
    var date14 = document.getElementById("fromm").value;
    var date15 = document.getElementById("too").value;


    var one_day=1000*60*60*24;

    var date1 = new Date(date14);
    var date2 = new Date(date15);

      // 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
var ddd =  Math.round(difference_ms/one_day);
document.getElementById("dayss").value = (ddd + 1);
   var a1 = document.getElementById("dayss").value;
    var a2 = document.getElementById("cinpday").value;
document.getElementById("inttt").value =  (a1*a2);
 var a11 = document.getElementById("inttt").value;
document.getElementById("tds").value =  ((a11*1) * (10/100));

var a = document.getElementById("pass").value; 
var b = document.getElementById("inttt").value; 
var c = document.getElementById("tds").value; 
var d = document.getElementById("addless").value; 
var e = document.getElementById("hloan").value; 
var f = document.getElementById("fine").value; 

document.getElementById("urname").value =((a*1)+(b*1)-(c*1)+(e*1)+(f*1)-(d*1)); 
}
</script>
  <!--  page-wrapper -->
         <div class="right_col" role="main">
         
            <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-12"> 
    <form name="form1" class="form-horizontal" method="post" action="" enctype="multipart/form-data">

<?php $rrow44=0;$rrow45=0;
										
									$sql = "SELECT SUM(hpamount) FROM fincust where mfin='$mfin2' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql);
                                    $row52 = mysqli_fetch_array($q);	
                                    $rrow44 = $row52[0] + $rrow44;								
									
									$sql = "SELECT SUM(pass) FROM finuser where mfin='$mfin2' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql);
                                    $row53 = mysqli_fetch_array($q);	
                                    $rrow45 = $row53[0] + $rrow45;																			
									
									
									 $rrow445= $rrow44 - $rrow45; ?>
<?php $rrno2 = 0;
$qry5=mysqli_query($conn, "select * from finuser where hpl='$hpl' && mfin='$mfin2' order by fid desc");
$n5=mysqli_num_rows($qry5);
$row5=mysqli_fetch_array($qry5);
$fromm = $row5['fromm'];
$too2 = $row5['too'];

$result = mysqli_query($conn, "SELECT MAX(rno) FROM finroll where mfin='$mfin2'");
$row = mysqli_fetch_array($result);
$rrno2 =  $row[0];
$rrno = $rrno + 1;

$qry=mysqli_query($conn, "select * from fincust where mfin='$mfin2' &&  hpl='$hpl'");
$row=mysqli_fetch_array($qry);
	$sad = $row['duemnt'];
		$hpamt = $row['hpamount'];
		$inter = $row['inter'];
		$remarks = $row['remarks'];
if($n5 == 0) { $too2 = $row['hpdate5']; }	
$too = date("Y-m-d", strtotime("$too2 + " . 1 . " day")); 	
$tdy = date("Y-m-d"); 
  $d11 = strtotime($too);
$d22 = strtotime($tdy);
$min_date1 = min($d11, $d22);
$max_date1 = max($d11, $d22);
$i66 = 0;
if($d11<=$d22) {
while (($min_date1 = strtotime("+1 DAY", $min_date1)) <= $max_date1) {
    $i66++;
} }
$i6 = $i66 + 1;
$qry522=mysqli_query($conn, "select sum(pass) from finuser where hpl='$hpl' && mfin='$mfin2'");
$row522 = mysqli_fetch_array($qry522);
$paidprin = $row522[0];
$balprin = $hpamt - $paidprin;
$inpday = ($balprin * ($inter / 100))/30;
$interest = $inpday * $i6;
$tds = $interest * (10/100);
$tottt =$interest - $tds;
		if($remarks!=NULL){
echo '<script language="javascript">';
echo 'alert("'.$remarks.'")';
echo '</script>'; }
$dd = $row['uimg'];	
$g1 = $row['g1'];
$b1 = $row['b1'];
?>


<div class="col-md-12">

	<div class="col-md-3">
   <div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">Loan NO</label>
    <div class="col-sm-4">
 <input type="text" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="hpl" width="48" value="<?php echo $row['hpl'];?>" placeholder=""  required>  
 <input type="hidden" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="vno" width="48" value="<?php echo $row['vno'];?>" placeholder=""  >  
 <input type="hidden" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="hpdate" width="48" value="<?php echo $row['hpdate'];?>" placeholder=""  >  
 <input type="hidden" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="no" width="48" value="<?php echo $row['duemnt'];?>" placeholder=""  >  
 <input type="hidden" class="form-control" style="width:170px; height:29px " id="dueamount" name="dueamount" width="48" value="<?php echo $row['total'];?>" placeholder=""  >  
 <input type="hidden" class="form-control" style="width:170px; height:29px " id="ddamt" name="ddamt" width="48" value="<?php echo $row['dueamt'];?>" placeholder=""  >  
 <input type="hidden" class="form-control" style="width:170px; height:29px " id="interest" name="interest" width="48" value="<?php echo $row['interest'];?>" placeholder=""  >    
 <input type="hidden" class="form-control" style="width:170px; height:29px " id="cinter" name="cinter" width="48" value="<?php echo $row['inter'];?>" placeholder=""  >    
 <input type="hidden" class="form-control" style="width:170px; height:29px " id="chpamt" name="chpamt" width="48" value="<?php echo $row['hpamount'];?>" placeholder=""  >    
  <input type="hidden" class="form-control" style="width:170px; height:29px " id="cinpday" name="cinpday" width="48" value="<?php echo $inpday;?>" placeholder=""  >    
  <input type="hidden" class="form-control" style="width:170px; height:29px " id="paidprin" name="paidprin" width="48" value="<?php echo $paidprin;?>" placeholder=""  >    
  <input type="hidden" class="form-control" style="width:170px; height:29px " id="balprin" name="balprin" width="48" value="<?php echo $balprin;?>" placeholder=""  >    

  </div>
   </div>
 </div>
 	
     <input type="hidden" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="vno" value="<?php echo $row['vno'];?>" placeholder=""  required>  
  
 	<div class="col-md-3">
   <div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">RECPNO</label>
    <div class="col-sm-4">
     <input type="text" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="roll" value="<?php echo $rrno;?>" placeholder=""  required>  
       <input type="hidden" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="roll55" value="<?php echo $rrno;?>" placeholder=""  >  
    </div>
   </div>
 </div>
 	<div class="col-md-3">
   <div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">Date </label>
    <div class="col-sm-4">
     <input type="text" class="form-control"  style="width:170px; height:29px " id="inputPassword3" name="paydate" value="<?php echo date("d-m-Y");?>" placeholder=""  required>  
    </div>
   </div>
 </div>
 <div class="col-md-3">
   <div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">PartyName</label>
    <div class="col-sm-4">
     <input type="text" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="name" width="10" value="<?php echo $row['name'];?>" placeholder=""  required>  
   </div>
 </div>
 </div>
 </div>
<div class="col-md-12"> 
 <div class="col-md-3">
   <div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">From</label>
    <div class="col-sm-4">
     <input type="date" class="form-control" style="width:170px; height:29px " id="fromm" name="fromm" value="<?php echo $too; ?>"  placeholder=""  required>  
    </div> </div>
 </div>
	 <div class="col-md-3">
   <div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">To</label>
    <div class="col-sm-4">
    
  <input type="date" class="form-control" style="width:170px; height:29px " id="too" name="too" value="<?php echo $tdy; ?>" onkeyup="onch()" onchange="onch()" placeholder="E.g gg" required >   
     
   </div> </div>
 </div>
    <div class="col-md-3">
   <div class="form-group">
   <label for="inputPassword3" class="col-sm-2 control-label">Days</label>
    <div class="col-sm-4">
 
<input type="text" class="form-control" style="width:170px; height:29px " id="dayss" name="dayss" value="<?php echo $i6; ?>" onclick="onch()" placeholder="E.g gg" required >  
   </div> </div>
 </div>
 </div>	  
<div class="col-md-12">
<div class="col-md-6 div1">

<div class="form-group"> <br>

<label for="inputPassword3" class="col-sm-2 control-label">Principle</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="pass" name="pass" value="0" placeholder="" onkeyup="add02()" required>  
<input type="hidden" class="form-control" id="payyy" name="payyy" value="<?php echo $sql5;?>" placeholder=""  required> 
<input type="hidden" class="form-control" id="dueamt2" name="dueamt2" value="<?php echo $u;?>" placeholder=""  required>  
<input type="hidden" class="form-control" id="paymnt11" name="paymnt11" value="<?php echo $ni;?>" placeholder="">  
<input type="hidden" class="form-control" id="paymnt" name="paymnt" value="<?php echo $ni;?>" placeholder="" onkeyup="add01()" required>  
</div>
<label for="inputPassword3" class="col-sm-2 control-label">Interest</label>
<div class="col-sm-4">
<input type="hidden" class="form-control" id="dueamt11" name="dueamt11" value="<?php echo $spddd;?>"  placeholder="E.g 1008" >  
<input type="hidden" class="form-control" id="dueamt" name="dueamt" value="<?php echo $spddd;?>" onkeyup="add03()"  placeholder="E.g 1008" required> 
<input type="text" class="form-control" id="inttt" name="inttt" value="<?php echo $interest; ?>" placeholder="" onkeyup="add02()" required>    
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Hand Loan</label>
<div class="col-sm-4">
<input type="hidden" class="form-control" STYLE="color: #ff5521; font-family: Verdana; font-weight: bold; font-size: 14px; background-color: #9bc7ef;"  id="hlbal" name="hlbal" value="<?php echo $hlbal; ?>" placeholder="" required>
<input type="hidden" class="form-control" id="hloan11" name="hloan11" value="<?php echo $hlbal; ?>" placeholder="" >

<a href="viewhl.php?hpl=<?php echo $hpl; ?>&mfin2=<?php echo $mfin2; ?>" target="_blank"><input type="text" class="form-control" STYLE="color: #ff5521; font-family: Verdana; font-weight: bold; font-size: 14px; background-color: #9bc7ef;"  onkeyup="add02()" id="hloan" name="hloan" value="0" placeholder="" required></a>

</div>
 <label for="inputPassword3" class="col-sm-2 control-label">Def Amt</label>
<div class="col-sm-4">

<input type="text" class="form-control" id="fine" name="fine" value="0" onkeyup="add02()" placeholder=""  required>  
</div>

<input type="hidden" class="form-control" id="hlrmk" name="hlrmk" value="" placeholder=""  >  


</div>
 
  <div class="form-group">
  <label for="inputPassword3" class="col-sm-2 control-label">TDS Amount</label>
<div class="col-sm-4">
<input type="hidden" class="form-control" id="tdsper" name="tdsper" value="10" placeholder=""  >  

<input type="text" class="form-control" id="tds" name="tds" value="<?php echo $tds;?>" onkeyup="add02()" placeholder=""  required>  
</div>

	<label for="inputPassword3" class="col-sm-2 control-label">Total</label>
    <div class="col-sm-4">
      <input type="hidden" class="form-control" id="urname11" name="urname11" value="<?php echo $tottt; ?>" placeholder="E.g 1008" >   

  <input type="text" class="form-control" id="urname" name="urname" value="<?php echo $tottt; ?>" placeholder="E.g 1008" required>   
   </div>
 </div>
 
   <div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Add/ Less</label>
    <div class="col-sm-4">
     <input type="text" class="form-control" id="addless" name="addless" value="0"  onkeyup="add02()" placeholder=""  required>  
    </div>
<label for="inputPassword3" class="col-sm-2 control-label">Remark</label>
    <div class="col-sm-4">
    
  <input type="text" class="form-control" id="remarks" name="remarks" value="" placeholder="E.g gg" >   
   </div>
 </div>	
	
   <div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Pay Mode</label>
    <div class="col-sm-4">
      <select type="text" class="form-control"  style="width:200px; height:29px " id="inputPassword3" name="mode" width="48" value="" placeholder=""  required>  
 <option></option>
 <option>Cash A/C</option>

<?php $abank = mysqli_query($conn, "select * from ledger where under='Bank Accounts'");
	while($bbank = mysqli_fetch_array($abank)) { ?>
	<option><?php echo $bbank['ledger']; ?></option>
	<?php } ?>
	  </select>   
   </div>
  
   <?php
	  $sql55 = mysqli_query($conn, "select * from sizzing where mfin='$mfin2' && hpl=$hpl");
	  $n55 = mysqli_num_rows($sql55);
	  $row55 = mysqli_fetch_array($sql55);
	  if($n55>0) { ?>   
   
<label for="inputPassword3" class="col-sm-2 control-label">Release Vehicle in Seizing</label>
    <div class="col-sm-4">
     <select type="text" class="form-control"  style="width:200px; height:29px " id="inputPassword3" name="sss" width="48" value="" placeholder="" >  
 <option></option>
 <option>Yes</option>
  <option>No</option>
 </select>   
   </div>
   
	  <?php } else { ?> 
	  <input type="hidden" class="form-control" name="sss" value="" placeholder="" >
      <?php } ?></div>
</div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 <div class="col-md-6 div2"> <br>
 <table >
 <tr>
 <td>
 Loan Amount/Dt 
 </td>
 <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
<?php echo $row['hpamount']; ?> / <?php echo $row['hpdate']; ?>
 </td>
 </tr>
  <tr>
 <td>
 Total Dues
 </td> <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
 <?php echo $row['duemnt']; ?>
 </td>
 </tr>
 
  <tr>
 <td>
 Paid Principle
 </td> <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
<?php echo $paidprin;?>
 </td>
 </tr>
 
  <tr>
 <td>
Last Recpt Date
 </td> <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
 <?php echo $lddate; ?>
 </td>
 </tr>
 
  <tr>
 <td>
Interest Per Day
 </td> <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
 <?php echo $inpday; ?>
 </td>
 </tr>
 
  <tr>
 <td>
 Coln Visit 
 </td> <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
 -
 </td>
 </tr>
 
  <tr>
 <td>
Visit Result
 </td> <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
 -
 </td>
 </tr>
 <tr>
 <td colspan="2"> <?php  if(($postt == 'MD') || ($postt == 'Office All')) { ?>
 <select class="form-control" style="width:170px; height:29px " id="inputPassword3" name="rolll" value="" placeholder="" >  
 <option value="0">Normal RCPT</option>
 <option value="1">RCPT No Not Reflect</option></select>
 <?php } else { ?>

 <input type="hidden" class="form-control" style="width:170px; height:29px " id="inputPassword3" name="rolll" value="555" placeholder="" > 
 <?php } ?>
 </td>
 </tr>
 </table>
 </div>
 </div>

 <input type="hidden" class="form-control" id="inputPassword3" name="hpl" value="<?php echo $row['hpl'];?>" placeholder="E.g 1008" readonly required>
 
   </div> <div> &nbsp;</div><div>
      <button type="submit" class="btn btn-warning btn-block" name="s155">Save & Print</button>  </div>
       <div>
	<?php
							if(isset($_POST['s155']))
							{
								extract($_POST);
								if($roll == $roll55){
								$result = mysqli_query($conn, "SELECT MAX(rno) FROM finroll where mfin='$mfin2'");
$row = mysqli_fetch_array($result);
$rrno2 =  $row[0];
								$roll = $rrno2 + 1; }
								$duemnt2 = $no;
								$hpamt = $chpamt;
								$ddamt = $ddamt;
								$fddue = $dueamount * $paymnt;
								$dueamt11 = $dueamt11;
								$dueamt = $dueamt;
								
							$paydate2 = date('Y-m-d', strtotime($paydate));
date_default_timezone_set('Asia/Kolkata');
$date = date('h:i:s a m/d/y');
$ddate =  date('h:i:s a d/m/y', strtotime($date));	
								$insert=mysqli_query($conn, "insert into finuser(createdate,paydate2,remarks,hlrmk,hloan,mfin,scode,hpl,uid,name,paydate,fine,urname,roll,pass,rno,bil,mode,fromm,too,dayss,tdsper,tds)
											 values('$ddate','$paydate2','$remarks','$hlrmk','$hloan','$mfin2','$scode','$hpl','$hpl','$name','$paydate','$fine','$urname','$roll','$pass','$inttt','$roll','$mode','$fromm','$too','$dayss','$tdsper','$tds')");
								$insert33=mysqli_query($conn, "insert into finroll(rno,mfin,scode)value('$roll','$mfin2','$scode')");
			if($insert) { echo "Registered Successfully"; header("Location:finsearch55.php");	 }
			else { echo "Failure"; }		}
?>
	  </div>
</form> 
					
</div>
</div></div>
</div></div></div> <?php include "layouts/footer.php"; ?> </body></html>