<?php
$debit="";
$credit="";
$from="";
$to="";
if(isset($_REQUEST['from']))
$from=$_REQUEST['from'];
if(isset($_REQUEST['to']))
$to=$_REQUEST['to'];
include("../include/config.php");
require_once "../include/Database_functions.php";
$sqlObj=new sqlclass();
?>
<table width="60%" border="0" cellspacing="0" cellpadding="5">
      <tr>
        <td width="22%" height="30" align="center" valign="middle" style="border:#333333 1px solid;"><strong>Date</strong></td>
        <td width="42%" height="30" align="center" valign="middle" style="border:#333333 1px solid;"><strong>Particulars</strong></td>
        <td width="15%" align="center" valign="middle" style="border:#333333 1px solid;"><strong>Credit</strong></td>
        <td width="21%" align="center" valign="middle" style="border:#333333 1px solid;"><strong>Debit</strong></td>
      </tr>
	  <?php
	    $i=1;
		$limit=10;
		$sq_arr="select * from tbl_report  ";
	    if($from!='' && $to!=''){
		$sq_arr="select * from tbl_report where  date between '$from' and '$to' ";
		}
		if($from!='' && $to==''){
		$sq_arr="select * from tbl_report where  date>='$from' ";
		}
		if($from=='' && $to!=''){
		$sq_arr="select * from tbl_report where  date<='$to' ";
		}
	  $function="data";
	  $query=$sq_arr;
	  include("../paging.php");
	 $sq_arr.=" LIMIT $start, $limit";
	  $array=mysql_query($sq_arr);
	  while($result=mysql_fetch_array($array))
	  {
	  	  if($result['type'] == 'reciept')
		  {
		  $type="company";
		  }else if($result['type'] == 'voucher')
		  {
		  $type="clients";
		  }
		  
		  $dat_today=$result['date'];
		  $dat_today=explode("-",$dat_today); 
		  
	  ?>  
        <tr  >
         <td width="22%" height="30" align="center" valign="middle" style="border:#333333 1px solid;"><strong><?php echo $dat_today[2].'-'.$dat_today[1].'-'.$dat_today[0]?></strong></td> 
        <td width="42%" height="30" align="center" valign="middle" style="border:#333333 1px solid;"><strong><?php  echo $result['category'];?>	</strong></td>
        <td width="15%" align="center" valign="middle" style="border:#333333 1px solid;"><strong><?php if($result['type'] == 'reciept'){echo $result['cash'];}else{echo '--';}?>	</strong></td>
        <td width="21%" align="center" valign="middle" style="border:#333333 1px solid;"><strong><?php if($result['type'] == 'voucher'){echo $result['cash'];}else{echo '--';}?></strong></td>
      </tr>
	  <?php
	  $i++;}
	  $credit=mysql_query("select sum(cash) as sal from tbl_report where type='reciept'");
	  if($from!='' && $to!=''){
		$credit=mysql_query("select sum(cash) as sal from tbl_report where type='reciept' and date between '$from' and '$to'");
		}
	  if($credit){
$result=mysql_fetch_array($credit);
$cre=$result['sal'];
}
$debit=mysql_query("select sum(cash) as pay from tbl_report where type='voucher'");
if($from!='' && $to!=''){
		$debit=mysql_query("select sum(cash) as pay from tbl_report where type='voucher' and date between '$from' and '$to'");
		}
if($debit){
$res=mysql_fetch_array($debit);
$deb=$res['pay'];
}
if($cre>0){
	  ?>
	  <tr><td style="border-top:#333333 1px solid;">&nbsp;</td><td colspan="2" align="right" style="border-top:#333333 1px solid;">Total Credit : <?php echo $cre; ?></td>
	  <td align="left" style="border-top:#333333 1px solid;">Total Debit :  <?php echo $deb; ?></td></tr>
	  <? }if($deb>0){?>
	   <tr>
        <td align="center" >&nbsp;</td>
        <td align="right" >&nbsp;		 </td>
        <td colspan="2" align="left" > <?php $pl=$cre-$deb; ?>
          Profit / Loss   <span class="style1"><?php echo $pl; ?></span></td>
        </tr>
		<? }?>
	  <tr>
	    <td align="center" >&nbsp;</td>
	    <td align="right" >
		<? $credit1=mysql_query("select liquidcash from tbl_cash where type='cash'");
			if($credit1){
				$result1=mysql_fetch_array($credit1);
				$cre1=$result1['liquidcash'];
			}
				$debit1=mysql_query("select bankcash from tbl_cash where type='cheque'");
			if($debit1){
				$res1=mysql_fetch_array($debit1);
				$deb1=$res1['bankcash'];
			}
		?>
</td>
	    <td colspan="2" align="left" >&nbsp;</td>
	    </tr>
		<? if(mysql_num_rows($credit1)>0){?>
	  <tr>
	    <td align="center" >&nbsp;</td>
	    <td align="right" >Cash : </td>
	    <td colspan="2" align="left" class="err_msg"><b><?=$cre1?></b></td>
	    </tr>
		<? }if(mysql_num_rows($debit1)>0){?>
	  <tr>
	    <td align="center" >&nbsp;</td>
	    <td align="right" >Cheque : </td>
	    <td colspan="2" align="left" class="err_msg"><b><?=$deb1?></b></td>
	    </tr>
	 <? }?>
	  
	   <tr><td colspan="3"><div align="right" style="padding-top:10px;"><?=$pagination?></div></td></tr>
    </table>