<?php ob_start(); session_start(); ?>
	<!DOCTYPE html>
	<html>
	<?php include "../layouts/db_connect.php"; ?>
	<?php 
if(isset($_SESSION['code'])) {
	  $code = $_SESSION['code'];
	  $scode = $_SESSION['code'];
	   
		$staff = $_SESSION['name'];
		 $postt = $_SESSION['postt'];
		  $mfin222 = $_SESSION['mfin222'];
	} 
	?>
		<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		
		<!-- Meta, title, CSS, favicons, etc. -->
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta http-equiv="X-UA-Compatible" content="chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1">
<style>

table, th, td {
    border: 1px solid black;
}
#customers {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    border-collapse: collapse;
    width: 100%;
}

#customers td, #customers th {
    border: 1px solid #ddd;
    padding: 8px;
}

#customers tr:nth-child(even){background-color: #f2f2f2;}

#customers tr:hover {background-color: #ddd;}

#customers th {
    padding-top: 12px;
    padding-bottom: 12px;
    text-align: left;
    background-color: #4CAF50;
    color: white;
}
</style>
		<title>INFOSSEL SOFT SOLUTIONS </title> </head>
		<body>
  
  <?php 		  
  $idd=$_REQUEST['id'];
	$sql=mysqli_query($conn, "select * from pending where id=$idd");
$row=mysqli_fetch_array($sql);
$n = mysqli_num_rows($sql);
 ?>
    <!--  page-wrapper -->
         <div class="right_col" role="main">

            <div class="row">
                <div class="col-lg-12">
                    <!-- Form Elements -->
                    <div class="panel panel-default">
                       
                         <h3><center><font face="Courier New" color="red">Pending</br>
                         <a href="udelete5.php?id=<?php echo $idd; ?>">With Photo</a></br>
                         
                          <a href="udeletec.php?id=<?php echo $idd; ?>">Closing Amt</a></br>
                       
                  

<?php 
	$hpl =$row['hpl'];
	$mfin3 = $row['mfin'];
	$mfin4 =  $row['mfin'];
	//if($mfin3=='SENTHOOR MOTOR FINANCE')
	//{
	//$mfin4 = 'SENTHOOR MOTOR FINANCE';
//	}
//	else {
//	$mfin4 = 'SOORYA MOTOR FINANCE';
//	}
	
$sql2 = mysqli_query($conn, "select * from customerdetails where hpl='$hpl' && mfin='$mfin3'");
$row2 = mysqli_fetch_array($sql2);
$sql24 = mysqli_query($conn, "select * from sizzing where hpl='$hpl' && mfin='$mfin3'");
$nnn = mysqli_num_rows($sql24); ?>
<?php $ff = $row2['lat']; if($ff>0) { ?>	
<a href="https://www.google.com/maps/?q=<?php echo $row2['lat'];?>,<?php echo $row2['lang'];?>"  data-toggle="tooltip" title="Google Map !" title="Full View!" target="_blank">Google Map</a> <?php } ?>
   </font></center></h3>
   <div class="panel-body">
                            <div class="row">
							 <div class="col-lg-6">
<table id="customers">
<thead>
<tr>
<?php
if($nnn>0){
	?>
	<button class="btn btn-danger">Seized Vehicle List</button>
	<?php
}
?>
<th><b><?php echo $row2['name']; ?> : <?php echo $row['hpl']; ?></b></th>

</tr></thead><tbody>

<tr><td><b><font size="2">
 <?php
$sql22 = mysqli_query($conn, "select * from addr where hpl='$hpl' && mfin='$mfin4' order by id asc");
$row3 = mysqli_fetch_array($sql22);
$nn = mysqli_num_rows($sql22);
$iddf = $row3['id'];

if($nn>0) {

$iddf = $row3['id'];
for($i=1;$i<7;$i++){
	$iddf++;
$sql223 = mysqli_query($conn, "select * from addr where id='$iddf'");
$row33 = mysqli_fetch_array($sql223);
	?>
<b><font size="2" color="blue"><?php echo $row33['addr']; ?></font></b></br>
<?php } }  

$sql22 = mysqli_query($conn, "select * from addr where hpl='$hpl' && mfin='$mfin4' order by id asc");
$row3 = mysqli_fetch_array($sql22);
$nn = mysqli_num_rows($sql22);
$iddf = $row3['id'];

if($nn>0) {
?>
<b><font size="2" color="black">Work Address : </font></b></br>
<?php
$iddf = $row3['id'];
for($i=1;$i<7;$i++){
	$iddf++;
$sql223 = mysqli_query($conn, "select * from addr where id='$iddf' order by id asc");
$row33 = mysqli_fetch_array($sql223);
	?>
<b><font size="2" color="blue"><?php echo $row33['oadd']; ?></font></b></br>
<?php } }  ?>
<b><font size="4" color="red"><a href="#<?php echo $row['pno']; ?>">Phone : <?php echo $row2['pno']; ?></a> </font>  </b></br>
<font size="3" color="blue">Phone Office : <?php echo $row2['pnooffice']; ?></br>
Phone Resi :  <?php echo $row2['pnoresi']; ?></font></b></br>
</td></tr>

<tr>
<td><b><font size="2">Area : <?php echo $row2['area']; ?></font></b></td>
</tr>

<th><b>Co-Obligant : <?php echo $row2['cobname']; ?></b></th>
<tr><td><b><font size="2">
 <?php
$sql22 = mysqli_query($conn, "select * from addr where hpl='$hpl' && mfin='$mfin4' order by id asc");
$row3 = mysqli_fetch_array($sql22);
$nn = mysqli_num_rows($sql22);
if($nn>0) {
$iddf = $row3['id'];
for($i=1;$i<7;$i++){
	$iddf++;
$sql22 = mysqli_query($conn, "select * from addr where id='$iddf'");
$row3 = mysqli_fetch_array($sql22);
	?>
<b><font size="2" color="red"><?php echo $row3['co']; ?></font></b></br>
<?php } } ?>

</td></tr>

<th><b>Vehicle : <?php echo $row['vno']; ?></b></th>
<tr>
<td><b><font size="2">Vehicle : <?php echo $row2['vname']; ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">Model : <?php echo $row2['model']; ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">Color  : <?php echo $row2['color']; ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">Engine No  : <?php echo $row2['eno']; ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">Chasis No   : <?php echo $row2['cno']; ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">Broker   : <?php echo $row2['bname']; ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">Dealer   : <?php echo $row2['dealer']; ?></font></b></td>
</tr>
<?php 
$sql2 = mysqli_query($conn, "select * from customerdetails where hpl='$hpl' && mfin='$mfin3'");
$row = mysqli_fetch_array($sql2);
 $n41 = 0; $n42 = 0; $n43 = 0;
	$x = $row['hpl'];
	$sql41 = mysqli_query($conn, "select * from net where hpl='$x' && mfin='$mfin3'");
	$n41 = mysqli_num_rows($sql41);
	$sql42 = mysqli_query($conn, "select * from sizzing where hpl='$x' && mfin='$mfin3'");
	$n42 = mysqli_num_rows($sql42);
	$sql43 = mysqli_query($conn, "select * from user where hpl='$x' && status='Reloan' && mfin='$mfin3'");
	$n43 = mysqli_num_rows($sql43);
	$mfin = $mfin3;
	if(($n41==0)&&($n42==0)&&($n43==0)) {
	$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'];
			$vno = $row['vno'];
			$vname = $row['vname'];
			$model = $row['model'];
			$area = $row['area'];
			$name = $row['name'];
  $rrno2 = 0;
  $mfin = $mfin;
  $aaa = mysqli_query($conn, "select * from bad where hpl='$hpl' && mfin='$mfin'");
  $an = mysqli_num_rows($aaa);
  $aaa1 = mysqli_query($conn, "select * from sizzing where hpl='$hpl' && mfin='$mfin'");
  $an1 = mysqli_num_rows($aaa1);

$rrow44=0;$rrow45=0;
										
									$sql = "SELECT SUM(hpamount) FROM customerdetails where mfin='$mfin' &&  hpl='$hpl'";
                                    $q = mysqli_query($conn, $sql);
                                    $row52 = mysqli_fetch_array($q);	
                                    $rrow44 = $row52[0] + $rrow44;								
									
									$sql = "SELECT SUM(pass) FROM user 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 user ORDER BY id DESC");
$n5=mysqli_num_rows($qry5);
$row5=mysqli_fetch_array($qry5);
											
$qry=mysqli_query($conn, "select * from user where mfin='$mfin' && hpl='$hpl' ORDER BY fid DESC");
						$n=mysqli_num_rows($qry);
						
						if($n==0)
						{
							$sss = 0;
						}
						else
					    {
						$row=mysqli_fetch_array($qry);
						$lddate = $row['paydate'];
						$sss = $row['bal'];
						$newsss = $row['bal'];
						
						}
$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 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 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;

 $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;
						$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'];
$intt2 = $row['interest'];
$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 = 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'];
$rcptno = $row5['roll'];
$fidd = $row5['fid'];
$gi = 0;
$rno1 = $row5['rno'];
$rno = $rno1/$duemnt;
$pass1 = $row5['pass'];
$pday = $row5['paydate'];
$pass = $pass1/$duemnt;
$urname1 = $row5['urname'];
$hloan = $row5['hloan'];
$fine1 = $row5['fine'];
$urname = ($urname1 - $hloan - $fine1) /$duemnt;
$dmm = $urname1 - $hloan - $fine1;
$ff55 = 0;
while($dmm>0) { $gi++; $rr++;
if($ff55 == 0){
	$fine18 = $fine1;
	$hloan8 = $hloan;
}
else {
	$fine18 = 0;
	$hloan8 = 0;
}
$ff55++;
if($sts==0) {
if($dmm>$damt){
	$sts = 1; $less = 0;
	$pamt = $damt;
	$noo++;
}
elseif($dmm==$damt){
	$sts = 0; $less = 0;
	$pamt = $damt;
	$noo++;
}
else{
	$sts = 2;
	$pamt = $dmm;
	$less = $damt - $dmm;
}
$ii++;
$selected_date=$duedat;
		  	$selected_date=strtotime( $selected_date );
			$mysqldate = date( 'd-m-Y', $selected_date );
			$month = date( 'm', $selected_date );
			$day = date( 'd', $selected_date );
			$yyyy = date( 'Y', $selected_date );
if((($day==30)&&($month==01)) || (($day==29)&&($month==01)) || (($day==31)&&($month==01)))	
{
$duedat = "28-02-".$yyyy;
}
else {	
$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++;
}
}
if($i6 <= 3){
    
$fine2 = 0;
} else {
$fine2 = (($defamt/$damt)*($i6 * $pamt)); }
if($fine2 < 0) {
	$fine2 = 0;
}
 $dmm = $dmm - $pamt;
$spfine = $spfine + $fine2;
$spdd = $spdd + $i6; $spdue = $spdue + $pamt;
$spff = $spff + $fine18;
$sphl = $sphl + $hloan8;
 } 

elseif($sts == 1) {
	if($dmm>$damt){
	$sts = 1; $less = 0;
	$pamt = $damt;
	$noo++;
}
elseif($dmm==$damt){
	$sts = 0; $less = 0;
	$pamt = $damt;
	$noo++;
}
else{
	$sts = 2;
	$pamt = $dmm;
	$less = $damt - $dmm;
} $ii++; 
$selected_date=$duedat;
		  	$selected_date=strtotime( $selected_date );
			$mysqldate = date( 'd-m-Y', $selected_date );
			$month = date( 'm', $selected_date );
			$day = date( 'd', $selected_date );
			$yyyy = date( 'Y', $selected_date );
if((($day==30)&&($month==01)) || (($day==29)&&($month==01)) || (($day==31)&&($month==01)))	
{
$duedat = "28-02-".$yyyy;
}
else {	
$duedat = date("d-m-Y", strtotime("$duedat + " . 1 . " month"));
}



  $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++;
}
}
if($i6 <= 3){
    
$fine2 = 0;
} else {
$fine2 = (($defamt/$damt)*($i6 * $pamt)); }
if($fine2 < 0) {
	$fine2 = 0;
}  $dmm = $dmm - $pamt;
$spfine = $spfine + $fine2;
$spdd = $spdd + $i6; $spdue = $spdue + $pamt;
$spff = $spff + $fine18;
$sphl = $sphl + $hloan8;
 } 
else { 
  $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++;
}
}
if($i6 < 3){
    
$fine2 = 0;
} else {
$fine2 = (($defamt/$damt)*($i6 * $less));
 }
if($fine2 < 0) {
	$fine2 = 0;
}
if($less>$dmm){
$dmm2 = $less - $dmm; $noo++;
$less2 = $less  - $dmm2; 
$spdue = $spdue + $less;
$dmm = 0;
if($dmm>$damt){
	$sts = 1;
	$less = 0;
	$pamt = $damt;
	$noo++;
}
elseif($dmm==$damt){
	$sts = 0; $less = 0;
	$pamt = $damt;
	$noo++;
}
else{
	
	$sts = 2;
	$pamt = $less2;
	$less = $dmm2;
}
$pamt = $less2;	
}
else{
$dmm = $dmm - $less; $noo++;
$spdue = $spdue + $less;
if($dmm>$damt){
	$sts = 1;
	$less = 0;
	$pamt = $damt;
	$noo++;
}
elseif($dmm==$damt){
	$sts = 0; $less = 0;
	$pamt = $damt;
	$noo++;
}
else{
	
	$sts = 0;
	$pamt = $dmm;
	$less = 0;
}
$pamt = $dmm; }
 $dmm = $dmm;
$spfine = $spfine + $fine2;
$spdd = $spdd + $i6; $spff = $spff + $fine18;  
$sphl = $sphl + $hloan8;
 }  
$ttp = $ttp + $pass; $tti = $tti + $rno; $ttdue = $ttdue + $urname;	$ttdd = $ttdd + $i6;	
$ttfine = $ttfine + $fine2;	
$ttpf = $fine1 + $ttpf;	$tthl = $tthl + $hloan;	$tttot = $tttot + $urname1;
				
} } 

$qry51=mysqli_query($conn, "select * from net where mfin='$mfin' &&  hpl='$hpl'");
					$n51=mysqli_num_rows($qry51);
					$row51 = mysqli_fetch_array($qry51);
					if($n51>0){  $ttt = $row51['tot'];  $spdue = $spdue + $ttt;	}
else { 
if($less > 0){
	$tday = date('d-m-Y');
  $d11 = strtotime($duedat);
$d22 = strtotime($tday);
  $duedatles = $duedat;
$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++;
}
}
if($i6 < 3){
    
$fine2 = 0;
} else {
$fine2 = (($defamt/$damt)*($i6 * $less));
 }
if($fine2 < 0) {
	$fine2 = 0;
}

$dmm = 0;	
$spfine = $spfine + $fine2;
$spdd = $spdd + $i6;
$sppp = $sppp + $less;
}
$iiii = $ii;
$ii++; $ni = 0;

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++;
} }

if($i6 <= 3){
    
$fine2 = 0;
} else {
$fine2 = $defamt * $i6; }
if($fine2 < 0) {
	$fine2 = 0;
} $ii++; 
$ttdd = $ttdd + $i6;	
$ttfine = $ttfine + $fine2;	
$spfine = $spfine + $fine2;
$spdd = $spdd + $i6;
if($i6>0){
	$ni++;
	$sppdue = $sppdue + $damt;
}
} }
$fine55 = $spfine - $spff;
  $d119 = strtotime($duedatles);
$d229 = strtotime("today");
if($d119>=$d229){
	$spddd = $sppdue;
}
else {
$spddd = $less + $sppdue;
if($less>0){
$iiii = $iiii - 1;
$ni = $ni + 1;
    
}
}
	 $tottt = 0;
 $caa = round($fine55,0); 
 $tottt = ($spddd *1) + ($caa * 1) + ($hlbal * 1);  ?>
<th><b>Loan : <?php echo $row2['hpl']; ?> - <?php echo $row2['name']; ?></b></th>

<tr>
<td><b><font size="2">Loan Date   : <?php echo $row2['hpdate']; ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">Loan Amount   : <?php echo $row2['hpamount']; ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">Due Amt   : <?php echo $row2['total']; ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">Total Dues  : <?php echo $row2['duemnt']; ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">Paid Dues  : <?php echo $iiii; ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">Pend Dues  : <?php echo $ni; ?></font></b></td>
</tr><?php
$a = $row['defamt'];
$b =  $row['penamt'];
$c = $row['hloan'];
$tott = $b - $a - $c;
?>
<tr>
<td><b><font size="2">Pend Amt  : <?php echo round($spddd,0); ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">Def Amount  : <?php echo round($fine55,0); ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">HL Amt  : <?php echo $hlbal; ?></font></b></td>
</tr>

<tr>
<td><b><font size="2">Total Pend  : <?php echo $tottt; ?></font></b></td>
</tr>
<tr>
<td><b><font size="2">Last Paid  : <?php echo $lddate; ?></font></b></td>
  </tr> <?php } else {
	  
	  echo "A/c Closed / Sized ";
	}  ?>


</tbody>

</table>

<a href="https://senthoormotorfinance.in/col/geo2.php?hpl=<?php echo $hpl; ?>&mfin=<?php echo $mfin; ?>">Add Geo Location</a>
</div>

</div></div>
</div></div></div></div></div></div> </body></html>
