<?php

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


include("config.inc.php");
include("Functions_Sales.php");


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


//Read From SalesSetup Table
$querySalesSetup="Select SalesTTC, Warehouse As SetupDftWareHouse, ifNull(Sale_MaxExceedQty,0) As Sale_MaxExceedQty From SalesSetup";
$resultSalesSetup=mysql_query($querySalesSetup,$connection) or die(mysql_error());
while($rowSalesSetup=mysql_fetch_array($resultSalesSetup)){
	extract($rowSalesSetup);
}

//Warehouse List
$querywarehouse=" select distinct warehouse.warehouse_code, warehouse_name ".
				" from warehouse where warehouse_code in (select warehouse_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."') ".
				" order by warehouse.warehouse_code";
$resultwh = mysql_query($querywarehouse,$connection) or die(mysql_error());
$whexist   = mysql_num_rows($resultwh);
if ($whexist == 0)
	$querywarehouse="select warehouse_code,warehouse_name from warehouse order by warehouse_code";
	
$resultwarehouse=mysql_query($querywarehouse,$connection) or die(mysql_error());



$querydflwh="select warehouse_code as defaultwarehouse from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' and ifNull(default_warehouse,0) = 1 ";
$resultdflwh=mysql_query($querydflwh,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflwh)){
  extract($rows);
}


print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">


function SubmitRecord() {
	x = document.salesdt;
	
	var result = CheckFields();
	
	var SaId      = x.PSaId.value;
	var vMainMode = x.mainaction.value;
	var vMode     = x.actionmode.value;
	
	if (result == 1) {
		x.btnSubmitRecord.disabled = true;
		
		x.action="Form_Delivery_Actions.php?mainmode=loaditems&SSaId="+SaId;
		x.submit();
	}	
}

function ChangeLocation() {
	x = document.salesdt;
	var vMode = x.actionmode.value;
	
	if (vMode == 'submitrecord') {
		opener.document.sales.actionmode.value = x.actionmode.value;
		opener.document.sales.mainaction.value = x.mainaction.value;
		opener.document.sales.txtSaId.value = x.PSaId.value;
		opener.document.sales.submit();
		
		self.close();
	
	}

}

function CheckFields(){
  
    x = document.salesdt;
	
	var SaDtWarehouse = x.lstWarehouse.value;
	
	
	if (SaDtWarehouse=='')
	{
		alert("Warehouse is mandatory!");
		x.lstWarehouse.focus();
		return 0;
	}
		
	
	else
	return 1 ;	
}



function kd(e)
{
	x=document.salesdt;
    var intKey = (window.Event) ? e.which : e.keyCode;
    if (intKey == 13) { //enter key
        //x.btnSubmitRecord.click();
		return false;
    }
    return true;
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Delivery Detail - Add Items</title>


<script type="text/javascript" src="dropdown.js"></script>
<link rel="stylesheet" href="default.css" type="text/css" />
<link rel="stylesheet" href="short.css" type="text/css" />
<link rel="stylesheet" href="dropdown.css" type="text/css" />
<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}

</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

</head>
<body onLoad='ChangeLocation();' >
<form name='salesdt' method='post'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='LoadPrice' value='$LoadPrice'>
<input type='hidden' name='PSaDate' value='$PSaDate'>
<input type='hidden' name='PSaId' value='$PSaId'>
<input type='hidden' name='PSaDtId' value='$PSaDtId'>
<input type='hidden' name='PSaMaturityDate' value='$PSaMaturityDate'>
<input type='hidden' name='PSaClientCode' value='$PSaClientCode'>
<input type='hidden' name='PSaSalesmanCode' value='$PSaSalesmanCode'>
<input type='hidden' name='PSaCurr' value='$PSaCurr'>
<input type='hidden' name='PSaProjectCode' value='$PSaProjectCode'>
<input type='hidden' name='PSaCostCentCode' value='$PSaCostCentCode'>
<input type='hidden' name='PSaDiscount' value='$PSaDiscount'>
<input type='hidden' name='PSaDiscountAmt' value='$PSaDiscountAmt'>
<input type='hidden' name='PSaVatChkbx' value='$PSaVatChkbx'>

<input type='hidden' name='PSaVehicleWeight' value='$PSaVehicleWeight'>
<input type='hidden' name='PSaVehicleLoadWeight' value='$PSaVehicleLoadWeight'>



HERE;
echo "<input type='hidden' name='PSaRemark' value='".htmlspecialchars($PSaRemark, ENT_QUOTES)."' > 
	  <input type='hidden' name='PSaDriverName' value='".htmlspecialchars($PSaDriverName, ENT_QUOTES)."' >
	  <input type='hidden' name='PSaVehicleNumber' value='".htmlspecialchars($PSaVehicleNumber, ENT_QUOTES)."' >
	  <input type='hidden' name='PSaDAddress' value='".htmlspecialchars($PSaDAddress, ENT_QUOTES)."' > 
	  <input type='hidden' name='PSaIAddress' value='".htmlspecialchars($PSaIAddress, ENT_QUOTES)."' >";

	


$lstWarehouse = $_POST["lstWarehouse"]; if ($lstWarehouse == ""){$lstWarehouse = $_GET["lstWarehouse"];}   

if (empty($lstWarehouse)) {
	if(!empty($defaultwarehouse))
		$lstWarehouse = $defaultwarehouse;
	else	
		$lstWarehouse = $SetupDftWareHouse;
}


//$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; width:120px;'";

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='400px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:400px' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Load Items</span></td></tr>
			
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  	  
echo"   <table border='0' style='table-layout:fixed' align='center' valign='top' >
          <col width=75>
		  <col width=370>";
  
	echo" 
		   <tr bgcolor='#F7F7F7' >	
			 <td colspan='2' align='center'><font size='1' color='#FF0000' face='Verdana'><b>".$message."<br>".$WarningMsg."</b></font></td>
		   </tr>
			 
		   <tr bgcolor='#F7F7F7' height='35'>
             <td valign='center' align='left' ><input type='hidden' name='txtSaDtId' value='$txtSaDtId' ><span class='style12'>Warehouse&nbsp;<span class='style26'>*</span></span></td>";
			 
				echo"<td><select name='lstWarehouse' id='lstWarehouse' style='font-size:12px; width:300px; height:22px;' >";
				echo"<option></option>";
				while($wrhf=mysql_fetch_row($resultwarehouse)){
				echo"<option ";
					if (($lstWarehouse==$wrhf[0]) || ($DftWareHouse==$wrhf[0]))
						echo " selected ";
				echo" value='$wrhf[0]'>$wrhf[0] - $wrhf[1]</option>";
				}
				
				echo"</select></td>";
		
echo"	  </tr>	 
		  <tr bgcolor='#F7F7F7' height='30'>
		     <td colspan='2' align='center' bgcolor=#D8D8D8>
			  <button type='button' id='btnSubmitRecord' name='btnSubmitRecord' onclick='SubmitRecord(); return false;' title='Load Sold Items'><span><span>Load</span></span></button>
			  </td>
		  </tr>
        </table>";
 echo "</td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";			 
	echo"	<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:560px;' valign='top'></td>
		<td id='search-bottom3' style='height:34px; width:31px;' valign='top'></td>";
echo" </tr></table>";	  

print <<<HERE
</form>
</body>

HERE;

?>