<?php

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


include("config.inc.php");
include("Functions_Purchase.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");

							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2 from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
extract($rowsetup);
}



print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="default.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Item Quantity</title>
<script type="text/javascript" language="javascript">

function ClearForm()
{
	x=document.productionqty;
	x.txtPrdDtQtyActual.value='';
	
	x.action='Form_ProductionEditQty.php';
	x.submit();

}


function SubmitForm() {
	x=document.productionqty;
	
	var vItemQty = x.txtPrdDtQtyActual.value;
	var vPrdDtId = x.PPrdDtId.value;
	var vPrdId   = x.PPrdId.value;
	
	vItemQty = parseFloat(vItemQty);
	
	if (vItemQty == '' || vItemQty*1 != vItemQty/1 || vItemQty <= 0){
		alert('Quantity should be a NUMERIC value and MORE THAN Zero.');
		x.txtPrdDtQtyActual.focus();
	}
	else 
	{
		x.btnSubmit.disabled = true;
		x.btnCancel.disabled = true;
			
		x.action="Form_Production_Actions.php?mode=editqtyRM&SPrdId="+vPrdId+"&SPrdDtId="+vPrdDtId;
		x.submit();
		
	}

}


function LoadForm() 
{
	x=document.productionqty;
	x.txtPrdDtQtyActual.focus();
	x.txtPrdDtQtyActual.select();
	
	ChangeLocation();
}


function ChangeLocation()
{	
	x=document.productionqty;
	
    if (document.productionqty.PMode.value == 1) {
		opener.document.production.PTabIndex.value = 1;
		opener.document.production.action='Form_Production.php?PTabIndex=1';
		opener.document.production.submit();
		self.close();
	}	
}





</script>

<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; }
.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: #000000 ;font-size: 10px;}

</style>

</head>
<body onLoad='LoadForm();'>
<form name='productionqty' method='post' action=''>
<input type='hidden' name='PMode' id='PMode' value='$PMode'/>
<input type='hidden' name='PPrdId' value='$PPrdId'>
<input type='hidden' name='PPrdDtId' value='$PPrdDtId'>
<input type='hidden' name='PTabIndex' id='PTabIndex' value='$PTabIndex'>
HERE;


$sub_query = " Select ProductionSummaryRM.ProductionSummaryRM_Id, ProductionSummaryRM.Item_Code, Items.Item_Description, ".
			 " ifNull(ProductionSummaryRM_Quantity,0) As ActualQty, ifNull(ProductionSummaryRM_IdealQty,0) As IdealQty, ProductionSummaryRM_Multiplier ".
			 " From Temp_ProductionSummaryRM As ProductionSummaryRM Left Join Items on ProductionSummaryRM.Item_Code = Items.Item_code ".
			 " Where ProductionSummaryRM.ProductionSummaryRM_Id = '".$PPrdDtId."' ".
			 " And ProductionHD_Id = '".$PPrdId."'";
$sub_result = selectData($connection, $sub_query);

$txtItemCode        = $sub_result[1];
$txtItemDesc        = $sub_result[2];
$txtPrdDtQtyActual  = $sub_result[3];
$txtPrdDtQtyIdeal   = $sub_result[4];
$txtPrdDtMultiplier = $sub_result[5];

echo"<table border='0' style='table-layout:fixed' align='center'>
	  <col width=100>
	  <col width=300>";

if ($message != '') {	  
  echo"<tr bgcolor='#F7F7F7'>
		  <td height='15' align='center' colspan='2'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
	   </tr>";
}
		     
echo"  <tr bgcolor='#F7F7F7'>
	    <td align='left'><span class='style11'>Item</span></td>
		<td align='left'><b>$txtItemCode&nbsp;-&nbsp;$txtItemDesc</b></td>
	  </tr>
	  <tr bgcolor='#F7F7F7'>
	    <td align='left' ><span class='style11'>Ideal Qty</span></td>
		<td align='left' ><b>".number_format($txtPrdDtQtyIdeal, $DecimalBase)."</b></td> 
	  </tr>	  
	  <tr bgcolor='#F7F7F7'>
	    <td align='left' ><span class='style11'>Actual Qty</span></td>
		<td align='left' ><span class='style11'>
			<input type='text' name='txtPrdDtQtyActual' id='txtPrdDtQtyActual' value='$txtPrdDtQtyActual' size='20' maxlength='40'/>
		</span></td> 
	  </tr>
	  <tr bgcolor='#DDDDDD' height='35'>
		<td align='center' colspan='2'><span class='style11'><input type='button' name='btnSubmit' value='Submit' onclick='SubmitForm();' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
						  <input type='button' name='btnCancel' value='Cancel' onclick='ClearForm();' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></span></td> 
	  </tr>	
  
	</table>";
	


          

		  

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

HERE;



?>