<?php include "layouts/menu.php"; 
 date_default_timezone_set("Asia/Kolkata"); 
?>
<script type="text/javascript">  
    function PrintDiv() 
   {  
       var divContents = document.getElementById("printdivcontent").innerHTML;  
       var printWindow = window.open('', '', 'height=200,width=400');  
       printWindow.document.write('<html><head><title>Print DIV Content</title>');  
       printWindow.document.write('</head><body >');  
       printWindow.document.write(divContents);  
       printWindow.document.write('</body></html>');  
       printWindow.document.close();  
       printWindow.print();  
    }  
</script>
  <!--  page-wrapper -->
         <div class="right_col" role="main">
            <div class="row">
                 <!-- page header -->
          
                <!--end page header -->
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <!-- Form Elements -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                         Statement   Details
                        </div>
                        <div class="panel-body">
                            <div class="row">

				
   <div class="alert alert-info">Statement For Paid Dues</div>
    <form class="form-horizontal" method="post" action="" enctype="multipart/form-data">
    <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Enter From Date</label>
    <div class="col-sm-4">
    <input type="date" class="form-control" id="datepicker" name="fdate" value="<?php echo date('Y-m-d');?>" placeholder="DD/MM/YYYY" onfocus="insertDate(this,'DD-MM-YYYY')">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Enter To Date</label>
    <div class="col-sm-4">
    <input type="date" class="form-control" id="datepicker" name="tdate" value="<?php echo date('Y-m-d');?>" placeholder="DD/MM/YYYY" onfocus="insertDate(this,'DD-MM-YYYY')">
    </div>
  </div>
			<div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-default" name="s15">Total</button>
    </div>
  </div>
   
<?php
								if(isset($_POST['s15']))
								{
									extract($_POST);
									$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;
								$qas1 = $fdate;
								$qas2 = $tdate;
			 $paydate = $fdate;

///Interest 
	$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(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] ;
		$int2 = $rrow21 + $int;
///Interest 

//// Principle 
			$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(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];									
		
		$princ = $rrow68 + 	$rrow0021 - $addless;
//// Principle 
///// savings

$sql = "SELECT SUM(hloan) 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(hloan) 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 SUM(samt) FROM mcust where mfin='$mfin' &&  edate between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $erow519000 = mysqli_fetch_array($q);
									$errow0005 = $erow519000[0];									
		$savings = $rrow4 + $rrow0005 + $errow0005;
///////savings
////// entry fee
$sql = "SELECT SUM(efee) FROM mcust where mfin='$mfin' &&  edate between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $eerow519000 = mysqli_fetch_array($q);
									$eerrow0005 = $eerow519000[0];
		$efee = $eerrow0005;
////// entry fee
////// insu new loan fee
$sql = "SELECT SUM(document) FROM customerdetails where mfin='$mfin' &&  hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $nrow519000 = mysqli_fetch_array($q);
									$nlfee = $nrow519000[0];
$sql = "SELECT SUM(ifee) FROM customerdetails where mfin='$mfin' &&  hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $irow519000 = mysqli_fetch_array($q);
									$insu = $irow519000[0];
/////insu
//////  loan amount
$sql = "SELECT SUM(hpamount) FROM customerdetails where mfin='$mfin' &&  hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row9 = mysqli_fetch_array($q);
									$hploan = $row9[0];
/////// loan amount
////// total expence

									
$sql = "SELECT SUM(dr) FROM voucher where vtype='Payment' && mfin='$mfin' &&  date between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $soerow7 = mysqli_fetch_array($q);
									$errow7 = $soerow7[0];
									

//////expence
////// remitance
$sql = "SELECT SUM(cr) FROM voucher2 where vtype='Payment' && par='$mfin' &&  date between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $rsoerow7 = mysqli_fetch_array($q);
									$remcre = $rsoerow7[0];
$sql = "SELECT SUM(dr) FROM voucher2 where vtype='Payment' && par='$mfin' &&  date between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $rrsoerow7 = mysqli_fetch_array($q);
									$remdeb = $rrsoerow7[0];
///////expence
///////credit
$osql = "SELECT SUM(cr) FROM voucher where vtype='Receipt' && mfin='$mfin' &&  date between '$fdate' and '$tdate'";
                                    $oq = mysqli_query($conn, $osql);
                                    $cocsoerow7 = mysqli_fetch_array($oq);
									$cocc = $cocsoerow7[0];

									
///////savings
$sosql = "SELECT SUM(actamt2) FROM hloan where mfin='$mfin' && date2 between '$fdate' and '$tdate'";
                                    $soq = mysqli_query($conn, $sosql);
                                    $ssorrsoerow7 = mysqli_fetch_array($soq);
									$sref = $ssorrsoerow7[0];
								$ctot = 0; $ctott = 0;
								$fdate2 = date("1970-01-01");
								//$tdate2 = $tdate;
								$tdate2 = date("Y-m-d", strtotime("$tdate - " . 1 . " day"));

							$paydate1 = $fdate2;

/////////////////// old opening data

///Interest 
	$osql = "SELECT SUM(amt) FROM net where mfin='$mfin' &&  paydate2 between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $orow21 = mysqli_fetch_array($oq);
									$orrow21 = $orow21[0];
									
		$osql = "SELECT SUM(rno) FROM user where mfin='$mfin' && status!='Reloan' &&  paydate2 between '$fdate2' and '$tdate2'";
                                    $oqy = mysqli_query($conn, $osql);
                                    $orow00002 = mysqli_fetch_array($oqy);
									$oint = $orow00002[0] ;
		$oint2 = $orrow21 + $oint;
///Interest 

//// Principle 
			$osql = "SELECT SUM(pass) FROM user where mfin='$mfin' && status!='Reloan' && paydate2 between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $orow69 = mysqli_fetch_array($oq);
                                   $orrow68 = $orow69[0];
			$osql = "SELECT SUM(dueamt) FROM net where mfin='$mfin' &&  paydate2 between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $orow0021 = mysqli_fetch_array($oq);
									$orrow0021 = $orow0021[0];
$osql = "SELECT SUM(addless) FROM net where mfin='$mfin' &&  paydate2 between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $orow110021 = mysqli_fetch_array($oq);
									$oaddless = $orow110021[0];									
		
		$oprinc = $orrow68 + 	$orrow0021 - $oaddless;
//// Principle 
///// savings

$osql = "SELECT SUM(hloan) FROM user where mfin='$mfin' &&  paydate2 between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $orow4 = mysqli_fetch_array($oq);	
                                    $orrow4 = $orow4[0] + $orrow4;	
									
	$osql = "SELECT SUM(hloan) FROM net where mfin='$mfin' &&  paydate2 between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $orow519000 = mysqli_fetch_array($oq);
									$orrow0005 = $orow519000[0];
	$osql = "SELECT SUM(samt) FROM mcust where mfin='$mfin' &&  edate between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $oerow519000 = mysqli_fetch_array($oq);
									$oerrow0005 = $oerow519000[0];									
		$osavings = $orrow4 + $orrow0005 + $oerrow0005;
///////savings
////// entry fee
$osql = "SELECT SUM(efee) FROM mcust where mfin='$mfin' &&  edate between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $oeerow519000 = mysqli_fetch_array($oq);
									$oeerrow0005 = $oeerow519000[0];
		$oefee = $oeerrow0005;
////// entry fee
////// insu new loan fee
$osql = "SELECT SUM(document) FROM customerdetails where mfin='$mfin' &&  hpdate5 between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $onrow519000 = mysqli_fetch_array($oq);
									$onlfee = $onrow519000[0];
$osql = "SELECT SUM(ifee) FROM customerdetails where mfin='$mfin' &&  hpdate5 between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $oirow519000 = mysqli_fetch_array($oq);
									$oinsu = $oirow519000[0];
/////insu
//////  loan amount
$osql = "SELECT SUM(hpamount) FROM customerdetails where mfin='$mfin' &&  hpdate5 between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $orow9 = mysqli_fetch_array($oq);
									$ohploan = $orow9[0];
/////// loan amount
////// total expence
$osql = "SELECT SUM(dr) FROM voucher where vtype='Payment' && par='ppooOffice Maintanace' && mfin='$mfin' &&  date between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $ooerow7 = mysqli_fetch_array($oq);
									$oomain = $ooerow7[0];
$osql = "SELECT SUM(dr) FROM voucher where vtype='Payment' && mfin='$mfin' &&  date between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $osoerow7 = mysqli_fetch_array($oq);
									$oerrow7 = $osoerow7[0];
$osql = "SELECT SUM(cr) FROM voucher where vtype='Receipt' && mfin='$mfin' &&  date between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $ocsoerow7 = mysqli_fetch_array($oq);
									$occ = $ocsoerow7[0];

//////expence
////// remitance
$osql = "SELECT SUM(cr) FROM voucher2 where vtype='Payment' && par='$mfin' &&  date between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $orsoerow7 = mysqli_fetch_array($oq);
									$oremcre = $orsoerow7[0];
$osql = "SELECT SUM(dr) FROM voucher2 where vtype='Payment' && par='$mfin' &&  date between '$fdate2' and '$tdate2'";
                                    $oq = mysqli_query($conn, $osql);
                                    $orrsoerow7 = mysqli_fetch_array($oq);
									$oremdeb = $orrsoerow7[0];
////// remitance
////// saving refund
$sosql = "SELECT SUM(actamt2) FROM hloan where mfin='$mfin' && date2 between '$fdate2' and '$tdate2'";
                                    $soq = mysqli_query($conn, $sosql);
                                    $sorrsoerow7 = mysqli_fetch_array($soq);
									$osref = $sorrsoerow7[0];
									
$otottc = $oprinc + $oint2 + $osavings + $oefee + $oinsu + $onlfee + $oremcre + $occ;
$otottd = $ohploan + $oremdeb +  $oerrow7 + $osref;
$oopen = $otottc - $otottd;
$tottc = $princ + $int2 + $savings + $efee + $insu + $nlfee + $remcre + $cocc;
$tottd = $hploan + $remdeb +  $errow7 + $sref;
$closing = $oopen + $tottc - $tottd;
						?><center>
   <input type="button" onclick="PrintDiv();" value="Print" /> 
    <div id="printdivcontent" > 
<center><b><h1><b>Account Statement- <?php echo $mfin; ?> </h1><h2> </br> <b>Daily Summary - <?php echo $tdate; ?> (<?php echo $scode; ?>)</h1>


   	<table width="100%">
	<tr><td><center><h2><b>Opening Balance  Rs : <?php echo $oopen; ?></h2></center></td><td>
	<center><h2><b>Closing Balance Rs : <?php echo $closing; ?></h2></center></td></tr>
	<tr><td><table  border="1" width="400px" border="1"  >
<tr><td><b>Title</td><td>Amount</td></tr>
<tr><td><b>Principal Amount Collected </td><td><b><?php echo  $princ;	?></td></tr>
<tr><td><b>Interest Amount Collected </td><td><b><?php echo  $int2;?></td></tr>
<tr><td><b>Savings Amount Collected </td><td><b><?php echo  $savings;	?></td></tr>
<tr><td><b>Entry Fee </td><td><b><?php echo  $efee;	?></td></tr>
<tr><td><b>Insurance Fee </td><td><b><?php echo  $insu;	?></td></tr>
<tr><td><b>New Loan Fee</td><td><b><?php echo  $nlfee;	?></td></tr>
<tr><td><b>Remittance</td><td><b><?php echo  $remcre;	?></td></tr>
<?php 
$errow7 = 0;
	$qry40123 = mysqli_query($conn, "SELECT * FROM voucher where vtype='Receipt' && cr>'0' && mfin='$mfin' &&  date between '$fdate' and '$tdate'");
									while($rtow = mysqli_fetch_array($qry40123)){
									$cdexpy = $rtow['par'];
									$cdamtytt = $rtow['cr'];
									
 ?>
<tr><td><b><?php echo $cdexpy; ?></td><td><b> <?php echo  $cdamtytt;	?></td></tr>
<?php  } ?>
</table>




	   </td><td><table width="400px" border="1" >
<tr><td><b>Title</td><td> <b>Amount</td></tr>
<tr><td><b>Total Loan Given</td><td> <b><?php echo  $hploan;?></td></tr>

<?php if($remdeb>0){ ?>
<tr><td><b>Remittance</td><td> <b><?php echo  $remdeb;	?></td></tr>
<?php } ?>
<?php if($sref>0){ ?>
<tr><td><b>Savings Refund</td><td><b> <?php echo  $sref;	?></td></tr>
<?php } ?>
<?php 
$errow7 = 0;
	$qry401237 = mysqli_query($conn, "SELECT * FROM voucher where vtype='Payment' && dr>'0' && mfin='$mfin' &&  date between '$fdate' and '$tdate'");
									while($rtow = mysqli_fetch_array($qry401237)){
									$dexpy = $rtow['par'];
									$damtytt = $rtow['dr'];
									
 ?>
<tr><td><b><?php echo $dexpy; ?></td><td><b> <?php echo  $damtytt;	?></td></tr>
<?php  } ?>
</table>


	   </td></tr>
 <tr><td><center><h2><b>Total Income <?php echo $tottc; ?></h2></center>

</td><td> <center><h2><b>Total Expenses <?php echo $tottd;	?></h2></center></td></tr>
	 <tr><td colspan="2">
<table width="400px" border="1"  >
<?php
$tdy = date("Y-m-d");
$rsql = mysqli_query($conn, "select * from acc where date='$tdate'");
$row46 = mysqli_fetch_array($rsql); ?>
<h2><b>Cash Denomination</b></h2>
<tr><td>2000</td><td>x</td><td><?php echo $row46['n2000']; ?></td><td>=</td><td><?php echo $tg = $row46['n2000'] * 2000; ?></td></tr>
<tr><td>500</td><td>x</td><td><?php echo $row46['n500']; ?></td><td>=</td><td><?php echo $tg = $row46['n500'] * 500; ?></td></tr>
<tr><td>200</td><td>x</td><td><?php echo $row46['n200']; ?></td><td>=</td><td><?php echo $tg = $row46['n200'] * 200; ?></td></tr>
<tr><td>100</td><td>x</td><td><?php echo $row46['n100']; ?></td><td>=</td><td><?php echo $tg = $row46['n100'] * 100; ?></td></tr>
<tr><td>50</td><td>x</td><td><?php echo $row46['n50']; ?></td><td>=</td><td><?php echo $tg = $row46['n50'] * 50; ?></td></tr>
<tr><td>20</td><td>x</td><td><?php echo $row46['n20']; ?></td><td>=</td><td><?php echo $tg = $row46['n20'] * 20; ?></td></tr>
<tr><td>10</td><td>x</td><td><?php echo $row46['n10']; ?></td><td>=</td><td><?php echo $tg = $row46['n10'] * 10; ?></td></tr>
<tr><td>5</td><td>x</td><td><?php echo $row46['coins5']; ?></td><td>=</td><td><?php echo $tg = $row46['coins5'] * 5; ?></td></tr>
<tr><td>2</td><td>x</td><td><?php echo $row46['coins2']; ?></td><td>=</td><td><?php echo $tg = $row46['coins2'] * 2; ?></td></tr>
<tr><td>1</td><td>x</td><td><?php echo $row46['coins']; ?></td><td>=</td><td><?php echo $tg = $row46['coins'] * 1; ?></td></tr>
<tr><td colspan="3">Total</td><td><b><?php echo $tg = $row46['tot']; ?></td></tr>
</table>
</td>
</tr>	 
	   
	   </table>

</br>
</br>
<h3><center><b>Employee : 
<?php $ssc = $scode; 
$sqlu = mysqli_query($conn, "select * from customer where code='$ssc'");
$rowu = mysqli_fetch_array($sqlu);
echo $rowu['name']; ?> - <?php echo $scode; ?>

</br>
Date & Time : <?php echo date('d-m-Y h:i:sa'); ?></b>

</center></h3>
</div>	
								<?php } ?>
			</form>
			</div>
			</div>
</div>
</div></div>
</div></div></div><?php include "layouts/footer.php"; ?></body></html>
