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

  <table  border="0" cellspacing="0" cellpadding="0" class="tableList">
  <tr class="heading">
    <td>No</td>
  	<td>Date</td>
    <td>Tripsheet No</td>
    <td>Gross Weight</td>
    <td>Hire Amount</td>
  </tr>
  
  <?php

$routeid ='';
$tripdate ='';
$fromdate='';
$todate='';
$clientcode='';

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

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

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

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

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

$i=1;
$clientcodeval = '';
if(($_SESSION['typename'] == 'SuperAdmin')) {
$sq_arr="select * from cf_tripsheet where trip_status = '0' and delete_status = '0' ";

if($clientcode!=''){
	$sq_arr.=" and trip_sub_client_id = '".$clientcode."' ";
	}
}

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))
	{
		$clientcodeval.= "'".$rw['client_code']."',";
	}
	
	$clientnames = substr($clientcodeval, 0, -1);	
	$sq_arr="select * from cf_tripsheet where trip_status = '0' and delete_status = '0' and clientids IN ($clientnames)";
	
}


if($routeid!=''){
$sq_arr.=" and trip_route_id = '".$routeid."' ";
}

if($tripdate!=''){
$sq_arr.=" and 	trip_date = '".$tripdate1."' ";
}

if($fromdate!="" && $todate!=""){
$sq_arr.=" and trip_date between '$fromdate1' and '$todate1'";
}

/*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);
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 date('d-m-Y', strtotime($res['trip_date']));?></td>
  	<td><?php echo $res['trip_newsrno'];?></td>
    <td><?php echo $res['gross_weight'];?></td>
     <?php 
		//echo $res['hire_amt'];
		$kms= $res['kms'];
		$tripvechno = $res['trip_vechno'];
		//echo "select * from cf_vehicle where vehiclenum = '$tripvechno'  ";
		$sq_arr2=mysql_query("select * from cf_vehicle where vehiclenum = '$tripvechno'  ");
		$row2 = mysql_fetch_array($sq_arr2);
		$ratekms = $row2['ratekm'];
		$hiredamt = $ratekms * $kms; 
	?>
    <td><?php echo $hiredamt; ?></td>
  </tr>
  <?php 
    }}
  ?>
 
  <!--<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>-->

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