<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}


$veh_num='';
$sdate_12 ='';
$page='1';$client_main='';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
$msg = '';
$client_namek ='';
if(isset($_REQUEST['client_name'])){
$client_namek=mysql_escape_string($_REQUEST['client_name']);
}
if(isset($_REQUEST['del']) && $_REQUEST['del']=='delete')
{
	$id = $_REQUEST['id'];
	if(isset($_REQUEST['client_main']))
	$client_main=$_REQUEST['client_main'];
	$sql=mysql_query("delete from cf_route where route_id='".$id."'");
	header("location:route_list.php?client_main=".$client_main."&page=".$page."&client_name=".$client_namek."&msg=You Have Successfully Deleted");
}

$tablename='cf_tripsheet';




if(isset($_POST['btnsubmit']))
{
	
	if(isset($_POST['tripnum'])){
	$tripnum=addslashes($_POST['tripnum']);
	}
	$trip_num = explode("-",$tripnum);
	
	if(isset($_POST['sale_order_no'])){
	$saleorderno=addslashes($_POST['sale_order_no']);
	}
	if(isset($_POST['purchase_id'])){
	$purchase_id=addslashes($_POST['purchase_id']);
	}
	
	if(isset($_POST['sales_code_no'])){
	$salescodeno=addslashes($_POST['sales_code_no']);
	}
	
	
	/*echo "select * from cf_sales join cf_client on cf_sales.sales_clientid = cf_client.client_id where cf_sales.sales_id = '$saleorderno'";
	exit;*/
	
	$sq_client=mysql_query("select * from cf_sales join cf_client on cf_sales.sales_clientid = cf_client.client_id where cf_sales.sales_id = '$saleorderno'");
	$row = mysql_fetch_array($sq_client);
	$sales_type = $row['sales_type'];
	$sales_clientid = $row['sales_clientid'];
	$client_name = $row['client_name'];
	$client_code = $row['client_code'];
	$client_address = $row['client_address'];
	$client_phno = $row['client_phno'];
	
	
	if(isset($_POST['trip_start_date'])){
	$tripstartdate=addslashes($_POST['trip_start_date']);
	$tripstartdate1 = date('Y-m-d h:s', strtotime($tripstartdate));
	}
	
	
	if(isset($_POST['trip_finish_date'])){
	$tripfinishdate=addslashes($_POST['trip_finish_date']);
	$tripfinishdate1 = date('Y-m-d', strtotime($tripfinishdate));
	}
	
	if(isset($_POST['vechicle_no'])){
	$vechno=addslashes($_POST['vechicle_no']);
	}
	
	if(isset($_POST['currentkm'])){
	$currentkm=addslashes($_POST['currentkm']);
	}
	
	if(isset($_POST['returnkm'])){
	$returnkm=addslashes($_POST['returnkm']);
	}
	
	if(isset($_POST['km_val'])){
	$km_val=addslashes($_POST['km_val']);
	}
	
	if(isset($_POST['milage'])){
	$milage=addslashes($_POST['milage']);
	}	
	
	if(isset($_POST['diesel'])){
	$diesel=addslashes($_POST['diesel']);
	}
	
	if(isset($_POST['wg_in_tons'])){
	$wg_intons=addslashes($_POST['wg_in_tons']);
	}
	
	if(isset($_POST['wg_in_tons_client'])){
	$wg_intons_client=addslashes($_POST['wg_in_tons_client']);
	}
	
	if(isset($_POST['tripstatus'])){
	$tripstatus=addslashes($_POST['tripstatus']);
	}
	
	if(isset($_POST['grd_tot'])){
	$grdtot=addslashes($_POST['grd_tot']);
	}
	
	if(isset($_POST['froms'])){
	$froms=addslashes($_POST['froms']);
	}
	
	if(isset($_POST['tos'])){
	$tos=addslashes($_POST['tos']);
	}
	
	if(isset($_POST['driver_name'])){
	$driver_id=addslashes($_POST['driver_name']);
	}
	
	if(isset($_POST['driver_batta'])){
	$driver_batta=addslashes($_POST['driver_batta']);
	}	
	
	if(isset($_POST['advance_amt'])){
	$advance_amt=addslashes($_POST['advance_amt']);
	}
	
	if(isset($_POST['haultchg'])){
	$haultchg=addslashes($_POST['haultchg']);
	}
	
	
	/**/
	
	
	$today = date('Y-m-d');
	
	$sqlObj->tablename=$tablename;
			
			$sqlObj->fieldname='(trip_newsrno,trip_client_id,trip_salesid,trip_salescodeno,trip_saletype,trip_client_name,trip_client_address,trip_client_phno,trip_start_date,trip_finish_date,trip_addate,trip_vechno,from_place,to_place,drv_batta,drv_id,advance_amt,hault_chg_amt,current_km,returnkm,kms,milage,diesel,trip_autono,wg_in_ton,wg_in_ton_client,grand_tot,trip_status,trip_purchase_id)';
			$sqlObj->fieldvalue='"'.$tripnum.'","'.$sales_clientid.'","'.$saleorderno.'","'.$salescodeno.'","'.$sales_type.'","'.$client_name.'","'.$client_address.'","'.$client_phno.'","'.$tripstartdate1.'","'.$tripfinishdate1.'","'.$today.'","'.$vechno.'","'.$froms.'","'.$tos.'","'.$driver_batta.'","'.$driver_id.'","'.$advance_amt.'","'.$haultchg.'","'.$currentkm.'","'.$returnkm.'","'.$km_val.'","'.$milage.'","'.$diesel.'","'.$trip_num[2].'","'.$wg_intons.'","'.$wg_intons_client.'","'.$grdtot.'","'.$tripstatus.'","'.$purchase_id.'"';
			
			$qsy= "insert into ".$tablename.$sqlObj->fieldname." values(".$sqlObj->fieldvalue.")";
			$CreateClient 	= mysql_query($qsy);
			
			if($returnkm !='' || $returnkm !='0')
			{
				$currentkm = $returnkm;
			}
			
			if($km_val!='' && $km_val>0)
			{
				mysql_query("update cf_vehicle set open_km='$currentkm' where id = '$vechno'");
			}
			
			header("location:tripsheet_pending_list.php");		
	
}

$tripsrno='';
$tripsaleid='';
$tripsalescodeno='';
$tripvechno='';
$tripsaletype='';
$trip_startdate='';
$trip_finishdate='';
$fromplace='';
$toplace='';
$drv_batta='';
$drv_ids='';
$cashmemo='';
$hault_chg_amt='';
$advance_amt='';
$current_km='';
$returnkm='';
$kms='';
$milage='';
$diesel='';
$wgintons= ''; 
$wgintonsclient= ''; 
$trip_status='';

if(!empty($_REQUEST['tripid']))
{
	$tripid = $_REQUEST['tripid'];
	$sq_trip=mysql_query("select * from cf_tripsheet where trip_id = '$tripid'");
	$rw = mysql_fetch_array($sq_trip);
	
	$tripsrno  = $rw['trip_newsrno'];
	$tripsaleid  = $rw['trip_salesid'];
	$tripsalescodeno  = $rw['trip_salescodeno'];
	$tripvechno  = $rw['trip_vechno'];
	$tripsaletype  = $rw['trip_saletype'];
	
	$trip_purchase_id  = $rw['trip_purchase_id'];
	
	//$trip_startdate = $rw['trip_start_date'];
	//$trip_finishdate = $rw['trip_finish_date'];
	
	$trip_startdate = date('d-m-Y h:s:i',strtotime($rw['trip_start_date']));
	$trip_finishdate = date('d-m-Y h:s:i',strtotime($rw['trip_finish_date']));
	
	$current_km = $rw['current_km'];
	$fromplace = $rw['from_place'];
	$toplace = $rw['to_place'];
	
	$drv_batta = $rw['drv_batta'];
	$drv_ids = $rw['drv_id'];
	$cashmemo = $rw['cash_memo'];
	
	$hault_chg_amt = $rw['hault_chg_amt'];
	$advance_amt = $rw['advance_amt'];
	$returnkm = $rw['returnkm'];
	$kms = $rw['kms'];
	$milage = $rw['milage'];
	$diesel = $rw['diesel'];
	$wgintons = $rw['wg_in_ton']; 
	$wgintonsclient = $rw['wg_in_ton_client']; 
	$trip_status = $rw['trip_status']; 
	
	//$sales_clientid = $row['sales_clientid'];

}

if(isset($_POST['uptsubmit']))
{
	
	if(isset($_POST['trip_id'])){
	$trip_id=addslashes($_POST['trip_id']);
	}
	
	if(isset($_POST['trip_start_date'])){
	$tripstartdate=addslashes($_POST['trip_start_date']);
	$tripstartdate1 = date('Y-m-d h:s', strtotime($tripstartdate));
	}
	else if(isset($_POST['hiddentrip_start_date'])){
	$tripstartdate=addslashes($_POST['hiddentrip_start_date']);
	$tripstartdate1 = date('Y-m-d h:s', strtotime($tripstartdate));
	}
	//echo $tripstartdate1;
	
	
	if(isset($_POST['trip_finish_date'])){
	$tripfinishdate=addslashes($_POST['trip_finish_date']);
	$tripfinishdate1 = date('Y-m-d', strtotime($tripfinishdate));
	}
	else if(isset($_POST['hiddentrip_finish_date'])){
	$tripfinishdate=addslashes($_POST['hiddentrip_finish_date']);
	$tripfinishdate1 = date('Y-m-d', strtotime($tripfinishdate));
	}
	//echo $tripfinishdate1;
	//exit;
	if(isset($_POST['vechicle_no'])){
	$vechno=addslashes($_POST['vechicle_no']);
	}
	
	if(isset($_POST['currentkm'])){
	$currentkm=addslashes($_POST['currentkm']);
	}
	
	if(isset($_POST['returnkm'])){
	$returnkm=addslashes($_POST['returnkm']);
	}
	
	if(isset($_POST['km_val'])){
	$km_val=addslashes($_POST['km_val']);
	}
	
	if(isset($_POST['milage'])){
	$milage=addslashes($_POST['milage']);
	}
	
	if(isset($_POST['diesel'])){
	$diesel=addslashes($_POST['diesel']);
	}
	
	if(isset($_POST['wg_in_tons'])){
	$wg_intons=addslashes($_POST['wg_in_tons']);
	}
	
	if(isset($_POST['wg_in_tons_client'])){
	$wg_intons_client=addslashes($_POST['wg_in_tons_client']);
	}
	
	if(isset($_POST['tripstatus'])){
	$tripstatus=addslashes($_POST['tripstatus']);
	}
	
	if(isset($_POST['grd_tot'])){
	$grdtot=addslashes($_POST['grd_tot']);
	}
	
	if(isset($_POST['froms'])){
	$froms=addslashes($_POST['froms']);
	}
	
	if(isset($_POST['tos'])){
	$tos=addslashes($_POST['tos']);
	}
	
	if(isset($_POST['driver_batta'])){
	$driver_batta=addslashes($_POST['driver_batta']);
	}
	
	if(isset($_POST['driver_name'])){
	$driver_id=addslashes($_POST['driver_name']);
	}	
	
	if(isset($_POST['advance_amt'])){
	$advance_amt=addslashes($_POST['advance_amt']);
	}	
	
	if(isset($_POST['haultchg'])){
	$haultchg=addslashes($_POST['haultchg']);
	}
	
	mysql_query("update cf_tripsheet set trip_start_date='$tripstartdate1',trip_finish_date='$tripfinishdate1',trip_vechno='$vechno',drv_batta='$driver_batta',drv_id='$driver_id',hault_chg_amt='$haultchg',advance_amt='$advance_amt',from_place='$froms',to_place='$tos',current_km='$currentkm',returnkm='$returnkm',kms='$km_val',milage='$milage',diesel='$diesel',wg_in_ton='$wg_intons',wg_in_ton_client='$wg_intons_client',trip_status='$tripstatus',grand_tot='$grdtot' where trip_id = '$trip_id'");
	
	if($km_val!='' && $km_val>0)
	{
		if($returnkm !='' || $returnkm !='0')
			{
				$currentkm = $returnkm;
			}
	
		mysql_query("update cf_vehicle set open_km='$currentkm' where id = '$vechno'");
	}
	
		$sqlmilage_cnt = mysql_query("select * from cf_milage where vehicle_id = '$vechno'");
		if(mysql_num_rows($sqlmilage_cnt)==0)
		{
		
			$sqlveh = mysql_query("SELECT SUM(milage)/2 as milageval,count(trip_id) as cnt FROM (SELECT * FROM cf_tripsheet WHERE trip_vechno = '$vechno' and milage!= '0' order by trip_id ASC limit 2)  AS t1 ");
			$rwveh = mysql_fetch_array($sqlveh);
			if($rwveh['cnt'] ==2)
			{
				$milageval = round($rwveh['milageval'],2);
				$sqlmilage = mysql_query("insert into cf_milage(vehicle_id,milage_km) values ($vechno,$milageval) ");
			}
	 	}
	
	if($_REQUEST['type'] == 'fn')
	{
		header("location:tripsheet_finish_list.php");				
	}
	else
	{
		header("location:tripsheet_pending_list.php");				
	}
	
}


$flag = 0;
if(isset($_POST['printpage']))
{
	$flag = 1;
}


?>


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OIL FILL</title>
<link href="css/styles.css" rel="stylesheet"  />
<link href="css/style-trip.css" rel="stylesheet" type="text/css" />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/datepick/themes/chosen.css">
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<!--<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>-->
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/cash_memopopup.js" type="text/javascript"></script>


<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />

<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>
<link rel="stylesheet" href="js/jquery.datetimepicker.css">
<script src="js/jquery.datetimepicker.js"></script>

<style>
.lableentrytext{
font-size: 12px;
color: #505050;
clear: both;
margin-bottom: 5px;
text-transform: capitalize;
}

body {
	padding:0px;
	margin:0px;
	font-family:Arial, Helvetica, sans-serif;
	color:#000000;
}
.div01 {
	width:80%;
		margin:0 70px;
	padding-bottom:15px;
}
.ptForm {
	/*border:1px solid #000000;*/
	width:100%;
	margin:0 auto;
	padding:4px;
}
.ptText01 {
	font-size:20px;
	font-weight:bold;
}
.ptText02 {
	font-size:12px;
}
.ptText03 {
	font-size:12px;
	font-weight:bold;
}
.ptText04 {
	font-size:12px;
	font-weight:bold;
	border-left:solid 1px #000000;
	border-right:solid 1px #000000;
	border-top:solid 1px #000000;
}
.ptText05 {
	font-size:14px;
	font-weight:bold;
}
.field01 {
	border-bottom:#333333 dotted 1px;
	border-left:none;
	border-top:none;
	border-right:none;
	color:#000000;
	font-size:12px;
	font-weight:bold;
	background-color:#f1f1f1;
}
.field02 {
	border:none;
	color:#000000;
	font-size:12px;
	font-weight:bold;
	background-color:#f1f1f1;
}
.ptText06 {
	font-size:12px;
	font-weight:bold;
}
.rightTd {
	border-bottom:solid 1px #000000;
}
.leftTd {
	border-bottom:solid 1px #000000;
	border-right:solid 1px #000000;
	padding:4px;
}
.tdItem {
	border-bottom:solid 1px #000000;
	border-right:solid 1px #000000;
	padding:4px;
}
.rightTd {
	border-bottom:solid 1px #000000;
	padding:4px;
}
/*.rightTdBtm {
	border:none;
	padding:4px;
}
.leftTdBtm {
	border-right:solid 1px #000000;
	padding:4px;
}*/
.tdItemBtm {
	
	padding:4px;
}

#adv{

	display:none;
	
}


.ckl{
	 background-image:url(images/inputBg.gif); border:none; background-repeat:repeat-x; border-radius:4px; height:29px; padding:0 0px; border:1px solid #cccccc; 
}


</style>

<script>



function addmorefiled(cnt){		

	//------Add More Surety (Add Member Form)
  var dec=parseInt(cnt)-parseInt(1);
  if(document.getElementById("rem"+dec)){
  document.getElementById("rem"+dec).innerHTML='<a style="cursor:hand;cursor:pointer;font-weight:bold;" onclick="remfiled('+cnt+')">Remove</a>';
  }
 
  var k=parseInt(cnt)+parseInt(1);
//  var a =  $('#MemberModelName21').html();
  document.getElementById("addmoreid"+cnt).innerHTML=' <table cellpadding="5"><tr><td style="padding-right:10px;">Particulars</td><td><p><input type="text" name="particular'+cnt+'" style="width:100px;border:1px solid #ccc;" class="input1 input3" id="particular'+cnt+'" ></p></td><td style="padding-right:10px;">Amount</td><td><p><input type="text" name="amount'+cnt+'" style="width:100px;border:1px solid #ccc;" class="input1 input3" id="amount'+cnt+'" ></p></td><td><p class="input1 " id="rem'+cnt+'"><a style="cursor:hand;cursor:pointer;font-weight:bold;" onclick="addmorefiled('+k+')">Add More</a></p></td></tr></table><br/><div id="addmoreid'+k+'"></div>';
 if(document.getElementById("totalmemcnt")){
 document.getElementById("totalmemcnt").value=cnt;
 }
  }
/*$(document).ready(function(){
$('#trip_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});

$('#trip_finish_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});
*/



function getXMLHTTP()
	 { //fuction to return the xml http object
	var xmlhttp=false;	
		try
		{
		xmlhttp=new XMLHttpRequest();
		}
		catch(e)	
		{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(e)
			{
				try
				{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1)
				{
				xmlhttp=false;
				}
			}
		}
	return xmlhttp;
	}   


function Searchdate(page,val)
{ 
	var page=page;	
	var strURL="ajax/route_data.php?&page="+page;
	if(val!=''){
	strURL+="&client_name="+val;
	}
	var req = getXMLHTTP();
   if (req)
   {
     req.onreadystatechange = function()
     {
		 
			if ((req.readyState == 0)||(req.readyState == 1)||(req.readyState == 2)||(req.readyState == 3))
      		{
			//document.getElementById('order').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			//document.getElementById('Cakeorder').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			}
		 
		 
      if (req.readyState == 4)
      {
	 // only if "OK"
	 	if (req.status == 200)
	 	{ 
	   document.getElementById('list').innerHTML=req.responseText;
	//	document.getElementById('Cakeorder').innerHTML=req.responseText;
	 	}
	  else 
	 	{
   	   alert("There was a problem while using XMLHTTP:\n" + req.statusText);

	 }
     }
     }
   req.open("GET", strURL, true);
   req.send(null);
   }
}
//code select
function showClientcodedropdown(str){
var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtcodeshow").innerHTML="";
  Searchdate(1,str);
  return;
  }
  
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("txtcodeshow").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","clientajax_code_dropdown.php?str="+str,true);
xmlhttp.send();
}

function getclientdetails(val){

	var xmlhttp;    
if (val=="")
  {
  document.getElementById("txtHintClient").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("txtHintClient").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getajax_clientdetails.php?str="+val,true);
xmlhttp.send();

getSalesdetails(val);
}

function getSalesdetails(val){

	var xmlhttp;    
if (val=="")
  {
  document.getElementById("txtHintSales").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("txtHintSales").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getajax_salesdetails.php?str="+val,true);
xmlhttp.send();


}

function getvendordetails(val){
	var xmlhttp;    
if (val=="")
  {
  document.getElementById("txtHintClient").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("txtHintClient").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getajax_vendordetails.php?str="+val,true);
xmlhttp.send();

getpurchasedetails(val);
}
function getpurchasedetails(val){
	
	var xmlhttp;    
if (val=="")
  {
  document.getElementById("txtHintSales").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("txtHintSales").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getajax_purchasedetails.php?str="+val,true);
xmlhttp.send();
}

function showTripno(str)
{

//alert(str);
var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtHintTripno").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("txtHintTripno").innerHTML=xmlhttp.responseText;
	   document.getElementById("txtTripno").value=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","tripno_ajax.php?str="+str,true);
xmlhttp.send();
}

function getdriverbatta(str){

	var xmlhttp;    
	var frm = document.getElementById("froms").value;
	var to = document.getElementById("tos").value;

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  document.getElementById("driver_batta").value=xmlhttp.responseText;
    }
  }
  
  if(frm!='' && to!='')
  {
	xmlhttp.open("GET","get_deliveryarea_rate.php?from="+frm+"&to="+to,true);
	xmlhttp.send();
}
}

function getopenkm(str){
	var xmlhttp;    

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  var getveh = xmlhttp.responseText;
	  var res1 =  getveh.split("-");
	  //res1[0];
	  document.getElementById("currentkm").value=res1[0];
	  //document.getElementById("haultchg").value=res1[1]; // comment by nithya
	  //res = str.split("o");
    }
  }
xmlhttp.open("GET","get_openkm.php?str="+str,true);
xmlhttp.send();
}

//---------------------------------nithyya--------------------------------------------------------------//
function displayhaultingcharge(tripvechno){

if(document.getElementById("tripstatus").checked == true){

var trip_start_date = document.getElementById("trip_start_date").value;
var trip_finish_date = document.getElementById("trip_finish_date").value;

document.getElementById("trip_start_date").disabled = true;
document.getElementById("trip_finish_date").disabled = true;

document.getElementById("hiddentrip_start_date").value = trip_start_date;
document.getElementById("hiddentrip_finish_date").value = trip_finish_date;


var xmlhttp;    
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  var gethaultcharge = xmlhttp.responseText;
	  //alert(gethaultcharge);
	 // document.getElementById("haultchg").value =parseInt(gethaultcharge);
	 
    }
  }
xmlhttp.open("GET","gethaultcharge.php?vechno="+tripvechno+"&start="+trip_start_date+"&finish="+trip_finish_date,true);
xmlhttp.send();
}
else
{
//document.getElementById("haultchg").value =0;
document.getElementById("trip_start_date").disabled = false;
document.getElementById("trip_finish_date").disabled = false;
}
}

//---------------------------------End------------------------------------------------------------------//

function kmval(str){
	var currentkm = document.getElementById("currentkm").value;	
	var kmval = document.getElementById("km_val").value; 	
	var km = parseFloat(kmval)+parseFloat(currentkm);	
	document.getElementById("returnkm").value = km;
	getBatta(kmval,'km');
}

function getBatta(val,type)
{	
	var t=document.getElementById("batta_type").value;
	var km_rent=document.getElementById("km_rent").value;
	var tonnage_rent=document.getElementById("tonnage_rent").value;
	
	tonnage_rent
	var batta=0;	
	
	if(t=='km'){
		if(type=='type'){
			val=document.getElementById("km_val").value;
			batta=  ((parseFloat(val)*parseFloat(km_rent))*parseFloat(0.15));		
		}else if(type=='km'){
			batta=  ((parseFloat(val)*parseFloat(km_rent))*parseFloat(0.15));	
		}
		
	}	
	
	if(t=='tn'){
		if(type=='type'){
			val=document.getElementById("km_val").value;
		 batta=  (parseFloat(val)*parseFloat(km_rent));		
		}else if(type=='km'){
			 batta=  (parseFloat(val)*parseFloat(km_rent));	
		}
		
	}
	
	
	if(t=='tng'){
			
				val=document.getElementById("wg_in_tons").value;		
				 batta=  ((parseFloat(val)*parseFloat(tonnage_rent))*parseFloat(0.15));	
			
			
	}
	
	if(t=='others'){
		
			val=document.getElementById("wg_in_tons").value;		
			 batta=  (parseFloat(val)*parseFloat(tonnage_rent));
						
	}	
	
	if(batta>0){
		document.getElementById("driver_batta").value = batta;
	}else{
		document.getElementById("driver_batta").value ='0.00';
	}
	
}


function getmilage(val){
	var kmval = document.getElementById("km_val").value;
	var milage = kmval/val; 
	document.getElementById("milage").value = milage.toFixed(2);
}

function validation(){

if(document.tripform.vechicle_no.value==''){
alert("Enter the Vehicle Name");
document.tripform.vechicle_no.focus();
return false;
}

/*if(document.tripform.sale_order_no.value==''){
alert("Enter the Sales Id");
document.tripform.sale_order_no.focus();
return false;
}*/

if(document.tripform.trip_date.value==''){
alert("Enter the Trip Date");
document.tripform.trip_date.focus();
return false;
}

if(document.tripform.km_val.value==''){
alert("Enter the Km");
document.tripform.km_val.focus();
return false;
}

if(document.tripform.diesel.value==''){
alert("Enter the diesel");
document.tripform.diesel.focus();
return false;
}

/*if ( ( document.frmname.vehtype[0].checked == false ) && ( document.frmname.vehtype[1].checked == false ) ) { alert ( "Please check Vechicle Type" ); return false; }

	if(document.frmname.vehiclenum.value==''){
	alert("Enter the Vehicle Number");
	document.frmname.vehiclenum.focus();
	return false;
	}*/
}

function printDiv(divName) {
	 var printContents = document.getElementById(divName).innerHTML;
	document.getElementById(divName).style.display = 'none';
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;
     window.print();     
	setTimeout(function(){document.body.innerHTML = originalContents;},3000);
	
}

function getSales()
{
	 $("#salesStdiv").show();
     $("#purchaseStdiv").hide();
}

function getPurchase()
{
	 $("#purchaseStdiv").show();
     $("#salesStdiv").hide();
}



</script>

<!----------------------- script for autocomplete------------------------------>
		
		<script type="text/javascript"> 
		   jQuery(function(){
			 jQuery('#trip_start_date').datetimepicker({
			  format:'d-m-Y h:i',
			  onShow:function( ct ){
			   this.setOptions({
				maxDate:jQuery('#trip_finish_date').val()?jQuery('#trip_finish_date').val():false
			   })
			  },
			  timepicker:true
			 });
			 jQuery('#trip_finish_date').datetimepicker({
			  format:'d-m-Y h:i',
			  onShow:function( ct ){
			   this.setOptions({
				minDate:jQuery('#trip_start_date').val()?jQuery('#trip_start_date').val():false
			   })
			  },
			  timepicker:true
			 });
			});		
		
				
		</script>

<!----------------end of script -------------------------------->
</head>

<body onLoad="<?php if($flag == '1'){?>printDiv('div01');<?php }?>">
<!------------------popup area (view, edit)--------------->



<!---------------popup area ends------------------>

<div class="viewEmployeePopup login-popup"  id="login-box" style="width:700px;height:400px;">
<a href="#" class="close"><img src="images/close.png" class="btn_close" title="Close Window" alt="Close" /></a>
   <div id="popupid"></div>
   
     
    </div>
<div class="wrapper">
   <div>
<?php 
	include("header.php");
?>
 
</div>

 <div class="tabbedArea" style="position:relative; margin-top:">

  
  <div class="tabBody">
   <h1>TripSheet</h1>  
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px; ">
  
   <div class="container">
  <!-- /top-wrap -->
<div class="content-wrap">
<div class="cart-back-title">
  <h2>Trip Sheet</h2>
  <p>Address Come Here...</p>
  <!-- /attendance-cell-1 -->
</div>
</div><!-- /content-wrap --> 


<div class="display-cell-1">
<form action="" name="tripform" method="post" >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  
  <tr>
      <td><table width="100%" border="0" cellspacing="2" cellpadding="0">
      
      <tr>
        <td width="1900%" colspan="19" align="left" valign="top">
		<table width="100%" border="0" cellspacing="2" cellpadding="0">
          
          <tr>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td colspan="3" align="right" valign="top" class="display-border-1">&nbsp;</td>
          </tr>
          <tr>
            <td width="45%" align="left" valign="top" class="display-border-1"><table width="100%" border="0" cellspacing="5" cellpadding="5">
              <?php 
				  $srno = '';
				  //if(!empty($_REQUEST['tripid']))
				  //{
				  /*$tripid = $_REQUEST['tripid'];
				  $sq_max=mysql_query("select * from cf_tripsheet where trip_id = '$tripid'");
				  $rowm = mysql_fetch_array($sq_max);
				  $srno = $rowm['trip_newsrno'];*/
				  //}
			 ?>
              <tr>
                <td width="29%" align="left" class="trip-font-2">Trip No</td>
                <td width="71%" align="left" class="trip-font-2"><input type="hidden" id="txtTripno" name="tripnum" >
                <div id="txtHintTripno" style="font-weight:bold;">
                  <?=$tripsrno?>
                </div></td>
              </tr>
              <tr>
                <td><span class="trip-font-2">Vehicle No</span></td>
				<td><select class="chzn-select restselect input3" name="vechicle_no" onChange="getopenkm(this.value)">
                    <option value="">Vehicle No</option>
                    <?php 
                            $sq_vechicle="select * from cf_vehicle";
                            $arr1=mysql_query($sq_vechicle);
                            while($resvechicle=mysql_fetch_array($arr1))
                            {
                        ?>
                    <option value="<?=$resvechicle['id']?>" <? if($resvechicle['id']==$tripvechno) {?>selected<? }?>>
                    <?=$resvechicle['vehiclenum']?>
                    </option>
                    <?php
                                }
                     ?>
                  </select>   </td>
              </tr>
			  <tr>
                <td><span class="trip-font-2">Type</span></td>
				<td><select class="chzn-select restselect input3" name="batta_type" id="batta_type" onChange="getBatta(this.value,'type');">
                    <option value=""></option>                   
                    <option value="km">Km</option>
                    <option value="tn">Tonne</option>
                    <option value="tng">Tonnage</option>                   
                    <option value="others">Others</option>                   
                  </select>  
				  <?php $sq_batta=mysql_query("select * from cf_batta_master");
                        $rw_batta=mysql_fetch_array($sq_batta);
					?>	
				  <input type="hidden" name="km_rent" id="km_rent" value="<?=$rw_batta['km_rent']?>">
				  <input type="hidden" name="tonnage_rent" id="tonnage_rent" value="<?=$rw_batta['tonnage_rent']?>">
				  
				   </td>
              </tr>
			  <tr>
                <td><span class="trip-font-2">From</span></td>
				<td><select class="chzn-select restselect input3" name="froms" id="froms" onChange="getdriverbatta(this.value)">
                    <option value="">From</option>
                    <?php 
                            $sq_deliveryarea="select * from cf_deliveryarea group by from_location";
                            $arrdrv1=mysql_query($sq_deliveryarea);
                            while($resdrv1=mysql_fetch_array($arrdrv1))
                            {
                        ?>
                    <option value="<?=$resdrv1['from_location']?>" <? if($resdrv1['from_location']==$fromplace) {?>selected<? }?>>
                    <?=$resdrv1['from_location']?>
                    </option>
                    <?php
                                }
                     ?>
                  </select>                </td>
              </tr>
			  <tr>
                <td><span class="trip-font-2">To</span></td>
				<td><select class="chzn-select restselect input3" name="tos" id="tos" onChange="getdriverbatta(this.value)">
                    <option value="">To</option>
                    <?php 
                            $sq_deliveryarea1="select * from cf_deliveryarea";
                            $arrdrv2=mysql_query($sq_deliveryarea1);
                            while($resdrv2=mysql_fetch_array($arrdrv2))
                            {
                        ?>
                    <option value="<?=$resdrv2['to_location']?>" <? if($resdrv2['to_location']==$toplace) {?>selected<? }?>>
                    <?=$resdrv2['to_location']?>
                    </option>
                    <?php
                                }
                     ?>
                  </select>                </td>
              </tr>
			   <tr>
			  	<td><span class="trip-font-2">Driver </span></td>              
                <td><select class="chzn-select restselect input3" name="driver_name" id="driver_name" >
                    <option value="">Driver Name</option>
                    <?php 
                            $sq_driver1="select * from cf_driver";
                            $arrdrver2=mysql_query($sq_driver1);
                            while($resdriver2=mysql_fetch_array($arrdrver2))
                            {
                        ?>
                    <option value="<?=$resdriver2['driver_id']?>" <? if($resdriver2['driver_id']==$drv_ids) {?>selected<? }?>>
                    <?=$resdriver2['drivername']?>
                    </option>
                    <?php
                                }
                     ?>
                  </select>  </td>
              </tr>

			  
			  <tr>
			  	<td><span class="trip-font-2">Advance Amount</span></td>              
                <td><input type="text" name="advance_amt" id="advance_amt" class="input1" value="<?=$advance_amt?>"  ></td>
              </tr>
			  
			  <tr>
			  	<td><span class="trip-font-2">Expense</span></td>              
                <td><input type="text" name="cash_expense" id="cash_expense" value="<?=$cashmemo?>" class="input1" readonly="readonly" ></td>
              </tr>
			  
			  <tr>
			  	<td><span class="trip-font-2">Batta</span></td>              
                <td><input type="text" name="driver_batta" id="driver_batta" value="<?=$drv_batta?>" class="input1" ></td>
              </tr>
			  
			  <tr>
                <td><span class="trip-font-2">Haulting Charge</span></td>
				<td><input type="text" name="haultchg" id="haultchg" class="input1" value="<?=$hault_chg_amt?>"  ></td>
              </tr>
              <?php 
                if(empty($_REQUEST['tripid']))
				{
                ?>
                <tr>         
               <td><!--<span class="trip-font-2">Sale/Purchase  </span> --></td>
                <td> <input type="radio" name="saletype" id="saletype" value="1" onClick="getSales();">  Sales&nbsp;&nbsp;||&nbsp;&nbsp;
				  <input type="radio" name="saletype" id="purchasetype" value="2" onClick="getPurchase();"> Purchase</td> 
             </tr><?php }?>
             
                
              <tr>
               <?php if(!empty($_REQUEST['tripid'])){?> 
               <td><span class="trip-font-2">Purchase Code </span></td><?php }else{?>
               <td></td><?php }?>
                <td><?php 
                if(empty($_REQUEST['tripid']))
				{
                ?>
                <div id="purchaseStdiv" style="display: none;">
           <select class="chzn-select restselect input3 purchase_id" name="purchase_id"  id="purchase_id" onChange="getvendordetails(this.value),showTripno(this.value)" style="width:160px;">
                      <option value="">Purchase Code</option>
                      <?php 
                        $sq_arr="select pur_id,'kg' as purchase_type from cf_oilpurchase LEFT JOIN cf_tripsheet on cf_oilpurchase.pur_id = cf_tripsheet.trip_purchase_id WHERE cf_tripsheet.trip_purchase_id IS NULL";
                        $array=mysql_query($sq_arr);
                        while($res=mysql_fetch_array($array))
                        {
                        ?>
                      <option value="<?=$res['pur_id']?>" data-id="<?=$res['pur_id']?>">PR-
                        <?=$res['pur_id']?>
                        (
                        <?=$res['purchase_type']?>
                        )</option>
                      <?php
                        }
                 		?>
                    </select>
                  </div> 
                    <?php }
				else
				{
					if($trip_purchase_id>0){
						echo 'PR-'.$trip_purchase_id;
					}			
				
				}?>                </td>
              </tr>
             
             
              <tr>
          <?php if(!empty($_REQUEST['tripid'])){?> 
               <td><span class="trip-font-2">Sales Code </span></td><?php }else{?>
               <td></td><?php }?>
                <td><?php 
                if(empty($_REQUEST['tripid']))
				{
                ?>
                 <div id="salesStdiv" style="display: none;">
                    <select class="chzn-select restselect input3 sale_order_no" name="sale_order_no"  id="sale_order_no" onChange="getclientdetails(this.value),showTripno(this.value)" style="width:160px;">
                      <option value="">Sales Code</option>
                      <?php 
                        $sq_arr="select sales_id,sales_type,sales_code from cf_sales LEFT JOIN cf_tripsheet on cf_sales.sales_id = cf_tripsheet.trip_salesid WHERE cf_tripsheet.trip_salesid IS NULL";
                        $array=mysql_query($sq_arr);
                        while($res=mysql_fetch_array($array))
                        {
                        ?>
                      <option value="<?=$res['sales_id']?>" data-id="<?=$res['sales_code']?>">SL-
                        <?=$res['sales_code']?>
                        (
                        <?=$res['sales_type']?>
                        )</option>
                      <?php
                        }
                 		?>
                    </select>
                   
                   </div>
                    <input type="hidden" class="sales_code_no" name="sales_code_no" value="">
                    <?php }
				else
				{
					if($tripsaleid>0){
						echo 'SL-'.$tripsalescodeno;
					}			
				
				}?>                </td>
              </tr>
             			 
              <tr>
              
                <td colspan="2" id="txtHintClient" class="trip-font-1">
				
				  <?php 
			  $grandtotal='';
			  if(!empty($_REQUEST['tripid']))
				{
					
				if($tripsaleid>0){
						//echo "select * from cf_sales join cf_client on cf_client.client_id = cf_sales.sales_clientid where cf_sales.sales_id = '$tripsaleid'";
					$resclient = mysql_query("select * from cf_sales join cf_client on cf_client.client_id = cf_sales.sales_clientid where cf_sales.sales_id = '$tripsaleid'");
					$resclient = mysql_fetch_array($resclient);
					$grandtotal = $resclient['sales_tot'];
					?>

					<?=$resclient['client_name']?>
					<br />
					<?=$resclient['client_address']?>
					<br />
					Code: <strong>
					<?=$resclient['client_code']?>
					</strong><br />
					Phone: <strong>
					<?=$resclient['client_phno']?>
					</strong> </td>
					<?php }elseif($trip_purchase_id>0){ 
						$resclient = mysql_query("select * from cf_oilpurchase join cf_reseller on cf_reseller.reseller_id = cf_oilpurchase.pur_vendor_id where cf_oilpurchase.pur_id = '$trip_purchase_id'");
					$resclient = mysql_fetch_array($resclient);
					$grandtotal = $resclient['pur_total'];
					?>

					<?=$resclient['res_name']?>
					<br />
					<?=$resclient['re_address']?>
					<br />
					Code: <strong>
					<?=$resclient['re_code']?>
					</strong><br />
					Phone: <strong>
					<?=$resclient['re_contactno']?>
					</strong> </td>
				 <?php 	}
			  		} ?>
              </tr>
              
              <tr>
                <?php
                if(!empty($_REQUEST['tripid']))
				{
				?>
                <td colspan="2" class="trip-font-1">Trip Finished &nbsp;&nbsp;&nbsp;
                    <input type="checkbox" name="tripstatus" id="tripstatus" value="1" <?php if($trip_status == 1){?>checked="checked" <?php  } ?> onClick="displayhaultingcharge(<?php echo $tripvechno; ?>);" /></td>
					<?php } ?>
              </tr>
			  
			 
			  
            </table></td>
            <td width="55%" colspan="3" align="right" valign="top" class="display-border-1"><table width="100%" border="0" cellspacing="2" cellpadding="2">
              <tr>
                <td align="right" class="trip-font-2">Trip Add Date</td>
				<?php 
				/*if($trip_date!=''){
					$trpdt = date(('d-m-Y'),strtotime($trip_date));
					}
					else
					{
						$trpdt='';
					}*/
				?>
                <td align="right" class="trip-font-2">
				<input type="text" placeholder="Date" class="input1" name="trip_start_date" id="trip_start_date" value="<?=$trip_startdate?>" /></td>
				<input type="hidden" placeholder="Date" class="input1" name="hiddentrip_start_date" id="hiddentrip_start_date" value="<?=$trip_startdate?>" />
              </tr>
			  
			  <tr>
                <td align="right" class="trip-font-2">Trip Finished Date</td>
				<?php 
				/*if($trip_date!=''){
					$trpdt = date(('d-m-Y'),strtotime($trip_date));
					}
					else
					{
						$trpdt='';
					}*/
				?>
				
				<input type="hidden" placeholder="Date" class="input1" name="hiddentrip_finish_date" id="hiddentrip_finish_date" value="<?=$trip_finishdate?>" />
                <td align="right" class="trip-font-2"><input type="text" placeholder="Date" class="input1" name="trip_finish_date" id="trip_finish_date" value="<?=$trip_finishdate?>" /></td>
              </tr>
              
              <tr>
                <td width="88%" align="right" class="trip-font-2">Current KM : </td>
                <td width="12%" align="right" class="trip-font-2"><input type="text" name="currentkm" id="currentkm" value="<?=$current_km?>" class="input1" ></td>
              </tr>
              <tr>
                <td align="right" class="trip-font-2">Return KM : </td> 
                <td align="right" class="trip-font-2"><input type="text" name="returnkm" id="returnkm" value="<?=$returnkm?>" readonly="readonly" class="input1" ></td>
              </tr>
              <tr>
                <td align="right" class="trip-font-2">KM : </td>
                <td align="right" class="trip-font-2"><input type="text" name="km_val" id="km_val" value="<?=$kms?>" class="input1" onKeyUp="kmval(this.value);"></td>
              </tr>
              <tr>
                <td align="right" class="trip-font-2">Diesel(Lt): </td>
                <td align="right" class="trip-font-2"><input type="text" name="diesel" id="diesel" value="<?=$diesel?>" class="input1" onKeyUp="getmilage(this.value);"></td>
              </tr>
			  <tr>
                <td align="right" class="trip-font-2">Milage : </td>
                <td align="right" class="trip-font-2"><input type="text" name="milage" id="milage" value="<?=$milage?>" class="input1"></td>
              </tr>
			  <tr>
                <td align="right" class="trip-font-2">Wg in Tons : </td>
                <td align="right" class="trip-font-2"><input type="text" id="wg_in_tons" name="wg_in_tons" value="<?=$wgintons?>" class="input1" onChange="getBatta(this.value,'wg');"></td>
              </tr>
              <tr>
                <td align="right" class="trip-font-2">Wg in Tons(Client) : </td>
                <td align="right" class="trip-font-2"><input type="text" name="wg_in_tons_client" value="<?=$wgintonsclient?>" class="input1"></td>
              </tr>
              
            </table></td>
          </tr>
          
        </table></td>
      </tr>
      <tr>
        <td colspan="19" align="left" valign="top" class="display-border-1">&nbsp;</td>
      </tr>
      
      <?php 
		if(!empty($_REQUEST['tripid']))
		{ 
		
		?>
		 
      <tr>
        <td colspan="19" align="left" valign="top" class="display-border-1">
        
        <table width="100%" border="0" cellspacing="2" cellpadding="0">
    <tr>
    	 <td align="left" valign="top" class="display-border-1"><strong>Serial Number </strong></td>
         
          <?php  
          if($tripsaleid>0){	 
          
           	if($tripsaletype == 'box')
			{		 
		  ?>            
            <td align="left" valign="top" class="display-border-1"><strong>Brand</strong></td>
            <td align="left" valign="top" class="display-border-1"><strong>Liter</strong></td>
            <td align="left" valign="top" class="display-border-1"><strong>Kg (Litre) </strong></td>
            <td align="left" valign="top" class="display-border-1"><strong>Box Qty </strong></td>
            <td align="left" valign="top" class="display-border-1"><strong>Rates</strong></td>
            <td align="left" valign="top" class="display-border-1"><strong>Damage Return</strong></td>
            <td align="left" valign="top" class="display-border-1"><strong>Date</strong></td>
            <td align="left" valign="top" class="display-border-1"><strong>Total</strong></td>
            <?php }
			if($tripsaletype == 'tin')
			{		
			?>            
            <td align="left" valign="top" class="display-border-1"><strong>No Of Tins</strong></td>
            <td align="left" valign="top" class="display-border-1"><strong>Rate</strong></td>
            <td align="left" valign="top" class="display-border-1"><strong>Damage Return</strong></td>
            <td align="left" valign="top" class="display-border-1"><strong>Date</strong></td>
            <?php } 
            if($tripsaletype == 'kg')
			{		
			?>            
            <td align="left" valign="top" class="display-border-1"><strong>Qty</strong></td>
            <td align="left" valign="top" class="display-border-1"><strong>Kg Rate</strong></td>
            <td align="left" valign="top" class="display-border-1"><strong>Total</strong></td>
            <td align="left" valign="top" class="display-border-1"><strong>Date</strong></td>
            <?php }  } else{?>            
            <td width="6%" align="left" valign="top" class="display-border-1"><strong>Qty</strong></td>
            <td width="6%" align="left" valign="top" class="display-border-1"><strong>Rate</strong></td>
            <td width="6%" align="left" valign="top" class="display-border-1"><strong>Total</strong></td>
            <td width="6%" align="left" valign="top" class="display-border-1"><strong>Date</strong></td>
            
       <?php }?>
            </tr>
            
    	<?php  if($tripsaleid>0){
			  if($tripsaletype== 'box')
		  {
		 	
			$resulbox= mysql_query("select *,(select kgqty from cf_liter_qty where cf_liter_qty.literids = `cf_sales_sub`.`liter_id` and cf_liter_qty.brandid =  `cf_sales_sub`.`branch_id`) as kgqty ,(select liter_qty from cf_liter where cf_liter.liter_id = `cf_sales_sub`.`liter_id`) as litreqty from 	cf_sales_sub join cf_brand on cf_sales_sub.branch_id = cf_brand.brand_id  where cf_sales_sub.sale_id = '$tripsaleid'");
		  $i=1;
		  while($res_box = mysql_fetch_array($resulbox))
		  {
		  ?>		  
		  <tr>
            <td align="left" valign="top" class="display-border-1"><?=$i?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['brand_name'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['litreqty'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['kgqty'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['sale_box'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['sale_rate'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['sale_damage_qty'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo date(('d-m-Y'),strtotime($res_box['sale_date']));?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['sale_line_tot'];?></td>
          </tr>
          <?php $i++;} }
		  if($tripsaletype== 'tin')
			{
				$resultin = mysql_query("select * from 	cf_sales_sub  where cf_sales_sub.sale_id = '$tripsaleid' ");
				 $i=1;
				 while($res_tin = mysql_fetch_array($resultin))
				 {			
		   ?>
           <tr>
         	<td align="left" valign="top" class="display-border-1"><?=$i?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_tin['sale_no_tin_kg'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_tin['sale_rate'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_tin['sale_damage_qty'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo date(('d-m-Y'),strtotime($res_tin['sale_date']));?></td>          
          <tr>
          <?php $i++;} }
          if($tripsaletype== 'kg')
			{
				$resultkg = mysql_query("select * from 	cf_sales_sub  where cf_sales_sub.sale_id = '$tripsaleid' ");
				 $i=1;
				 while($res_kg = mysql_fetch_array($resultkg))
				 {			
		   ?>
           <tr>
         	<td align="left" valign="top" class="display-border-1"><?=$i?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_kg['sale_no_tin_kg'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_kg['sale_rate'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_kg['sale_line_tot'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo date(('d-m-Y'),strtotime($res_kg['sale_date']));?></td>          
          <tr>
          <?php $i++;} }  
				
		}else { 
		$sq_arr=mysql_query("select * from 	cf_oilpurchase  where pur_id = '$trip_purchase_id' ");
		
		 $i=1;
		  while($rw = mysql_fetch_array($sq_arr))
		  {
		  ?>		  
		  <tr>
            <td  width="20%" align="left" valign="top" class="display-border-1"><?=$i?></td>
            <td  width="20%" align="left" valign="top" class="display-border-1"><?php echo $rw['pur_com_kg'];?></td>
            <td  width="20%" align="left" valign="top" class="display-border-1"><?php echo $rw['pur_tin_rate'];?></td>
            <td  width="20%" align="left" valign="top" class="display-border-1"><?php echo $rw['pur_total'];?></td>
            <td  width="20%" align="left" valign="top" class="display-border-1"><?php echo date(('d-m-Y'),strtotime($rw['pur_addate']));?></td>
          </tr><tr>
          <?php $i++;} 	}?>
          
          
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
          </tr>
          <tr>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
          </tr>
        </table>
        

        
        </td>
      </tr>
      
     
      

      
      
      
 <!--   </table></td>
  </tr>-->
    <?php } ?>
  <tr>
        <td colspan="19" align="left" valign="top" id="txtHintSales"></td>
      </tr>
      <?php 
		if(!empty($_REQUEST['tripid']))
		{ ?>
      <tr>
        <td colspan="19" align="right" valign="top" class="trip-font-3">
        <input type="hidden" name="grd_tot" value="<?=$grandtotal?>" class="input1">
        Grand Total : <strong><?=$grandtotal?></strong> </td>
        </tr>
      <?php } ?>
  <tr><td height="70">
  
  
  <?php 
   if(empty($_REQUEST['tripid']))
	{?>
    <input type="submit" name="btnsubmit" class="input1" value="Submit" onClick="return validation();"/>
	
  <?php }else{   
  ?>
   <input type="hidden" name="trip_id" value="<?=$_REQUEST['tripid']?>"  >
   <input type="submit" name="uptsubmit" class="input1" value="Update" onClick="return validation();"/>
   <?php if($trip_status == 1){?>
   <input type="submit" name="printpage" value="Print" class="submit-btn" style="margin-left: 10px;">
   <?php } ?>
  <?php } ?></td>
  </tr>
  </table>
  </tr>
  </tr>
  </table>


   <div id="printableArea" >
   <div class="div01" id="div01" style="display: none;">
  <div class="ptForm" style="padding-top:10px;">

    <table width="100%" border="0" cellspacing="5" cellpadding="2"   padding:4px; font-size:14px;>
   
    	<!-- <tr>
        <td  colspan="5" class="ptText01" style="text-align:center;">G M  TRANSPORTS</td>
      </tr>-->
      
          <tr>
        <td  colspan="5" class="ptText02" style="text-align:center;"><h2 align="center">TRIP SHEET</h2></td>
      </tr>
      
          <tr>
        <td  colspan="5" class="ptText03" style="text-align:center;"></td>
      </tr>
      
       <!------------------------------------------------------------------------------------>
      
      <tr>
        <td  colspan="4" class="ptText02" >
     <div style="float:left;width:160px ; font-size:12px; padding-right:15px;font-weight: bold; ">Trip No : &nbsp;</div>
     <div id="txtHintClient" style="float:left;font-size:12px;">
       	<?php 
			echo $tripsrno;
		?>
        </div>
       
        </td>
        <td class="ptText02"  style="text-align:left;width: 600px;"><div style="float:left; font-size:12px; font-weight: bold;width:160px ;">Trip Add Date :</div>  
      <!-- <div style="float:left;font-size:12px; "><?php echo date(('d-m-Y'),strtotime($trip_startdate));?></div> -->
       <div style="float:left;font-size:12px; "><?php echo $trip_startdate; ?></div> 
           </td>
        </tr>
        <tr>
         <td  colspan="4" class="ptText02"  style="width:;">
     <div style="float:left;width:160px ; font-size:12px; padding-right:15px;font-weight: bold; ">Vehicle No : &nbsp;</div>
     <div id="txtHintClient" style="float:left;font-size:12px;">
       	<?php 
       $sq_vechicle=mysql_query("select * from cf_vehicle where id='.$tripvechno.'");
	$row = mysql_fetch_array($sq_vechicle);
	$vehiclenum = $row['vehiclenum'];
			echo $vehiclenum;
		?>
        </div>       
        </td>
        <td class="ptText02"  style="text-align:left;width: 600px;"><div style="float:left;width:160px; font-size:12px; font-weight: bold;">Finished Date :</div>   
          <div style="float:left;font-size:12px; font-size:12px;">
          <?php $trip_year=date('Y',strtotime($trip_finishdate));
          if($trip_year=="1970")$trip_finishdate="";
           echo $trip_finishdate;?>
          <!--<?php echo date(('d-m-Y'),strtotime($trip_finishdate));?>--></div>           
           </td>
             </tr><tr>
              <td  colspan="4" class="ptText02"  style="width:;">
     <div style="float:left;width:160px ; font-size:12px; padding-right:15px;font-weight: bold; ">From : &nbsp;</div>
     <div id="txtHintClient" style="float:left;font-size:12px;">
       	<?php 
			echo $fromplace;
		?>
        </div>       
        </td>
        <td class="ptText02"  style="text-align:left;width: 600px;"><div style="float:left;font-size:12px; font-weight: bold;width:160px ;">Current KM :</div>   
          <div style="float:left;font-size:12px; font-size:12px;"><?=$current_km?></div>           
           </td>
           </tr><tr>
            <td  colspan="4" class="ptText02"  style="width:;">
     <div style="float:left;width:160px ; font-size:12px; padding-right:15px;font-weight: bold; ">To : &nbsp;</div>
     <div id="txtHintClient" style="float:left;font-size:12px;">
       	<?php 
			echo $toplace;
		?>
        </div>       
        </td>
        <td class="ptText02"  style="text-align:left;width: 600px;"><div style="float:left;font-size:12px; font-weight: bold;width:160px ;">Return KM :</div>   
          <div style="float:left;font-size:12px; font-size:12px;"><?=$returnkm?></div>           
           </td>
           </tr>
           
           <tr>
        <!--    <?php  echo "1111111111111"; die;?> -->
               <td  colspan="4" class="ptText02"  style="width:;">
     <div style="float:left;width:160px ; font-size:12px; padding-right:15px;font-weight: bold; ">Driver : &nbsp;</div>
     <div id="txtHintClient" style="float:left;font-size:12px;">
       	<?php 
       	 $sq_driver1=mysql_query("select * from cf_driver where driver_id=$drv_ids");
       	
	$row = mysql_fetch_array($sq_driver1);
	$drivername = $row['drivername'];
			echo $drivername;
		?>
        </div>       
        </td>
        <td class="ptText02"  style="text-align:left;width: 600px;"><div style="float:left; font-size:12px;font-weight: bold;width:160px ;">KM :</div>   
          <div style="float:left;font-size:12px; font-size:12px;"><?=$kms?></div>           
           </td>
          </tr>
          <tr>
               <td  colspan="4" class="ptText02"  style="width:;">
     <div style="float:left;width:160px ; font-size:12px; padding-right:15px;font-weight: bold; ">Advance Amount 	: &nbsp;</div>
     <div id="txtHintClient" style="float:left;font-size:12px;">
       	<?php 
			echo $advance_amt;
		?>
        </div>       
        </td>
        <td class="ptText02"  style="text-align:left;width: 600px;"><div style="float:left; font-size:12px; font-weight: bold;width:160px ;">Diesel(Lt):</div>   
          <div style="float:left;font-size:12px; font-size:12px;"><?=$diesel?></div>           
           </td>
          </tr>
          
		<tr>
		<td  colspan="4" class="ptText02"  style="width:;">
		<div style="float:left;width:160px ; font-size:12px; padding-right:15px;font-weight: bold; ">Expense: &nbsp;</div>
		<div id="txtHintClient" style="float:left;font-size:12px;">
		<?php 
		echo $cashmemo;
		?>
		</div>       
		</td>
		<td class="ptText02"  style="text-align:left;width: 600px;"><div style="float:left; font-size:12px; font-weight: bold;width:160px ;">Milage :</div>   
		<div style="float:left;font-size:12px; font-size:12px;"><?=$milage?></div>           
		</td>
		</tr>
		
		<tr>
		<td  colspan="4" class="ptText02"  style="width:;">
		<div style="float:left;width:160px ; font-size:12px; padding-right:15px;font-weight: bold; ">Batta: &nbsp;</div>
		<div id="txtHintClient" style="float:left;font-size:12px;">
		<?php 
		echo $drv_batta;
		?>
		</div>       
		</td>
		<td class="ptText02"  style="text-align:left;width: 600px;">
		
		<div style="float:left;font-size:12px; font-weight: bold;width:160px ;">Wg in Tons :</div>   
		<div style="float:left;font-size:12px; font-size:12px;"><?=$wgintons?></div>           
		</td>
		</tr>
		
		<tr>
		<td  colspan="4" class="ptText02"  style="width:;">
		<div style="float:left;width:160px ; font-size:12px; padding-right:15px; font-weight: bold;">Haulting Charge: &nbsp;</div>
		<div id="txtHintClient" style="float:left;font-size:12px;">
		<?php 
		echo $hault_chg_amt;
		?>
		</div>       
		</td>
		<td class="ptText02"  style="text-align:left;width: 600px;">
		
		<div style="float:left; font-size:12px; font-weight: bold;width:160px ;">Wg in Tons(Client) :</div>
		<div style="float:left;font-size:12px; font-size:12px;"><?=$wgintonsclient?>  </div>     
		</td>
		</tr>
		
		<tr>
		<td  colspan="4" class="ptText02"  style="width:;">
		<div style="float:left;width:160px ; font-size:12px; padding-right:15px; font-weight: bold;">Sales Code : &nbsp;</div>
		<div id="txtHintClient" style="float:left;font-size:12px;">
		<?php 
		if($trip_purchase_id>0){
						echo 'PR-'.$trip_purchase_id;
					}else{
						echo 'SL-'.$tripsalescodeno;
					}	
		?>
		</div>       
		</td>		
		</tr>
		
		<?php
		
		if($tripsaleid>0){  $resclient = mysql_query("select * from cf_sales join cf_client on cf_client.client_id = cf_sales.sales_clientid where cf_sales.sales_id = '$tripsaleid'");
			  $resclient = mysql_fetch_array($resclient); ?>
		<tr>
		<td  colspan="4" class="ptText02"  style="width:;">		
		<div style="float:left;width:160px ; font-size:12px; padding-right:15px;font-weight: bold; ">Client Name : &nbsp;</div>	<?=$resclient['client_name']?>	     
		</td>		
		</tr>
		<tr>
		<td  colspan="4" class="ptText02"  style="width:;">		
		<div style="float:left;width:160px ; font-size:12px; padding-right:15px; font-weight: bold;">Address : &nbsp;</div><?=$resclient['client_address']?>		     
		</td>		
		</tr>
		<tr>
		<td  colspan="4" class="ptText02"  style="width:;">		
		<div style="float:left;width:160px ; font-size:12px; padding-right:15px; font-weight: bold;">Code : &nbsp;</div><?=$resclient['client_code']?>		     
		</td>		
		</tr>
		<tr>
		<td  colspan="4" class="ptText02"  style="width:;">		
		<div style="float:left;width:160px ; font-size:12px; padding-right:15px; font-weight: bold;">Phone : &nbsp;</div><?=$resclient['client_phno']?>	     
		</td>		
		</tr>
     <?php }elseif($trip_purchase_id>0){ 
						$resclient = mysql_query("select * from cf_oilpurchase join cf_reseller on cf_reseller.reseller_id = cf_oilpurchase.pur_vendor_id where cf_oilpurchase.pur_id = '$trip_purchase_id'");
					$resclient = mysql_fetch_array($resclient); ?>
					<tr>
		<td  colspan="4" class="ptText02"  style="width:;">		
		<div style="float:left;width:160px ; font-size:12px; padding-right:15px;font-weight: bold; ">Client Name : &nbsp;</div>	<?=$resclient['res_name']?>	     
		</td>		
		</tr>
		<tr>
		<td  colspan="4" class="ptText02"  style="width:;">		
		<div style="float:left;width:160px ; font-size:12px; padding-right:15px; font-weight: bold;">Address : &nbsp;</div><?=$resclient['re_address']?>		     
		</td>		
		</tr>
		<tr>
		<td  colspan="4" class="ptText02"  style="width:;">		
		<div style="float:left;width:160px ; font-size:12px; padding-right:15px; font-weight: bold;">Code : &nbsp;</div><?=$resclient['re_code']?>		     
		</td>		
		</tr>
		<tr>
		<td  colspan="4" class="ptText02"  style="width:;">		
		<div style="float:left;width:160px ; font-size:12px; padding-right:15px; font-weight: bold;">Phone : &nbsp;</div><?=$resclient['re_contactno']?>	     
		</td>		
		</tr>
		
				 <?php 	}?>
        <td  colspan="5"  class="ptText02" style="width:70%;">
        <div id="list">
        <table width="100%"  cellspacing="0" cellpadding="0"   class="List" align="center" style="border-top:solid 1px #000000; border-bottom:none; border-left:solid 1px #000000; border-right:solid 1px #000000;" >
         <tr>
              <td class="leftTd" style="width:1%; font-weight:bold;">Sl.No.</td>
        <?php  
        if($tripsaleid>0){
           	if($tripsaletype == 'box')
			{		 
		  ?> 
           
              <td class="tdItem" style="width:10%; font-weight:bold;">Brand</td>
              <td class="tdItem" style="width:10%; font-weight:bold;">Liter</td>
              <td class="tdItem" style="width:10%; font-weight:bold;">Kg (Litre)</td>
              <td class="tdItem" style="width:10%; font-weight:bold;">Box Qty</td>
              <td class="tdItem" style="width:3%; font-weight:bold;">Rates</td>
              <td class="tdItem" style="width:3%; font-weight:bold;">Damage Return</td>
              <td class="tdItem" style="width:3%; font-weight:bold;">Date</td>
              <td class="tdItem" style="width:3%; font-weight:bold;">Total</td>
          
             <?php }
			if($tripsaletype == 'tin')
			{		
			?>            
             <td class="tdItem" style="width:10%; font-weight:bold;"><strong>No Of Tins</strong></td>
              <td class="tdItem" style="width:10%; font-weight:bold;"><strong>Rate</strong></td>
             <td class="tdItem" style="width:10%; font-weight:bold;"><strong>Damage Return</strong></td>
             <td class="tdItem" style="width:10%; font-weight:bold;"><strong>Date</strong></td>
            <?php } 
            if($tripsaletype == 'kg')
			{		
			?>            
              <td class="tdItem" style="width:10%; font-weight:bold;"><strong>Qty</strong></td>
              <td class="tdItem" style="width:10%; font-weight:bold;"><strong>Kg Rate</strong></td>
              <td class="tdItem" style="width:10%; font-weight:bold;"><strong>Total</strong></td>
             <td class="tdItem" style="width:10%; font-weight:bold;"><strong>Date</strong></td>
            <?php } ?>
            
              </tr>
         	<?php  
		  if($tripsaletype== 'box')
		  {
		 	
			$resulbox= mysql_query("select *,(select kgqty from cf_liter_qty where cf_liter_qty.literids = `cf_sales_sub`.`liter_id` and cf_liter_qty.brandid =  `cf_sales_sub`.`branch_id`) as kgqty ,(select liter_qty from cf_liter where cf_liter.liter_id = `cf_sales_sub`.`liter_id`) as litreqty from 	cf_sales_sub join cf_brand on cf_sales_sub.branch_id = cf_brand.brand_id  where cf_sales_sub.sale_id = '$tripsaleid'");
		  $i=1;
		  while($res_box = mysql_fetch_array($resulbox))
		  {
		  ?>		  
		  <tr>
            <td class="leftTd" style="width:7%;"><?=$i?></td>
             <td class="tdItem" style="width:12%"><?php echo $res_box['brand_name'];?></td>
             <td class="tdItem" style="width:12%"><?php echo $res_box['litreqty'];?></td>
             <td class="tdItem" style="width:12%"><?php echo $res_box['kgqty'];?></td>
             <td class="tdItem" style="width:12%"><?php echo $res_box['sale_box'];?></td>
             <td class="tdItem" style="width:12%"><?php echo $res_box['sale_rate'];?></td>
             <td class="tdItem" style="width:12%"><?php echo $res_box['sale_damage_qty'];?></td>
             <td class="tdItem" style="width:12%"><?php echo date(('d-m-Y'),strtotime($res_box['sale_date']));?></td>
             <td class="tdItem" style="width:12%"><?php echo $res_box['sale_line_tot'];?>></td>          
           
          </tr>
          <?php $i++;} }
		  if($tripsaletype== 'tin')
			{
				$resultin = mysql_query("select * from 	cf_sales_sub  where cf_sales_sub.sale_id = '$tripsaleid' ");
				 $i=1;
				 while($res_tin = mysql_fetch_array($resultin))
				 {			
		   ?>
           <tr>
         	<td class="leftTd" style="width:7%;"><?=$i?></td>
         	    <td class="tdItem" style="width:12%"><?php echo $res_tin['sale_no_tin_kg'];?><!--<input type="text" class="input9" style="font-size:12px;" value="<?php echo $res_tin['sale_no_tin_kg'];?>" size="15" >--></td>
         	    
            <!--<td align="left" valign="top" class="display-border-1"><?php echo $res_tin['sale_no_tin_kg'];?></td>-->
           
         	    <td class="tdItem" style="width:12%"><?php echo $res_tin['sale_rate'];?><!--<input  type="text" class="input9"  style="font-size:12px;" value="<?php echo $res_tin['sale_rate'];?>" size="15" >--></td>
         	      <td class="tdItem" style="width:12%"><?php echo $res_tin['sale_damage_qty'];?><!--<input  type="text" class="input9"   style="font-size:12px;" value="<?php echo $res_tin['sale_damage_qty'];?>" size="15" >--></td>
         	        <td class="tdItem" style="width:12%"><?php echo date(('d-m-Y'),strtotime($res_tin['sale_date']));?><!--<input type="text" class="input9"  style="font-size:12px;" value="<?php echo date(('d-m-Y'),strtotime($res_tin['sale_date']));?>" size="15" >--></td>
            <!--<td align="left" valign="top" class="display-border-1"><?php echo $res_tin['sale_rate'];?></td>-->
                
          </tr>
          <?php $i++;} }
          if($tripsaletype== 'kg')
			{
				$resultkg = mysql_query("select * from 	cf_sales_sub  where cf_sales_sub.sale_id = '$tripsaleid' ");
				 $i=1;
				 while($res_kg = mysql_fetch_array($resultkg))
				 {			
		   ?>
           <tr>
         	<td class="leftTd" style="width:7%;"><?=$i?></td>
         	 <td class="tdItem" style="width:12%"><?php echo $res_kg['sale_no_tin_kg'];?></td>
         	 <td class="tdItem" style="width:12%"><?php echo $res_kg['sale_rate'];?></td>
         	 <td class="tdItem" style="width:12%"><?php echo $res_kg['sale_line_tot'];?></td>
         	 <td class="tdItem" style="width:12%"><?php echo date(('d-m-Y'),strtotime($res_kg['sale_date']));?></td>         	 
                 
          </tr>
          <?php $i++;} }  	} 
else{?>   

			<td class="tdItem" style="width:10%; font-weight:bold;"><strong>Qty</strong></td>
              <td class="tdItem" style="width:10%; font-weight:bold;"><strong>Kg Rate</strong></td>
              <td class="tdItem" style="width:10%; font-weight:bold;"><strong>Total</strong></td>
             <td class="tdItem" style="width:10%; font-weight:bold;"><strong>Date</strong></td>
             
            <?php
            $sq_arr=mysql_query("select * from 	cf_oilpurchase  where pur_id = '$trip_purchase_id' ");	
		 $i=1;
		  while($rw = mysql_fetch_array($sq_arr))
		  {
		  ?>		  
		  <tr>
		  <td class="leftTd" style="width:7%;"><?=$i?></td>
         	 <td class="tdItem" style="width:12%"><?php echo $rw['pur_com_kg'];?></td>
         	 <td class="tdItem" style="width:12%"><?php echo $rw['pur_tin_rate'];?></td>
         	 <td class="tdItem" style="width:12%"><?php echo $rw['pur_total'];?></td>
         	 <td class="tdItem" style="width:12%"><?php echo date(('d-m-Y'),strtotime($rw['pur_addate']));?></td>         	 
         	 
          </tr>
          <?php $i++;}
		}?>  
        
          </table> 
          </div>
        
        <?php /*?><div id="div<?=$div+1?>"></div><?php */?>
         </td>
      
        <tr>
           
              <td class="tdItemBtm" colspan="9" style="font-size:14px; font-weight:bold; text-align:right; padding-right:80px;">Grand Total : <?=$grandtotal?><!--<input type="text" name="gt" id="gt"  class="input5"  value="<?=$grandtotal?>"  >--></td>
            
            </tr>
            
               <tr>
            	<td width="825">
               
                      
                </td>
            </tr>    
       
    </table>
    
   <table width="100%" border="0" cellspacing="0" cellpadding="5">
  
      
    </table>
  </div>
  <div style="text-align:center;">
    
  </div>
</div>
</div>



</form>

 </div>


</div><!-- /display-cell-1 -->

</div>
</div>
   
  </div>
 </div>
 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 
</div>
<div class="quicLInksCover">
 <?php 
	include("leftlink.php");
?>

</div>
</body>
<script src="js/chosen.jquery.min.js" type="text/javascript">
		</script>
			<script type="text/javascript"> 
			
			$(".chzn-select").chosen({search_contains: true}); 
			$(function(){
				$('.sale_order_no').live('change',function(){
					var sales_code = $('.sale_order_no option:selected').attr('data-id');
					$('.sales_code_no').val(sales_code);
				});
				
				$('.purchase_order_no').live('change',function(){
					var sales_code = $('.purchase_order_no option:selected').attr('data-id');
					$('.purchase_order_no').val(sales_code);
				});
			})
			
		</script>
</html>
