<?php include "layouts/menu.php"; 
 date_default_timezone_set("Asia/Kolkata"); 
?>
<script>
        function printDiv() {
            var divContents = document.getElementById("mydivv").innerHTML;
            var a = window.open('', '', 'height=500, width=500');
            a.document.write('<html>');
            a.document.write('<body > <h1>Report <br>');
            a.document.write(divContents);
            a.document.write('</body></html>');
            a.document.close();
            a.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" placeholder="DD/MM/YYYY" value="<?php echo date("1990-01-01"); ?>" 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" placeholder="DD/MM/YYYY" value="<?php echo date('Y-m-d'); ?>" 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>
  
    <div class="alert alert-success">
  <b><p style="color:#1928CF;margin:10px;">
   <input type="button" value="Print it" onclick="printDiv()"> 
<div id="mydivv">
<?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 ; $errow7 =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;
									$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 customerdetails where mfin='$mfin' && status='Active' hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $row51999 = mysqli_fetch_array($q);
									$rrow51119 = $row51999[0] + $rrow51119;
									$gold = 0;
									$sql = "SELECT COUNT(hpl) FROM customerdetails where mfin='$mfin' && color='Gold' && status='Active' && hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $goldd = mysqli_fetch_array($q);
									$gold = $goldd[0];
									
									$sql = "SELECT sum(hpamount) FROM customerdetails where mfin='$mfin' && color='Gold' && status='Active' && hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $goldda = mysqli_fetch_array($q);
									$goldhp = $goldda[0];
									
									$sql = "SELECT sum(netgram) FROM customerdetails where mfin='$mfin' && color='Gold' && status='Active' && hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $golddan = mysqli_fetch_array($q);
									$goldn = $golddan[0];
									
									$sql = "SELECT COUNT(hpl) FROM customerdetails where mfin='$mfin' && color='Silver' && status='Active' && hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $sgoldd = mysqli_fetch_array($q);
									$sgold = $sgoldd[0];
									
									$sql = "SELECT sum(hpamount) FROM customerdetails where mfin='$mfin' && color='Silver' && status='Active' && hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $sgoldda = mysqli_fetch_array($q);
									$sgoldhp = $sgoldda[0];
									
									$sql = "SELECT sum(netgram) FROM customerdetails where mfin='$mfin' && color='Silver' && status='Active' && hpdate5 between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $sgolddan = mysqli_fetch_array($q);
									$sgoldn = $sgolddan[0];
									

									$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;
									
									
								
									$qry40123 = mysqli_query($conn, "SELECT * FROM ledger where under='Direct Expenses' && mfin='$mfin'");
									while($rtow = mysqli_fetch_array($qry40123)){
									$dexpy = $rtow['ledger'];
									$sql = "SELECT SUM(dr) FROM voucher where vtype='Payment' && par='$dexpy' && mfin='$mfin' &&  date between '$fdate' and '$tdate'";
                                    $q = mysqli_query($conn, $sql);
                                    $erow7 = mysqli_fetch_array($q);
									$errow7 = $erow7[0] + $errow7;
									}

									$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);
                                    
                                    	$sql0154 = "SELECT * FROM customerdetails where mfin='$mfin' && status='Active'";
                                    $q0154 = mysqli_query($conn, $sql0154);
                                    $c0154 = mysqli_num_rows($q0154);
                                    
                                    
									$ctot =$c0154;
									
									
									$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(dueamt) 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] - $c0223[0];
									$ctott = $ctottt;
									$ftr = $ftr + $rtr + $c033[0]; 
								
								
								
						?><center><table  width="800px" border="1" height="300px" ><tr ><td colspan="4"><font size="5">	<?php	
								echo '<center> MONTHLY STATEMENT </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 'Interest Received: ' ?></td></font><td align="right"><font size="4"><?php echo  $int2;?>&nbsp;</font></td></tr>
									
									<tr><td><font size="4">&nbsp;<?php
										
									echo 'Total Loan Amount: ' ?></td></font><td align="right"><font size="4"><?php echo  $rrow9;?>&nbsp;</font></td><td><font size="4">&nbsp;
									
									<?php	 echo 'Principle Recived : ' ?></font></td><td align="right"><font size="4"><?php echo  $princ;	?>&nbsp;</font></td></tr>
									
									<tr><td><font size="4">&nbsp;<?php

									
                                   echo 'Total New Loan: ' ?></td></font><td align="right"><font size="4"><?php echo  $rrow92;?>&nbsp;</font></td><td><font size="4">&nbsp;
									
									<?php	 echo 'Document Charge : ' ?></font></td><td align="right"><font size="4"><?php echo  $rrow3;	?>&nbsp;</font></td></tr>
									
									<tr><td><font size="4">&nbsp;<?php
									
                                   echo 'Total Closed Loan: ' ?></font></td><td align="right"><font size="4"><?php echo  $rrow5119;  ?>&nbsp;</font></td><td><font size="4">&nbsp;
								   <?php   echo 'Default Amount : ' ?></font></td><td align="right"><font size="4"><?php echo  $def;	?>&nbsp;</font></td></tr>
								   
								  
								   
								   <tr><td><font size="4">&nbsp;<?php

                                	echo 'Gold Packets : ' ?></td><td align="right"><font size="4"><?php echo $gold;	?>&nbsp;</td><td><font size="4">&nbsp;
									<?php      echo 'Hand Loan: ' ?></td><td align="right"><font size="4"><?php echo $hl;		?>&nbsp;</td></tr>
										
										<tr><td><font size="4">&nbsp;<?php

                                	echo 'Gold L.Amount : ' ?></td><td align="right"><font size="4"><?php echo $goldhp;	?>&nbsp;
									</font></td><td><font size="4">&nbsp;
								   <?php   echo 'Total: ' ?></font></td><td align="right"><font size="4"><?php echo  $tott;	?>&nbsp;</font></td></tr>
								   
								   
										 <tr><td><font size="4">&nbsp;<?php

                                	echo 'Gold Weight : ' ?></td><td align="right"><font size="4"><?php echo $goldn;	?>&nbsp;</font></td><td><font size="4">&nbsp;
								   
								   <?php       echo 'Commission Charge : ' ?></td><td align="right"><font size="4"><?php echo  $rrow39;	?>&nbsp;</td></tr>
								   
								   
										
								   
									<tr><td><font size="4">&nbsp;<?php

                                	echo 'Silver Packets : ' ?></td><td align="right"><font size="4"><?php echo $sgold;	?>&nbsp;
									
									</font></td><td><font size="4">&nbsp;
								   <?php   echo 'Expenses: ' ?></font></td><td align="right"><font size="4"><?php echo  $errow7;	?>&nbsp;</font></td></tr>
								   
								
								   
									
									<tr><td><font size="4">&nbsp;<?php

                                	echo 'Silver L.Amount : ' ?></td><td align="right"><font size="4"><?php echo $sgoldhp;	?>&nbsp;</td><td><font size="4">&nbsp;
						<?php      
									echo 'Net Profit : ' ?></td><td align="right"><font size="4"><?php $rrow3933555 = $int2 + $rrow3 +  $def +$hl - $rrow39 - $errow7; echo $rrow3933555; ?>&nbsp;</td></tr>
									
									
									
								   
								   
								   
								   
									
									
									
									<tr><td><font size="4">&nbsp;<?php

                                	echo 'Silver Weight : ' ?></td><td align="right"><font size="4"><?php echo $sgoldn;	?>&nbsp;<td><font size="4">&nbsp;
									<?php
									 echo 'Total OutStanding Balance(principal) :' ?></td><td align="right"><font size="4"><?php echo $ctott;  
									}
									?>&nbsp;</td></tr></font></table></center>
									</p></b>
			</form>
			</div>
			</div>
</div>
</div></div>
</div></div></div><?php include "layouts/footer.php"; ?></body></html>
