<?php include "layouts/menu.php"; ?> <div class="right_col" role="main">
  <script>
function add()
{
var a = document.getElementById("n2000").value;
var b = document.getElementById("n500").value;
var bb = document.getElementById("n200").value;
var c = document.getElementById("n100").value;
var d = document.getElementById("n50").value;
var e = document.getElementById("n10").value;
var f = document.getElementById("coins").value;
document.getElementById("tot").value =(a*2000)+(b*500)+(bb*200)+(c*100)+(d*50)+(e*10)+(f*1);
}
</script>   
    <?php $tot=$_REQUEST['tot'];
	$ddd=$_REQUEST['ddd'];
	?>
   <div class="row">
          
                <!--end page header -->
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <!-- Form Elements -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            ACCOUNT Close
                        </div>
                        <div class="panel-body">
                            <div class="row">
   <div class="alert alert-info">    ACCOUNT Close </div>
  <?php
  	$g = 0;$rrow68=0; $ftr = 0;
$rrow2 =0 ;$rrow3 =0 ;$rrow3 =0 ;$rrow4 =0 ;$rrow5 =0 ;$rrow6 =0 ;$rrow7 =0 ;$rrow8 =0 ;$rrow9 =0 ;$rrow10 =0 ;$rrow21 =0 ;$rrow71 =0 ;
$rrow519 =0 ;$rrow59 =0 ;$rrow144 =0 ;$rrow14 =0 ;$rrow1 = 0;$rrow212 = 0; $rrow39 = 0;$rrow92=0;$rrow51119=0;$rrow5119=0;
								$fdate = $ddd;
								$tdate = $ddd;
								
							
                                   $paydate = $fdate;
									$sql = "SELECT SUM(invest) FROM invest where mfin='$mfin' &&  date between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row1 = mysqli_fetch_array($q);
									$rrow1 = $row1[0] + $rrow1;								   

									$sql = "SELECT SUM(rno) FROM user where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $qy = mysqli_query($conn, $sql);
                                    $row2 = mysqli_fetch_array($qy);
									$rrow2 = $row2[0] + $rrow2;
									
									$sql = "SELECT SUM(rno) FROM user where mfin='$mfin' && status!='Reloan' &&  paydate2 between '$fdate' and '$tdate'";
                                    $qy = mysqli_query($conn, $sql);
                                    $row00002 = mysqli_fetch_array($qy);
									$int = $row00002[0] ;
									
									$sql = "SELECT SUM(amt) FROM net where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row21 = mysqli_fetch_array($q);
									$rrow21 = $row21[0];
									
									$sql = "SELECT SUM(dueamt) FROM net where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row0021 = mysqli_fetch_array($q);
									$rrow0021 = $row0021[0];
									
									$sql = "SELECT SUM(addless) FROM net where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row110021 = mysqli_fetch_array($q);
									$addless = $row110021[0];
								
									$sql = "SELECT SUM(fin) FROM net where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row212 = mysqli_fetch_array($q);
                                    $rrow212 = $row212[0] + $rrow212;
									
									$sql = "SELECT SUM(document) FROM customerdetails where mfin='$mfin' &&  hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row3 = mysqli_fetch_array($q);
									$rrow3 = $row3[0] + $rrow3;

									$sql = "SELECT SUM(bcommission) FROM customerdetails where mfin='$mfin' &&  hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row33 = mysqli_fetch_array($q);
									$rrow39 = $row33[0] + $rrow39;

									$sql = "SELECT SUM(fine) FROM user where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row4 = mysqli_fetch_array($q);	
                                    $rrow4 = $row4[0] + $rrow4;									

                					$sql = "SELECT SUM(urname) FROM user2 where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row7 = mysqli_fetch_array($q);
									$rrow7 = $row7[0] + $rrow7;

									$sql = "SELECT SUM(amt) FROM net2 where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row71 = mysqli_fetch_array($q);
									$rrow71 = $row71[0] + $rrow71;

                					$sql = "SELECT SUM(bal) FROM bank where mfin='$mfin' &&  date between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row5 = mysqli_fetch_array($q);
									$rrow5 = $row5[0] + $rrow5;

									$sql = "SELECT SUM(urname) FROM user where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row666 = mysqli_fetch_array($q);
                                    $row6[0] = $row666[0] -  $row2[0] - $row4[0];
									$rrow6 = $row6[0] + $rrow6;
									
									$sql = "SELECT SUM(pass) FROM user where mfin='$mfin' && status!='Reloan' && paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row69 = mysqli_fetch_array($q);
                                   $rrow68 = $row69[0];
								   
								   
							$sql = "SELECT SUM(urname) FROM user where mfin='$mfin' && status='Reloan' && paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $rrr1 = mysqli_fetch_array($q);
                                   $reloan1 = $rrr1[0];
								  
							$sql = "SELECT SUM(fine) FROM user where mfin='$mfin' && status='Reloan' && paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $rrr2 = mysqli_fetch_array($q);
                                   $reloan2 = $rrr2[0];
								   
					      $sql = "SELECT SUM(hloan) FROM user where mfin='$mfin' && status='Reloan' && paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $rrr3 = mysqli_fetch_array($q);
                                   $reloan3 = $rrr3[0];
									
									$sql = "SELECT SUM(tot) FROM net where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row519 = mysqli_fetch_array($q);
									$rrow519 = $row519[0] + $rrow519;
									
									$sql = "SELECT SUM(fine) FROM net where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row519000 = mysqli_fetch_array($q);
									$rrow0005 = $row519000[0];
									
									
									$sql = "SELECT COUNT(hpl) FROM net where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row5199 = mysqli_fetch_array($q);
									$rrow5119 = $row5199[0] + $rrow5119;
									
									$sql = "SELECT COUNT(hpl) FROM sizzing where mfin='$mfin' && sizdate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row51999 = mysqli_fetch_array($q);
									$rrow51119 = $row51999[0] + $rrow51119;

									$sql = "SELECT SUM(urname) FROM user where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row59 = mysqli_fetch_array($q);
									$rrow59 = $row59[0] + $rrow59;

									$sql = "SELECT SUM(dueamt) FROM net2 where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row144 = mysqli_fetch_array($q);
									$rrow144 = $row144[0] + $rrow144;
									
									$sql = "SELECT SUM(debit) FROM debit where mfin='$mfin' &&  date between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row7 = mysqli_fetch_array($q);
									$rrow7 = $row7[0] + $rrow7;

									$sql = "SELECT SUM(debit) FROM salary where mfin='$mfin' &&  date between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row8 = mysqli_fetch_array($q);
									$rrow8 = $row8[0] + $rrow8;

									$sql = "SELECT SUM(hpamount) FROM customerdetails where mfin='$mfin' &&  hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row9 = mysqli_fetch_array($q);
									$rrow9 = $row9[0] + $rrow9;
									
									$sql = "SELECT COUNT(hpl) FROM customerdetails where mfin='$mfin' &&  hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row95 = mysqli_fetch_array($q);
									$rrow92 = $row95[0] + $rrow92;
									
									$sql = "SELECT SUM(hloan) FROM user where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $rowhhl59 = mysqli_fetch_array($q);
									$hl1 = $rowhhl59[0];
									
									$sql = "SELECT SUM(hloan) FROM net where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $rowhl59 = mysqli_fetch_array($q);
									$hl2 = $rowhl59[0];
									
									
									
									$sql = "SELECT SUM(hpamount) FROM customer where mfin='$mfin' &&  hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row14 = mysqli_fetch_array($q);			
									$rrow14 = $row14[0] + $rrow14;
									$princ = $rrow68 + 	$rrow0021 - $addless + $reloan1 - $reloan2 - $reloan3;
									$hl = $hl1 + $hl2;
									
									$def = $rrow4 + $rrow0005;
									$int2 = $rrow21 + $int;
									$rrow49 = $rrow3 + $int2;
								$rrow393 = $rrow39 + $rrow7;
								$rrow3933 = $rrow49 - $rrow393;
								$rrowr9 = $rrow9 - $rrow68;
								$rrow5199=$rrow519  + $rrow59;
								
								$tott = $hl + $princ + $int2 + $def;
								$qry=mysqli_query($conn, "select * from customerdetails where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
								$n=mysqli_num_rows($qry);
							while($row=mysqli_fetch_array($qry))
  { 
							$hpl = $row['hpl'];								  
									$qry12=mysqli_query($conn, "select * from net where mfin='$mfin' &&  hpl=$hpl");
									$v4=mysqli_num_rows($qry12); 
									$qry122=mysqli_query($conn, "select * from sizzing where mfin='$mfin' &&  hpl=$hpl");
									$v44=mysqli_num_rows($qry122); 
								  if(($v4 == 0) and ($v44 == 0)) 
								  {
									 $g++;
								  }
								  }

								  
								  
								  
								  
								  
								
								$ctot = 0; $ctott = 0;
								$fdate2 = date("1990-02-28");
								$tdate2 = $tdate;
							
								$paydate1 = $fdate2;

								$sql01 = "SELECT * FROM customerdetails where mfin='$mfin' &&  hpdate5 between '$fdate2' and '$tdate2'";
                                    $q01 = mysqli_query($conn, $sql01);
                                    $c01 = mysqli_num_rows($q01);
									$sql02 = "SELECT * FROM net where mfin='$mfin' &&  paydate2 between '$fdate2' and '$tdate2'";
                                    $q02 = mysqli_query($conn, $sql02);
                                    $c02 = mysqli_num_rows($q02);
									$sql03 = "SELECT * FROM sizzing where mfin='$mfin' &&  sizdate2 between '$fdate2' and '$tdate2'";
                                    $q03 = mysqli_query($conn, $sql03);
                                    $c03 = mysqli_num_rows($q03);
									$ctot =$ctot + $c01 - $c02 - $c03;
									
									
									$sql011 = "SELECT SUM(hpamount) FROM customerdetails where mfin='$mfin' &&  hpdate5 between '$fdate2' and '$tdate2'";
                                    $q011 = mysqli_query($conn, $sql011);
                                    $c012 = mysqli_fetch_array($q011);
									$sql022 = "SELECT SUM(tot) FROM net where mfin='$mfin' &&  paydate2 between '$fdate2' and '$tdate2'";
                                    $q022 = mysqli_query($conn, $sql022);
                                    $c022 = mysqli_fetch_array($q022);
									$sql0223 = "SELECT SUM(amt) FROM net where mfin='$mfin' &&  paydate2 between '$fdate2' and '$tdate2'";
                                    $q0223 = mysqli_query($conn, $sql0223);
                                    $c0223= mysqli_fetch_array($q0223);
									$sql02233 = "SELECT SUM(fine) FROM net where mfin='$mfin' &&  paydate2 between '$fdate2' and '$tdate2'";
                                    $q02233 = mysqli_query($conn, $sql02233);
                                    $c02234= mysqli_fetch_array($q02233);
									$sql033 = "SELECT SUM(pass) FROM user where mfin='$mfin' &&  paydate2 between '$fdate2' and '$tdate2'";
                                    $q033 = mysqli_query($conn, $sql033);
                                    $c033 = mysqli_fetch_array($q033);
									
									
									
									$rtr = $c022[0] - $c0223[0];
									$ctottt = $c012[0]  - $c033[0] - $c02234[0];
									$ctott = $ctott + $ctottt - $rtr;
									$ftr = $ftr + $rtr + $c033[0]; 
								
								
								
						?><center><table  width="800px" border="1" height="300px" ><tr ><td colspan="4"><font size="5">	<?php	
								echo '<center> Closing</center>';?></font></td></tr>
								<tr><td colspan="4"><font size="4">	
                                       <?php  echo '<center> Date From: ' . $qas1;								
									 echo '    To: ' . $qas2;	echo '</center>';?></font></td></tr>
									 
									 <tr><td><font size="4">	&nbsp;<?php							
                                    echo 'Total Collection: ' ?></font></td><td align="right"><font size="4">	<?php echo  $rrow5199;?>&nbsp;</td><td><font size="4">&nbsp;
									<?php	echo 'Denamination Amt: ' ?></td></font><td align="right"><font size="4"><?php echo  $tot;?>&nbsp;</font></td></tr>
									
									<tr><td><font size="4">&nbsp;<?php $dddd = $rrow5199 - $tot;
										
									echo 'Net : ' ?></td></font><td align="right"><font size="4"><?php echo  $dddd;?>&nbsp;</font></td><td><font size="4">&nbsp;
									
									</font></td><td align="right"><font size="4">&nbsp;</font></td></tr>
									
									</font></table></center>
									</p></b>
</div>
 	
                                </div><!-- /.box-body -->
                            </div><!-- /.box -->
 
 
</div>
</div></div>
</div></div></div> <?php include "layouts/footer.php"; ?></body></html>