<?php

$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>Trip Date</td>
    <td>Trip No</td>
    <td>Client Code</td>
    <td>Dealer</td>
    <td>Town</td>
    <td>Inv No</td>
    <td>Inv Date</td>
    <td>Gross Weight</td>
    <td>Frieght Amount</td>
  </tr>
  
  <?php
  
$dealername='';
$clientcode='';
$tripdate='';
$fromdate='';
$todate='';

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

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

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


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

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

$i=1;
/*$sq_arr="select cf_tripsheetsub.trip_dealer as dealers,cf_tripsheetsub.trip_location as locations,cf_tripsheetsub.invoice_no as invoiceno,cf_tripsheetsub.invoice_date as invoicedate,cf_tripsheetsub.grossweight as grossweights,cf_tripsheet.trip_newsrno as tripsrno,cf_tripsheet.trip_date as tripdate,cf_tripsheet.bal_amt as balamt from cf_tripsheetsub left join cf_tripsheet on cf_tripsheet.trip_id = cf_tripsheetsub.trip_id where 1 ";*/

$sq_arr="select cf_tripsheet.trip_id as tripid, 
	   cf_tripsheetsub.trip_dealer as dealers,
	   cf_tripsheetsub.trip_location as locations,
       cf_tripsheetsub.trip_location_id as locationids,
       cf_tripsheetsub.invoice_no as invoiceno,
       cf_tripsheetsub.invoice_date as invoicedate,
       cf_tripsheetsub.grossweight as grossweights,
       cf_tripsheet.trip_newsrno as tripsrno,
       cf_tripsheet.trip_date as tripdate,
       cf_tripsheet.trip_sub_client_id as tripsubclientid,
       cf_tripsheet.bal_amt as balamt,
       cf_client.client_newcode as clientcode
       from cf_tripsheetsub left join cf_tripsheet on cf_tripsheet.trip_id = cf_tripsheetsub.trip_id join cf_client on cf_tripsheet.trip_sub_client_id =  cf_client.client_sub_id where 1 ";

if($dealername!=''){
$sq_arr.=" and 	cf_tripsheetsub.trip_dealer = '".$dealername."' ";
}

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


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

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

/*if($sdate_12!=''){
$sq_arr.=" and date='".$sdate."' ";
}*/
$sq_arr.=" order by cf_tripsheet.trip_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;
}
$newgross = 0;
$newfrieght =0;
$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 $res['tripdate'];?></td>
    <td><?php echo $res['tripsrno'];?></td>
    <td><?php echo $res['clientcode'];?></td>
    <td><?php echo $res['dealers'];?></td>    
    <td><?php echo $res['locations'];?></td>
    <td><?php echo $res['invoiceno'];?></td>
    <td><?php echo $res['invoicedate'];?></td>
    <td><?php echo $res['grossweights'];?></td>
    <?php 
    $newgross+= $res['grossweights'];
	$newfrieght+= $res['balamt'];
	
	$clientids = $res['tripsubclientid'];	
	$triplocationid = $res['locationids'];
	//echo "select * from cf_rate_act where  client_code = '$clientids' and rate_district_id = '$triplocationid'";
	$sqlrate = mysql_query("select * from cf_rate_act where  client_code = '$clientids' and rate_district_id = '$triplocationid'");
		$rw12 = mysql_fetch_array($sqlrate);
		$rates = $rw12['rate'];
		$newfreight = $rates * $res['grossweights'];
	
	?>
    <td><?php echo $newfreight;?></td>
  </tr>
  <?php 
    }}
  ?>
 
<?php /*?>  <tr class="heading">
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>Total</td>
    <td><?=$newgross?></td>
    <td><?=$newfrieght?></td>
   
  </tr><?php */?>

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