<?php require "_header.php"; ?>
<div id="main-content1" align="center">
<div style="font-weight:bold">A/C Ledger Report</div><br/>
<?php
	if($_SESSION['cCompany_id']!="" && isset($_SESSION['cCompany_id'])){
		$limit=0;
		$start=0;
		$condition="";
		$order_field="voucher_date";	
	   	$order_type="ASC";
		$objVoucherMasterMgmt= new  VoucherMasterMgmt();
		
		$qry="SELECT year_name FROM lms_yearmaster WHERE year_id = '".$_SESSION['cYear']."' ";
		$out=dbQuery($qry);
		$result = dbArray($out);
		$year_name = $result['year_name'];
		$start = substr($year_name,0,4)."-4-1";
		$end = substr($year_name,5,9)."-3-31";
		
		$account_id= Escape($_POST["account_id"]);
		if($account_id != ""){
		
			$qry="SELECT 
				   account_name,
				   account_opbalance,
				   account_baldate,
				   account_crdr
			  FROM ams_accountmaster am,
			  	   ams_accountmasterdetail ad
	          WHERE 
			  	   am.company_id = '".$_SESSION['cCompany_id']."' AND
				   ad.company_id = '".$_SESSION['cCompany_id']."' AND
				   ad.year_id = '".$_SESSION['cYear']."' AND
				   am.account_id = ad.account_id AND
				   am.account_id = '".$account_id."' ";
			$out=dbQuery($qry);	
			$result = dbArray($out);	
		
			$accountid = $account_id;
		 	$condition .= " AND vd.account_id = '$accountid' AND vm.voucher_date >= '$start' AND vm.voucher_date <= '$end' ";
		}
						
		$getGeneralReport = $objVoucherMasterMgmt->getGeneralReport("","",$condition,$order_field,$order_type);				
?>	    
<div style="width:50%">
	<div class="left"> <b>A/C ID:</b> <u><?php print $_POST['account_id']; ?></u> </div>
	<div class="right"> <b>A/C Name:</b> <u><?php print $result['account_name']; ?></u> </div>
</div>
<br /><br />
<table width="50%" cellpadding="0" cellspacing="0" style="border:0 none;">
	<tr>
		<td colspan="3" style="border:0 none;"><b>Ledger Report:</b>
			<?php 
				print FormatDate($getGeneralReport[0]["voucher_date"],"d/m/Y"); 
				print " To ".FormatDate($getGeneralReport[0]["voucher_lastdate"],"d/m/Y"); 
			?>
		</td>
		<td colspan="3" style="border:0 none;"><b>Ledger Report:</b>
			<?php 
				print FormatDate($getGeneralReport[0]["receipt_date"],"d/m/Y"); 
				print " To ".FormatDate($getGeneralReport[0]["receipt_lastdate"],"d/m/Y"); 
			?>
		</td>
	</tr>
	<tr>
		<td colspan="3" style="text-align:center;width:50%;border-bottom:0 none;"><b>Credit Detail</b></td>
		<td colspan="3" style="text-align:center;width:50%;border-bottom:0 none;"><b>Debit Detail</b></td>
	</tr>
	<?php
		$row_num = count($getGeneralReport);
		$creditTotal = 0; 
		$debitTotal = 0;
		if($row_num > 0){
			$j=0;			
	?>
			<tr>
				<td colspan="6" style="padding:0;border:0 none;">
					<table cellpadding="0" cellspacing="0" width="100%">
						<tr>
							<td width="10%"><b>Rec. No</b></td>
							<td width="20%" style="text-align:center"><b>Date</b></td>
							<td width="20%" style="text-align:right"><b>Amount</b></td>
							<td width="10%"><b>Vou. No</b></td>
							<td width="20%" style="text-align:center"><b>Date</b></td>
							<td width="20%" style="text-align:right"><b>Amount</b></td>
						</tr>					
				<?php
					if($result['account_crdr']=="C"){
						$creditTotal = $result['account_opbalance'];
						$debitTotal  = number_format(0,2);
						$debitBalanceData="";
						$creditBalanceData= FormatDate($result["account_baldate"],"d/m/Y")."&nbsp;&nbsp;"."Ope. Balance";
					}
					elseif($result['account_crdr']=="D"){
						$debitTotal = $result['account_opbalance'];
						$debitBalanceData= FormatDate($result["account_baldate"],"d/m/Y")."&nbsp;&nbsp;"."Ope. Balance";
						$creditBalanceData="";
						$creditTotal = number_format(0,2);
					}	
				?>
					<tr style="height:50px;">
							<td colspan="2" width="30%" style="border:0 none; text-align:center"><b><?php echo $creditBalanceData;?></b></td>							
							<td width="20%" style="text-align:right;border-bottom:0 none;border-left:0 none;"><b><?php echo number_format($creditTotal,2);?></b></td>
							<td  colspan="2" width="30%" style="border:0 none; text-align:center"><b><?php echo $debitBalanceData;?></b></td>
							<td width="20%" style="border:0 none; text-align:right"><b><?php echo number_format($debitTotal,2);?></b></td>
					</tr>
	<?php
			while($j < $row_num){
	?>	
			<tr>
				<?php if($getGeneralReport[$j]["voucher_creditamount"] > 0) {?>	
				<td style="border:0 none; text-align:center;">
					<?php echo $getGeneralReport[$j]["voucher_no"] ;?></td>   
				<td style="border:0 none; text-align:center;">
					<?php echo FormatDate($getGeneralReport[$j]["voucher_date"],"d/m/Y");?></td>   
				<td style="text-align:right; border-left:0 none; border-bottom:0 none; border-top:0 none; border-bottom:0 none">
					<?php echo number_format($getGeneralReport[$j]["voucher_creditamount"],2);?></td>   
				
				<?php } else { ?> 
				<td style="border:0 none; text-align:center;" colspan="3">&nbsp;</td>
				<?php } ?>
				
				<?php if($getGeneralReport[$j]["voucher_debitamount"] > 0) {?>	
				<td style="border:0 none; text-align:center;">
					<?php echo $getGeneralReport[$j]["receipt_no"] ;?></td>   
				<td style="border:0 none; text-align:center;">
					<?php echo FormatDate($getGeneralReport[$j]["receipt_date"],"d/m/Y");?></td>   
				<td style="border:0 none; text-align:right;">
					<?php echo number_format($getGeneralReport[$j]["voucher_debitamount"],2);?></td>   
				<?php } else { ?> 
				<td style="border:0 none; text-align:center;" colspan="3">&nbsp;</td>
				<?php } ?>
			</tr>	
	<?php		
			$creditTotal += $getGeneralReport[$j]["voucher_creditamount"];
			$debitTotal += $getGeneralReport[$j]["voucher_debitamount"];
			$j++;				
			}
		}
	?>
					</table>
				</td>
			</tr>
	<?php		
		if($creditTotal > $debitTotal){
	?>
	<tr>
		<td colspan="2" style="text-align:right; border-right:0 none; border-top:0 none; border-bottom:0 none;">Total Credit Rs.</td>
		<td style="text-align:right;border-left:0 none;border-top:0 none;border-bottom:0 none;"><?php print number_format($creditTotal,2); ?></td>
		<td colspan="2" style="text-align:right;border-right:0 none;border-top:0 none;border-bottom:0 none;"> Total Debit Rs.</td>
		<td style="text-align:right;border-left:0 none;border-top:0 none;border-bottom:0 none;"><?php print number_format($debitTotal,2); ?></td>
	</tr>
	<tr>
		<td colspan="2" style="text-align:right; border-top:0 none; border-right:0 none"><b>Final Debit : Rs.</b></td>
		<td style="text-align:right; border-left:0 none; border-top:0 none;"><?php print "0.00" ?></td>
		<td colspan="2" style="text-align:right; border-top:0 none; border-right:0 none"><b>Final Credit : Rs.</b></td>
		<td style="text-align:right; border-left:0 none; border-top:0 none;"><b><?php print number_format($creditTotal-$debitTotal,2); ?></b></td>
	</tr>
	<tr>
		<td colspan="2" style="text-align:right;border-right:0 none;">&nbsp;</td>
		<td style="text-align:right;border-left:0 none;"><?php print number_format($creditTotal,2); ?></td>
		<td colspan="2" style="text-align:right;border-right:0 none;">&nbsp;</td>
		<td style="text-align:right;border-left:0 none;"><?php print number_format($creditTotal,2); ?></td>
	</tr>
	<?php
		} else{
	?>
	<tr>
		<td colspan="2" style="text-align:right; border-right:0 none; border-top:0 none; border-bottom:0 none;">Total Credit Rs.</td>
		<td style="text-align:right;border-left:0 none;border-top:0 none;border-bottom:0 none;"><?php print number_format($creditTotal,2); ?></td>
		<td colspan="2" style="text-align:right;border-right:0 none;border-top:0 none;border-bottom:0 none;">Total Debit Rs.</td>
		<td style="text-align:right;border-left:0 none;border-top:0 none;border-bottom:0 none;"><?php print number_format($debitTotal,2); ?></td>
	</tr>
	<tr>
		<td colspan="2" style="text-align:right; border-top:0 none; border-right:0 none"><b>Final Debit : Rs.</b></td>
		<td style="text-align:right; border-left:0 none; border-top:0 none;"><b><?php print number_format($debitTotal-$creditTotal,2); ?></b></td>
		<td colspan="2" style="text-align:right; border-top:0 none; border-right:0 none"><b>Final Credit : Rs.</b></td>
		<td style="text-align:right; border-left:0 none; border-top:0 none;"><?php print "0.00" ?></td>
	</tr>
	<tr>
		<td colspan="2" style="text-align:right;border-right:0 none;">&nbsp;</td>
		<td style="text-align:right;border-left:0 none;"><u><?php print number_format($debitTotal,2); ?></u></td>
		<td colspan="2" style="text-align:right;border-right:0 none;">&nbsp; </td>
		<td style="text-align:right;border-left:0 none;"><u><?php print number_format($debitTotal,2); ?></u></td>
	</tr>
	<?php	
		}				
	?>		
</table>
<?php } 
	require "_footer.php";
?>