<?php include "layouts/menu.php"; ?>
    <?php $hpl=$_REQUEST['hpl']; $mfin2=$_REQUEST['mfin2'];
	?>
	<?php $area=$_REQUEST['area']; ?>
	


	 <script> 
function add() 
{ 
var x = document.getElementById("price").value; 

document.getElementById("tot").value =(x*1); 
} 
function add2() 
{ 
var t1 = document.getElementById("tott1").value; 
var t2 = document.getElementById("tott2").value; 
var t3 = document.getElementById("tott3").value; 
var t4 = document.getElementById("tott4").value; 
var t5 = document.getElementById("tott5").value; 
var t6 = document.getElementById("tott6").value; 
var t7 = document.getElementById("tott7").value; 
var t8 = document.getElementById("tott8").value; 
var t9 = document.getElementById("tott9").value; 
var t10 = document.getElementById("tott10").value; 
var t11 = document.getElementById("tott11").value; 
var t12 = document.getElementById("tott12").value; 
var t13 = document.getElementById("tott13").value; 
var t14 = document.getElementById("tott14").value; 
var t15 = document.getElementById("tott15").value; 
var t16 = document.getElementById("tott16").value; 
var t17 = document.getElementById("tott17").value; 
var t18 = document.getElementById("tott18").value; 
var t19 = document.getElementById("tott19").value; 
var t20 = document.getElementById("tott20").value;
var t21 = document.getElementById("tott21").value; 
var t22 = document.getElementById("tott22").value; 
var t23 = document.getElementById("tott23").value; 
var t24 = document.getElementById("tott24").value; 
var t25 = document.getElementById("tott25").value; 
var t26 = document.getElementById("tott26").value; 
var t27 = document.getElementById("tott27").value; 
var t28 = document.getElementById("tott28").value; 
var t29 = document.getElementById("tott29").value; 
var t30 = document.getElementById("tott30").value;
var t31 = document.getElementById("tott31").value; 
var t32 = document.getElementById("tott32").value; 
var t33 = document.getElementById("tott33").value; 
var t34 = document.getElementById("tott34").value; 
var t35 = document.getElementById("tott35").value; 
var t36 = document.getElementById("tott36").value; 
var t37 = document.getElementById("tott37").value; 
var t38 = document.getElementById("tott38").value; 
var t39 = document.getElementById("tott39").value; 
var t40 = document.getElementById("tott40").value;
var t41 = document.getElementById("tott41").value; 
var t42 = document.getElementById("tott42").value; 
var t43 = document.getElementById("tott43").value; 
var t44 = document.getElementById("tott44").value; 
var t45 = document.getElementById("tott45").value; 
var t46 = document.getElementById("tott46").value; 
var t47 = document.getElementById("tott47").value; 
var t48 = document.getElementById("tott48").value; 
var t49 = document.getElementById("tott49").value; 
var t50 = document.getElementById("tott50").value;
var t51 = document.getElementById("tott51").value; 
var t52 = document.getElementById("tott52").value; 
var t53 = document.getElementById("tott53").value; 
var t54 = document.getElementById("tott54").value; 
var t55 = document.getElementById("tott55").value; 
var t56 = document.getElementById("tott56").value; 
var t57 = document.getElementById("tott57").value; 
var t58 = document.getElementById("tott58").value; 
var t59 = document.getElementById("tott59").value; 
var t60 = document.getElementById("tott60").value;
var t61 = document.getElementById("tott61").value; 
var t62 = document.getElementById("tott62").value; 
var t63 = document.getElementById("tott63").value; 
var t64 = document.getElementById("tott64").value; 
var t65 = document.getElementById("tott65").value; 
var t66 = document.getElementById("tott66").value; 
var t67 = document.getElementById("tott67").value; 
var t68 = document.getElementById("tott68").value; 
var t69 = document.getElementById("tott69").value; 
var t70 = document.getElementById("tott70").value;
document.getElementById("tot").value =((t1*1)+(t2*1)+(t3*1)+(t4*1)+(t5*1)+(t6*1)+(t7*1)+(t8*1)+(t9*1)+(t10*1)+(t11*1)+(t12*1)+(t13*1)+(t14*1)+(t15*1)+(t16*1)+(t17*1)+(t18*1)+(t19*1)+(t20*1)+(t21*1)+(t22*1)+(t23*1)+(t24*1)+(t25*1)+(t26*1)+(t27*1)+(t28*1)+(t29*1)+(t30*1)+(t31*1)+(t32*1)+(t33*1)+(t34*1)+(t35*1)+(t36*1)+(t37*1)+(t38*1)+(t39*1)+(t40*1)+(t41*1)+(t42*1)+(t43*1)+(t44*1)+(t45*1)+(t46*1)+(t47*1)+(t48*1)+(t49*1)+(t50*1)+(t51*1)+(t52*1)+(t53*1)+(t54*1)+(t55*1)+(t56*1)+(t57*1)+(t58*1)+(t59*1)+(t60*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 add003() 
{ 
	$('.price').blur(function () {
		var sumdata = 0;
		$('.price').each(function() {
			if($(this).val()!="")
			 {
				sumdata += parseFloat($(this).val());
			 }

		});
			$("#sum").html(sumdata);
	});
}
</script>
<script>
// register jQuery extension
$(document).ready(function() {
  $(window).keydown(function(event){
    if(event.keyCode == 13) {
      event.preventDefault();
      return false;
    }
  });
});
	</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" id="testSuiteConfigurationform" name="testSuiteConfigurationform" class="form-horizontal" method="post" action="" enctype="multipart/form-data">
<div class="col-md-12">
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Date</label>
<div class="col-sm-4">

     <input type="text" class="form-control"   id="inputPassword3" name="paydate" value="<?php echo date("d-m-Y");?>" placeholder=""  required>  
</div>
</div> 

</div>

<div class="col-md-12">
<div class="form-group">
<div class="col-sm-1">
<input type="text" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;" id="inputPassword3" readonly name="sdgfesgh" value="A/C No" placeholder=""  >  
</div>
<div class="col-sm-3">

     <input type="text" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #645458;"   id="inputPassword3" readonly name="sdfghfsh" value="Name" placeholder=""  >  
</div>
<div class="col-sm-2">

     <input type="text" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #645458;"   id="inputPassword3" readonly name="fhhhhh" value="Balance Amt" placeholder=""  >  
</div>


     <input type="hidden" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #645458;"   id="inputPassword3" readonly name="dfhfh" value="<?php echo $row['duemnt'];?>" placeholder=""  >  

<div class="col-sm-2">

     <input type="text" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #645458;"   id="inputPassword3" readonly name="fhfdhth" value="Loan Date" placeholder=""  >  
</div>
<div class="col-sm-2">

     <input type="text" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #f96363;"   id="inputPassword3" readonly name="rfhfdhh" value="Amount Paid" placeholder=""  >  
</div>

<div class="col-sm-2">

     <input type="text" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #f96363;"   id="inputPassword3" readonly name="rfhfdhh" value="Mode" placeholder=""  >  
</div>
</div>

<?php $i = 0;
if($area=='dd'){
	$sql = mysqli_query($conn, "select * from customerdetailsm where status='Active' order by hpl asc");

}
else{
$sql = mysqli_query($conn, "select * from customerdetailsm where area='$area' &&  status='Active' order by hpl asc");
}
  
while($row = mysqli_fetch_array($sql)) { $i++; 
$mfin2 = $row['mfin'];
$hpl = $row['hpl'];
$rrow44=0;$rrow45=0;
										
									$sql44 = "SELECT SUM(totalhpamt) FROM customerdetailsm where mfin='$mfin2' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql44);
                                    $row52 = mysqli_fetch_array($q);	
                                    $rrow44 = $row52[0];								
									
									$sql55 = "SELECT SUM(urname) FROM userm where mfin='$mfin2' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql55);
                                    $row53 = mysqli_fetch_array($q);	
                                    $rrow45 = $row53[0];																			
									
									
									 $rrow445= $rrow44 - $rrow45;
?>
<div class="form-group">
<div class="col-sm-1">
<input type="text" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;" id="inputPassword3" name="hpl[<?php echo $i; ?>]" value="<?php echo $row['hpl'];?>" placeholder=""  >  
</div>
<div class="col-sm-3">

     <input type="text" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #645458;"   id="inputPassword3" name="name[<?php echo $i; ?>]" value="<?php echo $row['name'];?>" placeholder=""  >  
</div>
<div class="col-sm-2">

     <input type="text" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #645458;"   id="inputPassword3" name="hpamount[<?php echo $i; ?>]" value="<?php echo $rrow445;?>" placeholder=""  >  
</div>


     <input type="hidden" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #645458;"   id="inputPassword3" name="duemnt[<?php echo $i; ?>]" value="<?php echo $row['duemnt'];?>" placeholder=""  >  

<div class="col-sm-2">

     <input type="text" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #645458;"   id="inputPassword3" name="hpdate[<?php echo $i; ?>]" value="<?php echo $row['hpdate'];?>" placeholder=""  >  
</div>
<div class="col-sm-2">

     <input type="text" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #f96363;"   id="totalRetryCount" name="urname[<?php echo $i; ?>]" tabindex="<?php echo $i; ?>" onblur="validateElement('Configuration', 'testSuiteConfigurationform','totalRetryCount')" value="" placeholder=""  >  
</div>
<div class="col-sm-2">

 <select type="text" class="form-control"   id="inputPassword3" name="mode[<?php echo $i; ?>]" width="48" value="" placeholder=""  required>
 <option>Cash A/C</option>
<?php $abank = mysqli_query($conn, "select * from ledger where under='Bank Accounts' && mfin='$mfin2'");
	while($bbank = mysqli_fetch_array($abank)) { ?>
	<option><?php echo $bbank['ledger']; ?></option>
	<?php } ?>
	  </select>  </div>
</div>
<?php } ?>
Total <input type="text" class="form-control"   id="sum" name="fdsg" value="" onclick="add003()" placeholder=""  >  

 <input type="hidden" class="form-control"   id="inputPassword3" name="ii" value="<?php echo $i; ?>" placeholder=""  >  
      <button type="submit" class="btn btn-warning btn-block" name="s1">Save & Print</button>  </div>
       <div>
	<?php
							if(isset($_POST['s1']))
							{
								extract($_POST);
						$paydate2 = date('Y-m-d', strtotime($paydate));	
						$name = $_POST['name'];
						$urname = $_POST['urname'];
						$hpl = $_POST['hpl'];
						$mode = $_POST['mode'];
						//$na6me = $_POST['name'];
						$sql56 = mysqli_query($conn, "select * from userm order by fid desc");
	$row56 = mysqli_fetch_array($sql56);
	$ij = $row56['bil'];
$j = 1;
while($j<=$ii) {
	$urname2 = $urname[$j];
		$mode2 = $mode[$j];
	$name2 = $name[$j];
	$hpl2 = $hpl[$j];
	
	if($urname2 != NULL) {
		$ij++;
			$p3 = $urname2;
	$sql5 = mysqli_query($conn, "select * from customerdetailsm where hpl='$hpl2' && mfin='$mfin'");
	$row5 = mysqli_fetch_array($sql5);
	$p1  = $row5['dueamt'];
	$p2  = $row5['interest'];
	$total  = $row5['total'];
	$duemnt1 = $p3 / $total;
	$duemnt = round($duemnt1,0);
	$rno = $duemnt * $p2;
	$pass = $p3 - $rno;
	
$insert=mysqli_query($conn, "insert into userm(paydate2,mfin,hpl,name,paydate,urname,mode,rno,pass,paymnt,bil,roll)
values('$paydate2','$mfin','$hpl2','$name2','$paydate','$urname2','$mode2','$rno','$pass','$duemnt','$ij','$ij')");
	}
$j++;
}						
						
								
								if($insert)
								{

									echo "Registered Successfully";
								
							echo "Success";								
							}
								else
								{
									echo "Failure";
								}
							}
?>
	  </div>
</form>
					
</div>
</div></div>
</div></div></div> <?php include "layouts/footer.php"; ?> </body></html>