<!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> Operation 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."'";

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

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

$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 height='20px' bgcolor='#808080'>
		<td><span class='header1'>File</span></td>
		<td><span class='header1'>Date Order Received</span></td>
		<td><span class='header1'>Form M</span></td>
		<td><span class='header1'>Client Ref</span></td>
		<td><span class='header1'>Container Size</span></td>
		<td><span class='header1'>Bill of Lading</span></td>
		<td><span class='header1'>Shipping Line</span></td>
		<td><span class='header1'>ETA</span></td>
		<td><span class='header1'>Terminal</span></td>
		<td><span class='header1'>Terminal Paid</span></td>
		<td><span class='header1'>OBL Rec Date</span></td>
		<td><span class='header1'>Shipping Released</span></td>
		<td><span class='header1'>Date Duty Paid</span></td>
		<td><span class='header1'>Exam. Book</span></td>
		<td><span class='header1'>Examination Date</span></td>
		<td><span class='header1'>Custom Released</span></td>
		<td><span class='header1'>TDO</span></td>
		<td><span class='header1'>Remarks</span></td>
	</tr>";
$tempClient = '#*';
$query ="select client_code, Project_Code, date_format(LO_CreationDate,'%d/%m/%Y') as ReceivedDate, LO_MFNumber as FormM, LO_ClientRef as ClientRef, LO_twenty as Size20, LO_Forty as Size40,
		LO_BLNumber as BLNumber, Ship_Code, date_format(LO_ETADate,'%d/%m/%Y') as ETADate, Terminal_Code, date_format(LO_TerminalPaidDate,'%d/%m/%Y') as TerminalPaidDate,
		date_format(LO_OBLReceivedDate,'%d/%m/%Y') as OBLRecDate, date_format(LO_ShipCoReleaseDate,'%d/%m/%Y') as ShipCoReleaseDate, date_format(LO_DutyPaidDate,'%d/%m/%Y') as DutyPaidDate,
		date_format(LO_ExaminationBookDate,'%d/%m/%Y') as ExamBookDate, date_format(LO_ExaminedDate,'%d/%m/%Y') as ExaminedDate,
		date_format(LO_custReleasedDate,'%d/%m/%Y') as CustomReleased, date_format(LO_TDODate,'%d/%m/%Y') as TDODate, LO_Remark
		from Logistic_operations
		left join logistic_shipco on Ship_Id = LO_ShipCoId
		left join logistic_terminal on Terminal_Id = LO_TerminalID
		where date_format(LO_CreationDate, '%Y-%m-%d') between '$fromdate' and '$todate'
		and Project_Code between ifnull($fromproject,Project_Code) and ifnull($toproject,Project_Code)
		and Client_code between ifnull($fromclient,Client_code) and ifnull($toclient,Client_code)
		and if('$opStatus'='',1=1, LO_Status = '$opStatus')
		order by Client_code, Project_Code, LO_CreationDate ";	
$result = mysql_query($query, $connection);
while ($row = mysql_fetch_array($result)){
	extract($row);
	
	if ($Size20 != '') $Size20 .= "X 20ft";
	if ($Size40 != '') $Size40 .= "X 40ft";

	if ($client_code != $tempClient)
	echo "<tr height='20px' style='background-color:#d3d3d3;'><td colspan='18' align='center'><span class='header1'>$client_code</span></td></tr>";

	echo "<tr style='background-color:#d3d3d33d;'>
			<td align='left'><span class='detail1'>$Project_Code</span></td>
			<td align='left'><span class='detail1'>$ReceivedDate</span></td>
			<td align='left' ><span class='detail1'>$FormM</span></td>
			<td align='left' ><span class='detail1'>$ClientRef</span></td>
			<td align='left'><span class='detail1'>".($Size20 != '' && $Size40 != ''?$Size20."<br>".$Size40:$Size20.$Size40)."</span></td>
			<td align='left' ><span class='detail1'>$BLNumber</span></td>
			<td align='left' ><span class='detail1'>$Ship_Code</span></td>
			<td align='left' ><span class='detail1'>$ETADate</span></td>
			<td align='left' ><span class='detail1'>$Terminal_Code</span></td>
			<td align='left' ><span class='detail1'>$TerminalPaidDate</span></td>
			<td align='left' ><span class='detail1'>$OBLRecDate</span></td>
			<td align='left' ><span class='detail1'>$ShipCoReleaseDate</span></td>
			<td align='left' ><span class='detail1'>$DutyPaidDate</span></td>
			<td align='left' ><span class='detail1'>$ExamBookDate</span></td>
			<td align='left' ><span class='detail1'>$ExaminedDate</span></td>
			<td align='left' ><span class='detail1'>$CustomReleased</span></td>
			<td align='left' ><span class='detail1'>$TDODate</span></td>
			<td align='left' ><span class='detail1'>$LO_Remark</span></td>
	</tr>";
	
	$tempClient = $client_code;
}	
		
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;
