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


	 <script> 
function add4() 
{ 
let sum = 0;

for (let i = 1; ; i++) {
    let element = document.getElementById('pcost'+i);
    if (element === null) {
        break;
    }
    sum += parseFloat(element.value) || 0;
}

document.getElementById("totg").value = sum;
}

</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 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>
// 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="Loan No" 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="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="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: #645458;"   id="inputPassword3" readonly name="fhhhhh" value="Loan Amount" 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="rfhfdhh" value="Out Standing" placeholder=""  >  
</div>
<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: #645458;"   id="inputPassword3" readonly name="rfhfdhh" value="Due" 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>

<?php $i = 0;
if($area == 'dd'){
$sql = mysqli_query($conn, "select * from customerdetailsw where  status='Active'");
}
else{
    $sql = mysqli_query($conn, "select * from customerdetailsw where area='$area' &&  status='Active'");
}

while($row = mysqli_fetch_array($sql)) { $i++; 
$hpamt = $row['totalhpamt'];
$hpl = $row['hpl'];
    $sql43 = mysqli_query($conn, "select sum(urname) from userw where hpl='$hpl'");
$row43 = mysqli_fetch_array($sql43);
$urnn = $row43[0];
$bbal = $hpamt - $urnn;
?>
<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-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="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="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: #645458;"   id="inputPassword3" name="hpamount[<?php echo $i; ?>]" value="<?php echo $row['totalhpamt'];?>" 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="totalRetryCount" name="urndfdfame[<?php echo $i; ?>]"  value="<?php echo $bbal; ?>" placeholder=""  >  
</div>
<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: #645458;"   id="totalRetryCount" name="urndfdfame[<?php echo $i; ?>]"  value="<?php echo $row['total'];?>" placeholder=""  >  
</div>
<?php $tott = $tott + $row['total']; ?>
<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;" required  id="pcost<?php echo $i; ?>" name="urname[<?php echo $i; ?>]" value="" onkeyup="add4()" placeholder=""  >  
</div>





</div>
<?php } 
while($i <= 30){
$i++;	?>
<input type="hidden" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #0000ff;" required  id="pcost<?php echo $i; ?>" name="urnsssame[<?php echo $i; ?>]" value="" onkeyup="add4()" placeholder=""  >  

<?php }

?>

 <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>
               <input type="text" class="form-control" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #f96363;" required  id="totg" name="totg" onclick="add4()" value="" placeholder=""  >  

      <h1 style="color:black;float:right;font-family: Verdana;font-size:25px;">Total :<span style="border:1px solid black; margin-left:20px;background-image:linear-gradient(to left, #01ffc8 , #27bda9);;padding:0px 30px;color:Black;"><?php echo $tott; ?></span></h1>
      </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'];
						//$name = $_POST['name'];
$j = 1;
while($j<=$ii) {
	$urname2 = $urname[$j];
	$name2 = $name[$j];
	$hpl2 = $hpl[$j];
	if($urname2 != NULL) {
$insert=mysqli_query($conn, "insert into userw(paydate2,mfin,hpl,name,paydate,urname,mode)
values('$paydate2','$mfin','$hpl2','$name2','$paydate','$urname2','Cash A/c')");
	}
$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>