<?php include "layouts/menu.php"; ?> <div class="right_col" role="main">
            <div class="row">
                 <!-- page header -->
                <div class="col-lg-12">
                    <h1 class="page-header">Pending List</h1>
                </div>
                <!--end page header -->
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <!-- Form Elements -->
					 <!-- Form Elements -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Vehicle Loan
                        </div>
                        <div class="panel-body">
                            <div class="row">
                   
<div id="mydiv">
<input type="button" value="Print" onclick="PrintElem('#mydiv')"  style="margin:20px;">
<a href="pendcat.php"><button class="btn btn-primary">Catogory Wise</button></a>&nbsp;&nbsp;&nbsp;
<div class="table-responsive">
<center><a href="pen.php">Add Columns</a></center>
<table id="datatable-buttons" id="datatable-buttons" class="table table-striped table-bordered">
				<thead>
  <tr><th>Hpl</th>
						<th>Name</th>
				
						<th>Reg Date</th>
						<th>Phone</th>
						<th>Due Amount</th>
						<th>L.D.Date</th>
						<th>Total due </th>
						
						<th>Pending Due</th>
						<th>Hloan</th>
						<th>Def</th>
						<th>Pending amnt</th>
					
					</tr> </thead>
					
					   <tbody><?php  
					   $sts =42000; $sts22 =44000; $sts2 ="Active"; $hpl=$_REQUEST['hpl'];
  $qry2 = "SELECT * FROM customerdetails where mfin='$mfin' && status='$sts2' order by id ASC";
	  $rs = mysqli_query($conn, $qry2);
	  // Loop the recordset $rs
	// Each row will be made into an array ($row) using mysqli_fetch_array
while($row = mysqli_fetch_array($rs)) {
		$x = $row['hpl'];
		$hpl = $row['hpl'];
			$qry8=mysqli_query($conn, "select * from net where mfin='$mfin' &&  hpl='$x'");
			$row8=mysqli_fetch_array($qry8);
				$n8=mysqli_num_rows($qry8);
		if($n8==0){
		$rl = "Reloan";
				$qry80=mysqli_query($conn, "select * from user where mfin='$mfin' &&  hpl='$x' &&  status='$rl'");
			$row80=mysqli_fetch_array($qry80);
				$n80=mysqli_num_rows($qry80);
		if($n80==0){
			
					$qry85=mysqli_query($conn, "select * from sizzing where mfin='$mfin' &&  hpl='$x'");
			$row85=mysqli_fetch_array($qry85);
				$n85=mysqli_num_rows($qry85);
		if($n85==0){
			
			$selected_date=$row['hpdate'];
		  	$selected_date=strtotime( $selected_date );
			$mysqldate = date( 'd-m-Y', $selected_date );
			$month = date( 'm', $selected_date );
			$day = date( 'd', $selected_date );
if($day==31){
  $rrno2 = 0;
										

$sql1 = "select sum(paymnt) from user where mfin='$mfin' &&  hpl='$hpl'";
$qt = mysqli_query($conn, $sql1);
$row1 = mysqli_fetch_array($qt);
$sql5=$row1[0];
$sql6=$sql5 + 1;
$nuserpay = $sql5;
$hlbal20 = 0;
$sql155 = "select * from hloan where mfin='$mfin' &&  hpl='$hpl'";
$qt55 = mysqli_query($conn, $sql155);
while($row155 = mysqli_fetch_array($qt55)) {
	$ffh  = $row155['reslt'];
	if($ffh == NULL){
	$hlbal20= $hlbal20 +$row155['actamt2']; }
}
$sql155 = "select sum(postamt2) from otherentry where mfin='$mfin' &&  hpl='$hpl'";
$qt55 = mysqli_query($conn, $sql155);
$row155 = mysqli_fetch_array($qt55);
$hlbal2=$row155[0];

$sql1551 = "select sum(hlamt) from customerdetails where mfin='$mfin' &&  hpl='$hpl'";
$qt551 = mysqli_query($conn, $sql1551);
$row1551 = mysqli_fetch_array($qt551);
$hlbal1=$row1551[0];

$sql1552 = "select sum(hloan) from user where mfin='$mfin' &&  hpl='$hpl'";
$qt552 = mysqli_query($conn, $sql1552);
$row1552 = mysqli_fetch_array($qt552);
$hlbal3=$row1552[0];
$hlbal = $hlbal20 + $hlbal2 - $hlbal1 - $hlbal3;


		$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin' &&  hpl='$hpl'");		
	$row = mysqli_fetch_array($qry);
$tyty=$row['duemnt'];
   $u = $row['total'];
	   $row = str_replace('/', '-', $row['hpdate']);
  $d1 = strtotime($row);
$d2 = strtotime("today");
$min_date = min($d1, $d2);
$max_date = max($d1, $d2);
$i = 0;
while (($min_date = strtotime("+1 DAY", $min_date)) <= $max_date) {
    $i++;
}
$min_date = min($d1, $d2);
$max_date = max($d1, $d2);
$i5 = 0;
while (($min_date = strtotime("+1 MONTH", $min_date)) <= $max_date) {
    $i5++;
}
$iii = $i;
$sql1 = "select sum(paymnt) from user where mfin='$mfin' &&  hpl='$hpl'";
$qt = mysqli_query($conn, $sql1);
$row1 = mysqli_fetch_array($qt);
if($i5>$tyty)
{$i5=$tyty;}
$n444=$row1[0];

$sql12 = "select sum(rno) from user where mfin='$mfin' &&  hpl='$hpl'";
$qt2 = mysqli_query($conn, $sql12);
$row12 = mysqli_fetch_array($qt2);
$crno=$row12[0];
$sql13 = "select sum(pass) from user where mfin='$mfin' &&  hpl='$hpl'";
$qt3 = mysqli_query($conn, $sql13);
$row13 = mysqli_fetch_array($qt3);
$cpass=$row13[0];
$ctot = $crno + $cpass;
$cpaid=$n444;
$cxta = $u * $cpaid;
$cvv = $cxta - $ctot;
$e = $i5 - $n444;
$f = $u * $e + $cvv;
if($e<0){
	$e = 1;
    $f = $u;
}

							$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin' &&  hpl='$hpl'");			
$row = mysqli_fetch_array($qry);
	   $duedat = str_replace('/', '-', $row['hpdate']);
						$pp = $row['duemnt'];
						$addr = $row['address'];
			$damt = $row['total'];		
$intt = $row['inter'];
$prin = $row['dueamt'];			
	$defamt2 = $row['defamt'];	
	$defamt = (($damt*$defamt2)/100)/30;	
  $d1 = strtotime($duedat);
$d2 = strtotime("today");
$min_date = min($d1, $d2);
$max_date = max($d1, $d2);

if($iii>$pp)
{ $iii=$pp; }
$rc = $iii - $sql5 ;
$sql9 = $sql5 + $rc ; $vv = 1; $ii = 1;
 $finep = 0;   $finepp = 0;
$qry5=mysqli_query($conn, "select * from user where mfin='$mfin' && hpl='$hpl' order by paydate2 asc");			
while($row5 = mysqli_fetch_array($qry5)) { $rr = 0;
$duemnt = $row5['paymnt'];
while($rr<$duemnt) { $rr++;
$rno1 = $row5['rno'];
$rno = $rno1/$duemnt;
$pass1 = $row5['pass'];

$pass = $pass1/$duemnt;
$urname1 = $row5['urname'];
$hloan = $row5['hloan'];
$fine1 = $row5['fine'];
$urname = ($urname1 - $hloan - $fine1) /$duemnt;
$duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " month"));
$pday = $row5['paydate'];


  $d11 = strtotime($duedat);
$d22 = strtotime($pday);
$min_date1 = min($d11, $d22);
$max_date1 = max($d11, $d22);
$i6 = 0;
if($d11<=$d22) {
while (($min_date1 = strtotime("+1 DAY", $min_date1)) <= $max_date1) {
    $i6++;
}
}
$i6 = $i6;
$fine2 = $defamt * $i6;
$finep = $finep + $fine2;
$finepp = $finepp + $fine1;
 $ii++; } } while($ii<=$pp) {
	 $duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " month")); 
  $d11 = strtotime($duedat);
$d22 = strtotime("today");
$min_date1 = min($d11, $d22);
$max_date1 = max($d11, $d22);
$i6 = 0;
if($d11<=$d22) {
while (($min_date1 = strtotime("+1 DAY", $min_date1)) <= $max_date1) {
    $i6++;
} }
$i6 = $i6;
if($i6 < 0) {
	$i6 = 0;
}
$fine2 = $defamt * $i6;
if($fine2 < 0) {
	$fine2 = 0;
}
$finep = $finep + $fine2;
  $ii++; }  
  
$fineppp = $finep - $finepp;  
  if($fineppp<0) {
	  $fineppp = 0;
  }
$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin' &&  hpl='$hpl'");
$row=mysqli_fetch_array($qry);
	$sad = $row['duemnt'];
	$vno = $row['vno'];
$pno = $row['pno'];
$cobpno = $row['cobpno'];	
$fine55 = round($fineppp,0);	
$caa = round($fineppp,0);
 $tottt = $f + $hlbal + $caa;	
 if($tottt>0){
$username="senthoor"; 

$password="Somu1712.";

$message="Pls Pay Due ".$e.", Amt Rs.".$tottt.",Default Rs.".$fine55."-HL amt ".$hlbal." for a/c No-".$hpl.",Regn no.".$vno."- Senthoor finance - Ph-04222493068";

$sender="SENTOR"; //ex:INVITE

$mobile_number=$pno;

$url="osm.bulksms5.com/sendmessage.php?user=".urlencode($username)."&password=".urlencode($password)."&mobile=".urlencode($mobile_number)."&message=".urlencode($message)."&sender=".urlencode($sender)."&type=".urlencode('3');

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

echo $curl_scraped_page = curl_exec($ch);

curl_close($ch);

$message1="Pls arrange to pay Due for Veh No-".$vno.",Pending Due-".$e.", Amt-Rs.".$tottt."-Default Rs.".$fine55."- HL Amt ".$hlbal." for your guarantee-For Loan No-".$hpl." -Senthoor Finance";

//ex:INVITE

$mobile_number1=$cobpno;
$url1="osm.bulksms5.com/sendmessage.php?user=".urlencode($username)."&password=".urlencode($password)."&mobile=".urlencode($mobile_number1)."&message=".urlencode($message1)."&sender=".urlencode($sender)."&type=".urlencode('3');

//rlencode($mobile_number1)."&message=".urlencode($message1)."&sender=".urlencode($sender)."&type=".urlencode('3');

$ch1 = curl_init($url1);

curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);

echo $curl_scraped_page1 = curl_exec($ch1);

curl_close($ch1);
 ?>
		<tr><td><?php echo $row['hpl']; ?></td>
						<td><?php echo $row['name']; ?></td>
						<td><?php echo $row['hpdate']; ?></td>
						<td><?php echo $row['pno']; ?></td>
						<td><?php echo $row['total']; ?></td>
						<td><?php echo $lddate; ?></td>
						<td><?php echo $row['duemnt']; ?></td>
						
						<td><?php echo $e; ?></td> 
						<td><?php echo $hlbal; ?></td>
						<td><?php echo $fine55; ?></td>
						<td><?php echo $tottt; ?></td>
						
					</tr>
<?php } } } } } } ?>
			
				</tbody></table>
 </div></div>
 
 
</div>
</div></div>
</div><?php include "layouts/footer.php"; ?></body></html>