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


$veh_num='';
$sdate_12 ='';
$page='1';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
$msg = '';

if(isset($_REQUEST['del']) && $_REQUEST['del']=='delete')
{
	$id = $_REQUEST['id'];
	$sql=mysql_query("delete from cf_tripsheet where trip_id='$id'");
	header("location:tripsheet-list.php?msg=You Have Successfully Deleted");
}

?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Supply Chain Management</title>
<link href="css/styles.css" rel="stylesheet"  />
<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/trippopup.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>

<script>
$(document).ready(function(){
$('#tripdate').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

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

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

/*function drivername()
{
	alert(document.frmname.clientid.value);
}*/



</script>

<script language="javascript">
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(val)
{ 
 	 var page=val;	
	 var vechicle_no='';
	 var clientcode='';
	 //var con_person='';
	 	
	 if(document.trip_frm.vechicle_no){
	 vechicle_no= document.trip_frm.vechicle_no.value;
	 }
	 
	 if(document.trip_frm.client_code){
	 clientcode= document.trip_frm.client_code.value;
	 } 
	 
	 if(document.trip_frm.tripdate){
	 tripdate= document.trip_frm.tripdate.value;
	 }
	 
	 if(document.trip_frm.fromdate){
	 fromdate= document.trip_frm.fromdate.value;
	 }
	 
	 if(document.trip_frm.todate){
	 todate= document.trip_frm.todate.value;
	 }
	 
	 var strURL="ajax/vechicletrip_data.php?&page="+page;
		if(vechicle_no!=''){
		strURL+="&vechicle_no="+vechicle_no;
		}
		
		if(clientcode!=''){
		strURL+="&clientcode="+clientcode;
		}
	
		if(tripdate!=''){
		strURL+="&tripdate="+tripdate;
		}
		
		if(fromdate!=''){
		strURL+="&fromdate="+fromdate;
		}
		
		if(todate!=''){
		strURL+="&todate="+todate;
		}
	
	//alert(strURL);
	
	
	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);
   }
 
   
}
</script>

</head>

<body>
<!------------------popup area (view, edit)--------------->
<div class="viewEmployeePopup login-popup"  id="login-box">
<a href="#" class="close"><img src="images/close.png" class="btn_close" title="Close Window" alt="Close" /></a>
   <div id="popupid"></div>
   
     
    </div>


<!---------------popup area ends------------------>
<div class="wrapper">
   <div>
<?php 
	include("header.php");
?>
 
</div>
 
 <div class="tabbedArea">
   
  <div class="tabBody">
   <h1>Vehicle Wise Tripsheet List Report</h1>
   <form name="trip_frm" id="trip_frm" method="post"  >
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px; ">
   <div style="padding:20px;">
    <div class="searchField">
     <p class="input1">Vehicle No</p>
       
   <select class="chzn-select restselect input3" name="vechicle_no">
     <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['vehiclenum']?>" ><?=$resvechicle['vehiclenum']?></option>
        <?php
				}
	 ?>
     </select>
     <!--<input type="text" name="client_name" id="client_name" class="input1" />-->
    </div>
    <?php 
    if(($_SESSION['typename'] == 'SuperAdmin')) {
	?>
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">Client Code</p>
     <select class="input1 input3" name="client_code">
     <option value="">Client Code</option>
     	 <?php 
        	$sq_clientcd="select * from cf_client";
			$arr2=mysql_query($sq_clientcd);
			while($resclient=mysql_fetch_array($arr2))
			{
		?>
			<option value="<?=$resclient['client_sub_id']?>" ><?=$resclient['client_newcode']?></option>
        <?php
				}
	 ?>
     </select>
    </div>
    <?php } ?>
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">Trip Date</p>
     <input type="text" name="tripsdate" id="tripdate" size="20" maxlength="100" class="input1" />
    </div>
    
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">From Date</p>
     <input type="text" name="fromdate" id="fromdate" size="20" maxlength="100" class="input1" />
    </div>
    
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">To Date</p>
     <input type="text" name="todate" id="todate" size="20" maxlength="100" class="input1" />
    </div>
       
    <div class="searchField">
     <input name="button" type="button" class="input1" onClick="Searchdate(1);" value="search" />
    </div>
  
   </div>
   </div>
   </form>
   <div id="list">
   <table  border="0" cellspacing="0" cellpadding="0" class="tableList">
  <tr class="heading">
    <td>No</td>    
    <td width="90">Tripsheet No</td>
    <td width="90">Vehicle No</td>
    <td width="70">Trip Date</td>
    <td>Destination</td> 
    <td width="90">Route No</td> 
    <td>Route Km</td> 
    <td>Km</td> 
    <td>Gross Weight</td> 
    <td>Frieght Paid</td>
  </tr>
  
  <?php


/*
if(isset($_REQUEST['typename'])){
$typenames=$_REQUEST['typename'];
}*/

$i=1;
$clientcode='';
if(($_SESSION['typename'] == 'SuperAdmin')) {
$sq_arr="select * from cf_tripsheet where delete_status = 0 ";

}


if(($_SESSION['typename'] == 'SubAdmin')) {
	$userids = $_SESSION['admin_id'];
	
	$sq_clientid=mysql_query("select * from cf_user_clientid where user_id = $userids ");	
	while($rw = mysql_fetch_array($sq_clientid))
	{
		$clientcode.= "'".$rw['client_code']."',";
	}
	
	$clientnames = substr($clientcode, 0, -1);	
	
	$sq_arr="select * from cf_tripsheet where delete_status = 0 and clientids IN ($clientnames) "; 	
}


$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 $res['trip_vechno'];?></td>
    <td><?php echo date('d-m-Y', strtotime($res['trip_date']));?></td>
    <?php
     	$distictname = '';
		$tripid = $res['trip_id'];
       	$sq_drv=mysql_query("SELECT * FROM `cf_tripsheetsub`  where trip_id = '$tripid'  ");
			while($row2 = mysql_fetch_array($sq_drv))
			{
				$districtnam= $row2['trip_location'];	
				$distictname.=  $districtnam.' ,';	
				$distictnames = substr($distictname, 0, -1);				
			}
    ?>
    <td><?php if($distictnames!='')echo $distictnames;else echo '--'; ?></td>
    <?php 
		$triprouteid = $res['trip_route_id'];
		$sq_drvs=mysql_query("SELECT * FROM `cf_route` where route_id = '$triprouteid'  ");
		$row4 = mysql_fetch_array($sq_drvs);
	?>
     <td><?php echo $row4['route_name'];?></td>
     <td><?php echo $row4['routedistance'];;?></td>
    <td><?php if($res['kms']!='')echo $res['kms'];else echo '--'; ?></td>
  	<td><?php if($res['gross_weight']!='')echo $res['gross_weight'];else echo '--'; ?></td>
    <td><?php if($res['bal_amt']!='')echo $res['bal_amt'];else echo '--'; ?></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> 
  </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">
 <div class="quickLink">
  <img src="images/quickLinks.gif" border="0" usemap="#Map">
<map name="Map"><area shape="rect" coords="5,6,39,50" href="#"><area shape="rect" coords="7,62,41,111" href="#"><area shape="rect" coords="3,122,43,172" href="#"><area shape="rect" coords="4,186,42,237" href="javascript:parent.history.back();"><area shape="rect" coords="3,247,43,300" href="javascript:parent.history.forward();"></map>
 </div>

</div>-->

<div class="quicLInksCover">
 <?php 
	include("leftlink.php");
?>

</div>
</body>
</html>
<!----------------------- script for autocomplete------------------------------>
		<script src="js/chosen.jquery.min.js" type="text/javascript">
		</script>
		<script type="text/javascript"> 
			$(".chzn-select").chosen({search_contains: true}); 
		</script>

<!----------------end of script -------------------------------->
