<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<?php

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



print <<< HERE
<HTML>
<HEAD>
<TITLE> Transporter Report </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style type="text/css" >

.header1 {
	font-size: 12px;
	font-weight: bold;
	font-family: sans-serif;
}

.detail1 {
	font-size: 12px;
	font-family: sans-serif;
}

.table1 tr:first-child td {
	border-bottom: 2px solid white;
}
.table1 tr td {
	border-bottom: 1px solid white;
}
</style>
</HEAD>

HERE;



include("config.inc.php");
include 'function.inc.php';

set_time_limit(0);

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

$id = $_GET['id'];

$querylog="SELECT print as printaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

$query = "select company_name, Company_memo, COMPANY_TELEPHONE from setup";
$result = mysql_query($query, $connection);
$row = mysql_fetch_row($result);
$companyname = $row[0];
$companymemo = $row[1];
$companytel = $row[2];

if ($printaccess==0 or $printaccess=='')
echo'<BODY oncontextmenu="return false;">';
else
echo'<BODY>';

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

if ($fromproject == '')  $fromproject = "NULL";
else $fromproject = "'".$fromproject."'";

if ($toproject == '')  $toproject = "NULL";
else $toproject = "'".$toproject."'";

$fromdate 	= explodeword($fromdate);
$todate 	= explodeword($todate);
			
echo "<table cellspacing='0' cellpadding='0' width='100%'>
		<col width=18%><col width=32%><col width=50%>";
// header
echo "<tr>
		<td colspan='2'><span style='font-size: 18px;font-weight: bold; font-family: sans-serif;'>$companyname</span></td>
		<td ></td>
	</tr>";
echo "<tr>
		<td colspan='2'><span style='font-size: 12px;font-weight: bold; font-family: sans-serif;'>$companymemo</span></td>
		<td></td>
	</tr>";
echo "<tr>
		<td colspan='2'><span style='font-size: 12px;font-weight: bold; font-family: sans-serif;'>$companytel</span></td>
		<td ></td>
	</tr>";
echo "<tr height='20px'><td></td></tr>";	
echo "</table>";

echo "<table cellspacing='0' cellpadding='0' width='100%' class='table1'>";
echo "<tr bgcolor='#808080'>
		<td><span class='header1'>Reference Number</span></td>
		<td><span class='header1'>Status</span></td>
		<td><span class='header1'>Time/Date<br>Out of Port</span></td>
		<td><span class='header1'>Transporter</span></td>
		<td><span class='header1'>Pick up Point</span></td>
		<td><span class='header1'>Destin.</span></td>
		<td><span class='header1'>Arrival at Client</span></td>
		<td><span class='header1'>Date off Load</span></td>
		<td><span class='header1'>Date Dropped Empty</span></td>
		<td><span class='header1'>S/N</span></td>
		<td><span class='header1'>Date/Time<br>TDO Given(TDP)</span></td>
		<td><span class='header1'>Container #</span></td>
		<td><span class='header1'>Container Size</span></td>
		<td><span class='header1'>Truck #</span></td>
		<td><span class='header1'>Days to Reach Client</span></td>
		<td><span class='header1'>Days to Offload at Client</span></td>
		<td><span class='header1'>Days to Drop Empty</span></td>
	</tr>";
	
$temp = "**";
$tempstat = "**";

$query ="select LT_ProjectCode, LTdt_Status, date_format(LTdt_OutofPortDate,'%d-%m-%Y %h:%i %p') as OutofPortDate,  Transporter_Code, PickUp_Code, Destination_Code,
		date_format(LTdt_ArrivalatClientDate,'%d-%m-%Y %h:%i %p') as ArrivalatClientDate, date_format(LTdt_OffLoadDate,'%d-%m-%Y %h:%i %p') as OffLoadDate,
		date_format(LTdt_DroppedEmptyDate,'%d-%m-%Y %h:%i %p') as DroppedEmptyDate, date_format(LTdt_TdoDate,'%d-%m-%Y %h:%i %p') as TdoDate,
		LTdt_ContainerNo, LTdt_ContainerSize, LTdt_TruckNo, LTdt_DaysToReachClient, LTdt_DaysToOffload, LTdt_DaysToDropEmpty
		from logistic_transportdt
		inner join logistic_transport on logistic_transport.lt_id = logistic_transportdt.lt_id
		left join logistic_transporter on Transporter_Id = LTdt_TransporterId
		left join logistic_pickup on PickUp_Id = LTdt_PickUpPointId
		left join logistic_destination on Destination_Id = LTdt_ContainerId
		where date_format(LT_Date, '%Y-%m-%d') between '$fromdate' and '$todate'
		and LT_ProjectCode between ifnull($fromproject,LT_ProjectCode) and ifnull($toproject,LT_ProjectCode)
		order by LT_ProjectCode, LTdt_Status ";	
$result = mysql_query($query, $connection);
while ($row = mysql_fetch_array($result)){
	extract($row);
	
	if ($temp != $LT_ProjectCode){
		echo "<tr bgcolor='#a9a9a9'>
				<td colspan='17'><span class='detail1'>$LT_ProjectCode</span></td>
			</tr>";
			$tempstat = "**";
	}	
	echo "<tr>";
	
	if ($temp != $LT_ProjectCode)
		echo "<td style='background-color:#a9a9a9;'><span class='detail1'>$LT_ProjectCode</span></td>";
	else echo "<td style='background-color:#a9a9a9;'></td>";
	
	if ($tempstat != $LTdt_Status)
		echo "<td style='background-color:#d3d3d33d;'><span class='detail1'>$LTdt_Status</span></td>";
	else echo "<td style='background-color:#d3d3d33d;'></td>";
	
	echo "
			<td align='right' style='background-color:#d3d3d33d;'><span class='detail1'>$OutofPortDate</span></td>
			<td style='background-color:#80808059;'><span class='detail1'>$Transporter_Code</span></td>
			<td style='background-color:#d3d3d33d;'><span class='detail1'>$PickUp_Code</span></td>
			<td style='background-color:#d3d3d33d;'><span class='detail1'>$Destination_Code</span></td>
			<td align='right' style='background-color:#d3d3d33d;'><span class='detail1'>$ArrivalatClientDate</span></td>
			<td style='background-color:#80808059;'><span class='detail1'>$OffLoadDate</span></td>
			<td align='right' style='background-color:#d3d3d33d;'><span class='detail1'>$DroppedEmptyDate</span></td>
			<td style='background-color:#d3d3d33d;'><span class='detail1'></span></td>
			<td align='right' style='background-color:#d3d3d33d;'><span class='detail1'>$TdoDate</span></td>
			<td style='background-color:#80808059;'><span class='detail1'>$LTdt_ContainerNo</span></td>
			<td align='right' style='background-color:#d3d3d33d;'><span class='detail1'>$LTdt_ContainerSize</span></td>
			<td style='background-color:#80808059;'><span class='detail1'>$LTdt_TruckNo</span></td>
			<td align='right' style='background-color:#d3d3d33d;'><span class='detail1'>$LTdt_DaysToReachClient</span></td>
			<td align='right' style='background-color:#80808059;'><span class='detail1'>$LTdt_DaysToOffload</span></td>
			<td align='right' style='background-color:#d3d3d33d;'><span class='detail1'>$LTdt_DaysToDropEmpty</span></td>
	</tr>";
	
	$temp 	  = $LT_ProjectCode;
	$tempstat = $LTdt_Status;
}	
		
echo "</table>";		
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;
}

function explodeword($date)
{

$trim = explode('/',$date);
$trim = "$trim[2]"."-"."$trim[1]"."-"."$trim[0]";
return $trim;
}




if ($printaccess==1)
print <<< HERE

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