<?php

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

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(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}
	if ($form == 'ADJ') {
		ShowAdjustmentDtGrid($connection,$form,$transid,$_SESSION['gadj_parameters'],$_SESSION['gadj_arrayaccess'],$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	}
	else if ($form == 'ADJ-TOT') {
		ShowAdjustmentTotals($connection,$transid,$_SESSION['gadj_parameters'],$_SESSION['gadj_arrayaccess']);
	}
	
}

function ShowAdjustmentDtGrid($connection,$form,$PAdjId,$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_ShowCostPrice 		 	= $arrayparams['FI_ShowCostPrice'];
	$module_locationadjustment 	= $arrayparams['module_locationadjustment'];
	$ShowSellingPrice 			= $arrayparams['ShowSellingPrice'];
	$SetupDftWareHouse 			= $arrayparams['SetupDftWareHouse'];
	$defaultwarehouse  			= $arrayparams['defaultwarehouse'];
	$Module_Heatno 				= $arrayparams['Module_Heatno'];	
	$Adjustment_doubleunit 		= $arrayparams['Adjustment_doubleunit'];	
	$module_allowexpiry 		= $arrayparams['module_allowexpiry'];
	
	$DecimalBase 				= $arrayparams['DecimalBase'];
	$Base1 						= $arrayparams['Base1'];
	$Base2 						= $arrayparams['Base2'];
	
	$txtDate         			= $arrayparams['txtDate'];
	$txtCurrCode    	 		= $arrayparams['txtCurrCode'];
	$AdjustType      			= $arrayparams['AdjustType'];
	$Module_IsInvoice      		= $arrayparams['Module_IsInvoice'];

	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_DataGrid_Adjustment.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, "adjustmentdt_heatno");

	 array_push($columnsarray, "adjdtquantity");
	 
	if ($Module_DoubleUnit == 1) array_push($columnsarray, 'unit2qty');
	if ($FI_ShowCostPrice == 1)	 array_push($columnsarray, 'costprice');	
	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');
	}	
	if($Module_IsInvoice == 1  && $AdjustType == 'O') array_push($columnsarray, 'InvDEBITaccount');
	
	$columnsarrayall = array("itemcode", "itemdescription", "warehousecode", "adjdtquantity", "unit2qty", "costprice", "adjdttotal", "projectcodedt", "costcentcodedt", "expiredate", "batchno", "InvDEBITaccount", "adjdtid", "existingqty", "bookingqty", "availableqty", "itemunit1", "itemunit2", "itemvat", "itemexpire", "itemunitcoef");
	$orderbyarray = array("AdjustmentDt.Item_CodePacked", "Items.Item_Code", "Items.Item_Description", "AdjustmentDt.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 = 690;
	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 ($FI_ShowCostPrice == 1)    	$TableWidth += 190;
	if ($ShowSellingPrice == 1) 	$TableWidth += 120;
	if ($Module_ProjectDt == 1)    	$TableWidth += 160;
	if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) $TableWidth += 160;
	if ($Module_ExpireDate == 1)   $TableWidth += 190;
	if ($Module_IsInvoice == 1  && $AdjustType == 'O') $TableWidth += 120;
	if($Module_Heatno==1) $TableWidth += 150;
	
	$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 height='25px'>";
		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."', '".$PAdjId."', 'datagrid', 1, '".$dftorderby."', 'COR','AdjustmentDt.Item_CodePacked','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code Packed".$orderimg1."</span></th>";
			
		echo"  <th width='165px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PAdjId."', '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."', '".$PAdjId."', '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."', '".$PAdjId."', 'datagrid', 1, '".$dftorderby."', 'COR','AdjustmentDt.Warehouse_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Warehouse".$orderimg4."</span></th>";
		if($module_locationadjustment == 1)
	echo"  <th width='105px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PAdjId."', 'datagrid', 1, '".$dftorderby."', 'COR','AdjustmentDt.Warehouse_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Location".$orderimg4."</span></th>";
	
		if($Module_Heatno==1)
		echo"  <th width='150px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PAdjId."', 'datagrid', 1, '".$dftorderby."', 'COR','AdjustmentDt.Warehouse_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>HeatNo</span></th>";
	
		
		echo"  <th width='65px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PAdjId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_UnitSalesDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Unit1".$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."', '".$PAdjId."', '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>";
		}
		  
		if ($FI_ShowCostPrice == 1)  
			echo"  <th width='85px;' align='center'><span>Cost Price</span></th>";
		if ($ShowSellingPrice == 1) 
			echo"  <th width='85px;' align='center'><span>Selling Price</span></th>";
		if ($FI_ShowCostPrice == 1)  	
			echo"  <th width='105px;' align='center'><span>Total</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 ";
			if($module_allowexpiry == 1 && $AdjustType == 'O')
				echo " width='100px;' ";
			else echo " width='85px;' ";
			echo " align='center'><span>Expire Date</span></th>";	
		}
		if ($Module_IsInvoice == 1  && $AdjustType == 'O') echo "<th width='120px;'  align='center'><span>Invoice Debit</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 ($PAdjId != '' ) {
		      
			$TotalQty = 0;
			$i_nonstock  = 0;
			$i_zeroprice = 0;
			$i_minprice  = 0;
			$i_unitcoef  = 1;
			$i_expire    = 0;

					   
			$query = " Select AdjustmentDt.AdjustmentDt_ID, AdjustmentDt.Item_CodePacked, AdjustmentDt.Item_code, Item_Description, AdjustmentDt.Warehouse_Code, ".
					 " AdjustmentDt_Quantity, Round(AdjustmentDt_Price, ".$DecimalBase."), AdjustmentDt_PriceBase1, AdjustmentDt_PriceBase2, ".
					 " Round((ifNull(AdjustmentDt_Quantity,0)*ifNull(AdjustmentDt_Price,0)), ".$DecimalBase.") As TotalAmount, ".
					 " AdjustmentDt.Item_Unit2Qty, Item_UnitPurchaseDesc, Item_UnitSalesDesc, AdjustmentDt.Project_code, AdjustmentDt.CostCent_Code,  ".
					 " ifNull(item_withserialno,0) As ItemWithSerialNo, Count(SerialNo_Code) As CountSerialNo,  Date_Format(AdjustmentDt_ExpireDate,'%d/%m/%Y') As AdjustmentDt_ExpireDate, ".
					 " AdjustmentDt_BatchNo, AdjustmentDt.Journal_Type,adjustmentdt_heatno, ifnull(Item_SellingPrice1Base1,0) as Item_SellingPrice1Base1, AdjustmentDt.InvDEBITaccount ".
					 " From Temp_AdjustmentDt As AdjustmentDt Left Join Items on AdjustmentDt.Item_code = Items.Item_code ".
					 " Left Join Temp_Purchasesserialno on AdjustmentDt.AdjustmentDt_ID = Temp_Purchasesserialno.PurchaseDt_ID ".
					 " And Temp_Purchasesserialno.Journal_Type = AdjustmentDt.Journal_Type ".
					 " And Temp_Purchasesserialno.AdjustmentDt_ID Is Not Null ".
					 " Where AdjustmentDt.Adjustment_ID = ".$PAdjId.
					 " Group By  AdjustmentDt.AdjustmentDt_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)){
			    $adjustmentdt_heatno[$i]=$rowsdt[20];			
				$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;
				
				
				$Qry_QtyBookTemp = "SELECT ifnull(QtyBooking_Temp('".$rowsdt[2]."', '".$rowsdt[4]."', '".insertMySQLDate($txtDate)."', $rowsdt[0]),0) ";
				$result = selectData($connection, $Qry_QtyBookTemp);
				if ($result[0] < 0){$result[0] = 0;}
				$min_book_qty = $result[0];
								 
				$Qry_QtyExists = " SELECT ifnull(QtyExists('".$rowsdt[2]."', '".$rowsdt[4]."', '".insertMySQLDate($txtDate)."', $rowsdt[0], '".$rowsdt[19]."', '', ''),0) As QtyExists ";				 
				$result = selectData($connection, $Qry_QtyExists);
				$min_exists_qty = $result[0];
				//echo $Qry_QtyExists;
				
				$Qry_Unit2QtyExists = " SELECT ifnull(Unit2QtyExists('".$rowsdt[2]."', '".$rowsdt[4]."', '".insertMySQLDate($txtDate)."', $rowsdt[0], '".$rowsdt[19]."', '', ''),0) As QtyExists ";
				$result = selectData($connection, $Qry_Unit2QtyExists);
				$min_exists_unit2qty = $result[0];
				//echo $Qry_Unit2QtyExists;
				
				$Qry_QtyAvailable = " Select QtyExistsWSorder_Temp('".$rowsdt[2]."', '".$rowsdt[4]."', '".insertMySQLDate($txtDate)."', $rowsdt[0], '".$rowsdt[19]."', '', '', 0) QtyExists From Dual ";
				$result = selectData($connection, $Qry_QtyAvailable);
				$min_available_qty = $result[0];
				//echo $Qry_QtyAvailable;
		
				$Qry_QtyInTemp = " Select ifNull(Sum(ifNull(AdjustmentDt_Quantity,0)),0) FROM Temp_AdjustmentDt ".
								 " WHERE Item_code = '".$rowsdt[2]."'  And  Warehouse_code = '".$rowsdt[4]."' And Adjustment_ID = $PAdjId And AdjustmentDt_ID != ifNull('".$rowsdt[0]."',0) ";
				$result = selectData($connection, $Qry_QtyInTemp);
				$QtyTemp_Adj = $result[0];
				
					
				$min_available_qty = $min_available_qty + $QtyTemp_Adj;
				$min_exists_qty = $min_exists_qty + $QtyTemp_Adj;
				$min_book_qty = $min_book_qty;
		
				$txtBookingQty[$i]    = $min_book_qty;
				$txtAvailableQty[$i]  = $min_available_qty;
				$txtExistingQty[$i]   = $min_exists_qty;
				$txtExistUnit2Qty[$i] = $min_exists_unit2qty;

				if($ShowSellingPrice == 1){
					
					$txtAdjDtSellingPrice[$i] =  ConvertCurrency($Base1, $txtCurrCode, insertMySQLDate($txtDate), $rowsdt[21], $connection);
				}
				
				
				//Checking For Difference Btw Qty and Count SerialNo
				if (($rowsdt[5] != $rowsdt[16] && $rowsdt[15] != 0 && $Module_SerialNo == 1) || ($rowsdt[5] == 0 && $rowsdt[15] != 0 && $Module_SerialNo == 1) || ($rowsdt[5] == 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."', '".$PAdjId."','".$rowsdt[0]."','".$i."','".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."');return false;\" title='Delete Record'  ></td>";
				
				// If ItemWithSerialNo True And ModuleSerialNo True	
				if ($rowsdt[15] == 1 && $Module_SerialNo == 1) {
					echo "	<td width='25px;' align='center' valign='center'><img src='img/button_addserial.png' onMouseOver=\"style.cursor='hand'\" onclick=\"AddSerialNo('".$rowsdt[0]."','".htmlentities($rowsdt[2])."','".$rowsdt[5]."','".$rowsdt[4]."')\" title='Add Serial Nos'  ></td>";
				}
				else if ($rowsdt[15] == 0 && $Module_SerialNo == 1) {
					echo "	<td width='25px;' align='center' valign='center'>&nbsp;</td>";
				}
				
				if ($Module_Pack == 1)
					echo "	<td width='125px;' align='left'><span class='".$TextColor."'>".$rowsdt[1]."</span></td>";
					
				echo "	<td width='165px;' align='left'>
							<input type='hidden' name='txtAdjDtId[$i]' id='adjdtid[$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='hidden' name='txtExistUnit2Qty[$i]' id='exitunit2qty[$i]' value='$txtExistUnit2Qty[$i]' >
							<label><span><img src='img/scroll-down-1.png' title='Show Details'  width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"ShowSlidingDiv('#slidingDiv$i');\" style='vertical-align:bottom;'/></span></label>
							<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');\"    onblur='checkduplicate(this.value,$i);' ".$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>
							<div id='slidingDiv$i' class='slidingDiv slidingDivHide'>
								<table align='center' border='0' cellpadding='0' cellspacing='0'>
									<tr height='25px;'><td width='100px;'><span class='style1'>Existing Qty</span></td><td width='100px;' align='right'><span class='style1'>".number_format($txtExistingQty[$i],2)."</span></td></tr>
									<tr height='25px;'><td width='100px;'><span class='style1'>Booking Qty</span></td><td width='100px;' align='right'><span class='style1'>".number_format($txtBookingQty[$i],2)."</span></td></tr>
									<tr height='25px;'><td width='100px;'><span class='style1'>Available Qty</span></td><td width='100px;' align='right'><span class='style1'>".number_format($txtAvailableQty[$i],2)."</span></td></tr>";
									
							if ($Module_DoubleUnit == 1 && $rowsdt[15] != $rowsdt[16] && $rowsdt[15] != '') {
								echo"<tr height='25px;'><td width='100px;'><span class='style1'>Existing Unit2Qty</span></td><td width='100px;' align='right'><span class='style1'>".$rowsdt[15] ."  ".number_format($txtExistUnit2Qty[$i],2)."</span></td></tr>";
							}
									
				echo"			</table>
								<div style='text-align:right;display:block;margin-top:5px;'><a href='javascript:void(0);' onclick=\"ShowSlidingDiv('#slidingDiv$i');\"><span style='font-weight:normal;'>Close</span></a></div>
							</div>
						</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>";
				if($module_locationadjustment == 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]'); \" 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='150px;' align='center'>
							<input type='text' name='adjustmentdt_heatno[$i]' id='adjustmentdt_heatno[$i]' value='".$adjustmentdt_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:120px; 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='adjustmentdt_heatno[$i]' id='adjustmentdt_heatno[$i]' value='".$adjustmentdt_heatno[$i]."'  maxlength='20' class='".$ClassE."'  />";
						
				echo "	<td width='65px;' align='left'><span class='".$TextColor."'>".$rowsdt[12]."</span></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtAdjDtQty[$i]' id='adjdtquantity[$i]' value='".$rowsdt[5]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; border-width:0px; width:70px; height:20px;' onKeyup=\"CalcAdjDtTotal(1,$DecimalBase,$i);\" onchange=\"SetModRecord('ModRec_G1','$i'); SetOutQty(1,$DecimalBase,$i); CalcQty2($Module_Unit1Method,1,$i);\" ".$KeyDown." ></td>";
					
				
				if ($Module_DoubleUnit == 1) { 
					echo"  <td width='65px;' align='left'><span class='".$TextColor."'>".$rowsdt[11]."</span>
							<input type='hidden' name='txtItemUnit2' id='itemunit2[$i]' value='".$rowsdt[11]."'></td>";	
					
					echo"  <td width='80px;' align='center'><input type='text' name='txtAdjDtQty2[$i]' id='unit2qty[$i]' value='".$rowsdt[10]."' maxlength='20' onchange=\"CalcQty2($Module_Unit1Method,2,$i); SetModRecord('ModRec_G1','$i');\" ";
					if($Adjustment_doubleunit == 1) echo " onkeyup=\"changeQty2(this.value,'$i');\" ";
					echo " class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' ".$KeyDown." ></td>";
				} else {
					echo"  <input type='hidden' name='txtAdjDtQty2[$i]' id='unit2qty[$i]' value='' >";
				}
				
				if ($Module_SerialNo == 1) {
					echo"  <td width='55px;' align='center'><span class='".$TextColor."'>".$rowsdt[16]."</span></td>";
				}
				
				if ($FI_ShowCostPrice == 1) 
					echo"	<td width='85px;' align='center'><input type='text' name='txtAdjDtPrice[$i]' id='costprice[$i]' value='".$rowsdt[6]."' maxlength='20' onKeyup='CalcAdjDtTotal(2,$DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' ".$KeyDown."  ></td>";
				else 
					echo" <input type='hidden' name='txtAdjDtPrice' id='costprice[$i]' value='' >";
				
				if ($ShowSellingPrice == 1) 
					echo"	<td width='85px;' align='center'><input type='text' name='txtAdjDtSellingPrice[$i]' id='sellingPrice[$i]' value='$txtAdjDtSellingPrice[$i]' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' readonly ".$KeyDown."  ></td>";
				else 
					echo"<input type='hidden' name='txtAdjDtSellingPrice[$i]' id='sellingPrice[$i]' value='' >";
				
				if ($FI_ShowCostPrice == 1) 			
					echo"   <td width='105px;' align='center'><input type='text' name='txtAdjDtTotal[$i]' id='adjdttotal[$i]' value='".$rowsdt[9]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." readonly ></td>";
				else 
					echo"<input type='hidden' name='txtAdjDtTotal' id='adjdttotal[$i]' value='' >";
				
				
				if ($Module_ProjectDt == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='".$rowsdt[13]."' class='".$ClassE."' style='width:120px;' maxlength='20' 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[14]."' class='".$ClassE."' style='width:130px;' maxlength='20' 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) {
					if ($AdjustType == 'I') {
						echo" 	<td width='105px;' align='center'><input type='text' name='txtAdjDtBatchNo[$i]' id='batchno[$i]' value='".htmlspecialchars($rowsdt[18], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='font-size:12px; width:100px; height:20px;' ".$KeyDown." ></td>";
					} else {
							
						echo" 	<td width='105px;' align='center'><input type='text' name='txtAdjDtBatchNo[$i]' id='batchno[$i]' value='".htmlspecialchars($rowsdt[18], 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>";
					}
					if($module_allowexpiry == 1 && $AdjustType == 'O')
						echo"	<td width='100px;' align='center'><input type='text' name='txtAdjDtExpireDate[$i]' id='expiredate[$i]' value='".$rowsdt[17]."' maxlength='10' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE." ' style='font-size:12px; width:70px; height:20px;' ".$KeyDown." >
							<label><span><img src='img/openlist.png' title='Select Expire Date' id='lstExpDate[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistExpDate(1,$i); ' style='vertical-align:bottom;'/></span></label></td>"; 	 
					
					else 
					echo"	<td width='85px;' align='center'><input type='text' name='txtAdjDtExpireDate[$i]' id='expiredate[$i]' value='".$rowsdt[17]."' 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='txtAdjDtExpireDate[$i]' id='expiredate[$i]' value=''>";
					echo" <input type='hidden' name='txtAdjDtBatchNo[$i]' id='batchno[$i]' value=''>";
				}
				if ($Module_IsInvoice == 1  && $AdjustType == 'O')
					echo"	<td width='120px;' align='center'><input type='text' name='txtAdjDtInvDebitAcc[$i]' id='InvDEBITaccount[$i]' value='".$rowsdt[22]."' maxlength='10' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='font-size:12px; width:100px; height:20px;' ".$KeyDown." >
					<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 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."', '".$PAdjId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$Module_SerialNo); 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."', '".$PAdjId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$Module_SerialNo); 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];
				$LastInvDebitAcc = $rowsdt[22];
			}
			
			
		}
		
		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;
			}
			
			if($txtAdjDtInvDebitAcc[$i] == '') $txtAdjDtInvDebitAcc[$i] = $LastInvDebitAcc;
			$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='165px;' align='left'>
						<input type='hidden' name='txtAdjDtId[$i]' id='adjdtid[$i]' value='$txtAdjDtId[$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]' >
						<label><span><img src='img/scroll-down-1.png' title='Show Details'  width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"GetSelectedItemQty('getitemqty','".$i."','".$txtDate."');ShowSlidingDiv('#slidingDiv$i');\" style='vertical-align:bottom;'/></span></label>
						<input type='text' name='txtItemCode[$i]' id='itemcode[$i]' value='$txtItemCode[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:110px; height:20px;'  onblur='checkduplicate(this.value,$i);'  onchange=\"SetModRecord('ModRec_G1','$i'); GetSelectedItem(this.id,'getitem','".$i."','".$txtDate."','".$txtCurrCode."','-2'); GetSelectedItemQty('getitemqty','".$i."','".$txtDate."');getAccount('$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>
						<div id='slidingDiv$i' class='slidingDiv slidingDivHide'>
							<table align='center' border='0' cellpadding='0' cellspacing='0'>
								<tr height='25px;'><td width='100px;'><span class='style1'>Existing Qty</span></td><td width='100px;' align='right'><input type='text' name='txtExistingQty[$i]' id='existingqty[$i]' value='$txtExistingQty[$i]' style='font-size:12px; font-weight:bold; text-align:right; border-width:0px; background-color:transparent; width:100px; height:20px;' readonly></td></tr>
								<tr height='25px;'><td width='100px;'><span class='style1'>Booking Qty</span></td><td width='100px;' align='right'><input type='text' name='txtBookingQty[$i]' id='bookingqty[$i]' value='$txtBookingQty[$i]' style='font-size:12px; font-weight:bold; text-align:right; border-width:0px; background-color:transparent; width:100px; height:20px;' readonly></td></tr>
								<tr height='25px;'><td width='100px;'><span class='style1'>Available Qty</span></td><td width='100px;' align='right'><input type='text' name='txtAvailableQty[$i]' id='availableqty[$i]' value='$txtAvailableQty[$i]' style='font-size:12px; font-weight:bold; text-align:right; border-width:0px; background-color:transparent; width:100px; height:20px;' readonly></td></tr>";
								
						if ($Module_DoubleUnit == 1) {
							echo"<tr height='25px;'><td width='100px;'><span class='style1'>Existing Unit2Qty</span></td><td width='100px;' align='right'><input type='text' name='txtExistUnit2Qty[$i]' id='exitunit2qty[$i]' value='$txtExistUnit2Qty[$i]' style='font-size:12px; font-weight:bold; text-align:right; border-width:0px; background-color:transparent; width:100px; height:20px;' readonly></td></tr>";
						}	
						
			echo"			</table>
							<div style='text-align:right;display:block;margin-top:5px;'><a href='javascript:void(0);' onclick=\"ShowSlidingDiv('#slidingDiv$i');\"><span style='font-weight:normal;'>Close</span></a></div>
						</div>
					</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>";
			if($module_locationadjustment == 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='150px;' align='center'>
							<input type='text' name='adjustmentdt_heatno[$i]' id='adjustmentdt_heatno[$i]' value='".$adjustmentdt_heatno[$i]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:120px; 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='adjustmentdt_heatno[$i]' id='adjustmentdt_heatno[$i]' value='".$adjustmentdt_heatno[$i]."'  maxlength='20' class='".$ClassE."'   />";
						
			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='txtAdjDtQty[$i]' id='adjdtquantity[$i]' value='$txtAdjDtQty[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:70px; height:20px;' onKeyup=\"CalcAdjDtTotal(1,$DecimalBase,$i);\" onchange=\"SetModRecord('ModRec_G1','$i'); SetOutQty(1,$DecimalBase,$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='txtAdjDtQty2[$i]' id='unit2qty[$i]' value='$txtAdjDtQty2[$i]' maxlength='20' onchange=\"CalcQty2($Module_Unit1Method,2,$i); SetModRecord('ModRec_G1','$i');\" ";
				if($Adjustment_doubleunit == 1) echo "onkeyup=\"changeQty2(this.value,'$i');\"";
				echo " class='".$ClassI."'  style='font-size:12px; width:75px; height:20px;' ".$KeyDown." ></td>";
			} else {
				echo "<input type='hidden' name='txtAdjDtQty2[$i]' id='unit2qty[$i]' value='' >";
			}
			
			if ($Module_SerialNo == 1) {
				echo"  <td width='55px;' align='center'><span class='".$TextColor."'>&nbsp;</span></td>";
			}
			
				
			if ($FI_ShowCostPrice == 1) 
				echo"	<td width='85px;' align='center'><input type='text' name='txtAdjDtPrice[$i]' id='costprice[$i]' value='$txtAdjDtPrice[$i]' maxlength='20' onKeyup='CalcAdjDtTotal(2,$DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' ".$KeyDown."  ></td>";
			else 
				echo" <input type='hidden' name='txtAdjDtPrice' id='costprice[$i]' value='' >";
			
			if ($ShowSellingPrice == 1) 
				echo"	<td width='85px;' align='center'><input type='text' name='txtAdjDtSellingPrice[$i]' id='sellingPrice[$i]' value='$txtAdjDtSellingPrice[$i]' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' readonly ".$KeyDown."  ></td>";
			else 
				echo"<input type='hidden' name='txtAdjDtSellingPrice[$i]' id='sellingPrice[$i]' value='' >";
			
			if ($FI_ShowCostPrice == 1) 	
				echo"   <td width='105px;' align='center'><input type='text' name='txtAdjDtTotal[$i]' id='adjdttotal[$i]' value='$txtAdjDtTotal[$i]' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:100px; height:20px;' ".$KeyDown." readonly ></td>";
			else 
				echo"<input type='hidden' name='txtAdjDtTotal' id='adjdttotal[$i]' value='' >";
			
				
			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='20' 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='20' 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) {
				if ($AdjustType == 'I') {
					echo" 	<td width='105px;' align='center'><input type='text' name='txtAdjDtBatchNo[$i]' id='batchno[$i]' value='".htmlspecialchars($txtAdjDtBatchNo[$i], ENT_QUOTES)."'  maxlength='40' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' style='font-size:12px; width:100px; height:20px;' ".$KeyDown." ></td>";
				} else {
					echo" 	<td width='105px;' align='center'><input type='text' name='txtAdjDtBatchNo[$i]' id='batchno[$i]' value='".htmlspecialchars($txtAdjDtBatchNo[$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>";
				}
				if($module_allowexpiry == 1 && $AdjustType == 'O')
				echo"	<td width='100px;' align='center'><input type='text' name='txtAdjDtExpireDate[$i]' id='expiredate[$i]' value='$txtAdjDtExpireDate[$i]' maxlength='10' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI." ' style='font-size:12px; width:70px; height:20px;' ".$KeyDown." >
			<label><span><img src='img/openlist.png' title='Select Expire Date' id='lstExpDate[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistExpDate(1,$i); ' style='vertical-align:bottom;'/></span></label></td>"; 	 	
				else
				echo"	<td width='85px;' align='center'><input type='text' name='txtAdjDtExpireDate[$i]' id='expiredate[$i]' value='$txtAdjDtExpireDate[$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='txtAdjDtExpireDate[$i]' id='expiredate[$i]' value=''>";
				echo" <input type='hidden' name='txtAdjDtBatchNo[$i]' id='batchno[$i]' value=''>";
			}
			if ($Module_IsInvoice == 1  && $AdjustType == 'O')
				echo"	<td width='120px;' align='center'><input type='text' name='txtAdjDtInvDebitAcc[$i]' id='InvDEBITaccount[$i]' value='".$txtAdjDtInvDebitAcc[$i]."' maxlength='10' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."' style='font-size:12px; width:100px; height:20px;' ".$KeyDown." >
				<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 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."', '".$PAdjId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$Module_SerialNo); 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."', '".$PAdjId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$Module_ExpireDate,$Module_SerialNo); 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,$PAdjId,'datagrid',$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	
	echo"</div>";
	
	
}

function ShowAdjustmentTotals($connection,$PAdjId,$arrayparams,$arrayaccess){

	$DecimalBase  = $arrayparams['DecimalBase'];
	$DecimalBase1 = $arrayparams['DecimalBase1'];
	$DecimalBase2 = $arrayparams['DecimalBase2'];
	
	$Base1 = $arrayparams['Base1'];
	$Base2 = $arrayparams['Base2'];
	$txtCurr = $arrayparams['txtCurrCode']; 
	
	$FI_ShowCostPrice = $arrayparams['FI_ShowCostPrice']; 
	
	if ($PAdjId != "") {
		$sub_query = " Select Round(Adjustment_Amount, ".$DecimalBase.") As AdjustmentAmount, ".
					 " Round(Adjustment_AmountBase1, ".$DecimalBase1.") As AdjustmentAmountBase1, ".
					 " Round(Adjustment_AmountBase2, ".$DecimalBase2.") As AdjustmentAmountBase2 ".
					 " From Temp_Adjustment As Adjustment ".
					 " Where Adjustment_ID = ".$PAdjId;
			 
		//echo $sub_query;
		$sub_result = selectData($connection, $sub_query);
		
		$txtAdjAmount      		= $sub_result[0];
		$txtAdjAmountBase1		= $sub_result[1];
		$txtAdjAmountBase2   	= $sub_result[2];
		
	} 
	
	
	if ( $FI_ShowCostPrice==1) {
	echo"	<table border='0' style='table-layout:fixed;width:100px' cellspacing=0>
		<tr>
		<td id='total-top' style='width:240px;height:12px;'></td>
		</tr>
		<tr><td id='total-content' style='width:240px;height:12px;'>
		<table valign='top' border='0' cellspacing=0 cellpadding=0 style='width:240px;'>
		
			<col width=90>
			<col width=140>
				<tr height='25px'>
					<td valign='center' align='right' ><span class='style10'>Amount:</span>&nbsp;</td>
					<td align='left' ><input type='text' id='adjamount'  name='txtAdjAmount' value='$txtAdjAmount' maxlength='20' style='text-align:right; width:120px; height:20px;background:#C6D4E5;";
					
					if($txtAdjAmount<0) echo " color:#FF0000;";
					
				echo" ' readonly></td>
				</tr>
				<tr height='25px'>
					<td valign='center' align='right' ><span class='style10'>Amount $Base1:</span>&nbsp;</td>
					<td align='left' ><input type='text' id='adjamountb1'  name='txtAdjAmountBase1' value='$txtAdjAmountBase1' maxlength='20' style='text-align:right; width:120px; height:20px;background:#C6D4E5;";
					
				if($txtAdjAmountBase1<0) echo " color:#FF0000;";	
					
					echo" ' readonly></td>
				</tr>
				<tr height='25px'>
					<td valign='center' align='right' ><span class='style10'>Amount $Base2:</span>&nbsp;</td>
					<td align='left' ><input type='text' id='adjamountb2'  name='txtAdjAmountBase2' value='$txtAdjAmountBase2' maxlength='20' style='text-align:right; width:120px; height:20px;background:#C6D4E5;";
					
				if($txtAdjAmountBase2<0) echo " color:#FF0000;";		
					
					echo" ' readonly></td>
				</tr>";
		  
	 echo" </table></td>
				</tr><tr>
					<td id='total-bottom' style='width:240px;height:12px;'></td>
				</tr></table></td></tr>";
			
	} else {
		echo"<input type='hidden' id='adjamount'  name='txtAdjAmount' value='$txtAdjAmount' maxlength='20' />";
		echo"<input type='hidden' id='adjamountb1'  name='txtAdjAmountBase1' value='$txtAdjAmountBase1' maxlength='20' />";
		echo"<input type='hidden' id='adjamountb2'  name='txtAdjAmountBase2' value='$txtAdjAmountBase2' maxlength='20' />";
	}

}
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>";

}

?>