<!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'>FTL Reference</span></td>
		<td><span class='header1'>20</span></td>
		<td><span class='header1'>40</span></td>
		<td><span class='header1'>BL #</span></td>
		<td><span class='header1'>Ship Co</span></td>
		<td><span class='header1'>Vessel</span></td>
		<td><span class='header1'>ETA</span></td>
		<td><span class='header1'>Terminal</span></td>
		<td><span class='header1'>ROT #</span></td>
		<td><span class='header1'>ROT Date</span></td>
		<td><span class='header1'>Vessel Berthed</span></td>
		<td><span class='header1'>Ship Co DN Request</span></td>
		<td><span class='header1'>Ship Co Rating</span></td>
		<td><span class='header1'>Ship Co DN Paid</span></td>
		<td><span class='header1'>Ship Co Released</span></td>
		<td><span class='header1'>Remark</span></td>
	</tr>";
	
$query ="select Project_Code, LO_twenty, LO_Forty, Dealer_Code, Team_Code, LO_BLNumber, Ship_Code, LO_VesselName,date_format(LO_ETADate,'%d-%m-%Y') as ETADate, Terminal_Code,
		LO_ROTNumber, date_format(LO_ROTDate,'%d-%m-%Y') as ROTDate,
		date_format(LO_ShippingAdditionalDate,'%d-%m-%Y') as  ShippingAdditionalDate,
		date_format(LO_ShippingRatePerDate,'%d-%m-%Y') as  ShippingRatePerDate,
		date_format(LO_ShippingPaidDate,'%d-%m-%Y') as ShippingPaidDate,
		date_format(LO_ShipCoReleaseDate,'%d-%m-%Y') as ShipCoReleaseDate,LO_Remark
		from Logistic_operations
		left join logistic_dealer on Dealer_Id = LO_DealerId
		left join logistic_team on Team_Id = LO_TeamId
		left join logistic_terminal on Terminal_Id = LO_TerminalID
		left join logistic_shipco on Ship_Id = LO_ShipCoId
		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 LO_CreationDate, Project_Code, Client_code ";	
$result = mysql_query($query, $connection);
while ($row = mysql_fetch_array($result)){
	extract($row);
	
	echo "<tr style='background-color:#d3d3d33d;'>
			<td align='left'><span class='detail1'>$Project_Code</span></td>
			<td align='left'><span class='detail1'>$LO_twenty</span></td>
			<td align='left' ><span class='detail1'>$LO_Forty</span></td>
			<td align='left' ><span class='detail1'>$LO_BLNumber</span></td>
			<td align='left'><span class='detail1'>$Ship_Code</span></td>
			<td align='left' ><span class='detail1'>$LO_VesselName</span></td>
			<td align='center'><span class='detail1'>$ETADate</span></td>
			<td align='left' ><span class='detail1'>$Terminal_Code</span></td>
			<td align='left'><span class='detail1'>$LO_ROTNumber</span></td>
			<td align='center' ><span class='detail1'>$ROTDate</span></td>
			<td ><span class='detail1'></span></td>
			<td align='center' ><span class='detail1'>$ShippingAdditionalDate</span></td>
			<td align='center' ><span class='detail1'>$ShippingRatePerDate</span></td>
			<td align='center' ><span class='detail1'>$ShippingPaidDate</span></td>
			<td align='center' ><span class='detail1'>$ShipCoReleaseDate</span></td>
			<td align='left' ><span class='detail1'>$LO_Remark</span></td>
	</tr>";
	
	
}	
		
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;
