<?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">
                             Current Cash
                        </div>
                        <div class="panel-body">
                         
								
                            <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 =  $rowww['date1']; 
										$tdate = $rowww['date2'];  ?> 
									 <input type="button" class="btn btn-primary" value="Print" onclick="PrintElem('#mydiv')"  style="margin:20px;"> 
   <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>Current Cash </b></font></center></th>
					</tr>
						<tr class="success" style="color:purple;">
						<th colspan="2" width="50%"><font size="4" color="blue">Particulars</font></th>
						
				
						<th colspan="2" width="50%"><font size="4" color="blue">Amount</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);
$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];	
	
 $hpp = $row15[0]; 
 $finuserr = $row002[0]; 
 $finnett = $row003[0];
$doc = $row4415[0]; 
$hl = $row779[0];
$cre = $vcr+$hpp+$finuserr+$finnett+$hl;
$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];
$cdoc11  = $cdoc112 + $cdoc115 - $cdoc1156 - $cdoc1158;
$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);
$qry445=mysqli_query($conn, "select sum(tot) from net where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row445 = mysqli_fetch_array($qry445);
$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];	
$vcr = $row145[0]; 
 $vdr = $row1455[0];
 $nett = $row445[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;
$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;$qcre = 0; $qdeb = 0; $qtot = 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 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];
$cdoc11  = $cdoc112 + $cdoc115 - $cdoc1156 - $cdoc1158;
$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);
$qry445=mysqli_query($conn, "select sum(tot) from net where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row445 = mysqli_fetch_array($qry445);
$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' && pmode2!='Cash A/c' && hpdate5 between '$fdate' and '$tdate'");
$hbcdoc1581 = mysqli_fetch_array($hbcdoc581);
$hbcdoc11581 = $hbcdoc1581[0];	
			
$userr = $row45[0];	
$vcr = $row145[0]; 
 $vdr = $row1455[0];
 $nett = $row445[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;
	$debb = $userr+$nett+$fincustt+$monuserr+$monnett+$vdr;

	$qcre = $qcre + $cre;
$qdeb = $qdeb + $debb  + $opening;
}
$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 Party(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];

$hpparty = $sdcdoc11 - $hppass111 - $hppass222;

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

$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]; 
$ffine = $hppass1113 + + $hppass2223;
$intrcpt = $hppass111 + $mpbchpartuser  + $mpbchpartner + $hppass222;
$ddincome = $ddincome  + $intrcpt + $ffine;
$dincome = $dincome2 + $intrcpt + $ffine; 
 //echo $sdcdoc11;
 //// Document Charge Add OR Not $ddincome = $ddincome + $sdcdoc11 + $intrcpt + $ffine;
////////////////////////$dincome = $dincome2 + $sdcdoc11 + $intrcpt + $ffine;
//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];

$maddd=mysqli_query($conn, "select sum(addless) from monnet where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$maddd1 = mysqli_fetch_array($maddd);
$maddd11 = $maddd1[0];
$mlesss=mysqli_query($conn, "select sum(addless) from monuser where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$mlesss1 = mysqli_fetch_array($mlesss);
$mlesss11 = $mlesss1[0];

$faddd=mysqli_query($conn, "select sum(addless) from finnet where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$faddd1 = mysqli_fetch_array($faddd);
$faddd11 = $faddd1[0];
$flesss=mysqli_query($conn, "select sum(addless) from finuser where mfin='$mfin' && paydate2 between '$fdate' and '$tdate'");
$flesss1 = mysqli_fetch_array($flesss);
$flesss11 = $flesss1[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;
$addles =  $faddd11 + $flesss11 - $addd11 - $lesss11 - $maddd11 - $mlesss11;
$intpaid = $pbchpartuser + $pbchpartnet;
$dexp = $dexp2  + $addles+ $intpaid;
$ddexp = $ddexp + $addles + $intpaid; 


//Total P & L + $sdcdoc11 bcom

$dtot = $dincome - $dexp;  
//echo $dincome; echo "<>"; echo $dexp; ?>

						<tr class="danger" style="color:purple;">
						<td colspan="2" width="50%"><font size="4" color="blue">Cash</font></td>
						
				
						<td colspan="2" width="50%"><font size="4" color="blue"><?php echo $cassin; ?></font></td>
						
						</tr>
						<tr class="warning" style="color:purple;">
						<td colspan="2" width="50%"><font size="4" color="blue">Bank</font></td>
						
				
						<td colspan="2" width="50%"><font size="4" color="blue"><?php echo $banka; ?></font></td>
						
						</tr>
						<tr class="success" style="color:purple;">
						<td colspan="2" width="50%"><font size="4" color="blue">HP</font></td>
						
				
						<td colspan="2" width="50%"><font size="4" color="blue"><?php echo $hpparty; ?></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>
