<?php
header("Content-type: text/html; charset=windows-1256");
session_start();

if (!function_exists('ConvertCurrency')) {
	function ConvertCurrency($FromCurr, $ToCurr, $FromDate, $Amount, $connection)
	{
		$query = "SELECT ifNull(convertcurfunc('".$FromCurr."', '".$ToCurr."', '".$FromDate."', 0, 0, '', '', ifNull($Amount,0)),0) From Dual ";
		$result = selectData($connection, $query);
		//echo $query;
		Return	$result[0];

	}
}

if (!empty($_GET["action"])) {
	$dftorderby   = $_GET["dftorderby"];
	$action 	  = $_GET["action"];
	$orderby 	  = $_GET["orderby"];
	$morelines	  = $_GET["morelines"];
	$startrange   = $_GET["startrange"];
	$perpage 	  = $_GET["perpage"];
	$totalrows    = $_GET["totalrows"];
	$direction    = $_GET["direction"];
	$filepath     = $_GET["filepath"];
	$transid      = $_GET["transid"];
	$transdtid    = $_GET["transdtid"];
	$form      	  = $_GET["form"];
	
	
	
	include("config.inc.php");
	include("Functions_Sales.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");
	
	
	if ($form == 'PRD-1') {
		ShowProdDtGridFG($connection,$form,$transid,$_SESSION['gprd_parameters'],$_SESSION['gprd_arrayaccess'],$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	}
	else if ($form == 'PRD-2') {
		ShowProdDtGridRM($connection,$form,$transid,$_SESSION['gprd_parameters'],$_SESSION['gprd_arrayaccess'],$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	}
	else if ($form == 'PRD-SUMM') {
		ShowProdGridSummary($connection,$transid,$_SESSION['gprd_parameters'],$_SESSION['gprd_arrayaccess']);
	}	
	else if ($form == 'PRD-TOT') {
		ShowProductionTotals($connection,$transid,$_SESSION['gprd_parameters'],$_SESSION['gprd_arrayaccess']);
	}
	else if ($form == 'PRD-TPL-1') {
		ShowProdTplDtGridFG($connection,$form,$transid,$_SESSION['gprdtpl_parameters'],$_SESSION['gprdtpl_arrayaccess'],$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	}
	else if ($form == 'PRD-TPL-2') {
		ShowProdTplDtGridRM($connection,$form,$transid,$_SESSION['gprdtpl_parameters'],$_SESSION['gprdtpl_arrayaccess'],$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	}
}

function ShowProdDtGridFG($connection,$form,$PPrdId,$arrayparams,$arrayaccess,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction){
	
	$Module_Pack = $arrayparams['Module_Pack'];
	$Module_DoubleUnit = $arrayparams['Module_DoubleUnit'];
	$Module_ProjectDt = $arrayparams['Module_ProjectDt'];
	$Module_CostCenterDt = $arrayparams['Module_CostCenterDt'];
	$Module_Project = $arrayparams['Module_Project'];
	$Module_CostCenter = $arrayparams['Module_CostCenter'];
	$Module_RestrictProjCost = $arrayparams['Module_RestrictProjCost'];
	$Module_RestrictCost = $arrayparams['Module_RestrictCost'];
	$ShowCostCentLayout = $arrayparams['ShowCostCentLayout'];
	$Module_SerialNo = $arrayparams['Module_SerialNo'];
	$Module_ExpireDate = $arrayparams['Module_ExpireDate'];
	$FI_ShowCostPrice = $arrayparams['FI_ShowCostPrice'];
	
	$SetupDftWareHouse = $arrayparams['SetupDftWareHouse'];
	$defaultwarehouse  = $arrayparams['defaultwarehouse'];
	$Module_Heatno = $arrayparams['Module_Heatno'];
	$DecimalBase = $arrayparams['DecimalBase'];
	$Base1 = $arrayparams['Base1'];
	$Base2 = $arrayparams['Base2'];
	
	$txtDate         = $arrayparams['txtDate'];
	$txtCurrCode     = $arrayparams['txtCurrCode'];
	$DisableIdeal    = $arrayparams['DisableIdeal'];

	
	/// grid Motion
		$Motion   = 1;
		$NextCell = 'itemcoderm[0]';
		$TabIndex = 0;		
	/////////////
	
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_DataGrid_Production.php';
	
	$i = 0;
	$k = 0;
	
	if ($startrange=='') $startrange = 0;
	if ($perpage=='')	 $perpage = 50;
	if ($orderby=='')	 $orderby = $dftorderby;
	if ($morelines=='')	 $morelines = 1;
	
	if ($action == 'COR' || $direction == '') {
		if ($direction == 'asc') $direction = 'desc';
		else if ($direction == 'desc') $direction = 'asc';
		else $direction = 'asc';
	}
	
	$columnsarray = array("itemcodefg", "itemdescriptionfg", "warehousecodefg");


	if($Module_Heatno==1){
		array_push($columnsarray, "HeatNo");
		array_push($columnsarray, "Bundle");
		}
	array_push($columnsarray,"prddtqtyinitialfg", "prddtqtydamagefg", "prddtqtyremixfg", "prddtqtyfg");
	
	if ($DisableIdeal == 0) {
		array_push($columnsarray, 'prddtidealqtyfg');
		array_push($columnsarray, 'prddtwastecalcfg');
		array_push($columnsarray, 'prddtwastefg');
	}	
	
	if ($FI_ShowCostPrice == 1) {
	array_push($columnsarray, 'costpricefg');
	array_push($columnsarray, 'prddttotalfg');
	}
	
	if ($DisableIdeal == 0) array_push($columnsarray, 'prddttotalidealfg');

	
	
	if ($FI_ShowCostPrice == 1)
	array_push($columnsarray, 'prdcostoptionfg');
	
	if ($Module_ProjectDt == 1) array_push($columnsarray, 'projectcodedtfg');
	if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) array_push($columnsarray, 'costcentcodedtfg');
	if ($Module_ExpireDate == 1) {
		array_push($columnsarray, 'batchnofg');
		array_push($columnsarray, 'expiredatefg');
	}	
	array_push($columnsarray, 'remarkdtfg');
	
	
	$columnsarrayall = array("itemcodefg", "itemdescriptionfg", "warehousecodefg", "prddtqtyinitialfg", "prddtqtydamagefg", "prddtqtyremixfg", "prddtqtyfg", "prddtidealqtyfg", "prddtwastecalcfg", "prddtwastefg", 
	                         "costpricefg", "prddttotalfg", "prddttotalidealfg", "prdcostoptionfg", "projectcodedtfg", "costcentcodedtfg", "batchnofg", "expiredatefg", "remarkdtfg", "prdfgid");
	$orderbyarray = array("ProductionFG.Item_CodePacked", "Items.Item_Code", "Items.Item_Description", "ProductionFG.Warehouse_Code", "Items.Item_UnitSalesDesc");
	
	for ($j=1; $j<=count($orderbyarray); $j++){
				
		$index = array_search($orderby, $orderbyarray);
		$index += 1;
		
		$orderimg = 'orderimg'.$index;
		
		if (in_array($orderby, $orderbyarray) && $direction=='asc')
			$$orderimg = "<img src='img/asc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";
		else if (in_array($orderby, $orderbyarray) && $direction=='desc')
			$$orderimg = "<img src='img/desc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";	
		else
			$$orderimg = "";
			
	}	

		
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
	
	
	$TableWidth = 1335;
	if ($Module_SerialNo == 1)     $TableWidth += 20;
	if ($Module_Pack == 1)         $TableWidth += 125;
	if ($DisableIdeal == 0)	       $TableWidth += 330;
	//if ($Module_SerialNo == 1)     $TableWidth += 50;
	if ($Module_ProjectDt == 1)    $TableWidth += 160;
	if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) $TableWidth += 160;
	if ($Module_ExpireDate == 1)   $TableWidth += 170;
	
	//Initializations for Div Ids
	$ContainerDiv = 'container1';
	$LoaderDiv    = 'Loader1';
	$HeaderDiv    = 'grid_headerDiv1';
	$ContentDiv   = 'grid_contentDiv1';
	$TableFocus   = 'table-focus-g1';
	
	$TableWidthStyle = 'width:'.$TableWidth.'px;';
	
	echo"<div id='$ContainerDiv' style='position: relative;z-index:1;' >";
	echo"	<div id='$LoaderDiv' class=''></div>";
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:1073px;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
	
		echo"<tr height='25'>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		
		if ($Module_SerialNo == 1) {
			echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		}
		
		if ($Module_Pack == 1)
			echo"  <th width='125px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid-1', 1, '".$dftorderby."', 'COR','ProductionFG.Item_CodePacked','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code Packed".$orderimg1."</span></th>";
			
		echo"  <th width='140px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid-1', 1, '".$dftorderby."', 'COR','Items.Item_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code (FG)".$orderimg2."</span></th>";
		echo"  <th width='205px;' align='left' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid-1', 1, '".$dftorderby."', 'COR','Items.Item_Description','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Description".$orderimg3."</span></th>";
		echo"  <th width='105px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid-1', 1, '".$dftorderby."', 'COR','ProductionFG.Warehouse_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Warehouse".$orderimg4."</span></th>";
		
		if($Module_Heatno==1)
		echo"  <th width='210px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','ProductionDt.ProductionDt_Heatno','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>HeatNo</span></th>";
	
		if($Module_Heatno==1)
		echo"  <th width='210px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','ProductionDt.productionfg_bundle','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Bundle</span></th>";
	
		echo"  <th width='65px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid-1', 1, '".$dftorderby."', 'COR','Items.Item_UnitSalesDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Unit1".$orderimg5."</span></th>";
		echo"  <th width='75px;' align='center'><span>Initial Qty</span></th> ";	
		echo"  <th width='75px;' align='center'><span>Damage Qty</span></th> ";	
		echo"  <th width='75px;' align='center'><span>Remix Qty</span></th> ";	
		echo"  <th width='75px;' align='center'><span>Actual Qty</span></th> ";	
		
		if ($DisableIdeal == 0) {
			echo"  <th width='75px;' align='center'><span>Ideal Qty</span></th>";
			echo"  <th width='75px;' align='center'><span>Waste</span></th>";
			echo"  <th width='75px;' align='center'><span>Actual Waste</span></th>";
		}
		
		
		if ($FI_ShowCostPrice == 1) {  	
			echo"  <th width='85px;' align='center'><span>Cost Price</span></th>";
			echo"  <th width='105px;' align='center'><span>Actual Total</span></th>";
		}
		
		if ($DisableIdeal == 0) {
			echo"  <th width='105px;' align='center'><span>Ideal Total</span></th>";
		}
		
		if ($FI_ShowCostPrice == 1) 
		echo"  <th width='230px;' align='center'><span>Cost Option</span></th>";	
		
		if ($Module_ProjectDt == 1) {
			echo"  <th width='160px;' align='center'><span>Project</span></th>";	
		}
		if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) {
			echo"  <th width='160px;' align='center'><span>Costcenter</span></th>";	
		}
		
		if ($Module_ExpireDate == 1) {
			echo"  <th width='105px;' align='center'><span>Batch No</span></th>";	
			echo"  <th width='85px;' align='center'><span>Expire Date</span></th>";	
		}
	
		echo"  <th width='255px;' align='center'><span>Remark</span></th>";	
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv');\" style='width:1090px;height:135px;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
		echo"<input type='hidden' name='SelectedRec_G1' id='SelectedRec_G1' value='$SelectedRec_G1'>
			 <input type='hidden' name='SelectedRecColor_G1' id='SelectedRecColor_G1' value='$SelectedRecColor_G1'>
			 <input type='hidden' name='ModRec_G1' id='ModRec_G1' value='$ModRec_G1'>";  
		
			 
		
		
		if ($PPrdId != '' ) {
				  
			$query = " Select ProductionFG.ProductionFG_ID, ProductionFG.Item_CodePacked, ProductionFG.Item_code, Item_Description, ProductionFG.Warehouse_Code, ".
					 " ProductionFG_Remark, ProductionFG_Quantity, ProductionFG_IdealQty, Round(ProductionFG_Cost, ".$DecimalBase."), ProductionFG_CostBase1, ProductionFG_CostBase2, ".
					 " ifNull(ProductionFG_IdealQty,0) - ifNull(ProductionFG_Quantity,0) As ProductionFGWasteCalc, ProductionFG_Waste, ".
					 " Round((ProductionFG_Quantity*ProductionFG_Cost), ".$DecimalBase.") As TotalActual, ".
					 " Round((ProductionFG_IdealQty*ProductionFG_Cost), ".$DecimalBase.") As TotalIdeal, ".
					 " ifNull(item_withserialno,0) As ItemWithSerialNo, Count(Temp_Purchasesserialno.SerialNo_Code) As CountSerialNo, Item_UnitSalesDesc, ".
					 " Date_Format(ProductionFG_ExpireDate,'%d/%m/%Y') As ProductionFG_ExpireDate, ProductionFG_BatchNo, ProductionFG.Project_code, ProductionFG.CostCenter_Code, ".
					 " ProductionFG_CostOption, ifNull(ProductionFG_InitialQty,0), ifNull(ProductionFG_DamageQty,0), ifNull(ProductionFG_RemixQty,0) , productionfg_heatno , productionfg_bundle ".
					 " 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' ".
					 " And Temp_Purchasesserialno.PurchaseDt_ID Is Not Null ".
					 " Where ProductionFG.ProductionHD_ID = ".$PPrdId.
					 " Group By  ProductionFG.ProductionFG_ID ".
					 " Order By $orderby $direction ";
					 
			//echo $query;
					
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);

			$query = $query." limit ".$startrange.",".$perpage;
			$resultdt=mysql_query($query,$connection);
			
			
			while($rowsdt=mysql_fetch_array($resultdt)){
			    				
				$recno = $i+1;
				$k = $k + 1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$TextColor = 'style7';
				$productionfg_heatno[$i] = $rowsdt[26];
				$productionfg_bundle[$i] = $rowsdt[27];
				 
				$sub_query = " SELECT ifNull(Item_Pack, 0), ifNull(item_zeroPrice, 0), Item_UnitSalesDesc, Item_UnitPurchaseDesc, ifNull(Item_Unit,1), ifNull(Item_NonStock, 0), ifNull(Item_MinimumPrice, 0), ifNull(Item_Expire,0), ifNull(item_withserialno,0) ".
							 " FROM Items ".
							 " WHERE Items.Item_Code = '".$rowsdt[2]."'";
					
				//echo "<br><br>".$sub_query;
				$sub_result = selectData($connection, $sub_query);
				$i_pack       = $sub_result[0];
				$i_zeroprice  = $sub_result[1];
				$i_unit1      = $sub_result[2];
				$i_unit2 	  = $sub_result[3]; 
				$i_unitcoef	  = $sub_result[4];
				$i_nonstock   = $sub_result[5];
				$i_minprice   = $sub_result[6];
				$i_expire	  = $sub_result[7];
				$i_withserial = $sub_result[8];
				
				
				
					
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_1['.$i.']\')"';
				
				echo"<tr id='CurRec_G1$i' class='$bgcolor $TableFocus'>";		
				echo"	<td width='25px;' $RecStyle>$recno</td>";
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteRecordGridFG('".$filepath."','".$form."', '".$PPrdId."','".$rowsdt[0]."','".$i."','".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."');return false;\" title='Delete Record'  ></td>";
				
				// If ItemWithSerialNo True And ModuleSerialNo True	
				if ($rowsdt[15] == 1 && $Module_SerialNo == 1) {
					echo "	<td width='25px;' align='center' valign='center'><img src='img/button_addserial.png' onMouseOver=\"style.cursor='hand'\" onclick=\"AddSerialNo('".$rowsdt[0]."','".htmlentities($rowsdt[2])."','".$rowsdt[6]."','".$rowsdt[4]."')\" title='Add Serial Nos'  ></td>";
				}
				else if ($rowsdt[15] == 0 && $Module_SerialNo == 1) {
					echo "	<td width='25px;' align='center' valign='center'>&nbsp;</td>";
				}
				
				if ($Module_Pack == 1)
					echo "	<td width='125px;' align='left'><span class='".$TextColor."'>".$rowsdt[1]."</span></td>";
					
				echo "	<td width='140px;' align='left'>
							<input type='hidden' name='txtPrdFGId[$i]' id='prdfgid[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtItemExpire[$i]' id='itemexpirefg[$i]' value='$txtItemExpire[$i]' >
							<input type='hidden' name='txtItemWithSerial[$i]' id='itemwithserialfg[$i]' value='$txtItemWithSerial[$i]' >
							<input type='hidden' name='txtExistingQty[$i]' id='existingqty[$i]' value='$txtExistingQty[$i]' >
							<input type='hidden' name='txtBookingQty[$i]' id='bookingqty[$i]' value='$txtBookingQty[$i]' >
							<input type='hidden' name='txtAvailableQty[$i]' id='availableqty[$i]' value='$txtAvailableQty[$i]' >
							<input type='text' name='txtItemCodeFG[$i]' id='itemcodefg[$i]' value='".$rowsdt[2]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:110px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','items','item_code',this.value,'lstItemCodeFG[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'itemcodefg[$i]','itemdescriptionfg[$i]','items');\" ".$KeyDown.">
							<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(8,$i); ' style='vertical-align:bottom;'/></span></label>
						</td>";
										
				echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDescFG[$i]' id='itemdescriptionfg[$i]' value='".$rowsdt[3]."' class='".$ClassE."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDescFG[$i]');\" ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDescFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDesc(8,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
						</td>";
				echo"  	<td width='105px;' align='center'>
							<input type='text' name='txtWarehouseCodeFG[$i]' id='warehousecodefg[$i]' value='".$rowsdt[4]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCodeFG[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecodefg[$i]','warehousenamefg[$i]','warehouse');\" ".$KeyDown."   />
							<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouseFG($i);' style='vertical-align:bottom;'/></span></label>
						</td>";
				
			if($Module_Heatno==1)		
				echo"  	<td width='210px;' align='center'>
							<input type='text' name='productionfg_heatno[$i]' id='productionfg_heatno[$i]' value='".$productionfg_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\" ".$KeyDown."   />
							<label><span><img src='img/openlist.png' title='Select HeatNo' id='lstHeatNo[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistHeatNo($i);' style='vertical-align:bottom;'/></span></label>
						</td>";		
			else echo"<input type='hidden' name='productionfg_heatno[$i]' id='productionfg_heatno[$i]' value='".$productionfg_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\" ".$KeyDown."   />";
			
			if($Module_Heatno==1)		
				echo"  	<td width='210px;' align='center'>
							<input type='text' name='productionfg_bundle[$i]' id='productionfg_bundle[$i]' value='".$productionfg_bundle[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;'   ".$KeyDown."   />
							
						</td>";		
				else 	echo"<input type='hidden' name='productionfg_bundle[$i]' id='productionfg_bundle[$i]' value='".$productionfg_bundle[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;'   ".$KeyDown."   />";

				
				echo "	<td width='65px;' align='center'><span class='".$TextColor."'>".$rowsdt[17]."</span></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyInitialFG[$i]' id='prddtqtyinitialfg[$i]' value='".$rowsdt[23]."' maxlength='20' onkeyup='CalcPrdFinalQtyFG($DecimalBase,$i);' class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyDamageFG[$i]' id='prddtqtydamagefg[$i]' value='".$rowsdt[24]."' maxlength='20' onkeyup='CalcPrdFinalQtyFG($DecimalBase,$i);' class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyRemixFG[$i]' id='prddtqtyremixfg[$i]' value='".$rowsdt[25]."' maxlength='20' onkeyup='CalcPrdFinalQtyFG($DecimalBase,$i);' class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyFG[$i]' id='prddtqtyfg[$i]' value='".$rowsdt[6]."' maxlength='20'  onKeyup='CalcPrdDtTotalFG($DecimalBase,$i);' class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
				
				if ($DisableIdeal == 0) {
					echo"  <td width='75px;' align='center'><input type='text' name='txtPrdDtQtyIdealFG[$i]' id='prddtidealqtyfg[$i]' value='".$rowsdt[7]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' readonly ></td>";
					echo"  <td width='75px;' align='center'><input type='text' name='txtPrdDtWasteCalcFG[$i]' id='prddtwastecalcfg[$i]' value='".$rowsdt[11]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' readonly ></td>";
					echo"  <td width='75px;' align='center'><input type='text' name='txtPrdDtWasteFG[$i]' id='prddtwastefg[$i]' value='".$rowsdt[12]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
				} else {
					echo"  <input type='hidden' name='txtPrdDtQtyIdealFG[$i]' id='prddtidealqtyfg[$i]' value='' >";
					echo"  <input type='hidden' name='txtPrdDtWasteCalcFG[$i]' id='prddtwastecalcfg[$i]' value='' >";
					echo"  <input type='hidden' name='txtPrdDtWasteFG[$i]' id='prddtwastefg[$i]' value='' >";
				}
				if ($FI_ShowCostPrice == 1) {  		
					echo"	<td width='85px;' align='center'><input type='text' name='txtPrdDtCostPriceFG[$i]' id='costpricefg[$i]' value='".$rowsdt[8]."' maxlength='20' onKeyup='CalcPrdDtTotalFG($DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' ".$KeyDown."  ></td>";
					echo"   <td width='105px;' align='center'><input type='text' name='txtPrdDtTotalFG[$i]' id='prddttotalfg[$i]' value='".$rowsdt[13]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." ></td>";
				} else {
					echo"	<input type='hidden' name='txtPrdDtCostPriceFG[$i]' id='costpricefg[$i]' value='".$rowsdt[8]."' maxlength='20' onKeyup='CalcPrdDtTotalFG($DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' ".$KeyDown."  >";
					echo"   <input type='hidden' name='txtPrdDtTotalFG[$i]' id='prddttotalfg[$i]' value='".$rowsdt[13]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." >";
				}
				
				if ($DisableIdeal == 0) {
					echo"   <td width='105px;' align='center'><input type='text' name='txtPrdDtTotalIdealFG[$i]' id='prddttotalidealfg[$i]' value='".$rowsdt[14]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." ></td>";
				}	
				
				if ($FI_ShowCostPrice == 1) {  		
					echo"   <td width='230px;' align='center'><span>";
					echo"  		<input type='radio' name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='1' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." "; if($rowsdt[22]=='1' ) echo "checked />"; else echo " />";echo" <font size=2>";  echo " Percentage";
					echo"	 	<input type='radio' name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='2' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." "; if($rowsdt[22]=='2' || $rowsdt[22]=='') echo "checked />"; else echo " />";  echo " Quantity";
					echo"	 	<input type='radio' name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='3' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." "; if($rowsdt[22]=='3') echo "checked />"; else echo " />";  echo " Fixed";
					echo"	</span></td>";
				} else {
					echo"  		<span><input type='radio' hidden name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='1' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." "; if($rowsdt[22]=='1' || $rowsdt[22]=='') echo "checked />"; else echo " />"; 
					echo"	 	<input type='radio' hidden  name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='2' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." "; if($rowsdt[22]=='2') echo "checked />"; else echo " />";  
					echo"	 	<input type='radio'  hidden name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='3' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." "; if($rowsdt[22]=='3') echo "checked />"; else echo " /></span>";  
				}

				
				if ($Module_ProjectDt == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDtFG[$i]' id='projectcodedtfg[$i]' value='".$rowsdt[20]."' class='".$ClassE."' style='width:120px;' maxlength='15' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCodeFG[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistProjectDt(1,$i); ' style='vertical-align:bottom;'/></span></label></td>";	
				} else {
					echo"  <input type='hidden' name='txtProjectCodeDtFG[$i]' id='projectcodedtfg[$i]' value='' >";
				}
				if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDtFG[$i]' id='costcentcodedtfg[$i]' value='".$rowsdt[21]."' class='".$ClassE."' style='width:130px;' maxlength='15' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCodeFG[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
				} else {
					echo"  <input type='hidden' name='txtCostCentCodeDtFG[$i]' id='costcentcodedtfg[$i]' value='' >";
				}
				
				if ($Module_ExpireDate == 1) {
					echo" 	<td width='105px;' align='center'><input type='text' name='txtPurDtBatchNoFG[$i]' id='batchnofg[$i]' value='".htmlspecialchars($rowsdt[19], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='font-size:12px; width:100px; height:20px;' ".$KeyDown." ></td>
							<td width='85px;' align='center'><input type='text' name='txtPurDtExpireDateFG[$i]' id='expiredatefg[$i]' value='".$rowsdt[18]."' maxlength='10' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE." date' style='font-size:12px; width:80px; height:20px;' ".$KeyDown." ></td>"; 	 
				} else {
					echo" <input type='hidden' name='txtPurDtExpireDateFG[$i]' id='expiredatefg[$i]' value=''>";
					echo" <input type='hidden' name='txtPurDtBatchNoFG[$i]' id='batchnofg[$i]' value=''>";
				}
					
				$j=$i+1;
				echo"	<td width='255px;'><input type='text' name='txtPrdDtRemarkFG[$i]' id='remarkdtfg[$i]' value='".htmlspecialchars($rowsdt[5], ENT_QUOTES)."'  maxlength='200'  class='".$ClassE."' style='font-size:12px; width:245px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";	
				echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_1[$i]' 
				onclick=\"SubmitRecordGridFG('".$i."','".$filepath."', '".$form."', '".$PPrdId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$Module_SerialNo,'itemcodefg[$j]',$Motion,$TabIndex); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
				echo "</tr>";
						
				
				$i+=1;
				
				$LastItemWarehouse = $rowsdt[4];
			}
			
			
		}
		
		
							
		for ($k=1;$k <= 1;$k++) {
			$recno = $i+1;
			$mode = 'i';
			
			if ($i%2==0) $bgcolor='bgcolor1';
			else $bgcolor='bgcolor2';	
			
			if (empty($txtWarehouseCodeFG[$i])) {
				if (!empty($LastItemWarehouse))
					$txtWarehouseCodeFG[$i] = $LastItemWarehouse;
				else if (!empty($SetupDftWareHouse))
					$txtWarehouseCodeFG[$i] = $SetupDftWareHouse;
				else	
					$txtWarehouseCodeFG[$i] = $defaultwarehouse;
			}

			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_1['.$i.']\')"';
			
				
			echo"<tr id='CurRec_G1$i' class='$bgcolor $TableFocus' >";
			echo"	<td width='25px;'>$recno</td>";
			echo"	<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G1');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
			
			if ($Module_SerialNo == 1) {
				echo "	<td width='25px;' align='center' valign='center'>&nbsp;</td>";
			}
			
			if ($Module_Pack == 1)
				echo"  <td width='125px;' align='center'><span>&nbsp;</span></td>";
				
			echo "	<td width='140px;' align='left'>
						<input type='hidden' name='txtPrdFGId[$i]' id='prdfgid[$i]' value='$txtPrdFGId[$i]' >
						<input type='hidden' name='txtItemExpire[$i]' id='itemexpirefg[$i]' value='$txtItemExpire[$i]' >
						<input type='hidden' name='txtItemWithSerial[$i]' id='itemwithserialfg[$i]' value='$txtItemWithSerial[$i]' >
						<input type='hidden' name='txtExistingQty[$i]' id='existingqty[$i]' value='$txtExistingQty[$i]' >
						<input type='hidden' name='txtBookingQty[$i]' id='bookingqty[$i]' value='$txtBookingQty[$i]' >
						<input type='hidden' name='txtAvailableQty[$i]' id='availableqty[$i]' value='$txtAvailableQty[$i]' >
						<input type='text' name='txtItemCodeFG[$i]' id='itemcodefg[$i]' value='$txtItemCodeFG[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:110px; height:20px;'  onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','items','item_code',this.value,'lstItemCodeFG[$i]'); GetSelectedItem(this.id,'getitem','".$i."','".$txtDate."','".$txtCurrCode."','-3'); SetRecordGridDefaults($i);\" onkeyup=\"AutoCompleteData(event,this.id,'itemcodefg[$i]','itemdescriptionfg[$i]','items');\"  ".$KeyDown.">
						<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(8,$i); ' style='vertical-align:bottom;'/></span></label>
					</td>";
									
			echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDescFG[$i]' id='itemdescriptionfg[$i]' value='$txtItemDescFG[$i]'  class='".$ClassI."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDescFG[$i]');\" ".$KeyDown." />
						<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDescFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDesc(8,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
					</td>";
			echo"  	<td width='105px;' align='center'>
						<input type='text' name='txtWarehouseCodeFG[$i]' id='warehousecodefg[$i]' value='$txtWarehouseCodeFG[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:75px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCodeFG[$i]'); \" onkeyup=\"AutoCompleteData(event,this.id,'warehousecodefg[$i]','warehousenamefg[$i]','warehouse');\"  ".$KeyDown."  />
						<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouseFG($i);' style='vertical-align:bottom;'/></span></label>
					</td>";
			
			if($Module_Heatno==1)		
				echo"  	<td width='210px;' align='center'>
							<input type='text' name='productionfg_heatno[$i]' id='productionfg_heatno[$i]' value='".$productionfg_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\" ".$KeyDown."   />
							<label><span><img src='img/openlist.png' title='Select HeatNo' id='lstHeatNo[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistHeatNo($i);' style='vertical-align:bottom;'/></span></label>
						</td>";		
				else echo"<input type='hidden' name='productionfg_heatno[$i]' id='productionfg_heatno[$i]' value='".$productionfg_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\" ".$KeyDown."   />		";
				
			if($Module_Heatno==1)		
				echo"  	<td width='210px;' align='center'>
							<input type='text' name='productionfg_bundle[$i]' id='productionfg_bundle[$i]' value='".$productionfg_bundle[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;'   ".$KeyDown."   />
							
						</td>";		
				else echo"<input type='hidden' name='productionfg_bundle[$i]' id='productionfg_bundle[$i]' value='".$productionfg_bundle[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;'   ".$KeyDown."   />";
				
			echo"   <td width='65px;' align='center'><input type='text' name='txtItemUnit1FG' id='itemunit1fg[$i]' value='$txtItemUnit1FG' maxlength='20' onkeyup='CalcPrdFinalQtyFG($DecimalBase,$i);' class='".$ClassI."'  style='text-align:right; font-size:12px; width:60px; height:20px;' readonly></td>";
			echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyInitialFG[$i]' id='prddtqtyinitialfg[$i]' value='$txtPrdDtQtyInitialFG[$i]' maxlength='20' onkeyup='CalcPrdFinalQtyFG($DecimalBase,$i);' class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
			echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyDamageFG[$i]' id='prddtqtydamagefg[$i]' value='$txtPrdDtQtyDamageFG[$i]' maxlength='20' onkeyup='CalcPrdFinalQtyFG($DecimalBase,$i);' class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
			echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyRemixFG[$i]' id='prddtqtyremixfg[$i]' value='$txtPrdDtQtyRemixFG[$i]' maxlength='20' onkeyup='CalcPrdFinalQtyFG($DecimalBase,$i);' class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
			echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyFG[$i]' id='prddtqtyfg[$i]' value='$txtPrdDtQtyFG[$i]' maxlength='20' onKeyup='CalcPrdDtTotalFG($DecimalBase,$i);' class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." ></td>";
			
			if ($DisableIdeal == 0) {
				echo"  <td width='75px;' align='center'><input type='text' name='txtPrdDtQtyIdealFG[$i]' id='prddtidealqtyfg[$i]' value='$txtPrdDtQtyIdealFG[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' readonly ></td>";
				echo"  <td width='75px;' align='center'><input type='text' name='txtPrdDtWasteCalcFG[$i]' id='prddtwastecalcfg[$i]' value='$txtPrdDtWasteCalcFG[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' readonly ></td>";
				echo"  <td width='75px;' align='center'><input type='text' name='txtPrdDtWasteFG[$i]' id='prddtwastefg[$i]' value='$txtPrdDtWasteFG[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
			} else {
				echo"  <input type='hidden' name='txtPrdDtQtyIdealFG[$i]' id='prddtidealqtyfg[$i]' value='' >";
				echo"  <input type='hidden' name='txtPrdDtWasteCalcFG[$i]' id='prddtwastecalcfg[$i]' value='' >";
				echo"  <input type='hidden' name='txtPrdDtWasteFG[$i]' id='prddtwastefg[$i]' value='' >";
			}
			if ($FI_ShowCostPrice == 1) {  
				echo"	<td width='85px;' align='center'><input type='text' name='txtPrdDtCostPriceFG[$i]' id='costpricefg[$i]' value='$txtPrdDtCostPriceFG[$i]' maxlength='20' onKeyup='CalcPrdDtTotalFG($DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' ".$KeyDown."  ></td>";
				echo"   <td width='105px;' align='center'><input type='text' name='txtPrdDtTotalFG[$i]' id='prddttotalfg[$i]' value='$txtPrdDtTotalFG[$i]' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." ></td>";
			} else {
				echo"	<input type='hidden' name='txtPrdDtCostPriceFG[$i]' id='costpricefg[$i]' value='$txtPrdDtCostPriceFG[$i]' maxlength='20' onKeyup='CalcPrdDtTotalFG($DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' ".$KeyDown."  >";
				echo"  <input type='hidden' name='txtPrdDtTotalFG[$i]' id='prddttotalfg[$i]' value='$txtPrdDtTotalFG[$i]' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." >";
			}
				
			if ($DisableIdeal == 0) {
				echo"   <td width='105px;' align='center'><input type='text' name='txtPrdDtTotalIdealFG[$i]' id='prddttotalidealfg[$i]' value='$txtPrdDtTotalIdealFG[$i]' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." ></td>";
			}	
			if ($FI_ShowCostPrice == 1) {  	
			echo"   <td width='230px;' align='center'><span>";
			echo"  		<input type='radio' name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='1' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown."  />";echo" <font size=2>"; echo " Percentage";
			echo"	 	<input type='radio' name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='2' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." checked/>";  echo " Quantity";
			echo"	 	<input type='radio' name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='3' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." />";  echo " Fixed";
			echo"	</span></td>";
			} else {
			
			echo"  		<span><input type='radio' hidden  name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='1' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown."  />";
			echo"	 	<input type='radio'    hidden  name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='2' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." checked/>";  
			echo"	 	<input type='radio'    hidden  name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='3' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." /></span>";  
			
			}
			
			if ($Module_ProjectDt == 1) {
				echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDtFG[$i]' id='projectcodedtfg[$i]' value='$txtProjectCodeDtFG[$i]' class='".$ClassI."' style='width:120px;' maxlength='15' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCodeFG[$i]');\" ".$KeyDown." /></span>
						<label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistProjectDt(1,$i); ' style='vertical-align:bottom;'/></span></label></td>";	
			} else {
				echo"  <input type='hidden' name='txtProjectCodeDtFG[$i]' id='projectcodedtfg[$i]' value='' >";
			}
			if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) {
				echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDtFG[$i]' id='costcentcodedtfg[$i]' value='$txtCostCentCodeDtFG[$i]' class='".$ClassI."' style='width:130px;' maxlength='15' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCodeFG[$i]');\" ".$KeyDown." /></span>
						<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
			} else {
				echo"  <input type='hidden' name='txtCostCentCodeDtFG[$i]' id='costcentcodedtfg[$i]' value='' >";
			}
			
			if ($Module_ExpireDate == 1) {
				echo" 	<td width='105px;' align='center'><input type='text' name='txtPurDtBatchNoFG[$i]' id='batchnofg[$i]' value='".htmlspecialchars($txtPurDtBatchNoFG[$i], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' style='font-size:12px; width:100px; height:20px;' ".$KeyDown." ></td>
						<td width='85px;' align='center'><input type='text' name='txtPurDtExpireDateFG[$i]' id='expiredatefg[$i]' value='$txtPurDtExpireDateFG[$i]' maxlength='10' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI." date' style='font-size:12px; width:80px; height:20px;' ".$KeyDown." ></td>"; 	 
			} else {
				echo" <input type='hidden' name='txtPurDtExpireDateFG[$i]' id='expiredatefg[$i]' value=''>";
				echo" <input type='hidden' name='txtPurDtBatchNoFG[$i]' id='batchnofg[$i]' value=''>";
			}
				
				$j=$i+1;
			echo"	<td width='255px;'><input type='text' name='txtPrdDtRemarkFG[$i]' id='remarkdtfg[$i]' value='".htmlspecialchars($txtPrdDtRemarkFG[$i], ENT_QUOTES)."'  maxlength='200' class='".$ClassI."'  style='font-size:12px; width:245px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";	
			echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_1[$i]' onclick=\"SubmitRecordGridFG('".$i."','".$filepath."', '".$form."', '".$PPrdId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$Module_SerialNo,'itemcodefg[$j]',$Motion,$TabIndex); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
			echo"</tr>";  

			$i+=1;	
		}
		

	
	echo"	</table>";  
	echo"	</div>";
	
	showDataGridFooter($filepath,$form,$PPrdId,'datagrid-1',$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	
	echo"</div>";
	
	$query = " Select Count(*) FROM Temp_ProductionFG ".
			 " WHERE ProductionHD_Id = ".$PPrdId;
			 
	$result = selectData($connection, $query);
	$txtPrdCountFG = $result[0];
	if($txtPrdCountFG == '') $txtPrdCountFG = 0;
	
	echo"<input type='hidden' name='txtPrdCountFG' value='$txtPrdCountFG' >";
	
}



function ShowProductionTotals($connection,$PPrdId,$arrayparams,$arrayaccess){

	$DecimalBase  = $arrayparams['DecimalBase'];
	
	$Base1 = $arrayparams['Base1'];
	$Base2 = $arrayparams['Base2'];
	$txtCurr = $arrayparams['txtCurrCode']; 
	
	if ($PPrdId != "") {
		$sub_query = " Select Round(ProductionHD_Total, ".$DecimalBase.") As ProductionTotal, ".
					 " Round(ProductionHD_IdealTotal, ".$DecimalBase.") As ProductionIdealTotal ".
					 " From Temp_ProductionHD As ProductionHD ".
					 " Where ProductionHD_ID = ".$PPrdId;
			 
		//echo $sub_query;
		$sub_result = selectData($connection, $sub_query);
		
		$txtPrdTotal      		= $sub_result[0];
		$txtPrdTotalIdeal		= $sub_result[1];
		
		
		$sub_query = " Select sum(ProductionFG_Quantity*ProductionFG_Cost) from Temp_Productionfg where productionhd_id = ".$PPrdId;
		$sub_result = selectData($connection, $sub_query);
		$txtPrdTotalFG      		= $sub_result[0];
		
		$sub_query = " Select sum(ProductionRM_Quantity*ProductionRM_Cost) from Temp_ProductionRM where productionhd_id = ".$PPrdId;
		$sub_result = selectData($connection, $sub_query);
		$txtPrdTotalRM      		= $sub_result[0];
		
	} 
	
	$txtPrdTotalBal = $txtPrdTotalFG - $txtPrdTotalRM;
	
	echo"	<table border='0' style='table-layout:fixed;width:100px' cellspacing=0>
			<tr>
				<td id='total-top' style='width:240px;height:12px;'></td>
			</tr>
			<tr><td id='total-content' style='width:240px;height:12px;'>
				<table border='0' style='table-layout:fixed;' cellspacing=0 >
				<col width=90>
				<col width=140>
			
				<tr><td valign='center' align='right' width='45%'><span class='style10'>Total Cost Actual:</span>&nbsp;</td>
					<td align='left' ><input type='text' id='totalactual'  name='txtPrdTotal' value='$txtPrdTotal' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
				</tr>
				<tr><td valign='center' align='right' width='45%'><span class='style10'>Total Cost Ideal:</span>&nbsp;</td> 
					<td align='left' ><input type='text' id='totalideal'  name='txtPrdTotalIdeal' value='$txtPrdTotalIdeal' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
				</tr>
				<tr><td valign='center' align='right' width='45%'><span class='style1'>Total Cost FG:</span>&nbsp;</td> 
					<td align='left' ><input type='text' id='totalideal'  name='txtPrdTotalFG' value='$txtPrdTotalFG' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
				</tr>
				
				<tr><td valign='center' align='right' width='45%'><span class='style1'>Total Cost RM:</span>&nbsp;</td> 
					<td align='left' ><input type='text' id='totalideal'  name='txtPrdTotalRM' value='$txtPrdTotalRM' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
				</tr>
				
					<tr><td valign='center' align='right' width='45%'><span class='style1'>Balance:</span>&nbsp;</td> 
					<td align='left' ><input type='text' id='totalideal'  name='txtPrdTotalBal' value='$txtPrdTotalBal' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
				</tr>
				
				
				</table></td>
			</tr><tr>
				<td id='total-bottom' style='width:240px;height:12px;'></td>
			</tr>
			
	 
			
			</table></td></tr>";
			


}
function ShowProdDtGridRM($connection,$form,$PPrdId,$arrayparams,$arrayaccess,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction){
	
	$Module_Pack = $arrayparams['Module_Pack'];
	$Module_DoubleUnit = $arrayparams['Module_DoubleUnit'];
	$Module_ProjectDt = $arrayparams['Module_ProjectDt'];
	$Module_CostCenterDt = $arrayparams['Module_CostCenterDt'];
	$Module_Project = $arrayparams['Module_Project'];
	$Module_CostCenter = $arrayparams['Module_CostCenter'];
	$Module_RestrictProjCost = $arrayparams['Module_RestrictProjCost'];
	$Module_RestrictCost = $arrayparams['Module_RestrictCost'];
	$ShowCostCentLayout = $arrayparams['ShowCostCentLayout'];
	$Module_SerialNo = $arrayparams['Module_SerialNo'];
	$Module_ExpireDate = $arrayparams['Module_ExpireDate'];
	$FI_ShowCostPrice = $arrayparams['FI_ShowCostPrice'];
	$SetupDftWareHouse = $arrayparams['SetupDftWareHouse'];
	$defaultwarehouse  = $arrayparams['defaultwarehouse'];
	
	$DecimalBase = $arrayparams['DecimalBase'];
	$Base1 = $arrayparams['Base1'];
	$Base2 = $arrayparams['Base2'];
	
	$txtDate         = $arrayparams['txtDate'];
	$txtCurrCode     = $arrayparams['txtCurrCode'];
	$DisableIdeal    = $arrayparams['DisableIdeal'];
	$Module_Heatno = $arrayparams['Module_Heatno'];
	/// grid Motion
					$Motion = 1;
					$NextCell = 'itemcodefg[0]';	
					$down = 1;	
			//////////
			
			
			
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_DataGrid_Production.php';
	
	$i = 0;
	$k = 0;
	
	if ($startrange=='') $startrange = 0;
	if ($perpage=='')	 $perpage = 50;
	if ($orderby=='')	 $orderby = $dftorderby;
	if ($morelines=='')	 $morelines = 1;
	
	if ($action == 'COR' || $direction == '') {
		if ($direction == 'asc') $direction = 'desc';
		else if ($direction == 'desc') $direction = 'asc';
		else $direction = 'asc';
	}
	
	$columnsarray = array("itemcoderm", "itemdescriptionrm", "warehousecoderm");
	
	if($Module_Heatno==1)
		array_push($columnsarray, "HeatNo");
	
	if($Module_Heatno==1)
		array_push($columnsarray, "Bundle");
		
	
	array_push($columnsarray, 'prddtqtyrm');
	
	if ($DisableIdeal == 0) {
		array_push($columnsarray, 'prddtidealqtyrm');
		array_push($columnsarray, 'prddtwastecalcrm');
		array_push($columnsarray, 'prddtwasterm');
	}	
	
	if ($FI_ShowCostPrice == 1) {
	array_push($columnsarray, 'costpricerm');
	array_push($columnsarray, 'prddttotalrm');
	}
	
	if ($DisableIdeal == 0) array_push($columnsarray, 'prddttotalidealrm');
	
	if ($FI_ShowCostPrice == 1) 
	array_push($columnsarray, 'prdcostoptionrm');
	
	if ($Module_ProjectDt == 1) array_push($columnsarray, 'projectcodedtrm');
	if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) array_push($columnsarray, 'costcentcodedtrm');
	if ($Module_ExpireDate == 1) {
		array_push($columnsarray, 'batchnorm');
		array_push($columnsarray, 'expiredaterm');
	}	
	array_push($columnsarray, 'remarkdtrm');
	
	
	
	$columnsarrayall = array("itemcoderm", "itemdescriptionrm", "warehousecoderm", "prddtqtyrm", "prddtidealqtyrm", "prddtwastecalcrm", "prddtwasterm", 
	                         "costpricerm", "prddttotalrm", "prddttotalidealrm", "projectcodedtrm", "costcentcodedtrm", "batchnorm", "expiredaterm", "remarkdtrm", "prdrmid");
	$orderbyarray = array("ProductionRM.Item_CodePacked", "Items.Item_Code", "Items.Item_Description", "ProductionRM.Warehouse_Code", "Items.Item_UnitSalesDesc");
	
	for ($j=1; $j<=count($orderbyarray); $j++){
				
		$index = array_search($orderby, $orderbyarray);
		$index += 1;
		
		$orderimg = 'orderimg'.$index;
		
		if (in_array($orderby, $orderbyarray) && $direction=='asc')
			$$orderimg = "<img src='img/asc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";
		else if (in_array($orderby, $orderbyarray) && $direction=='desc')
			$$orderimg = "<img src='img/desc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";	
		else
			$$orderimg = "";
			
	}	

		
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
	
	
	$TableWidth = 1110;
	if ($Module_SerialNo == 1)     $TableWidth += 20;
	if ($Module_Pack == 1)         $TableWidth += 125;
	if ($DisableIdeal == 0)	       $TableWidth += 330;
	//if ($Module_SerialNo == 1)     $TableWidth += 50;
	if ($Module_ProjectDt == 1)    $TableWidth += 160;
	if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) $TableWidth += 160;
	if ($Module_ExpireDate == 1)   $TableWidth += 170;
	
	//Initializations for Div Ids
	$ContainerDiv = 'container2';
	$LoaderDiv    = 'Loader2';
	$HeaderDiv    = 'grid_headerDiv2';
	$ContentDiv   = 'grid_contentDiv2';
	$TableFocus   = 'table-focus-g2';
	
	$TableWidthStyle = 'width:'.$TableWidth.'px;';
	
	echo"<div id='$ContainerDiv' style='position: relative;z-index:1;' >";
	echo"	<div id='$LoaderDiv' class=''></div>";
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:1073px;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
	
		echo"<tr height='25'>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		
		if ($Module_SerialNo == 1) {
			echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		}
		
		if ($Module_Pack == 1)
			echo"  <th width='125px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid-2', 1, '".$dftorderby."', 'COR','ProductionFG.Item_CodePacked','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code Packed".$orderimg1."</span></th>";
			
		echo"  <th width='140px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid-2', 1, '".$dftorderby."', 'COR','Items.Item_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code (RM)".$orderimg2."</span></th>";
		echo"  <th width='205px;' align='left' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid-2', 1, '".$dftorderby."', 'COR','Items.Item_Description','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Description".$orderimg3."</span></th>";
		echo"  <th width='105px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid-2', 1, '".$dftorderby."', 'COR','ProductionFG.Warehouse_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Warehouse".$orderimg4."</span></th>";
		
		if($Module_Heatno==1)
		echo"  <th width='210px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','ProductionDt.ProductionDt_Heatno','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>HeatNo</span></th>";
	
		if($Module_Heatno==1)
		echo"  <th width='210px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','ProductionDt.productionRM_bundle','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Bundle</span></th>";
	
		
		echo"  <th width='65px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid-2', 1, '".$dftorderby."', 'COR','Items.Item_UnitSalesDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Unit1".$orderimg5."</span></th>";
		echo"  <th width='75px;' align='center'><span>Actual Qty</span></th> ";	
		
		if ($DisableIdeal == 0) {
			echo"  <th width='75px;' align='center'><span>Ideal Qty</span></th>";
			echo"  <th width='75px;' align='center'><span>Waste</span></th>";
			echo"  <th width='75px;' align='center'><span>Actual Waste</span></th>";
		}
		
		if ($FI_ShowCostPrice == 1) {
		echo"  <th width='85px;' align='center'><span>Cost Price</span></th>";
		echo"  <th width='105px;' align='center'><span>Actual Total</span></th>";
		}
		
		if ($DisableIdeal == 0) {
			echo"  <th width='105px;' align='center'><span>Ideal Total</span></th>";
		}
		
		if ($FI_ShowCostPrice == 1) 
		echo"  <th width='230px;' align='center'><span>Cost Option</span></th>";	
		
		if ($Module_ProjectDt == 1) {
			echo"  <th width='160px;' align='center'><span>Project</span></th>";	
		}
		if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) {
			echo"  <th width='160px;' align='center'><span>Costcenter</span></th>";	
		}
		
		if ($Module_ExpireDate == 1) {
			echo"  <th width='105px;' align='center'><span>Batch No</span></th>";	
			echo"  <th width='85px;' align='center'><span>Expire Date</span></th>";	
		}
	
		echo"  <th width='255px;' align='center'><span>Remark</span></th>";	
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv');\" style='width:1090px;height:135px;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
		echo"<input type='hidden' name='SelectedRec_G2' id='SelectedRec_G2' value='$SelectedRec_G2'>
			 <input type='hidden' name='SelectedRecColor_G2' id='SelectedRecColor_G2' value='$SelectedRecColor_G2'>
			 <input type='hidden' name='ModRec_G2' id='ModRec_G2' value='$ModRec_G2'>";  
		
			 
		
		
		if ($PPrdId != '' ) {
				   
			$query = " Select ProductionRM.ProductionRM_ID, ProductionRM.Item_CodePacked, ProductionRM.Item_code, Item_Description, ProductionRM.Warehouse_Code, ".
					 " ProductionRM_Remark, ProductionRM_Quantity, ProductionRM_IdealQty, Round(ProductionRM_Cost, ".$DecimalBase."), ProductionRM_CostBase1, ProductionRM_CostBase2, ".
					 " ifNull(ProductionRM_IdealQty,0) - ifNull(ProductionRM_Quantity,0) As ProductionRMWasteCalc, ProductionRM_Waste, ".
					 " Round((ProductionRM_Quantity*ProductionRM_Cost), ".$DecimalBase.") As TotalActual, ".
					 " Round((ProductionRM_IdealQty*ProductionRM_Cost), ".$DecimalBase.") As TotalIdeal, ".
					 " ifNull(item_withserialno,0) As ItemWithSerialNo, Count(Temp_Purchasesserialno.SerialNo_Code) As CountSerialNo, Item_UnitSalesDesc, ".
					 " Date_Format(ProductionRM_ExpireDate,'%d/%m/%Y') As ProductionRM_ExpireDate, ProductionRM_BatchNo, ProductionRM.Project_code, ProductionRM.CostCenter_Code, ".
					 " ProductionRM_CostOption,productionrm_heatno,productionRM_bundle ".
					 " 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 = 'PD' ".
					 " And Temp_Purchasesserialno.PurchaseDt_ID Is Not Null ".
					 " Where ProductionRM.ProductionHD_ID = ".$PPrdId.
					 " Group By  ProductionRM.ProductionRM_ID ".
					 " Order By $orderby $direction ";
					 
			//echo $query;
					
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);

			$query = $query." limit ".$startrange.",".$perpage;
			$resultdt=mysql_query($query,$connection);
			
			
			while($rowsdt=mysql_fetch_array($resultdt)){
			    				
				$recno = $i+1;
				$k = $k + 1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$TextColor = 'style7';
				
				$sub_query = " SELECT ifNull(Item_Pack, 0), ifNull(item_zeroPrice, 0), Item_UnitSalesDesc, Item_UnitPurchaseDesc, ifNull(Item_Unit,1), ifNull(Item_NonStock, 0), ifNull(Item_MinimumPrice, 0), ifNull(Item_Expire,0), ifNull(item_withserialno,0) ".
							 " FROM Items ".
							 " WHERE Items.Item_Code = '".$rowsdt[2]."'";
					
				//echo "<br><br>".$sub_query;
				$sub_result = selectData($connection, $sub_query);
				$i_pack       = $sub_result[0];
				$i_zeroprice  = $sub_result[1];
				$i_unit1      = $sub_result[2];
				$i_unit2 	  = $sub_result[3]; 
				$i_unitcoef	  = $sub_result[4];
				$i_nonstock   = $sub_result[5];
				$i_minprice   = $sub_result[6];
				$i_expire	  = $sub_result[7];
				$i_withserial = $sub_result[8];
				
				$productionrm_heatno[$i] = $rowsdt[23];
				$productionrm_bundle[$i] = $rowsdt[24];
				
					
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2['.$i.']\')"';
				
				echo"<tr id='CurRec_G2$i' class='$bgcolor $TableFocus'>";		
				echo"	<td width='25px;' $RecStyle>$recno</td>";
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteRecordGridRM('".$filepath."','".$form."', '".$PPrdId."','".$rowsdt[0]."','".$i."','".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."');return false;\" title='Delete Record'  ></td>";
				
				// If ItemWithSerialNo True And ModuleSerialNo True	
				if ($rowsdt[15] == 1 && $Module_SerialNo == 1) {
					echo "	<td width='25px;' align='center' valign='center'><img src='img/button_addserial.png' onMouseOver=\"style.cursor='hand'\" onclick=\"AddSerialNo('".$rowsdt[0]."','".htmlentities($rowsdt[2])."','".$rowsdt[6]."','".$rowsdt[4]."')\" title='Add Serial Nos'  ></td>";
				}
				else if ($rowsdt[15] == 0 && $Module_SerialNo == 1) {
					echo "	<td width='25px;' align='center' valign='center'>&nbsp;</td>";
				}
				
				if ($Module_Pack == 1)
					echo "	<td width='125px;' align='left'><span class='".$TextColor."'>".$rowsdt[1]."</span></td>";
					
				echo "	<td width='140px;' align='left'>
							<input type='hidden' name='txtPrdRMId[$i]' id='prdrmid[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtItemExpire[$i]' id='itemexpirerm[$i]' value='$txtItemExpire[$i]' >
							<input type='hidden' name='txtItemWithSerial[$i]' id='itemwithserialrm[$i]' value='$txtItemWithSerial[$i]' >
							<input type='hidden' name='txtExistingQty[$i]' id='existingqty[$i]' value='$txtExistingQty[$i]' >
							<input type='hidden' name='txtBookingQty[$i]' id='bookingqty[$i]' value='$txtBookingQty[$i]' >
							<input type='hidden' name='txtAvailableQty[$i]' id='availableqty[$i]' value='$txtAvailableQty[$i]' >
							<input type='text' name='txtItemCodeRM[$i]' id='itemcoderm[$i]' value='".$rowsdt[2]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:110px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i'); CheckLookup('chkcodeexists','items','item_code',this.value,'lstItemCodeRM[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'itemcoderm[$i]','itemdescriptionrm[$i]','items');\" ".$KeyDown.">
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemCodeRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItems(9,$i); ' style='vertical-align:bottom;'/></span></label>
						</td>";
										
				echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDescRM[$i]' id='itemdescriptionrm[$i]' value='".$rowsdt[3]."' class='".$ClassE."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDescRM[$i]');\" ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDescRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDesc(9,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
						</td>";
				echo"  	<td width='105px;' align='center'>
							<input type='text' name='txtWarehouseCodeRM[$i]' id='warehousecoderm[$i]' value='".$rowsdt[4]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCodeRM[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecoderm[$i]','warehousenamerm[$i]','warehouse');\" ".$KeyDown."   />
							<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCodeRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouseRM($i);' style='vertical-align:bottom;'/></span></label>
						</td>";
				

				if($Module_Heatno==1)		
				echo"  	<td width='210px;' align='center'>
							<input type='text' name='productionrm_heatno[$i]' id='productionrm_heatno[$i]' value='".$productionrm_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\" ".$KeyDown."   />
							<label><span><img src='img/openlist.png' title='Select HeatNo' id='lstHeatNo[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistHeatNo1($i);' style='vertical-align:bottom;'/></span></label>
						</td>";	
				else echo"<input type='hidden' name='productionrm_heatno[$i]' id='productionrm_heatno[$i]' value='".$productionrm_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\" ".$KeyDown."   />";
				
				if($Module_Heatno==1)		
					echo"  	<td width='210px;' align='center'>
							<input type='text' name='productionrm_bundle[$i]' id='productionrm_bundle[$i]' value='".$productionrm_bundle[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' ".$KeyDown."   />
						</td>";	
				else echo"<input type='hidden' name='productionrm_bundle[$i]' id='productionrm_bundle[$i]' value='".$productionrm_bundle[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' ".$KeyDown."   />";
						
				echo "	<td width='65px;' align='center'><span class='".$TextColor."'>".$rowsdt[17]."</span></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyRM[$i]' id='prddtqtyrm[$i]' value='".$rowsdt[6]."' maxlength='20' onKeyup='CalcPrdDtTotalRM($DecimalBase,$i);' class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";
				
				if ($DisableIdeal == 0) {
					echo"  <td width='75px;' align='center'><input type='text' name='txtPrdDtQtyIdealRM[$i]' id='prddtidealqtyrm[$i]' value='".$rowsdt[7]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' readonly ></td>";
					echo"  <td width='75px;' align='center'><input type='text' name='txtPrdDtWasteCalcRM[$i]' id='prddtwastecalcrm[$i]' value='".$rowsdt[11]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' readonly ></td>";
					echo"  <td width='75px;' align='center'><input type='text' name='txtPrdDtWasteRM[$i]' id='prddtwasterm[$i]' value='".$rowsdt[12]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";
				} else {
					echo"  <input type='hidden' name='txtPrdDtQtyIdealRM[$i]' id='prddtidealqtyrm[$i]' value='' >";
					echo"  <input type='hidden' name='txtPrdDtWasteCalcRM[$i]' id='prddtwastecalcrm[$i]' value='' >";
					echo"  <input type='hidden' name='txtPrdDtWasteRM[$i]' id='prddtwasterm[$i]' value='' >";
				}
				
				if ($FI_ShowCostPrice == 1) {
					echo"	<td width='85px;' align='center'><input type='text' name='txtPrdDtCostPriceRM[$i]' id='costpricerm[$i]' value='".$rowsdt[8]."' maxlength='20' onKeyup='CalcPrdDtTotalRM($DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' ".$KeyDown."  ></td>";
					echo"   <td width='105px;' align='center'><input type='text' name='txtPrdDtTotalRM[$i]' id='prddttotalrm[$i]' value='".$rowsdt[13]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." ></td>";
				} else {
					echo"	<input type='hidden' name='txtPrdDtCostPriceRM[$i]' id='costpricerm[$i]' value='".$rowsdt[8]."' maxlength='20' onKeyup='CalcPrdDtTotalRM($DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' ".$KeyDown."  >";
					echo"   <input type='hidden' name='txtPrdDtTotalRM[$i]' id='prddttotalrm[$i]' value='".$rowsdt[13]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." >";				
				
				}
				
				if ($DisableIdeal == 0) {
					echo"   <td width='105px;' align='center'><input type='text' name='txtPrdDtTotalIdealRM[$i]' id='prddttotalidealrm[$i]' value='".$rowsdt[14]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." ></td>";
				}	
				if ($FI_ShowCostPrice == 1) {
				echo"   <td width='230px;' align='center'><span>";
				echo"  		<input type='radio' name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='1' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." "; if($rowsdt[22]=='1' || $rowsdt[22]=='') echo "checked />"; else echo " />"; echo" <font size=2>"; echo " Percentage";
				echo"	 	<input type='radio' name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='2' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." "; if($rowsdt[22]=='2') echo "checked />"; else echo " />";  echo " Quantity";
				echo"	 	<input type='radio' name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='3' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." "; if($rowsdt[22]=='3') echo "checked />"; else echo " />";  echo " Fixed";
				echo"	</span></td>";
				} else {
					echo"  		<span><input type='radio' hidden  name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='1' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." "; if($rowsdt[22]=='1' || $rowsdt[22]=='') echo "checked />"; else echo " />"; 
					echo"	 	<input type='radio' hidden name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='2' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." "; if($rowsdt[22]=='2') echo "checked />"; else echo " />";  
					echo"	 	<input type='radio'  hidden name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='3' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." "; if($rowsdt[22]=='3') echo "checked />"; else echo " /></span>";  
				}
				
				
				if ($Module_ProjectDt == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDtRM[$i]' id='projectcodedtrm[$i]' value='".$rowsdt[20]."' class='".$ClassE."' style='width:120px;' maxlength='15' onchange=\"SetModRecord('ModRec_G2','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCodeRM[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCodeRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistProjectDt(2,$i); ' style='vertical-align:bottom;'/></span></label></td>";	
				} else {
					echo"  <input type='hidden' name='txtProjectCodeDtRM[$i]' id='projectcodedtrm[$i]' value='' >";
				}
				if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDtRM[$i]' id='costcentcodedtrm[$i]' value='".$rowsdt[21]."' class='".$ClassE."' style='width:130px;' maxlength='15' onchange=\"SetModRecord('ModRec_G2','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCodeRM[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCodeRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(2,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
				} else {
					echo"  <input type='hidden' name='txtCostCentCodeDtRM[$i]' id='costcentcodedtrm[$i]' value='' >";
				}
				
				if ($Module_ExpireDate == 1) {
					echo" 	<td width='105px;' align='center'><input type='text' name='txtPurDtBatchNoRM[$i]' id='batchnorm[$i]' value='".htmlspecialchars($rowsdt[19], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' ".$KeyDown." >
								<label><span><img src='img/openlist.png' title='Select Batch No' id='lstBatchNoRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistBatchNoRM(1,$i); ' style='vertical-align:bottom;'/></span></label></td>
							<td width='85px;' align='center'><input type='text' name='txtPurDtExpireDateRM[$i]' id='expiredaterm[$i]' value='".$rowsdt[18]."' maxlength='10' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassE." date' style='font-size:12px; width:80px; height:20px;' ".$KeyDown." ></td>"; 	 
				} else {
					echo" <input type='hidden' name='txtPurDtExpireDateRM[$i]' id='expiredaterm[$i]' value=''>";
					echo" <input type='hidden' name='txtPurDtBatchNoRM[$i]' id='batchnorm[$i]' value=''>";
				}
					
				
				echo"	<td width='255px;'><input type='text' name='txtPrdDtRemarkRM[$i]' id='remarkdtrm[$i]' value='".htmlspecialchars($rowsdt[5], ENT_QUOTES)."'  maxlength='200'  class='".$ClassE."' style='font-size:12px; width:245px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";	
				echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_2[$i]' onclick=\"SubmitRecordGridRM('".$i."','".$filepath."', '".$form."', '".$PPrdId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."'); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
				echo "</tr>";
						
				
				$i+=1;
				
				$LastItemWarehouse = $rowsdt[4];
			}
			
			
		}
		
		
							
		for ($k=1;$k <= 1;$k++) {
			$recno = $i+1;
			$mode = 'i';
			
			if ($i%2==0) $bgcolor='bgcolor1';
			else $bgcolor='bgcolor2';	
			
			if (empty($txtWarehouseCodeRM[$i])) {
				if (!empty($LastItemWarehouse))
					$txtWarehouseCodeRM[$i] = $LastItemWarehouse;
				else if (!empty($SetupDftWareHouse))
					$txtWarehouseCodeRM[$i] = $SetupDftWareHouse;
				else	
					$txtWarehouseCodeRM[$i] = $defaultwarehouse;
			}

			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2['.$i.']\')"';
			$KeyDown1  = "onkeydown=\"return dokey1(event,this,".$i.",'".$columnslist."','imgSubmit_2[".$i."]','1');\" ";		
		
				
			echo"<tr id='CurRec_G2$i' class='$bgcolor $TableFocus' >";
			echo"	<td width='25px;'>$recno</td>";
			echo"	<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G2');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
			
			if ($Module_SerialNo == 1) {
				echo "	<td width='25px;' align='center' valign='center'>&nbsp;</td>";
			}
			
			if ($Module_Pack == 1)
				echo"  <td width='125px;' align='center'><span>&nbsp;</span></td>";
				
			echo "	<td width='140px;' align='left'>
						<input type='hidden' name='txtPrdRMId[$i]' id='prdrmid[$i]' value='$txtPrdRMId[$i]' >
						<input type='hidden' name='txtItemExpire[$i]' id='itemexpirerm[$i]' value='$txtItemExpire[$i]' >
						<input type='hidden' name='txtItemWithSerial[$i]' id='itemwithserialrm[$i]' value='$txtItemWithSerial[$i]' >
						<input type='hidden' name='txtExistingQty[$i]' id='existingqty[$i]' value='$txtExistingQty[$i]' >
						<input type='hidden' name='txtBookingQty[$i]' id='bookingqty[$i]' value='$txtBookingQty[$i]' >
						<input type='hidden' name='txtAvailableQty[$i]' id='availableqty[$i]' value='$txtAvailableQty[$i]' >
						<input type='text' name='txtItemCodeRM[$i]' id='itemcoderm[$i]' value='$txtItemCodeRM[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:110px; height:20px;'   onchange=\"SetModRecord('ModRec_G2','$i'); GetSelectedItem(this.id,'getitem','".$i."','".$txtDate."','".$txtCurrCode."','-4'); CheckLookup('chkcodeexists','items','item_code',this.value,'lstItemCodeRM[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'itemcoderm[$i]','itemdescriptionrm[$i]','items');\"  ".$KeyDown1.">
						<label><span><img src='img/openlist.png' title='Select Item' id='lstItemCodeRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItems(9,$i); ' style='vertical-align:bottom;'/></span></label>
					</td>";
									
			echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDescRM[$i]' id='itemdescriptionrm[$i]' value='$txtItemDescRM[$i]'  class='".$ClassI."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDescRM[$i]');\" ".$KeyDown." />
						<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDescRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDesc(9,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
					</td>";
			echo"  	<td width='105px;' align='center'>
						<input type='text' name='txtWarehouseCodeRM[$i]' id='warehousecoderm[$i]' value='$txtWarehouseCodeRM[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:75px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCodeRM[$i]'); \" onkeyup=\"AutoCompleteData(event,this.id,'warehousecoderm[$i]','warehousenamerm[$i]','warehouse');\"  ".$KeyDown."  />
						<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCodeRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouseRM($i);' style='vertical-align:bottom;'/></span></label>
					</td>";
					
					
				if($Module_Heatno==1)		
				echo"  	<td width='210px;' align='center'>
							<input type='text' name='productionrm_heatno[$i]' id='productionrm_heatno[$i]' value='".$productionrm_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\" ".$KeyDown."   />
							<label><span><img src='img/openlist.png' title='Select HeatNo' id='lstHeatNo[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistHeatNo1($i);' style='vertical-align:bottom;'/></span></label>
						</td>";	
				else echo"<input type='hidden' name='productionrm_heatno[$i]' id='productionrm_heatno[$i]' value='".$productionrm_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\" ".$KeyDown."   />";
				
				if($Module_Heatno==1)		
					echo"  	<td width='210px;' align='center'>
							<input type='text' name='productionrm_bundle[$i]' id='productionrm_bundle[$i]' value='".$productionrm_bundle[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' ".$KeyDown."   />
						</td>";	
				else echo"<input type='hidden' name='productionrm_bundle[$i]' id='productionrm_bundle[$i]' value='".$productionrm_bundle[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' ".$KeyDown."   />";
				
			echo"   <td width='65px;' align='center'><input type='text' name='txtItemUnit1RM' id='itemunit1rm[$i]' value='$txtItemUnit1RM' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:60px; height:20px;' readonly></td>";
			echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyRM[$i]' id='prddtqtyrm[$i]' value='$txtPrdDtQtyRM[$i]' maxlength='20' onKeyup='CalcPrdDtTotalRM($DecimalBase,$i);' class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." ></td>";
			
			if ($DisableIdeal == 0) {
				echo"  <td width='75px;' align='center'><input type='text' name='txtPrdDtQtyIdealRM[$i]' id='prddtidealqtyrm[$i]' value='$txtPrdDtQtyIdealRM[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' readonly ></td>";
				echo"  <td width='75px;' align='center'><input type='text' name='txtPrdDtWasteCalcRM[$i]' id='prddtwastecalcrm[$i]' value='$txtPrdDtWasteCalcRM[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' readonly ></td>";
				echo"  <td width='75px;' align='center'><input type='text' name='txtPrdDtWasteRM[$i]' id='prddtwasterm[$i]' value='$txtPrdDtWasteRM[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";
			} else {
				echo"  <input type='hidden' name='txtPrdDtQtyIdealRM[$i]' id='prddtidealqtyrm[$i]' value='' >";
				echo"  <input type='hidden' name='txtPrdDtWasteCalcRM[$i]' id='prddtwastecalcrm[$i]' value='' >";
				echo"  <input type='hidden' name='txtPrdDtWasteRM[$i]' id='prddtwasterm[$i]' value='' >";
			}
			if ($FI_ShowCostPrice == 1) {
				echo"	<td width='85px;' align='center'><input type='text' name='txtPrdDtCostPriceRM[$i]' id='costpricerm[$i]' value='$txtPrdDtCostPriceRM[$i]' maxlength='20' onKeyup='CalcPrdDtTotalRM($DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' ".$KeyDown."  ></td>";
				echo"   <td width='105px;' align='center'><input type='text' name='txtPrdDtTotalRM[$i]' id='prddttotalrm[$i]' value='$txtPrdDtTotalRM[$i]' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." ></td>";
				} else {
				echo"	<input type='hidden' name='txtPrdDtCostPriceRM[$i]' id='costpricerm[$i]' value='$txtPrdDtCostPriceRM[$i]' maxlength='20' onKeyup='CalcPrdDtTotalRM($DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' ".$KeyDown."  >";
				echo"   <input type='hidden' name='txtPrdDtTotalRM[$i]' id='prddttotalrm[$i]' value='$txtPrdDtTotalRM[$i]' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." >";				
				}
			if ($DisableIdeal == 0) {
				echo"   <td width='105px;' align='center'><input type='text' name='txtPrdDtTotalIdealRM[$i]' id='prddttotalidealrm[$i]' value='$txtPrdDtTotalIdealRM[$i]' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." ></td>";
			}	
			if ($FI_ShowCostPrice == 1) {	
			echo"   <td width='230px;' align='center'><span>";
			echo"  		<input type='radio' name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='1' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown."  />";echo" <font size=2>"; echo " Percentage";
			echo"	 	<input type='radio' name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='2' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." checked/>";  echo " Quantity";
			echo"	 	<input type='radio' name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='3' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." />";  echo " Fixed";
			echo"	</span></td>";
			} else {
			echo"  		<span><input type='radio'  hidden name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='1' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown."  />";
			echo"	 	<input type='radio' hidden  name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='2' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." checked/>";  
			echo"	 	<input type='radio' hidden name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='3' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." /></span>";  
			}
			
			if ($Module_ProjectDt == 1) {
				echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDtRM[$i]' id='projectcodedtrm[$i]' value='$txtProjectCodeDtRM[$i]' class='".$ClassI."' style='width:120px;' maxlength='15' onchange=\"SetModRecord('ModRec_G2','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCodeRM[$i]');\" ".$KeyDown." /></span>
						<label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCodeRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistProjectDt(2,$i); ' style='vertical-align:bottom;'/></span></label></td>";	
			} else {
				echo"  <input type='hidden' name='txtProjectCodeDtRM[$i]' id='projectcodedtrm[$i]' value='' >";
			}
			if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) {
				echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDtRM[$i]' id='costcentcodedtrm[$i]' value='$txtCostCentCodeDtRM[$i]' class='".$ClassI."' style='width:130px;' maxlength='15' onchange=\"SetModRecord('ModRec_G2','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCodeRM[$i]');\" ".$KeyDown." /></span>
						<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCodeRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(2,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
			} else {
				echo"  <input type='hidden' name='txtCostCentCodeDtRM[$i]' id='costcentcodedtrm[$i]' value='' >";
			}
			
			if ($Module_ExpireDate == 1) {
				echo" 	<td width='105px;' align='center'><input type='text' name='txtPurDtBatchNoRM[$i]' id='batchnorm[$i]' value='".htmlspecialchars($txtPurDtBatchNoRM[$i], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassI."' style='font-size:12px; width:75px; height:20px;' ".$KeyDown." >
							<label><span><img src='img/openlist.png' title='Select Batch No' id='lstBatchNoRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistBatchNoRM(1,$i); ' style='vertical-align:bottom;'/></span></label></td>
						<td width='85px;' align='center'><input type='text' name='txtPurDtExpireDateRM[$i]' id='expiredaterm[$i]' value='$txtPurDtExpireDateRM[$i]' maxlength='10' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassI." date' style='font-size:12px; width:80px; height:20px;' ".$KeyDown." ></td>"; 	 
			} else {
				echo" <input type='hidden' name='txtPurDtExpireDateRM[$i]' id='expiredaterm[$i]' value=''>";
				echo" <input type='hidden' name='txtPurDtBatchNoRM[$i]' id='batchnorm[$i]' value=''>";
			}
				
				
			echo"	<td width='255px;'><input type='text' name='txtPrdDtRemarkRM[$i]' id='remarkdtrm[$i]' value='".htmlspecialchars($txtPrdDtRemarkRM[$i], ENT_QUOTES)."'  maxlength='200' class='".$ClassI."'  style='font-size:12px; width:245px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";	
			echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_2[$i]' onclick=\"SubmitRecordGridRM('".$i."','".$filepath."', '".$form."', '".$PPrdId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."'); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
			echo"</tr>";  

			$i+=1;	
		}
		

	
	echo"	</table>";  
	echo"	</div>";
	
	showDataGridFooter($filepath,$form,$PPrdId,'datagrid-1',$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	
	echo"</div>";
	
	 
	
	$query = " Select Count(*) FROM Temp_ProductionRM ".
			 " WHERE ProductionHD_Id = ".$PPrdId;
	$result = selectData($connection, $query);
	$txtPrdCountRM = $result[0];
	if($txtPrdCountRM == '') $txtPrdCountRM = 0;
	
	
	echo"<input type='hidden' name='txtPrdCountRM' value='$txtPrdCountRM' >";
	
}

function ShowProdTplDtGridFG($connection,$form,$PPrdId,$arrayparams,$arrayaccess,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction){
	
	$Module_Pack = $arrayparams['Module_Pack'];
	
	$SetupDftWareHouse = $arrayparams['SetupDftWareHouse'];
	$defaultwarehouse  = $arrayparams['defaultwarehouse'];
	
	$DecimalBase = $arrayparams['DecimalBase'];
	$Base1       = $arrayparams['Base1'];
	$Base2       = $arrayparams['Base2'];
	$txtDate     = $arrayparams['txtDate'];
	
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_DataGrid_Production.php';
	
	$i = 0;
	$k = 0;
	
	if ($startrange=='') $startrange = 0;
	if ($perpage=='')	 $perpage = 50;
	if ($orderby=='')	 $orderby = $dftorderby;
	if ($morelines=='')	 $morelines = 1;
	
	if ($action == 'COR' || $direction == '') {
		if ($direction == 'asc') $direction = 'desc';
		else if ($direction == 'desc') $direction = 'asc';
		else $direction = 'asc';
	}
	
	$columnsarray = array("itemcodefg", "itemdescriptionfg", "warehousecodefg", "prddtqtyfgf", "prddtqtyfg", "prdcostoptionfg", "remarkdtfg");
	$columnsarrayall = array("itemcodefg", "itemdescriptionfg", "warehousecodefg", "prddtqtyfg", "prddtqtyfgf", "remarkdtfg", "prdfgid");
	$orderbyarray = array("ProdRecipeFG.Item_CodePacked", "Items.Item_Code", "Items.Item_Description", "ProdRecipeFG.Warehouse_Code", "Items.Item_UnitSalesDesc");
	
	for ($j=1; $j<=count($orderbyarray); $j++){
				
		$index = array_search($orderby, $orderbyarray);
		$index += 1;
		
		$orderimg = 'orderimg'.$index;
		
		if (in_array($orderby, $orderbyarray) && $direction=='asc')
			$$orderimg = "<img src='img/asc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";
		else if (in_array($orderby, $orderbyarray) && $direction=='desc')
			$$orderimg = "<img src='img/desc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";	
		else
			$$orderimg = "";
			
	}	

		
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
	
	
	$TableWidth = 1225;
	if ($Module_Pack == 1) $TableWidth += 125;
	
	
	//Initializations for Div Ids
	$ContainerDiv = 'container1';
	$LoaderDiv    = 'Loader1';
	$HeaderDiv    = 'grid_headerDiv1';
	$ContentDiv   = 'grid_contentDiv1';
	$TableFocus   = 'table-focus-g1';
	
	$TableWidthStyle = 'width:'.$TableWidth.'px;';
	
	echo"<div id='$ContainerDiv' style='position: relative;z-index:1;' >";
	echo"	<div id='$LoaderDiv' class=''></div>";
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:1073px;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
	
		echo"<tr height='25'>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		
		if ($Module_Pack == 1)
			echo"  <th width='125px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','ProdRecipeFG.Item_CodePacked','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code Packed".$orderimg1."</span></th>";
			
		echo"  <th width='140px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code".$orderimg2."</span></th>";
		echo"  <th width='205px;' align='left' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_Description','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Description".$orderimg3."</span></th>";
		echo"  <th width='105px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','ProdRecipeFG.Warehouse_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Warehouse".$orderimg4."</span></th>";
		echo"  <th width='65px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_UnitSalesDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Unit1".$orderimg5."</span></th>";
		echo"  <th width='75px;' align='center'><span>Qty From</span></th> ";	
		echo"  <th width='75px;' align='center'><span>Qty To</span></th> ";	
		echo"  <th width='230px;' align='center'><span>Cost Option</span></th>";
		echo"  <th width='255px;' align='center'><span>Remark</span></th>";	
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv');\" style='width:1090px;height:135px;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
		echo"<input type='hidden' name='SelectedRec_G1' id='SelectedRec_G1' value='$SelectedRec_G1'>
			 <input type='hidden' name='SelectedRecColor_G1' id='SelectedRecColor_G1' value='$SelectedRecColor_G1'>
			 <input type='hidden' name='ModRec_G1' id='ModRec_G1' value='$ModRec_G1'>";  
		
			 
		
		
		if ($PPrdId != '' ) {
		      
			$query = " Select ProdRecipeFG.ProdRecipeFG_ID, ProdRecipeFG.Item_CodePacked, ProdRecipeFG.Item_code, Item_Description, ProdRecipeFG.Warehouse_Code, ".
					 " ProdRecipeFG_Remark, ProdRecipeFG_QuantityFrom, ProdRecipeFG_Quantity, ProdRecipeFG_DistOption, Items.Item_UnitPurchaseDesc ".
					 " From ProdRecipeFG Left Join Items on ProdRecipeFG.Item_code = Items.Item_code ".
					 " Where ProdRecipeFG.ProdRecipe_ID = ".$PPrdId.
					 " Order By $orderby $direction ";
					 
			//echo $query;
					
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);

			$query = $query." limit ".$startrange.",".$perpage;
			$resultdt=mysql_query($query,$connection);
			
			
			while($rowsdt=mysql_fetch_array($resultdt)){
			    				
				$recno = $i+1;
				$k = $k + 1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$TextColor = 'style7';
				
				$sub_query = " SELECT ifNull(Item_Pack, 0), ifNull(item_zeroPrice, 0), Item_UnitSalesDesc, Item_UnitPurchaseDesc, ifNull(Item_Unit,1), ifNull(Item_NonStock, 0), ifNull(Item_MinimumPrice, 0), ifNull(Item_Expire,0), ifNull(item_withserialno,0) ".
							 " FROM Items ".
							 " WHERE Items.Item_Code = '".$rowsdt[2]."'";
					
				//echo "<br><br>".$sub_query;
				$sub_result = selectData($connection, $sub_query);
				$i_pack       = $sub_result[0];
				$i_zeroprice  = $sub_result[1];
				$i_unit1      = $sub_result[2];
				$i_unit2 	  = $sub_result[3]; 
				$i_unitcoef	  = $sub_result[4];
				$i_nonstock   = $sub_result[5];
				$i_minprice   = $sub_result[6];
				$i_expire	  = $sub_result[7];
				$i_withserial = $sub_result[8];
				
				
				
					
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_1['.$i.']\')"';
				
				echo"<tr id='CurRec_G1$i' class='$bgcolor $TableFocus'>";		
				echo"	<td width='25px;' $RecStyle>$recno</td>";
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteRecordGridFG('".$filepath."','".$form."', '".$PPrdId."','".$rowsdt[0]."','".$i."','".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."');return false;\" title='Delete Record'  ></td>";
				
				if ($Module_Pack == 1)
					echo "	<td width='125px;' align='left'><span class='".$TextColor."'>".$rowsdt[1]."</span></td>";
					
				echo "	<td width='140px;' align='left'>
							<input type='hidden' name='txtPrdFGId[$i]' id='prdfgid[$i]' value='".$rowsdt[0]."' >
							<input type='text' name='txtItemCodeFG[$i]' id='itemcodefg[$i]' value='".$rowsdt[2]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:110px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','items','item_code',this.value,'lstItemCodeFG[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'itemcodefg[$i]','itemdescriptionfg[$i]','items');\" ".$KeyDown.">
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsFG(1,$i); ' style='vertical-align:bottom;'/></span></label>
						</td>";
										
				echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDescFG[$i]' id='itemdescriptionfg[$i]' value='".$rowsdt[3]."' class='".$ClassE."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDescFG[$i]');\" ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDescFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDescFG(1,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
						</td>";
				echo"  	<td width='105px;' align='center'>
							<input type='text' name='txtWarehouseCodeFG[$i]' id='warehousecodefg[$i]' value='".$rowsdt[4]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCodeFG[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecodefg[$i]','warehousenamefg[$i]','warehouse');\" ".$KeyDown."   />
							<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouseFG($i);' style='vertical-align:bottom;'/></span></label>
						</td>";
						
				echo "	<td width='65px;' align='center'><span class='".$TextColor."'>".$rowsdt[9]."</span></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyFGF[$i]' id='prddtqtyfgf[$i]' value='".$rowsdt[6]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyFG[$i]' id='prddtqtyfg[$i]' value='".$rowsdt[7]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
				
				echo"   <td width='230px;' align='center'><span>";
				echo"  		<input type='radio' name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='1' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." "; if($rowsdt[8]=='1' || $rowsdt[8]=='') echo "checked />"; else echo " />"; echo"<font size=2>";echo " Percentage";
				echo"	 	<input type='radio' name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='2' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." "; if($rowsdt[8]=='2') echo "checked />"; else echo " />";  echo " Quantity";
				echo"	 	<input type='radio' name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='3' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." "; if($rowsdt[8]=='3') echo "checked />"; else echo " />";  echo " Fixed";
				echo"	</span></td>";
				
				echo"	<td width='255px;'><input type='text' name='txtPrdDtRemarkFG[$i]' id='remarkdtfg[$i]' value='".htmlspecialchars($rowsdt[5], ENT_QUOTES)."'  maxlength='200'  class='".$ClassE."' style='font-size:12px; width:245px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";	
				echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_1[$i]' onclick=\"SubmitRecordGridFG('".$i."','".$filepath."', '".$form."', '".$PPrdId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."'); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
				echo "</tr>";
						
				
				$i+=1;
				
				$LastItemWarehouse = $rowsdt[4];
			}
			
			
		}
		
		
							
		for ($k=1;$k <= 1;$k++) {
			$recno = $i+1;
			$mode = 'i';
			
			if ($i%2==0) $bgcolor='bgcolor1';
			else $bgcolor='bgcolor2';	
			
			if (empty($txtWarehouseCodeFG[$i])) {
				if (!empty($LastItemWarehouse))
					$txtWarehouseCodeFG[$i] = $LastItemWarehouse;
				else if (!empty($SetupDftWareHouse))
					$txtWarehouseCodeFG[$i] = $SetupDftWareHouse;
				else	
					$txtWarehouseCodeFG[$i] = $defaultwarehouse;
			}

			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_1['.$i.']\')"';
			
				
			echo"<tr id='CurRec_G1$i' class='$bgcolor $TableFocus' >";
			echo"	<td width='25px;'>$recno</td>";
			echo"	<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G1');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
			
			if ($Module_Pack == 1)
				echo"  <td width='125px;' align='center'><span>&nbsp;</span></td>";
				
			echo "	<td width='140px;' align='left'>
						<input type='hidden' name='txtPrdFGId[$i]' id='prdfgid[$i]' value='$txtPrdFGId[$i]' >
						<input type='text' name='txtItemCodeFG[$i]' id='itemcodefg[$i]' value='$txtItemCodeFG[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:110px; height:20px;'  onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','items','item_code',this.value,'lstItemCodeFG[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'itemcodefg[$i]','itemdescriptionfg[$i]','items');\"  ".$KeyDown.">
						<label><span><img src='img/openlist.png' title='Select Item' id='lstItemCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsFG(1,$i); ' style='vertical-align:bottom;'/></span></label>
					</td>";
									
			echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDescFG[$i]' id='itemdescriptionfg[$i]' value='$txtItemDescFG[$i]'  class='".$ClassI."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDescFG[$i]');\" ".$KeyDown." />
						<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDescFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDescFG(1,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
					</td>";
			echo"  	<td width='105px;' align='center'>
						<input type='text' name='txtWarehouseCodeFG[$i]' id='warehousecodefg[$i]' value='$txtWarehouseCodeFG[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:75px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCodeFG[$i]'); \" onkeyup=\"AutoCompleteData(event,this.id,'warehousecodefg[$i]','warehousenamefg[$i]','warehouse');\"  ".$KeyDown."  />
						<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouseFG($i);' style='vertical-align:bottom;'/></span></label>
					</td>";
					
			echo"   <td width='65px;' align='center'><input type='text' name='txtItemUnit1FG' id='itemunit1fg[$i]' value='$txtItemUnit1FG' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:60px; height:20px;' readonly></td>";
			echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyFGF[$i]' id='prddtqtyfgf[$i]' value='$txtPrdDtQtyFGF[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." ></td>";
			echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyFG[$i]' id='prddtqtyfg[$i]' value='$txtPrdDtQtyFG[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." ></td>";
			
			echo"   <td width='230px;' align='center'><span>";
			echo"  		<input type='radio' name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='1' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." checked />"; echo"<font size=2>";echo " Percentage ";
			echo"	 	<input type='radio' name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='2' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." />";  echo " Quantity";
			echo"	 	<input type='radio' name='txtCostOptionFG[$i]' id='prdcostoptionfg[$i]' value='3' onchange=\"SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." />";  echo " Fixed";
			echo"	</span></td>";
				
			echo"	<td width='255px;'><input type='text' name='txtPrdDtRemarkFG[$i]' id='remarkdtfg[$i]' value='".htmlspecialchars($txtPrdDtRemarkFG[$i], ENT_QUOTES)."'  maxlength='200' class='".$ClassI."'  style='font-size:12px; width:245px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";	
			echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_1[$i]' onclick=\"SubmitRecordGridFG('".$i."','".$filepath."', '".$form."', '".$PPrdId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."'); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
			echo"</tr>";  

			$i+=1;	
		}
		

	
	echo"	</table>";  
	echo"	</div>";
	
	showDataGridFooter($filepath,$form,$PPrdId,'datagrid',$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	
	echo"</div>";
	
	
}


function ShowProdGridSummary($connection,$PPrdId,$arrayparams,$arrayaccess){

	$DecimalBase  = $arrayparams['DecimalBase'];
	
	$Base1 = $arrayparams['Base1'];
	$Base2 = $arrayparams['Base2'];
	$txtCurr = $arrayparams['txtCurrCode']; 
	
	if ($PPrdId != "") {
		$sub_query = " Select ProductionSummaryRM.ProductionSummaryRM_Id, ProductionSummaryRM.Item_Code, Items.Item_Description, ".
					 " ifNull(ProductionSummaryRM_Quantity,0) As ActualQty, ifNull(ProductionSummaryRM_IdealQty,0) As IdealQty, ProductionSummaryRM_Multiplier, Items.Item_UnitSalesDesc ".
					 " From Temp_ProductionSummaryRM As ProductionSummaryRM Left Join Items on ProductionSummaryRM.Item_Code = Items.Item_code ".
					 " Where ProductionSummaryRM.ProductionHD_Id = '".$PPrdId."' ".
					 " Order By ProductionSummaryRM.Item_Code ";
		//echo $sub_query;
		
		echo"<table border='0' class='grid_data'>
			  <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"  <th align='left'><span>&nbsp;</span></th>";
		echo"  <th align='left'><span>Item Code</span></th>";
		echo"  <th align='left'><span>Description</span></th>";
		echo"  <th align='center'><span>Unit</span></th>";
		echo"  <th align='center'><span>Actual Qty</span></th>";
		echo"  <th align='center'><span>Ideal Qty</span></th>";
		echo"  <th align='center'><span>Multiplier</span></th>";
		echo"</tr>";		  
			
		$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());
		while($sub_rows=mysql_fetch_array($sub_result)){
			
			if ($i%2==0) $bgcolor='bgcolor1';
			else $bgcolor='bgcolor2';
							
						
			echo "<tr class='$bgcolor' >";
			echo "	<td align='center' valign='center'><span><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateSummaryQty('".$sub_rows[0]."') title='Edit Record'  ></span></td>";
			echo "	<td align='left'><span>".$sub_rows[1]."</span></td>";
			echo "	<td align='left'><span>".$sub_rows[2]."</span></td>";
			echo "	<td align='center'><span>".$sub_rows[6]."</span></td>";
			echo "	<td align='right'><span>".number_format($sub_rows[3], $DecimalBase)."</span></td>";
			echo "	<td align='right'><span>".number_format($sub_rows[4], $DecimalBase)."</span></td>";
			echo "	<td align='right'><span>".number_format($sub_rows[5], $DecimalBase)."</span></td>";
			echo "</tr>";
				
			$i+=1;
		}
			
		echo "</table>";
		
	} 

}


function ShowProdTplDtGridRM($connection,$form,$PPrdId,$arrayparams,$arrayaccess,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction){
	
	$Module_Pack = $arrayparams['Module_Pack'];
	
	$SetupDftWareHouse = $arrayparams['SetupDftWareHouse'];
	$defaultwarehouse  = $arrayparams['defaultwarehouse'];
	
	$DecimalBase = $arrayparams['DecimalBase'];
	$Base1       = $arrayparams['Base1'];
	$Base2       = $arrayparams['Base2'];
	$txtDate     = $arrayparams['txtDate'];
	$DefaultCur  = $arrayparams['DefaultCur'];
	
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_DataGrid_Production.php';
	
	$i = 0;
	$k = 0;
	
	if ($startrange=='') $startrange = 0;
	if ($perpage=='')	 $perpage = 50;
	if ($orderby=='')	 $orderby = $dftorderby;
	if ($morelines=='')	 $morelines = 1;
	
	if ($action == 'COR' || $direction == '') {
		if ($direction == 'asc') $direction = 'desc';
		else if ($direction == 'desc') $direction = 'asc';
		else $direction = 'asc';
	}
	
	$columnsarray = array("itemcoderm", "itemdescriptionrm", "warehousecoderm", "prddtqtyrmf", "prddtqtyrm", "prdcostoptionrm", "currencycoderm", "costpricerm", "wasteraterm", "wasteperbilletrm", "remarkdtrm");
	$columnsarrayall = array("itemcoderm", "itemdescriptionrm", "warehousecoderm", "prddtqtyrm", "prddtqtyrmf", "currencycoderm", "costpricerm", "wasteraterm", "wasteperbilletrm", "remarkdtrm", "prdrmid");
	$orderbyarray = array("ProdRecipeRM.Item_CodePacked", "Items.Item_Code", "Items.Item_Description", "ProdRecipeRM.Warehouse_Code", "Items.Item_UnitSalesDesc");
	
	for ($j=1; $j<=count($orderbyarray); $j++){
				
		$index = array_search($orderby, $orderbyarray);
		$index += 1;
		
		$orderimg = 'orderimg'.$index;
		
		if (in_array($orderby, $orderbyarray) && $direction=='asc')
			$$orderimg = "<img src='img/asc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";
		else if (in_array($orderby, $orderbyarray) && $direction=='desc')
			$$orderimg = "<img src='img/desc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";	
		else
			$$orderimg = "";
			
	}	

		
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
	
	
	$TableWidth = 1520;
	if ($Module_Pack == 1) $TableWidth += 125;
	
	
	//Initializations for Div Ids
	$ContainerDiv = 'container2';
	$LoaderDiv    = 'Loader2';
	$HeaderDiv    = 'grid_headerDiv2';
	$ContentDiv   = 'grid_contentDiv2';
	$TableFocus   = 'table-focus-g2';
	
	$TableWidthStyle = 'width:'.$TableWidth.'px;';
	
	echo"<div id='$ContainerDiv' style='position: relative;z-index:1;' >";
	echo"	<div id='$LoaderDiv' class=''></div>";
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:1073px;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
	
		echo"<tr height='25'>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		
		if ($Module_Pack == 1)
			echo"  <th width='125px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','ProdRecipeRM.Item_CodePacked','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code Packed".$orderimg1."</span></th>";
			
		echo"  <th width='140px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code".$orderimg2."</span></th>";
		echo"  <th width='205px;' align='left' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_Description','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Description".$orderimg3."</span></th>";
		echo"  <th width='105px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','ProdRecipeRM.Warehouse_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Warehouse".$orderimg4."</span></th>";
		echo"  <th width='65px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_UnitSalesDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Unit1".$orderimg5."</span></th>";
		echo"  <th width='75px;' align='center'><span>Qty From</span></th> ";	
		echo"  <th width='75px;' align='center'><span>Qty To</span></th> ";	
		echo"  <th width='230px;' align='center'><span>Cost Option</span></th>";
		echo"  <th width='60px;' align='center'><span>Currency</span></th>";
		echo"  <th width='85px;' align='center'><span>Cost Price</span></th>";
		echo"  <th width='75px;' align='center'><span>Waste Rate(%)</span></th>";
		echo"  <th width='75px;' align='center'><span>Waste Per Billet(%)</span></th>";
		echo"  <th width='255px;' align='center'><span>Remark</span></th>";	
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv');\" style='width:1090px;height:135px;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
		echo"<input type='hidden' name='SelectedRec_G2' id='SelectedRec_G2' value='$SelectedRec_G2'>
			 <input type='hidden' name='SelectedRecColor_G2' id='SelectedRecColor_G2' value='$SelectedRecColor_G2'>
			 <input type='hidden' name='ModRec_G2' id='ModRec_G2' value='$ModRec_G2'>";  
		
			 
		
		
		if ($PPrdId != '' ) {
	
			$query = " Select ProdRecipeRM.ProdRecipeRM_ID, ProdRecipeRM.Item_CodePacked, ProdRecipeRM.Item_code, Item_Description, ProdRecipeRM.Warehouse_Code, ".
					 " ProdRecipeRM_Remark, ProdRecipeRM_QuantityFrom, ProdRecipeRM_Quantity, ProdRecipeRM_DistOption, Items.Item_UnitPurchaseDesc, ".
					 " ProdRecipeRM.Currency_Code, ProdRecipeRM_Cost, ProdRecipeRM_WasteRate, ProdRecipeRM_WastePerBillet ".
					 " From ProdRecipeRM Left Join Items on ProdRecipeRM.Item_code = Items.Item_code ".
					 " Where ProdRecipeRM.ProdRecipe_ID = ".$PPrdId.
					 " Order By $orderby $direction ";
					 
			//echo $query;
					
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);

			$query = $query." limit ".$startrange.",".$perpage;
			$resultdt=mysql_query($query,$connection);
			
			
			while($rowsdt=mysql_fetch_array($resultdt)){
			    				
				$recno = $i+1;
				$k = $k + 1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$TextColor = 'style7';
				
				$sub_query = " SELECT ifNull(Item_Pack, 0), ifNull(item_zeroPrice, 0), Item_UnitSalesDesc, Item_UnitPurchaseDesc, ifNull(Item_Unit,1), ifNull(Item_NonStock, 0), ifNull(Item_MinimumPrice, 0), ifNull(Item_Expire,0), ifNull(item_withserialno,0) ".
							 " FROM Items ".
							 " WHERE Items.Item_Code = '".$rowsdt[2]."'";
					
				//echo "<br><br>".$sub_query;
				$sub_result = selectData($connection, $sub_query);
				$i_pack       = $sub_result[0];
				$i_zeroprice  = $sub_result[1];
				$i_unit1      = $sub_result[2];
				$i_unit2 	  = $sub_result[3]; 
				$i_unitcoef	  = $sub_result[4];
				$i_nonstock   = $sub_result[5];
				$i_minprice   = $sub_result[6];
				$i_expire	  = $sub_result[7];
				$i_withserial = $sub_result[8];
				
				
				$querycurrency="select currency_code from currency order by currency_code";
				$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error($connection));

					
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2['.$i.']\')"';
				
				echo"<tr id='CurRec_G2$i' class='$bgcolor $TableFocus'>";		
				echo"	<td width='25px;' $RecStyle>$recno</td>";
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteRecordGridRM('".$filepath."','".$form."', '".$PPrdId."','".$rowsdt[0]."','".$i."','".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."');return false;\" title='Delete Record'  ></td>";
				
				if ($Module_Pack == 1)
					echo "	<td width='125px;' align='left'><span class='".$TextColor."'>".$rowsdt[1]."</span></td>";
					
				echo "	<td width='140px;' align='left'>
							<input type='hidden' name='txtPrdRMId[$i]' id='prdrmid[$i]' value='".$rowsdt[0]."' >
							<input type='text' name='txtItemCodeRM[$i]' id='itemcoderm[$i]' value='".$rowsdt[2]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:110px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i'); CheckLookup('chkcodeexists','items','item_code',this.value,'lstItemCodeRM[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'itemcoderm[$i]','itemdescriptionrm[$i]','items');\" ".$KeyDown.">
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemCodeRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsRM(1,$i); ' style='vertical-align:bottom;'/></span></label>
						</td>";
										
				echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDescRM[$i]' id='itemdescriptionrm[$i]' value='".$rowsdt[3]."' class='".$ClassE."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDescRM[$i]');\" ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDescRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDescRM(1,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
						</td>";
				echo"  	<td width='105px;' align='center'>
							<input type='text' name='txtWarehouseCodeRM[$i]' id='warehousecoderm[$i]' value='".$rowsdt[4]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCodeRM[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecoderm[$i]','warehousenamerm[$i]','warehouse');\" ".$KeyDown."   />
							<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCodeRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouseRM($i);' style='vertical-align:bottom;'/></span></label>
						</td>";
						
				echo "	<td width='65px;' align='center'><span class='".$TextColor."'>".$rowsdt[9]."</span></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyRMF[$i]' id='prddtqtyrmf[$i]' value='".$rowsdt[6]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyRM[$i]' id='prddtqtyrm[$i]' value='".$rowsdt[7]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";
				
				echo"   <td width='230px;' align='center'><span>";
				echo"  		<input type='radio' name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='1' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." "; if($rowsdt[8]=='1' || $rowsdt[8]=='') echo "checked />"; else echo " />";echo" <font size=2>"; echo " Percentage";
				echo"	 	<input type='radio' name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='2' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." "; if($rowsdt[8]=='2') echo "checked />"; else echo " />";  echo " Quantity";
				echo"	 	<input type='radio' name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='3' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." "; if($rowsdt[8]=='3') echo "checked />"; else echo " />";  echo " Fixed";
				echo"	</span></td>";
				
				echo"   <td width='60px;' align='center'><select name='txtCurrencyCodeRM[$i]' id='currencycoderm[$i]' class='".$ClassE."' style='font-size:12px; width:55px; height:20px;' onChange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." >";
				echo"	<option></option>";
				while($curf=mysql_fetch_row($resultcurrency)){
					echo"<option ";
					if ($rowsdt[10]==$curf[0])	echo " selected ";
					echo" value='$curf[0]'>$curf[0] </option>";
				}
				echo"	</select></td>";	
				
				echo"	<td width='85px;' align='center'><input type='text' name='txtPrdDtCostRM[$i]' id='costpricerm[$i]' value='".$rowsdt[11]."' maxlength='20' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' ".$KeyDown."  ></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtWasteRateRM[$i]' id='wasteraterm[$i]' value='".$rowsdt[12]."' maxlength='20' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassE."' style='font-size:12px; width:70px; height:20px;' ".$KeyDown." ></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtWastePerBilletRM[$i]' id='wasteperbilletrm[$i]' value='".$rowsdt[13]."' maxlength='20' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassE."' style='font-size:12px; width:70px; height:20px;' ".$KeyDown." ></td>";
				
				echo"	<td width='255px;'><input type='text' name='txtPrdDtRemarkRM[$i]' id='remarkdtrm[$i]' value='".htmlspecialchars($rowsdt[5], ENT_QUOTES)."'  maxlength='200'  class='".$ClassE."' style='font-size:12px; width:245px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";	
				echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_2[$i]' onclick=\"SubmitRecordGridRM('".$i."','".$filepath."', '".$form."', '".$PPrdId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."'); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
				echo "</tr>";
						
				
				$i+=1;
				
				$LastItemWarehouse = $rowsdt[4];
			}
			
			
		}
		
		
							
		for ($k=1;$k <= 1;$k++) {
			$recno = $i+1;
			$mode = 'i';
			
			if ($i%2==0) $bgcolor='bgcolor1';
			else $bgcolor='bgcolor2';	
			
			if (empty($txtWarehouseCodeRM[$i])) {
				if (!empty($LastItemWarehouse))
					$txtWarehouseCodeRM[$i] = $LastItemWarehouse;
				else if (!empty($SetupDftWareHouse))
					$txtWarehouseCodeRM[$i] = $SetupDftWareHouse;
				else	
					$txtWarehouseCodeRM[$i] = $defaultwarehouse;
			}
			
			if (empty($DefaultCur))  $DefaultCur = $Base1;
			if (empty($txtCurrencyCodeRM[$i])) $txtCurrencyCodeRM[$i] = $DefaultCur;

			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2['.$i.']\')"';
			
			$querycurrency="select currency_code from currency order by currency_code";
			$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error($connection));
				
			echo"<tr id='CurRec_G2$i' class='$bgcolor $TableFocus' >";
			echo"	<td width='25px;'>$recno</td>";
			echo"	<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G2');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
			
			if ($Module_Pack == 1)
				echo"  <td width='125px;' align='center'><span>&nbsp;</span></td>";
				
			echo "	<td width='140px;' align='left'>
						<input type='hidden' name='txtPrdRMId[$i]' id='prdrmid[$i]' value='$txtPrdRMId[$i]' >
						<input type='text' name='txtItemCodeRM[$i]' id='itemcoderm[$i]' value='$txtItemCodeRM[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:110px; height:20px;'  onchange=\"SetModRecord('ModRec_G2','$i'); GetItemCost(this.id,'costpricerm[$i]','getitemcost','".$i."','".$txtDate."','".$txtCurrencyCodeRM[$i]."'); CheckLookup('chkcodeexists','items','item_code',this.value,'lstItemCodeRM[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'itemcoderm[$i]','itemdescriptionrm[$i]','items');\"  ".$KeyDown.">
						<label><span><img src='img/openlist.png' title='Select Item' id='lstItemCodeRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsRM(1,$i); ' style='vertical-align:bottom;'/></span></label>
					</td>";
									
			echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDescRM[$i]' id='itemdescriptionrm[$i]' value='$txtItemDescRM[$i]'  class='".$ClassI."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDescRM[$i]');\" ".$KeyDown." />
						<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDescRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDescRM(1,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
					</td>";
			echo"  	<td width='105px;' align='center'>
						<input type='text' name='txtWarehouseCodeRM[$i]' id='warehousecoderm[$i]' value='$txtWarehouseCodeRM[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:75px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCodeRM[$i]'); \" onkeyup=\"AutoCompleteData(event,this.id,'warehousecoderm[$i]','warehousenamerm[$i]','warehouse');\"  ".$KeyDown."  />
						<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCodeRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouseRM($i);' style='vertical-align:bottom;'/></span></label>
					</td>";
					
			echo"   <td width='65px;' align='center'><input type='text' name='txtItemUnit1RM' id='itemunit1rm[$i]' value='$txtItemUnit1RM' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:60px; height:20px;' readonly></td>";
			echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyRMF[$i]' id='prddtqtyrmf[$i]' value='$txtPrdDtQtyRMF[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." ></td>";
			echo"	<td width='75px;' align='center'><input type='text' name='txtPrdDtQtyRM[$i]' id='prddtqtyrm[$i]' value='$txtPrdDtQtyRM[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." ></td>";
			
			echo"   <td width='230px;' align='center'><span>";
			echo"  		<input type='radio' name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='1' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." checked />"; echo" <font size=2>";echo " Percentage";
			echo"	 	<input type='radio' name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='2' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." />";  echo " Quantity";
			echo"	 	<input type='radio' name='txtCostOptionRM[$i]' id='prdcostoptionrm[$i]' value='3' onchange=\"SetModRecord('ModRec_G2','$i'); \" ".$KeyDown." />";  echo " Fixed";
			echo"	</span></td>";
				
			echo"   <td width='60px;' align='center'><select name='txtCurrencyCodeRM[$i]' id='currencycoderm[$i]' class='".$ClassI."' style='font-size:12px; width:55px; height:20px;' onChange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." >";
			echo"	<option></option>";
			while($curf=mysql_fetch_row($resultcurrency)){
				echo"<option ";
				if ($txtCurrencyCodeRM[$i]==$curf[0])	echo " selected ";
				echo" value='$curf[0]'>$curf[0] </option>";
			}
			echo"	</select></td>";	
				
			echo"	<td width='85px;' align='center'><input type='text' name='txtPrdDtCostRM[$i]' id='costpricerm[$i]' value='$txtPrdDtCostRM[$i]' maxlength='20' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' ".$KeyDown."  ></td>";
			echo"	<td width='75px;' align='center'><input type='text' name='txtWasteRateRM[$i]' id='wasteraterm[$i]' value='$txtWasteRateRM[$i]' maxlength='20' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassI."' style='font-size:12px; width:70px; height:20px;' ".$KeyDown." ></td>";
			echo"	<td width='75px;' align='center'><input type='text' name='txtWastePerBilletRM[$i]' id='wasteperbilletrm[$i]' value='$txtWastePerBilletRM[$i]' maxlength='20' onchange=\"SetModRecord('ModRec_G2','$i');\" class='".$ClassI."' style='font-size:12px; width:70px; height:20px;' ".$KeyDown." ></td>";
				
			echo"	<td width='255px;'><input type='text' name='txtPrdDtRemarkRM[$i]' id='remarkdtrm[$i]' value='".htmlspecialchars($txtPrdDtRemarkRM[$i], ENT_QUOTES)."'  maxlength='200' class='".$ClassI."'  style='font-size:12px; width:245px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";	
			echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_2[$i]' onclick=\"SubmitRecordGridRM('".$i."','".$filepath."', '".$form."', '".$PPrdId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."'); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
			echo"</tr>";  

			$i+=1;	
		}
		

	
	echo"	</table>";  
	echo"	</div>";
	
	showDataGridFooter($filepath,$form,$PPrdId,'datagrid',$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	
	echo"</div>";
	
	
}


function showDataGridFooter($filepath,$form,$transid,$gridid,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction) {
	
	echo"<div class='grid_toolbarDiv'>
			<table width='100%' border=0 cellpadding='0' cellspacing='0'>
			<tr>";
	
	$rangefrom = ($startrange + 1);
	if (($startrange + $perpage) >= $totalrows) $rangeto = $totalrows; else $rangeto = ($startrange + $perpage);
				
	if ($totalrows > 0)			
		echo"	<td align='left' style='width:33%; padding-left:10px;border-top:1px solid #000000;'><span class='toolbar_style'>View ".$rangefrom." - ".$rangeto." of ".$totalrows."</span></td>";
	else
		echo"	<td align='left' style='width:33%; padding-left:10px;border-top:1px solid #000000;'><span class='toolbar_style'>No records to view</span></td>";
	
	echo"		<td align='center' style='width:15%;border-top:1px solid #000000;'><span class='toolbar_style'>Per Page </span><span class='toolbar_style'><select name='perpage' id='perpage' value='$perpage' onchange=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'CP','".$orderby."','".$morelines."',0,this.value,'".$totalrows."','".$direction."');\">";
				  
				if ($perpage==10)		 $s10 = 'selected';
				else if ($perpage==20)	 $s20 = 'selected';
				else if ($perpage==30)	 $s30 = 'selected';
				else if ($perpage==40)	 $s40 = 'selected';
				else if ($perpage==50)	 $s50 = 'selected';
				else if ($perpage==100)	 $s100 = 'selected';
				else if ($perpage==1000) $s1000 = 'selected';

								
				echo'<option '.$s10.' value="10">10</option>
					 <option '.$s20.' value="20">20</option>
					 <option '.$s30.' value="30">30</option>
					 <option '.$s40.' value="40">40</option>
					 <option '.$s50.' value="50">50</option>
					 <option '.$s100.' value="100">100</option>
					 <option '.$s1000.' value="1000">1000</option>
					 </select></span>
				</td>';
				
	echo"		<td  style='width:10%;border-right:1px solid #000000;text-align:right;border-top:1px solid #000000;'>";
				
				if($startrange > 0)
					echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='pointer'\"    onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'F','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');return false;\" >";

				$diff= $startrange - $perpage;
					
				if (($diff) >= 0 ){
					$prvstartrange = $startrange - $perpage;
					echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'P','".$orderby."','".$morelines."','".$prvstartrange."','".$perpage."','".$totalrows."','".$direction."');return false;\" >";
				}
				else
					echo "&nbsp;";
			
	echo"		</td><td  align='left' style='width:10%;border-top:1px solid #000000;'>&nbsp;";
			
			
				if ($startrange <= $totalrows){
					$startrange1 = $startrange + $perpage;
					if  ($startrange1 < $totalrows){ 
						echo"<img src='img/arrowright.png' title='Next' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'N','".$orderby."','".$morelines."','".$startrange1."','".$perpage."','".$totalrows."','".$direction."');return false;\" onmouseover=\"style.cursor='pointer'\" >";
						echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='pointer'\" onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'L','".$orderby."','".$morelines."','".$prvstartrange."','".$perpage."','".$totalrows."','".$direction."');return false;\" >";	
					}
				} else
					echo "&nbsp;";
			
				
				$currentpage = ($startrange / $perpage) + 1;
				$totalpages  = ceil($totalrows / $perpage);
				
	echo"		</td><td style='text-align:center; width:14%;border-top:1px solid #000000;'>&nbsp;<span class='toolbar_style'>Page $currentpage / $totalpages</span></td>";
	

	
	echo"		<td style='text-align:center; width:6%;border-top:1px solid #000000;'><img src='img/Refresh-icon.png'  onMouseOver=\"style.cursor='pointer'\"  width='20' height='20' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'R','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\" ></td>";
	echo"		<td align='right' style='width:12%; padding-right:10px;border-top:1px solid #000000;'>&nbsp;</td>";
	
	echo"	</tr>";
	echo"	</table></div>";

}


?>