<?php
session_start();
$i=1;
include("../include/config.php");
require_once "../include/Database_functions.php";

$pagetot = '';
$grandtot = '';
$vechicle_no ='';
$tripdate ='';
$client_code='';
if(isset($_REQUEST['client_code'])){
$client_code=$_REQUEST['client_code'];
}

/*if(isset($_REQUEST['tripdate'])){
$tripdate=$_REQUEST['tripdate'];
}*/

$i=1;

if(($_SESSION['typename'] == 'SuperAdmin')) {
			$sq_arr="select * from `cf_receipt` where type = 'cash'";
		}

if(($_SESSION['typename'] == 'SubAdmin')) {
	$userids = $_SESSION['admin_id'];
			
			$sq_clientid=mysql_query("select * from cf_user_clientid where user_id = $userids ");	
			while($rw = mysql_fetch_array($sq_clientid))
			{
				$clientcode= $rw['client_code'];
			}
				
			$sq_arr="select * from `cf_receipt` where type = 'cash' and client_code like '$clientcode%' ";
}

//$sq_arr="select * from `cf_receipt` where type = 'cash'";
if($client_code!=''){
$sq_arr.=" and client_code like '$client_code%' ";
}
/*
if($tripdate!=''){
$sq_arr.=" and 	trip_date = '".$tripdate."' ";
}*/

/*if($sdate_12!=''){
$sq_arr.=" and date='".$sdate."' ";
}*/
$sq_arr.=" order by rec_id desc ";
$query=$sq_arr;
//echo $query;
$function="Searchdate";
include("../pagingserch.php");
$sq_arr.=" LIMIT $start, $limit";

if(isset($_REQUEST['page'])){
$page=$_REQUEST['page'];
}else{
$page=10;
}

$array=mysql_query($sq_arr);

		$sumarray=mysql_query($query);
		while($rw1 = mysql_fetch_array($sumarray))
		{
			$grandtot = $grandtot + $rw1['acc_amt'];
		}
?>
<div style="margin-right:100px; margin-top:15px; font-weight:bold;color: #009999; text-align:right;">Total:<?=$grandtot?></div>
  <table  border="0" cellspacing="0" cellpadding="0" class="tableList">
  <tr class="heading">
    <td>No</td>
    <td>Client</td>
	<td>To</td>
    <td>Add Date</td>
    <td>Amount</td> 
    <td>Edit</td> 
    <td>Print</td> 
    <td>Delete</td> 
  </tr>
  
  <?php

if($array && mysql_num_rows($array)>0){
$pagecnt=$start;
while($res=mysql_fetch_array($array))
{
$pagecnt++;
  ?> 
 	<tr>
       <td><?php echo $res['receipt_id'];?></td>
       <td><?php echo $res['client_code'];?></td>
       <td><?php echo $res['to'];?></td>
       <td><?php echo date('d-m-Y', strtotime($res['acc_date']));?></td>
       <td><?php echo $res['acc_amt'];?></td>    
       <td class="tr_td_b"><a href="add-cash-receipt.php?recedit_id=<?php echo $res['rec_id']; ?>" style="color:#FF9900">Edit</a></td>  
       <td class="tr_td_b"><a href="add-cash-receipt.php?rec_id=<?php echo $res['rec_id']; ?>&flag=1&type=view" style="color:#FF9900">Print</a></td>  
       <td class="tr_td_r" ><a href="cash-receipt-list.php?del=delete&id=<?php echo $res['rec_id']; ?>" onClick="return confirm('Do you really want to delete this field?');"><img src="images/delete.png" title="Delete"></a></td> 
    </tr>
  <?php 
  $pagetot = $pagetot + $res['acc_amt'];
    }}
  ?>
 
  <!--<tr>
    <td><input type="checkbox">2</td>
    <td>2323d</td>
    <td>jinesh</td>
    <td>jose</td>
    <td>9443274636</td>
    <td>email@gmail.com</td>
    <td>design</td>
    <td>designer</td>
    <td>23/4/11</td>
    <td><div class="deletedStat"></div></td>
    <td><a href="#">
      <div class="actEdit"></div><div class="actDelete"></div>
    </a></td>
  </tr>-->
  
  <tr class="heading">
    <td></td>    
    <td></td>   
    <td></td>
    <td>page Total</td>
    <td><?=$pagetot?></td>
    <td></td> 
    <td></td> 
    <td></td> 
    <td></td>
   </tr>

   
</table>
  
   <div align="right" style="padding-top:10px;"><?=$pagination?></div>