<?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:balss.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 where mfin='$mfin'");
	$rowww = mysqli_fetch_array($sqll);
	$fdate = "1890-04-31";
										$fdate1 =  $rowww['date1']; 
										$tdate = $rowww['date2'];   ?>
									 <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
$qry15=mysqli_query($conn, "select sum(hpamount) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$row15 = mysqli_fetch_array($qry15);
$qry4415=mysqli_query($conn, "select sum(document) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$row4415 = mysqli_fetch_array($qry4415);
$qry45=mysqli_query($conn, "select sum(urname) from user where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$row45 = mysqli_fetch_array($qry45);
$qry4501=mysqli_query($conn, "select sum(pass) from user where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$row4501 = mysqli_fetch_array($qry4501);
$qry4502=mysqli_query($conn, "select sum(rno) from user where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$row4502 = mysqli_fetch_array($qry4502);

$qry445=mysqli_query($conn, "select sum(tot) from net where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$row445 = mysqli_fetch_array($qry445);
$qry44501=mysqli_query($conn, "select sum(amt) from net where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$row44501 = mysqli_fetch_array($qry445);
$qry44502=mysqli_query($conn, "select sum(rno) from net where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$row44502 = mysqli_fetch_array($qry445);

$qry779=mysqli_query($conn, "select sum(actamt) from hloan where mfin='$mfin' && date2 between '$fdate' and '$tdate'");
$row779 = mysqli_fetch_array($qry779);

$qry001=mysqli_query($conn, "select sum(hpamount) from fincust where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$row001 = mysqli_fetch_array($qry001);

$mqry001=mysqli_query($conn, "select sum(hpamount) from moncust where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$mrow001 = mysqli_fetch_array($mqry001);


$qry002=mysqli_query($conn, "select sum(urname) from finuser where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$row002 = mysqli_fetch_array($qry002);
$qry003=mysqli_query($conn, "select sum(tot) from finnet where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$row003 = mysqli_fetch_array($qry003);


$qry145=mysqli_query($conn, "select sum(cr) from voucher where mfin='$mfin' && par='Cash A/c' && date between '$fdate' and '$tdate'");
$row145 = mysqli_fetch_array($qry145);
$qry1455=mysqli_query($conn, "select sum(dr) from voucher where mfin='$mfin' && par='Cash A/c' && date between '$fdate' and '$tdate'");
$row1455 = mysqli_fetch_array($qry1455);						$n=mysqli_num_rows($qry);



$qry0021=mysqli_query($conn, "select sum(pass) from finuser where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$row0021 = mysqli_fetch_array($qry0021);
$qry0022=mysqli_query($conn, "select sum(rno) from finuser where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$row0022 = mysqli_fetch_array($qry0022);
$qry0031=mysqli_query($conn, "select sum(dueamt) from finnet where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$row0031 = mysqli_fetch_array($qry0031);
$qry0032=mysqli_query($conn, "select sum(rno) from finnet where mfin='$mfin' &&  paydate2 between '$fdate' and '$tdate'");
$row0032 = mysqli_fetch_array($qry0032);



//Loan Liablity calc
$pass= $row0021[0] + $row0031[0];	
 $partn = $row001[0] - $pass; 

//Current lia-> Cash in Hand
$userr = $row45[0];	
$vcr = $row145[0]; 
 $vdr = $row1455[0];
 $nett = $row445[0]; 
 $fincustt = $row001[0];	
	$moncustt = $mrow001[0];
 $hpp = $row15[0]; 
 $finuserr = $row002[0]; 
 $finnett = $row003[0];
$doc = $row4415[0]; 
$hl = $row779[0];
$cre = $vcr+$hpp+$finuserr+$finnett+$hl+$moncustt;
$debb = $userr+$nett+$fincustt+$doc+$vdr;
$tot = abs($cre - $debb);

$pass2= $row4501[0] + $row44501[0];	
 $pass3 = $row15[0] - $pass2; 
 
 
$lia = $pass3;
//Capital Account Part
$sql11=mysqli_query($conn, "select sum(openbal) from ledger where mfin='$mfin' &&  under='Capital Account' && yn='Cr'");
$rrr11 = mysqli_fetch_array($sql11);
$cpp1 = $rrr11[0];

$sql1=mysqli_query($conn, "select sum(openbal) from ledger where mfin='$mfin' &&  under='Capital Account' && yn='Dr'");
$rrr1 = mysqli_fetch_array($sql1);
$cpp2 = $rrr1[0];
$banka = 0;

$sqlu = mysqli_query($conn, "select * from ledger where under='Capital Account' && mfin='$mfin'");  $capvccdr =0; $capvcccr =0;
while($rowu = mysqli_fetch_array($sqlu)){
	$ledgername = $rowu['ledger']; 
$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);
$ff000 = $rowa145[0];

$capvccdr = $capvccdr + $rowa145[0];
$capvcccr = $capvcccr + $rowb145[0];
}

$cpp = $cpp1 - $cpp2 - $capvccdr + $capvcccr;
////	//Capital Account Part

//Curretn Assets
        $fir = 0;
$sqluu = mysqli_query($conn, "select * from ledgerg where under='Current Assets' && mfin='$mfin'");  
while($rowuu = mysqli_fetch_array($sqluu)){
		$ledg = $rowuu['ledger']; $rrf = 0;
 
$openbal = 0; $qdeb = 0; $qcre = 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']; 
if($ledgername == 'Cash A/c') {
$ff = NULL; $led = 'Cash A/c';
$sqll = mysqli_query($conn, "select * from ledger where ledger='$led' && mfin='$mfin'");
    $roww = mysqli_fetch_array($sqll);
	$led = $roww['ledger'];
	$opening = $roww['openbal'];
$cdoc2=mysqli_query($conn, "select sum(hpamount) from customerdetails where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$cdoc12 = mysqli_fetch_array($cdoc2);
$cdoc112 = $cdoc12[0];
$cdoc5=mysqli_query($conn, "select sum(chqamt) from customerdetails where mfin='$mfin' && pmode2='$led' && hpdate5 between '$fdate' and '$tdate'");
$cdoc15 = mysqli_fetch_array($cdoc5);
$cdoc115 = $cdoc15[0];
$cdoc28=mysqli_query($conn, "select sum(hpamount) from customerdetails where mfin='$mfin' && pmode!='$led' && pmode!='$ff' && hpdate5 between '$fdate' and '$tdate'");
$cdoc128 = mysqli_fetch_array($cdoc28);
$cdoc1128 = $cdoc128[0];
$cdoc58=mysqli_query($conn, "select sum(chqamt) from customerdetails where mfin='$mfin' && pmode2!='$led' && pmode2!='$ff' && hpdate5 between '$fdate' and '$tdate'");
$cdoc158 = mysqli_fetch_array($cdoc58);
$cdoc1158 = $cdoc158[0];
$cdoc56=mysqli_query($conn, "select sum(dealeramt) from customerdetails where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$cdoc156 = mysqli_fetch_array($cdoc56);
$cdoc1156 = $cdoc156[0];

$cdoc2m=mysqli_query($conn, "select sum(hpamount) from customerdetailsm where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$cdoc12m = mysqli_fetch_array($cdoc2m);
$cdoc112m = $cdoc12m[0];

$cdoc2w=mysqli_query($conn, "select sum(hpamount) from customerdetailsw where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$cdoc12w = mysqli_fetch_array($cdoc2w);
$cdoc112w = $cdoc12w[0];

$cdoc11  = $cdoc112 + $cdoc115 - $cdoc1156 - $cdoc1158 + $cdoc112m + $cdoc112w;
$qry4415=mysqli_query($conn, "select sum(document) from customerdetails where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$row4415 = mysqli_fetch_array($qry4415);
$qry45=mysqli_query($conn, "select sum(urname) from user where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row45 = mysqli_fetch_array($qry45);
$qry45w=mysqli_query($conn, "select sum(urname) from userw where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row45w = mysqli_fetch_array($qry45w);
$qry45m=mysqli_query($conn, "select sum(urname) from userm where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row45m = mysqli_fetch_array($qry45m);
$qry445=mysqli_query($conn, "select sum(tot) from net where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row445 = mysqli_fetch_array($qry445);
$qry445w=mysqli_query($conn, "select sum(tot) from netw where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row445w = mysqli_fetch_array($qry445w);
$qry445m=mysqli_query($conn, "select sum(tot) from netm where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row445m = mysqli_fetch_array($qry445m);
$qry779=mysqli_query($conn, "select sum(actamt2) from hloan where mfin='$mfin' && mode='$led' && date2 between '$fdate' and '$tdate'");
$row779 = mysqli_fetch_array($qry779);
$bqry4415=mysqli_query($conn, "select sum(bcommission) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$brow4415 = mysqli_fetch_array($bqry4415);
$qry001=mysqli_query($conn, "select sum(hpamount) from fincust where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$row001 = mysqli_fetch_array($qry001);
$qry002=mysqli_query($conn, "select sum(urname) from finuser where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row002 = mysqli_fetch_array($qry002);
$qry003=mysqli_query($conn, "select sum(tot) from finnet where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row003 = mysqli_fetch_array($qry003);

$mqry001=mysqli_query($conn, "select sum(hpamount) from moncust where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$mrow001 = mysqli_fetch_array($mqry001);
$mqry002=mysqli_query($conn, "select sum(urname) from monuser where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$mrow002 = mysqli_fetch_array($mqry002);

$mqry002r=mysqli_query($conn, "select sum(deb) from monuser where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$mrow002r = mysqli_fetch_array($mqry002r);

$mqry002re=mysqli_query($conn, "select sum(cre) from monuser where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$mrow002re = mysqli_fetch_array($mqry002re);

$mqry003=mysqli_query($conn, "select sum(tot) from monnet where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$mrow003 = mysqli_fetch_array($mqry003);


$qry145=mysqli_query($conn, "select sum(cr) from voucher where mfin='$mfin' && par='$led' &&  date between '$fdate' and '$tdate'");
$row145 = mysqli_fetch_array($qry145);
$qry1455=mysqli_query($conn, "select sum(dr) from voucher where mfin='$mfin' && par='$led' &&  date between '$fdate' and '$tdate'");
$row1455 = mysqli_fetch_array($qry1455);	
$hbcdoc581=mysqli_query($conn, "select sum(hlamt) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$hbcdoc1581 = mysqli_fetch_array($hbcdoc581);
$hbcdoc11581 = $hbcdoc1581[0];	
			
$userr = $row45[0]+$row45w[0]+$row45m[0];	
$vcr = $row145[0] + $mrow002r[0] + $mrow002re[0];  
 $vdr = $row1455[0];
 $nett = $row445[0]+$row445w[0]+$row445m[0]; 
 
 $fincustt = $row001[0];	
  $moncustt = $mrow001[0];	
	
 $hpp = $cdoc11; 
 $finuserr = $row002[0]; 
 $finnett = $row003[0];
  $monuserr = $mrow002[0]; 
 $monnett = $mrow003[0];
$doc = $row4415[0]; 
$hl = $row779[0];
$bcom = $brow4415[0];

	$cre = $vcr+$hpp+$finuserr+$moncustt+$finnett+$hl+$bcom;
$debb = $userr+$nett+$fincustt+$monuserr+$monnett+$doc+$vdr+$hbcdoc11581; 
$qcre =  $cre;
$qdeb =  $debb;
$qdeb = $qdeb + $opening;
$qtot = $qdeb - $qcre;
$captot = $qtot;
$cassin = $qtot;
// End of Cash A/c
 } 


///////////////Bank Accounts
elseif($ledg == 'Bank Accounts') { $opening = 0;
$userr = 0;	$vcr = 0; $vdr = 0; $nett = 0; $fincustt = 0; $moncustt = 0;$hpp = 0; $finuserr = 0;  $finnett = 0; $monuserr = 0; $monnett = 0; $doc = 0;  $hl = 0; $bcom = 0; $cre = 0; $debb = 0;
	$ff = NULL; $led = $ledgername;
	$sqll = mysqli_query($conn, "select * from ledger where ledger='$led' && mfin='$mfin'");
    while($roww = mysqli_fetch_array($sqll)){
	$led = $roww['ledger'];
	$opening = $roww['openbal']; 
$cdoc2=mysqli_query($conn, "select sum(hpamount) from customerdetails where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$cdoc12 = mysqli_fetch_array($cdoc2);
$cdoc112 = $cdoc12[0];
$cdoc5=mysqli_query($conn, "select sum(chqamt) from customerdetails where mfin='$mfin' && pmode2='$led' && hpdate5 between '$fdate' and '$tdate'");
$cdoc15 = mysqli_fetch_array($cdoc5);
$cdoc115 = $cdoc15[0];
$cdoc28=mysqli_query($conn, "select sum(hpamount) from cusdffdftomerdetails where mfin='$mfin' && pmode!='$led' && pmode!='$ff' && hpdate5 between '$fdate' and '$tdate'");
$cdoc128 = mysqli_fetch_array($cdoc28);
$cdoc1128 = $cdoc128[0];
$cdoc58=mysqli_query($conn, "select sum(chqamt) from customerdetails where mfin='$mfin' && pmode2!='$led' && pmode2!='$ff' && hpdate5 between '$fdate' and '$tdate'");
$cdoc158 = mysqli_fetch_array($cdoc58);
$cdoc1158 = $cdoc158[0];
$cdoc56=mysqli_query($conn, "select sum(dealeramt) from customerdetails where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$cdoc156 = mysqli_fetch_array($cdoc56);
$cdoc1156 = $cdoc156[0];

$cdoc2m=mysqli_query($conn, "select sum(hpamount) from customerdetailsm where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$cdoc12m = mysqli_fetch_array($cdoc2m);
$cdoc112m = $cdoc12m[0];

$cdoc2w=mysqli_query($conn, "select sum(hpamount) from customerdetailsw where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$cdoc12w = mysqli_fetch_array($cdoc2w);
$cdoc112w = $cdoc12w[0];

$cdoc11  = $cdoc112 + $cdoc115 - $cdoc1156 - $cdoc1158 + $cdoc112m + $cdoc112w;
$qry4415=mysqli_query($conn, "select sum(document) from customerdetails where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$row4415 = mysqli_fetch_array($qry4415);
$qry45=mysqli_query($conn, "select sum(urname) from user where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row45 = mysqli_fetch_array($qry45);
$qry45w=mysqli_query($conn, "select sum(urname) from userw where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row45w = mysqli_fetch_array($qry45w);
$qry45m=mysqli_query($conn, "select sum(urname) from userm where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row45m = mysqli_fetch_array($qry45m);
$qry445=mysqli_query($conn, "select sum(tot) from net where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row445 = mysqli_fetch_array($qry445);
$qry445w=mysqli_query($conn, "select sum(tot) from netw where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row445w = mysqli_fetch_array($qry445w);
$qry445m=mysqli_query($conn, "select sum(tot) from netm where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row445m = mysqli_fetch_array($qry445m);
$qry779=mysqli_query($conn, "select sum(actamt2) from hloan where mfin='$mfin' && mode='$led' && date2 between '$fdate' and '$tdate'");
$row779 = mysqli_fetch_array($qry779);
$bqry4415=mysqli_query($conn, "select sum(bcommission) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$brow4415 = mysqli_fetch_array($bqry4415);
$qry001=mysqli_query($conn, "select sum(hpamount) from fincust where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$row001 = mysqli_fetch_array($qry001);
$qry002=mysqli_query($conn, "select sum(urname) from finuser where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row002 = mysqli_fetch_array($qry002);
$qry003=mysqli_query($conn, "select sum(tot) from finnet where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row003 = mysqli_fetch_array($qry003);

$mqry001=mysqli_query($conn, "select sum(hpamount) from moncust where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$mrow001 = mysqli_fetch_array($mqry001);
$mqry002=mysqli_query($conn, "select sum(urname) from monuser where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$mrow002 = mysqli_fetch_array($mqry002);
$mqry003=mysqli_query($conn, "select sum(tot) from monnet where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$mrow003 = mysqli_fetch_array($mqry003);


$qry145=mysqli_query($conn, "select sum(cr) from voucher where mfin='$mfin' && par='$led' &&  date between '$fdate' and '$tdate'");
$row145 = mysqli_fetch_array($qry145);
$qry1455=mysqli_query($conn, "select sum(dr) from voucher where mfin='$mfin' && par='$led' &&  date between '$fdate' and '$tdate'");
$row1455 = mysqli_fetch_array($qry1455);	
$hbcdoc581=mysqli_query($conn, "select sum(hlamt) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$hbcdoc1581 = mysqli_fetch_array($hbcdoc581);
$hbcdoc11581 = $hbcdoc1581[0];	
			
$userr = $row45[0]+$row45w[0]+$row45m[0];	
$vcr = $row145[0];  
 $vdr = $row1455[0];
 $nett = $row445[0]+$row445w[0]+$row445m[0]; 
 
 $fincustt = $row001[0];	
  $moncustt = $mrow001[0];	
	
 $hpp = $cdoc11; 
 $finuserr = $row002[0]; 
 $finnett = $row003[0];
  $monuserr = $mrow002[0]; 
 $monnett = $mrow003[0];
$doc = $row4415[0]; 
$hl = $row779[0];
$bcom = $brow4415[0];

	$cre = $vcr+$hpp+$finuserr+$moncustt+$finnett+$hl+$bcom;
$debb = $userr+$nett+$fincustt+$monuserr+$monnett+$doc+$vdr+$hbcdoc11581; 

	$qcre = $qcre + $cre;
$qdeb = $qdeb + $debb  + $opening; 
}
//echo $qcre; //echo "jdfjhfd"; 
//echo $qdeb;
$qtot = $qdeb - $qcre;
$captot = $qtot;
$banka = $qtot;
}
else {	
$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;
 }
}
 } }

 

$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];
$qhppass2=mysqli_query($conn, "select sum(addless) from user where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$qhppass22 = mysqli_fetch_array($qhppass2);
$qhppass222 = $qhppass22[0];
$whppass2=mysqli_query($conn, "select sum(addless) from net where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$whppass22 = mysqli_fetch_array($whppass2);
$whppass222 = $whppass22[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];
// - $qhppass222 - $whppass222
$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(rno) from monuser where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$mhppass1 = mysqli_fetch_array($mhppass);
$mhppass111 = $mhppass1[0];

$mhppassr=mysqli_query($conn, "select sum(cre) from monuser where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$mhppass1r = mysqli_fetch_array($mhppassr);
$mhppass111r = $mhppass1r[0];

$mhppassrf=mysqli_query($conn, "select sum(deb) from monuser where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$mhppass1rf = mysqli_fetch_array($mhppassrf);
$mhppass111rf = $mhppass1rf[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 - $mhppass111rf  - $mhppass111r - $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  + $mhpparty + $sdept ;	


// Current Liablities // Sundery Creditors
//////////////////////////////////////////////////////////// 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;
	
	if($dealera > 0) { $suncred = $suncred + $dealera;  
 } else { $suncrec = $suncrec + abs($dealera); 
 } 
 if($brkbb > 0) { $suncred = $suncred + $brkbb;  
 } else { $suncrec = $suncrec + abs($brkbb); 
 } 
 if($colagent > 0) { $suncred = $suncred + $colagent;  
 } else { $suncrec = $suncrec + abs($colagent); 
} 
 if($ddcol > 0) { $suncred = $suncred + $ddcol;  
 } else { $suncrec = $suncrec + abs($ddcol);  } 
$curlia = abs($suncred) - abs($suncrec);
?>

</p>
						
				
						<?php  $cuas = 0;
$sqlcu = mysqli_query($conn, "select * from ledger where under='CURRENT ACCOUNT' && mfin='$mfin'");
while($rowcu = mysqli_fetch_array($sqlcu)){
$ledgername = $rowcu['ledger'];
$openbal = $rowcu['openbal'];	
$yn = $rowcu['yn'];

$cacass11=mysqli_query($conn, "select sum(dr) from voucher where mfin='$mfin' && vtype='Payment' && par='$ledgername' && date between '$fdate' and '$tdate'");
$cacass1 = mysqli_fetch_array($cacass11); 
$cacass22=mysqli_query($conn, "select sum(cr) from voucher where mfin='$mfin' && vtype='Receipt' && par='$ledgername' && date between '$fdate' and '$tdate'");
$cacass23 = mysqli_fetch_array($cacass22);

$cacrascr = $cacass1[0];
$cacrasdr = $cacass23[0];
$cuas = $cuas + $openbal + $cacrasdr - $cacrascr;
}



//			 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 + $cuas;?>
<?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];
//////////////



//$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' && status='Active'");
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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Current Accounts </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' && status='Active'");
while($rowcap=mysqli_fetch_array($sqlcap)){
$parhpl = $rowcap['hpl'];
$ffqry00321=mysqli_query($conn, "select sum(hpamount) from fincust where mfin='$mfin' && status='Active'  && hpl='$parhpl' && hpdate5 between '$fdate' and '$tdate'");
$ffrow001 = mysqli_fetch_array($ffqry00321);
$ffqry0021=mysqli_query($conn, "select sum(urname) 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(amt) 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]; 
	?>
&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><?php echo $cuas; ?></br></font>
</br></br> <?php
$tot11 = $tot11 + abs($curlia) ;
$tot11 = $tot11 + abs($tds) ;
$tot11 = $tot11 + abs($cuas) ;
 } 
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; Loan 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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Current Accounts </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>
<?php echo $cuas; ?></br>
</font>
</br></br><?php 
$tot22 = $tot22 + abs($curlia) ;
$tot22 = $tot22 + abs($tds) ;
$tot22 = $tot22 + abs($cuas) ;
} ?>	
<?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>
