<?php


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

include("config.inc.php");

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");


$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");



$querylog = "SELECT print as printaccess, ifNull(FI_Grn,0) As FI_Grn, ifNull(FI_Purchases,0) As FI_Purchases, ExporttoExcel 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);
}



$querylog = "SELECT 1 as loginaccess,ifnull(fi_showcostprice,0) as fi_showcostprice 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);
}
if ($loginaccess == '' or $loginaccess == 0)
	header("location:menu.php");



$querylog = "select * from " . $_SESSION['dbLabel'] . ".login where user_account='" . $_SESSION['useraccount'] . "'";
$resultlog = mysql_query($querylog) or die(mysql_error());
while ($rows = mysql_fetch_array($resultlog)) {
	extract($rows);
}


$querysalessetup = "select Salesttc from salessetup";
$resultsalessetup = mysql_query($querysalessetup, $connection) or die(mysql_error());
while ($rowssalessetup = mysql_fetch_array($resultsalessetup)) {
	extract($rowssalessetup);
}

$querysetup = "select base1, base2, if(DefaultBase=1, base1, base2) as defaultcurr from setup ";
$resultsetup = mysql_query($querysetup, $connection) or die(mysql_error());
$rowsetup = mysql_fetch_row($resultsetup);
$defaultcurr = $rowsetup[2];

$querydflproject = "select project_code as defaultproject from " . $_SESSION['dbLabel'] . ".loginstk where user_account='" . $_SESSION['useraccount'] . "' and default_project=1  and Upper(loginstk.company_name) = Upper('" . $_SESSION['dbName'] . "') ";
$resultdflproject = mysql_query($querydflproject, $connection) or die(mysql_error());
while ($rows = mysql_fetch_array($resultdflproject)) {
	extract($rows);
}

$queryproject = " select distinct project.project_code, project_name " .
	" from project left join " . $_SESSION['dbLabel'] . ".loginstk on project.project_code like concat(loginstk.project_code,'%') " .
	" where user_account='" . $_SESSION['useraccount'] . "'  and Upper(loginstk.company_name) = Upper('" . $_SESSION['dbName'] . "') " .
	" and (loginstk.project_code is not null and loginstk.project_code != '') " .
	" order by project.project_code";

$projectresult = mysql_query($queryproject, $connection) or die(mysql_error());
$projectrows   = mysql_num_rows($projectresult);
if ($projectrows == 0)
	$queryproject = " select distinct project_code, project_name from project order by project_code ";
$resultproject = mysql_query($queryproject, $connection) or die(mysql_error());


$querysordertype = "select Sorder_Type, Sorder_TypeName from sordertype where FormType = 'Sorder' order by Sorder_Type";
$resultsordertype = mysql_query($querysordertype, $connection) or die(mysql_error());

if (empty($fromdate)) $fromdate = date('01/m/Y');
if (empty($todate))   $todate   = displayToday();

if ($fromadjustmententry == '') $fromadjustmententry = 'All';

print <<< HERE


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">

<script language="JavaScript" src="CalendarPopup.js" ></script>
<script type="text/javascript" language="javascript">
function PrintPrev(exp)
{
	var str='';
  	var x = document.transForm;
	
	var fromdate 	= x.fromdate.value;
	var todate 		= x.todate.value;
	var details = 0;
	if(document.getElementById('details').checked) details = 1;


   
	str = "rep_pendingDeliveryReport.php";
 	
	str = str + "?fromdate="+fromdate+"&todate="+todate+"&exp="+exp+"&details="+details;
	
	window.open(str,"Report");
}

function clearPage(){
	var x = document.transForm;
	
	x.fromdate.value 	= '';
	x.todate.value 		= '';
	 
	x.action = "Form_PendingDelivery.php";
	x.submit();
}
	
</script>


<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
.style1 {
	color: #FF0000;
	font-family: "Times New Roman", Times, serif;
	font-size: 20px;
}
.style8 {font-size: 11px; color: #999999; font-weight: bold; }
.style11 {font-size: 11px}
body {
	margin-top: 0px;
}

</style>

<title>Pending Delivery Report</title>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20101112" media="screen"></link>
<script type="text/javascript" src="dhtmlgoodies_calendar.js?random=20100118"></script>

</head>
<body>
HERE;

echo "<form id='transForm' name='transForm' method='post' action='$_SERVER[PHP_SELF]'>";

echo "<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo " <tr><td  valign='top'>";

include_once("sidemenu.php");
echo "  </td></tr>";


echo " <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'> Pending Delivery </span></td>
				<td class='message' valign='middle' style='height:26px;'>" . htmlspecialchars($message, ENT_QUOTES) . "</td>
			</tr></table>
		</td>
	  </tr>";

echo "<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='30'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px' align='left'>";

echo " <button type='button' id='btnClear' name='btnClear'  title='Clear Page' onClick=\"clearPage()\"><span><span>Clear</span></span></button>";


echo " <button type='button' id='preview' name='preview' onClick=\"PrintPrev('0')\"; title='Preview'><span><span>Preview</span></span></button>";


if ($ExporttoExcel == 1) {
	echo " <button type='button' id='btnExcel' name='btnExcel' onClick=\"PrintPrev('1')\"; title='Export Excel'><span><span>Export Excel</span></span></button>";
}


echo "	</td></tr></table>";
echo "</td></tr>";


echo "<tr><td id='content-body'>
<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
   <tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";

echo "  <table border='0' align='center' width='1100px'>";

// sub-table 1
echo "<tr><td><table border='0' align='center' width='1100px'>";
echo "<col width=100px><col width=200px><col width=400px><col width=400px>";

echo "<tr height='30px'>
		<td colspan='2' align='left'><span class='style8'>Date</span></td>";



echo "   <td width='10%'   bgcolor='#F5F5F5'><span class='style8'>Master</span>  </td> ";

//echo"   <td width='10%' rowspan='2' valign='top' bgcolor='#F5F5F5'><span class='style8'><label>";



echo "<td></td><td align='center'>&nbsp;</td>
	  </tr>";


echo "<tr height='30px'>
	  <td align='left'><span class='style8'>From</span></td>
	  <td align='left'><input type='text' name='fromdate' value='$fromdate' maxlength='10' size='10'>
		   <a href='#' onClick=\"displayCalendar(document.transForm.fromdate,'dd/mm/yyyy',this); return false; \" name='anchor1' id='anchor1'><image src='./img/cal.gif' border=0 align=center></image></a>
	  </td>
	  <td align='left' colspan='2'> 
    <span class='style8'><input type='checkbox' name='details' id='details' value=''>Show Details</span>  </td> ";

echo "   </td>

	  
		  </tr>";
echo "<tr height='30px'>
		  <td align='left'><span class='style8'>To</span></td>
		  <td align='left'><input type='text' name='todate' value='$todate' maxlength='10' size='10'>
			   <a href='#' onClick=\"displayCalendar(document.transForm.todate,'dd/mm/yyyy',this); return false; \" name='anchor1' id='anchor1'><image src='./img/cal.gif' border=0 align=center></image></a>
		  </td></tr>";

echo "<tr height='20px'><td colspan='4'></td></tr>";
echo "</table></td></tr>";






// sub-table 2
echo "<tr><td><table border='0' align='center' width='1100px'>";
echo "<col width=100px><col width=400px><col width=100px><col width=100px><col width=400px>";



echo "</table></td></tr>";


echo "   </table></td></tr>";
echo "   </table></td></tr><tr height='30'><td align='center' id='content-bottom' ></td></tr>";
echo " </table>
 
</form>
</body>
</html>";

function displayFromDate($data)
{
	return "01/01/" . substr($data, 6, 4);
}
//Return Today's Date in DD/MM/YYYY format
function displayToday()
{
	return strftime("%d") . "/" . strftime("%m") . "/" . strftime("%Y");
}
