<?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;
										$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']; 
									?>
									<div class="table-responsive">
									     <input type="button" class="btn btn-primary" value="Print" onclick="PrintElem('#mydiv')"  style="margin:20px;"> 				<div class="table-responsive my div" id="mydiv">
  <table class="table table-bordered table-hover" border="1"><thead>
										

					<font size="1">
					    <tr class="danger" style="color:purple;">
					
						<th colspan="4"><font color="blue" size="3"><b><center><?php echo $led; ?> Book <?php echo date("d-m-Y", strtotime($fdate11)); ?> To <?php echo date("d-m-Y", strtotime($tdate1)); ?></b></font></center></th>
						
					
						
					</tr>
					
						<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;
								
											$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];
$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]; 

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