<?
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_client where client_sub_id='$id'");
	header("location:client-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 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 language="javascript">

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

$(document).ready(function(){
$('#todate').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd'
});
});
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 client_name='';
	 var con_person='';
	 var client_code='';
	 var fromdate='';
	 var todate='';
	 
	 if(document.client_frm.dealername){
	 dealername= document.client_frm.dealername.value;
	 }
	 
	 if(document.client_frm.clientcode){
	 clientcode= document.client_frm.clientcode.value;
	 }	 
	 		 
	 if(document.client_frm.fromdate){
	 fromdate= document.client_frm.fromdate.value;
	 }
	 
	 if(document.client_frm.todate){
	 todate= document.client_frm.todate.value;
	 }
	
	var strURL="ajax/clientinvoice_data.php?&page="+page;
	if(dealername!=''){
	strURL+="&dealername="+dealername;
	}
	
	if(clientcode!=''){
	strURL+="&clientcode="+clientcode;
	}		
	
	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>

<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">



function nwtest()
{
	
   $('#dealername').autocomplete("autodealer.php", {
		width: 260,
		matchContains: true,
		//mustMatch: true,
		//minChars: 0,
		//multiple: true,
		//highlight: false,
		//multipleSeparator: ",",
		selectFirst: false
	});
	
	
}

</script>
</head>

<body>
<!------------------popup area (view, edit)--------------->



<!---------------popup area ends------------------>
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 <div class="tabbedArea">
   
  <div class="tabBody">
   <h1>Client Invoice List</h1>
   <form name="client_frm" id="client_frm" method="post"  >
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px; ">
   <div style="padding:20px;">
        
    <div class="searchField">
     <p class="input1">Dealer</p>
     <input type="text" name="dealername" id="dealername" class="input1" value="" onClick="nwtest();" />          
    </div>
    
    <div class="searchField">
     <p class="input1">Client Code</p>
     <input type="text" name="clientcode" id="clientcode" class="input1" value="" />          
    </div>
        
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">From Date</p>
     <input type="text" name="fromdate" id="fromdate" class="input1" />
    </div>
    
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">To Date</p>
     <input type="text" name="todate" id="todate" 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>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

$i=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 ";


$sq_arr.=" order by cf_tripsheet.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;
}
$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 
	 	$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>
    <?php 
    $newgross+= $res['grossweights'];
	$newfrieght+= $res['balamt'];
	?>
  </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> 
  </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>
</html>
