<?php
session_start();

include("config.inc.php");

print <<< HERE

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Serial Availability</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
	background-color: #F5F5F5;
}

p {font-size: 11px; font-weight: bold; }


-->
</style>

</head>
<body>
HERE;



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



$sub_query = " Select Distinct SerialNo_Code, Warehouse_Code ".
			 " From Purchasesserialno ".
			 " Where SerialNo_Code = '".$PSerialNo."' ".
			 " And Journal_Type in ('PI','DR','SR','TR','AI','PD') ".
			 " And ifNull(SerialNo_Used,0) = 0  ".
			 " And (RelatedSerial_Id Is Null or RelatedSerial_Id = '') ".
			 " And Not Exists ( Select 1 From Purchasesserialno As PSerNo ".
			 "                  Where PSerNo.RelatedSerial_Id = Purchasesserialno.Serial_ID ".
			 "                  And PSerNo.Journal_Type in ('PR','DI','SI','TR','AR','PD') ".
			 "                 ) ";
			
$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());
$subnum=mysql_num_rows($sub_result);
			
if ($subnum != 0)
{
	$WarehouseCode='';
	while($sub_row=mysql_fetch_array($sub_result)){
			$WarehouseCode = $WarehouseCode." , ".$sub_row[1];
	}
				
	$WarehouseCode = substr($WarehouseCode,2);
	
	$message = 'Serial No. ('.$PSerialNo.') is available in the following warehouse(s): ';
	
	
} else {
	$message = 'Serial No. ('.$PSerialNo.') is not available.';
}

echo "<p>".$message."</p>";
echo "<p>".$WarehouseCode."</p>";


echo"</body></html>";
?>
