<?php
session_start();
$i=1;
include("../include/config.php");
require_once "../include/Database_functions.php";
$userids = $_SESSION['admin_id'];

$veh_num ='';
$clientcode='';
$tripdate ='';
$fromdate='';
$todate='';
$pagetot = '';
$grandtot = '';
$tripsheetno = '';
$saletype='';

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

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

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['client_code'])){
$client_code=$_REQUEST['client_code'];
}
if(isset($_REQUEST['saletype'])){
$saletype=$_REQUEST['saletype'];
}

$i=1;
$clientcodeid = '';

	$sq_arr="select * from cf_tripsheet left join cf_vehicle on cf_vehicle.id=cf_tripsheet.trip_vechno where cf_tripsheet.trip_status = 1 and cf_tripsheet.delete_status = 0 ";	

if($tripsheetno!=''){
$sq_arr.=" and cf_tripsheet.trip_newsrno like '%".$tripsheetno."%' ";
}
if($veh_num!=''){
$sq_arr.=" and cf_vehicle.vehiclenum like '%".$veh_num."%' ";
}



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


if($saletype!=''){
$sq_arr.=" and cf_tripsheet.trip_saletype = '".$saletype."' ";
}

/*if($sdate_12!=''){
$sq_arr.=" and date='".$sdate."' ";
}*/
$sq_arr.=" order by trip_start_date 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);
	
?>
<div style="margin-right:100px; margin-top:15px; font-weight:bold;color: #009999; text-align:right;"></div>
  <table  border="0" cellspacing="0" cellpadding="0" class="tableList" style="margin-top:10px;">
  <tr class="heading">
    <td>No</td>   
   
    <td>Tripsheet No</td>
    <td>Sales No</td>
    <td>Vehicle No</td>
	<td>Drv Name</td>
    <!--<td>Client Name</td>
    <td>Sales Type</td>-->
	<td>From</td>
	<td>To</td>
	<td>Km</td>
	<td>Start Date</td>    
	<td>Finish Date</td>      
    <td>Total</td>  
    <td align="center">Edit</td>  
    <td align="center">Delete</td>
	<td align="center">Cash Memo</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><a href="#login-box" class="login-window" data-id=<?php echo $res['trip_salesid'];?> data-chk=<?php echo $res['trip_saletype'];?> ><?php echo $res['trip_newsrno'];?></a></td>
    <?php 
    	$sq_veh=mysql_query("select * from cf_vehicle where id = '".$res['trip_vechno']."'");
		$rw = mysql_fetch_array($sq_veh);
		
		$sq_drv=mysql_query("select * from cf_driver where driver_id = '".$res['drv_id']."'");
		$rwdrv = mysql_fetch_array($sq_drv);
	?>
    
    <td><?php echo 'SL-'.$res['trip_salescodeno'];?></td> 
    <td><?php echo $rw['vehiclenum'];?></td> 
	<td><?php echo $rwdrv['drivername'];?></td>
    <?php /*?><td><?php echo $res['trip_client_name'];?></td>
    <td><?php echo $res['trip_saletype'];?></td><?php */?>
	<td><?php echo $res['from_place'];?></td>
	<td><?php echo $res['to_place'];?></td>
	<td><?php echo $res['kms'];?></td>
        
    <td><?php echo date(('d-m-Y h:s'),strtotime($res['trip_start_date']));?></td>  
	<td><?php echo date(('d-m-Y h:s'),strtotime($res['trip_finish_date']));?></td>    
    <td><?php echo $res['grand_tot'];?></td>
    
    
    <td align="center" class="tr_td_b"><a href="add_tripsheet.php?page=<?php echo $page; ?>&tripid=<?php echo $res['trip_id']; ?>&ab=<?php echo $i;?>" target="_blank"><img src="images/edit.png" title="edit"></a></td>  
       
    <td align="center" class="tr_td_r" ><a href="tripsheet_pending_list.php?trip_del=<?=$res['trip_id']?>&del=delete" onClick="return confirm('Do you really want to delete this field?');"><img src="images/delete.png" title="delete"></a></td>
	<td align="center" class="tr_td_r" ><a href="#login-box_2" class="login-window_2" style="font-weight:bold;" data-id=<?=$res['trip_id']?>>Add</a>/<a href="#login-box_2" class="login-window_3" style="font-weight:bold;" data-id=<?=$res['trip_id']?> data-chk=<?=$res['trip_newsrno']?>>View</a></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>-->
  <tr class="heading">
    <td></td>    
    <td></td>   
    <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>