<?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-3">  <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-3">   <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-3">      <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:pnl2.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 =  $_REQUEST['fdate']; 
										$tdate = $_REQUEST['tdate']
									//	$fdate =  $rowww['date1']; 
									//	$tdate =  $rowww['date2'];  ?>
					 <input type="button" class="btn btn-primary" value="Print" onclick="PrintElem('#mydiv')"  style="margin:20px;">				<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="3"><b><center>Profit & Loss A/c From <?php echo $fdate; ?> To <?php echo $tdate; ?></b></font></center></th>
					</tr>
						<tr class="success" style="color:purple;">
						<th colspan="2"><font size="3">Particulars</font></th>
						
				
						<th colspan="2"><font size="3">Particulars</font></th>
						
						</tr></thead> <tbody>
									
									<?php $tot111 = 0; $tot222 = 0;
 //Profit & Loss	
	//Direct Income 
	$dincome2 = 0; $dexp2 = 0; $inexp = 0; $ddexp = 0; $ddincome = 0; $inincome = 0;

$sqlu = mysqli_query($conn, "select * from ledger where under='Direct Incomes' && 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];
$ddincome = $ddincome + $openbal + $crasdr - $crascr;
$dincome2 = $dincome2 + $openbal + $crasdr - $crascr;
}
$sqlu = mysqli_query($conn, "select * from ledger where under='Indirect Incomes' && mfin='$mfin'");  
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];
$inincome = $inincome + $openbal + $crasdr - $crascr;
$dincome2 = $dincome2 + $openbal + $crasdr - $crascr;
}
$sdcdoc=mysqli_query($conn, "select sum(document) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$sdcdoc1 = mysqli_fetch_array($sdcdoc);
$sdcdoc11 = $sdcdoc1[0];
$hppass=mysqli_query($conn, "select sum(rno) from user where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass1 = mysqli_fetch_array($hppass);
$hppass111 = $hppass1[0];
$hppass3=mysqli_query($conn, "select sum(fine) from user where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass13 = mysqli_fetch_array($hppass3);
$hppass1113 = $hppass13[0];
$hppass2=mysqli_query($conn, "select sum(amt) from net where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass22 = mysqli_fetch_array($hppass2);
$hppass222 = $hppass22[0];
$hppass23=mysqli_query($conn, "select sum(fine) from net where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass223 = mysqli_fetch_array($hppass23);
$hppass2223 = $hppass223[0];

$mpbchhqry002=mysqli_query($conn, "select sum(rno) from monuser where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$mpbchhrow002 = mysqli_fetch_array($mpbchhqry002);
$mpbchpartuser = $mpbchhrow002[0];
$mpbchhqry003=mysqli_query($conn, "select sum(amt) from monnet where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$mpbchhrow003 = mysqli_fetch_array($mpbchhqry003);
$mpbchpartner = $mpbchhqry003[0];

//$pbchhqry001=mysqli_query($conn, "select sum(hpamount) from fincust where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
//$pbchhrow001 = mysqli_fetch_array($pbchhqry001);
//$pbchhpart = $pbchhrow001[0]; 
$ddincome = $ddincome + $sdcdoc11 + $hppass111 + $hppass1113 + $mpbchpartuser + $mpbchpartner + $hppass222 + $hppass2223;
$dincome = $dincome2 + $sdcdoc11 + $hppass111 + $hppass1113 + $mpbchpartuser + $mpbchpartner + $hppass222 + $hppass2223; //echo $hppass2223; // $clsdcdoc11 - Bcommision

//Direct Expence
$sqlu = mysqli_query($conn, "select * from ledger where under='Direct Expenses' && 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];
$ddexp = $ddexp + $openbal - $crasdr + $crascr;
$dexp2 = $dexp2 + $openbal - $crasdr + $crascr;
}
$sqlu = mysqli_query($conn, "select * from ledger where under='Indirect Expenses' && mfin='$mfin'");   
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];
$inexp = $inexp + $openbal - $crasdr + $crascr;
$dexp2 = $dexp2 + $openbal - $crasdr + $crascr; 
} 
$sdcdoc=mysqli_query($conn, "select sum(bcommission) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$sdcdoc1 = mysqli_fetch_array($sdcdoc);
$sdcdoc11 = $sdcdoc1[0];
$addd=mysqli_query($conn, "select sum(addless) from net where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$addd1 = mysqli_fetch_array($addd);
$addd11 = $addd1[0];
$lesss=mysqli_query($conn, "select sum(addless) from user where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$lesss1 = mysqli_fetch_array($lesss);
$lesss11 = $lesss1[0];
$pbchhqry002=mysqli_query($conn, "select sum(rno) from finuser where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$pbchhrow002 = mysqli_fetch_array($pbchhqry002);
$pbchpartuser = $pbchhrow002[0];
$pbchhqry003=mysqli_query($conn, "select sum(amt) from finnet where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$pbchhrow003 = mysqli_fetch_array($pbchhqry003);
$pbchpartnet = $pbchhrow003[0]; //echo $pbchhpart; echo "asas"; echo $pbchpartuser; echo "asas"; echo $pbchpartnet;
$dexp = $dexp2  + $addd11 + $lesss11 + $pbchpartuser + $pbchpartnet;
$ddexp = $ddexp + $addd11 + $lesss11 + $pbchpartuser + $pbchpartnet;
//Total P & L + $sdcdoc11 bcom

$dtot = $dincome - $dexp;  
//echo $dincome; echo "<>"; echo $dexp;
?>
<tr>
<td><font size="3"><b> Direct Expences</b></font></td>
<td><font size="3"><?php echo $ddexp; ?></b></font></td>
<td><font size="3"><b> Direct Incomes</b></font></td>
<td><font size="3"><b><?php echo $ddincome; ?></b></font></td>
</tr>
<?php $gdtot = $ddincome - $ddexp;
if($gdtot > 0) { $ggp = abs($gdtot) + $ddexp; $tot222 = $tot222 + abs($gdtot);
?>	
<tr>
<td><font size="3"><b> Gross Profit c/o </br> &nbsp;</b></font></td>
<td><font size="3"><b> <?php echo abs($gdtot); ?> </br> <u><?php echo $ggp; ?></u></b></font></td>
<td><font size="3"><b></b></font></td>
<td><font size="3"><b> </br> <u><?php echo $ggp; ?></b></font></td>
</tr>
<tr>
<td><font size="3"><b></b></font></td>
<td><font size="3"><b></b></font></td>
<td><font size="3"><b> Gross Profit b/f</b></font></td>
<td><font size="3"><b> <?php echo abs($gdtot); ?></b></font></td>

</tr>
<?php } else { $ggpg = abs($gdtot) + $ddincome; $tot111 = $tot111 + abs($gdtot);  ?>
<tr>
<td><font size="3"><b></b></font></td>
<td><font size="3"><b></br> <u><?php echo $ggpg; ?></b></font></td>
<td><font size="3"><b> Gross Loss c/o </br> &nbsp;</b></font></td>
<td><font size="3"><b> <?php echo abs($gdtot); ?> </br> <u><?php echo $ggpg; ?></u></b></font></td>
</tr> 
<tr>

<td><font size="3"><b> Gross Loss b/f</b></font></td>
<td><font size="3"><b> <?php echo abs($gdtot); ?></b></font></td>
<td><font size="3"><b></b></font></td>
<td><font size="3"><b></b></font></td>

</tr>
<?php }  ?>
<tr>
<td><font size="3"><b> Indirect Expences</b></font></td>
<td><font size="3"><?php echo $inexp; ?></b></font></td>
<td><font size="3"><b> Indirect Incomes</b></font></td>
<td><font size="3"><b><?php echo $inincome; ?></b></font></td>
</tr>
<?php
if($dtot > 0) { $tot111 = $tot111 + $inexp + abs($dtot); $tot222 = $tot222 + $inincome;
?>	
<tr>
<td><font size="3"><b> Nett Profit </b></font></td>
<td><font size="3"><?php echo $dtot; ?></b></font></td>
<td><font size="3"><b></b></font></td>
<td><font size="3"><b></b></font></td>
</tr> <?php  $tot11 = $tot11 + $dtot;	?>	
<?php } else { $tot111 = $tot111 + $inexp; $tot222 = $tot222 + $inincome + abs($dtot); ?>
<tr>
<td><font size="3"><b></b></font></td>
<td><font size="3"><b></b></font></td>
<td><font size="3"><b> Nett Loss </b></font></td>
<td><font size="3"><?php echo abs($dtot); ?></b></font></td>
</tr> <?php   $tot22 = $tot22 + abs($dtot) ;	?>	
<?php } ?>

		<tr>
<td><font size="3"><b>&nbsp;</b></font></td>
<td><font size="3"><b>&nbsp;</b></font></td>
<td><font size="3"><b>&nbsp;</b></font></td>
<td><font size="3"><b>&nbsp;</b></font></td>
</tr>
	<tr>
<td><font size="3"><b>&nbsp;</b></font></td>
<td><font size="3"><b>&nbsp;</b></font></td>
<td><font size="3"><b>&nbsp;</b></font></td>
<td><font size="3"><b>&nbsp;</b></font></td>
</tr>
	<tr>
<td><font size="3"><b>&nbsp;</b></font></td>
<td><font size="3"><b>&nbsp;</b></font></td>
<td><font size="3"><b>&nbsp;</b></font></td>
<td><font size="3"><b>&nbsp;</b></font></td>
</tr>
	<tr>
<td><font size="3"><b>&nbsp;</b></font></td>
<td><font size="3"><b>&nbsp;</b></font></td>
<td><font size="3"><b>&nbsp;</b></font></td>
<td><font size="3"><b>&nbsp;</b></font></td>
</tr>				
								
				<tr>
<td><font size="3"><b></b></font></td>
					<td><font size="3"><b><?php echo $tot111; ?></b></font></td>
						
						<td><font size="3"><b></b></font></td>
						<td><font size="3"><b><?php echo $tot222; ?></b></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>
