<?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">Liablities</font></th>
						
				
						<th colspan="2" width="50%"><font size="4" color="blue">Assets</font></th>
						
						</tr></thead> <tbody>
									
									<?php

 

$sqlu = mysqli_query($conn, "select * from ledger where under='Current Assets' && mfin='$mfin'");   $capvccdr =0; $capvcccr =0; $fir++;
while($rowu = mysqli_fetch_array($sqlu)){
	$ledgername = $rowu['ledger'];
$openbal = $rowu['openbal'];	
$yn = $rowu['yn'];
	
$qrya145=mysqli_query($conn, "select sum(dr) from voucher where mfin='$mfin' && vtype='Payment' && par='$ledgername' && date between '$fdate' and '$tdate'");
$rowa145 = mysqli_fetch_array($qrya145);
$qryb145=mysqli_query($conn, "select sum(cr) from voucher where mfin='$mfin' && vtype='Receipt' && par='$ledgername' && date between '$fdate' and '$tdate'");
$rowb145 = mysqli_fetch_array($qryb145);

$capvccdr = $rowa145[0];
$capvcccr = $rowb145[0];
$captot = $openbal - $capvccdr + $capvcccr;

if($rrf == 0) {
	$curasname = $ledg;
	$captot11 = $captot;
 } 
 
} 	
//Hp Customer(s)
$sdcdoc=mysqli_query($conn, "select sum(hpamount) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$sdcdoc1 = mysqli_fetch_array($sdcdoc);
$sdcdoc11 = $sdcdoc1[0];
$dsdcdoc=mysqli_query($conn, "select sum(dealeramt) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$dsdcdoc1 = mysqli_fetch_array($dsdcdoc);
$dsdcdoc11 = $dsdcdoc1[0];
$hppass=mysqli_query($conn, "select sum(pass) from user where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass1 = mysqli_fetch_array($hppass);
$hppass111 = $hppass1[0];
$hppass2=mysqli_query($conn, "select sum(dueamt) from net where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass22 = mysqli_fetch_array($hppass2);
$hppass222 = $hppass22[0];
/////////////week
$sdcdocw=mysqli_query($conn, "select sum(hpamount) from customerdetailsw where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$sdcdoc1w = mysqli_fetch_array($sdcdocw);
$sdcdoc11w = $sdcdoc1w[0];
$dsdcdocw=mysqli_query($conn, "select sum(dealeramt) from customerdetailsw where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$dsdcdoc1w = mysqli_fetch_array($dsdcdocw);
$dsdcdoc11w = $dsdcdoc1w[0];
$hppassw=mysqli_query($conn, "select sum(pass) from userw where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass1w = mysqli_fetch_array($hppassw);
$hppass111w = $hppass1w[0];
$hppass2w=mysqli_query($conn, "select sum(dueamt) from netw where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass22w = mysqli_fetch_array($hppass2w);
$hppass222w = $hppass22w[0];
////////////dc
$sdcdocm=mysqli_query($conn, "select sum(hpamount) from customerdetailsm where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$sdcdoc1m = mysqli_fetch_array($sdcdocm);
$sdcdoc11m = $sdcdoc1m[0];
$dsdcdocm=mysqli_query($conn, "select sum(dealeramt) from customerdetailsm where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$dsdcdoc1m = mysqli_fetch_array($dsdcdocm);
$dsdcdoc11m = $dsdcdoc1m[0];
$hppassm=mysqli_query($conn, "select sum(pass) from userm where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass1m = mysqli_fetch_array($hppassm);
$hppass111m = $hppass1m[0];
$hppass2m=mysqli_query($conn, "select sum(dueamt) from netm where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass22m = mysqli_fetch_array($hppass2m);
$hppass222m = $hppass22m[0];

$hpparty = $sdcdoc11 - $hppass111 - $hppass222 + $sdcdoc11w - $hppass111w - $hppass222w + $sdcdoc11m - $hppass111m - $hppass222m;

$msdcdoc=mysqli_query($conn, "select sum(hpamount) from moncust where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$msdcdoc1 = mysqli_fetch_array($msdcdoc);
$msdcdoc11 = $msdcdoc1[0];
$mdsdcdoc=mysqli_query($conn, "select sum(dealeramt) from moncust where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$mdsdcdoc1 = mysqli_fetch_array($mdsdcdoc);
$mdsdcdoc11 = $mdsdcdoc1[0];
$mhppass=mysqli_query($conn, "select sum(pass) from monuser where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$mhppass1 = mysqli_fetch_array($mhppass);
$mhppass111 = $mhppass1[0];
$mhppass2=mysqli_query($conn, "select sum(dueamt) from monnet where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$mhppass22 = mysqli_fetch_array($mhppass2);
$mhppass222 = $mhppass22[0];

$mhpparty = $msdcdoc11 - $mhppass111 - $mhppass222;

if($rrf == 0) {
	$curasname = $ledg;
	$captot11 = $captot;
 }
//Sundry Deptor
$ssdcdoc=mysqli_query($conn, "select sum(hloan) from user where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$ssdcdoc1 = mysqli_fetch_array($ssdcdoc);
$ssdcdoc11 = $ssdcdoc1[0];
$cssdcdoc=mysqli_query($conn, "select sum(hlamt) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$cssdcdoc1 = mysqli_fetch_array($cssdcdoc);
$cssdcdoc11 = $cssdcdoc1[0];
$saddd=mysqli_query($conn, "select sum(hloan) from net where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$saddd1 = mysqli_fetch_array($saddd);
$saddd11 = $saddd1[0];
$hsaddd=mysqli_query($conn, "select sum(actamt2) from hloan where mfin='$mfin' && date2 between '$fdate' and '$tdate'");
$hsaddd1 = mysqli_fetch_array($hsaddd);
$hsaddd11 = $hsaddd1[0]; //fin loan int
$fissdcdoc=mysqli_query($conn, "select sum(rno) from finuser where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$fissdcdoc1 = mysqli_fetch_array($fissdcdoc);
$fissdcdoc11 = $fissdcdoc1[0];
$fisaddd=mysqli_query($conn, "select sum(amt) from finnet where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$fisaddd1 = mysqli_fetch_array($fisaddd);
$fisaddd11 = $fisaddd1[0];

$mfissdcdoc=mysqli_query($conn, "select sum(rno) from monuser where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$mfissdcdoc1 = mysqli_fetch_array($mfissdcdoc);
$mfissdcdoc11 = $mfissdcdoc1[0];
$mfisaddd=mysqli_query($conn, "select sum(amt) from monnet where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$mfisaddd1 = mysqli_fetch_array($mfisaddd);
$mfisaddd11 = $mfisaddd1[0];


$sdept = $hsaddd11 - $ssdcdoc11 - $saddd11 - $cssdcdoc11;
//echo $hsaddd11; echo "<>";   echo $ssdcdoc11; echo "<>";  echo $saddd11; echo "<>";   echo $fissdcdoc11; echo "<>";   echo $fisaddd11; echo "<>"; 

//total Current Asset
$curass = 	$cassin + $banka + $hpparty + $sdept;	


// Current Liablities // Sundery Creditors
$curlia2 = 0; $drdeb = 0; $crcre = 0;
$sqluu = mysqli_query($conn, "select * from ledgerg 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 "<>";
} 
}
$clsdcdoc=mysqli_query($conn, "select sum(bcommission) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$clsdcdoc1 = mysqli_fetch_array($clsdcdoc);
$clsdcdoc11 = $clsdcdoc1[0];
$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]; //echo $drdeb; echo "deb & CRE"; echo $crcre; echo "bcom"; echo $clsdcdoc11; echo "dealamt"; echo $clsdcdoc1122;
$curlia = $curlia2 + $clsdcdoc11 - $clsdcdoc1122;
	?></p>
						
				
						<?php 
//			 Duties & Taxes		
$tddd=mysqli_query($conn, "select sum(tds) from finuser where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$tdsss = mysqli_fetch_array($tddd);
$tds1 = $tdsss[0];
$tddd1=mysqli_query($conn, "select sum(tds) from finnet where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$tdsss1 = mysqli_fetch_array($tddd1);
$tds2 = $tdsss1[0];
$tds = $tds1 + $tds2;  $frfrfr = $curlia - $tds;?>
<?php //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];
///////week 
$sdcdocw=mysqli_query($conn, "select sum(document) from customerdetailsw where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$sdcdoc1w = mysqli_fetch_array($sdcdocw);
$sdcdoc11w = $sdcdoc1w[0];
$hppassw=mysqli_query($conn, "select sum(rno) from userw where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass1w = mysqli_fetch_array($hppassw);
$hppass111w = $hppass1w[0];
$hppass3w=mysqli_query($conn, "select sum(fine) from userw where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass13w = mysqli_fetch_array($hppass3w);
$hppass1113w = $hppass13w[0];
$hppass2w=mysqli_query($conn, "select sum(amt) from netw where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass22w = mysqli_fetch_array($hppass2w);
$hppass222w = $hppass22w[0];
$hppass23w=mysqli_query($conn, "select sum(fine) from netw where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass223w = mysqli_fetch_array($hppass23w);
$hppass2223w = $hppass223w[0];
/////dc
$sdcdocm=mysqli_query($conn, "select sum(document) from customerdetailsm where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$sdcdoc1m = mysqli_fetch_array($sdcdocm);
$sdcdoc11m = $sdcdoc1m[0];
$hppassm=mysqli_query($conn, "select sum(rno) from userm where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass1m = mysqli_fetch_array($hppassm);
$hppass111m = $hppass1m[0];
$hppass3m=mysqli_query($conn, "select sum(fine) from userm where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass13m = mysqli_fetch_array($hppass3m);
$hppass1113m = $hppass13m[0];
$hppass2m=mysqli_query($conn, "select sum(amt) from netm where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass22m = mysqli_fetch_array($hppass2m);
$hppass222m = $hppass22m[0];
$hppass23m=mysqli_query($conn, "select sum(fine) from netm where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$hppass223m = mysqli_fetch_array($hppass23m);
$hppass2223m = $hppass223m[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+ $sdcdoc11w + $hppass111w + $hppass1113w + $hppass222w + $hppass2223w + $sdcdoc11m + $hppass111m + $hppass1113m + $hppass222m + $hppass2223m;
$dincome = $dincome2 + $sdcdoc11 + $hppass111 + $hppass1113 + $mpbchpartuser + $mpbchpartner + $hppass222 + $hppass2223+ $sdcdoc11w + $hppass111w + $hppass1113w + $hppass222w + $hppass2223w+ $sdcdoc11m + $hppass111m + $hppass1113m + $hppass222m + $hppass2223m; //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>
<!-- Cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc  -->	
<td width="35%"><a href="balcap.php">
<font size="4" color="red" ><b>Capital Account</a></b></font></br>
<?php $sqlcap = mysqli_query($conn, "select * from ledger where under='Capital Account' && mfin='$mfin'");
while($rowcap=mysqli_fetch_array($sqlcap)){ ?>
&nbsp;&nbsp;&nbsp;&nbsp;<font size="2" color="black"><b><?php echo $rowcap['ledger']; ?></a></b></font></br>
<?php } ?>
 </BR></BR>
<font size="4" color="red"><b>Loan (Liablity)</b></font></br>
<?php $sqlcap = mysqli_query($conn, "select * from fincust where mfin='$mfin'");
while($rowcap=mysqli_fetch_array($sqlcap)){ ?>
&nbsp;&nbsp;&nbsp;&nbsp;<font size="2" color="black"><b><?php echo $rowcap['name']; ?></a></b></font></br>
<?php } ?>
</br></br>
<?php
//$tot11 = $tot11 + $tds;
if($frfrfr < 0) {
?>
<font size="4" color="red"><b>Current Liablities</b></font> </br>
<font size="2" color="black"><b></br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sundry Creditor</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Duties & Taxes </br></b></font>
</br></br><?php } 
if($dtot > 0) { ?>
	<font size="4" color="red"><b> Profit & Loss A/c </b></br> Opening Balance </br> Current Period</b></font> <?php } ?>
	
</td>


<td width="15%"><font size="4" color="red"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo  $cpp; ?></b></font> </br>
<?php $sqlcap = mysqli_query($conn, "select * from ledger where under='Capital Account' && mfin='$mfin'");
while($rowcap=mysqli_fetch_array($sqlcap)){ $cpppppp1 = 0; $ccapvccdr = 0; $ccapvcccr = 0;  $cpppppp1 = $rowcap['openbal']; $capfir = 0; $ledgername = $rowcap['ledger'];
$cqrya145=mysqli_query($conn, "select sum(dr) from voucher where mfin='$mfin' && vtype='Payment' && par='$ledgername' && date between '$fdate' and '$tdate'");
$crowa145 = mysqli_fetch_array($cqrya145);
$cqryb145=mysqli_query($conn, "select sum(cr) from voucher where mfin='$mfin' && vtype='Receipt' && par='$ledgername' && date between '$fdate' and '$tdate'");
$crowb145 = mysqli_fetch_array($cqryb145);
$cff000 = $crowa145[0];
$ccapvccdr =  $crowa145[0];
$ccapvcccr =  $crowb145[0]; $capfir = $cpppppp1 - $ccapvccdr + $ccapvcccr; 
	?>
<font size="2" color="black"><b><?php echo $capfir; ?></a></b></font></br>
<?php } ?>
 </br></br>
<font size="4" color="red"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo  $partn ?></b></font></br>
<?php $sqlcap = mysqli_query($conn, "select * from fincust where mfin='$mfin'");
while($rowcap=mysqli_fetch_array($sqlcap)){
$parhpl = $rowcap['hpl'];
$ffqry0021=mysqli_query($conn, "select sum(pass) from finuser where mfin='$mfin' && hpl='$parhpl' && paydate2 between '$fdate' and '$tdate'");
$ffrow0021 = mysqli_fetch_array($ffqry0021);
$ffqry0022=mysqli_query($conn, "select sum(rno) from finuser where mfin='$mfin' && hpl='$parhpl' &&  paydate2 between '$fdate' and '$tdate'");
$ffrow0022 = mysqli_fetch_array($ffqry0022);
$ffqry0031=mysqli_query($conn, "select sum(dueamt) from finnet where mfin='$mfin' && hpl='$parhpl' &&  paydate2 between '$fdate' and '$tdate'");
$ffrow0031 = mysqli_fetch_array($ffqry0031);
$ffqry0032=mysqli_query($conn, "select sum(rno) from finnet where mfin='$mfin' && hpl='$parhpl' &&  paydate2 between '$fdate' and '$tdate'");
$ffrow0032 = mysqli_fetch_array($ffqry0032);
//Loan Liablity calc
$ffpass= $ffrow0021[0] + $ffrow0031[0];	
 $ffpartn = $ffrow001[0] - $ffpass; 
	?>
&nbsp;&nbsp;&nbsp;&nbsp;<font size="2" color="black"><b><?php echo $ffpartn; ?></a></b></font></br>
<?php } ?>
	</br></br>
<?php
//$tot11 = $tot11 + $tds;
if($frfrfr < 0) {
?>
<font size="4" color="red"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo  $frfrfr; ?></b></font></br>
<font size="2" color="black"><?php echo  abs($curlia); ?> 
</br><?php echo $tds; ?></br></font>
</br></br> <?php } 
if($dtot > 0) {
?>	
<font size="4" color="red"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo abs($dtot); $tot11 = $tot11 + $dtot; ?></br></br></b></font><?php } ?>	
</td> 
<!-- Asssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss  -->			
<td width="35%"><a href="balcasset.php">
<font size="4" color="blue" ><b>Current Asset</a></b></font>
<font size="2"  color="black"><b></br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="ledvled.php?led='Cash A/c'">Cash In Hand</a>
</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="ledvled.php?led='Bank A/c'">Bank Accounts</a>
</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hp Customer(s)
</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MonthlyLoan Customer(s)
</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sundry Debtors
</br> </b></font>
</br></br>
<?php
//$tot11 = $tot11 + $tds;
if($frfrfr > 0) {
?>
<font size="4" color="blue"><b>Current Liablities</b></font>
<font size="2" color="black"><b></br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sundry Creditor</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Duties & Taxes </br></b></font>
 </br></br> <?php } ?>
<?php
if($dtot < 0) { ?>
	<font size="4" color="blue"><b> Profit & Loss A/c </b></br> Opening Balance </br> Current Period</b></font> <?php } ?>
</a></font></td>

<td width="15%"><font size="4" color="blue"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $curass; ?></b></font>
<font size="2" color="black"><b></br><?php echo $cassin; ?>
</br><?php echo $banka; ?>
</br><?php echo $hpparty; ?>
</br><?php echo $mhpparty; ?>
</br><?php echo $sdept; ?>
</br> </font></b>
</br></br>
<?php
//$tot11 = $tot11 + $tds;
if($frfrfr > 0) {
?>
<font size="4" color="blue"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo  abs($frfrfr); ?></b></font></br>
<font size="2" color="black"><?php echo  $curlia; ?> 
</br>(-)<?php echo $tds; ?></br></font>
</br></br><?php } ?>	
<?php
if($dtot < 0) {
?>	
<font size="4" color="blue"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php echo abs($dtot); $tot22 = $tot22 + abs($dtot) ; ?></br></br></b></font><?php } ?>	
</a></font></td>
					</tr>
		

		<?php  $tot11 = $tot11 + $cpp; $tot22 = $tot22 + $curass ; $tot11 = $tot11 + $partn;	?>							
	

		<?php if($tot11 == $tot22) {	?>			
		 <?php  } elseif($tot11 > $tot22) {  $bala = $tot11 - $tot22; $tot22 = $tot11;	?>
						<tr>
<td width="35%"><font size="4" color="blue"><b></b></font></td>
					<td width="15%"><font size="4" color="blue"><b></b></font></td>
						
						<td width="35%"><font size="3" color="black">Difference in Opening Balalnces</font></td>
						<td width="15%"><font size="4" color="black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $bala; ?></font></td>
						
						</tr> <?php  } else { $bala = $tot22 - $tot11; $tot11 = $tot22;	?>
						<tr>

						
						<td width="35%"><font size="4" color="black">Difference in Opening Balalnces</font></td>
						<td width="15%"><font size="4" color="black"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $bala; ?></b></font></td>
						<td width="35%"><font size="4" color="blue"><b></b></font></td>
					<td width="15%"><font size="4" color="blue"><b></b></font></td>
						</tr> <?php } ?>
						
								
				<tr>
<td><font size="4" color="blue"><b></b></font></td>
					<td><font size="5" color="red"><b><?php echo $tot11; ?></b></font></td>
						
						<td><font size="4" color="blue"><b></b></font></td>
						<td><font size="5" color="blue"><b><?php echo $tot22; ?></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>
