<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);

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(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
		mysql_query("SET NAMES 'utf8'"); 
		mysql_query('SET CHARACTER SET utf8'); 
		mysql_set_charset('utf8', $connection);
	}

	//echo $_SESSION['dbName']."<br>";

 if ($form == 'ADR') {

					//Read From Module Table
					$querymodule=" Select ifNull(Module_AdditionalTaxes,0) As Module_AdditionalTaxes, ifNull(Module_Pack,0) As Module_Pack, ".
								 " ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
								 " ifNull(Module_RestrictProjCost,0) As Module_RestrictProjCost, ifNull(Module_RestrictCost,0) As Module_RestrictCost, ".
								 " ifNull(Module_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt, ".
								 " ifNull(Module_PRequestConfirm,0) As Module_PRequestConfirm, ifNull(Module_DoubleUnit,0) As Module_DoubleUnit, ifNull(Module_Unit1Method,0) As Module_Unit1Method ".
								 ", ifnull(Module_PurchaseRequestPrice,0) as Module_PurchaseRequestPrice ".
								 " From Module ";
					$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
					while($rowmodule=mysql_fetch_array($resultmodule)){
						extract($rowmodule);
					}

					
	//Read From Module Table
$querymodule=" Select ifNull(Module_TransferWithOneWh,0) As Module_TransferWithOneWh,ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter , ifNull(Module_RestrictProjCost,0) As Module_RestrictProjCost, ifNull(Module_RestrictCost,0) As Module_RestrictCost , module_serialno,ifNull(Module_NegativeQuantity,0) As Module_NegativeQuantity ,Module_TransferSorder  
				,ifNull(Module_DoubleUnit,0) As Module_DoubleUnit 
				From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$ModuleProject=$Module_Project;
$ModuleCostCenter=$Module_CostCenter;
	
	//Read From Module Table
$querymodule="Select ifNull(Module_TransferWithOneWh,0) As Module_TransferWithOneWh,Module_TransferSorder,ifnull(Module_ZeroQuantity,0) as Module_ZeroQuantity,ifnull(Module_Unit1Method,0) as Module_Unit1Method, 
			ifNull(Module_Heatno,0) As Module_Heatno,ifnull(Module_DoubleUnit,0) as Module_DoubleUnit,ifnull(Module_TransferRequestPrice,0) as Module_TransferRequestPrice, ifnull(Module_IsInvoice,0) as Module_IsInvoice
			From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ".
								 " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

	ShowAdjustmentRequestDtGrid($connection,'ADR',$transid,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2,$DecimalBase,$Module_DoubleUnit,$Module_ProjectDt,$Module_CostCenterDt,$Module_Unit1Method,$Module_Pack, $Module_Heatno, $Module_IsInvoice);
		
	}

}
	    	



function ShowAdjustmentRequestDtGrid($connection,$form,$txtAdjId,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2,$DecimalBase,$Module_DoubleUnit,$Module_ProjectDt,$Module_CostCenterDt,$Module_Unit1Method,$Module_Pack, $Module_Heatno, $Module_IsInvoice){

	//Read From AdjustmentSetup Table
	$queryAdjustSetup="Select ifNull(ShowCostCentLayout,0) As ShowCostCentLayout From AdjustmentSetup ";
	$resultAdjustSetup=mysql_query($queryAdjustSetup,$connection) or die(mysql_error());
	while($rowAdjustSetup=mysql_fetch_array($resultAdjustSetup)){
		extract($rowAdjustSetup);
	}
	
	$queryCostSetup="Select ifNull(FI_ShowCostPrice,0) As FI_ShowCostPrice From ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."') ";
	$resultCostSetup=mysql_query($queryCostSetup,$connection) or die(mysql_error());
	while($rowCostSetup=mysql_fetch_array($resultCostSetup)){
		extract($rowCostSetup);
	} 
	
	$ClassI = 'grid_roundedtext2';
	$filepath = 'Forms_DataGrid_AdjustmentRqst.php';
	

	$PriceLabel = 'Price';	
	if ($PurchaseTTC == 1)  $PriceLabel = 'Price TTC';	
	
	
	if ($startrange=='')	$startrange = 0;
		
	if ($direction == 'asc')
		$direction = 'desc';
	else if ($direction == 'desc')
		$direction = 'asc';
	else $direction = 'asc';

	if ($perpage=='')
		$perpage = 20;
	
		
			
								
	$columnsarray = array("txtItemCodePacked"
						,"txtItemCode"
						,"txtItemDesc"
						,"lstWarehouse"
						,"txtAdjDtQty"
						);

	if ($Module_DoubleUnit==1) {
				$columnsarray[] = 'txtItemUnit1';
				$columnsarray[] = 'txtAdjDtQty2';
				$columnsarray[] = 'txtItemUnit2';
	}
	if($FI_ShowCostPrice == 1)				
		$columnsarray[] = "txtcostpriceDt";
	if($Module_Heatno == 1) $columnsarray[] = 'txtAdjDtHeatNo';		
	if ($Module_ProjectDt == 1)	$columnsarray[] = "txtProjectCodeDt";
	
	if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1)
		$columnsarray[] = "txtCostCentCodeDt";
			
		$columnsarray[] = "txtAdjDtExpireDate";
	
	if($Module_IsInvoice == 1) $columnsarray[] = "InvDEBITaccount";
	$columnslist = implode(',', $columnsarray);
	
	

	
echo"<input type='hidden' name='headercurrency_code' id='headercurrency_code' value='$headercurrency_code'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";


if ($orderby=='')
	$orderby = 'prqstdt_id';
	
	
	  
		$query = " Select AdjustmentRequestDt.AdjustmentRequestDt_ID, AdjustmentRequestDt.Item_CodePacked, AdjustmentRequestDt.Item_code, Item_Description, AdjustmentRequestDt.Project_code, AdjustmentRequestDt.CostCent_Code, AdjustmentRequestDt.Warehouse_Code, ".
				 " AdjustmentRequestDt_Quantity ,AdjustmentRequestDt.Item_Unit2Qty, Item_UnitPurchaseDesc, Item_UnitSalesDesc ".
				 " ,Date_Format(AdjustmentRequestDt.AdjustmentRequestDt_ExpireDate,'%d/%m/%Y') As ExpireDate , AdjustmentRequestDt.AdjustmentRequestDt_BatchNo ".
				 ", Round(AdjustmentRequestDt_Price, ".$DecimalBase."), AdjustmentRequestDt_PriceBase1, AdjustmentRequestDt_PriceBase2, ".
				 " Round((ifNull(AdjustmentRequestDt_Quantity,0)*ifNull(AdjustmentRequestDt_Price,0)), ".$DecimalBase.") As TotalAmount, AdjustmentRequestDt_heatno, InvDEBITaccount ".
				 " From Temp_AdjustmentRequestDt As AdjustmentRequestDt Left Join Items on AdjustmentRequestDt.Item_code = Items.Item_code ".
				 " Where AdjustmentRequestDt.AdjustmentRequest_ID = '".$txtAdjId."'".
				 " Group By  AdjustmentRequestDt.AdjustmentRequestDt_ID ".
				 " Order By AdjustmentRequestDt.AdjustmentRequestDt_ID Asc ";
						
						
//echo $query;	
$result=mysql_query($query,$connection)  or die(mysql_error());
$totalrows = mysql_num_rows($result);

$query = $query." limit ".$startrange.",".$perpage;
//echo $query;
$result=mysql_query($query,$connection);

$i=0;
//echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";
echo"<div id='prequestdtdiv' style='width:1200px;height:300px'>";
echo"<table border='0' align='left'   class='grid_data'  style='table-layout:fixed;font-size:10px;border:0px solid black;border-spacing:0;width:1200px;' cellpadding='0' cellspacing='1'>";
echo"	<col width=30>";
if ($Module_Pack == 1)
	echo" <col width=120>";

    echo" <col width=150>  
		  <col width=200>	
		  <col width=110>
		  <col width=80>	
		  <col width=80> ";
  
if ($Module_DoubleUnit==1)	{		  
	echo"<col width=80><col width=85>";
}

if($FI_ShowCostPrice == 1){
    echo"<col width=80><col width=85>";
}
if($Module_Heatno == 1) echo"<col width=120>";				  
if ($Module_ProjectDt == 1)	 echo"<col width=120>";
if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) echo"<col width=120>";
	echo"<col width=75>";
if($Module_IsInvoice == 1)	  echo"<col width=120>";		
	echo "<col width=30>";
		  

	echo"<tr height='25px'>";
	echo"  <th bgcolor='#F7F7F7' align='left'>&nbsp;</span></th>";
if ($Module_Pack == 1)
	echo"  <th bgcolor='#F7F7F7' align='left'>Item Packed</span></th>";  
	echo"  <th bgcolor='#F7F7F7' align='left'>Item </span></th>";  
	echo"  <th bgcolor='#F7F7F7' align='left'>Description</span></th>";
	echo"  <th bgcolor='#F7F7F7' align='center'>WH.</span></th>";
	echo"  <th bgcolor='#F7F7F7' align='left'>Qty</span></th>";
	echo"  <th bgcolor='#F7F7F7' align='left'>Unit1</span></th>";
	//echo"  <td bgcolor='#F7F7F7' align='left'>Real Qty</span></td>";
if ($FI_ShowCostPrice == 1) {  
	echo"  <th width='85px;' align='center'><span>Cost Price</span></th>";
	echo"  <th width='105px;' align='center'><span>Total</span></th>";
}

if ($Module_DoubleUnit==1) {
	echo"  <th bgcolor='#F7F7F7' align='left'>Qty2</span></th>";
	echo"  <th bgcolor='#F7F7F7' align='left'>Unit2</span></th>";
}

if($Module_Heatno == 1) echo"  <th bgcolor='#F7F7F7' align='left'>Heat No.</span></th>";

if ($Module_ProjectDt == 1)	
	echo"  <th bgcolor='#F7F7F7' align='center'>Project</span></th>";

if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1)
	echo"  <th bgcolor='#F7F7F7' align='center'>Costcenter</span></th>";

	echo"  <th bgcolor='#F7F7F7' align='left'>Expire Date</span></th>";	  
if ($Module_IsInvoice == 1)	
	echo"  <th bgcolor='#F7F7F7' align='left'>Ledger Number</span></th>";	  
	echo"  <th bgcolor='#F7F7F7' align='left'></th>";	  

	echo"</tr>";



	$i=0;
	$j=1;
	
	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'>		 
		 ";

		 
while($row=mysql_fetch_row($result)){
		
		
	if ($i%2==0)
		$bgcolor='#F5FAFF';
	else	
		$bgcolor='#FFFFFF';
		
		$KeyDown   = 'onkeydown="return dokeytransferrequest(event,this,'.$i.',\''.$columnslist.'\',\'PTransReqDt\')"';



		
			   
	$txtAdjDtId[$i] = $row[0];
	$lstItemType[$i] = 'All';
	$txtItemCodePacked[$i] = $row[1];
	$txtItemCode[$i] = $row[2];
	$txtItemDesc[$i] = $row[3];
	$txtProjectCodeDt[$i] = $row[4];
	$txtCostCentCodeDt[$i] = $row[5];
	$lstWarehouse[$i] = $row[6];
	$txtAdjDtQty[$i] = $row[7];
	$txtAdjDtQty2[$i] = $row[8];
	$txtItemUnit1[$i] = $row[9];
	$txtItemUnit2[$i] = $row[10];
	
	$txtAdjDtExpireDate[$i] = $row[11];
	$txtAdjDtBatchNo[$i] = $row[12];

	$txtcostpriceDt[$i] = $row[13];
	$txtAdjDtHeatNo[$i] = $row[17];
	$txtAdjDtTotal[$i] = $txtcostpriceDt[$i] * $txtAdjDtQty[$i];
	$txtAdjDtInvDebitAcc[$i] = $row[18];
	//echo"<tr height='20px' id='prqstdt$i' onclick=\"returncolor(this,'SelectedRec','SelectedRecColor','$row[0]')\" style='background-color:$bgcolor'>";
	echo"<tr id='CurRec$i' class='$bgcolor table-focus-g1'>";

		
	$recno = $i+1;
	$recno = $perpage * (($startrange / $perpage)) + 1 + $i;
	
	echo"<td  align=center onclick=\"deletetrequestsdt('".$txtAdjId."','".$txtAdjDtId[0]."','".$txtItemCodePacked[$i]."','".$txtItemCode[$i]."','$filepath'); return false;\"><img src='img/delete.png' onmouseover=\"style.cursor='pointer'\" name='' title='Delete' ></td>";

   //if ($Module_Pack == 1)
//		echo"<td ><span class='style4'><input type='text'   class='roundedtext_amortization_medium' readonly   $KeyDown  name='txtItemCodePacked[$i]' id='txtItemCodePacked[$i]' value='".$txtItemCodePacked[$i]."' style='width:100px'> </span></td>";
//	else
//		echo"<input type='hidden'  name='txtItemCodePacked[$i]' id='txtItemCodePacked[$i]' value='".$txtItemCodePacked[$i]."'>";
	
   if ($Module_Pack == 1)
   echo"<td ><span class='style4'><input type='text'   name='txtItemCodePacked[$i]' id='txtItemCodePacked[$i]' value='".$txtItemCodePacked[$i]."'   $KeyDown   class='roundedtext_amortization_small'   readonly  style='width:100px'></span></td>";

	echo"<td align=center><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'     name='txtItemCode[$i]' id='txtItemCode[$i]' value='".$txtItemCode[$i]."' onchange=\"setitemcode(this.value,'txtItemCode[$i]','txtItemDesc[$i]','Item_Unit[$i]','txtItemUnit1[$i]','txtItemUnit2[$i]','i_unitcoef[$i]','','trqstdtitemcodeimage[$i]','trqstdtitemcodeimage1[$i]',1,'$i');SetModRecord('ModRec_G1','$i')\"  onblur=\"FillData('txtProjectCodeDt[$i]','txtCostCentCodeDt[$i]')\" style='width:120px'></span>
		<img src='img/scroll-down-1.png' width='20' height='20' id='trqstdtitemcodeimage[$i]' onmouseover=\"style.cursor='pointer'\"  onclick=\"showlistItems('$i');FillData('txtProjectCodeDt[$i]','txtCostCentCodeDt[$i]')\">
			</td>";

	echo"<td align=center><span class='style4'><input type='text'   class='roundedtext_amortization_mediumlarge'    $KeyDown     onchange=\"setitemcode(this.value,'txtItemCode[$i]','txtItemDesc[$i]','Item_Unit[$i]','txtItemUnit1[$i]','txtItemUnit2[$i]','i_unitcoef[$i]','','prqstdtitemcodeimage[$i]','trqstdtitemcodeimage1[$i]',2, '$i');SetModRecord('ModRec_G1','$i')\"     name='txtItemDesc[$i]' id='txtItemDesc[$i]' value='".$txtItemDesc[$i]."' style='width:190px'> </span>
	<img src='img/scroll-down-1.png' width='20' hidden height='20' id='trqstdtitemcodeimage1[$i]' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage1('itemcode','txtItemCode[$i]','txtItemDesc[$i]','Item_Unit[$i]','txtItemUnit1[$i]','txtItemUnit2[$i]','i_unitcoef[$i]','800','500','".htmlentities($txtProjectCodeDt[$i])."','$TransType')\">	";
		
	echo"</td>";
			
	
	echo"<td align=center><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='lstWarehouse[$i]' id='lstWarehouse[$i]' value='".$lstWarehouse[$i]."' onchange=\"setwarehousecode(this.value,'lstWarehouse[$i]','imgwarehousebtn[$i]');SetModRecord('ModRec_G1','$i');\"  > </span>";
		echo"<img src='img/scroll-down-1.png' title=' Select Warehouse ' id='imgwarehousebtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistWarehouse('lstWarehouse','lstWarehouse[$i]','800','500') \" />
		</td>";					
			
	echo"<td align=center><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'   name='txtAdjDtQty[$i]' id='txtAdjDtQty[$i]' value='".$txtAdjDtQty[$i]."' style='width:70px'  ";
	if($FI_ShowCostPrice == 1) echo " onKeyup=\"CalcAdjDtTotal(1,$DecimalBase,$i);\" ";
	echo " onchange=\"changeqty2(1,'$Item_Unit','$Module_Unit1Method',$i);SetModRecord('ModRec_G1','$i');\" > </span></td>";


	echo"<td align=center><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'   name='txtItemUnit1[$i]' id='txtItemUnit1[$i]' value='".$txtItemUnit1[$i]."' style='width:70px'  onchange=\"SetModRecord('ModRec_G1','$i');\" > </span></td>";
	if ($FI_ShowCostPrice == 1) {  
		echo"<td align=center><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='txtcostpriceDt[$i]' onKeyup=\"CalcAdjDtTotal(1,$DecimalBase,$i);\"      style='width:70px'  id='txtcostpriceDt[$i]'  value='".$txtcostpriceDt[$i]."'  size=4> </td>";
		echo"<td align=center> <input type='text' $KeyDown   class='roundedtext_amortization_medium' name='txtAdjDtTotal[$i]'      style='width:70px'  id='txtAdjDtTotal[$i]'  value='".$txtAdjDtTotal[$i]."'  size=4 readonly> </td>";
	}	
		
		
	if ($Module_DoubleUnit==1) {
	echo"<td align=center><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='txtAdjDtQty2[$i]'    ";
	
	echo " onchange=\"changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i);\"   style='width:70px'  id='txtAdjDtQty2[$i]'  value='".$txtAdjDtQty2[$i]."'  size=4> </td>";
	echo"<td align=center><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='txtItemUnit2[$i]'    onchange=changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i)   style='width:70px'  id='txtItemUnit2[$i]'  value='".$txtItemUnit2[$i]."'  size=4> </td>";
	}
	else {
	echo"<input type='hidden' name='txtAdjDtQty2[$i]'  "; 
	
	echo " onchange=changeqty2(2,'$Item_Unit[$i]',$Module_Unit1Method,$i)  value='".$txtAdjDtQty2[$i]."'  size=4>";
	}

	echo"	  <input type='hidden' name='lstItemType[$i]'  id='lstItemType[$i]' value='".$lstItemType[$i]."'  size=4>";
	echo"	  <input type='hidden' name='Item_Unit[$i]' id='Item_Unit[$i]' value='".$Item_Unit[$i]."'  size=4>";

			if ($rowsdt[6]=='')		$rowsdt[6] = 0;
			if ($rowsdt[7]=='') 	$rowsdt[7] = 0;
			
				
			$amount[$i] = $rowsdt[6] * $rowsdt[7];
			//$totalamount = $totalamount + $amount;
				
			

			
	echo"<input type='hidden' name='txtAdjDtBatchNo[$i]'   style='width:70px'  id='txtAdjDtBatchNo[$i]'  value='".$txtAdjDtBatchNo[$i]."'  size=4>";
			
	if($Module_Heatno == 1)	
		echo"<td align=center><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='txtAdjDtHeatNo[$i]'  style='width:90px'  id='txtAdjDtHeatNo[$i]'  value='".$txtAdjDtHeatNo[$i]."'  > 
			<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='txtAdjDtHeatNo[$i]' id='txtAdjDtHeatNo[$i]' value='".$txtAdjDtHeatNo[$i]."'>";
	
	if ($Module_ProjectDt == 1)	
		echo"<td align=center><span class='style4'><input type='text'   $KeyDown  class='roundedtext_amortization_medium'    style='width:90px'  name='txtProjectCodeDt[$i]' id='txtProjectCodeDt[$i]' value='".$txtProjectCodeDt[$i]."'   onchange=\"setprojectcode(this.value,'txtProjectCodeDt[$i]','imgprojectbtn[$i]');SetModRecord('ModRec_G1','$i');\" > </span>
		<img src='img/scroll-down-1.png' title=' Select Project ' id='imgprojectbtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"SetModRecord('ModRec_G1','$i');showlistProject('project','txtProjectCodeDt[$i]','800','500',3); \" />			
		</td>";
	else
		echo"<span class='style4'><input type='hidden'   name='txtProjectCodeDt[$i]' id='txtProjectCodeDt[$i]' value='".$txtProjectCodeDt[$i]."'> ";
	
	if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1)
		echo"<td align=center><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:90px'  name='txtCostCentCodeDt[$i]' id='txtCostCentCodeDt[$i]' value='".$txtCostCentCodeDt[$i]."'    onchange=\"setcostcentercode(this.value,'txtCostCentCodeDt[$i]','imgcostcenterbtn[$i]');SetModRecord('ModRec_G1','$i');\"  > 
			<img src='img/scroll-down-1.png' title=' Select Costcenter ' id='imgcostcenterbtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"SetModRecord('ModRec_G1','$i');showlistCostcenter('costcenter','txtCostCentCodeDt[$i]','800','500',3) \" />
			</span></td>";
	else
		echo"<input type='hidden'  name='txtCostCentCodeDt[$i]' id='txtCostCentCodeDt[$i]' value='".$txtCostCentCodeDt[$i]."'>"; 				
	
	
	echo"<td align=center><span class='style4'><input type='text'   $KeyDown      class='".$ClassI." date'  style='width:65px;border-width:0px' name='txtAdjDtExpireDate[$i]' id='txtAdjDtExpireDate[$i]' value='".$txtAdjDtExpireDate[$i]."' onclick=\"SetModRecord('ModRec_G1','$i');\" > </span></td>";
	
	if ($Module_IsInvoice == 1)	
		echo"<td align=center><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   maxlength='10'  style='width:90px'  name='txtAdjDtInvDebitAcc[$i]' id='InvDEBITaccount[$i]' value='".$txtAdjDtInvDebitAcc[$i]."'    onchange=\"SetModRecord('ModRec_G1','$i');\" > 
			<label><img src='img/btnopen.jpg' title=' Select Ledger ' id='lstLedgerCodeC' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistLedgers('3','$i'); \" /></label></td>";		
	else 
		echo" <input type='hidden' name='txtAdjDtInvDebitAcc[$i]' id='InvDEBITaccount[$i]' value=''>";		
	echo"<td align=center><img src='img/confirm-1.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitPTransReqDt[$i]' title='Save' onclick=\"submitAdjustReqDt('$txtAdjDtId[$i]','$txtAdjId','$i','e','$PurchaseTTC','$FIPurchaseCategory','$filepath')\"></td>";
	echo"<input type='hidden'  name='txtAdjDtId[$i]' id='txtAdjDtId[$i]' value='".$txtAdjDtId[$i]."' >";
	echo"</tr>";
			
			
			$i+=1;
		}
		
		if (empty($warehousecode[$i])) { //echo $_SESSION['prqstdefaultwarehouse'];
				if(!empty($_SESSION['prqstsetupdefaultWareHouse'] ))
					$warehousecode[$i] = $_SESSION['prqstsetupdefaultWareHouse'] ;
				else	
					$warehousecode[$i] = $_SESSION['prqstdefaultwarehouse'];
			}
			
	$k=1;
		$morelines = 1;
		//echo $morelines;
		while ($k <= $morelines) {
			$recno = $i+1;
			if ($k==$morelines)
				$mode = 'i';
			else
				$mode = 'e';			
			
			$KeyDown   = 'onkeydown="return dokeytransferrequest(event,this,'.$i.',\''.$columnslist.'\',\'PTransReqDt\');"';
		
			echo"<tr height='30px' id='CurRec$i' class='$bgcolor table-focus-g1'>";
			echo"<td align=center><img src='img/undo-1.png' width=20 height=20 onmouseover=\"style.cursor='pointer'\" name='' title='Clear' onclick=\"clearprequestdt('$i','$PurchaseTTC','$Module_DoubleUnit')\"></td>";
			if ($Module_Pack == 1)
			echo"<td ><span class='style4'><input type='text'   name='txtItemCodePacked[$i]' id='txtItemCodePacked[$i]' value='".$txtItemCodePacked[$i]."'   $KeyDown   class='roundedtext_amortization_small'   readonly  style='width:100px'></span></td>";
		
			echo"<td align=center valign='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'     name='txtItemCode[$i]' id='txtItemCode[$i]' value='".$txtItemCode[$i]."' onchange=\"setitemcode(this.value,'txtItemCode[$i]','txtItemDesc[$i]','Item_Unit[$i]','txtItemUnit1[$i]','txtItemUnit2[$i]','i_unitcoef[$i]','','trqstdtitemcodeimage[$i]','trqstdtitemcodeimage1[$i]',1, '$i');SetModRecord('ModRec_G1','$i')\"  onblur=\"FillData('txtProjectCodeDt[$i]','txtCostCentCodeDt[$i]')\" style='width:120px'></span>
				<img src='img/scroll-down-1.png' width='20' height='20' id='trqstdtitemcodeimage[$i]' onmouseover=\"style.cursor='pointer'\"  onclick=\"showlistItems('$i');FillData('txtProjectCodeDt[$i]','txtCostCentCodeDt[$i]')\">
					</td>";

			echo"<td align=center><span class='style4'><input type='text'   class='roundedtext_amortization_mediumlarge'    $KeyDown     onchange=\"setitemcode(this.value,'txtItemCode[$i]','txtItemDesc[$i]','Item_Unit[$i]','txtItemUnit1[$i]','txtItemUnit2[$i]','i_unitcoef[$i]','','prqstdtitemcodeimage[$i]','trqstdtitemcodeimage1[$i]',2,'$i');SetModRecord('ModRec_G1','$i')\"     name='txtItemDesc[$i]' id='txtItemDesc[$i]' value='".$txtItemDesc[$i]."' style='width:190px'> </span>
			<img src='img/scroll-down-1.png' width='20' hidden height='20' id='trqstdtitemcodeimage1[$i]' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage1('itemcode','txtItemCode[$i]','txtItemDesc[$i]','Item_Unit[$i]','txtItemUnit1[$i]','txtItemUnit2[$i]','i_unitcoef[$i]','800','500','".htmlentities($txtProjectCodeDt[$i])."','$TransType')\">	";
				
			echo"</td>";
					
			$prei = $i-1;
		if ($lstWarehouse[$prei] !='')
			$lstWarehouse[$i] = $lstWarehouse[$prei];
		else
		if (empty($lstWarehouse[$i])) { 
				if(!empty($_SESSION['prqstsetupdefaultWareHouse'] ))
					$lstWarehouse[$i] = $_SESSION['prqstsetupdefaultWareHouse'] ;
				else	
					$lstWarehouse[$i] = $_SESSION['prqstdefaultwarehouse'];
			}
			
			
			echo"<td align=center><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='lstWarehouse[$i]' id='lstWarehouse[$i]' value='".$lstWarehouse[$i]."' onchange=\"setwarehousecode(this.value,'lstWarehouse[$i]','imgwarehousebtn[$i]');SetModRecord('ModRec_G1','$i');\"  > </span>";
				echo"<img src='img/scroll-down-1.png' title=' Select Warehouse ' id='imgwarehousebtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistWarehouse('lstWarehouse','lstWarehouse[$i]','800','500') \" />
				</td>";					
					
			echo"<td align=center><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'   name='txtAdjDtQty[$i]' id='txtAdjDtQty[$i]' value='".$txtAdjDtQty[$i]."' style='width:70px'  ";
			if($FI_ShowCostPrice == 1) echo " onKeyup=\"CalcAdjDtTotal(1,$DecimalBase,$i);\" ";
			echo " onchange=\"changeqty2(1,'$Item_Unit','$Module_Unit1Method',$i);SetModRecord('ModRec_G1','$i');\" > </span></td>";
	

			echo"<td align=center><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'   name='txtItemUnit1[$i]' id='txtItemUnit1[$i]' value='".$txtItemUnit1[$i]."' style='width:70px'  onchange=\"SetModRecord('ModRec_G1','$i');\" > </span></td>";
	
		if($FI_ShowCostPrice == 1){
			echo"<td align=center><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='txtcostpriceDt[$i]'    onKeyup=\"CalcAdjDtTotal(1,$DecimalBase,$i);\"     style='width:70px'  id='txtcostpriceDt[$i]'  value='".$txtcostpriceDt[$i]."'  size=4> </td>";
			echo"<td align=center><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='txtAdjDtTotal[$i]'       style='width:70px'  id='txtAdjDtTotal[$i]'  value='".$txtAdjDtTotal[$i]."'  size=4 readonly> </td>";
		
		}else {
					echo" <input type='hidden' name='txtcostpriceDt' id='txtcostpriceDt[$i]' value='' >
						  <input type='hidden' name='txtAdjDtTotal' id='txtAdjDtTotal[$i]' value='' >";
				}
				
		if ($Module_DoubleUnit==1) {
		echo"<td align=center><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='txtAdjDtQty2[$i]'   ";
				
		echo " onchange=\"changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i);\"   style='width:70px'  id='txtAdjDtQty2[$i]'  value='".$txtAdjDtQty2[$i]."'  size=4> </td>";
		echo"<td align=center><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='txtItemUnit2[$i]'    onchange=changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i)   style='width:70px'  id='txtItemUnit2[$i]'  value='".$txtItemUnit2[$i]."'  size=4> </td>";
		}
		else {
		echo"<input type='hidden' name='txtAdjDtQty2[$i]'  ";
		
		echo " onchange=changeqty2(2,'$Item_Unit[$i]',$Module_Unit1Method,$i)  value='".$txtAdjDtQty2[$i]."'  size=4>";
		}
		
		echo"	  <input type='hidden' name='lstItemType[$i]'  id='lstItemType[$i]' value='".$lstItemType[$i]."'  size=4>";
		echo"	  <input type='hidden' name='Item_Unit[$i]' id='Item_Unit[$i]' value='".$Item_Unit[$i]."'  size=4>";

				if ($rowsdt[6]=='')		$rowsdt[6] = 0;
				if ($rowsdt[7]=='') 	$rowsdt[7] = 0;
				
					
				$amount[$i] = $rowsdt[6] * $rowsdt[7];
				//$totalamount = $totalamount + $amount;
				
			

			
				echo"<input type='hidden' name='txtAdjDtBatchNo[$i]'   style='width:70px'  id='txtAdjDtBatchNo[$i]'  value='".$txtAdjDtBatchNo[$i]."'  size=4>";
			
			
				
			
	if($Module_Heatno == 1)	
		echo"<td align=center><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='txtAdjDtHeatNo[$i]'  style='width:90px'  id='txtAdjDtHeatNo[$i]'  value='".$txtAdjDtHeatNo[$i]."'  > 
			<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='txtAdjDtHeatNo[$i]' id='txtAdjDtHeatNo[$i]' value='".$txtAdjDtHeatNo[$i]."'>";
	
	if ($Module_ProjectDt == 1)	
			echo"<td align=center><span class='style4'><input type='text'   $KeyDown  class='roundedtext_amortization_medium'    style='width:90px'  name='txtProjectCodeDt[$i]' id='txtProjectCodeDt[$i]' value='".$txtProjectCodeDt[$i]."'   onchange=\"setprojectcode(this.value,'txtProjectCodeDt[$i]','imgprojectbtn[$i]');SetModRecord('ModRec_G1','$i');\"  > </span>
			<img src='img/scroll-down-1.png' title=' Select Project ' id='imgprojectbtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"SetModRecord('ModRec_G1','$i');showlistProject('project','txtProjectCodeDt[$i]','800','500',3); \" />			
			</td>";
	else
	echo"<input type='hidden'   name='txtProjectCodeDt[$i]' id='txtProjectCodeDt[$i]' value='".$txtProjectCodeDt[$i]."'> ";

		if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1)
			echo"<td align=center><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:90px'  name='txtCostCentCodeDt[$i]' id='txtCostCentCodeDt[$i]' value='".$txtCostCentCodeDt[$i]."'    onchange=\"setcostcentercode(this.value,'txtCostCentCodeDt[$i]','imgcostcenterbtn[$i]');SetModRecord('ModRec_G1','$i');\" > 
			<img src='img/scroll-down-1.png' title=' Select Costcenter ' id='imgcostcenterbtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"SetModRecord('ModRec_G1','$i');showlistCostcenter('costcenter','txtCostCentCodeDt[$i]','800','500',3) \" />
			</span></td>";
		else
		echo"<input type='hidden' name='txtCostCentCodeDt[$i]' id='txtCostCentCodeDt[$i]' value='".$txtCostCentCodeDt[$i]."'>"; 				

	echo"<td align=center><span class='style4'><input type='text'   $KeyDown      class='".$ClassI." date'  style='width:65px;border-width:0px' name='txtAdjDtExpireDate[$i]' id='txtAdjDtExpireDate[$i]' value='".$txtAdjDtExpireDate[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" > </span></td>";
	
	if ($Module_IsInvoice == 1)	
		echo"<td align=center><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   maxlength='10'  style='width:90px'  name='txtAdjDtInvDebitAcc[$i]' id='InvDEBITaccount[$i]' value='".$txtAdjDtInvDebitAcc[$i]."'    onchange=\"SetModRecord('ModRec_G1','$i');\" > 
			<label><img src='img/btnopen.jpg' title=' Select Ledger ' id='lstLedgerCodeC' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick=\"showlistLedgers('3','$i'); \" /></label></td>";		
	else 
		echo" <input type='hidden' name='txtAdjDtInvDebitAcc[$i]' id='InvDEBITaccount[$i]' value=''>";		
	echo"<td align=center><img src='img/confirm-1.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitPTransReqDt[$i]' title='Save' onclick=\"return submitAdjustReqDt('$txtAdjDtId[$i]','$txtAdjId','$i','i','$PurchaseTTC','$FIPurchaseCategory','$filepath');\"></td>";
	echo"<input type='hidden'  name='txtAdjDtId[$i]' id='txtAdjDtId[$i]' value='".$txtAdjDtId[$i]."' >";
	echo"</tr>";
		$i+=1;
		$k+=1;
		}	
	
	echo"</table></div>";
	

	


}


?>