<?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 == 'GRN') {
		ShowGoodRecNoteDtGrid($connection,$form,$transid,$_SESSION['ggrn_parameters'],$_SESSION['ggrn_arrayaccess'],$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	}
else if ($form == 'GRN-R') {
		ShowReturnGoodRecNoteDtGrid($connection,$form,$transid,$_SESSION['ggrnr_parameters'],$_SESSION['ggrnr_arrayaccess'],$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	}	
	
	
}
	
	
	
function ShowGoodRecNoteDtGrid($connection,$form,$PPurId,$arrayparams,$arrayaccess,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction){
	
	$Module_Unit1Method 		= $arrayparams['Module_Unit1Method'];
	$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_PurchaseCategory 		= $arrayparams['FI_PurchaseCategory'];
	$Module_Heatno 				= $arrayparams['Module_Heatno'];
	$module_locationGrn 		= $arrayparams['module_locationGrn'];
	$Login_location 			= $arrayparams['Login_location'];
	//echo $module_locationGrn;
	$SetupDftWareHouse 			= $arrayparams['SetupDftWareHouse'];
	$defaultwarehouse  			= $arrayparams['defaultwarehouse'];
	$showBatch  				= $arrayparams['showBatch'];
	$Module_GRNwithPorder  		= $arrayparams['Module_GRNwithPorder'];	
	$DecimalBase 				= $arrayparams['DecimalBase'];
	$txtDate         			= $arrayparams['txtDate'];
	$txtSupplierCode 			= $arrayparams['txtSupplierCode'];
	$PurType         			= $arrayparams['PurType'];

	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_DataGridGrn.php';
	
	$i = 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("itemcode", "itemdescription", "warehousecode");

	if($Module_Heatno==1)
		array_push($columnsarray, "HeatNo");
	
	array_push($columnsarray, "Location_code");
	if ($showBatch == 1) {
		array_push($columnsarray, "packagingno");
		array_push($columnsarray, "numberofunit");
	}	
	array_push($columnsarray, "purdtquantity");
	
	if ($Module_DoubleUnit == 1) array_push($columnsarray, 'unit2qty');
	//array_push($columnsarray, 'purdtvolume');
	
	if ($Module_ProjectDt == 1) array_push($columnsarray, 'projectcodedt');
	if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) array_push($columnsarray, 'costcentcodedt');
	if ($Module_ExpireDate == 1 || $showBatch == 1) 
		array_push($columnsarray, 'batchno');
	if ($Module_ExpireDate == 1) {
		array_push($columnsarray, 'expiredate');
	}	
	array_push($columnsarray, 'remarkdt');
	
	
	$columnsarrayall = array("itemcode", "itemdescription", "warehousecode","", "porderref", "porderqty", "purdtquantity", "unit2qty","packagingno","numberofunit", "purdtquantity", "projectcodedt", "costcentcodedt", "expiredate", "batchno", "remarkdt", "purdtid", "existingqty", "bookingqty", "availableqty", "itemunit1", "itemunit2", "itemvat", "itemexpire", "itemunitcoef", "itemcodeFG");
	
	$orderbyarray = array("GrnPurchasesDt.Item_CodePacked", "Items.Item_Code", "Items.Item_Description", "GrnPurchasesDt.Warehouse_Code","GrnPurchasesDt.Location_Code", "Items.Item_UnitSalesDesc", "Items.Item_UnitPurchaseDesc");
	
	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 = 1075;
	if ($Module_SerialNo == 1)     $TableWidth += 25;
	if ($Module_Pack == 1)         $TableWidth += 125;
	if ($PurType == 'RM')          $TableWidth += 105;
	if ($Module_DoubleUnit == 1)   $TableWidth += 145;
	if ($Module_SerialNo == 1)     $TableWidth += 55;
	if ($Module_ProjectDt == 1)    $TableWidth += 160;
	if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) $TableWidth += 160;
	if ($Module_ExpireDate == 1)   $TableWidth += 85;
	if($showBatch == 1) $TableWidth += 245;
	if($Module_Heatno==1) $TableWidth += 120;
	$TableWidthStyle = 'width:'.$TableWidth.'px;';
	
	echo"<div id='container' style='position: relative;z-index:1;' >";
	echo"	<div id='Loader' class=''></div>";
	echo" 	<div id='grid_headerDiv' class='grid_headerDiv'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
	
		echo"<tr>";
		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."', '".$PPurId."', 'datagrid', 1, '".$dftorderby."', 'COR','PurchasesDt.Item_CodePacked','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code Packed".$orderimg1."</span></th>";
			
		echo"  <th width='145px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPurId."', '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."', '".$PPurId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_Description','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Description".$orderimg3."</span></th>";
		
		if ($PurType == 'RM')
			echo"  <th width='105px;' align='center'><span>Item Code Finished</span></th> ";
			
		echo"  <th width='105px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPurId."', 'datagrid', 1, '".$dftorderby."', 'COR','GrnPurchasesDt.Warehouse_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Warehouse".$orderimg4."</span></th>";
	
	if($module_locationGrn == 1 and $Login_location == 1)
	echo"  <th width='105px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPurId."', 'datagrid', 1, '".$dftorderby."', 'COR','GrnPurchasesDt.Location_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Location".$orderimg4."</span></th>";
	
	if($Module_Heatno==1)
		echo"  <th width='120px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPorId."', 'datagrid', 1, '".$dftorderby."', 'COR','PorderDt.Warehouse_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>HeatNo</span></th>";
	
		
		echo"  <th width='75px;' align='center'><span>Order Ref </span></th> ";	
		echo"  <th width='75px;' align='center'><span>Rem. Order Qty</span></th>";	
		echo"  <th width='65px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPurId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_UnitSalesDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Unit".$orderimg5."</span></th>";
		if ($showBatch == 1) {
				echo"  <th width='70px;' align='center'><span>Packaging Nbr</span></th> ";	
				echo"  <th width='70px;' align='center'><span>Nbr of Units</span></th> ";	
			}
		echo"  <th width='75px;' align='center'><span>Quantity</span></th> ";	
		  
		if ($Module_DoubleUnit == 1) {
			echo"  <th width='65px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPurId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_UnitPurchaseDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Unit2".$orderimg6."</span></th>";
			echo"  <th width='80px;' align='center'><span>Unit2 Qty</span></th>";
		}
		
		if ($Module_SerialNo == 1) {
			echo"  <th width='55px;' align='center'><span>S/N Bal</span></th>";
		}
		  
		//echo"  <th width='105px;' align='center'><span>Volume</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 ($showBatch == 1 || $Module_ExpireDate == 1) 
			echo"  <th width='105px;' align='center'><span>Batch No</span></th>";	
		
		if ($Module_ExpireDate == 1) {
			
			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='grid_contentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('grid_headerDiv','grid_contentDiv')\">";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
		echo"<input type='hidden' name='SelectedRec' id='SelectedRec' value='$SelectedRec'>
			 <input type='hidden' name='SelectedRecColor' id='SelectedRecColor' value='$SelectedRecColor'>
			 <input type='hidden' name='ModRec_G1' id='ModRec_G1' value='$ModRec_G1'>";  
		
			 
		
		
		if ($PPurId != '' ) {
		      
			$TotalQty = 0;
			$i_nonstock  = 0;
			$i_zeroprice = 0;
			$i_minprice  = 0;
			$i_unitcoef  = 1;
			$i_expire    = 0;
			
						   
			$query = " Select GrnPurchasesDt.PurchaseDt_ID, GrnPurchasesDt.Item_CodePacked, GrnPurchasesDt.Item_code, Item_Description, GrnPurchasesDt.Warehouse_Code, ".
					 " Purchasedt_Remark, PurchaseDt_Quantity, PurchaseDt_Volume, GrnPurchasesDt.Item_Unit2Qty, Item_UnitPurchaseDesc, Item_UnitSalesDesc, GrnPurchasesDt.Project_code, ".
					 " GrnPurchasesDt.CostCent_Code,  PorderDt.PorderDt_Quantity, Porder.Porder_reference, GrnPurchasesDt.RelatedDt_Id, GrnPurchasesDt.Item_CodeFinished, ".
					 " ifNull(item_withserialno,0) As ItemWithSerialNo, Count(SerialNo_Code) As CountSerialNo,  Date_Format(PurchaseDt_ExpireDate,'%d/%m/%Y') As PurchaseDt_ExpireDate, PurchaseDt_BatchNo,PurchaseDt_heatNo, Location_code, ".
					 " grnpurchasesdt_packagingno , grnpurchasesdt_nbrUnit ".
					 " From Temp_GrnPurchasesDt As GrnPurchasesDt Left Join Items on GrnPurchasesDt.Item_code = Items.Item_code ".
					 " Left Join Temp_Purchasesserialno on GrnPurchasesDt.PurchaseDt_ID = Temp_Purchasesserialno.GrnDt_ID ".
					 " And Temp_Purchasesserialno.Journal_Type = 'PI' ".
					 " And Temp_Purchasesserialno.PurchaseDt_ID Is Not Null ".
					 " Left Join PorderDt on PorderDt.PorderDt_ID = GrnPurchasesDt.RelatedDt_Id  ".
					 " Left Join Porder on Porder.Porder_ID = PorderDt.Porder_ID  ".
					 " Where GrnPurchasesDt.Purchase_ID = ".$PPurId.
					 " Group By  GrnPurchasesDt.PurchaseDt_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;
				
				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];
				
				
				$txtItemWithSerial[$i] = $i_withserial;
				$txtItemUnitCoef[$i]   = $i_unitcoef;
				$txtItemExpire[$i]     = $i_expire;
				
				
				$vPorderDtQty  = $rowsdt[13];
				$vPorderDtId   = $rowsdt[15];
				$purchasedt_heatno[$i]   = $rowsdt[21];
				
				if (!empty($vPorderDtId) && $vPorderDtId != '') {
				
					$sub_query1 = " Select Sum(if(Journal_Type='PI', ifNull(GrnPurchasesDt.PurchaseDt_Quantity,0), ifNull(GrnPurchasesDt.PurchaseDt_Quantity,0)*(-1))) As QuantityPurchased ".
								  " From GrnPurchasesDt ".
								  " Where GrnPurchasesDt.RelatedDt_ID =  '".$vPorderDtId."' ".
								  " And GrnPurchasesDt.Journal_Type In ('PI','PR') ".
								  " And GrnPurchasesDt.PurchaseDt_Id != '".$rowsdt[0]."' ";
					$sub_result1 = selectData($connection, $sub_query1);
					if ($sub_result1[0] == '') $sub_result1[0] = 0;
				
					$sub_query2 = " Select Sum(ifNull(Temp_GrnPurchasesDt.PurchaseDt_Quantity,0)) As QuantityPurchasedTemp ".
								  " From Temp_GrnPurchasesDt ".
								  " Where Temp_GrnPurchasesDt.RelatedDt_ID =  '".$vPorderDtId."' ".
								  " And Temp_GrnPurchasesDt.Journal_Type = 'PI' ".
								  " And Temp_GrnPurchasesDt.PurchaseDt_Id != '".$rowsdt[0]."' ";
					$sub_result2 = selectData($connection, $sub_query2);
					if ($sub_result2[0] == '') $sub_result2[0] = 0;		  
									
					//Get The Remaining Qty
					$vPorRemainQty = ($vPorderDtQty - ($sub_result1[0] + $sub_result2[0]));
					
				}	
				
				//Checking For Difference Btw Qty and Count SerialNo
				if (($rowsdt[6] != $rowsdt[18] && $rowsdt[17] != 0 && $Module_SerialNo == 1) || ($rowsdt[6] == 0 && $rowsdt[17] != 0 && $Module_SerialNo == 1) || ($rowsdt[6] == 0)) {
					$RecStyle = "style='background-color:#FF0000;'";
				}
				
			
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit['.$i.']\')"';
				
				echo"<tr id='CurRec$i' class='$bgcolor table-focus-g1'>";		
				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=\"DeleteRecordGrid('".$filepath."','".$form."', '".$PPurId."','".$rowsdt[0]."','".$i."','".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."');return false;\" title='Delete Record'  ></td>";
				
				// If ItemWithSerialNo True And ModuleSerialNo True	
				if ($rowsdt[17] == 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]."','".$vPorRemainQty."')\" title='Add Serial Nos'  ></td>";
				}
				else if ($rowsdt[17] == 0 && $Module_SerialNo == 1) {
					echo "	<td width='20px;' 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='145px;' align='left'>
							<input type='hidden' name='txtPurDtId[$i]' id='purdtid[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtItemVat[$i]' id='itemvat[$i]' value='$txtItemVat[$i]' >
							<input type='hidden' name='txtItemExpire[$i]' id='itemexpire[$i]' value='$txtItemExpire[$i]' >
							<input type='hidden' name='txtItemWithSerial[$i]' id='itemwithserial[$i]' value='$txtItemWithSerial[$i]' >
							<input type='hidden' name='txtItemUnitCoef[$i]' id='itemunitcoef[$i]' value='$txtItemUnitCoef[$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='txtItemCode[$i]' id='itemcode[$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,'lstItemCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'itemcode[$i]','itemdescription[$i]','items');\" ".$KeyDown.">
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItems(1,$i); ' style='vertical-align:bottom;'/></span></label>
						</td>";
										
				echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDesc[$i]' id='itemdescription[$i]' value='".$rowsdt[3]."' class='".$ClassE."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDesc[$i]');\" ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDesc[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDesc(1,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
						</td>";
						
				if ($PurType == 'RM')
					echo"	<td width='105px;' align='center'><input type='text' name='txtItemCodeFG[$i]' id='itemcodeFG[$i]' value='".$rowsdt[16]."' maxlength='20' class='".$ClassE."' style='font-size:12px; width:100px; height:20px;' readonly></td>";
					
				echo"  	<td width='105px;' align='center'>
							<input type='text' name='txtWarehouseCode[$i]' id='warehousecode[$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,'lstWarehouseCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\" ".$KeyDown."   />
							<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistWarehouse($i,'warehouse');\" style='vertical-align:bottom;'/></span></label>
						</td>";
				if($module_locationGrn == 1 and $Login_location == 1)
				echo"  	<td width='105px;' align='center'>
						<input type='text' name='txtlocationCode[$i]' id='locationcode[$i]' value='".$rowsdt[22]."'  maxlength='20'  class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstlocationcode[$i]'); GetSelectedItemQty('getitemqty','".$i."','".$txtDate."');\" onkeyup=\"AutoCompleteData(event,this.id,'locationcode[$i]','locationname[$i]','warehouse');\"  ".$KeyDown."  />
						<label><span><img src='img/openlist.png' title='Select Location' id='lstlocationcode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistWarehouse($i, 'shelf');\" style='vertical-align:bottom;'/></span></label>
					</td>";		

				if($Module_Heatno==1)		
				echo"  	<td width='120px;' align='center'>
							<input type='text' name='purchasedt_heatno[$i]' id='purchasedt_heatno[$i]' value='".$purchasedt_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:90px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); ".$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='purchasedt_heatno[$i]' id='purchasedt_heatno[$i]' value='".$purchasedt_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); ".$KeyDown."   />";
				
				echo"	<td width='75px;' align='center'><input type='text' name='txtPorderRef[$i]' id='porderref[$i]' value='".$rowsdt[14]."' maxlength='20' class='".$ClassE."' style='font-size:12px; width:70px; height:20px;' readonly></td>";
				echo"   <td width='75px;' align='center'><input type='text' name='txtPorderQty[$i]' id='porderqty[$i]' value='".$vPorRemainQty."' maxlength='20' class='".$ClassE."' style='font-size:12px; width:70px; height:20px;' readonly  ></td>";
				echo "	<td width='65px;' align='left'><span class='".$TextColor."'>".$rowsdt[10]."</span></td>";
				if($showBatch == 1){
					echo" 	<td width='70px;' align='center'><input type='text' name='txtPurDtPackagingNo[$i]' id='packagingno[$i]' value='".htmlspecialchars($rowsdt[23], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' onkeyup=\"setQty('$i');\"  style='font-size:12px; width:70px; height:20px;' ".$KeyDown." ></td>";
					echo" 	<td width='70px;' align='center'><input type='text' name='txtPurDtNbrUnit[$i]' id='numberofunit[$i]' value='".htmlspecialchars($rowsdt[24], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' onkeyup=\"setQty('$i');\"  style='font-size:12px; width:70px; height:20px;' ".$KeyDown." ></td>";
				} else {
					echo" <input type='hidden' name='txtPurDtPackagingNo[$i]' id='packagingno[$i]' value=''>";
					echo" <input type='hidden' name='txtPurDtNbrUnit[$i]' id='numberofunit[$i]' value=''>";
				}
				echo"	<td width='75px;' align='center'><input type='text' name='txtPurDtQty[$i]' id='purdtquantity[$i]' value='".$rowsdt[6]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; border-width:0px; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CalcQty2($Module_Unit1Method,1,$i);\" ".$KeyDown." ></td>";
					
				
				if ($Module_DoubleUnit == 1) { 
					echo"  <td width='65px;' align='left'><span class='".$TextColor."'>".$rowsdt[9]."</span></td>";	
					echo"  <td width='80px;' align='center'><input type='text' name='txtPurDtQty2[$i]' id='unit2qty[$i]' value='".$rowsdt[8]."' maxlength='20' onchange=\"CalcQty2($Module_Unit1Method,2,$i); SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' ".$KeyDown." ></td>";
				} else {
					echo"  <input type='hidden' name='txtPurDtQty2[$i]' id='unit2qty[$i]' value='' >";
				}
				
				if ($Module_SerialNo == 1) {
					echo"  <td width='55px;' align='center'><span class='".$TextColor."'>".$rowsdt[18]."</span></td>";
				}
				
				//echo"	<td width='105px;' align='center'><input type='text' name='txtPurDtVolume[$i]' id='purdtvolume[$i]' value='".$rowsdt[7]."' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown."  ></td>";
				
				if ($Module_ProjectDt == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='".$rowsdt[11]."' class='".$ClassE."' style='width:120px;' maxlength='15' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCode[$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='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='' >";
				}
				if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='".$rowsdt[12]."' class='".$ClassE."' style='width:130px;' maxlength='15' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode[$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='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='' >";
				}
				
				if($showBatch == 1 || $Module_ExpireDate == 1)
					echo" 	<td width='105px;' align='center'><input type='text' name='txtPurDtBatchNo[$i]' id='batchno[$i]' value='".htmlspecialchars($rowsdt[20], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='font-size:12px; width:80px; height:20px;' ".$KeyDown." >
							<label><span><img src='img/openlist.png' title='Select Batch No' id='lstBatchNo[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistBatchNo(2,$i); ' style='vertical-align:bottom;'/></span></label></td>";
				else
					echo" <input type='hidden' name='txtPurDtBatchNo[$i]' id='batchno[$i]' value=''>";
				
				if ($Module_ExpireDate == 1) {
					echo"	<td width='85px;' align='center'><input type='text' name='txtPurDtExpireDate[$i]' id='expiredate[$i]' value='".$rowsdt[19]."' 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='txtPurDtExpireDate[$i]' id='expiredate[$i]' value=''>";
					
				}
				
				echo"	<td width='255px;'><input type='text' name='txtPurDtRemark[$i]' id='remarkdt[$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'><img src='img/confirm-1.png' id='imgSubmit[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitRecordGrid('".$i."','".$filepath."', '".$form."', '".$PPurId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$FI_PurchaseCategory); return false;\" title='Submit Record' style='vertical-align:bottom;' ></td>";
				echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit[$i]' onclick=\"SubmitRecordGrid('".$i."','".$filepath."', '".$form."', '".$PPurId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$Module_SerialNo,$FI_PurchaseCategory,$module_locationGrn); 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];
			}
			
			
		}
	
	if ($Module_GRNwithPorder != '1')	{
		for ($k=1;$k <= 1;$k++) {
			$recno = $i+1;
			$mode = 'i';
			
			if ($i%2==0) $bgcolor='bgcolor1';
			else $bgcolor='bgcolor2';	
			
			if (empty($txtWarehouseCode[$i])) {
				if (!empty($LastItemWarehouse))
					$txtWarehouseCode[$i] = $LastItemWarehouse;
				else if (!empty($SetupDftWareHouse))
					$txtWarehouseCode[$i] = $SetupDftWareHouse;
				else	
					$txtWarehouseCode[$i] = $defaultwarehouse;
			}

			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit['.$i.']\')"';
			
				
			echo"<tr id='CurRec$i' class='$bgcolor table-focus-g1' >";
			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='145px;' align='left'>
						<input type='hidden' name='txtPurDtId[$i]' id='purdtid[$i]' value='$txtPurDtId[$i]' >
						<input type='hidden' name='txtItemVat[$i]' id='itemvat[$i]' value='$txtItemVat[$i]' >
						<input type='hidden' name='txtItemExpire[$i]' id='itemexpire[$i]' value='$txtItemExpire[$i]' >
						<input type='hidden' name='txtItemWithSerial[$i]' id='itemwithserial[$i]' value='$txtItemWithSerial[$i]' >
						<input type='hidden' name='txtItemUnitCoef[$i]' id='itemunitcoef[$i]' value='$txtItemUnitCoef[$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='txtItemCode[$i]' id='itemcode[$i]' value='$txtItemCode[$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,'lstItemCode[$i]'); GetSelectedItem(this.id,'getitem','".$i."','".$txtDate."','".$txtCurrCode."','-1'); GetSelectedItemQty('getitemqty','".$i."','".$txtDate."');\" onkeyup=\"AutoCompleteData(event,this.id,'itemcode[$i]','itemdescription[$i]','items');\"  ".$KeyDown.">
						<label><span><img src='img/openlist.png' title='Select Item' id='lstItemCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItems(1,$i); ' style='vertical-align:bottom;'/></span></label>
					</td>";
									
			echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDesc[$i]' id='itemdescription[$i]' value='$txtItemDesc[$i]'  class='".$ClassI."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDesc[$i]');\" ".$KeyDown." />
						<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDesc[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDesc(1,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
					</td>";
					
			if ($PurType == 'RM')
				echo"	<td width='105px;' align='center'><input type='text' name='txtItemCodeFG[$i]' id='itemcodeFG[$i]' value='$txtItemCodeFG[$i]' maxlength='20' class='".$ClassI."' style='font-size:12px; width:100px; height:20px;' readonly></td>";
					
			echo"  	<td width='105px;' align='center'>
						<input type='text' name='txtWarehouseCode[$i]' id='warehousecode[$i]' value='$txtWarehouseCode[$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,'lstWarehouseCode[$i]'); GetSelectedItemQty('getitemqty','".$i."','".$txtDate."');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\"  ".$KeyDown."  />
						<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistWarehouse($i, 'warehouse');\" style='vertical-align:bottom;'/></span></label>
					</td>";
			if($module_locationGrn == 1 and $Login_location == 1)		
			echo"  	<td width='105px;' align='center'>
						<input type='text' name='txtlocationCode[$i]' id='locationcode[$i]' value='$txtLocationCode[$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,'lstlocationcode[$i]'); GetSelectedItemQty('getitemqty','".$i."','".$txtDate."');\" onkeyup=\"AutoCompleteData(event,this.id,'locationcode[$i]','locationname[$i]','warehouse');\"  ".$KeyDown."  />
						<label><span><img src='img/openlist.png' title='Select Location' id='lstlocationcode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistWarehouse($i, 'shelf');\" style='vertical-align:bottom;'/></span></label>
					</td>";
			if($Module_Heatno==1)		
				echo"  	<td width='120px;' align='center'>
							<input type='text' name='purchasedt_heatno[$i]' id='purchasedt_heatno[$i]' value='".$purchasedt_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:90px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); ".$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='purchasedt_heatno[$i]' id='purchasedt_heatno[$i]' value='".$purchasedt_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:185px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); ".$KeyDown."   />";
			
			echo"	<td width='75px;' align='center'><input type='text' name='txtPorderRef[$i]' id='porderref[$i]' value='' maxlength='20' class='".$ClassI."' style='font-size:12px; width:70px; height:20px;' readonly></td>";
			echo"   <td width='75px;' align='center'><input type='text' name='txtPorderQty[$i]' id='porderqty[$i]' value='' maxlength='20' class='".$ClassI."' style='font-size:12px; width:70px; height:20px;' readonly  ></td>";
			echo"   <td width='65px;' align='center'><input type='text' name='txtItemUnit1' id='itemunit1[$i]' value='$txtItemUnit1' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:60px; height:20px;' readonly></td>";
			if ($showBatch == 1 ) {
				echo" 	<td width='70px;' align='center'><input type='text' name='txtPurDtPackagingNo[$i]' id='packagingno[$i]' value='".htmlspecialchars($txtPurDtPackagingNo[$i], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' onkeyup=\"setQty('$i');\"  style='font-size:12px; width:70px; height:20px;' ".$KeyDown." ></td>
						<td width='70px;' align='center'><input type='text' name='txtPurDtNbrUnit[$i]' id='numberofunit[$i]' value='".htmlspecialchars($txtPurDtNbrUnit[$i], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' onkeyup=\"setQty('$i');\"  style='font-size:12px; width:70px; height:20px;' ".$KeyDown." ></td>";
					
			} else {
				echo" <input type='hidden' name='txtPurDtPackagingNo[$i]' id='packagingno[$i]' value=''>";
				echo" <input type='hidden' name='txtPurDtNbrUnit[$i]' id='numberofunit[$i]' value=''>";
			}		
		echo"	<td width='75px;' align='center'><input type='text' name='txtPurDtQty[$i]' id='purdtquantity[$i]' value='$txtPurDtQty[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CalcQty2($Module_Unit1Method,1,$i);\" ".$KeyDown." ></td>";
					
				
		  
			if ($Module_DoubleUnit == 1) {
				echo"  <td width='65px;' align='center'><input type='text' name='txtItemUnit2' id='itemunit2[$i]' value='$txtItemUnit2' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:60px; height:20px;' readonly></td>";
				echo"  <td width='80px;' align='center'><input type='text' name='txtPurDtQty2[$i]' id='unit2qty[$i]' value='$txtPurDtQty2[$i]' maxlength='20' onchange=\"CalcQty2($Module_Unit1Method,2,$i); SetModRecord('ModRec_G1','$i');\" class='".$ClassI."'  style='font-size:12px; width:75px; height:20px;' ".$KeyDown." ></td>";
			} else {
				echo "<input type='hidden' name='txtPurDtQty2[$i]' id='unit2qty[$i]' value='' >";
			}
			
			if ($Module_SerialNo == 1) {
				echo"  <td width='55px;' align='center'><span class='".$TextColor."'>&nbsp;</span></td>";
			}
			
			//echo"	<td width='105px;' align='center'><input type='text' name='txtPurDtVolume[$i]' id='purdtvolume[$i]' value='$txtPurDtVolume[$i]' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown."  ></td>";
				
			if ($Module_ProjectDt == 1) {
				echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='$txtProjectCodeDt[$i]' class='".$ClassI."' style='width:120px;' maxlength='15' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode[$i]');\" ".$KeyDown." /></span>
						<label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCode[$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='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='' >";
			}
			if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) {
				echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='$txtCostCentCodeDt[$i]' class='".$ClassI."' style='width:130px;' maxlength='15' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span>
						<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode[$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='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='' >";
			}
			
			if ($showBatch == 1 || $Module_ExpireDate == 1) 
				echo" 	<td width='105px;' align='center'><input type='text' name='txtPurDtBatchNo[$i]' id='batchno[$i]' value='".htmlspecialchars($txtPurDtBatchNo[$i], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' style='font-size:12px; width:80px; height:20px;' ".$KeyDown." >
						<label><span><img src='img/openlist.png' title='Select Batch No' id='lstBatchNo[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistBatchNo(2,$i); ' style='vertical-align:bottom;'/></span></label></td>";
			else
				echo" <input type='hidden' name='txtPurDtBatchNo[$i]' id='batchno[$i]' value=''>";
				
			
			if ($Module_ExpireDate == 1) {			
				echo" 	<td width='85px;' align='center'><input type='text' name='txtPurDtExpireDate[$i]' id='expiredate[$i]' value='$txtPurDtExpireDate[$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='txtPurDtExpireDate[$i]' id='expiredate[$i]' value=''>";
				
			}
			
					
			echo"	<td width='255px;'><input type='text' name='txtPurDtRemark[$i]' id='remarkdt[$i]' value='".htmlspecialchars($txtPurDtRemark[$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'><img src='img/confirm-1.png' id='imgSubmit[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitRecordGrid('".$i."','".$filepath."', '".$form."', '".$PPurId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$Module_SerialNo,$FI_PurchaseCategory); return false;\" title='Submit Record' style='vertical-align:bottom;' ></td>";
			echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit[$i]' onclick=\"SubmitRecordGrid('".$i."','".$filepath."', '".$form."', '".$PPurId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$Module_SerialNo,$FI_PurchaseCategory,$module_locationGrn); 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 "<input type='hidden' name='rownbr' id='rownbr' value='$i'>";
	echo"	</table>";  
	echo"	</div>";
	
	showDataGridFooter($filepath,$form,$PPurId,'datagrid',$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	
	echo"</div>";
	
	
}


function ShowReturnGoodRecNoteDtGrid($connection,$form,$PPurId,$arrayparams,$arrayaccess,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction){
	
	$Module_Unit1Method = $arrayparams['Module_Unit1Method'];
	$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_PurchaseCategory = $arrayparams['FI_PurchaseCategory'];
	
	
	$SetupDftWareHouse = $arrayparams['SetupDftWareHouse'];
	$defaultwarehouse  = $arrayparams['defaultwarehouse'];
		
	
	$DecimalBase = $arrayparams['DecimalBase'];
	
	$txtDate         = $arrayparams['txtDate'];
	$txtSupplierCode = $arrayparams['txtSupplierCode'];
	
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_DataGridGrn.php';
	
	$i = 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("itemcode", "itemdescription", "warehousecode", "purdtquantity");
	if ($Module_DoubleUnit == 1) array_push($columnsarray, 'unit2qty');
	//array_push($columnsarray, 'purdtvolume');
	
	if ($Module_ProjectDt == 1) array_push($columnsarray, 'projectcodedt');
	if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) array_push($columnsarray, 'costcentcodedt');
	if ($Module_ExpireDate == 1) {
		array_push($columnsarray, 'batchno');
		array_push($columnsarray, 'expiredate');
	}	
	array_push($columnsarray, 'remarkdt');
	
	
	$columnsarrayall = array("itemcode", "itemdescription", "warehousecode", "grnref", "grnqty", "purdtquantity", "unit2qty", "purdtquantity", "projectcodedt", "costcentcodedt", "expiredate", "batchno", "remarkdt", "purdtid", "existingqty", "bookingqty", "availableqty", "itemunit1", "itemunit2", "itemvat", "itemexpire", "itemunitcoef");
	$orderbyarray = array("GrnPurchasesDt.Item_CodePacked", "Items.Item_Code", "Items.Item_Description", "GrnPurchasesDt.Warehouse_Code", "Items.Item_UnitSalesDesc", "Items.Item_UnitPurchaseDesc");
	
	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 = 1075;
	if ($Module_SerialNo == 1)     $TableWidth += 25;
	if ($Module_Pack == 1)         $TableWidth += 125;
	if ($Module_DoubleUnit == 1)   $TableWidth += 145;
	if ($Module_SerialNo == 1)     $TableWidth += 55;
	if ($Module_ProjectDt == 1)    $TableWidth += 160;
	if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) $TableWidth += 160;
	if ($Module_ExpireDate == 1)   $TableWidth += 190;
	
	$TableWidthStyle = 'width:'.$TableWidth.'px;';
	
	echo"<div id='container' style='position: relative;z-index:1;' >";
	echo"	<div id='Loader' class=''></div>";
	echo" 	<div id='grid_headerDiv' class='grid_headerDiv'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
	
		echo"<tr>";
		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."', '".$PPurId."', 'datagrid', 1, '".$dftorderby."', 'COR','PurchasesDt.Item_CodePacked','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code Packed".$orderimg1."</span></th>";
			
		echo"  <th width='145px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPurId."', '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."', '".$PPurId."', '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."', '".$PPurId."', 'datagrid', 1, '".$dftorderby."', 'COR','PurchasesDt.Warehouse_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Warehouse".$orderimg4."</span></th>";
		echo"  <th width='75px;' align='center'><span>GRN Ref</span></th> ";	
		echo"  <th width='75px;' align='center'><span>Rem. GRN Qty</span></th>";	
		echo"  <th width='65px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPurId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_UnitSalesDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Unit".$orderimg5."</span></th>";
		echo"  <th width='75px;' align='center'><span>Quantity</span></th> ";	
		  
		if ($Module_DoubleUnit == 1) {
			echo"  <th width='65px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPurId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_UnitPurchaseDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Unit2".$orderimg6."</span></th>";
			echo"  <th width='80px;' align='center'><span>Unit2 Qty</span></th>";
		}
		
		if ($Module_SerialNo == 1) {
			echo"  <th width='55px;' align='center'><span>S/N Bal</span></th>";
		}
		  
		//echo"  <th width='105px;' align='center'><span>Volume</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='grid_contentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('grid_headerDiv','grid_contentDiv')\">";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
		echo"<input type='hidden' name='SelectedRec' id='SelectedRec' value='$SelectedRec'>
			 <input type='hidden' name='SelectedRecColor' id='SelectedRecColor' value='$SelectedRecColor'>
			 <input type='hidden' name='ModRec_G1' id='ModRec_G1' value='$ModRec_G1'>";  
		
			 
		
		
		if ($PPurId != '' ) {
		      
			$TotalQty = 0;
			$i_nonstock  = 0;
			$i_zeroprice = 0;
			$i_minprice  = 0;
			$i_unitcoef  = 1;
			$i_expire    = 0;
			
						   
			$query = " Select GrnPurchasesDt.PurchaseDt_ID, GrnPurchasesDt.Item_CodePacked, GrnPurchasesDt.Item_code, Item_Description, GrnPurchasesDt.Warehouse_Code, ".
					 " Purchasedt_Remark, PurchaseDt_Quantity, PurchaseDt_Volume, GrnPurchasesDt.Item_Unit2Qty, Item_UnitPurchaseDesc, Item_UnitSalesDesc, GrnPurchasesDt.Project_code, ".
					 " GrnPurchasesDt.CostCent_Code, GrnPurchasesDt.Related_Ref, GrnPurchasesDt.RelatedDt_Id, GrnPurchasesDt.Item_CodeFinished, ".
					 " ifNull(item_withserialno,0) As ItemWithSerialNo, Count(SerialNo_Code) As CountSerialNo,  Date_Format(PurchaseDt_ExpireDate,'%d/%m/%Y') As PurchaseDt_ExpireDate, PurchaseDt_BatchNo ".
					 " From Temp_GrnPurchasesDt As GrnPurchasesDt Left Join Items on GrnPurchasesDt.Item_code = Items.Item_code ".
					 " Left Join Temp_Purchasesserialno on GrnPurchasesDt.PurchaseDt_ID = Temp_Purchasesserialno.GrnDt_ID ".
					 " And Temp_Purchasesserialno.Journal_Type = 'PR' ".
					 " And Temp_Purchasesserialno.PurchaseDt_ID Is Not Null ".
					 " Where GrnPurchasesDt.Purchase_ID = ".$PPurId.
					 " Group By  GrnPurchasesDt.PurchaseDt_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;
				
				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];
				
				
				$txtItemWithSerial[$i] = $i_withserial;
				$txtItemUnitCoef[$i]   = $i_unitcoef;
				$txtItemExpire[$i]     = $i_expire;
				
				
				
				$vRelatedDtId  = $rowsdt[14];
				
				if (!empty($vRelatedDtId) && $vRelatedDtId != '') {
					$sub_query = " Select ifNull(GrnPurchasesDt.PurchaseDt_Quantity,0) - ifNull(Sum(ifNull(ReturnGrnPurchasesDt.PurchaseDt_Quantity,0)),0) ".
								 " From GrnPurchasesDt ".
								 " Left Join GrnPurchasesDt As ReturnGrnPurchasesDt on ReturnGrnPurchasesDt.RelatedDt_Id = GrnPurchasesDt.PurchaseDt_ID And ReturnGrnPurchasesDt.Journal_Type = 'PR' ".
								 " Where GrnPurchasesDt.PurchaseDt_ID = '".$vRelatedDtId."' ".
								 " And GrnPurchasesDt.Journal_Type = 'PI' ";
								 //" And ReturnGrnPurchasesDt.Purchase_Id != '".$PPurId."' ";
								 //" And ReturnGrnPurchasesDt.PurchaseDt_Id != '".$rowsdt[0]."' ";

					$sub_result = selectData($connection, $sub_query);
					if ($sub_result[0] == '') $sub_result[0] = 0;	
					
					$sub_query2 = " Select Sum(ifNull(Temp_GrnPurchasesDt.PurchaseDt_Quantity,0)) As QuantityPurchasedTemp ".
								  " From Temp_GrnPurchasesDt ".
								  " Where Temp_GrnPurchasesDt.RelatedDt_ID =  '".$vRelatedDtId."' ".
								  " And Temp_GrnPurchasesDt.Journal_Type = 'PR' ".
								  " And Temp_GrnPurchasesDt.PurchaseDt_Id != '".$rowsdt[0]."' ";
					$sub_result2 = selectData($connection, $sub_query2);
					if ($sub_result2[0] == '') $sub_result2[0] = 0;		

					$vRemainQty = $sub_result[0] - $sub_result2[0];
					if ($vRemainQty == '') $vRemainQty = 0;
				
				}	
			
								
				//Checking For Difference Btw Qty and Count SerialNo
				if (($rowsdt[6] != $rowsdt[17] && $rowsdt[16] != 0 && $Module_SerialNo == 1) || ($rowsdt[6] == 0 && $rowsdt[16] != 0 && $Module_SerialNo == 1) || ($rowsdt[6] == 0)) {
					$RecStyle = "style='background-color:#FF0000;'";
				}
				
			
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit['.$i.']\')"';
				
				echo"<tr id='CurRec$i' class='$bgcolor table-focus-g1'>";		
				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=\"DeleteRecordGrid('".$filepath."','".$form."', '".$PPurId."','".$rowsdt[0]."','".$i."','".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."');return false;\" title='Delete Record'  ></td>";
				
				// If ItemWithSerialNo True And ModuleSerialNo True	
				if ($rowsdt[16] == 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]."','".$vRemainQty."')\" title='Add Serial Nos'  ></td>";
				}
				else if ($rowsdt[16] == 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='145px;' align='left'>
							<input type='hidden' name='txtPurDtId[$i]' id='purdtid[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtItemVat[$i]' id='itemvat[$i]' value='$txtItemVat[$i]' >
							<input type='hidden' name='txtItemExpire[$i]' id='itemexpire[$i]' value='$txtItemExpire[$i]' >
							<input type='hidden' name='txtItemWithSerial[$i]' id='itemwithserial[$i]' value='$txtItemWithSerial[$i]' >
							<input type='hidden' name='txtItemUnitCoef[$i]' id='itemunitcoef[$i]' value='$txtItemUnitCoef[$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='txtItemCode[$i]' id='itemcode[$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,'lstItemCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'itemcode[$i]','itemdescription[$i]','items');\" ".$KeyDown.">
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItems(1,$i); ' style='vertical-align:bottom;'/></span></label>
						</td>";
										
				echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDesc[$i]' id='itemdescription[$i]' value='".$rowsdt[3]."' class='".$ClassE."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDesc[$i]');\" ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDesc[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDesc(1,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
						</td>";
						
					
				echo"  	<td width='105px;' align='center'>
							<input type='text' name='txtWarehouseCode[$i]' id='warehousecode[$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,'lstWarehouseCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\" ".$KeyDown."   />
							<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouse($i);' style='vertical-align:bottom;'/></span></label>
						</td>";
						
				echo"	<td width='75px;' align='center'><input type='text' name='txtGrnRef[$i]' id='grnref[$i]' value='".$rowsdt[13]."' maxlength='20' class='".$ClassE."' style='font-size:12px; width:70px; height:20px;' readonly></td>";
				echo"   <td width='75px;' align='center'><input type='text' name='txtGrnQty[$i]' id='grnqty[$i]' value='".$vRemainQty."' maxlength='20' class='".$ClassE."' style='font-size:12px; width:70px; height:20px;' readonly  ></td>";
				echo "	<td width='65px;' align='left'><span class='".$TextColor."'>".$rowsdt[10]."</span></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtPurDtQty[$i]' id='purdtquantity[$i]' value='".$rowsdt[6]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; border-width:0px; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CalcQty2($Module_Unit1Method,1,$i);\" ".$KeyDown." ></td>";
					
				
				if ($Module_DoubleUnit == 1) { 
					echo"  <td width='65px;' align='left'><span class='".$TextColor."'>".$rowsdt[9]."</span></td>";	
					echo"  <td width='80px;' align='center'><input type='text' name='txtPurDtQty2[$i]' id='unit2qty[$i]' value='".$rowsdt[8]."' maxlength='20' onchange=\"CalcQty2($Module_Unit1Method,2,$i); SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' ".$KeyDown." ></td>";
				} else {
					echo"  <input type='hidden' name='txtPurDtQty2[$i]' id='unit2qty[$i]' value='' >";
				}
				
				if ($Module_SerialNo == 1) {
					echo"  <td width='55px;' align='center'><span class='".$TextColor."'>".$rowsdt[17]."</span></td>";
				}
				
				//echo"	<td width='105px;' align='center'><input type='text' name='txtPurDtVolume[$i]' id='purdtvolume[$i]' value='".$rowsdt[7]."' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown."  ></td>";
				
				if ($Module_ProjectDt == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='".$rowsdt[11]."' class='".$ClassE."' style='width:120px;' maxlength='15' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCode[$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='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='' >";
				}
				if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='".$rowsdt[12]."' class='".$ClassE."' style='width:130px;' maxlength='15' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode[$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='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='' >";
				}
				
				if ($Module_ExpireDate == 1) {
					echo" 	<td width='105px;' align='center'><input type='text' name='txtPurDtBatchNo[$i]' id='batchno[$i]' value='".htmlspecialchars($rowsdt[19], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' ".$KeyDown." >
								<label><span><img src='img/openlist.png' title='Select Batch No' id='lstBatchNo[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistBatchNo(1,$i); ' style='vertical-align:bottom;'/></span></label></td>
							<td width='85px;' align='center'><input type='text' name='txtPurDtExpireDate[$i]' id='expiredate[$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='txtPurDtExpireDate[$i]' id='expiredate[$i]' value=''>";
					echo" <input type='hidden' name='txtPurDtBatchNo[$i]' id='batchno[$i]' value=''>";
				}
				
				echo"	<td width='255px;'><input type='text' name='txtPurDtRemark[$i]' id='remarkdt[$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'><img src='img/confirm-1.png' id='imgSubmit[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitRecordGrid('".$i."','".$filepath."', '".$form."', '".$PPurId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$FI_PurchaseCategory); return false;\" title='Submit Record' style='vertical-align:bottom;' ></td>";
				echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit[$i]' onclick=\"SubmitRecordGrid('".$i."','".$filepath."', '".$form."', '".$PPurId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$FI_PurchaseCategory); 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($txtWarehouseCode[$i])) {
				if (!empty($LastItemWarehouse))
					$txtWarehouseCode[$i] = $LastItemWarehouse;
				else if (!empty($SetupDftWareHouse))
					$txtWarehouseCode[$i] = $SetupDftWareHouse;
				else	
					$txtWarehouseCode[$i] = $defaultwarehouse;
			}

			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit['.$i.']\')"';
			
				
			echo"<tr id='CurRec$i' class='$bgcolor table-focus-g1' >";
			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='145px;' align='left'>
						<input type='hidden' name='txtPurDtId[$i]' id='purdtid[$i]' value='$txtPurDtId[$i]' >
						<input type='hidden' name='txtItemVat[$i]' id='itemvat[$i]' value='$txtItemVat[$i]' >
						<input type='hidden' name='txtItemExpire[$i]' id='itemexpire[$i]' value='$txtItemExpire[$i]' >
						<input type='hidden' name='txtItemWithSerial[$i]' id='itemwithserial[$i]' value='$txtItemWithSerial[$i]' >
						<input type='hidden' name='txtItemUnitCoef[$i]' id='itemunitcoef[$i]' value='$txtItemUnitCoef[$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='txtItemCode[$i]' id='itemcode[$i]' value='$txtItemCode[$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,'lstItemCode[$i]'); GetSelectedItem(this.id,'getitem','".$i."','".$txtDate."','".$txtCurrCode."','-1'); GetSelectedItemQty('getitemqty','".$i."','".$txtDate."');\" onkeyup=\"AutoCompleteData(event,this.id,'itemcode[$i]','itemdescription[$i]','items');\"  ".$KeyDown.">
						<label><span><img src='img/openlist.png' title='Select Item' id='lstItemCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItems(1,$i); ' style='vertical-align:bottom;'/></span></label>
					</td>";
									
			echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDesc[$i]' id='itemdescription[$i]' value='$txtItemDesc[$i]'  class='".$ClassI."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDesc[$i]');\" ".$KeyDown." />
						<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDesc[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDesc(1,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
					</td>";
					
			echo"  	<td width='105px;' align='center'>
						<input type='text' name='txtWarehouseCode[$i]' id='warehousecode[$i]' value='$txtWarehouseCode[$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,'lstWarehouseCode[$i]'); GetSelectedItemQty('getitemqty','".$i."','".$txtDate."');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\"  ".$KeyDown."  />
						<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouse($i);' style='vertical-align:bottom;'/></span></label>
					</td>";
					
			echo"	<td width='75px;' align='center'><input type='text' name='txtGrnRef[$i]' id='grnref[$i]' value='' maxlength='20' class='".$ClassI."' style='font-size:12px; width:70px; height:20px;' readonly></td>";
			echo"   <td width='75px;' align='center'><input type='text' name='txtGrnQty[$i]' id='grnqty[$i]' value='' maxlength='20' class='".$ClassI."' style='font-size:12px; width:70px; height:20px;' readonly  ></td>";
			echo"   <td width='65px;' align='center'><input type='text' name='txtItemUnit1' id='itemunit1[$i]' value='$txtItemUnit1' 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='txtPurDtQty[$i]' id='purdtquantity[$i]' value='$txtPurDtQty[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CalcQty2($Module_Unit1Method,1,$i);\" ".$KeyDown." ></td>";
					
				
		  
			if ($Module_DoubleUnit == 1) {
				echo"  <td width='65px;' align='center'><input type='text' name='txtItemUnit2' id='itemunit2[$i]' value='$txtItemUnit2' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:60px; height:20px;' readonly></td>";
				echo"  <td width='80px;' align='center'><input type='text' name='txtPurDtQty2[$i]' id='unit2qty[$i]' value='$txtPurDtQty2[$i]' maxlength='20' onchange=\"CalcQty2($Module_Unit1Method,2,$i); SetModRecord('ModRec_G1','$i');\" class='".$ClassI."'  style='font-size:12px; width:75px; height:20px;' ".$KeyDown." ></td>";
			} else {
				echo "<input type='hidden' name='txtPurDtQty2[$i]' id='unit2qty[$i]' value='' >";
			}
			
			if ($Module_SerialNo == 1) {
				echo"  <td width='55px;' align='center'><span class='".$TextColor."'>&nbsp;</span></td>";
			}
			
			//echo"	<td width='105px;' align='center'><input type='text' name='txtPurDtVolume[$i]' id='purdtvolume[$i]' value='$txtPurDtVolume[$i]' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown."  ></td>";
				
			if ($Module_ProjectDt == 1) {
				echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='$txtProjectCodeDt[$i]' class='".$ClassI."' style='width:120px;' maxlength='15' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode[$i]');\" ".$KeyDown." /></span>
						<label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCode[$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='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='' >";
			}
			if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) {
				echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='$txtCostCentCodeDt[$i]' class='".$ClassI."' style='width:130px;' maxlength='15' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span>
						<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode[$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='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='' >";
			}
			
			if ($Module_ExpireDate == 1) {
				echo" 	<td width='105px;' align='center'><input type='text' name='txtPurDtBatchNo[$i]' id='batchno[$i]' value='".htmlspecialchars($txtPurDtBatchNo[$i], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' style='font-size:12px; width:75px; height:20px;' ".$KeyDown." >
							<label><span><img src='img/openlist.png' title='Select Batch No' id='lstBatchNo[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistBatchNo(1,$i); ' style='vertical-align:bottom;'/></span></label></td>
						<td width='85px;' align='center'><input type='text' name='txtPurDtExpireDate[$i]' id='expiredate[$i]' value='$txtPurDtExpireDate[$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='txtPurDtExpireDate[$i]' id='expiredate[$i]' value=''>";
				echo" <input type='hidden' name='txtPurDtBatchNo[$i]' id='batchno[$i]' value=''>";
			}
			
			echo"	<td width='255px;'><input type='text' name='txtPurDtRemark[$i]' id='remarkdt[$i]' value='".htmlspecialchars($txtPurDtRemark[$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'><img src='img/confirm-1.png' id='imgSubmit[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitRecordGrid('".$i."','".$filepath."', '".$form."', '".$PPurId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$Module_SerialNo,$FI_PurchaseCategory); return false;\" title='Submit Record' style='vertical-align:bottom;' ></td>";
			echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit[$i]' onclick=\"SubmitRecordGrid('".$i."','".$filepath."', '".$form."', '".$PPurId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$FI_PurchaseCategory); 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,$PPurId,'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>";

}

	
	
?>