<?php

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


include("config.inc.php");
include("Functions_Purchase.php");
include("Forms_DataGrid.php");


$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");


$querylog="SELECT FI_Production as loginaccess, ifNull(FI_ProductionApp,0) As FI_ProductionApp, ifNull(Login_FastPrint,0) As Login_FastPrint, FI_ShowCostPrice as FI_ShowCostPrice 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_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt, ".
			 " ifNull(Module_ExpireDate,0) As Module_ExpireDate ".
			 " 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, Currency_Code as SetupDftCurrency 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 ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' and default_warehouse_code != '' ";
$resultdflwh=mysql_query($querydflwh,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflwh)){
  extract($rows);
}

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

$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('prd-nextcell');
		MoveNextRecord(NextElement);
		eraseCookie('prd-nextcell');
		
		
	});
	
	
</script>

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

function CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost){
  
    x = document.production;
	
	var PrdDate     = x.txtDate.value;
	var PrdCurr     = x.txtCurr.value;
	var PrdProject  = x.txtProjectCode.value;
	var PrdCostCenter  = x.txtCostCentCode.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 (PrdCurr=='' )
	{
		alert("Currency Column is mandatory!");
		x.txtCurr.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 CheckFieldsDtFG(PIndex,ItemExpire,ModuleExpireDate,ItemWithSerial,ModuleSerialNo){
  
    x = document.production;
	
	var PrdDtItem 	   = document.getElementById('itemcodefg['+PIndex+']').value;
	var PrdDtWarehouse = document.getElementById('warehousecodefg['+PIndex+']').value;
	var PrdDtQty       = document.getElementById('prddtqtyfg['+PIndex+']').value;
	var PrdDtPrice     = document.getElementById('costpricefg['+PIndex+']').value;
	
	var PrdDtExpireDate = document.getElementById('expiredatefg['+PIndex+']').value;
	var PrdDtBatchNo    = document.getElementById('batchnofg['+PIndex+']').value;
	
	
	var vmode = x.actionmode.value;
	
	if (PrdDtPrice == '')   PrdDtPrice = 0;
	if (PrdDtQty == '')     PrdDtQty = 0;
	
	PrdDtQty     = parseFloat(PrdDtQty);	
	
	
	if (PrdDtItem=='')
	{
		alert("Item is mandatory!");
		document.getElementById('itemcodefg['+PIndex+']').focus();
		return 0;
	}	
	else if (PrdDtWarehouse=='')
	{
		alert("Warehouse is mandatory!");
		document.getElementById('warehousecodefg['+PIndex+']').focus();
		return 0;
	}
	else if (PrdDtQty*1 != PrdDtQty/1   ) {
		alert('Quantity ('+PrdDtQty+') should be NUMERIC and POSITIVE and GREATER Than Zero. ');
		document.getElementById('prddtqtyfg['+PIndex+']').focus();
		return 0;
	}
	else if ((PrdDtPrice*1 != PrdDtPrice/1 || PrdDtPrice < 0) ) {
		alert('Cost Price should be a NUMERIC and POSITIVE value');
		document.getElementById('costpricefg['+PIndex+']').focus();
		return 0;
	}
	else if (ItemExpire == 1 && ModuleExpireDate==1 && PrdDtExpireDate == '' ) {
		alert('Item Expire Date is mandatory.');
		document.getElementById('expiredatefg['+PIndex+']').focus();
		return 0;
	}
	else if (ItemExpire == 1 && ModuleExpireDate==1 && PrdDtBatchNo == '' ) {
		alert('Item Batch No is mandatory.');
		document.getElementById('batchnofg['+PIndex+']').focus();
		return 0;
	}
	
		
	
	else
	return 1 ;	
}

function CheckFieldsDtRM(PIndex,ItemExpire,ModuleExpireDate,ItemWithSerial,ModuleSerialNo){
  
    x = document.production;
	
	var PrdDtItem 	   = document.getElementById('itemcoderm['+PIndex+']').value;
	var PrdDtWarehouse = document.getElementById('warehousecoderm['+PIndex+']').value;
	var PrdDtQty       = document.getElementById('prddtqtyrm['+PIndex+']').value;
	var PrdDtPrice     = document.getElementById('costpricerm['+PIndex+']').value;
	
	var PrdDtExpireDate = document.getElementById('expiredaterm['+PIndex+']').value;
	var PrdDtBatchNo    = document.getElementById('batchnorm['+PIndex+']').value;
	
	
	var vmode = x.actionmode.value;
	
	if (PrdDtPrice == '')   PrdDtPrice = 0;
	if (PrdDtQty == '')     PrdDtQty = 0;
	
	PrdDtQty     = parseFloat(PrdDtQty);	
	
	
	if (PrdDtItem=='')
	{
		alert("Item is mandatory!");
		document.getElementById('itemcoderm['+PIndex+']').focus();
		return 0;
	}	
	else if (PrdDtWarehouse=='')
	{
		alert("Warehouse is mandatory!");
		document.getElementById('warehousecoderm['+PIndex+']').focus();
		return 0;
	}
	else if (PrdDtQty*1 != PrdDtQty/1  ) {
		alert('Quantity ('+PrdDtQty+') should be NUMERIC and POSITIVE and GREATER Than Zero. ');
		document.getElementById('prddtqtyrm['+PIndex+']').focus();
		return 0;
	}
	else if ((PrdDtPrice*1 != PrdDtPrice/1 || PrdDtPrice < 0) ) {
		alert('Cost Price should be a NUMERIC and POSITIVE value');
		document.getElementById('costpricerm['+PIndex+']').focus();
		return 0;
	}
	else if (ItemExpire == 1 && ModuleExpireDate==1 && PrdDtExpireDate == '' ) {
		alert('Item Expire Date is mandatory.');
		document.getElementById('expiredaterm['+PIndex+']').focus();
		return 0;
	}
	else if (ItemExpire == 1 && ModuleExpireDate==1 && PrdDtBatchNo == '' ) {
		alert('Item Batch No is mandatory.');
		document.getElementById('batchnorm['+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_Production.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_Production.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 permenantly?"))
	{
		x.action="Form_Production_Actions.php?mode=cancel&mainmode=&SPrdId="+PrdId;
		x.submit();
	}
    
}


function PostChanges(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost) {
	x = document.production;
	var PrdId  = x.txtPrdId.value;
	var vMainMode = x.mainaction.value;
	
	var result = CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost);
	
	if (document.getElementById('txtPrdCountFG').value == 0 || document.getElementById('txtPrdCountFG').value == '') {
		alert('Save not allowed. Please add at least one item (Finished Good).');
	}
	else if (document.getElementById('txtPrdCountRM').value == 0 || document.getElementById('txtPrdCountRM').value == '') {
		alert('Save not allowed. Please add at least one item (Raw Material).');
	}
	else
	{
		if (result == 1) {
			if (confirm ( "Are you sure you want to Save current production?"))
			{
				//Save Grid Before Posting	
				var vModRec  = document.getElementById('ModRec_G1').value;
				if (vModRec != "") {
					var Obj = document.getElementById('CurRec'+vModRec);
					Obj.style.backgroundColor='#F13A3A';
					alert("Please Submit changes before.");
					
				} else {
					if (document.getElementById('btnPost'))
						x.btnPost.disabled = true;
					if (document.getElementById('btnCancel'))
						x.btnCancel.disabled = true;	
					if (document.getElementById('btnClear'))
						x.btnClear.disabled = true;
					if (document.getElementById('btnAddItemFG'))
						x.btnAddItemFG.disabled = true;
					if (document.getElementById('btnAddItemRM'))
						x.btnAddItemRM.disabled = true;		
					if (document.getElementById('btnLoadRM'))
						x.btnLoadRM.disabled = true;		
					if (document.getElementById('btnLoadTemp'))
						x.btnLoadTemp.disabled = true;			
					
						
					x.actionmode.value='post';
					x.action="Form_Production_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 vTabIndex = x.PTabIndex.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_Production_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&SPrdId="+PrdId+"&SPrdDtId="+PrdDtId+"&STabIndex="+vTabIndex;
		x.submit();
	}

}

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

}

function UpdateSummaryQty(PrdDtId) {
	x = document.production;
	
	XPos = (screen.availHeight - 150) / 2;
	YPos = (screen.availWidth - 430) / 2;
	
	var vPrdId    = x.txtPrdId.value;
	var vMainMode = x.mainaction.value;
	
	win = window.open('Form_ProductionEditQty.php?mainaction='+vMainMode+'&actionmode=&PPrdId='+vPrdId+'&PPrdDtId='+PrdDtId, 
					  'Form_ProductionEditQty', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,width=430,height=150,left='+YPos+',top='+XPos);		
	win.creator = self;
	win.focus();

}

function AddSerialNo(PrdDtId, Option) {
	x = document.production;
	var vItemType   = Option;
	var vPrdId      = x.txtPrdId.value;
	
	
	XPos = (screen.availHeight - 450) / 2;
	YPos = (screen.availWidth - 550) / 2;
    win = window.open('Form_ProductionSerialNo.php?SRItemType='+vItemType+'&SRPrdDtId='+PrdDtId+'&SRPrdId='+vPrdId, 'Form_ProductionSerialNo', 'titlebar=no,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,directories=no, width=550,height=450,left='+YPos+',top='+XPos);
	win.creator = self;
	win.focus();	
}





//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.txtJvRef.value='';
		x.txtJvFolio.value='';
		x.txtExpireDate.value='';
		x.txtBatchNo.value='';
		x.txtPrdType[1].checked = true;
		x.txtRemark.value='';
		x.txtCurr.value='';
		x.txtProjectCode.value='';
		x.txtCostCentCode.value='';
		
		
		x.txtPrdTotal.value='';
		x.txtPrdTotalIdeal.value='';
		
		x.message.value='';
		x.txtPrdCountFG.value='';
		x.txtPrdCountRM.value='';
		
		x.actionmode.value = '';
		x.mainaction.value = '';
		x.PTabIndex.value = 0;
	} 
}

function AddItems(Option, ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost) {
	x = document.production;
	var result = CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost);
	
	var vItemType      = Option;
	var vPrdId    	   = x.txtPrdId.value;
	var vPrdDate  	   = x.txtDate.value;
	var vPrdExpireDate = x.txtExpireDate.value;
	var vPrdBatchNo    = x.txtBatchNo.value;
	var vPrdRemark     = x.txtRemark.value;
	var vPrdCurr       = x.txtCurr.value;
	var vPrdProjectCode  = x.txtProjectCode.value;
	var vPrdCostCentCode = x.txtCostCentCode.value;
		
	vPrdRemark  = vPrdRemark.replace('&','%26');
	vPrdBatchNo = vPrdBatchNo.replace('&','%26');
		
	vPrdRemark  = vPrdRemark.replace('#','%23');
	vPrdBatchNo = vPrdBatchNo.replace('#','%23');

	
	var vMainMode = x.mainaction.value;
	
	if (result == 1) {
		win = window.open('Form_ProductionDetail.php?PItemType='+vItemType+'&mainaction='+vMainMode+'&actionmode=&PPrdId='+vPrdId+'&PPrdDate='+vPrdDate+'&PPrdExpireDate='+vPrdExpireDate+
		                  '&PPrdBatchNo='+vPrdBatchNo+'&PPrdCurr='+vPrdCurr+'&PPrdProjectCode='+vPrdProjectCode+'&PPrdCostCentCode='+vPrdCostCentCode+'&PPrdRemark='+vPrdRemark, 
						  'Form_ProductionDetail', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=700,height=460,top=100');		
		win.creator = self;
		win.focus();		
	}	
	
   
}

function LoadMaterials(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost) {
	x = document.production;
	var result = CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost);

	var vPrdId    	   = x.txtPrdId.value;
	var vPrdDate  	   = x.txtDate.value;
	var vPrdExpireDate = x.txtExpireDate.value;
	var vPrdBatchNo    = x.txtBatchNo.value;
	var vPrdRemark     = x.txtRemark.value;
	var vPrdCurr       = x.txtCurr.value;
		
	vPrdRemark  = vPrdRemark.replace('&','%26');
	vPrdBatchNo = vPrdBatchNo.replace('&','%26');
		
	vPrdRemark  = vPrdRemark.replace('#','%23');
	vPrdBatchNo = vPrdBatchNo.replace('#','%23');
		
	var vMainMode = x.mainaction.value;
	
	
	if (result == 1) {
		win = window.open('Form_Production_LoadMaterials.php?mainaction='+vMainMode+'&actionmode=&PPrdId='+vPrdId+'&PPrdDate='+vPrdDate+'&PPrdExpireDate='+vPrdExpireDate+
						  '&PPrdBatchNo='+vPrdBatchNo+'&PPrdCurr='+vPrdCurr+'&PPrdRemark='+vPrdRemark, 
						  'Form_Production_LoadMaterials', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=960,height=580,top=100,left=20');		
		win.creator = self;
		win.focus();		
	}	
	
    
}

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

	var vMode = 'deletedtFG';
	
	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);			
					ReloadGridDt(filepath,'PRD-TOT','TOTALS','totals',transid,-1);
				}
			}
		}

		xmlhttp.open("GET","Form_Production_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&SPrdId="+vPrdId+"&SPrdDtId="+PrdDtId+"&STabIndex="+vTabIndex+"&txtCurr="+vPrdCurr+"&txtDate="+vPrdDate);
		xmlhttp.send();
	}	

}


function SubmitRecordGridFG(PIndex,filepath,formname,transid,dftorderby,orderby,morelines,startrange,perpage,direction,ModuleRestProj,ModuleRestCost,ModuleProj,ModuleCost,ModuleExpireDate,ModuleSerialNo,NextField,Motion,TabIndex) {
	
	x = document.production;
	
	var ItemExpire     = document.getElementById('itemexpirefg['+PIndex+']').value;
	var ItemWithSerial = document.getElementById('itemwithserialfg['+PIndex+']').value;
	
	var result = 1;
	result = CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost);
	
	if (result == 1) {
		result = CheckFieldsDtFG(PIndex,ItemExpire,ModuleExpireDate,ItemWithSerial,ModuleSerialNo);
	}
	
	var PrdDtId   = document.getElementById('prdfgid['+PIndex+']').value;
	if (PrdDtId == '') vMode = 'submitrecord-ajax';	
	else vMode = 'editdt-ajax';	
	
	var vCostOption = document.getElementsByName('txtCostOptionFG['+PIndex+']');
	for (var i=0; i < vCostOption.length; i++)
	{
		if (vCostOption[i].checked)
		{
		  var vPrdCostOption = vCostOption[i].value;
		}
	}
	
	for (var i=0; i < x.txtPrdType.length; i++)
	{
		if (x.txtPrdType[i].checked)
		{
		  var vPrdType = x.txtPrdType[i].value;
		}
	}
	

	var  the_data = 'mode='+vMode+
					'&mainmode='+x.mainaction.value+
					'&SItemType=FG'+
					'&SPrdId='+x.txtPrdId.value+
					'&PPrdId='+x.txtPrdId.value+
					'&PPrdType='+vPrdType+
					'&PPrdDate='+x.txtDate.value+
					'&PPrdCurr='+x.txtCurr.value+
					'&PPrdExpireDate='+x.txtExpireDate.value+
					'&PPrdBatchNo='+x.txtBatchNo.value+
					'&PPrdProjectCode='+x.txtProjectCode.value+
					'&PPrdCostCentCode='+x.txtCostCentCode.value+
					'&PPrdRemark='+encodeURIComponent(x.txtRemark.value)+
					'&SPrdDtId='+document.getElementById('prdfgid['+PIndex+']').value+
					'&lstWarehouse='+document.getElementById('warehousecodefg['+PIndex+']').value+
					'&txtItemCode='+document.getElementById('itemcodefg['+PIndex+']').value+
					'&txtPrdDtRemark='+document.getElementById('remarkdtfg['+PIndex+']').value+
					'&txtPrdDtQtyInitial='+document.getElementById('prddtqtyinitialfg['+PIndex+']').value+
					'&txtPrdDtQtyDamage='+document.getElementById('prddtqtydamagefg['+PIndex+']').value+
					'&txtPrdDtQtyRemix='+document.getElementById('prddtqtyremixfg['+PIndex+']').value+
					'&txtPrdDtQty='+document.getElementById('prddtqtyfg['+PIndex+']').value+
					'&txtPrdDtQtyIdeal='+document.getElementById('prddtidealqtyfg['+PIndex+']').value+
					'&txtPrdDtWaste='+document.getElementById('prddtwastefg['+PIndex+']').value+
					'&txtPrdDtCostPrice='+document.getElementById('costpricefg['+PIndex+']').value+
					'&txtCostOption='+vPrdCostOption+
					'&txtPrdDtBatchNo='+document.getElementById('batchnofg['+PIndex+']').value+
					'&txtPrdDtExpireDate='+document.getElementById('expiredatefg['+PIndex+']').value+
					'&txtProjectCodeDt='+document.getElementById('projectcodedtfg['+PIndex+']').value+
					'&txtCostCentCodeDt='+document.getElementById('costcentcodedtfg['+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.open("POST", "Form_Production_Actions.php", true);
		
			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('prd-nextcell',nextcell);
						
						ReloadGrid(filepath,formname,transid,'datagrid-1',PIndex,dftorderby,'ADD',orderby,morelines,startrange,perpage,0,direction,function() {
							
						
						if(Motion==1 && PrdDtId == ''){ //case on insert to move back to the inserted row and then go to next grid
								var lastindex = index - 1;
								
								
								var lastcell = 'itemcodefg['+lastindex+']';
								MoveNextRecord(lastcell);
							
								if (document.getElementById('CurRec_G1'+lastindex))
									document.getElementById('CurRec_G1'+lastindex).click();
									
							}
							
							if(Motion==0){ //case motion is false
								MoveNextRecord(nextcell);
								if (document.getElementById('CurRec_G1'+index))
									document.getElementById('CurRec_G1'+index).click();
							}
							
							if(Motion==1){ ////maroun grid motion case motion is true
									
									if(document.getElementById(NextField)) {								
										document.getElementById(NextField).focus();
										
										}
							}
							
							//document.getElementById('CurRec'+index).click();
							if (document.getElementById('RecIndex_G1')) 
									document.getElementById('RecIndex_G1').value = parseInt(index) - 1;
									
									
							
							
							ReloadGridDt(filepath,'PRD-TOT','TOTALS','totals',transid,-1);
							document.getElementById('ModRec_G1').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_Production_Actions.php?"+the_data);
			xmlhttp.send();
			
		}
	}
}

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

	var vMode = 'deletedtRM';
	
	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);			
					ReloadGridDt(filepath,'PRD-TOT','TOTALS','totals',transid,-1);
				}
			}
		}

		xmlhttp.open("GET","Form_Production_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&SPrdId="+vPrdId+"&SPrdDtId="+PrdDtId+"&STabIndex="+vTabIndex+"&txtCurr="+vPrdCurr+"&txtDate="+vPrdDate);
		xmlhttp.send();
	}	

}



function SubmitRecordGridRM(PIndex,filepath,formname,transid,dftorderby,orderby,morelines,startrange,perpage,direction,ModuleRestProj,ModuleRestCost,ModuleProj,ModuleCost,ModuleExpireDate,ModuleSerialNo) {
	
	x = document.production;
	
	var ItemExpire     = document.getElementById('itemexpirerm['+PIndex+']').value;
	var ItemWithSerial = document.getElementById('itemwithserialrm['+PIndex+']').value;
	
	var result = 1;
	result = CheckFields(ModuleRestProj, ModuleRestCost, ModuleProj, ModuleCost);
	
	if (result == 1) {
		result = CheckFieldsDtRM(PIndex,ItemExpire,ModuleExpireDate,ItemWithSerial,ModuleSerialNo);
	}
	
	var PrdDtId   = document.getElementById('prdrmid['+PIndex+']').value;
	if (PrdDtId == '') vMode = 'submitrecord-ajax';	
	else vMode = 'editdt-ajax';	
	
	var vCostOption = document.getElementsByName('txtCostOptionRM['+PIndex+']');
	for (var i=0; i < vCostOption.length; i++)
	{
		if (vCostOption[i].checked)
		{
		  var vPrdCostOption = vCostOption[i].value;
		}
	}
	
	for (var i=0; i < x.txtPrdType.length; i++)
	{
		if (x.txtPrdType[i].checked)
		{
		  var vPrdType = x.txtPrdType[i].value;
		}
	}
	

	var  the_data = 'mode='+vMode+
					'&mainmode='+x.mainaction.value+
					'&SItemType=RM'+
					'&SPrdId='+x.txtPrdId.value+
					'&PPrdId='+x.txtPrdId.value+
					'&PPrdType='+vPrdType+
					'&PPrdDate='+x.txtDate.value+
					'&PPrdCurr='+x.txtCurr.value+
					'&PPrdExpireDate='+x.txtExpireDate.value+
					'&PPrdBatchNo='+x.txtBatchNo.value+
					'&PPrdProjectCode='+x.txtProjectCode.value+
					'&PPrdCostCentCode='+x.txtCostCentCode.value+
					'&PPrdRemark='+encodeURIComponent(x.txtRemark.value)+
					'&SPrdDtId='+document.getElementById('prdrmid['+PIndex+']').value+
					'&lstWarehouse='+document.getElementById('warehousecoderm['+PIndex+']').value+
					'&txtItemCode='+document.getElementById('itemcoderm['+PIndex+']').value+
					'&txtPrdDtRemark='+document.getElementById('remarkdtrm['+PIndex+']').value+
					'&txtPrdDtQty='+document.getElementById('prddtqtyrm['+PIndex+']').value+
					'&txtPrdDtQtyIdeal='+document.getElementById('prddtidealqtyrm['+PIndex+']').value+
					'&txtPrdDtWaste='+document.getElementById('prddtwasterm['+PIndex+']').value+
					'&txtPrdDtCostPrice='+document.getElementById('costpricerm['+PIndex+']').value+
					'&txtCostOption='+vPrdCostOption+
					'&txtPrdDtBatchNo='+document.getElementById('batchnorm['+PIndex+']').value+
					'&txtPrdDtExpireDate='+document.getElementById('expiredaterm['+PIndex+']').value+
					'&txtProjectCodeDt='+document.getElementById('projectcodedtrm['+PIndex+']').value+
					'&txtCostCentCodeDt='+document.getElementById('costcentcodedtrm['+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.open("POST", "Form_Production_Actions.php", true);
		
			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('prd-nextcell',nextcell);
						
						ReloadGrid(filepath,'PRD-1',transid,'datagrid-1',1,'','ADD','ProductionFG.ProductionFG_ID',morelines,startrange,perpage,0,direction);
						ReloadGridDt(filepath,'PRD-SUMM','SUMMARY','summary',transid,-1);
						ReloadGrid(filepath,formname,transid,'datagrid-2',PIndex,dftorderby,'ADD',orderby,morelines,startrange,perpage,0,direction,function() {
							MoveNextRecord(nextcell);
							ReloadGridDt(filepath,'PRD-TOT','TOTALS','totals',transid,-1);
							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_Production_Actions.php?"+the_data);
			xmlhttp.send();
			
		}
	}
}


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

}	

function LoadProdRequest() {
	x = document.production;
	
	win = window.open('Form_Production_LoadRequest.php', 'Form_Production_LoadRequest', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=800,height=580,top=100,left=20');		
	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_Production_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_Production_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();

}

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

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


function SelectPrdType(option) {
	x = document.production;
	
	if (option == 'T') {
		x.btnLoadTemp.disabled = false;
		x.btnLoadRM.disabled = true;
	}
	else if (option == 'P') {
		x.btnLoadTemp.disabled = true;
		x.btnLoadRM.disabled = false;
	}

}


function PrintProduction(PrdId, PrdRef) {
	var str = '';
	var vPrtSer = 0;
	
	if (confirm ( "Do you want to Print current Production with reference "+PrdRef+" ?"))
	{
		if (confirm ( "Do you want to Print with Serial No ?","Yes","No") )
		{
			vPrtSer = 1;
		}
		
		str = 'Form_ProductionPreview.php?ProductionId='+PrdId+'&PrtSer='+vPrtSer;
		window.open(str);
	}	
}


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=1&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 showlistProject(str){

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

function showlistCostcenter(str){

  window.open('List_SorCostcenter.php?frm=7&item='+str,'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;
	
	if (str == 1)
		vProjectCode = encodeURIComponent(document.getElementById('projectcodedtfg['+PIndex+']').value);
	else
		vProjectCode = encodeURIComponent(document.getElementById('projectcodedtrm['+PIndex+']').value);
	
	window.open('List_SorProject.php?frm=28&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;
	
	if (str == 1)
		vCostcentCode = encodeURIComponent(document.getElementById('costcentcodedtfg['+PIndex+']').value);
	else
		vCostcentCode = encodeURIComponent(document.getElementById('costcentcodedtrm['+PIndex+']').value);
	
	window.open('List_SorCostcenter.php?frm=28&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 showlistItems(frm,PIndex){
	var vDate, vItemCode;
	x = document.production;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 850) / 2;
  
	vDate 	   = x.txtDate.value;
	
	if (frm == 8)
		vItemCode  = encodeURIComponent(document.getElementById('itemcodefg['+PIndex+']').value);
	else
		vItemCode  = encodeURIComponent(document.getElementById('itemcoderm['+PIndex+']').value);
  
	window.open('List_SorItems.php?frm='+frm+'&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 showlistItemsDesc(frm,PIndex){
	var vDate, vItemCode;
	x = document.production;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 850) / 2;
  
	vDate 	   = x.txtDate.value;
	
	if (frm == 8)
		vItemDesc  = encodeURIComponent(document.getElementById('itemdescriptionfg['+PIndex+']').value);
	else
		vItemDesc  = encodeURIComponent(document.getElementById('itemdescriptionrm['+PIndex+']').value);
	
	window.open('List_SorItems.php?frm='+frm+'&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 showlistWarehouseRM(PIndex) {
	XPos = (screen.availHeight - 550) / 2;
	YPos = (screen.availWidth - 850) / 2;
	
	var vWarehouseCode = encodeURIComponent(document.getElementById('warehousecoderm['+PIndex+']').value);
	
	window.open('List_SorWarehouse.php?frm=4&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 showlistBatchNoRM(str,PIndex) {
	x = document.production;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 580) / 2;
	
	vItemCode = encodeURIComponent(document.getElementById('itemcoderm['+PIndex+']').value);
	
	window.open('List_BatchNo.php?frm=11&index='+PIndex+'&PItem_Code='+vItemCode,'List_BatchNo','width=580,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,left='+YPos+',top='+XPos);
}

function CalcPrdDtTotalFG(dec,PIndex) {
	x = document.production;
	var vmode = x.actionmode.value;
	var Qty      = document.getElementById('prddtqtyfg['+PIndex+']').value;
	var Price    = document.getElementById('costpricefg['+PIndex+']').value;
	
	if (Qty == '') 		Qty = 0;
	if (Price == '') 	Price = 0;
	
	Qty      = parseFloat(Qty);
	Price    = parseFloat(Price);
	
	if (Qty > 0 && Price >= 0) {
	   document.getElementById('prddttotalfg['+PIndex+']').value = roundNumber((Qty*Price),dec);
	}  

}

function CalcPrdFinalQtyFG(dec,PIndex) {
	x = document.production;
	
	var QtyInitial = document.getElementById('prddtqtyinitialfg['+PIndex+']').value;
	var QtyDamage  = document.getElementById('prddtqtydamagefg['+PIndex+']').value;
	var QtyRemix   = document.getElementById('prddtqtyremixfg['+PIndex+']').value;
	
	if (QtyInitial == '') QtyInitial = 0;
	if (QtyDamage == '')  QtyDamage = 0;
	if (QtyRemix == '')   QtyRemix = 0;
	
	QtyInitial = parseFloat(QtyInitial);
	QtyDamage  = parseFloat(QtyDamage);
	QtyRemix   = parseFloat(QtyRemix);

	var QtyFinal = (QtyInitial - QtyDamage - QtyRemix);
	document.getElementById('prddtqtyfg['+PIndex+']').value = QtyFinal;
	
	CalcPrdDtTotalFG(dec,PIndex);
}

function CalcPrdDtTotalRM(dec,PIndex) {
	x = document.production;
	var vmode = x.actionmode.value;
	var Qty      = document.getElementById('prddtqtyrm['+PIndex+']').value;
	var Price    = document.getElementById('costpricerm['+PIndex+']').value;
	
	if (Qty == '') 		Qty = 0;
	if (Price == '') 	Price = 0;
	
	Qty      = parseFloat(Qty);
	Price    = parseFloat(Price);
	
	if (Qty > 0 && Price >= 0) {
	   document.getElementById('prddttotalrm['+PIndex+']').value = roundNumber((Qty*Price),dec);
	}  

}

function SetRecordGridDefaults(PIndex) {
	x = document.production;

	document.getElementById('batchnofg['+PIndex+']').value = x.txtBatchNo.value;
	document.getElementById('expiredatefg['+PIndex+']').value = x.txtExpireDate.value;

}

</script>

<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') document.getElementById('PTabIndex').value = i;
  },

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

};

</script>
<title>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'>
<input type='hidden' name='PTabIndex' id='PTabIndex' value='$PTabIndex'>
HERE;

//Get Default Project
$querydflproject="select project_code as defaultproject from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['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 ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['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;	
	
if (empty($txtCurr)) {
	if ($SetupDftCurrency != '')
		$txtCurr = $SetupDftCurrency;
	else
		$txtCurr = $base1;
}

if (empty($txtDate))	
	$txtDate = displayToday();
//if (empty($txtExpireDate))	
	//$txtExpireDate = displayToday();
	
		
if ($actionmode != "cancel" && $txtPrdId != '') {
	// Read From Temp Tables For Selected Record				 
	$query = " Select ProductionHD_ID, ProductionHD_Reference, Date_Format(ProductionHD_Date,'%d/%m/%Y') As ProductionHD_Date, ".
	         " Date_Format(ProductionHD_ExpireDate,'%d/%m/%Y') As ExpireDate, ProductionHD.ProductionHD_BatchNo, ".
			 " ProductionHD_Remark, ProductionHD_Type, ProductionHD.Currency_Code, ".
			 " Round(ProductionHD_Total, ".$DecimalBase.") As ProductionTotal, ".
			 " Round(ProductionHD_IdealTotal, ".$DecimalBase.") As ProductionIdealTotal, ".
			 " Round(ProductionHD_WasteTotal, ".$DecimalBase.") As ProductionWasteTotal, ".
			 " Journal.Journal_Folio, Journal.Journal_RefGovernment, ProductionHD.Project_Code, ProductionHD.Costcenter_code ".
			 " From Temp_ProductionHD As ProductionHD ".
			 " Left Join Journal on ProductionHD.Journal_ID = Journal.Journal_ID ".
	         " Where ProductionHD_ID = ".$txtPrdId;
			 //" And Logged_Code = '".$HTTP_SESSION_VARS['useraccount']."' ";
			 
			 
	//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];
	$txtExpireDate = $rows[3];
	$txtBatchNo    = $rows[4];
	$txtRemark     = $rows[5];
	$txtPrdType    = $rows[6];
	$txtCurr       = $rows[7];
	$txtPrdTotal        = $rows[8];
	$txtPrdTotalIdeal   = $rows[9];
	$txtPrdTotalWaste   = $rows[10];
	$txtProjectCode  	= $rows[13];
	$txtCostCentCode 	= $rows[14];
	
	$txtJvFolio	    = $rows[11];
	$txtJvRef 	    = $rows[12];
	
	
	$query = " Select Count(*) FROM Temp_ProductionFG ".
			 " WHERE ProductionHD_Id = ".$txtPrdId;
	$result = selectData($connection, $query);
	$txtPrdCountFG = $result[0];
	if($txtPrdCountFG == '') $txtPrdCountFG = 0;
	
	$query = " Select Count(*) FROM Temp_ProductionRM ".
			 " WHERE ProductionHD_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</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>";
				
if ($txtPrdId != '')
	echo"   <button type='button' name='btnCancel' id='btnCancel'  onclick='CancelRecord();return false;'  title='Cancel Changes'><span><span>Cancel</span></span></button>";
				
if ($txtPrdId != '')
	echo"   <button type='button' name='btnPost' id='btnPost'  onclick='PostChanges($Module_RestrictProjCost, $Module_RestrictCost, $Module_Project, $Module_CostCenter);return false;' 	title='Save Changes' />
	<span><span>Save</span></span></button>";

if ($txtPrdId == '')
	echo"   <button name='btnSearch' type='button' id='btnSearch'  onclick='SearchForRef();return false;' title='Search By Reference' />
			<span><span>Search</span></span></button>";

if ($txtPrdId == '')	
	echo"   <button name='btnPending' type='button' id='btnPending' onclick='SearchForPending();return false;'  title='Pending Production' />
			<span><span>Pending</span></span></button>";	
		
if ($FI_ProductionApp == 1) {
	if ($txtPrdType == 'T')
		echo"&nbsp;<button type='button' id='btnLoadTemp' name='btnLoadTemp'  onclick='LoadTemplate();return false;'  title='Load Template'>
			<span><span>Load Template</span></span></button>";
	else	
		echo"&nbsp;<button type='button' id='btnLoadTemp' name='btnLoadTemp' onclick='LoadTemplate();return false;' title='Load Template' disabled >
			<span><span>Load Template</span></span></button>";
}

if ($FI_ProductionApp == 1) {
	echo"&nbsp;<button type='button' id='btnLoadRequest' name='btnLoadRequest'   onclick='LoadProdRequest();return false;' title='Load Production Request'>
		<span><span>Load Request</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=80>
		  <col width=70>
		  <col width=50>
		  <col width=110>
		  <col width=40>
		  <col width=65>
		  <col width=50>
		  <col width=60>
		  <col width=105>
		  <col width=110>
		  <col width=80>
		  <col width=240>

		<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' id='txtPrdCountFG' name='txtPrdCountFG' value='$txtPrdCountFG' >
			<input type='hidden' id='txtPrdCountRM' name='txtPrdCountRM' value='$txtPrdCountRM' >
			<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>
			  <input type="hidden" name="txtJvFolio" value="$txtJvFolio" >
			  <input type="hidden" name="txtJvRef" value="$txtJvRef" >
		  </td>
						   
HERE;

if ($Module_PostToJournal == 1) {
	echo" <td align='left'><span class='style1'>Folio</span></td>	
		  <td><font face='Verdana' size='2'><b>&nbsp;$txtJvFolio</b></font></td>
		  <td align='left'><span class='style1'>JV Ref.</span></td>	
		  <td><font face='Verdana' size='2'><b>&nbsp;$txtJvRef</b></font></td>";
} else 	{
	echo" <td align='left' colspan='4'>&nbsp;</td>";
}		  
		  

if ($Module_ExpireDate == 1) {
    echo" <td align='left' ><span class='style1'>Expire Date</span></td>
          <td ><input type='text' name='txtExpireDate' value='$txtExpireDate' maxlength='10' style='width:80px;' >
						  <A HREF='#' onClick=\"displayCalendar(document.production.txtExpireDate,'dd/mm/yyyy',this); return false;\" NAME='anchor1' ID='anchor1'><img src='./img/cal.gif' border=0 align=center></A></td>";
} else {
	echo" <td align='left' colspan='2'><input type='hidden' name='txtExpireDate' value='$txtExpireDate'>&nbsp;</td>";
}


$Parameters = array();
$Parameters['Module_Pack'] = $Module_Pack;
$Parameters['Module_DoubleUnit'] = $Module_DoubleUnit;
$Parameters['Module_Project'] = $Module_Project;
$Parameters['Module_CostCenter'] = $Module_CostCenter;
$Parameters['Module_ProjectDt'] = $Module_ProjectDt;
$Parameters['Module_CostCenterDt'] = $Module_CostCenterDt;
$Parameters['Module_RestrictProjCost'] = $Module_RestrictProjCost;
$Parameters['Module_RestrictCost'] = $Module_RestrictCost;
$Parameters['ShowCostCentLayout'] = $ShowCostCentLayout;
$Parameters['Module_SerialNo'] = $Module_SerialNo;
$Parameters['Module_ExpireDate'] = $Module_ExpireDate;
$Parameters['DecimalBase'] = $DecimalBase;
$Parameters['Base1'] = $base1;
$Parameters['Base2'] = $base2;
$Parameters['DisableIdeal'] = $DisableIdeal;
$Parameters['FI_ShowCostPrice'] = $FI_ShowCostPrice;

$Parameters['SetupDftWareHouse'] = $SetupDftWareHouse;
$Parameters['defaultwarehouse']  = $defaultwarehouse;

$Parameters['txtDate'] 		   = $txtDate;
$Parameters['txtCurrCode']     = $txtCurr;

$_SESSION['gprd_parameters']  = $Parameters;


echo"	  <td rowspan='4' colspan='2' valign='top'>";

echo"	<div id='totals' style='width:270px; margin-top:3px; float:right;'>";
	ShowProductionTotals($connection,$txtPrdId,$_SESSION['gprd_parameters'],$_SESSION['gprd_arrayaccess']);
echo"	</div>"; 

echo"	  </td>
		</tr>";
		
/*
echo"   <td rowspan='4' colspan='2' valign='top'><table border='0' style='table-layout:fixed'>
			<col width=110>
			<col width=110>
			
			<tr bgcolor='#D8D8D8' height='30'>
			 <td valign='center' align='right' ><span class='style1'>Total Cost: <br>Actual</span></td> 
			 <td align='center'><input type='text' name='txtPrdTotal' value='$txtPrdTotal' maxlength='20' readonly style='text-align:right; width:100px; height=23px;'></td>
		  </tr>";
		  
	echo" <tr bgcolor='#D8D8D8' height='30'>
			 <td valign='center' align='right' ><span class='style1'>Total Cost: <br>Ideal</span></td> 
			 <td align='center'><input type='text' name='txtPrdTotalIdeal' value='$txtPrdTotalIdeal' maxlength='20' readonly style='text-align:right; width:100px; height=23px;'>
			 </td>
		  </tr>";
echo"	  </table></td>";		
echo"   </tr>";*/

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

if ($Module_ExpireDate == 1){
	echo" <td align='left' ><span class='style1'>Batch No.</span></td>";
	echo" <td ><span class='style1'><input type='text' name='txtBatchNo' id='txtBatchNo' value='$txtBatchNo' style='width:80px;' maxlength='40' /></span></td>";
} else {
	echo" <td align='left' colspan='2'><span class='style1'><input type='hidden' name='txtBatchNo' value='$txtBatchNo'>&nbsp;</span></td>";
}	
echo"   </tr>";	


		


echo"   <tr bgcolor='#F7F7F7' height='27'>
		  <td align='left' ><span class='style1'>Type&nbsp;<span class='style16'>*</span></span></td>";
echo"     <td colspan='7' ><span class='style1'><label>";
echo"      <input type='radio' name='txtPrdType' id='txtPrdType' value='T' onclick='SelectPrdType(this.value);' "; if($txtPrdType=='T') echo "checked />"; else echo " />";  echo " Template";
echo"	   <input type='radio' name='txtPrdType' id='txtPrdType' value='P' onclick='SelectPrdType(this.value);' "; if($txtPrdType=='P' || $txtPrdType=='') echo "checked />"; else echo " />";  echo " Production";
echo"     </label>
          </span>
          </td>";

echo"     <td align='left' ><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'>";
/*
echo"	<td align='left' ><span class='style1'>Divisions</span></td>";
echo"	<td align='left' colspan='7'> <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>";
*/

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:90px;' maxlength='15' readonly /></span>
		    <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Project ' 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='$txtProjectCode' /></td>";

}			

if ($Module_CostCenter == 1 && $ShowCostCentLayout == 1) {		  
	echo" <td align='right' ><span class='style1'>Costcenter&nbsp;<span class='style16'>*</span></span></td>		
		  <td align='left' colspan='4'><span class='style1'>
		    <input type='text' name='txtCostCentCode' id='txtCostCentCode' value='$txtCostCentCode' style='width:149px;' maxlength='15' readonly /></span>
		    <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCostcenter(1); ' /></span></label></td>";
} else {
	echo" <td align='left' colspan='5'><input type='hidden' name='txtCostCentCode' id='txtCostCentCode' value='$txtCostCentCode' /></td>";

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

/*
if ($txtPrdId != '' ) {
	$sub_query = " Select ProductionHDDivisions_ID, ProductionHDDivisions.Divisions_Id, DivisionTypes_Name, Divisions_Code, Divisions_Name  ".
				 " From Temp_ProductionHDDivisions As ProductionHDDivisions ".
				 " Inner Join Divisions on ProductionHDDivisions.Divisions_Id = Divisions.Divisions_Id ".
				 " Inner Join DivisionTypes on Divisions.DivisionTypes_Id = DivisionTypes.DivisionTypes_Id ".
				 " Where ProductionHDDivisions.ProductionHD_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='8'>";
		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"   <td align='left' colspan='4'>&nbsp;</td>";
		echo"</tr>";

	}	
}	
*/


echo"   <tr bgcolor='#D8D8D8' height='30'>
			<td colspan='10' align='center'>";
			
			if ($FI_ProductionApp == 1)
				echo"<button type='button' id='btnAddItemFG' name='btnAddItemFG'  onclick=\"AddItems('FG',$Module_RestrictProjCost, $Module_RestrictCost, $Module_Project, $Module_CostCenter);return false;\"  title='Add Finished Good'>
					<span><span>Add Item FG</span></span></button>";
					
			if ($FI_ProductionApp == 1)
				echo"<button type='button' id='btnAddItemRM' name='btnAddItemRM'   onclick=\"AddItems('RM',$Module_RestrictProjCost, $Module_RestrictCost, $Module_Project, $Module_CostCenter);return false;\"  title='Add Raw Material'>
					<span><span>Add Item RM</span></span></button>";

			if ($FI_ProductionApp == 1)
				echo"<button type='button' id='btnLoadRM' name='btnLoadRM'  onclick=\"LoadMaterials($Module_RestrictProjCost, $Module_RestrictCost, $Module_Project, $Module_CostCenter);return false;\"  title='Load Raw Materials (Stock Out)'>
					<span><span>Load Materials-Stock Out</span></span></button>";
					
echo"       </td>
			<td bgcolor='#F7F7F7' align='left' colspan='2'>&nbsp;</td>
		</tr>";

		  

echo"   <tr><td colspan='12' valign='top' style='padding-top:7px;'>";

echo"	<div class='tabber' id='tab1'>";
echo"		<div class='tabbertab'>
				<h2 title='Items'>Items</h2>";

				
//***********Finished Goods*******************

echo"	<div id='datagrid-1' style='width:1090px;height:200px;margin-top:10px;border:1px solid gray;' >";
echo"	<div id='Loader' class=''><div></div></div>";

//Show Items Grid
ShowProdDtGridFG($connection,'PRD-1',$txtPrdId,$_SESSION['gprd_parameters'],$_SESSION['gprd_arrayaccess'],'ProductionFG.ProductionFG_ID');

echo"	  </div>"; 

//***********Raw Materials*******************

echo"	<div id='datagrid-2' style='width:1090px;height:200px;margin-top:10px;border:1px solid gray;' >";
echo"	<div id='Loader' class=''><div></div></div>";

//Show Items Grid
ShowProdDtGridRM($connection,'PRD-2',$txtPrdId,$_SESSION['gprd_parameters'],$_SESSION['gprd_arrayaccess'],'ProductionRM.ProductionRM_ID');

echo"	  </div>"; 
				
/*
echo"	<div style='overflow:scroll; height:250px; width:980px;' >";
echo"     <table border='0' style='table-layout:fixed'>
          <col width=20>
		  <col width=20>
		  <col width=20>
		  <col width=110>
		  <col width=110>
		  <col width=85>
		  <col width=70>
		  <col width=70>
		  <col width=60>
		  <col width=70>
		  <col width=60>
		  <col width=90>
		  <col width=100>
		  <col width=100>";
		  
if ($Module_ProjectDt == 1)	
	echo"<col width=100>";
if ($Module_CostCenterDt == 1)
	echo"<col width=100>";
if ($Module_ExpireDate == 1) {
	echo"<col width=80>";
	echo"<col width=80>";
}
		  
//***********Finished Goods*******************
		  
echo"<tr bgcolor='#D8D8D8' height='20'>";
echo"  <td align='center' colspan='18'><span class='style16'>Finished Goods</span></td>";
echo"</tr>";		  

if ($DisableIdeal == 0) {		  
	echo"<tr>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
    //echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>Item Code Packed</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>Item Code</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left' colspan='2'><span class='style27'>Description</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>WH</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Actual Qty</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Unit</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Ideal Qty</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Waste</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Cost Price</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Actual Total</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Ideal Total</span></td>";
	
	if ($Module_ProjectDt == 1)	
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Project</span></td>";
	if ($Module_CostCenterDt == 1)
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>CostCenter</span></td>";
	if ($Module_ExpireDate == 1) {
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Batch No</span></td>";
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Expire Date</span></td>";
	}
	
    echo"</tr>";
} else {
	echo"<tr>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
    //echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>Item Code Packed</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>Item Code</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left' colspan='4'><span class='style27'>Description</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center' colspan='2'><span class='style27'>WH</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Actual Qty</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Unit</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Cost Price</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Actual Total</span></td>";
	
	if ($Module_ProjectDt == 1)	
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Project</span></td>";
	if ($Module_CostCenterDt == 1)
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>CostCenter</span></td>";
	if ($Module_ExpireDate == 1) {
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Batch No</span></td>";
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Expire Date</span></td>";
	}
	
    echo"</tr>";

}		  
		  
if ($txtPrdId != '' ) {
			
	$sub_query1 = " Select ProductionFG.ProductionFG_ID, ProductionFG.Item_CodePacked, ProductionFG.Item_Code, Item_Description, ProductionFG.Warehouse_Code, ".
				  " ProductionFG_Quantity, ProductionFG_IdealQty, Round(ProductionFG_Cost, ".$DecimalBase."), ProductionFG_CostBase1, ProductionFG_CostBase2, ".
				  " ifNull(ProductionFG_IdealQty,0) - ifNull(ProductionFG_Quantity,0) As ProductionFG_Waste, ".
				  " Round((ProductionFG_Quantity*ProductionFG_Cost), ".$DecimalBase.") As TotalActual, ".
				  " Round((ProductionFG_IdealQty*ProductionFG_Cost), ".$DecimalBase.") As TotalIdeal, ".
				  " Count(Temp_Purchasesserialno.SerialNo_Code) As CountSerialNo, ifNull(Item_WithSerialNo,0) As ItemWithSerialNo, ".
				  " Date_Format(ProductionFG_ExpireDate,'%d-%m-%Y') As ExpireDate, ProductionFG.ProductionFG_BatchNo, Items.Item_UnitSalesDesc, ".
				  " ProductionFG.Project_code, ProductionFG.CostCenter_Code ".
				  " From Temp_ProductionFG As ProductionFG Left Join Items on ProductionFG.Item_Code = Items.Item_code ".
				  " Left Join Temp_Purchasesserialno on ProductionFG.ProductionFG_ID = Temp_Purchasesserialno.PurchaseDt_ID ".
				  " And Temp_Purchasesserialno.Journal_Type = 'PD' ".
				  " Where ProductionFG.ProductionHD_ID = ".$txtPrdId.
				  " Group By ProductionFG.ProductionFG_ID ".
				  " Order By ProductionFG.ProductionFG_ID Desc ";
	//echo $sub_query1;
	$sub_result1=mysql_query($sub_query1,$connection) or die(mysql_error());
	while($sub_rows1=mysql_fetch_array($sub_result1)){
		$ct+=1;

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

		// If ItemWithSerialNo True And ModuleSerialNo True	
		if ($sub_rows1[14] == 1 && $Module_SerialNo == 1) 
			echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_addserial.png' onMouseOver=\"style.cursor='hand'\" onclick=\"AddSerialNo('".$sub_rows1[0]."','FG')\" title='Add Serial Nos'  ></span></td>";
		else
			echo "	<td align='center' valign='center'>&nbsp;</td>";
					
		echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdatePrdDt('".$sub_rows1[0]."','FG') 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=\"DeletePrdDt('".$sub_rows1[0]."','".htmlentities($sub_rows1[1])."','".htmlentities($sub_rows1[2])."','FG')\" title='Delete Record'  ></span></td>";
				
		//echo "	<td align='left'><span class='style15'>".$sub_rows1[1]."</span></td>";
		echo "	<td align='left'><span class='style15'>".$sub_rows1[2]."</span></td>";
				
		if ($DisableIdeal == 0) {
			echo "	<td align='left' colspan='2'><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'>".$sub_rows1[5]."</span></td>";
			echo "	<td align='left'><span class='style15'>".$sub_rows1[17]."</span></td>";
			echo "	<td align='right'><span class='style15'>".$sub_rows1[6]."</span></td>";
			echo "	<td align='right'><span class='style15'>".$sub_rows1[10]."</span></td>";
			echo "	<td align='right'><span class='style15'>".number_format($sub_rows1[7], $DecimalBase)."</span></td>";
			echo "	<td align='right'><span class='style15'>".number_format($sub_rows1[11], $DecimalBase)."</span></td>";
			echo "	<td align='right'><span class='style15'>".number_format($sub_rows1[12], $DecimalBase)."</span></td>";
			
			if ($Module_ProjectDt == 1)	
				echo "	<td align='left'><span class='style15'>".$sub_rows1[18]."</span></td>";
			if ($Module_CostCenterDt == 1)
				echo "	<td align='left'><span class='style15'>".$sub_rows1[19]."</span></td>";
			if ($Module_ExpireDate == 1) {
				echo "	<td align='left'><span class='style15'>".$sub_rows1[16]."</span></td>";
				echo "	<td align='left'><span class='style15'>".$sub_rows1[15]."</span></td>";
			}	
				
			echo "</tr>";
			
		} else {
			echo "	<td align='left' colspan='4'><span class='style15'>".$sub_rows1[3]."</span></td>";
			echo "	<td align='left' colspan='2'><span class='style15'>".$sub_rows1[4]."</span></td>";
			echo "	<td align='right'><span class='style15'>".$sub_rows1[5]."</span></td>";
			echo "	<td align='left'><span class='style15'>".$sub_rows1[17]."</span></td>";
			echo "	<td align='right'><span class='style15'>".number_format($sub_rows1[7], $DecimalBase)."</span></td>";
			echo "	<td align='right'><span class='style15'>".number_format($sub_rows1[11], $DecimalBase)."</span></td>";
			
			if ($Module_ProjectDt == 1)	
				echo "	<td align='left'><span class='style15'>".$sub_rows1[18]."</span></td>";
			if ($Module_CostCenterDt == 1)
				echo "	<td align='left'><span class='style15'>".$sub_rows1[19]."</span></td>";
			if ($Module_ExpireDate == 1) {
				echo "	<td align='left'><span class='style15'>".$sub_rows1[16]."</span></td>";
				echo "	<td align='left'><span class='style15'>".$sub_rows1[15]."</span></td>";
			}	
			
			echo "</tr>";
			
			
		}	
								
	}
			
}

//***********Raw Materials*******************
		  
echo"<tr bgcolor='#D8D8D8' height='20'>";
echo"  <td align='center' colspan='18'><span class='style16'>Raw Materials</span></td>";
echo"</tr>";		  

if ($DisableIdeal == 0) {		  
	echo"<tr>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
    //echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>Item Code Packed</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>Item Code</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left' colspan='2'><span class='style27'>Description</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>WH</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Actual Qty</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Unit</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Ideal Qty</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Waste</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Cost Price</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Actual Total</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Ideal Total</span></td>";
	
	if ($Module_ProjectDt == 1)	
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Project</span></td>";
	if ($Module_CostCenterDt == 1)
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>CostCenter</span></td>";
	if ($Module_ExpireDate == 1) {
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Batch No</span></td>";
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Expire Date</span></td>";
	}
	
    echo"</tr>";
} else {
	echo"<tr>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>&nbsp;</span></td>";
    //echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>Item Code Packed</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>Item Code</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='left' colspan='4'><span class='style27'>Description</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center' colspan='2'><span class='style27'>WH</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Actual Qty</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Unit</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Cost Price</span></td>";
	echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Actual Total</span></td>";
	
	if ($Module_ProjectDt == 1)	
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Project</span></td>";
	if ($Module_CostCenterDt == 1)
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>CostCenter</span></td>";
	if ($Module_ExpireDate == 1) {
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Batch No</span></td>";
		echo"  <td bgcolor='#F7F7F7' align='center'><span class='style27'>Expire Date</span></td>";
	}
    echo"</tr>";

}		  
		  
if ($txtPrdId != '' ) {
			
	$sub_query2 = " Select ProductionRM.ProductionRM_ID, ProductionRM.Item_CodePacked, ProductionRM.Item_Code, Items.Item_Description, ProductionRM.Warehouse_Code, ".
				  " ProductionRM_Quantity, ProductionRM_IdealQty, Round(ProductionRM_Cost, ".$DecimalBase."), ProductionRM_CostBase1, ProductionRM_CostBase2, ".
				  " ifNull(ProductionRM_IdealQty,0) - ifNull(ProductionRM_Quantity,0) As ProductionRM_Waste, ".
				  " Round((ProductionRM_Quantity*ProductionRM_Cost), ".$DecimalBase.") As TotalActual, ".
				  " Round((ProductionRM_IdealQty*ProductionRM_Cost), ".$DecimalBase.") As TotalIdeal, ".
				  " Count(Temp_Purchasesserialno.SerialNo_Code) As CountSerialNo, ifNull(Items.Item_WithSerialNo,0) As ItemWithSerialNo, ".
				  " Date_Format(ProductionRM_ExpireDate,'%d-%m-%Y') As ExpireDate, ProductionRM.ProductionRM_BatchNo, Items.Item_UnitSalesDesc, ".
				  " ProductionReqRM.Item_CodeFinished, Items1.Item_Description as Item_DescFinished, ProductionRM.Project_code, ProductionRM.CostCenter_Code ".
				  " From Temp_ProductionRM As ProductionRM Left Join Items on ProductionRM.Item_Code = Items.Item_code ".
				  " Left Join Temp_Purchasesserialno on ProductionRM.ProductionRM_ID = Temp_Purchasesserialno.PurchaseDt_ID ".
				  " And Temp_Purchasesserialno.Journal_Type In ('PDT','PDO') ".
				  " Left Join ProductionReqRM on ProductionRM.ProductionReqRM_Id = ProductionReqRM.ProductionReqRM_Id ".
				  " Left Join Items as Items1 on ProductionReqRM.Item_CodeFinished = Items1.Item_code ".
				  " Where ProductionRM.ProductionHD_ID = ".$txtPrdId.
				  " Group By ProductionRM.ProductionRM_ID ".
				  " Order By ProductionRM.ProductionRM_ID Desc ";
	//echo $sub_query1;
	$sub_result2=mysql_query($sub_query2,$connection) or die(mysql_error());
	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."'";	
					
				
		echo "<tr ".$Color." >";

		// If ItemWithSerialNo True And ModuleSerialNo True	
		if ($sub_rows2[14] == 1 && $Module_SerialNo == 1) 
			echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_addserial.png' onMouseOver=\"style.cursor='hand'\" onclick=\"AddSerialNo('".$sub_rows2[0]."','RM')\" title='Add Serial Nos'  ></span></td>";
		else
			echo "	<td align='center' valign='center'>&nbsp;</td>";
					
		echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_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/c_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[1]."</span></td>";
		echo "	<td align='left'><span class='style15'>".$sub_rows2[2]."</span></td>";
				
		if ($DisableIdeal == 0) {
			echo "	<td align='left' colspan='2'><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[17]."</span></td>";
			echo "	<td align='right'><span class='style15'>".number_format($sub_rows2[6], $DecimalBase)."</span></td>";
			echo "	<td align='right'><span class='style15'>".number_format($sub_rows2[10], $DecimalBase)."</span></td>";
			echo "	<td align='right'><span class='style15'>".number_format($sub_rows2[7], $DecimalBase)."</span></td>";
			echo "	<td align='right'><span class='style15'>".number_format($sub_rows2[11], $DecimalBase)."</span></td>";
			echo "	<td align='right'><span class='style15'>".number_format($sub_rows2[12], $DecimalBase)."</span></td>";
			
			if ($Module_ProjectDt == 1)	
				echo "	<td align='left'><span class='style15'>".$sub_rows2[20]."</span></td>";
			if ($Module_CostCenterDt == 1)
				echo "	<td align='left'><span class='style15'>".$sub_rows2[21]."</span></td>";
			if ($Module_ExpireDate == 1) {
				echo "	<td align='left'><span class='style15'>".$sub_rows2[16]."</span></td>";
				echo "	<td align='left'><span class='style15'>".$sub_rows2[15]."</span></td>";
			}
			echo "</tr>";
			
			echo "<tr ".$Color.">";
			echo "	<td align='left' colspan='3'><span class='style15'>&nbsp;</span></td>";	
			echo "	<td align='left'><span class='style15'>".$sub_rows2[18]."</span></td>";
			echo "	<td align='left' colspan='10'><span class='style15'>".$sub_rows2[19]."</span></td>";	
			echo "</tr>";				
			
		} else {
			echo "	<td align='left' colspan='4'><span class='style15'>".$sub_rows2[3]."</span></td>";
			echo "	<td align='left' colspan='2'><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[17]."</span></td>";
			echo "	<td align='right'><span class='style15'>".number_format($sub_rows2[7], $DecimalBase)."</span></td>";
			echo "	<td align='right'><span class='style15'>".number_format($sub_rows2[11], $DecimalBase)."</span></td>";
			
			if ($Module_ProjectDt == 1)	
				echo "	<td align='left'><span class='style15'>".$sub_rows2[20]."</span></td>";
			if ($Module_CostCenterDt == 1)
				echo "	<td align='left'><span class='style15'>".$sub_rows2[21]."</span></td>";
			if ($Module_ExpireDate == 1) {
				echo "	<td align='left'><span class='style15'>".$sub_rows2[16]."</span></td>";
				echo "	<td align='left'><span class='style15'>".$sub_rows2[15]."</span></td>";
			}
			echo "</tr>";
			
			echo "<tr ".$Color.">";
			echo "	<td align='left' colspan='3'><span class='style15'>&nbsp;</span></td>";	
			echo "	<td align='left'><span class='style15'>".$sub_rows2[18]."</span></td>";
			echo "	<td align='left' colspan='10'><span class='style15'>".$sub_rows2[19]."</span></td>";	
			echo "</tr>";				
			
		}	
		
		
								
	}
			
}

echo "</table></div>";*/


echo"		</div>";
echo"		<div class='tabbertab'>
				<h2 title='Summary'>Summary</h2>";
				
		if ($txtPrdId != '' ) {
			
			echo"<div id='summary' style='margin-top:10px;' >";
			
			//Show RM Items Grid
			ShowProdGridSummary($connection,$txtPrdId,$_SESSION['gprd_parameters'],$_SESSION['gprd_arrayaccess']);

			echo"</div>"; 
			
			/*
			echo"<table border='0' style='table-layout:fixed'>
					  <col width=20>
					  <col width=130>
					  <col width=350>
					  <col width=60>
					  <col width=100>
					  <col width=100>
					  <col width=100>";
					  
			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'>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'>Unit</span></td>";
			echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>Actual Qty</span></td>";
			echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>Ideal Qty</span></td>";
			echo"  <td bgcolor='#D8D8D8' align='center'><span class='style27'>Multiplier</span></td>";
			echo"</tr>";		  
			
			$sub_query3 = " Select ProductionSummaryRM.ProductionSummaryRM_Id, ProductionSummaryRM.Item_Code, Items.Item_Description, ".
						  " ifNull(ProductionSummaryRM_Quantity,0) As ActualQty, ifNull(ProductionSummaryRM_IdealQty,0) As IdealQty, ProductionSummaryRM_Multiplier, Items.Item_UnitSalesDesc ".
						  " From Temp_ProductionSummaryRM As ProductionSummaryRM Left Join Items on ProductionSummaryRM.Item_Code = Items.Item_code ".
						  " Where ProductionSummaryRM.ProductionHD_Id = '".$txtPrdId."' ".
						  " Order By ProductionSummaryRM.Item_Code ";
			//echo $sub_query3;
			$sub_result3=mysql_query($sub_query3,$connection) or die(mysql_error());
			while($sub_rows3=mysql_fetch_array($sub_result3)){
				$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=UpdateSummaryQty('".$sub_rows3[0]."') title='Edit Record'  ></span></td>";
				echo "	<td align='left'><span class='style15'>".$sub_rows3[1]."</span></td>";
				echo "	<td align='left'><span class='style15'>".$sub_rows3[2]."</span></td>";
				echo "	<td align='center'><span class='style15'>".$sub_rows3[6]."</span></td>";
				echo "	<td align='right'><span class='style15'>".number_format($sub_rows3[3], $DecimalBase)."</span></td>";
				echo "	<td align='right'><span class='style15'>".number_format($sub_rows3[4], $DecimalBase)."</span></td>";
				echo "	<td align='right'><span class='style15'>".number_format($sub_rows3[5], $DecimalBase)."</span></td>";
				echo "</tr>";
										
			}
			
			echo "</table>";	*/		
					
		}
		
echo"		</div>";
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
	
	
echo"<script type=\"text/javascript\" language=\"javascript\">";
echo"	tabberAutomatic(tabberOptions);";
echo"   vTabIndex = document.getElementById('PTabIndex').value; ";
echo"	if (document.getElementById('tab1')) document.getElementById('tab1').tabber.tabShow(vTabIndex); ";
echo"</script>";


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;

?>