<?php
$frmdate11='';
$todate_11='';
$sdate_12='';
$billno='';
$frmdate1='';
$todate_1='';
$todate_12='';
$from='';
$to='';
$sdate='';
$typeno='';

if(isset($_REQUEST['frmdate1'])){
$frmdate11=$_REQUEST['frmdate1'];
$frmdate1=explode("-",$frmdate11);
$from=$frmdate1[2].'-'.$frmdate1[1].'-'.$frmdate1[0];
}
if(isset($_REQUEST['todate_1'])){
$todate_11=$_REQUEST['todate_1'];
$todate_1=explode("-",$todate_11);
$to  =$todate_1[2].'-'.$todate_1[1].'-'.$todate_1[0];
}
if(isset($_REQUEST['singdate'])){
$sdate_12=$_REQUEST['singdate'];
$todate_12=explode("-",$sdate_12);
$sdate=$todate_12[2].'-'.$todate_12[1].'-'.$todate_12[0];
}
if(isset($_REQUEST['billno'])){
$billno=$_REQUEST['billno'];
}


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


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

 <table width="98%" border="0" cellspacing="0" cellpadding="0">
     <tr>
      <th width="10%" align="left" valign="middle" class="tr_td">Container No</th>
      <th width="21%" align="left" valign="middle" class="tr_td">Vehicle No</th>
	  <th width="11%" align="left" valign="middle" class="tr_td">DRIVER</th>
	  <th width="12%" align="left" valign="middle" class="tr_td">Trip Status</th>
	  <th width="12%" align="left" valign="middle" class="tr_td">Mileage</th>
	  <th width="12%" align="left" valign="middle" class="tr_td">Expense</th>
      <th width="12%" align="left" valign="middle" class="tr_td">Given</th>
      <th width="9%" align="left" valign="middle" class="tr_td">RemAining</th>
      <th width="10%" align="left" valign="middle" class="tr_td">CONSIGNEE</th>   
      <th width="6%" align="left" valign="middle" class="tr_td">Due date</th>
      <th width="9%" colspan="2" align="left" valign="middle" class="tr_td">OPTION</th>
      </tr>
<?php
//$array=mysql_query("select * from tbl_trip_sheet order by bill_no asc");
$sq_arr="select * from tbl_trip_sheet where 1 ";
if($typeno!=''){
$sq_arr.=" and 	(status='".$typeno."') ";
}
if($billno!=''){
$sq_arr.=" and 	(container_no='".$billno."' or vehicle_no='".$billno."') ";
}
if($frmdate11!='' && $todate_11!=''){
$sq_arr.=" and date between '$from' and '$to' ";
}
if($frmdate11!='' && $todate_11==''){
$sq_arr.=" and date>='".$from."' ";
}
if($frmdate11=='' && $todate_11!=''){
$sq_arr.=" and date <='".$to."' ";
}
if($sdate_12!=''){
$sq_arr.=" and date='".$sdate."' ";
}
$sq_arr.=" order by id desc ";
$query=$sq_arr;

$function="Searchdate";
include("../paging.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){
while($res=mysql_fetch_array($array))
{
$dat_today=$res['date'];
$dat_today=explode("-",$dat_today);
if(is_null($res['driver_details'])){
$drv_det='---';
}else{
$drv_detid=$res['driver_details'];

$driver_sql=mysql_query("SELECT name FROM `tbl_employee` where id='".$drv_detid."'");
	if(mysql_num_rows($driver_sql)>0){
	$drv_obj=mysql_fetch_object($driver_sql);
	$drv_det=stripslashes($drv_obj->name); 
	}
	}
?>	
  <tr>
      <td class="tr_td"><?php echo $res['container_no']; ?></td>
      <td class="tr_td"><?php echo $res['vehicle_no'];?></td>
	  <td class="tr_td"><?php echo $drv_det;?></td>
	  <td class="tr_td">
	  <?php
	  		if($res['status'] == '0'){
				echo "Not Finished";
			}
			else{
				echo "Finished";
			}?></td>
			
			<td class="tr_td">
	  <?php
	  		echo $res['milage'];			
	  ?>
	  </td>
			
			
			
			<td class="tr_td">
	 <? 
	 if($res['total_expence']!=''){
	 echo $res['total_expence'];}else {echo '--';}?>
	  
	  </td>
      <td class="tr_td">
	 <? 
	 if($res['batta']!=''){
	 echo $res['batta'];}else {echo '--';}?>
	  
	  </td>
      <td class="tr_td">
	  <? 
	 if($res['amount_paid']>0){
	 echo $res['amount_paid'];}else {
	 if($res['amount_pend']>0){
	 echo '-'.$res['amount_pend'];
	 }else{	 
	 echo '--';
	 }}?>
	  
	  </td>
      <td class="tr_td"><?php echo $res['consignee'];?></td>
     <td class="tr_td"><?php echo $res['date'];?></td>
	 <td style="border-right:1px solid #000000;border-bottom:#6b6b6b solid 1px;border-left:#6b6b6b solid 1px; color:#616161;"><a href="view_trip_sheet.php?veh_no=<?php echo $res['id'];?>&page=<?php echo $page;?>"><img src="images/icon2.jpg" width="18" height="18" title="Edit"/></a>
	 <a href="trip-sheets.php?del=delete&id=<?php echo $res['id']; ?>&contno=<?php echo $res['container_no'] ?>&vechno=<?php echo $res['vehicle_no'] ?>" onclick="return confirm('Do you really want to delete this field?');"><img src="images/icon1.jpg" width="21" height="21" title="Delete"/></a>	
	 <a href="print_tripsheet.php?veh_no=<?php echo $res['id'];?>" target="_blank"><img src="images/icon4.jpg" width="22" height="20" /></a>
	  </td>
    </tr>
<?php
$i++;
}
}else{?>
 <tr>
      <td class="tr_td" colspan="3" ><span class="err_msg"><?php echo $res['bill_no']; ?></span>
	  </td>
	  </tr>
<? }
?>      </table>
 <div align="right" style="padding-top:10px;"><?=$pagination?></div>