<?php

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


include("config.inc.php");
include("Functions_Purchase.php");
include("Forms_DataGrid_ProductionFactory.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_FactoryProduction as loginaccess, ifNull(Login_FastPrint,0) As Login_FastPrint 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");

	
	
//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_Pack,0) As Module_Pack, ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter,
			 ifNull(Module_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt
			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 Currency_code As SetupDftCurrency, Warehouse_code As SetupDftWareHouse From ProductionSetup";
$resultProductionSetup=mysql_query($queryProductionSetup,$connection) or die(mysql_error());
while($rowProductionSetup=mysql_fetch_array($resultProductionSetup)){
	extract($rowProductionSetup);
}


$querydflwh="select default_warehouse_code as defaultwarehouse from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_warehouse_code != '' ";
$resultdflwh=mysql_query($querydflwh,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflwh)){
  extract($rows);
}
$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);
}

$querycurrency="select Currency_code from currency order by currency_code";
$resultcurrency=mysql_query($querycurrency,$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($txtProjectCode)) && $Module_Project == 1)
	$txtProjectCode = $defaultproject;
if ((empty($txtCostCentCode)) && $Module_CostCenter == 1)
	$txtCostCentCode = $defaultcostcent;	

if (empty($txtCurr) )
{	
	if ($SetupDftCurrency != '')
		$txtCurr = $SetupDftCurrency;
	else
		$txtCurr = $base1;
} 
if (empty($txtDate))	
	$txtDate = displayToday();
 
$message = ereg_replace("'"," ",$message);

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">
<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>


<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>

<link type="text/css" href="js/grid/scripts/jquery-ui.css" rel="stylesheet">
<script type="text/javascript" src="js/grid/scripts/jquery-ui.min.js"></script>

<script type="text/javascript" language="javascript">
	$(document).ready(function() { 
		
		$(document).on('focus', '.date', function() {
			$('.date').datepick({showTrigger: '#calImg'});
		});
		
		$(document).on('focusin', '.table-focus-g1', function() { 
			AutoSaveRecordGrid(this.id,'SelectedRec_G1','ModRec_G1','imgSubmit_1');
			selRecordColor(this,'SelectedRec_G1','SelectedRecColor_G1');
		});
		$(document).on('focusin', '.table-focus-g2', function() { 
			AutoSaveRecordGrid(this.id,'SelectedRec_G2','ModRec_G2','imgSubmit_2');
			selRecordColor(this,'SelectedRec_G2','SelectedRecColor_G2');
		});

		//Set Scroll Positions on Page Load
		scrollToPage();
		
		$(window).scroll(function(){
			scrollPage();
		});
		
		//Set Cursor Position After Page Reload
		var NextElement = readCookie('prdtpl-nextcell');
		MoveNextRecord(NextElement);
		eraseCookie('prdtpl-nextcell');
		
		
	});
	
	
</script>

<script type="text/javascript" language="javascript">

function CheckFields(){
  
    x = document.production;
	
	var PrdDate     = x.txtDate.value;
	
	var vmode  = x.mainaction.value;
	var vmode1 = x.actionmode.value;
	
	if (PrdDate=='' )
	{
		alert("Date Column is mandatory!");
		x.txtDate.focus();
		return 0;
	} else if(x.group_code.value ==''){
		alert("Group Code is mandatory!");
		x.group_code.focus();
		return 0;
	}
	 else if(x.subgroup_code.value ==''){
		alert("Sub Group Code is mandatory!");
		x.subgroup_code.focus();
		return 0;
	}
	 else if(x.category_code.value ==''){
		alert("Category Code is mandatory!");
		x.category_code.focus();
		return 0;
	}
		
	
	else
	return 1 ;	
}

function CheckFieldsDtFG(PIndex){
  
    x = document.production;
	
	var PrdItemFG 	 = document.getElementById('itemcodefg['+PIndex+']').value;
	var PrdWarehouseFG = document.getElementById('warehousecodefg['+PIndex+']').value;
	var PrdQtyFG         = document.getElementById('prdqtyfg['+PIndex+']').value;

	
	
	var vmode = x.actionmode.value;
	
	if (PrdQtyFG == '')   PrdQtyFG = 0;
	
	PrdQtyFG = parseFloat(PrdQtyFG);	
	
	
	if (PrdItemFG=='')
	{
		alert("Item is mandatory!");
		document.getElementById('itemcodefg['+PIndex+']').focus();
		return 0;
	}	
	else if (PrdWarehouseFG=='')
	{
		alert("Warehouse is mandatory!");
		document.getElementById('warehousecodefg['+PIndex+']').focus();
		return 0;
	}
	
	else if (PrdQtyFG*1 != PrdQtyFG/1 || PrdQtyFG <= 0  ) {
		alert('Quantity ('+PrdQtyFG+') should be NUMERIC and POSITIVE and GREATER Than Zero. ');
		document.getElementById('prdqtyfg['+PIndex+']').focus();
		return 0;
	}
		
	
	else
	return 1 ;	
}

function CheckFieldsDtSF(PIndex){
  
    x = document.production;
	
	var PrdItemSF	 	 = document.getElementById('itemcodesf['+PIndex+']').value;
	var PrdWarehouseSF 	 = document.getElementById('warehousecodesf['+PIndex+']').value;
	var PrdQtySF      	 = document.getElementById('prdqtysf['+PIndex+']').value;
	var PrdCostSF      = document.getElementById('prdpricesf['+PIndex+']').value;
	
	var vmode = x.actionmode.value;
	
	if (PrdQtySF == '')   PrdQtySF = 0;
	if (PrdCostSF == '')  PrdCostSF = 0;
	
	
	PrdQtySF = parseFloat(PrdQtySF);	
	PrdCostSF  = parseFloat(PrdCostSF);
		
	if (PrdItemSF=='')
	{
		alert("Item is mandatory!");
		document.getElementById('itemcodesf['+PIndex+']').focus();
		return 0;
	}	
	else if (PrdWarehouseSF=='')
	{
		alert("Warehouse is mandatory!");
		document.getElementById('warehousecodesf['+PIndex+']').focus();
		return 0;
	}
	else if (PrdQtySF*1 != PrdQtySF/1 || PrdQtySF <= 0  ) {
		alert('Quantity ('+PrdQtySF+') should be NUMERIC and POSITIVE and GREATER Than Zero. ');
		document.getElementById('prdqtysf['+PIndex+']').focus();
		return 0;
	}
	else if ((PrdCostSF*1 != PrdCostSF/1 || PrdCostSF < 0) ) {
		alert('Cost Price should be a NUMERIC and POSITIVE value');
		document.getElementById('prdpricesf['+PIndex+']').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_ProductionFactory.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_ProductionFactory.php';
	x.submit();
}


function PostChanges() {
	x = document.production;
	var PrdId  = x.txtPrdId.value;
	var vMainMode = x.mainaction.value;
	
	var result = CheckFields();
	
	if (result == 1) {
		if (confirm ( "Are you sure you want to Save current production?"))
		{
			//Save Grid Before Posting	
			var vModRec_G1  = document.getElementById('ModRec_G1').value;
			var vModRec_G2  = document.getElementById('ModRec_G2').value;
			
			if (vModRec_G1 != "") {
				var Obj = document.getElementById('CurRec_G1'+vModRec_G1);
				Obj.style.backgroundColor='#F13A3A';
				alert("Please Submit changes before.");
				
			}
			else if (vModRec_G2 != "") {
				var Obj = document.getElementById('CurRec_G2'+vModRec_G2);
				Obj.style.backgroundColor='#F13A3A';
				alert("Please Submit changes before.");
				
			}	
			else {
			
				if (document.getElementById('btnPost'))
					x.btnPost.disabled = true;
				if (document.getElementById('btnClear'))
					x.btnClear.disabled = true;
				
				x.actionmode.value='post';
				x.action="Form_ProductionFactory_Actions.php?mode=post&mainmode="+vMainMode+"&SPrdId="+PrdId;
				x.submit();
			}	
		}
	}	

}

	
function DeletePrdDt(PrdDtId, ItemPackCode, ItemCode, Option) {

	x = document.production;
	var PrdId  = x.txtPrdId.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_ProductionFactory_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&SPrdId="+PrdId+"&SPrdDtId="+PrdDtId;
		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.txtCurr.value='';
		x.txtNetWeightRM.value='';
		x.txtNetWeightSF.value='';
		x.txtNetWaste.value='';
		x.txtWasteItem.value='';
		x.txtProjectCode.value='';
		x.txtCostCentCode.value='';
		x.txtManualNo.value='';
		
		x.message.value='';
		x.txtPrdCountFG.value='';
		x.txtPrdCountSF.value='';
		
		x.actionmode.value = '';
		x.mainaction.value = '';
	} 
}


function DeleteRecordGridFG(filepath,formname,transid,PrdDtId,index,dftorderby,orderby,morelines,startrange,perpage,direction) {
	x = document.production;
	var vPrdId    = x.txtPrdId.value;
	var vMainMode = x.mainaction.value;
	var vDelMsg = 'Are you sure you want to delete this record?';

		
	if (confirm ( vDelMsg ))
	{
		var xmlhttp = getXMLHttpRequest();	
		$("#Loader1").addClass("ajaxsaving");
		
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var data = $.parseJSON(xmlhttp.responseText);
					
				var msg = data[0].message;
					
				if (msg != "") {
					$("#Loader1").removeClass("ajaxsaving");
					alert(decodeURIComponent(msg));
				} else { 
					$("#Loader1").removeClass("ajaxsaving");
					ReloadGrid(filepath,formname,transid,'datagrid-1',index,dftorderby,'DEL',orderby,morelines,startrange,perpage,0,direction);			
					x.submit();	
				}
			}
		}

		xmlhttp.open("GET","Form_ProductionFactory_Actions.php?mode=deletedtFG&mainmode="+vMainMode+"&SPrdId="+vPrdId+"&SPrdFGId="+PrdDtId);
		xmlhttp.send();
	}	

}


function SubmitRecordGridFG(PIndex,filepath,formname,transid,dftorderby,orderby,morelines,startrange,perpage,direction) {
	
	x = document.production;
		
	var result = 1;
	result = CheckFields();
	
	if (result == 1) {
		result = CheckFieldsDtFG(PIndex);
	}
	
	var PrdFGId   = document.getElementById('prdfgid['+PIndex+']').value;
	if (PrdFGId == '') vMode = 'submitrecord-ajax';	
	else vMode = 'editdt-ajax';	
	
	
	var  the_data = 'mode='+vMode+
					'&mainmode='+x.mainaction.value+
					'&SItemType=FG'+
					'&SPrdId='+x.txtPrdId.value+
					'&PPrdId='+x.txtPrdId.value+
					'&PPrdDate='+x.txtDate.value+
					'&PPrdCur='+x.txtCurr.value+
					'&PPrdRemark='+encodeURIComponent(x.txtRemark.value)+
					'&PPrdManualNo='+encodeURIComponent(x.txtManualNo.value)+
					'&PPrdProjectCode='+x.txtProjectCode.value+
					'&PPrdCostCode='+x.txtCostCentCode.value+
					'&group_code='+encodeURIComponent(x.group_code.value)+'&subgroup_code='+encodeURIComponent(x.subgroup_code.value)+'&category_code='+encodeURIComponent(x.category_code.value)+
					'&txtNetWeightRM='+x.txtNetWeightRM.value+'&txtNetWeightSF='+x.txtNetWeightSF.value+'&txtNetWaste='+x.txtNetWaste.value+
					'&SPrdFGId='+document.getElementById('prdfgid['+PIndex+']').value+
					'&lstWarehouse='+document.getElementById('warehousecodefg['+PIndex+']').value+
					'&txtItemCode='+document.getElementById('itemcodefg['+PIndex+']').value+
					'&txtItemCreadted='+document.getElementById('itemcreatedfg['+PIndex+']').value+
					'&txtPrdQtyFG='+document.getElementById('prdqtyfg['+PIndex+']').value+
					'&txtPrdPriceFG='+document.getElementById('prdcostpricefg['+PIndex+']').value+
					'&txtPrdNetFG='+document.getElementById('totalprice['+PIndex+']').value+
					'&txtPrdNetWeightFG='+document.getElementById('netweightfg['+PIndex+']').value+
					'&txtPrdProjectCodedt='+document.getElementById('projectcodedt['+PIndex+']').value+
					'&txtPrdCostcentCodedt='+document.getElementById('costcentcodedt['+PIndex+']').value;
		
	
	if (result == 1) {
		var xmlhttp = getXMLHttpRequest();	
		var getdate = new Date();  //Used to prevent caching during ajax call
  
		$("#Loader1").addClass("ajaxsaving");
		//$('#datagrid :input').attr('disabled', true);
		
		var SubBtnID = 'imgSubmit_1['+PIndex+']';
		if (document.getElementById(SubBtnID))	document.getElementById(SubBtnID).disabled = true;
		
		
		if(xmlhttp) {
				
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					var data = $.parseJSON(xmlhttp.responseText);
					
					var msg = data[0].message;
					
					if (msg != "") {
						$("#Loader1").removeClass("ajaxsaving");
						if (document.getElementById(SubBtnID))	document.getElementById(SubBtnID).disabled = false;
						alert(decodeURIComponent(msg));
					} else {	
						if (transid == ""){
							transid = data[0].transid;
							
							x.txtPrdId.value = transid;
							x.submit();
						} 
							
						var index = parseInt(PIndex) + 1;
						var nextcell = 'itemcodefg['+index+']';
						
						createCookie('prdtpl-nextcell',nextcell);
						
						ReloadGrid(filepath,formname,transid,'datagrid-1',PIndex,dftorderby,'ADD',orderby,morelines,startrange,perpage,0,direction,function() {
							MoveNextRecord(nextcell);
							document.getElementById('ModRec_G1').value = "";
						});
						x.submit();
						
						
					}
				}
			}
			
			// adds  a header to tell the PHP script to recognize the data as is sent via POST
			//xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			//xmlhttp.send(the_data);
			
			xmlhttp.open("GET","Form_ProductionFactory_Actions.php?"+the_data);
			xmlhttp.send();
			
		}
	}
}


function DeleteRecordGridSF(filepath,formname,transid,PrdDtId,index,dftorderby,orderby,morelines,startrange,perpage,direction) {
	x = document.production;
	var vPrdId    = x.txtPrdId.value;
	var vMainMode = x.mainaction.value;
	var vDelMsg = 'Are you sure you want to delete this record?';

		
	if (confirm ( vDelMsg ))
	{
		var xmlhttp = getXMLHttpRequest();	
		$("#Loader2").addClass("ajaxsaving");
		
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var data = $.parseJSON(xmlhttp.responseText);
					
				var msg = data[0].message;
					
				if (msg != "") {
					$("#Loader2").removeClass("ajaxsaving");
					alert(decodeURIComponent(msg));
				} else { 
					$("#Loader2").removeClass("ajaxsaving");
					ReloadGrid(filepath,formname,transid,'datagrid-2',index,dftorderby,'DEL',orderby,morelines,startrange,perpage,0,direction);	
					x.submit();	
				}
			}
		}

		xmlhttp.open("GET","Form_ProductionFactory_Actions.php?mode=deletedtSF&mainmode="+vMainMode+"&SPrdId="+vPrdId+"&SPrdSFId="+PrdDtId);
		xmlhttp.send();
	}	

}


function SubmitRecordGridSF(PIndex,filepath,formname,transid,dftorderby,orderby,morelines,startrange,perpage,direction) {
	
	x = document.production;
	
	
	var result = 1;
	result = CheckFields();
	
	if (result == 1) {
		result = CheckFieldsDtSF(PIndex);
	}
	
	var SPrdSFId   = document.getElementById('prdsfid['+PIndex+']').value;
	vMode = 'editdt-ajax';	
	
	var  the_data = 'mode='+vMode+
					'&mainmode='+x.mainaction.value+
					'&SItemType=SF'+
					'&SPrdId='+x.txtPrdId.value+
					'&PPrdId='+x.txtPrdId.value+
					'&PPrdDate='+x.txtDate.value+
					'&PPrdCur='+x.txtCurr.value+
					'&PPrdRemark='+encodeURIComponent(x.txtRemark.value)+
					'&PPrdManualNo='+encodeURIComponent(x.txtManualNo.value)+
					'&PPrdProjectCode='+x.txtProjectCode.value+
					'&PPrdCostCode='+x.txtCostCentCode.value+
					'&txtNetWeightRM='+x.txtNetWeightRM.value+'&txtNetWeightSF='+x.txtNetWeightSF.value+'&txtNetWaste='+x.txtNetWaste.value+
					'&SPrdSFId='+document.getElementById('prdsfid['+PIndex+']').value+
					'&lstWarehouse='+document.getElementById('warehousecodesf['+PIndex+']').value+
					'&txtItemCode='+document.getElementById('itemcodesf['+PIndex+']').value+
					'&txtPrdWeightSF='+document.getElementById('prdweightsf['+PIndex+']').value+
					'&txtPrdQtySF='+document.getElementById('prdqtysf['+PIndex+']').value+
					'&txtPrdPriceSF='+document.getElementById('prdpricesf['+PIndex+']').value+
					'&txtPrdProjectCodedt2='+document.getElementById('projectcodedt2['+PIndex+']').value+
					'&txtPrdCostcentCodedt2='+document.getElementById('costcentcodedt2['+PIndex+']').value+
					'&txtgroup_code='+document.getElementById('group_code['+PIndex+']').value+
					'&txtsubgroup_code='+document.getElementById('subgroup_code['+PIndex+']').value+
					'&txtcategory_code='+document.getElementById('category_code['+PIndex+']').value;
		
	
	if (result == 1) {
		var xmlhttp = getXMLHttpRequest();	
		var getdate = new Date();  //Used to prevent caching during ajax call
  
		$("#Loader2").addClass("ajaxsaving");
		//$('#datagrid :input').attr('disabled', true);
		
		var SubBtnID = 'imgSubmit_2['+PIndex+']';
		if (document.getElementById(SubBtnID))	document.getElementById(SubBtnID).disabled = true;
		
		
		if(xmlhttp) {
			
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					var data = $.parseJSON(xmlhttp.responseText);
					
					var msg = data[0].message;
					
					if (msg != "") {
						$("#Loader2").removeClass("ajaxsaving");
						if (document.getElementById(SubBtnID))	document.getElementById(SubBtnID).disabled = false;
						alert(decodeURIComponent(msg));
					} else {	
						if (transid == ""){
							transid = data[0].transid;
							
							x.txtPrdId.value = transid;
							x.submit();
						} 
							
						var index = parseInt(PIndex) + 1;
						var nextcell = 'itemcoderm['+index+']';
						
						createCookie('prdtpl-nextcell',nextcell);
						
						ReloadGrid(filepath,formname,transid,'datagrid-2',PIndex,dftorderby,'ADD',orderby,morelines,startrange,perpage,0,direction,function() {
							MoveNextRecord(nextcell);
							document.getElementById('ModRec_G2').value = "";
						});
						
						
					}
				}
			}
			
			// adds  a header to tell the PHP script to recognize the data as is sent via POST
			//xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			//xmlhttp.send(the_data);
			
			xmlhttp.open("GET","Form_ProductionFactory_Actions.php?"+the_data);
			xmlhttp.send();
			
		}
	}
}
function GetItemInfo(index, dec){
	
		var xmlhttp = getXMLHttpRequest();	
		var getdate = new Date();  //Used to prevent caching during ajax call
		var x = document.production;
		$("#Loader1").addClass("ajaxsaving");
				
		if(xmlhttp) {
				
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					var data = xmlhttp.responseText.split("[BRK]");
					
					var msg = data[0];
					var netweight = data[1];
					var avgCost = data[2];
					if (msg != "") {
						$("#Loader1").removeClass("ajaxsaving");
						alert(decodeURIComponent(msg));
					} else {	
						$("#Loader1").removeClass("ajaxsaving");
						document.getElementById("netweightfg["+index+"]").value = netweight;	
						document.getElementById("prdcostpricefg["+index+"]").value = avgCost;							
						var rmnetweight = document.getElementById("txtNetWeightRM").value;
						if(rmnetweight == '')  rmnetweight=0;
						rmnetweight = parseFloat(rmnetweight+ netweight); 
						document.getElementById("txtNetWeightRM").value = rmnetweight;	
						if(document.getElementById("prdqtyfg["+index+"]").value == '')	
							document.getElementById("prdqtyfg["+index+"]").value = 1;
						getAmountFG(dec,index);
						if(document.getElementById("projectcodedt["+index+"]").value == '')	
							document.getElementById("projectcodedt["+index+"]").value = document.getElementById("txtProjectCode").value;
						if(document.getElementById("costcentcodedt["+index+"]").value == '')	
							document.getElementById("costcentcodedt["+index+"]").value = document.getElementById("txtCostCentCode").value;
						
					}
				}
			}
			var the_data = "mode=&mainmode=getiteminfo&txtItemCode="+document.getElementById("itemcodefg["+index+"]").value+"&txtDate="+x.txtDate.value+
						"&txtCurr="+x.txtCurr.value;
			// adds  a header to tell the PHP script to recognize the data as is sent via POST
			//xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			//xmlhttp.send(the_data);
			
			xmlhttp.open("GET","Form_ProductionFactory_Actions.php?"+the_data);
			xmlhttp.send();
			
		}
}
function SearchForRef(){
    //ClearForm('All');
    x = document.production;
    win = window.open('Form_ProductionFactorySearch.php', 'Form_ProductionFactorySearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=880,height=580,top=100,left=10');		
	win.creator = self;
	win.focus();		
			
}
function showlistItems(str){
	var vDate, vItemCode;
	x = document.production;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 850) / 2;
  
	vDate 	   = x.txtDate.value;
	vItemCode  = encodeURIComponent(document.getElementById('txtWasteItem').value);
  
	window.open('List_SorItems.php?frm=15&index=&PItem_Code='+vItemCode+'&ItemType=All&TransDate='+vDate,'List_SorItems','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}
function showlistItemsFG(str,PIndex){
	var vDate, vItemCode;
	x = document.production;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 850) / 2;
  
	vDate 	   = x.txtDate.value;
	vItemCode  = encodeURIComponent(document.getElementById('itemcodefg['+PIndex+']').value);
  
	window.open('List_SorItems.php?frm=14&index='+PIndex+'&PItem_Code='+vItemCode+'&ItemType=All&TransDate='+vDate,'List_SorItems','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}

function showlistItemsDescFG(str,PIndex){
	var vDate, vItemCode;
	x = document.production;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 850) / 2;
  
	vDate 	   = x.txtDate.value;
	vItemDesc  = encodeURIComponent(document.getElementById('itemdescriptionfg['+PIndex+']').value);
	
	window.open('List_SorItems.php?frm=8&index='+PIndex+'&PItem_Description='+vItemDesc+'&ItemType=All&TransDate='+vDate,'List_SorItems','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}

function showlistWarehouseFG(PIndex) {
	XPos = (screen.availHeight - 550) / 2;
	YPos = (screen.availWidth - 850) / 2;
	
	var vWarehouseCode = encodeURIComponent(document.getElementById('warehousecodefg['+PIndex+']').value);
	
	window.open('List_SorWarehouse.php?frm=3&index='+PIndex+'&PWarehouse_Code='+vWarehouseCode,'List_SorWarehouse','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}



function showlistItemsRM(str,PIndex){
	var vDate, vItemCode;
	x = document.production;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 850) / 2;
  
	vDate 	   = x.txtDate.value;
	vItemCode  = encodeURIComponent(document.getElementById('itemcoderm['+PIndex+']').value);
  
	window.open('List_SorItems.php?frm=9&index='+PIndex+'&PItem_Code='+vItemCode+'&ItemType=All&TransDate='+vDate,'List_SorItems','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}

function showlistWarehouseSF(PIndex) {
	XPos = (screen.availHeight - 550) / 2;
	YPos = (screen.availWidth - 850) / 2;
	
	var vWarehouseCode = encodeURIComponent(document.getElementById('warehousecodesf['+PIndex+']').value);
	
	window.open('List_SorWarehouse.php?frm=12&index='+PIndex+'&PWarehouse_Code='+vWarehouseCode,'List_SorWarehouse','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}

function getAmountFG(dec, index){
	var qty = document.getElementById("prdqtyfg["+index+"]").value;
	var price = document.getElementById("prdcostpricefg["+index+"]").value;
	if(qty=='') qty=0;
	if(price=='') price=0;
	var totprice = qty*price;
	document.getElementById("totalprice["+index+"]").value = roundNumber(totprice, dec);
}
function getAmountSF(dec, index){
	var qty = document.getElementById("prdqtysf["+index+"]").value;
	var price = document.getElementById("prdpricesf["+index+"]").value;
	if(qty=='') qty=0;
	if(price=='') price=0;
	var totprice = qty*price;
	document.getElementById("prdnetsf["+index+"]").value = roundNumber(totprice, dec);
}
function SearchForPending(){
     x = document.production;
    win = window.open('Form_ProductionFactorySearchPending.php', 'Form_ProductionFactorySearchPending', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=680,height=560,top=100');		
	win.creator = self;
	win.focus();		
			
}


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

function CalcWeight(index, dec, rmid, prdsfid){
	var weightsf = document.getElementById("prdweightsf["+index+"]").value;
	var txtNetWeightRM = document.getElementById("txtNetWeightRM").value;
		
	var xmlhttp = getXMLHttpRequest();	
	var getdate = new Date();  //Used to prevent caching during ajax call
	var x = document.production;
	$("#Loader1").addClass("ajaxsaving");
			
	if(xmlhttp) {
			
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var data = xmlhttp.responseText.split("[BRK]");
				
				var msg = data[0];
				var netweight = data[1];
				if (msg != "") {
					$("#Loader1").removeClass("ajaxsaving");
					alert(decodeURIComponent(msg));
				} else {	
					$("#Loader1").removeClass("ajaxsaving");
					var txtNetWeightSF = parseFloat(netweight) + parseFloat(weightsf);
					document.getElementById("txtNetWeightSF").value = parseFloat(txtNetWeightSF);
					document.getElementById("txtNetWaste").value = parseFloat(txtNetWeightRM - document.getElementById("txtNetWeightSF").value);
					var rmindex = "indexed"+rmid;
					rmindex = document.getElementById(rmindex).value;
					var rmcost = document.getElementById("prdcostpricefg["+rmindex+"]").value; 
					document.getElementById("prdpricesf["+index+"]").value = roundNumber(parseFloat(rmcost*weightsf/txtNetWeightRM),dec);
					getAmountSF(dec, index);												
					
				}
			}
		}
		var the_data = "mode=&mainmode=CalcWeight&prdsfid="+prdsfid+"&txtNetWeightRM="+txtNetWeightRM+
					"&txtPrdId="+x.txtPrdId.value;
		// adds  a header to tell the PHP script to recognize the data as is sent via POST
		//xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		//xmlhttp.send(the_data);
		
		xmlhttp.open("GET","Form_ProductionFactory_Actions.php?"+the_data);
		xmlhttp.send();
		
	}
	
}

function showlistProject(str){

	vProjectCode = encodeURIComponent(document.getElementById('txtProjectCode').value);
	window.open('List_SorProject.php?frm=32&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=32&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 showlistProjectDt(str,PIndex){
	XPos = (screen.availHeight - 550) / 2;
	YPos = (screen.availWidth - 850) / 2;
	
	vProjectCode = encodeURIComponent(document.getElementById('projectcodedt['+PIndex+']').value);
	
	window.open('List_SorProject.php?frm=33&index='+PIndex+'&item='+str+'&PProject_Code='+vProjectCode,'List_SorProject','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,left='+YPos+',top='+XPos);
}

function showlistCostcenterDt(str,PIndex){
	XPos = (screen.availHeight - 550) / 2;
	YPos = (screen.availWidth - 850) / 2;
	
	vCostcentCode = encodeURIComponent(document.getElementById('costcentcodedt['+PIndex+']').value);
	
	window.open('List_SorCostcenter.php?frm=33&index='+PIndex+'&item='+str+'&PCostcent_Code='+vCostcentCode,'List_SorCostcenter','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,left='+YPos+',top='+XPos);
}
function showlistcategory(str, index){
	window.open('List_Categories.php?str='+str+'&index='+index,'categorywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function showlistsubgroups(str, index){
	window.open('List_SubGroup.php?str='+str+'&index='+index,'List_SubGroup','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function getWasteItem(){
	var x = document.production;
	if(x.txtNetWaste.value > 0 && x.txtWasteItem.value != ''){
		var xmlhttp = getXMLHttpRequest();	
		var getdate = new Date();  //Used to prevent caching during ajax call
		
		$("#Loader1").addClass("ajaxsaving");
			
	if(xmlhttp) {
			
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var data = xmlhttp.responseText.split("[BRK]");
				
				var msg = data[0];
				var netweight = data[1];
				if (msg != "") {
					$("#Loader1").removeClass("ajaxsaving");
					alert(decodeURIComponent(msg));
				} else {	
					$("#Loader1").removeClass("ajaxsaving");
					x.txtWasteItem.value = '';
					x.txtWasteItemdesc.value = '';	
					x.submit();
					
				}
			}
		}
		var the_data = "mode=&mainmode=getWasteItem&PPrdDate="+x.txtDate.value+"&txtWasteItem="+x.txtWasteItem.value+"&txtNetWaste="+x.txtNetWaste.value+"&txtNetWeightRM="+x.txtNetWeightRM.value+
					   "&PPrdCur="+x.txtCurr.value+"&SPrdId="+x.txtPrdId.value;
				
		xmlhttp.open("GET","Form_ProductionFactory_Actions.php?"+the_data);
		xmlhttp.send();
		
	}	
		
	}
	
	
}

function showlistgroups(str, index){
	window.open('List_Grouping.php?str='+str+'&index='+index,'List_Grouping','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
</script>
<title>Factory Production</title>


<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'>

HERE;

if ($actionmode != "cancel" && $txtPrdId != '') {
	// Read From Tables For Selected Record				 
	$query = " Select productionFactory_id, productionFactory_reference, Date_Format(productionFactory_date,'%d/%m/%Y'), productionFactory_remark, productionFactory.Currency_Code,   ".
			 " ifnull(totnetweightrm,0), ifnull(totnetweightsf,0), ifnull(totwaste,0), productionfactory_manualno, productionFactory.project_code, productionFactory.costcent_code, ".
			 " wasteItem_Code, item_description, productionFactory.item_group, productionFactory.item_subgroup, productionFactory.item_category ".
	         " From temp_productionFactory as productionFactory ".
			 " left join items on items.item_code = wasteItem_Code ".
	         " Where productionFactory_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];
	$txtCurr       	= $rows[4];
	$txtNetWeightRM = $rows[5];
	$txtNetWeightSF = $rows[6];
	$txtNetWaste    = $rows[7];
	$txtManualNo    = $rows[8];
	$txtProjectCode = $rows[9];
	$txtCostCentCode = $rows[10];
	$txtWasteItem	= $rows[11];
	$txtWasteItemdesc = $rows[12];
	$group_code 	= $rows[13];
	$subgroup_code 	= $rows[14];
	$category_code 	= $rows[15];
	
	$query = " Select Count(*) FROM temp_productionFactoryFG ".
			 " WHERE productionFactory_id = ".$txtPrdId;
	$result = selectData($connection, $query);
	$txtPrdCountFG = $result[0];
	if($txtPrdCountFG == '') $txtPrdCountFG = 0;
	
	$query = " Select Count(*) FROM temp_productionFactorySF ".
			 " WHERE productionFactory_id = ".$txtPrdId;
	$result = selectData($connection, $query);
	$txtPrdCountSF = $result[0];
	if($txtPrdCountSF == '') $txtPrdCountSF = 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 Factory</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' id='btnCancel' name='btnCancel' onclick='CancelPage();return false;' title='Cancel'><span><span>Cancel</span></span></button>";				

if ($txtPrdId != '')
	echo" <button type='button' id='btnPost' name='btnPost' onclick='PostChanges();return false;' title='Save Changes'><span><span>Save</span></span></button>";


if ($txtPrdId == ''){
	echo" <button type='button' id='btnSearch' name='btnSearch' onclick='SearchForRef();return false;' title='Search By Reference'><span><span>Search</span></span></button>";
	echo" <button type='button' id='btnPending' name='btnPending' onclick='SearchForPending();return false;' title='Pending'><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'>";	


print <<<HERE
	
		<table border="0" style='table-layout:fixed'>
		  <col width=90>
		  <col width=120>
		  <col width=60>
		  <col width=120>
		  <col width=200>
		  <col width=250>

		<tr bgcolor="#F7F7F7" >
          <td valign="center" align='left' ><span class="style1">Reference&nbsp;<span class="style16">*</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='txtPrdCountSF' value='$txtPrdCountSF' >
			<input type='hidden' name='txtPrdId' value='$txtPrdId' >
			<input type="hidden" name="txtRef" value="$txtRef" >
		  </td>
		  <td align="left"><span class="style1">Date&nbsp;<span class="style16">*</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>
						   
HERE;



echo"     <td align='right' ><span class='style1'>Currency&nbsp;<span class='style16'>*</span></span></td>";
echo"     <td ><span class='style1'><select name='txtCurr' id='txtCurr' style='width:80px;'>";
		  echo"<option></option>";
		  while($curf=mysql_fetch_row($resultcurrency)){
		  echo"<option ";
			if ($txtCurr==$curf[0])
				echo " selected ";
		    echo" value='$curf[0]'>$curf[0] </option>";
		  }
		  echo"</select></span></td>";	  
echo"   </tr>";

echo"   <tr bgcolor='#F7F7F7' >
		  <td align='left' ><span class='style1'>Remark</span></td><td colspan='4' > <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'>&nbsp;</span></td>";
echo"   </tr>";	


echo"   <tr bgcolor='#F7F7F7' >
		  <td align='left' ><span class='style1'>Total Raw Material Net Weight</span></td><td colspan='1' > <span class='style1'>
		  <input type='text' name='txtNetWeightRM' id='txtNetWeightRM' value='".$txtNetWeightRM."'  style='width:120px;' readonly ></span></td>";
echo" 	  <td align='left'><span class='style1'>&nbsp;</span></td>";
echo "<td align='left' ><span class='style1'>Total Semi Finished Net Weight</span></td><td colspan='1' > <span class='style1'>
		  <input type='text' name='txtNetWeightSF' id='txtNetWeightSF' value='".$txtNetWeightSF."'  style='width:120px;' readonly></span></td>";
echo "<td align='left' ><span class='style1'>Waste</span><span class='style1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		  <input type='text' name='txtNetWaste' id='txtNetWaste' value='".$txtNetWaste."'  style='width:120px;' readonly ></span> &nbsp;&nbsp;&nbsp; ";
echo"</td>  </tr>";	

echo"   <tr bgcolor='#F7F7F7' >";
if ($Module_Project	== 1) {
	echo "<td align='left' ><span class='style1'>Project&nbsp;<span class='style16'>*</span></span></td>
	      <td align='left' colspan='2'> <span class='style1'>
		    <input type='text' name='txtProjectCode' id='txtProjectCode' value='$txtProjectCode' style='width:120px;' maxlength='20' 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='3'><input type='hidden' name='txtProjectCode' id='txtProjectCode' value='' /></td>";
}	

if ($Module_CostCenter == 1 ) {		  
	echo" <td align='left' ><span class='style1'>Costcenter&nbsp;<span class='style16'>*</span></span></td>";		
	echo" <td align='left' colspan='1'><span class='style1'>
		    <input type='text' name='txtCostCentCode' id='txtCostCentCode' value='$txtCostCentCode' style='width:139px;' maxlength='20' 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='2'><input type='hidden' name='txtCostCentCode' id='txtCostCentCode' value='' /></td>";
}			


echo"   <td align='left' valign='center'><span class='style1'>Manual No</span>&nbsp;
		<input type='text' name='txtManualNo' value='".htmlspecialchars($txtManualNo, ENT_QUOTES)."'  style='width:120px;' maxlength='20' ></td>";
echo "</tr>";

echo"   <tr bgcolor='#F7F7F7' height='30px' ><td>";
echo "<span class='style1'>Waste Item</span></td><td  colspan='5'><span class='style1'>
		  <input type='text' name='txtWasteItem' id='txtWasteItem' value='".$txtWasteItem."'    maxlength='20' style='font-size:12px; width:130px; height:20px;' readonly >
		  <label><span><img src='img/openlist.png' title='Select Item' id='lstItemCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItems(1); ' style='vertical-align:bottom;'/></span></label></span>
		  <input type='text' name='txtWasteItemdesc' id='txtWasteItemdesc' value='".$txtWasteItemdesc."'   maxlength='20' style='font-size:12px; width:180px; height:20px;' readonly >";	
echo" &nbsp;&nbsp;&nbsp;<button type='button' id='btnWaste' name='btnWaste' onclick='getWasteItem();return false;' title='Add Item'><span><span>Add Item</span></span></button>";		  
echo "</td></tr>";		  

echo"   <tr bgcolor='#F7F7F7' height='30px' ><td><span class='style1'>Item Group</span></td>".
		"<td ><input type='text' name='group_code' value='$group_code' readonly style='width:120px;' >
		<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Group ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistgroups('9','');\"  /></span></label>
		</td><td></td>";
echo "<td><span class='style1'>Item SubGroup</span></td>
	  <td><input type='text' name='subgroup_code' value='$subgroup_code' readonly style='width:120px;'>
	  <label><span class='style1'><img src='img/btnopen.jpg' title=' Select SubGroup ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistsubgroups('8','');\"  /></span></label>
	  </td>";
echo "<td><span class='style1'>Category </span> &nbsp;&nbsp;
	<input type='text' name='category_code' value='$category_code'  style='width:120px;height:20px;' readonly>
	<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Category ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistcategory('6','');\"  /></span></label>
	</td>";
	  
echo "</tr>";		  

$Parameters = array();
$Parameters['DecimalBase'] = $DecimalBase;
$Parameters['Base1'] = $base1;
$Parameters['Base2'] = $base2;
$Parameters['txtDate'] 	  = $txtDate;
$Parameters['DefaultCur'] = $SetupDftCurrency;

$Parameters['SetupDftWareHouse'] = $SetupDftWareHouse;
$Parameters['defaultwarehouse']  = $defaultwarehouse;
$Parameters['Module_ProjectDt'] = $Module_ProjectDt;
$Parameters['Module_CostCenterDt'] = $Module_CostCenterDt;
$_SESSION['gprdtpl_parameters']  = $Parameters;




//***********Production Factory Raw Material*******************
		  
echo"	<tr bgcolor='#D8D8D8' height='20'>";
echo"  		<td align='center' colspan='6'><span class='style16'>Raw Material</span></td>";
echo"	</tr>";
echo"   <tr><td colspan='6' valign='top'>";
echo"	<div id='datagrid-1' class='grid' style='width:1090px;height:125px;' >";
//echo"	<div id='Loader' class=''><div></div></div>";

//Show Items Grid
ShowProdFacFGGrid($connection,'PRD-FAC-1',$txtPrdId,$_SESSION['gprdtpl_parameters'],$_SESSION['gprdtpl_arrayaccess'],'productionFactoryfg_id');

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


//***********Production Factory Semi Finished*******************
		  
echo"<tr bgcolor='#D8D8D8' height='20'>";
echo"  <td align='center' colspan='6'><span class='style16'>Semi Finished</span></td>";
echo"</tr>";
echo"   <tr><td colspan='6' valign='top'>";
echo"	<div id='datagrid-2' class='grid' style='width:1090px;height:400px;' >";
//echo"	<div id='Loader' class=''><div></div></div>";

//Show Items Grid
ShowProdFacSFGrid($connection,'PRD-FAC-2',$txtPrdId,$_SESSION['gprdtpl_parameters'],$_SESSION['gprdtpl_arrayaccess'],'productionFactorysf_id');

echo"	  </div>"; 
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
	
	
if ($actionmode == "post" && $PrPrdId != '') {
	echo '<script type="text/javascript" language="javascript">';
	
	//if ($Login_FastPrint == 1) 
		//echo ' PrintProduction(\''.$PrPrdId.'\', \''.$PrPrdRef.'\'); ';
		
	echo ' ClearPage1(); ';
	echo '</script>';

}

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

HERE;

?>