<?php

session_start();
if($_SESSION['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($_SESSION['dbName'],$connection) or die("Could not find DB");


$querylog="SELECT FI_Production as loginaccess, ifNull(FI_ProductionReqApp,0) As FI_ProductionReqApp, ifNull(Login_FastPrint,0) As Login_FastPrint from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['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");

	
	
//Read From Setup Table							
$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);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_RestrictProjCost,0) As Module_RestrictProjCost, ifNull(Module_RestrictCost,0) As Module_RestrictCost, ".
			 " ifNull(Module_SerialNo,0) As Module_SerialNo, ifNull(Module_PostToJournal,0) As Module_PostToJournal, ".
			 " ifNull(Module_ExpireDate,0) As Module_ExpireDate, ifNull(Module_BatchNo,0) As Module_BatchNo ".
			 " From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

//Read From ProductionSetup Table
$queryProductionSetup="Select ifNull(DisableIdeal,0) As DisableIdeal, ifNull(ShowCostCentLayout,0) As ShowCostCentLayout,ifNull(productionReq_packdt,0) As productionReq_packdt  From ProductionSetup";
$resultProductionSetup=mysql_query($queryProductionSetup,$connection) or die(mysql_error());
while($rowProductionSetup=mysql_fetch_array($resultProductionSetup)){
	extract($rowProductionSetup);
}


$querycurrency="select Currency_code from currency order by currency_code";
$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error());

$querydivtype="Select DivisionTypes_Name From DivisionTypes Where Upper(DivisionTypes_Forms) Like '%PD%' Order By DivisionTypes_Name";
$resultdivtype=mysql_query($querydivtype,$connection) or die(mysql_error());


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


if (empty($mainaction))	$mainaction = 'insert';
if (empty($PTabIndex))  $PTabIndex  = 0;


if (empty($txtCurr))	$txtCurr = $base1;
if (empty($txtDate))	$txtDate = displayToday();

$message = ereg_replace("'"," ",$message);

//Get Default Project
$querydflproject="select project_code as defaultproject from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_project=1 ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}
	
//Get Default Coscenter
$querydflcostcent="select costcent_code as defaultcostcent from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_costcenter=1 ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}

	
if ((empty($txtProjectCode)) && $Module_Project == 1)
	$txtProjectCode = $defaultproject;
if ((empty($txtCostCentCode)) && $Module_CostCenter == 1)
	$txtCostCentCode = $defaultcostcent;	

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" />
<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 type="text/javascript" language="javascript">

function CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost){
  
    x = document.production;
	
	var PrdDate        = x.txtDate.value;
	var PrdDtItem      = x.txtItemCode.value;
	var PrdDtWHFG      = x.txtWhCode.value;
	var PrdDtWHRM      = x.txtWhCodeRM.value;
	var PrdDtQty       = x.txtPrdDtQty.value;
	var PrdProject     = x.txtProjectCode.value;
	var PrdCostCenter  = x.txtCostCentCode.value;
	
	PrdDtQty = parseFloat(PrdDtQty);
	
	var vmode = x.actionmode.value;
		
	if (PrdDate=='' )
	{
		alert("Date Column is mandatory!");
		x.txtDate.focus();
		return 0;
	}	
	else if (PrdDtWHFG=='')
	{
		alert("FG Warehouse Column is mandatory!");
		x.txtWhCode.focus();
		return 0;
	}
	else if (PrdDtWHRM=='')
	{
		alert("RM Warehouse Column is mandatory!");
		x.txtWhCodeRM.focus();
		return 0;
	}
	else if (PrdDtItem=='' )
	{
		alert("Item Column is mandatory!");
		x.txtItemCode.focus();
		return 0;
	}
	else if ((PrdDtQty == '' || PrdDtQty*1 != PrdDtQty/1 || PrdDtQty < 0)) {
		alert('Quantity should be a NUMERIC and POSITIVE value ');
		x.txtPrdDtQty.focus();
		return 0;
	}
	else if (PrdProject=='' && ModuleRestProj==1 && ModuleProj==1)
	{
		alert("Project is mandatory!");
		x.txtProjectCode.focus();
		return 0;
	}
	else if (PrdCostCenter=='' && ModuleRestCost==1 && ModuleCost==1 && document.getElementById('txtCostCentCode').type == 'text')
	{
		alert("CostCenter is mandatory!");
		x.txtCostCentCode.focus();
		return 0;
	}	
	
	
	else
	return 1 ;	
}




function ClearPage(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		x = document.production;
		x.mainaction.value='insert';
		x.actionmode.value='';
		x.action='Form_ProductionRequest.php';
		x.submit();
	}	
}

function ClearPage1(){
	x = document.production;
	var msg = x.message.value;
	
	ClearForm('All');
	
	x.mainaction.value='insert';
	x.actionmode.value='';
	x.message.value=msg;
	x.action='Form_ProductionRequest.php';
	x.submit();
}

function CancelRecord(){
	x = document.production;
	var vmode  = x.mainaction.value;
	var vmode1 = x.actionmode.value;
	var PrdId = x.txtPrdId.value;
	
	if (confirm ( "Are you sure you want to Delete current pending production request permenantly?"))
	{
		x.action="Form_ProductionReq_Actions.php?mode=cancel&mainmode=&SPrdId="+PrdId;
		x.submit();
	}
    
}

function PostChanges() {
	x = document.production;
	var PrdId  = x.txtPrdId.value;
	var vMainMode = x.mainaction.value;
	
	
	if (x.txtPrdCountFG.value == 0 || x.txtPrdCountFG.value == '') {
		alert('Save not allowed. Please add at least one item (Finished Good).');
	}
	else if (x.txtPrdCountRM.value == 0 || x.txtPrdCountRM.value == '') {
		alert('Save not allowed. Please add at least one item (Raw Material).');
	}
	else
	{
		if (confirm ( "Are you sure you want to Save current production request?"))
		{
			x.btnPost.disabled = true;
			x.btnCancel.disabled = true;
			x.btnClear.disabled = true;
			
			if (document.getElementById('btnSubmitRecord'))
				x.btnSubmitRecord.disabled = true;
			
				
			x.actionmode.value='post';
			x.action="Form_ProductionReq_Actions.php?mode=post&mainmode="+vMainMode+"&SPrdId="+PrdId;
			x.submit();
		}
	}
}

function SubmitRecord(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost) {
	x = document.production;
	
	var result = CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost);
	var vPrdId      = x.txtPrdId.value;
	var vPrdDtId    = x.txtPrdDtId.value;
	var vPrdTempId  = x.PrdTempId.value;
	var vItemType   = x.txtItemType.value;
	var vMainMode   = x.mainaction.value;
	var vMode       = x.actionmode.value;
	
	
	if (vPrdDtId == '')
		vMode = 'submitrecord';	
	else
		vMode = 'editdt';	
	   
	if (result == 1) {
		x.action="Form_ProductionReq_Actions.php?SItemType="+vItemType+"&mode="+vMode+"&mainmode="+vMainMode+"&SPrdId="+vPrdId+"&SPrdDtId="+vPrdDtId+"&SPrdTempId="+vPrdTempId;
		x.submit();
		
	}	
}
	
function DeletePrdDt(PrdDtId, ItemPackCode, ItemCode, Option) {

	x = document.production;
	var vPrdId    = x.txtPrdId.value;
	var vTabIndex = x.PTabIndex.value;
	var vMainMode = x.mainaction.value;
	var vDelMsg   = '';
	
	var vMode = 'deletedt'+Option;


	if (ItemPackCode != '')
	   vDelMsg = "Are you sure you want to Delete Pack Item "+ItemPackCode+" ?";
	else  
	   vDelMsg = "Are you sure you want to Delete Item "+ItemCode+" ?";
	   
	if (confirm ( vDelMsg ))
	{
		x.action="Form_ProductionReq_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&SPrdId="+vPrdId+"&SPrdDtId="+PrdDtId+"&STabIndex="+vTabIndex;
		x.submit();
	}

}

function UpdatePrdDt(PrdDtId, Option) {
    x = document.production;
	
	var vItemType   = Option;
	var vPrdId      = x.txtPrdId.value;
		
	var vMainMode = x.mainaction.value;
	
	win = window.open('Form_ProductionReqDetail.php?PItemType='+vItemType+'&mainaction='+vMainMode+'&actionmode=&PPrdId='+vPrdId+'&PPrdDtId='+PrdDtId, 
					  'Form_ProductionReqDetail', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=600,height=250,top=100');		
	win.creator = self;
	win.focus();		

}


function AddDivision(){
	x = document.production;
	
	var vMainMode      = x.mainaction.value;
	var vPrdId    	   = x.txtPrdId.value;
	var vPrdDivId      = x.txtPrdDivID.value;
	var vDivisionId    = x.txtDivisionID.value;
	var vDivisionCode  = x.txtDivisionCode.value;
	
	if (vPrdId == "") {
		alert("Please add an item first.!");
	}
	else if (vDivisionCode == "") {
		alert("Division code is mandatory.!");
		x.txtDivisionCode.focus();
	}
	else {
		if (vPrdDivId == '')	vMode = 'adddivision';	
		else vMode = 'editdivision';
		
		x.action="Form_ProductionReq_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&SPrdId="+vPrdId+"&SPrdDivId="+vPrdDivId;
		x.submit();
	
	}
}

function EditDivision(PrdDivId, DivisionId, DivisionType, DivisionCode) {
	x = document.production;
	
	x.txtPrdDivID.value = PrdDivId;
	x.txtDivisionID.value = DivisionId;
	x.txtDivisionCode.value = DivisionCode;
	x.txtDivType.value = DivisionType;
	
	x.submit();
	
}

function DeleteDivision(PrdDivId, DivisionType, DivisionCode) {
	x = document.production;
	
	var vMainMode = x.mainaction.value;
	var vPrdId    = x.txtPrdId.value;
	var vDelMsg   = "Are you sure you want to Delete "+DivisionType+" ("+DivisionCode+") ?";
	   
	if (confirm ( vDelMsg ))
	{
		x.action="Form_ProductionReq_Actions.php?mode=deletedivision&mainmode="+vMainMode+"&SPrdId="+vPrdId+"&SPrdDivId="+PrdDivId;
		x.submit();
	}

}

function ClearDivision() {
	x = document.production;
	
	x.txtPrdDivID.value = '';
	x.txtDivisionID.value = '';
	x.txtDivisionCode.value = '';
	x.txtDivType.value = '';
	
	x.submit();

}

//All= All form; D= Detail Part
function ClearForm(Option){
    x = document.production;
	var vmode = x.actionmode.value;
	
	if (Option == 'All') {
		
		x.txtPrdId.value='';
		x.txtRef.value='';
		x.txtDate.value='';
		x.txtRemark.value='';
		x.txtManager.value='';
		x.txtShift.value='';
		x.txtConfirmed.value=0;
		x.txtProjectCode.value='';
		x.txtCostCentCode.value='';
		
		x.txtWhCode.value='';
		x.txtWhDesc.value='';
		x.txtWhCodeRM.value='';
		x.txtWhDescRM.value='';
		x.txtItemCode.value='';
		x.txtItemDesc.value='';
		x.txtPrdDtQty.value='';
		x.txtPrdDtId.value='';
		x.txtItemType.value='';
		x.PrdTempId.value='';
				
		x.message.value='';
		x.txtPrdCountFG.value='';
		x.txtPrdCountRM.value='';
		
		x.actionmode.value = '';
		x.mainaction.value = '';
		x.PTabIndex.value = 0;
	} 
}



function SearchForRef(){
    //ClearForm('All');
    x = document.production;
    win = window.open('Form_ProductionReqSearch.php', 'ProductionReqSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=1030,height=580,top=100,left=10');		
	win.creator = self;
	win.focus();		
			
}

function SearchForPending(){
    //ClearForm('All');
    x = document.production;
    win = window.open('Form_ProductionReqSearchPending.php', 'Form_ProductionReqSearchPending', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=900,height=580,top=100,left=10');		
	win.creator = self;
	win.focus();		
			
}



function SetConfirmed() {
	x = document.production;
	
	x.txtConfirmed.value = 0;
	if (x.chkConfirmed.checked) x.txtConfirmed.value = 1;

}


function PrintProductionReq(PrdId, PrdRef) {
	var str = '';
	var vPrintRM = 0;
	
	if (confirm ( "Do you want to Print current Production Request with reference "+PrdRef+" ?"))
	{
		if (confirm ('Do you want to print with Raw Materials?') )
		{
			vPrintRM = 1;
		}
		str = 'Form_ProductionReqPreview.php?ProductionReqId='+PrdId+'&PPrintRM='+vPrintRM;
		window.open(str);
	}	
}



function showlistTemplate() {
	x = document.production;
	
	win = window.open('Form_ProductionReq_LoadTemplate.php', 'Form_ProductionReq_LoadTemplate', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=760,height=580,top=100,left=20');		
	win.creator = self;
	win.focus();

}

function showlistItems(str){
	var vdate, vid;
	x = document.production;
	  
	vdate = x.txtDate.value;
	vid   = x.txtPrdId.value;
	vItemSort  = 'ItemCode';
	vItemType  = 'Trading';
	vItemWh    = x.txtWhCode.value;
	vItemCode  = x.txtItemCode.value;
	  
	vItemWh = vItemWh.replace('&','%26');
	  
	window.open('List_SorItems.php?frm=3&PItem_Code='+vItemCode+'&ItemType='+vItemType+'&ItemSort='+vItemSort+'&ItemWh='+vItemWh+'&TransDate='+vdate,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,top=50,left=100');
}

function showlistWarehouse(str){
	var vdate, vcode;
  
	window.open('List_SorWarehouse.php?frm=1&item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,top=50,left=100');
}
function showlistFromWarehouse(vindx){
	window.open('List_SorWarehouse.php?frm=8&item=1&index='+vindx,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,top=50,left=100');
}

function showlistProject(str){

	vProjectCode = encodeURIComponent(document.getElementById('txtProjectCode').value);
	window.open('List_SorProject.php?frm=7&item='+str+'&PProject_Code='+vProjectCode,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistCostcenter(str){

	vCostcentCode = encodeURIComponent(document.getElementById('txtCostCentCode').value);
	window.open('List_SorCostcenter.php?frm=7&item='+str+'&PCostcent_Code='+vCostcentCode,'mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistDivision(str) {
	x = document.production;
	
	vDivisionType = x.txtDivType.value;
	
	if (vDivisionType == "") {
		alert("Division Type is mandatory.!");
		x.txtDivType.focus();
	} else {
		window.open('List_FrmDivisions.php?frm=3&item='+str+'&divtype='+vDivisionType,'Divisions','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,width=700,height=450,left=100,top=20');
	}
	
}

function roundNumber(num, dec) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
  newnumber = parseFloat(newnumber); 
  
  return newnumber;
}

function formatNumber(num, dec) { // Arguments: number to format, number of decimal places
	return num.toFixed(dec);
}

function savedata(){
	var x = document.production;
	var vMainMode = 'insert';
	var vMode = 'transferData';
	var SPrdId = x.txtPrdId.value;
	x.action="Form_ProductionReq_Actions.php?SPrdId="+SPrdId+"&mode="+vMode+"&mainmode="+vMainMode;
	x.submit();
}
function savedataFG(){
	var x = document.production;
	var vMainMode = 'insert';
	var vMode = 'transferDataFG';
	var SPrdId = x.txtPrdId.value;
	x.action="Form_ProductionReq_Actions.php?SPrdId="+SPrdId+"&mode="+vMode+"&mainmode="+vMainMode;
	x.submit();
}

</script>
<title>Production Request</title>



<script type="text/javascript" src="tabsClass/tabber.js"></script>
<link rel="stylesheet" href="tabsClass/tabber.css" type="text/css" />

<script type="text/javascript">

/* Optional: Temporarily hide the "tabber" class so it does not "flash"
   on the page as plain HTML. After tabber runs, the class is changed
   to "tabberlive" and it will appear.
*/

var tabberOptions = {

  /* Optional: instead of letting tabber run during the onload event,
     we'll start it up manually. This can be useful because the onload
     even runs after all the images have finished loading, and we can
     run tabber at the bottom of our page to start it up faster. See the
     bottom of this page for more info. Note: this variable must be set
     BEFORE you include tabber.js.
  */
  'manualStartup':true,

  /* Optional: code to run after each tabber object has initialized */


  /* Optional: code to run when the user clicks a tab. If this
     function returns boolean false then the tab will not be changed
     (the click is canceled). If you do not return a value or return
     something that is not boolean false, */

  'onClick': function(argsObj) {

    var t = argsObj.tabber; /* Tabber object */
    var id = t.id; /* ID of the main tabber DIV */
    var i = argsObj.index; /* Which tab was clicked (0 is the first tab) */
    var e = argsObj.event; /* Event object */
	
	if (id == 'tab1-1') document.getElementById('PTabIndex').value = i;
  },

  /* Optional: set an ID for each tab navigation link */
  'addLinkId': true

};


</script>
<style>
.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>
<form name='production' method='post'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='message' value='$message' size='200'>
<input type='hidden' name='PTabIndex' id='PTabIndex' value='$PTabIndex'>
<input type='hidden' name='PrdTempId' value='$PrdTempId' >
HERE;


if (empty($txtConfirmed)) $txtConfirmed = 1;
	
		
if ($actionmode != "cancel" && $txtPrdId != '') {
	// Read From Temp Tables For Selected Record				 
	$query = " Select ProductionReq_ID, ProductionReq_Reference, Date_Format(ProductionReq_Date,'%d/%m/%Y') As ProductionReq_Date, ".
	         " ProductionReq_Remark, ProductionReq_Manager, ProductionReq_Shift, ifNull(ProductionReq_Confirmed,0), Project_Code, CostCenter_Code ".
			 " From Temp_ProductionRequest As ProductionRequest ".
			 " Where ProductionReq_ID = ".$txtPrdId;
			 
			 
	//echo $query;
	$result=mysql_query($query,$connection) or die(mysql_error());
    $rows=mysql_fetch_array($result);
	
	$txtPrdId      = $rows[0];
	$txtRef        = $rows[1];
	$txtDate       = $rows[2];
	$txtRemark     = $rows[3];
	$txtManager    = $rows[4];
	$txtShift      = $rows[5];
	$txtConfirmed  = $rows[6];
	$txtProjectCode  = $rows[7];
	$txtCostCentCode = $rows[8];
	
	
	$query = " Select Count(*) FROM Temp_ProductionReqFG ".
			 " WHERE ProductionReq_Id = ".$txtPrdId;
	$result = selectData($connection, $query);
	$txtPrdCountFG = $result[0];
	if($txtPrdCountFG == '') $txtPrdCountFG = 0;
	
	$query = " Select Count(*) FROM Temp_ProductionReqRM ".
			 " WHERE ProductionReq_Id = ".$txtPrdId;
	$result = selectData($connection, $query);
	$txtPrdCountRM = $result[0];
	if($txtPrdCountRM == '') $txtPrdCountRM = 0;
	
}


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


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'>PRODUCTION REQUEST</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' onclick=\"ClearPage();return false;\"' title='Clear Page'><span><span>Clear Page</span></span></button>";
		
echo"   <button type='button' name='btnCancel' id='btnCancel' ";//cancel
		if ($actionmode=='cancel' || ($actionmode=='' && $mainaction!='edit'))
			echo " disabled ";
		echo" onclick='CancelRecord();'  title='Cancel Changes'><span><span>Cancel</span></span></button>";
				
echo"   <button type='button' name='btnPost' id='btnPost'  ";//post
		if (($actionmode=='' || $actionmode=='cancel') && $mainaction!='edit')
			echo " disabled ";
		echo" onclick='PostChanges();' title='Save Changes' /><span><span>Save</span></span></button>";

echo"   <button name='btnSearch' type='button' id='btnSearch' value='Search' onclick='SearchForRef();'  title='Search By Reference' ";
        if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit') 
		    echo " disabled ";
		echo " /><span><span>Search</span></span></button>";
				
echo"   <button name='btnPending' type='button' id='btnPending' value='Pending' onclick='SearchForPending();'  title='Pending Production' ";
        if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit')
		    echo " disabled ";
		echo " /><span><span>Pending</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' style='table-layout:fixed'>
		  <col width=90>
		  <col width=130>
		  <col width=80>
		  <col width=200>
		  <col width=80>
		  <col width=400>";

echo"	<tr bgcolor='#F7F7F7' >
          <td valign='center' align='left' ><span class='style1'>Reference&nbsp;<span class='style26'>*</span></span></td>
		  <td><font face='Verdana' size='2'><b>&nbsp;$txtRef</b></font>
			<input type='hidden' name='txtPrdCountFG' value='$txtPrdCountFG' >
			<input type='hidden' name='txtPrdCountRM' value='$txtPrdCountRM' >
			<input type='hidden' name='txtPrdId' value='$txtPrdId' >
			<input type='hidden' name='txtRef' value='$txtRef' >
			<input type='hidden' name='txtConfirmed' value='$txtConfirmed' ></td>
		  <td align='left'><span class='style1'>Date&nbsp;<span class='style26'>*</span></span></td>
		  <td><input type='text' name='txtDate' value='$txtDate' maxlength='10'  style='width:80px;' >
		                   <A HREF='#' onClick=\"displayCalendar(document.production.txtDate,'dd/mm/yyyy',this); return false;\" NAME='anchor1' ID='anchor1'><img src='./img/cal.gif' border=0 align=center></A>
		  </td>";
						   


echo" 	  <td align='left' ><span class='style1'>Manager</span></td>
		  <td ><input type='text' name='txtManager' value='".htmlspecialchars($txtManager, ENT_QUOTES)."'  style='width:300px;' maxlength='100' ></td>";
echo"   </tr>";

echo"   <tr bgcolor='#F7F7F7' >
		  <td align='left' ><span class='style1'>Remark</span></td>
		  <td colspan='3' ><span class='style1'><input type='text' name='txtRemark' value='".htmlspecialchars($txtRemark, ENT_QUOTES)."'  style='width:385px;' maxlength='100' ></td>";

echo" 	  <td align='left' ><span class='style1'>Shift</span></td>
		  <td ><input type='text' name='txtShift' value='".htmlspecialchars($txtShift, ENT_QUOTES)."'  style='width:300px;' maxlength='100' ></td>";
echo"   </tr>";	


echo"	<tr bgcolor='#F7F7F7'>";

if ($Module_Project == 1) {
	echo" <td align='left' ><span class='style1'>Project&nbsp;<span class='style26'>*</span></span></td>
	      <td align='left' ><span class='style1'>
		    <input type='text' name='txtProjectCode' id='txtProjectCode' value='$txtProjectCode' style='width:100px;' maxlength='15' onchange=\"CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCodeH');\" /></span>
		    <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Project ' id='lstProjectCodeH' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistProject(1); '  /></span></label></td>";
} else {
	echo" <td align='left' colspan='2'><input type='hidden' name='txtProjectCode' id='txtProjectCode' value='' /></td>";

}			

if ($Module_CostCenter == 1 && $ShowCostCentLayout == 1) {		  
	echo" <td align='right' ><span class='style1'>Costcenter&nbsp;<span class='style26'>*</span></span></td>		
		  <td align='left' ><span class='style1'>
		    <input type='text' name='txtCostCentCode' id='txtCostCentCode' value='$txtCostCentCode' style='width:139px;' maxlength='15' onchange=\"CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCodeH');\" /></span>
		    <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Costcenter ' id='lstCostCentCodeH' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCostcenter(1); ' /></span></label></td>";
} else {
	echo" <td align='left' colspan='3'><input type='hidden' name='txtCostCentCode' id='txtCostCentCode' value='' /></td>";

}
echo"     	<td align='left' colspan='2'>&nbsp;</td>";
echo"   </tr>";

/*
echo"	<tr bgcolor='#F7F7F7'>";
echo"		<td align='left' ><span class='style1'>Divisions</span></td>";
echo"		<td align='left' colspan='3'> <span class='style1'>
			<span class='style1'><select name='txtDivType' id='txtDivType' style='width:100px;'>";
			echo"<option></option>";
			while($divtype=mysql_fetch_row($resultdivtype)){
				echo"<option ";
				if ($txtDivType==$divtype[0])
					echo " selected ";
				echo" value='$divtype[0]'>$divtype[0] </option>";
			}
echo"		</select></span>";
echo"		<input type='hidden' name='txtPrdDivID' id='txtPrdDivID' value='$txtPrdDivID'> ";
echo"		<input type='hidden' name='txtDivisionID' id='txtDivisionID' value='$txtDivisionID'> ";
echo"		<input type='text' name='txtDivisionCode' id='txtDivisionCode' value='$txtDivisionCode' style='width:150px;' maxlength='15' readonly /></span>
				<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Division ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistDivision(1); '/></span></label>";
echo"		<input type='button' id='btnAddDivision' name='btnAddDivision' value='Submit'  onclick=\"AddDivision();\" $style title='Add Division'>";
echo"		<input type='button' id='btnClearDivision' name='btnClearDivision' value='Clear'  onclick=\"ClearDivision();\" $style title='Clear Division'>";
echo"   	</td>";
echo"     	<td align='left' colspan='2'>&nbsp;</td>";
echo"   </tr>";*/


/*
if ($txtPrdId != '' ) {
	$sub_query = " Select ProductionReqDivisions_ID, ProductionReqDivisions.Divisions_Id, DivisionTypes_Name, Divisions_Code, Divisions_Name  ".
				 " From Temp_ProductionReqDivisions As ProductionReqDivisions ".
				 " Inner Join Divisions on ProductionReqDivisions.Divisions_Id = Divisions.Divisions_Id ".
				 " Inner Join DivisionTypes on Divisions.DivisionTypes_Id = DivisionTypes.DivisionTypes_Id ".
				 " Where ProductionReqDivisions.ProductionReq_Id = '".$txtPrdId."' ";
	$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());	
	$sub_totalrows = mysql_num_rows($sub_result);
	//echo $sub_query;
	
	if ($sub_totalrows > 0) {
		
		echo"<tr bgcolor='#F7F7F7'>";
		echo"	<td align='left' colspan='6'>";
		echo"	<table border='0' style='table-layout:fixed'>
				  <col width=20>
				  <col width=20>
				  <col width=100>
				  <col width=130>
				  <col width=250>";
		echo"		<tr>";
		echo"  			<td bgcolor='#F7F7F7' align='left' colspan='3'><span class='style27'>&nbsp;</span></td>";
		echo"  			<td bgcolor='#F7F7F7' align='left'><span class='style27'>Code</span></td>";
		echo"  			<td bgcolor='#F7F7F7' align='left'><span class='style27'>Name</span></td>";		  
		echo"		</tr>";
		
		while($sub_rows=mysql_fetch_array($sub_result)){
			$ct+=1;

			if($ct%2==0)
				$Color="style='background-color:".$grid_color1."'";
			else			
				$Color="style='background-color:".$grid_color2."'";	
						
					
			echo "<tr ".$Color." >";
			echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=\"EditDivision('".$sub_rows[0]."','".$sub_rows[1]."','".htmlentities($sub_rows[2])."','".htmlentities($sub_rows[3])."')\" title='Edit Record'  ></span></td>";
			echo "	<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=\"DeleteDivision('".$sub_rows[0]."','".htmlentities($sub_rows[2])."','".htmlentities($sub_rows[3])."')\" title='Delete Record'  ></span></td>";
			echo "	<td align='left'><span class='style15'>".$sub_rows[2]."</span></td>";
			echo "	<td align='left'><span class='style15'>".$sub_rows[3]."</span></td>";
			echo "	<td align='left'><span class='style15'>".$sub_rows[4]."</span></td>";
			echo "</tr>";
									
		}
		
		echo"	</table></td>";
		echo"</tr>";

	}	
}	*/

if ($PrdTempId != '') {
	//Load Finished Good From Template
	if($productionReq_packdt == 1)
		$sub_query = " Select ProdRecipeFG.Item_Code, Items.Item_Description, ProdRecipeFG.Warehouse_Code, ".
				 " Warehouse.Warehouse_Name, ifNull(ProdRecipeFG_Quantity, 1) ".
				 " From ProdRecipeFG ".
				 " Inner Join Items on Items.Item_Code = ProdRecipeFG.Item_Code ".
				 " Inner Join Warehouse on Warehouse.Warehouse_Code = ProdRecipeFG.Warehouse_Code ".
				 " Where ProdRecipeFG.ProdRecipe_Id = '".$PrdTempId."' ";
	else if($productionReq_packdt == 0)			 
	$sub_query = " Select ProdRecipeFG.Item_Code, Items.Item_Description, ProdRecipeFG.Warehouse_Code, ".
				 " Warehouse.Warehouse_Name, ifNull(ProdRecipeFG_Quantity, 1) ".
				 " From ProdRecipeFG ".
				 " Inner Join Items on Items.Item_Code = ProdRecipeFG.Item_Code ".
				 " Inner Join Warehouse on Warehouse.Warehouse_Code = ProdRecipeFG.Warehouse_Code ".
				 " Where ProdRecipeFG.ProdRecipe_Id = '".$PrdTempId."' ";
	//echo $sub_query;			 
	$sub_result = selectData($connection, $sub_query);
	$txtItemCode = $sub_result[0];
	$txtItemDesc = $sub_result[1];
	$txtWhCode   = $sub_result[2];
	$txtWhDesc   = $sub_result[3];
	//$txtWhCodeRM = $sub_result[5];
	//$txtWhDescRM = $sub_result[6];
	$txtPrdDtQty = $sub_result[4];
						  
}


echo"   <tr bgcolor='#F7F7F7'><td colspan='6' valign='top'>";
echo"   <table border='0' cellspacing=1 style='table-layout:fixed; margin-top:7px;'>
		  <col width=120>
		  <col width=130>
		  <col width=80>
		  <col width=200>
		  <col width=80>
		  <col width=220>";
echo"   <tr bgcolor='#D8D8D8'>
		  <td align='left' ><span class='style1'>Warehouse FG&nbsp;<span class='style26'>*</span></span></td>";
echo"     <td align='left' colspan='3' ><span class='style1'><label>
           <input type='text' name='txtWhCode' id='txtWhCode' value='$txtWhCode' style='width:110px;' maxlength='10'  />
           <input type='text' name='txtWhDesc' id='txtWhDesc' value='$txtWhDesc' style='width:270px;'  />
		   <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Warehouse For FG ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistWarehouse(1); ' /> </span></label>
		   <input type='hidden' name='txtPrdDtId' value='$txtPrdDtId' >
		   <input type='hidden' name='txtItemType' value='$txtItemType' >
          </label>
          </span>
          </td>";
echo"     <td align='left'>&nbsp;</td>";
echo"     <td align='left'>";
echo"			<span class='style1'><input type='checkbox' name='chkConfirmed' id='chkConfirmed' value='1' onclick='SetConfirmed();' "; if($txtConfirmed==1) echo "checked />"; else echo " />"; echo " Confirmed</span>";
echo"     </td>";
echo"   </tr>";	

echo"   <tr bgcolor='#D8D8D8'>
		  <td align='left' ><span class='style1'>Warehouse RM&nbsp;<span class='style26'>*</span></span></td>";
if( $txtWhCodeRM!= '' && $txtWhDescRM == '')		  {
	$querywh = "select warehouse_name from warehouse where warehouse_code='$txtWhCodeRM'";
	$reswh = mysql_query($querywh,$connection);
	$rowwh = mysql_fetch_row($reswh);
	$txtWhDescRM = $rowwh[0];
}
echo"     <td align='left' colspan='3' ><span class='style1'><label>
           <input type='text' name='txtWhCodeRM' id='txtWhCodeRM' value='$txtWhCodeRM' style='width:110px;' maxlength='10'  />
           <input type='text' name='txtWhDescRM' id='txtWhDescRM' value='$txtWhDescRM' style='width:270px;'  />
		   <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Warehouse For RM ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistWarehouse(2); ' /> </span></label>
          </label>
          </span>
          </td>";
echo"     <td align='left' colspan='2'>&nbsp;</td>";
echo"   </tr>";	

echo"   <tr bgcolor='#D8D8D8'>
		  <td align='left' ><span class='style1'>Item&nbsp;<span class='style26'>*</span></span></td>";
echo"     <td align='left' colspan='3' ><span class='style1'><label>
           <input type='text' name='txtItemCode' id='txtItemCode' value='$txtItemCode' style='width:110px;' maxlength='10'  />
           <input type='text' name='txtItemDesc' id='txtItemDesc' value='$txtItemDesc' style='width:270px;'  />
		   <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Item ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistTemplate(); ' /> </span></label>
          </label>
          </span>
          </td>";

echo"     <td align='left' ><span class='style1'>Quantity</span></td>";
echo"     <td ><span class='style1'><input type='text' name='txtPrdDtQty' id='txtPrdDtQty' value='$txtPrdDtQty' style='width:100px;' /></span>

			<button type='button' id='btnSubmitRecord' name='btnSubmitRecord'   onclick='SubmitRecord($Module_RestrictProjCost, $Module_RestrictCost, $Module_Project, $Module_CostCenter)' $style style='width:80px;' title='Submit Record'>
			<span><span>Submit</span></span></button>
		  </td>";
echo"   </tr>";	
echo"	</table></td></tr>";


echo"   <tr bgcolor='#F7F7F7'><td colspan='6' align='left' style='padding-top:7px;'>";
			
echo"	<div class='tabber' id='tab1'>";
echo"		<div class='tabbertab'>
				<h2 title='Items'>Items</h2>";
		
		//Create Tabs For Each FG
		if ($txtPrdId != '' ) {
			echo"<div class='tabber' id='tab1-1'>";
			
			
			$sub_query1 = " Select ProductionReqFG.ProductionReqFG_ID, ProductionReqFG.Item_CodePacked, ProductionReqFG.Item_Code, Item_Description, ".
						  " ProductionReqFG.Warehouse_Code, ifNull(ProductionReqFG_Quantity,0), Items.Item_UnitSalesDesc ".
						  " From Temp_ProductionReqFG As ProductionReqFG Left Join Items on ProductionReqFG.Item_Code = Items.Item_code ".
						  " Where ProductionReqFG.ProductionReq_ID = '".$txtPrdId."' ";
			//echo $sub_query1;
			$sub_result1=mysql_query($sub_query1,$connection) or die(mysql_error());
			while($sub_rows1=mysql_fetch_row($sub_result1)){
				
				echo"<div class='tabbertab'>
					 <h2 class='tab2' title='".$sub_rows1[2]."'>".$sub_rows1[2]."</h2>";
				
				echo"<table border='0' style='table-layout:fixed'>
						  <col width=30>
						  <col width=30>
						  <col width=150>
						  <col width=350>
						  <col width=100>
						  <col width=100>
						  <col width=60>";
						  
				echo"<tr height='20px;'>";		  
				echo"  <td colspan='2' align='left'>
						 <img src='img/edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdatePrdDt('".$sub_rows1[0]."','FG') title='Edit Record'  >
						 |&nbsp;<img src='img/delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=\"DeletePrdDt('".$sub_rows1[0]."','".htmlentities($sub_rows1[1])."','".htmlentities($sub_rows1[2])."','FG')\" title='Delete Record'  >
					   </td>";
				echo"  <td colspan='2' align='left'><span class='style15'>".$sub_rows1[3]."</span></td>";
				echo"  <td align='left'><span class='style15'>".$sub_rows1[4]."</span></td>";
				echo "	<td align='right'><span class='style15'>".number_format($sub_rows1[5], $DecimalBase)."</span></td>";
				echo"  <td align='left'><span class='style15'>".$sub_rows1[6]."</span></td>";
				echo"</tr>";
				
				echo"<tr height='20px;'>";
				echo"  <td bgcolor='#D8D8D8' align='left'><span class='style27'>&nbsp;</span></td>";
				echo"  <td bgcolor='#D8D8D8' align='left'><span class='style27'>&nbsp;</span></td>";
				echo"  <td bgcolor='#D8D8D8' align='left'><span class='style27'>Item Code</span></td>";
				echo"  <td bgcolor='#D8D8D8' align='left'><span class='style27'>Description</span></td>";
				echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>WH</span></td>";
				echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>Qty</span></td>";
				echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>Unit</span></td>";
				if($productionReq_packdt == 1)
				echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>Qty Exist</span></td>";
				echo"</tr>";		  
				
				if($productionReq_packdt == 0)
				$sub_query2 = " Select ProductionReqRM.ProductionReqRM_ID, ProductionReqRM.Item_CodePacked, ProductionReqRM.Item_Code, Item_Description, ".
							  " ProductionReqRM.Warehouse_Code, ifNull(ProductionReqRM_Quantity,0) As ProductionReqRM_Quantity, Items.Item_UnitSalesDesc ".
							  " From Temp_ProductionReqRM As ProductionReqRM Left Join Items on ProductionReqRM.Item_Code = Items.Item_code ".
							  " Where ProductionReqRM.ProductionReq_ID = '".$txtPrdId."' ".
							  " And ProductionReqFG_Id = '".$sub_rows1[0]."'";
				else if($productionReq_packdt == 1)	
				$sub_query2 = " Select ProductionReqRM.ProductionReqRM_ID, ProductionReqRM.Item_CodePacked, ProductionReqRM.Item_Code, Item_Description, ".
							  " ProductionReqRM.Warehouse_Code, ifNull(ProductionReqRM_Quantity,0) As ProductionReqRM_Quantity, Items.Item_UnitSalesDesc ".
							  " From Temp_ProductionReqRM As ProductionReqRM ".
							  " left join items on items.item_code = ProductionReqRM.Item_Code ".
							  " Where ProductionReqRM.ProductionReq_ID = '".$txtPrdId."' ".
							  " And ProductionReqFG_Id = '".$sub_rows1[0]."' ";				
				//echo $sub_query2;
				$sub_result2=mysql_query($sub_query2,$connection) or die(mysql_error());
				while($sub_rows2=mysql_fetch_row($sub_result2)){
					$ct+=1;

					if($ct%2==0)
						$Color="style='background-color:".$grid_color1."'";
					else			
						$Color="style='background-color:".$grid_color2."'";	
					

					$sub_query3  = " Select QtyExistsWSorder('".$sub_rows2[2]."', '".$sub_rows2[4]."', Now(), 0, 'PDT', '', '') QtyExists From Dual ";
				$sub_result3 = selectData($connection, $sub_query3);
				$vItemQtyExists = 0;
				$vItemQtyExists = $sub_result3[0]; 
				
					echo "<tr ".$Color." >";
					echo "	<td align='center' valign='center'><span class='style15'><img src='img/edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdatePrdDt('".$sub_rows2[0]."','RM') title='Edit Record'  ></span></td>";
					echo "	<td align='center' valign='center'><span class='style15'><img src='img/delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=\"DeletePrdDt('".$sub_rows2[0]."','".htmlentities($sub_rows2[1])."','".htmlentities($sub_rows2[2])."','RM')\" title='Delete Record'  ></span></td>";
					echo "	<td align='left'><span class='style15'>".$sub_rows2[2]."</span></td>";
					echo "	<td align='left'><span class='style15'>".$sub_rows2[3]."</span></td>";
					echo "	<td align='left'><span class='style15'>".$sub_rows2[4]."</span></td>";
					echo "	<td align='right'><span class='style15'>".number_format($sub_rows2[5], $DecimalBase)."</span></td>";
					echo "	<td align='left'><span class='style15'>".$sub_rows2[6]."</span></td>";
					if($productionReq_packdt == 1)
					echo "	<td align='right'><span class='style15'>".number_format($vItemQtyExists, $DecimalBase)."</span></td>";
					echo "</tr>";
											
				}
				if($transferdoneFG!='') $disablebtn2 = 'disabled';
			else $disablebtn2 = '';
			if($productionReq_packdt == 0){
			echo "<input type='hidden' name='transferdoneFG' value='$transferdoneFG'>";
			echo "<tr><td colspan='8' align='center'><input type='button' name='but2'  onmouseover=\"style.cursor='pointer'\"  onclick='savedataFG();' value='Create Transfer' $disablebtn2></td></tr>";
			}
				echo "</table>";
			
				echo"</div>";
			}
			
			echo"</div>"; $flag=1;
		}

		
echo"		</div>";

echo"		<div class='tabbertab'>
				<h2 title='Summary'>Summary</h2>";
	$flag=0;	
		if ($txtPrdId != '' ) {
			echo"<table border='0' style='table-layout:fixed'>
					  <col width=120>
					  <col width=250>
					  <col width=150><col width=100>";
			if($productionReq_packdt == 0)
			echo "<col width=100>";
			echo "<col width=60>
					  <col width=100>
					  <col width=100>";
					  
			echo"<tr height='20px;'>";
			echo"  <td bgcolor='#D8D8D8' align='left'><span class='style27'>Item Code</span></td>";
			echo"  <td bgcolor='#D8D8D8' align='left'><span class='style27'>Description</span></td>";
			if($productionReq_packdt == 0)
			echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>From WH</span></td>";
			echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>To WH</span></td>";
			echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>Qty</span></td>";
			if($productionReq_packdt == 0)
			echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>Qty to Transfer</span></td>";
			echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>Unit</span></td>";
			echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>Qty Exists</span></td>";
			echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>Qty Shortage</span></td>";
			echo"</tr>";		  
			
			if($productionReq_packdt == 0){	
			$sub_query2 = " Select ProductionReqRM.ProductionReqRM_ID, ProductionReqRM.Item_CodePacked, ProductionReqRM.Item_Code, Item_Description, ProductionReqRM.Warehouse_Code, ";
			if($transferdone != '') 
				$sub_query2 =	$sub_query2." Sum(ifNull(TransferDt_Quantity,0)) As ProductionReqRM_Quantity, ";			
			else $sub_query2 =	$sub_query2." Sum(ifNull(ProductionReqRM_Quantity,0)) As ProductionReqRM_Quantity, ";  
			$sub_query2 =	$sub_query2." Items.Item_UnitSalesDesc ";
			if($transferdone != '') 
				$sub_query2 =	$sub_query2.",TransferDt_WarehouseFrom ";
				$sub_query2 =	$sub_query2." From Temp_ProductionReqRM As ProductionReqRM Left Join Items on ProductionReqRM.Item_Code = Items.Item_code ";
			if($transferdone != '') 
				$sub_query2 =	$sub_query2."left join temp_transfer on Transfer_Id = '$transferdone' 
											left join temp_transferdt on temp_transferdt.Transfer_Id = temp_transfer.Transfer_Id 
											and temp_transferdt.item_code = ProductionReqRM.Item_Code ";		  
			$sub_query2 =	$sub_query2." Where ProductionReqRM.ProductionReq_ID = '".$txtPrdId."' ".
						  " Group By ProductionReqRM.Item_Code, ProductionReqRM.Warehouse_Code ".
						  " Order By ProductionReqRM.Item_Code, ProductionReqRM.Warehouse_Code ";
			}else if($productionReq_packdt == 1)	
				$sub_query2 = " Select ProductionReqRM.ProductionReqRM_ID, ProductionReqRM.Item_CodePacked, ProductionReqRM.Item_Code, Item_Description, ProductionReqRM.Warehouse_Code, ".
						  " Sum(ifNull(ProductionReqRM_Quantity,0)) As ProductionReqRM_Quantity, Items.Item_UnitSalesDesc ".
						  " From Temp_ProductionReqRM As ProductionReqRM ".
						  " left join items on items.item_code = ProductionReqRM.Item_Code ".
						  " Where ProductionReqRM.ProductionReq_ID = '".$txtPrdId."' ".
						  " Group By ProductionReqRM.Item_Code, ProductionReqRM.Warehouse_Code ".
						  " Order By ProductionReqRM.Item_Code, ProductionReqRM.Warehouse_Code ";
			//echo $sub_query2;
			$sub_result2=mysql_query($sub_query2,$connection) or die(mysql_error());
			$i=0;
			//echo "<input type='hidden' name='txtFromWhCode' id='txtFromWhCode' value='$txtFromWhCode'>";
			while($sub_rows2=mysql_fetch_array($sub_result2)){
				$ct+=1;

				if($ct%2==0)
					$Color="style='background-color:".$grid_color1."'";
				else			
					$Color="style='background-color:".$grid_color2."'";	
							
				$sub_query3  = " Select QtyExistsWSorder('".$sub_rows2[2]."', '".$sub_rows2[4]."', Now(), 0, 'PDT', '', '') QtyExists From Dual ";
				$sub_result3 = selectData($connection, $sub_query3);
				$vItemQtyExists = 0;
				$vItemQtyExists = $sub_result3[0]; 
				 if($$txtFromWhCode == '')		{
					$queryfromWh = "select warehouse from transfersetup";
					$resfromWh = mysql_query($queryfromWh,$connection);
					$rowfromWh = mysql_fetch_row($resfromWh);
					$$txtFromWhCode = $rowfromWh[0];
				} 
				if($transferdone != '' && $$txtFromWhCode == '') $$txtFromWhCode = $sub_rows2[7];
				$itemqty = 'itemqty'.$i;
				$qtytotransfer = 'qtytotransfer'.$i;
				$towharehouse = 'towharehouse'.$i;
				echo "<tr ".$Color." >";
				echo "	<td align='left'><span class='style15'>".$sub_rows2[2]."</span></td>";
				echo "	<td align='left'><span class='style15'>".$sub_rows2[3]."</span></td>";
				if($productionReq_packdt == 0){
				echo "	<td align='left' valign='center'>";
				echo "<input type='text' name='txtFromWhCode[$i]' id='txtFromWhCode[$i]' value='".$$txtFromWhCode."' style='width=:110px;border:none;margin:0 0 8px' class='style15'>";
				echo "<label><span class='style1'><img src='img/btnopen.jpg' title=' Select From Warehouse' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistFromWarehouse($i); ' /> </span></label>";
				echo "</td>";}
				echo "	<td align='left'><span class='style15'>".$sub_rows2[4]."</span>
				<input type='hidden' name='$towharehouse' value='$sub_rows2[4]'></td>";
				echo "	<td align='right'><span class='style15'><input type='text' name='$itemqty' value='".number_format($sub_rows2[5], $DecimalBase)."'  style='width=:90px;border:none;margin:0 0 8px' class='style15'></span></td>";
				if($productionReq_packdt == 0)
				echo "	<td align='left'><span class='style15'><input type='text' name='$qtytotransfer' value='".number_format($sub_rows2[5], $DecimalBase)."'  style='width=:90px;border:none;margin:0 0 8px' class='style15'></span></td>";
				echo "	<td align='center'><span class='style15'>".$sub_rows2[6]."</span></td>";
				echo "	<td align='right'><span class='style15'>".number_format($vItemQtyExists, $DecimalBase)."</span></td>";
				echo "	<td align='right'><span class='style15'>".number_format(($vItemQtyExists - $sub_rows2[5]), $DecimalBase)."</span></td>";
				echo "</tr>";
				$i+=1;						
			}
			if($transferdone!='') $disablebtn = 'disabled';
			else $disablebtn = '';
			if($productionReq_packdt == 0){
			echo "<input type='hidden' name='transferdone' value='$transferdone'>";
			echo "<tr><td colspan='8' align='center'><input type='button' name='but'  onmouseover=\"style.cursor='pointer'\"  onclick='savedata()' value='Create Transfer' $disablebtn></td></tr>";
			}
			echo "</table>";			
					
		}

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

		
echo"   <tr bgcolor='#D8D8D8' height='30'><td colspan='6' align='center'>";


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

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

echo" </table>  ";//end of last table menu


echo"<script type=\"text/javascript\" language=\"javascript\">";
echo"	tabberAutomatic(tabberOptions);";
echo"   vTabIndex = document.getElementById('PTabIndex').value; ";
echo"	if (document.getElementById('tab1-1')) document.getElementById('tab1-1').tabber.tabShow(vTabIndex); ";
echo"</script>";
	
if ($actionmode == "post" && $PrPrdId != '') {
	echo '<script type="text/javascript" language="javascript">';
	
	if ($Login_FastPrint == 1) 
		echo ' PrintProductionReq(\''.$PrPrdId.'\', \''.$PrPrdRef.'\'); ';
		
	echo ' ClearPage1(); ';
	echo '</script>';

}

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

HERE;

?>