<?php include "layouts/menu.php"; ?>
<div class="right_col" role="main">
            <div class="row">
                 <!-- page header -->
            
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <!-- Form Elements -->
					 <!-- Form Elements -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                         Refresh Pending List
                        </div>
                    
 
    <?php
							
												   $sts2 ="Active";
					  $ii=$day;  $ddd= date("d");
  $stime=$stime;
					  $iii=23000;
  $qry2 = "SELECT * FROM moncust where mfin='$mfin'  && status='Active' 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'];
	
	$tottt = 0; $caa = 0; $fine55 = 0; $hlbal = 0;
	$spdd= 0; $spdue = 0; $spff = 0; $spfine = 0;
	$sppp = 0; $less = 0; $sppdue = 0;
	$spfine = 0; $spddd = 0;
$spdd = 0; $spdue = 0;
$spff = 0;
$sphl = 0;
		
		$hpl = $row['hpl'];
		$hpdate = $row['hpdate'];
			$hpdate5 = $row['hpdate5'];
			$vno = $row['vno'];
			$dd = $row['dd'];
			$pno = $row['pno'];
			$vname = $row['vname']; 		$duemnt55 = $row['duemnt'];
			$model = $row['v1'].",".$row['v2'].",".$row['v3'].",".$row['v4'].",".$row['v5'];
			$area = $row['area'];
			$name = $row['name'];
				$eno  = $row['eno'];
	$cno  = $row['cno'];
	$bname  = $row['bname'];
	$color  = $row['color'];
	$hpamt  = $row['hpamount'];
	$lat  = $row['lat'];
	$lang  = $row['lang'];
	$sch  = $row['sch'];
	$uimg  = $row['uimg'];
	$img  = $row['img'];
	$gi1  = $row['g1'];
	$bi1  = $row['b1'];
	$profession  = $row['profession'];
	$rdate  = $row['rdate'];
	$remarks  = $row['remarks'];
	$cobname  = $row['cobname'];
			$netgram  = $row['netgram'];
	
  $rrno2 = 0;
  $mfin = $mfin;
$rrow44=0;$rrow45=0;
										
									$sql = "SELECT SUM(hpamount) FROM moncust where mfin='$mfin' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql);
                                    $row52 = mysqli_fetch_array($q);	
                                    $rrow44 = $row52[0] + $rrow44;								
									
									$sql = "SELECT SUM(pass) FROM monuser where mfin='$mfin' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql);
                                    $row53 = mysqli_fetch_array($q);	
                                    $rrow45 = $row53[0] + $rrow45;																			
									
									
									 $rrow445= $rrow44 - $rrow45;  $rrno2 = 0;
$qry5=mysqli_query($conn, "select * from monuser ORDER BY id DESC");
$n5=mysqli_num_rows($qry5);
$row5=mysqli_fetch_array($qry5);
											
$qry=mysqli_query($conn, "select * from monuser where mfin='$mfin' && hpl='$hpl' ORDER BY fid DESC");
						$n=mysqli_num_rows($qry);
						
						if($n==0)
						{
							$sss = 0;
							$lddate = "-";
						}
						else
					    {
						$row=mysqli_fetch_array($qry);
						$lddate = $row['paydate'];
						$sss = $row['bal'];
						$newsss = $row['bal'];
						
						}
 $rrow44=0;$rrow45=0;
																		
									
									
									 $rrow445= $rrow44 - $rrow45; 
 $rrno2 = 0;
$qry5=mysqli_query($conn, "select * from monuser where hpl='$hpl' && mfin='$mfin' order by fid desc");
$n5=mysqli_num_rows($qry5);
$row5=mysqli_fetch_array($qry5);
$fromm = $row5['fromm'];
$too2 = $row5['too'];
$ff = NULL;
if($too2 == $ff) { $too2 = $row5['paydate']; }
$result = mysqli_query($conn, "SELECT MAX(rno) FROM roll where mfin='$mfin'");
$row = mysqli_fetch_array($result);
$rrno2 =  $row[0];
$rrno = $rrno2 + 1;

$qry=mysqli_query($conn, "select * from moncust where mfin='$mfin' &&  hpl='$hpl'");
$row=mysqli_fetch_array($qry);
	$sad = $row['duemnt'];
		$hpamt = $row['hpamount'];
		$inter = $row['inter'];
		$remarks = $row['remarks'];
		$sch = $row['sch'];
		$pinter = $row['pinter'];
if($n5 == 0) { 
if($pinter>0){
$qwerty = $row['hpdate5']; 
$too2 = date("Y-m-d", strtotime("$qwerty + " . 1 . " month")); 
}
else{
$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++;
} }
if($i66==0){
	$i6 = 0;
	$iy6 = 0;
}
else{
$i6 = $i66 + 1;
$iy6 = $i6;

////// interest calculation part
$qry522q=mysqli_query($conn, "select * from monuser where hpl='$hpl' && mfin='$mfin'");
$nq1 = mysqli_num_rows($qry522);
if($nq1 == 0){
	if($i6<7){
$i6 = 7;
}
	else{
$i6 = ceil($i6 / 7) * 7;
	}
}
else{
	$i6 = ceil($i6 / 7) * 7;
}
}
$iz = $i6 - $iy6;
$tdat = date('Y-m-d');
$tdat2 = date("Y-m-d", strtotime("$tdat + " . $iz . " day"));
$qry522=mysqli_query($conn, "select sum(pass) from monuser where hpl='$hpl' && mfin='$mfin'");
$row522 = mysqli_fetch_array($qry522);
$paidprin = $row522[0];
$balprin = $hpamt - $paidprin;
$inpday = ($balprin * ($inter / 100))/30;
$interest = round(($inpday * $i6),0);
$tds = 0;
$tottt = $balprin + $interest;


$sql155 = "select sum(actamt2) from hloan where mfin='$mfin' && type!='COLLECTION' && hpl='$hpl'";
$qt55 = mysqli_query($conn, $sql155);
$row155 = mysqli_fetch_array($qt55); 
	$hlbal20= $row155[0]; 
$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 moncust where mfin='$mfin' &&  hpl='$hpl'";
$qt551 = mysqli_query($conn, $sql1551);
$row1551 = mysqli_fetch_array($qt551);
$hlbal1=$row1551[0];

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

 $noo = 0; $less = 0; $spdue= 0 ; $spfine = 0; $spdd = 0;
			$ttp = 0;	$tti = 0; $ttdue = 0;	$ttdd = 0;	$ttfine = 0;	$ttpf = 0;	$tthl = 0;	
				$tttot = 0;	
				$qdue = 0; $qdue25 = 0;
			$ttp = 0;	$tti  = 0; $ttdue = 0;	$ttdd = 0;	$ttfine = 0;	$ttpf = 0;	$tthl = 0;	
				$tttot = 0;	$dmm = 0; $sts = 0;
					
 $caa = round($fine55,0); 
 //$tottt = ($spddd *1) + ($caa * 1) + ($hlbal * 1); 
 $qry29=mysqli_query($conn, "select * from msch where name='$sch'");
								   $row29 = mysqli_fetch_array($qry29);
$hh = $row29['hh'];
$oo = $row29['oo'];
$gtyp = $row29['details'];
$pros = $row29['pros'];
$pg = $row29['pgram'];
$pg2 = $row29['pgram2'];
$dumn = $row29['edate'];

//$inter = $row29['inter'];
$intert = $row29['intert'];
$gdays11 = round(($gdays*($pg/100)),0);

$gdays1 = floor($gdays11/10)*10;
$gdays2 = round(($gdays*($pg2/100)),0);
	$duedat55 = date("d-m-Y", strtotime("$hpdate5 + " . $dumn . " month"));
$defday = $dymn * 30;
  $d111 = strtotime($duedat55);
    $d1111 = strtotime($hpdate5);

$d222 = strtotime("today");

$min_date1 = min($d1111, $d222);
$max_date1 = max($d1111, $d222);
$ni = 0;
if($d1111<=$d222) {
while (($min_date1 = strtotime("+1 DAY", $min_date1)) <= $max_date1) {
    $ni++;
}
}
if($d111<=$d222){
	$star = "*";
}
else{
	$star = NULL;
}

// if($tottt>0){
     $sql44 = mysqli_query($conn, "select * from monpending where hpl='$hpl' && mfin='$mfin'");
     $n447 = mysqli_num_rows($sql44);
     $row44 = mysqli_fetch_array($sql44);
     if($n447>0){
		 $ddate = date("Y-m-d");
         $delete2=mysqli_query($conn, "delete from monpending where mfin='$mfin' && hpl='$hpl'");
         	$insert=mysqli_query($conn, "insert into monpending(ddd,dd,defday,tpdue,ddate,hpamt,lat,lang,uimg,img,gi1,bi1,profession,rdate,remarks,cobname,mfin,hpl,vno,vname,model,hpdate,hlbal,penamt,pendmnt,hloan,fname,area,pno,cobpno,star)
											 values('$netgram','$inter','$defday','$tottt','$hpdate5','$hpamt','$pgram','$dumn','$uimg','$img','$gi1','$bi1','$profession','$duedat55','$remarks','$cobname','$mfin','$hpl','$balprin','$interest','$model','$hpdate','$hlbal','$tottt','$ni','$hlbal','$name','$area','$pno','$cobpno','$sch')");
								
         
     }
     else{ $ddate = date("Y-m-d");
$insert=mysqli_query($conn, "insert into monpending(ddd,dd,defday,tpdue,ddate,hpamt,lat,lang,uimg,img,gi1,bi1,profession,rdate,remarks,cobname,mfin,hpl,vno,vname,model,hpdate,hlbal,penamt,pendmnt,hloan,fname,area,pno,cobpno,star)
											 values('$netgram','$inter','$defday','$tottt','$hpdate5','$hpamt','$pgram','$dumn','$uimg','$img','$gi1','$bi1','$profession','$duedat55','$remarks','$cobname','$mfin','$hpl','$balprin','$interest','$model','$hpdate','$hlbal','$tottt','$ni','$hlbal','$name','$area','$pno','$cobpno','$sch')");
										 }
// }

	
 ?>
	
								<?php   }   
								echo "Process Completed Successfully .";
								

 ?>
			
				</tbody></table>
 </div></div>
 
 
</div>
</div></div>
</div><?php include "layouts/footer.php"; ?></body></html>