<?php include "layouts/menu.php"; ?>    
  <!--  page-wrapper -->
         <div class="right_col" role="main">
       
            <div class="row">
                <div class="col-lg-12">
                    <!-- Form Elements -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                             Balance Sheet
                        </div>
                        <div class="panel-body">
                           <div class="row">
							
				        <form id="demo-form2" data-parsley-validate class="form-horizontal form-label-left" method="post"  enctype="multipart/form-data">
  <div class="col-md-4">  <input type="date" class="form-control thicker" id="datepicker" name="fdate" value="<?php echo date("Y-m-d"); ?>" placeholder="From Date" onfocus="insertDate(this,'DD-MM-YYYY')">
    </div>
    <div class="col-md-4">   <input type="date" class="form-control thicker" id="datepicker" name="tdate" value="<?php echo date("Y-m-d"); ?>" placeholder="To Date" onfocus="insertDate(this,'DD-MM-YYYY')">
   </div>
 
   <div class="col-md-4">      <button type="submit" class="btn btn-info" name="s15">Show It</button></div>
              
            
                        <div class="card-box table-responsive">
                          
                                        <?php
		
								if(isset($_POST['s15']))
								{
									extract($_POST);
									
									header("location:bals2.php?fdate=$fdate&&tdate=$tdate");
								} ?></div> </form> </div>
								
                            <div class="row">
							<?php $e=0;  $s=0;  $r=0;  $t=0; $d=0; $d1=0; $i=1; $tot11 = 0; $tot22 = 0;
											$sqll = mysqli_query($conn, "select * from abc");
	$rowww = mysqli_fetch_array($sqll);
	$fdate = "1990-04-31";
										$fdate1 =  $_REQUEST['fdate']; 
										$tdate = $_REQUEST['tdate'];   ?>
									 <input type="button" class="btn btn-primary" value="Print" onclick="PrintElem('#mydiv')"  style="margin:20px;"> <a href="balss.php"><button class="btn btn-warning">Detailed</button></a>				<div class="table-responsive my div" id="mydiv">
   <table id="datatable-buttons" id="datatable-buttons" class="table table-striped table-bordered" border="1">   <thead>
				<tr class="danger" style="color:purple;">
<th colspan="4"><font color="blue" size="4" color="blue"><b><center>Balance Sheet From <?php echo $fdate1; ?> To <?php echo $tdate; ?></b></font></center></th>
					</tr>
						<tr class="success" style="color:purple;">
						<th colspan="2" width="50%"><font size="4" color="blue">Particulars</font></th>
						
				
						<th width="25%"><font size="4" color="blue">Credit</font></th>
							<th width="25%"><font size="4" color="blue">Debit</font></th>
						
						</tr></thead> <tbody>
									
									<?php

// Current Liablities // Sundery Creditors
$curlia2 = 0; $drdeb = 0; $crcre = 0;
$sqluu = mysqli_query($conn, "select * from ledger where under='Sundry Creditors' && mfin='$mfin'");  
while($rowuu = mysqli_fetch_array($sqluu)){
		$ledg = $rowuu['ledger']; $rrf = 0; $openbal = 0; $crasdr = 0; $crascr = 0;
$sqlu = mysqli_query($conn, "select * from ledger where under='$ledg' && mfin='$mfin'");   $capvccdr =0; $capvcccr =0; $fir++;
while($rowu = mysqli_fetch_array($sqlu)){
	$ledgername = $rowu['ledger'];
$openbal = $rowu['openbal'];	
$yn = $rowu['yn'];
$cass11=mysqli_query($conn, "select sum(dr) from voucher where mfin='$mfin' && vtype='Payment' && par='$ledgername' && date between '$fdate' and '$tdate'");
$cass1 = mysqli_fetch_array($cass11); $casss2 = 0;
$cass22=mysqli_query($conn, "select sum(cr) from voucher where mfin='$mfin' && vtype='Receipt' && par='$ledgername' && date between '$fdate' and '$tdate'");
$cass23 = mysqli_fetch_array($cass22);

$crascr = $cass1[0];
$crasdr = $cass23[0];
$vv1 = 0;
$vv1 = $openbal + $crasdr - $crascr; 
//$gfgfgfgf =  $openbal - $crasdr + $crascr;
//echo $ledgername; echo $gfgfgfgf;
$drdeb = $drdeb + $crasdr;
$crcre = $crcre + $crascr;
$curlia2 = $curlia2 + $openbal - $crasdr + $crascr;
//echo $ledgername; echo $vv1; echo "<>";
} 
}
$ff = NULL;
$clsdcdoc=mysqli_query($conn, "select sum(bcommission) from customerdetails where mfin='$mfin' && bname='Sethupathy' && hpdate5 between '$fdate' and '$tdate'");
$clsdcdoc1 = mysqli_fetch_array($clsdcdoc);
$clsdcdoc11 = $clsdcdoc1[0];





//////////////////////////////////////////////////////////// Broker 
$bdealc = 0; $bdeald = 0; $bdealo = 0;
$sqlu = mysqli_query($conn, "select * from ledger where under='Broker' && mfin='$mfin'");   $capvccdr =0; $capvcccr =0; $fir++;
while($rowu = mysqli_fetch_array($sqlu)){
	$ledgername = $rowu['ledger'];
$openbal = $rowu['openbal'];	
$yn = $rowu['yn'];
$cass11=mysqli_query($conn, "select sum(dr) from voucher where mfin='$mfin' && par='$ledgername' && date between '$fdate' and '$tdate'");
$cass1 = mysqli_fetch_array($cass11); $casss2 = 0;
$cass22=mysqli_query($conn, "select sum(cr) from voucher where mfin='$mfin' &&  par='$ledgername' && date between '$fdate' and '$tdate'");
$cass23 = mysqli_fetch_array($cass22);

$crasdr = $cass1[0];
$crascr = $cass23[0];
$bdealo = $bdealo + $openbal;
$bdeald = $bdeald + $crasdr;
$bdealc = $bdealc + $crascr;
}
$clsdcdoc=mysqli_query($conn, "select sum(bcommission) from customerdetails where mfin='$mfin' && dealeramt<='0' && hpdate5 between '$fdate' and '$tdate'");
$clsdcdoc1 = mysqli_fetch_array($clsdcdoc);
$bclsdcdoc11 = $clsdcdoc1[0];
$brkbb = $bdealo  + $bdeald - $bdealc - $bclsdcdoc11; 
//////////////////////////////////////////////////////////// Broker 





//////////////////////////////////////////////////////////// Dealer 
$dealc = 0; $deald = 0; $dealo = 0;
$sqlu = mysqli_query($conn, "select * from ledger where under='Dealer' && mfin='$mfin'");   $capvccdr =0; $capvcccr =0; $fir++;
while($rowu = mysqli_fetch_array($sqlu)){
	$ledgername = $rowu['ledger'];
$openbal = $rowu['openbal'];	
$yn = $rowu['yn'];
$cass11=mysqli_query($conn, "select sum(dr) from voucher where mfin='$mfin' && par='$ledgername' && date between '$fdate' and '$tdate'");
$cass1 = mysqli_fetch_array($cass11); $casss2 = 0;
$cass22=mysqli_query($conn, "select sum(cr) from voucher where mfin='$mfin' &&  par='$ledgername' && date between '$fdate' and '$tdate'");
$cass23 = mysqli_fetch_array($cass22);

$crasdr = $cass1[0];
$crascr = $cass23[0];
$dealo = $dealo + $openbal;
$deald = $deald + $crasdr;
$dealc = $dealc + $crascr;
}
$clsdcdoc22=mysqli_query($conn, "select sum(dealeramt) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$clsdcdoc122 = mysqli_fetch_array($clsdcdoc22);
$clsdcdoc1122 = $clsdcdoc122[0]; 

$ddclsdcdoc=mysqli_query($conn, "select sum(bcommission) from customerdetails where mfin='$mfin' && dealeramt>'0' && hpdate5 between '$fdate' and '$tdate'");
$ddclsdcdoc1 = mysqli_fetch_array($ddclsdcdoc);
$ddbclsdcdoc11 = $ddclsdcdoc1[0];

$dealera = $dealo  + $deald - $dealc - $clsdcdoc1122 - $ddbclsdcdoc11; 
//////////////////////////////////////////////////////////// Dealer 



//////////////////////////////////////////////////////////// Coolection Agent 
$coldealc = 0; $coldeald = 0; $coldealo = 0; $hlcolag = 0;
$sqlu = mysqli_query($conn, "select * from ledger where under='Collection Agent' && mfin='$mfin'");   $capvccdr =0; $capvcccr =0; $fir++;
while($rowu = mysqli_fetch_array($sqlu)){
	$ledgername = $rowu['ledger'];
	if($ledgername != 'DIRECT COLLECTION') {
$openbal = $rowu['openbal'];	
$yn = $rowu['yn'];
$cass11=mysqli_query($conn, "select sum(dr) from voucher where mfin='$mfin' && par='$ledgername' && date between '$fdate' and '$tdate'");
$cass1 = mysqli_fetch_array($cass11); $casss2 = 0;
$cass22=mysqli_query($conn, "select sum(cr) from voucher where mfin='$mfin' &&  par='$ledgername' && date between '$fdate' and '$tdate'");
$cass23 = mysqli_fetch_array($cass22);


$clsdcdoc22=mysqli_query($conn, "select sum(actamt2) from hloan where mfin='$mfin' && agent='$ledgername' && mode='$ledgername' && date2 between '$fdate' and '$tdate'");
$clsdcdoc122 = mysqli_fetch_array($clsdcdoc22);
$hlcolag = $hlcolag + $clsdcdoc122[0]; 


$crasdr = $cass1[0];
$crascr = $cass23[0];
$coldealo = $dealo + $coldealo;
$coldeald = $coldeald + $crasdr;
$coldealc = $coldealc + $crascr;
	}
}

$colagent = $coldealo  + $coldeald - $coldealc - $hlcolag; 
//////////////////////////////////////////////////////////// Coolection Agent  



/////////////////////////////////////////////////////////// Direct Collection
$clsdcdoc22=mysqli_query($conn, "select sum(actamt2) from hloan where mfin='$mfin' && agent='DIRECT COLLECTION' && mode='DIRECT COLLECTION' && date2 between '$fdate' and '$tdate'");
$clsdcdoc122 = mysqli_fetch_array($clsdcdoc22);
$ddcol1 = $clsdcdoc122[0];  $ddcol2 = 0;
$ddcol = $ddcol2 - $ddcol1;
/////////////////////////////////////////////////////////// Direct Collection
$suncrec = 0; $suncred = 0;
	?></p>

<tr>
<td colspan="2" width="50%"><font size="4" color="blue"><a href="baldealer.php?fdate=<?php echo $fdate1; ?>&tdate=<?php echo $tdate; ?>">Dealer</a></font></td>
<?php if($dealera > 0) { $suncred = $suncred + $dealera;  ?>
<td width="25%"><font size="4" color="blue"></font></td>
<td width="25%"><font size="4" color="blue"><?php echo $dealera; ?></font></td>

<?php } else { $suncrec = $suncrec + abs($dealera); ?>

<td width="25%"><font size="4" color="blue"><?php echo abs($dealera); ?></font></td>
<td width="25%"><font size="4" color="blue"></font></td>
<?php } ?>
</tr>

<tr>
<td colspan="2" width="50%"><font size="4" color="blue"><a href="balbrk.php?fdate=<?php echo $fdate1; ?>&tdate=<?php echo $tdate; ?>">Broker</a></font></td>
<?php if($brkbb > 0) { $suncred = $suncred + $brkbb;  ?>
<td width="25%"><font size="4" color="blue"></font></td>
<td width="25%"><font size="4" color="blue"><?php echo $brkbb; ?></font></td>

<?php } else { $suncrec = $suncrec + abs($brkbb); ?>

<td width="25%"><font size="4" color="blue"><?php echo abs($brkbb); ?></font></td>
<td width="25%"><font size="4" color="blue"></font></td>
<?php } ?>
</tr>

<tr>
<td colspan="2" width="50%"><font size="4" color="blue"><a href="balcol.php?fdate=<?php echo $fdate1; ?>&tdate=<?php echo $tdate; ?>">Collection Agent</a></font></td>
<?php if($colagent > 0) { $suncred = $suncred + $colagent;  ?>
<td width="25%"><font size="4" color="blue"></font></td>
<td width="25%"><font size="4" color="blue"><?php echo $colagent; ?></font></td>

<?php } else { $suncrec = $suncrec + abs($colagent); ?>

<td width="25%"><font size="4" color="blue"><?php echo abs($colagent); ?></font></td>
<td width="25%"><font size="4" color="blue"></font></td>
<?php } ?>
</tr>

<tr>
<td colspan="2" width="50%"><font size="4" color="blue"><a href="baldirc.php?fdate=<?php echo $fdate1; ?>&tdate=<?php echo $tdate; ?>">Direct Collection</a></font></td>
<?php if($ddcol > 0) { $suncred = $suncred + $ddcol;  ?>
<td width="25%"><font size="4" color="blue"></font></td>
<td width="25%"><font size="4" color="blue"><?php echo $ddcol; ?></font></td>

<?php } else { $suncrec = $suncrec + abs($ddcol); ?>

<td width="25%"><font size="4" color="blue"><?php echo abs($ddcol); ?></font></td>
<td width="25%"><font size="4" color="blue"></font></td>
<?php } ?>
</tr>

<tr>
<td width="25%" colspan="2"><font size="4" color="blue">Total</font></td>
<td width="25%"><font size="4" color="blue"><?php echo abs($suncrec); ?></font></td>
<td width="25%"><font size="4" color="blue"><?php echo abs($suncred); ?></font></td>

</tr>

					

					
					</tbody></table>	</form>
					
</div>
</div></div>
</div></div></div><footer>
          <div class="pull-right">
             <a href="https://infossel.com">Infossel Soft Solution</a>
          </div>
          <div class="clearfix"></div>
        </footer>
        <!-- /footer content -->
      </div>
    </div>

    <!-- jQuery -->
    <script src="vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="vendors/nprogress/nprogress.js"></script>
    <!-- iCheck -->
    <script src="vendors/iCheck/icheck.min.js"></script>
    <!-- Datatables -->
    <script src="vendors/datatables.net/js/jquery.dataTables.min.js"></script>
    <script src="vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
    <script src="vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
    <script src="vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
    <script src="vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
    <script src="vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
    <script src="vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
    <script src="vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
    <script src="vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
    <script src="vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
    <script src="vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
    <script src="vendors/datatables.net-scroller/js/dataTables.scroller.min.js"></script>
    <script src="vendors/jszip/dist/jszip.min.js"></script>
    <script src="vendors/pdfmake/build/pdfmake.min.js"></script>
    <script src="vendors/pdfmake/build/vfs_fonts.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="build/js/custom.min.js"></script>

  </body>
</html>
