<?php require "_header.php"; ?>
<?php
$profitstartdate = Escape($_POST["profitstartdate"]);
$profitenddate = Escape($_POST["profitenddate"]);
	
if($profitstartdate =="" && $profitenddate =="")
{
?>
	<script language="javascript" type="text/javascript">
		location.href='report-form-date-voucher.php';
	</script>
<?php
}
else
{
?>
	<div id="main-content1" align="center">
<div style="font-weight:bold">Day Book Report</div><br/>
<?php
	
	if($_SESSION['cCompany_id']!="" && isset($_SESSION['cCompany_id'])){
		$condition="";
      	
		if($profitstartdate  != ""){
			$startdate = DateConversion($profitstartdate,"Y-m-d","d/m/Y");
		 	$condition .= " AND voucher_date >= '$startdate' ";  
	   	}
	   	
		if($profitenddate != ""){
	     	$enddate = DateConversion($profitenddate,"Y-m-d","d/m/Y");
		 	$condition .= " AND voucher_date <= '$enddate' ";  
	   	}
	    
		$order_field="";	
	   	$order_type="";
		
	   	$objVoucherdate= new  VoucherMasterMgmt();
	   	$result = $objVoucherdate-> getVoucherDistinctDates("","",$condition,$order_field,$order_type);
	    $date_num= dbRows($result);
	   	
		$i=1;
		
		$table = array();
		if(dbRows($result) > 0){
       		while($row=dbArray($result)) {		  
			$table[$i]   = FormatDate($row["voucher_date"],"d/m/Y");	
			$voucher_ids = $row["voucher_ids"] ;
?>

<div style="width:70%;height:30px;">			
<div style="width:50%;float:left;text-align:left;">Date:<?php print $table[$i];?></div>
<div style="width:50%;float:right;text-align:right;">Date: <?php print $_POST['profitstartdate']; ?> To : <?php print $_POST['profitenddate'] ; ?></div>
</div>
<table width="70%" style="border:none;">
	<tr>
		<td align="center" width="40%"><b>Credit</b></td>
		<td align="right" width="10%"><b>Amount</b></td>
		<td align="center" width="40%"><b>Debit</b></td>
		<td align="right" width="10%"><b>Amount</b></td>
	</tr>
	<tr>
		<td><b>Op.Balance</b></td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<?php 
				$order_field="";	
			   	$order_type="";
				$condition =" AND find_in_set(voucher_id,'".$row["voucher_ids"]."') ";
				$limit=0;
				$start=0;
				
				$arrayDayBookEntry = $objVoucherdate->getDayBookEntry($limit,$start,$condition,$order_field,$order_type);
			    
				$row_num = count($arrayDayBookEntry);
				
				
				if($row_num > 0) {
		?>	
		<!--			<table cellpadding="0" cellspacing="0" border="0" width="100%"> -->
		<?php		$j=0;			
                    $creditTotal = 0; 
					$debitTotal = 0;  		 		
					while($j < $row_num){
					 
		?>				
			<tr>
				<td width="40%"><?php echo $arrayDayBookEntry[$j]["CreditAccount"] ;?></td>
				<td width="10%"><?php echo $arrayDayBookEntry[$j]["CreditAmount"]  ;?></td>
				<td width="40%"><?php echo $arrayDayBookEntry[$j]["DebitAccount"]  ;?></td>
				<td width="10%"><?php echo $arrayDayBookEntry[$j]["DebitAmount"]  ;?></td>
			</tr>	
		<?php												
				$creditTotal += $arrayDayBookEntry[$j]["CreditAmount"] ;
				$debitTotal += $arrayDayBookEntry[$j]["DebitAmount"] ;
				$j++;
					}
		?>
		<!--			</table>	-->				
		<?php
				}
				
			?>
	<tr>
		<td align="center"><b> Total Credit</b></td>
		<td><b><?php echo $creditTotal ;?></b></td>
		<td align="center"><b>Total Debit</b></td>
		<td><b><?php echo $debitTotal ;?></b></td>
	</tr>			     
	<tr>
		<td>&nbsp; </td>
		<td>&nbsp;</td>
		<td><b>Closing Balance</b></td>
		<td>&nbsp;</td>
	</tr>	          
</table>
<br/>
<?php $i++;       
	   	}		 	
		}
		else{
			echo "No Data Found";      
		}
}
?>	
</div>	
<?php 
} ?>
<?php require "_footer.php";?>