<?php


session_start();
if($HTTP_SESSION_VARS['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");

print <<< HERE
<HTML>
<HEAD>
<TITLE>Shipment Routing</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">

<style type="text/css">
	
.data{
	
	 FONT-WEIGHT: normal;
	 FONT-SIZE: 9pt;	 
	
	 FONT-FAMILY: arial, sans-serif;
	}
	
.dataitalic{
	
	 FONT-STYLE: italic;
	 FONT-WEIGHT: normal;
	 FONT-SIZE: 8pt;	 
	
	 FONT-FAMILY: arial, sans-serif;
	}

.headeritalic{
	
	 FONT-STYLE: italic;
	 FONT-WEIGHT: bold;
	 FONT-SIZE: 9pt;	 
	
	 FONT-FAMILY: arial, sans-serif;
	}
	
.header{
	
	 FONT-WEIGHT: bold;
	 FONT-SIZE: 11pt;	 
	
	 FONT-FAMILY: arial, sans-serif;
	}
	
.header2{
	
	 FONT-WEIGHT: bold;
	 FONT-SIZE: 8pt;	 
	
	 FONT-FAMILY: arial, sans-serif;
	}	
	
.footerbox{
				
							   
	border-left: 0 solid #000000; border-top: 1 solid #000000; border-bottom: 0 solid #000000;
	FONT-WEIGHT: bold;
	FONT-SIZE: 14px;	 
	color:#2D2D2D;
	font-family:Times-New-Roman;
	BACKGROUND-COLOR: #FFFFFF; 
	
	height: 20;
	 	}
</style>
</HEAD>
<BODY>
HERE;


$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'])
		or die("Could not connect to DB");
mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");

function current_server_time($connection){

  $string="Select date_format(NOW(),'%Y-%m-%d %h:%i %p') ";
  $result=mysql_query($string,$connection) or die(mysql_error());
  $now=mysql_fetch_row($result);

  return $now;
}


$now=current_server_time($connection);
$dt=split(" ",$now[0]);
$printdate=split("-",$dt[0]);


echo "<table border=0 width='100%' cellspacing=0 cellpadding=0  style='table-layout:fixed;' class='master'>
	<col width='35%'>
	<col width='35%'>
	<col width='30%'>";
	
	echo "<tr rowspan='2'><td height='60' valign='top'><b><font size=5 face='arial'>Gemayel Freres SAL</font></td><td align='center' valign='top'><b><font size=5 face='arial'><u>Shipment Routing <BR> (Draft)</u></font></td>
	<td height='40' valign='top' align='right'><img src='img/ISO9001.jpg' width='115' height='50' /></td>
	</tr>";
	


	echo "<tr><td colspan='3' align='center'><table width=100%  border='0'>
		<col width=120>
		<col width=200>
		<col width=110>
";
	 

	 
	$query_edit="select shipment_reference,shipments.cltcar_code,shipment_DriverName,shipments.currency_code,ledger_name,
				shipment_totalamount from shipments
				left join cltcar on cltcar.cltcar_code=shipments.cltcar_code
				left join ledger on ledger.ledger_number=cltcar.Cltcar_Owner
				
where shipment_id='".$shipment_id."'";
	//echo$query_edit;
	$resultedit = mysql_query($query_edit,$connection);
	$row_edit=mysql_fetch_row($resultedit);	
	
	$shipment_reference=$row_edit[0];
	$cltcar_code=$row_edit[1];
	$cltcar_name=$row_edit[2];
	$currency_code=$row_edit[3];
	
	$cltcar_owner=$row_edit[4];
	$totalprice=$row_edit[5];
	
	echo"	<tr  height='35'><td align='left' class='header'>Reference</td>	
<td class='data'><font face='Verdana' size='2'><b>$shipment_reference</font></td>
<td align='left' class='header'>License</td>
		<td class='data'>$cltcar_code";		
 echo"</td>

<td align='right'><font size='1' face='arial'><b>Printed&nbsp;Date&nbsp; &nbsp;</b>";
	echo $printdate[2]."/".$printdate[1]."/".$printdate[0];
	echo "<br><b>Time:</b> &nbsp;&nbsp;&nbsp; ".$dt[1]." ".$dt[2];
	echo "</font></td></tr>";	
	
echo"<tr><td align='left'  class='header'>Owner &nbsp;</td><td class='data'>$cltcar_owner</td>";
echo"	<td align='left'  class='header'>Driver Name</td>
<td class='data' colspan='2'>$cltcar_name</td>
</tr>";
			
echo"   </table></td></tr>";

echo"<tr><td colspan='8' valign='top'><table width=100% border='0'>
		<col width=110>
		<col width=450>
		<col width=110>
		<col width=180>
		<col width=70>";

		  
		  
		  
	$query_dt="select shipmentdt_id,client_code,client_address,sale_reference,delivery_reference,ledger_name,shipment_amount,area_name from shipmentsdt 
				left join clients on clients.ledger_number=shipmentsdt.client_code
				left join area on area.area_code=shipmentsdt.area_code
				where shipment_id='".$shipment_id."'
				order by visitnumber asc,client_code";
	//	echo$query_dt;		
	$resultdt=mysql_query($query_dt,$connection) or die(mysql_error());

			while($rowsdt=mysql_fetch_array($resultdt)){
			    
				$ct+=1;

				if($ct%2==0)
					$Color="style='background-color:".$grid_color1."'";
				else			
					$Color="style='background-color:".$grid_color2."'";	
						
				if($clientcode!=$rowsdt[1] ){
					echo "</td></tr>
					<tr height=25><td></td></tr><tr><td  align='left'  class='header'>Client</td><td align='left'  class='data'>$rowsdt[5] - $rowsdt[1]</td>
						
			
					
					</tr>";
					echo "<tr  ><td  align='left'  class='header'>Address</td><td align='left' class='data' colspan='5'>$rowsdt[2]</td></tr>";
					echo "<tr  ><td  align='left'  class='header'>SSD/INV</td><td align='left' class='data' colspan='5'>";
				}
				
				
				echo"<span class='style15'>$rowsdt[4] / $rowsdt[3] &nbsp; ";
			
				$clientcode=$rowsdt[1];
				
			}
	
	echo"</table></td></tr>";
	
	echo"<tr  height='15'><td align='center'  class='header' ></td>
		<td align='left'  class='header' colspan='2'>&nbsp;</td></tr>";
	

	echo"<tr><td colspan='3'><table border='0' style='border:1px solid #000000;' cellspacing=0>
	<col width=120>
	<col width=110>
	<col width=140>
	<col width=60>
	<col width=100>	
<col width=60>
	<col width=100>
	
	<tr height='35px'><td style='border-right:1px solid #000000;'>&nbsp;</td>
	<td  style='border-right:1px solid #000000;'>&nbsp;</td>
	<td style='border-right:1px solid #000000;'>&nbsp;</td>
	<td align='center'  class='header2' style='border-right:1px solid #000000;' valign='top'>TIME IN</td>
	<td class='header2' align='center' style='border-right:1px solid #000000;' valign='top'>DATE IN</td>
		<td align='center'  class='header2' style='border-right:1px solid #000000;' valign='top'>TIME OUT</td>
		<td class='header2' align='center' style='border-right:1px solid #000000;' valign='top'>DATE OUT</td></tr>
		<tr><td align='center'  class='header2' valign='bottom' style='border-right:1px   solid #000000;'>_ _ _ _ _ _ _ _ _ _ _  &nbsp;</td>
		<td align='center'  class='header2' valign='bottom' style='border-right:1px  solid #000000;'>_ _ _ _ _ _ _ _ _ _ _  &nbsp;</td>
		<td align='center'  class='header2' valign='bottom' style='border-right:1px  solid #000000;'>_ _ _ _ _ _ _ _ _ _ _ _ _ _  </td>
		<td align='left'  class='header2' valign='center' style='border-bottom:1px  solid #000000;border-right:1px  solid #000000;'>&nbsp;</td>
		<td align='left'  class='header2' valign='center' style='border-bottom:1px  solid #000000;border-right:1px  solid #000000;'>&nbsp;</td>
		<td align='left'  class='header2' valign='center' style='border-bottom:1px  solid #000000;border-right:1px  solid #000000;'>&nbsp;</td>
		<td align='left'  class='header2' valign='center' style='border-bottom:1px  solid #000000;border-right:1px  solid #000000;'>&nbsp;</td></tr>";

	echo"<tr height='45px'><td align='center'  class='header2' style='border-right:1px solid #000000;'> DRIVER </td>
		<td align='center'  class='header2' style='border-right:1px solid #000000;'> S.DELIVERY  &nbsp;&nbsp;</td>
		<td align='center'  class='header2' style='border-right:1px solid #000000;'> SHIP.COOR  &nbsp;&nbsp;</td>
		<td align='left'  class='header2' colspan='2' style='border-right:1px solid #000000;' valign='center'>GATE IN  _ _ _ _ _ _ _ _ _ _ _ </td>
		<td align='left'  class='header2' colspan='2' style='border-right:1px solid #000000;' valign='center'>GATE OUT  _ _ _ _ _ _ _ _ _ _ </td></tr></table></td></tr>";

		
		echo"<tr  height='45'><td align='right'  class='header' >Price1 : _________________&nbsp;&nbsp;&nbsp;</td>
		<td align='left'  class='header' colspan='2'>Price2 : _________________  &nbsp;&nbsp;
		
		Price3 : _________________ &nbsp;</td></tr>";
	
	echo"<tr  height='35'><td align='center'  class='header' ></td>
		<td align='left'  class='header' colspan='2'>&nbsp; Total : _________________</td></tr>";
	
echo "</table></td></tr>";


echo"</table>";
print <<< HERE

<script language=javascript>
if (typeof(window.print) != 'undefined')
{
    window.print();
}
</script>
HERE;
print<<<HERE
</BODY>
</HTML>
HERE;
?>