<?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">
                             Details
                        </div>
                        <div class="panel-body">
                            <div class="row">
    <?php				
			$led=$_REQUEST['led'];			
									$tr1 = 0; $tr2= 0;$tr3 = 0; $tr4= 0;$tr5 = 0; $tr6= 0;$tr7 = 0; $tr8= 0; ?>
									<div class="table-responsive">
  <table class="table table-bordered table-hover" border="1"><thead>
										

					<font size="1">
						<tr class="danger" style="color:purple;">
						<th><font size="3">Month</font></th>
						
				
						<th><font size="3">Credit</font></th>
						
						<th><font size="3">Debit</font></th>
						<th><font size="3">Closing</font></th>
						</tr></thead>
									
									<?php $e=0;  $s=0;  $r=0;  $t=0; $d=0; $d1=0; $i=1;
									$fdate1 =  date("Y-m-d", strtotime("2013-04-01")); 
										$sqll = mysqli_query($conn, "select * from abc where mfin='$mfin'");
	$rowww = mysqli_fetch_array($sqll);
	//$fdate=$_REQUEST['fdate'];
   // $tdate=$_REQUEST['tdate'];
									
										$fdate11 =  $rowww['date1'];
										$tdate1 =  $rowww['date2']; 
											$fdate =  date("Y-m-d", strtotime("2013-04-01")); 
										$tdate =  date("Y-m-d", strtotime("2013-04-31"));
								//$fdate5 =  date("Y-m-d", strtotime("2010-01-01")); 
									 
									//	$fdate5 =  date("Y-m-d", strtotime("2018-03-31")); 
						$obal = 0;
	$qcre =  0;
$qdeb =  0;
$sqll = mysqli_query($conn, "select * from ledger where ledger='$led' && mfin='$mfin'");
    $roww = mysqli_fetch_array($sqll);
	$led = $roww['ledger'];
	$opening = $roww['openbal']; $tot = ($opening * (-1)); $obal = $tot; ?>
		<tr>

					<td><font size="4"><b>Opening Balance</b></font></td>
						
						<td><font size="4"><b></b></font></td>
						<td><font size="4"><?php echo $opening; ?></b></font></td>
						<?php if($tot > 0) { ?>
						<td><font color="red" size="4"><b><?php echo $tot; ?> Cr</font></b></td>
						<?php } else { ?>
						<td><font size="4"><b><?php echo abs($tot); ?> Dr</font></b></td>
						<?php } ?>
						</tr>
	<?php
								//	   $fdate = $fdate;  $tdate = $tdate;
								while(strtotime($fdate)<=strtotime($tdate1)) {
					$monthh = date('F, Y', strtotime($fdate));
//$qry15=mysqli_query($conn, "select sum(hpamount) from customerdetails where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate5' and '$tdate5'");
//$row15 = mysqli_fetch_array($qry15);
//$qry45=mysqli_query($conn, "select sum(urname) from user where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate5' and '$tdate5'");
//$row45 = mysqli_fetch_array($qry45);
//$qry445=mysqli_query($conn, "select sum(tot) from net where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate5' and '$tdate5'");
//$row445 = mysqli_fetch_array($qry445);
//$qry145=mysqli_query($conn, "select sum(cr) from voucher where mfin='$mfin' && par='$led' &&  date between '$fdate5' and '$tdate5'");
//$row145 = mysqli_fetch_array($qry145);
//$qry1455=mysqli_query($conn, "select sum(dr) from voucher where mfin='$mfin' && par='$led' &&  date between '$fdate5' and '$tdate5'");
//$row1455 = mysqli_fetch_array($qry1455);						$n=mysqli_num_rows($qry);
//$c1 = $row45[0];	$c2 = $row145[0];  $c3 = $row445[0]; 	$d1 = $row1455[0];	$d2 = $row15[0]; 
//$qry15=mysqli_query($conn, "select sum(hpamount) from customerdetails where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate5' and '$tdate5'");
//$row15 = mysqli_fetch_array($qry15);
//$qry45=mysqli_query($conn, "select sum(urname) from user where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate5' and '$tdate5'");
//$row45 = mysqli_fetch_array($qry45);
//$qry445=mysqli_query($conn, "select sum(tot) from net where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate5' and '$tdate5'");
//$row445 = mysqli_fetch_array($qry445);
//$c11 = $row45[0];  $c31 = $row445[0]; 		$d21 = $row15[0]; 
	//	$obal = $c1 + $c2 - $d1 - $d2 + $c3 + $c11 - $d21;
$ff = NULL;
$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];

$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];

$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];

$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];


$cdoc56w=mysqli_query($conn, "select sum(dealeramt) from customerdetailsw where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$cdoc156w = mysqli_fetch_array($cdoc56w);
$cdoc1156w = $cdoc156w[0];

$cdoc56m=mysqli_query($conn, "select sum(dealeramt) from customerdetailsm where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$cdoc156m = mysqli_fetch_array($cdoc56m);
$cdoc1156m = $cdoc156m[0];
$cdoc11  = $cdoc112 + $cdoc115 - $cdoc1156 -$cdoc1156w - $cdoc1156m - $cdoc1158 + $cdoc112w + $cdoc112m;


$qry4415=mysqli_query($conn, "select sum(document) from customerdetails where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$row4415 = mysqli_fetch_array($qry4415);
$qry4415w=mysqli_query($conn, "select sum(document) from customerdetailsw where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$row4415w = mysqli_fetch_array($qry4415w);
$qry4415m=mysqli_query($conn, "select sum(document) from customerdetailsm where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
$row4415m = mysqli_fetch_array($qry4415m);

$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);

$qry45w=mysqli_query($conn, "select sum(urname) from userw where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row45w = mysqli_fetch_array($qry45w);
$qry445w=mysqli_query($conn, "select sum(tot) from netw where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row445w = mysqli_fetch_array($qry445w);

$qry45m=mysqli_query($conn, "select sum(urname) from userm where mfin='$mfin' && mode='$led' &&  paydate2 between '$fdate' and '$tdate'");
$row45m = mysqli_fetch_array($qry45m);
$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);
$mbqry4415=mysqli_query($conn, "select sum(bcommission) from customerdetailsm where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$mbrow4415 = mysqli_fetch_array($mbqry4415);

$wbqry4415=mysqli_query($conn, "select sum(bcommission) from customerdetailsw where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$wbrow4415 = mysqli_fetch_array($wbqry4415);

$bbccmmss = $brow4415[0] + $mbrow4415[0] + $wbrow4415[0];
$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];	

$pppqry4415=mysqli_query($conn, "select sum(preinc) from customerdetails where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$ppprow4415 = mysqli_fetch_array($pppqry4415);

$pppqry4415w=mysqli_query($conn, "select sum(preinc) from customerdetailsw where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$ppprow4415w = mysqli_fetch_array($pppqry4415w);

$pppqry4415m=mysqli_query($conn, "select sum(preinc) from customerdetailsm where mfin='$mfin' && hpdate5 between '$fdate' and '$tdate'");
$ppprow4415m = mysqli_fetch_array($pppqry4415m);
			
$userr = $row45[0] + $row45m[0] + $row45w[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] + $row4415m[0] +$row4415w[0]   + $ppprow4415[0] + $ppprow4415w[0] +$ppprow4415m[0]; 
$hl = $row779[0];
$bcom = $bbccmmss; 

//$qry15=mysqli_query($conn, "select sum(hpamount) from customerdetails where mfin='$mfin' && pmode='$led' && hpdate5 between '$fdate' and '$tdate'");
//$row15 = mysqli_fetch_array($qry15);
//$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);
//$c11 = $row45[0];  $c31 = $row445[0]; 		$d21 = $row15[0]; 
	//	$obal2 = $c1 + $c2 + $c4 - $d1 - $d2 - $d3 - $d4 + $c3; 
//$cre = $c1+$c2+$c3+$c4;
//$deb = $d1+$d2+$d3+$d4;

//echo " VCR  ".$vcr." Hpp  ".$hpp."  finuserr  ".$finuserr."  finnett  ".$finnett."  hl  ".$hl;
if($led=='Cash A/c') {
	$cre = $vcr+$hpp+$finuserr+$moncustt+$finnett+$hl +$bcom;
$debb = $userr+$nett+$fincustt+$monuserr+$monnett+$doc+$vdr+$hbcdoc11581; }
else {
	$cre = $vcr+$hpp+$finuserr+$moncustt+$finnett+$hl;
	$debb = $userr+$nett+$fincustt+$monuserr+$monnett+$vdr;
}
$tot = $obal + $cre - $debb;
$obal = $tot;
	$qcre = $qcre + $cre; 
$qdeb = $qdeb + $debb;
	
				if(($cre>0) || ($debb>0)) {		?></p>
						
				<tr>
<td><a href="ledvled3.php?led=<?php echo $led; ?>&&fdate=<?php echo $fdate; ?>&&tdate=<?php echo $tdate; ?>"><font size="3"><b><?php echo $monthh; ?></a></b></font></td>
						
						<td><font size="4"><b><?php echo $cre; ?></b></font></td>
						<td><font size="4"><?php echo $debb; ?></b></font></td>
						<?php if($tot > 0) { ?>
						<td><font color="red" size="4"><b><?php echo $tot; ?> Cr</font></b></td>
						<?php } else { ?>
						<td><font size="4"><b><?php echo abs($tot); ?> Dr</font></b></td>
						<?php } ?>
						</tr>
		
						<?php 
							} $fdate =  date("Y-m-d", strtotime("$fdate + " . 1 . " month"));

						$tdate = date("Y-m-t", strtotime("$fdate")); }
				$qdeb = $qdeb + + $opening;		?>
					<tr>
<td><font size="5"><b>Total</b></font></td>
		
						
						<td><font size="5"><b><?php echo $qcre; ?></b></font></td>
						<td><font size="5"><b><?php echo $qdeb; ?></b></font></td>
					<?php $qtot = $qcre - $qdeb; ?>
						<?php if($qtot > 0) { ?>
						<td><font color="red" size="5"><b><?php echo $qtot; ?> Cr</font></b></td>
						<?php } else { ?>
						<td><font size="5"><b><?php echo abs($qtot); ?> Dr</font></b></td>
						<?php } ?>
						</tr>
					 
					
					</tbody></table>	</form>
					
</div>
</div></div>
</div></div></div><?php include "layouts/footer.php"; ?></body></html>
