<?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>Tripsheet No</td>
  	<td>Date</td>
    <td>Route Name</td>
    <td>Km</td> 
    <td>Gross Weight</td>
    <td>Net Amount</td>
  </tr>
  
  <?php

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

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

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));
}

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

$i=1;

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

if(($_SESSION['typename'] == 'SubAdmin')) {
	$userids = $_SESSION['admin_id'];
	$sq_arr="select * from cf_tripsheet where trip_status = '1' and client_inv_status = '1' and delete_status = '0' and trip_userid = '$userids' "; 	
}


if($vechicle_no!=''){
$sq_arr.=" and trip_vechno = '".$vechicle_no."' ";
}

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

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 $res['trip_newsrno'];?></td>
    <td><?php echo date('d-m-Y', strtotime($res['trip_date']));?></td>
  	<?php 
		$routeid = $res['trip_route_id'];
    	$sq_route1="select * from cf_route where route_id = '$routeid' ";
		$array2=mysql_query($sq_route1);
		$res2=mysql_fetch_array($array2);
	?>
  	<td><?php echo $res2['route_name'];?></td>
    <td><?php echo $res['kms'];?></td>
    <td><?php echo $res['gross_weight'];?></td>
    <?php
		
		
		$grosswgh = '';
	
		$tripids = $res['trip_id'];
		$clientids = $res['trip_sub_client_id'];
		$sq_1="select * from cf_tripsheetsub where trip_id = '$tripids' ";
		$array3=mysql_query($sq_1);
		while($res3=mysql_fetch_array($array3))
		{
			$locationid = $res3['trip_location_id'];
			//echo "select * from cf_rate_act where  client_code = '$clientids' and rate_district_id = '$locationid'";
			$sq_w=mysql_query("select * from cf_rate_act where  client_code = '$clientids' and rate_district_id = '$locationid'");
			$rw4 = mysql_fetch_array($sq_w);
			$rates = $rw4['rate'];
			$res3['grossweight'];
			//echo "<br/>";
			$grosswgh+= $res3['grossweight'] * $rates;
			//echo "<br/>";
		}
		//echo $grosswgh;
	?>
    <td><?php  echo round($grosswgh,2);?></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>