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

$vechicle_no ='';
$tripdate ='';
$clientcode='';
$pagetot = '';
$grandtot = '';

if(isset($_REQUEST['vechicle_no'])){
$vechicle_no=$_REQUEST['vechicle_no'];
}

if(isset($_REQUEST['clientcode'])){
$clientcode=$_REQUEST['clientcode'];
}

if(isset($_REQUEST['tripdate'])){
$tripdate=$_REQUEST['tripdate'];
$tripdate1 = date('Y-m-d', strtotime($tripdate));
}

$i=1;
if(($_SESSION['typename'] == 'SuperAdmin')) {
	$sq_arr="select * from cf_tripsheet where advt_amt != '' and advt_amt != '0'";	
	
	if($vechicle_no!=''){
	$sq_arr.=" and trip_vechno = '".$vechicle_no."' ";
	}
	
	if($clientcode!=''){
	$sq_arr.=" and trip_sub_client_id = '".$clientcode."' ";
	}
	
	if($tripdate!=''){
	$sq_arr.=" and 	trip_date = '".$tripdate1."' ";
	}
}

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']."',";
	}
	
	$clientnames = substr($clientcode, 0, -1);	
	
	$sq_arr="select * from cf_tripsheet where advt_amt != '' and advt_amt != '0' and clientids IN ($clientnames)  "; 	
	
	if($vechicle_no!=''){
	$sq_arr.=" and trip_vechno = '".$vechicle_no."' ";
	}
	
	if($tripdate!=''){
	$sq_arr.=" and 	trip_date = '".$tripdate."' ";
	}
}

/*if($sdate_12!=''){
$sq_arr.=" and date='".$sdate."' ";
}*/
$sq_arr.=" order by trip_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['advt_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" style="margin-top:10px;">
  <tr class="heading">
    <td>No</td>
    <td>Advance Voucher No</td>
    <td>Vechicle No</td>
    <td>Trip Date</td>
    <td>Amount</td> 
    <td>Settled(Y/N)</td>
    <td>Print</td>   
  </tr>
  
  <?php


if($array && mysql_num_rows($array)>0){
$pagecnt=$start;
while($res=mysql_fetch_array($array))
{
$pagecnt++;
  ?> 
 	<tr>
        <td><?php echo $pagecnt;?></td>
        <td><?php echo $res['advt_no'];?></td>
        <td><?php echo $res['trip_vechno'];?></td>
        <td><?php echo date('d-m-Y', strtotime($res['trip_date']));?></td>
        <td><?php echo $res['advt_amt'];?></td>    
        <td>
	<?php 
		if($res['trip_status'] == 1)
		{ 
			echo "Yes";
		}
		else
		{ 
			echo "No";
		}		
	?></td>    
        <td class="tr_td_b"><a href="advance-printvoucher.php?trip_id=<?php echo $res['trip_id']; ?>&amt=<?=$res['advt_amt'];?>" style="color:#FF9900">Print</a></td>  
    </tr>
  <?php 
  $pagetot = $pagetot + $res['advt_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>
   </tr>
   
</table>
  
   <div align="right" style="padding-top:10px;"><?=$pagination?></div>