<?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 == 'SO') {
		ShowSorderDtGrid($connection,$form,$transid,$_SESSION['gso_parameters'],$_SESSION['gso_arrayaccess'],$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	}	
	else if ($form == 'SO-TOT') {
		ShowSorderTotals($connection,$transid,$_SESSION['gso_parameters'],$_SESSION['gso_arrayaccess']);
	}
	
}

function ShowSorderDtGrid($connection,$form,$PSorId,$arrayparams,$arrayaccess,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction){
	
	

	$FI_SorderCanceledQty 				= $arrayparams['FI_SorderCanceledQty'];
	$FI_SalesCheckSalesman 				= $arrayparams['FI_SalesCheckSalesman'];
	$Login_AllowPrice 					= $arrayparams['Login_AllowPrice'];
	$Login_NegativeQty 					= $arrayparams['Login_NegativeQty'];
	$Login_ModifySellingPrice 			= $arrayparams['Login_ModifySellingPrice'];
	$Allow_MinimumPrice 				= $arrayparams['Allow_MinimumPrice'];
	$Login_ModifyDiscount 				= $arrayparams['Login_ModifyDiscount'];
	$Module_NegativeSorder 				= $arrayparams['Module_NegativeSorder'];
	$Module_Unit1Method 				= $arrayparams['Module_Unit1Method'];
	$Module_SorderCheckQtyOnPost 		= $arrayparams['Module_SorderCheckQtyOnPost'];
	$Module_Pack 						= $arrayparams['Module_Pack'];
	$Module_DoubleUnit 					= $arrayparams['Module_DoubleUnit'];
	$Module_ProjectDt 					= $arrayparams['Module_ProjectDt'];
	$Module_CostCenterDt 				= $arrayparams['Module_CostCenterDt'];
	$Module_RestrictProjCost 			= $arrayparams['Module_RestrictProjCost'];
	$Module_RestrictCost 				= $arrayparams['Module_RestrictCost'];
	$ShowCostCentLayout 				= $arrayparams['ShowCostCentLayout'];
	$SetupDftWareHouse 					= $arrayparams['SetupDftWareHouse'];
	$defaultwarehouse					= $arrayparams['defaultwarehouse'];
	$Module_ShowWarehouseSalesorder  	= $arrayparams['Module_ShowWarehouseSalesorder'];
	$sorder_export  					= $arrayparams['sorder_export'];
	$txtSorType 						= $arrayparams['txtSorType'];
	$SubItem_Production 				= $arrayparams['SubItem_Production'];
	$FI_DeliverySalesPrice  			= $arrayparams['FI_DeliverySalesPrice'];
	$Module_Heatno  					= $arrayparams['Module_Heatno'];
	$sorderproduction  					= $arrayparams['sorderproduction'];
	
	if($sorder_export==''){
	$query = " Select Sorder_Export
					  From Temp_Sorder
					 Where Temp_Sorder.Sorder_ID = ".$PSorId;
					 
		if ($Login_ModifyDiscount == 0)	$ModeDiscount = ' readonly ';			 
			//echo $query;
					
			$result=mysql_query($query,$connection);
		 	$rows=mysql_fetch_array($result);
			$sorder_export  = $rows[0];
	}
	$SalesTTC = $arrayparams['SalesTTC'];
	$DecimalBase = $arrayparams['DecimalBase'];
	
	$txtDate         	= $arrayparams['txtDate'];
	$txtClientCode   	= $arrayparams['txtClientCode'];
	$txtClientDetail 	= $arrayparams['txtClientDetail'];
	$txtCurrCode     	= $arrayparams['txtCurrCode'];
	$txtClientPromotion = $arrayparams['txtClientPromotion'];
	
	if (empty($txtClientPromotion)) $txtClientPromotion = 0;
	
	if ($txtClientCode == '' && $PSorId != '') {
		$sub_query = "SELECT Client_Code FROM Temp_Sorder WHERE Sorder_ID = '".$PSorId."'";
		//echo "<br><br>".$sub_query;
		$sub_result = selectData($connection, $sub_query);
		$txtClientCode   = $sub_result[0];
	}
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_DataGrid_SalesOrder.php';
	
	$i = 0;
	
	$PriceLabel = 'Price';	
	if ($SalesTTC == 1)  $PriceLabel = 'Price TTC';	
	
	$ModeModifySellPrice = '';
	if ($Login_ModifySellingPrice != 1) $ModeModifySellPrice = 'readonly';
	
	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, 'sorderdt_heatno');
	if ($Module_DoubleUnit == 1) array_push($columnsarray, 'unit2qty');
	if($sorder_export==1){ 
		array_push($columnsarray, 'sorderdt_quantitybox');
		array_push($columnsarray, 'sorderdt_itemunit');
		array_push($columnsarray, 'sorderdt_itempackage');
				}
	if ($sorderproduction == 	1){
		array_push($columnsarray, "itemprodqty");
		array_push($columnsarray, "itemsentprod");
	}	
	array_push($columnsarray, "itemorderedqty");
	array_push($columnsarray, "cancelledqty");
	
	if($FI_DeliverySalesPrice == 1){
		array_push($columnsarray, 'price');
		array_push($columnsarray, 'sordtdiscount');
		array_push($columnsarray, 'sordttotal');
	}
	if ($Module_ProjectDt == 1) array_push($columnsarray, 'projectcodedt');
	if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) array_push($columnsarray, 'costcentcodedt');
	if($SubItem_Production != 1 ) array_push($columnsarray, 'remarkdt');
	array_push($columnsarray, 'chkpromo');
	
	$columnsarrayall = array("itemcode", "itemdescription", "warehousecode","sorderdt_heatno", "sorderdt_quantitybox","sorderdt_itemunit","sorderdt_itempackage", "itemorderedqty", "sordtquantity", "cancelledqty", "unit2qty", "price", "sordtdiscount", "sordttotal", "projectcodedt", "costcentcodedt", "remarkdt", "sordtid", "existingqty", "bookingqty", "availableqty", "lastprice", "itemunit1", "itemunit2", "itemvat", "itemminprice", "itemnonstock", "itemzeroprice", "itemunitcoef");
	$orderbyarray = array("SorderDt.Item_CodePacked", "Items.Item_Code", "Items.Item_Description", "SorderDt.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);
	
	
	
	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='width:1400px;'>";
	
		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($SubItem_Production == 1 )
			echo"  <th width='25px;' align='center' ></th> ";
		if ($Module_Pack == 1)
			echo"  <th width='150px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PSorId."', 'datagrid', 1, '".$dftorderby."', 'COR','SorderDt.Item_CodePacked','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code Packed".$orderimg1."</span></th>";
			
		echo"  <th width='170px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PSorId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code".$orderimg2."</span></th>";
		echo"  <th width='200px;' align='left' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PSorId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_Description','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Description".$orderimg3."</span></th>";
		
		if($Module_ShowWarehouseSalesorder==1)
		echo"  <th width='75px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PSorId."', 'datagrid', 1, '".$dftorderby."', 'COR','SorderDt.Warehouse_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>W.H".$orderimg4."</span></th>";
		
		if($Module_Heatno == 1)
			echo"  <th width='150px;' align='center'><span>Heat No.</span></th>";
		
		if (($Module_DoubleUnit == 1) )  	
				echo"  <th width='60px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PSorId."', 'datagrid', 1, '".$dftorderby."', 'COR','SorderDt.Item_UnitSalesDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Unit1".$orderimg5."</span></th>";
		//else
		//       echo"  <th width='0px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PSorId."', 'datagrid', 1, '".$dftorderby."', 'COR','SorderDt.Item_UnitSalesDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>".$orderimg5."</span></th>";		
		if($sorder_export==1){
		echo"  <th width='60px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PSorId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_UnitSalesDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Pack/Box".$orderimg5."</span></th>";
		echo"  <th width='60px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PSorId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_UnitSalesDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Unit".$orderimg5."</span></th>";
		echo"  <th width='60px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PSorId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_UnitSalesDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Qty Box".$orderimg5."</span></th>";
		
		}
		if ($sorderproduction == 	1)
		echo"  <th width='70px;' align='center'><span>Production Qty</span></th>
				<th width='80px;' align='center'><span>Sent Production</span></th>";	
		echo"  <th width='70px;' align='center'><span>Ordered Qty</span></th> ";	
		echo"  <th width='70px;' align='center'><span>Cancelled Qty</span></th>";	
		echo"  <th width='70px;' align='center'><span>Qty</span></th>";
			
		  
		if ($Module_DoubleUnit == 1) {
			echo"  <th width='60px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PSorId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_UnitPurchaseDesc','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Unit2".$orderimg6."</span></th>";
			echo"  <th width='75px;' align='center'><span>Unit2 Qty</span></th>";
		}
		
		if($FI_DeliverySalesPrice == 1){	
			echo"  <th width='100px;' align='center'><span>".$PriceLabel."</span></th>";
			echo"  <th width='80px;' align='center'><span>Last Sell. Price</span></th> ";
			echo"  <th width='65px;' align='center'><span>Disc(%)</span></th>";
			echo"  <th width='100px;' align='center'><span>Total</span></th>";
		}
		
		if ($Module_ProjectDt == 1) {
			echo"  <th width='170px;' align='center'><span>Project</span></th>";	
		}
		if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) {
			echo"  <th width='170px;' align='center'><span>Costcenter</span></th>";	
		}
	
		if($SubItem_Production != 1 ) echo"  <th width='250px;' align='center'><span>Remark</span></th>";	
		
		echo"  <th width='25px;' align='center'><span>&nbsp;</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='width:1400px;'>";
		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 ($PSorId != '' ) {
		      
			$TotalQty = 0;
			$i_nonstock  = 0;
			$i_zeroprice = 0;
			$i_minprice  = 0;
			$i_unitcoef  = 1;
			
			$query = " Select SorderDt.SorderDt_id, SorderDt.Item_CodePacked, SorderDt.Item_code, Item_Description, SorderDt.Warehouse_Code, ".
					 " SorderDt_Remark, SorderDt_Quantity, Round(SorderDt_Price, ".$DecimalBase."), SorderDt_PriceBase1, SroderDt_PriceBase2, ".
					 " Round(SorderDt_Discount, ".$DecimalBase."),  ".
					 " Round(((SorderDt_Quantity*SorderDt_Price)-((SorderDt_Quantity*SorderDt_Price*ifNull(SorderDt_Discount,0))/100)), ".$DecimalBase.") As Total, ".
					 " Round(SorderDt_PriceTTC, ".$DecimalBase."), ".
					 " Round(((SorderDt_Quantity*SorderDt_PriceTTC)-((SorderDt_Quantity*SorderDt_PriceTTC*ifNull(SorderDt_Discount,0))/100)), ".$DecimalBase.") As TotalTTC, ".
					 " SorderDt.Item_Unit2Qty, Item_UnitPurchaseDesc, Item_UnitSalesDesc, SorderDt.Project_code, SorderDt.CostCent_Code, ifNull(SorderDt_oqty,0), ifNull(SorderDt_cqty,0) ".
					 " ,SorderDt.sorderdt_quantitybox sorderdt_quantitybox,SorderDt.sorderdt_itemunit sorderdt_itemunit,SorderDt.sorderdt_itempackage as sorderdt_itempackage, ".
					 " sorderdt_clientdiscount,sorderdt_itemdiscount, sorderdt_desc1, sorderdt_heatno , ifNull(sorderdt_promotion,0), sorderdt_ProdQty, ifnull(sorderdt_sentProduction,0) ".
					 " From Temp_SorderDt As SorderDt Left Join Items on SorderDt.Item_code = Items.Item_code ".
					 " Where SorderDt.Sorder_ID = ".$PSorId.
					 " 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';

				$sorderdt_clientdiscount[$i]	= $rowsdt[24];
				$sorderdt_itemdiscount[$i] = $rowsdt[25];
				
				
				$sub_query  = " Select QtyExistsWSorder('".$rowsdt[2]."', '".$rowsdt[4]."', '".insertMySQLDate($txtDate)."', 0, 'SO', '', '') QtyExists From Dual ";
				//$sub_query  = " Select 0 From Dual "; //shukri
				//echo $sub_query;
				$sub_result = selectData($connection, $sub_query);
				$vItemQtyExists = 0;
				$vItemQtyExists = $sub_result[0];		
						
				$TextColor = 'style7';
				if ($vItemQtyExists < 0) {
					$Color="style='background-color:#FF0000;'";
					$TextColor = 'style8';
				}	
				
				$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) ".
							 " 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];
				
				$sorderdt_quantitybox  = $rowsdt[21];
				$sorderdt_itemunit  = $rowsdt[22];
				$sorderdt_itempackage  = $rowsdt[23];
				
				$sub_query = "SELECT ifNull(Client_SellingPrice,1) FROM Clients WHERE Ledger_Number = '".$txtClientCode."'";
				//echo "<br><br>".$sub_query;
				$sub_result = selectData($connection, $sub_query);
				$c_sp    = $sub_result[0];
				
				$txtItemMinPrice[$i]  = $i_minprice;
				$txtItemZeroPrice[$i] = $i_zeroprice;
				$txtItemNonStock[$i]  = $i_nonstock;
				$txtItemUnitCoef[$i]  = $i_unitcoef;
				
				$Qry_QtyBookTemp = "SELECT ifnull(QtyBooking_Temp('".$rowsdt[2]."', '".$rowsdt[4]."', '".insertMySQLDate($txtDate)."', $rowsdt[0]),0) ";
				$Qry_QtyBookTemp = "SELECT 0 from dual";  //shukri
				$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], 'SO', '', ''),0) As QtyExists ";				 
				//$Qry_QtyExists = " SELECT 0 As QtyExists ";	//shukri
				$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], 'SO', '', ''),0) As QtyExists ";
				$Qry_Unit2QtyExists = " SELECT 0 As QtyExists "; //shurki
				$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], 'SO', '', '', 0) QtyExists From Dual ";
				//$Qry_QtyAvailable = " Select 0 as QtyExists From Dual "; //shukri
				$result = selectData($connection, $Qry_QtyAvailable);
				$min_available_qty = $result[0];
				//echo $Qry_QtyAvailable;

				$Qry_QtyInTemp = " Select ifNull(Sum(ifNull(SorderDt_Quantity,0)),0) FROM Temp_Sorderdt ".
								 " WHERE Item_code = '".$rowsdt[2]."'  And  Warehouse_code = '".$rowsdt[4]."' And Sorder_ID = $PSorId And SorderDt_ID != ifNull('".$rowsdt[0]."',0) ";
				$result = selectData($connection, $Qry_QtyInTemp);
				$QtyTemp_SO = $result[0];
				
				$Qry_QtyTransferInTemp = " Select ifNull(Sum(ifNull(TransferDt_Quantity,0)),0) FROM Temp_TransferDt ".
										 " WHERE Item_code = '".$rowsdt[2]."'  And  TransferDt_WarehouseFrom = '".$rowsdt[4]."' ";
				$result = selectData($connection, $Qry_QtyTransferInTemp);						 
				$QtyTemp_TR = $result[0];
					
				$min_available_qty = $min_available_qty - $QtyTemp_SO - $QtyTemp_TR;
				$min_exists_qty = $min_exists_qty;
				$min_book_qty = $min_book_qty + $QtyTemp_SO + $QtyTemp_TR;
		
				$txtBookingQty[$i]    = $min_book_qty;
				$txtAvailableQty[$i]  = $min_available_qty;
				$txtExistingQty[$i]   = $min_exists_qty;
				$txtExistUnit2Qty[$i] = $min_exists_unit2qty;
				
			 
				$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/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteRecordGrid('".$filepath."','".$form."', '".$PSorId."','".$rowsdt[0]."','".$i."','".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."');return false;\" title='Delete Record'  ></td>";
				if($SubItem_Production == 1 )
				echo"  <td width='25px;' align='center' valign='center' ><img src='img/show.png' onmouseover=\"style.cursor='hand'\" onclick=\"AddParamter('$i', '$rowsdt[0]');\" 
				title='Add Parameters' height='15px' width='15px' style='cursor: pointer;'></td> ";
				if ($Module_Pack == 1)
					echo "	<td width='150px;' align='left'><span class='".$TextColor."'>".$rowsdt[1]."</span></td>";
					
				echo "	<td width='170px;' align='left'>
							<input type='hidden' name='txtItemVat[$i]' id='itemvat[$i]' value='$txtItemVat[$i]' >
							<input type='hidden' name='txtItemMinPrice[$i]' id='itemminprice[$i]' value='$txtItemMinPrice[$i]' >
							<input type='hidden' name='txtItemNonStock[$i]' id='itemnonstock[$i]' value='$txtItemNonStock[$i]' >
							<input type='hidden' name='txtItemZeroPrice[$i]' id='itemzeroprice[$i]' value='$txtItemZeroPrice[$i]' >
							<input type='hidden' name='txtItemUnitCoef[$i]' id='itemunitcoef[$i]' value='$txtItemUnitCoef[$i]' >
							<input type='hidden' name='txtSorDtId[$i]' id='sordtid[$i]' value='".$rowsdt[0]."' >
							<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]' >
							<input type='hidden' name='sorderdt_clientdiscount[$i]' id='sorderdt_clientdiscount[$i]' value='$sorderdt_clientdiscount[$i]' style='width:60'>
							<input type='hidden' name='sorderdt_itemdiscount[$i]' id='sorderdt_itemdiscount[$i]' value='$sorderdt_itemdiscount[$i]' style='width:60' >
							<label><span><img src='img/scroll-down-1.png' title='Show Details'  width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"ShowSlidingDiv($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;'   onblur='checkduplicate($i,this.value)'  onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','items','item_code',this.value,'lstItemCode[$i]'); GetSelectedItem(this.id,'getitem','".$i."','".$txtDate."','".$txtCurrCode."','".$txtClientCode."'); \" 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'><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($i);\"><span style='font-weight:normal;'>Close</span></a></div>
							</div>
						</td>";
										
				echo"  	<td width='200px;' 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($Module_ShowWarehouseSalesorder==1)		
				echo"  	<td width='75px;' align='center'>
							<input type='text' name='txtWarehouseCode[$i]' id='warehousecode[$i]' value='".$rowsdt[4]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:35px; 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>";
				else echo" <input type='hidden' name='txtWarehouseCode[$i]' id='warehousecode[$i]' value='".$rowsdt[4]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\" ".$KeyDown."   />";		
				
				if($Module_Heatno == 1)
				echo"  	<td width='150px;' align='center'>
							<input type='text' name='sorderdt_heatno[$i]' id='sorderdt_heatno[$i]' value='".$rowsdt[27]."'  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='sorderdt_heatno[$i]' id='sorderdt_heatno[$i]' value=''  />";
				
				
				if (($Module_DoubleUnit == 1))	
					echo "	<td width='60px;' align='left'><span class='".$TextColor."'>".$rowsdt[16]."</span></td>";
				//else
				//	echo "	<td width='0px;' align='left'><span class='".$TextColor."'>".$rowsdt[16]."</span></td>";
				if($sorder_export==1){
							echo"  <td width='60px;' align='center'><input type='text' name='sorderdt_quantitybox' id='sorderdt_quantitybox[$i]' value='$sorderdt_quantitybox' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' ".$KeyDown."  ></td>";
							echo"  <td width='60px;' align='center'><input type='text' name='sorderdt_itemunit' id='sorderdt_itemunit[$i]' value='$sorderdt_itemunit' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' ".$KeyDown."  ></td>";
							echo"  <td width='60px;' align='center'><input type='text' name='sorderdt_itempackage' id='sorderdt_itempackage[$i]' value='$sorderdt_itempackage' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' ".$KeyDown."  ></td>";
				} else {
							echo"  <input type='hidden' name='sorderdt_quantitybox' id='sorderdt_quantitybox[$i]' value='$sorderdt_quantitybox' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' ".$KeyDown."  >";
							echo"  <input type='hidden' name='sorderdt_itemunit' id='sorderdt_itemunit[$i]' value='$sorderdt_itemunit' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' ".$KeyDown."  >";
							echo"  <input type='hidden' name='sorderdt_itempackage' id='sorderdt_itempackage[$i]' value='$sorderdt_itempackage' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' ".$KeyDown."  >";
							
				}
				
				if ($sorderproduction == 	1){	
					echo"	<td width='70px;' align='center'><input type='text' name='txtProdQty[$i]' id='itemprodqty[$i]' value='".$rowsdt[29]."' maxlength='20'   class='".$ClassI."' style='font-size:12px; width:60px; height:20px;' ".$KeyDown."></td>";
					echo"	<td width='80px;' align='center'><select name='txtSentProd[$i]' id='itemsentprod[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:75px; height:20px;' ".$KeyDown.">
								<option value='0' ".($rowsdt[30]=='0'?'selected':'').">Not Sent</option>
								<option value='1' ".($rowsdt[30]=='1'?'selected':'').">Sent</option>
							</select></td>";
				} else echo "<input type='hidden' name='txtProdQty[$i]' id='itemprodqty[$i]' value=''><input type='hidden' name='txtSentProd[$i]' id='itemsentprod[$i]' value=''>";
			
			
				echo"	<td width='70px;' align='center'><input type='text' name='txtSorDtOQty[$i]' id='itemorderedqty[$i]' value='".$rowsdt[19]."' maxlength='20' onKeyup='CalcSorDtQty($i); CalcSorDtTotal($DecimalBase,$i);' onchange=\"CalcQty2($Module_Unit1Method,1,$i); SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='font-size:12px; width:60px; height:20px;' ".$KeyDown." $ModeModifyQty></td>";
				echo"   <td width='70px;' align='center'><input type='text' name='txtSorDtCQty[$i]' id='cancelledqty[$i]' value='".$rowsdt[20]."' maxlength='20' onKeyup='CalcSorDtQty($i); CalcSorDtTotal($DecimalBase,$i);'  onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='font-size:12px; width:60px; height:20px;' ".$KeyDown."  ></td>";
				echo"	<td width='70px;' align='center'><input type='text' name='txtSorDtQty[$i]' id='sordtquantity[$i]' value='".$rowsdt[6]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; border-width:0px; width:60px; height:20px;'  readonly></td>";
					
				
				if ($Module_DoubleUnit == 1) { 
					echo"  <td width='60px;' align='left'><span class='".$TextColor."'>".$rowsdt[15]."</span></td>";	
					echo"  <td width='75px;' align='center'><input type='text' name='txtSorDtQty2[$i]' id='unit2qty[$i]' value='".$rowsdt[14]."' maxlength='20' onchange=\"CalcQty2($Module_Unit1Method,2,$i); SetModRecord('ModRec_G1','$i');\" onkeyup=\"changeQty2(this.value,'$i');\" class='".$ClassE."' style='font-size:12px; width:60px; height:20px;' ".$KeyDown." ></td>";
				} else {
					echo"  <input type='hidden' name='txtSorDtQty2[$i]' id='unit2qty[$i]' value='' >";
				}
				
			if($FI_DeliverySalesPrice == 1){	
				if ($SalesTTC == 1) 
					echo"	<td width='100px;' align='center'><input type='text' name='txtSorDtPrice[$i]' id='price[$i]' value='".$rowsdt[12]."' maxlength='20' onKeyup='CalcSorDtTotal($DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' ".$KeyDown." $ModeModifySellPrice ></td>";
				else
					echo"	<td width='100px;' align='center'><input type='text' name='txtSorDtPrice[$i]' id='price[$i]' value='".$rowsdt[7]."' maxlength='20' onKeyup='CalcSorDtTotal($DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' ".$KeyDown." $ModeModifySellPrice ></td>";
					
				echo "	<td width='80px;' align='right'><span class='".$TextColor."'>&nbsp;</span></td>";
				echo"	<td width='65px;' align='center'><input type='text' name='txtSorDtDiscount[$i]'   onblur='UpdateDiscount($i,this.value)'  id='sordtdiscount[$i]' value='".$rowsdt[10]."' maxlength='20' onKeyup='CalcSorDtTotal($DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassE."' style='text-align:right; font-size:12px; width:60px; height:20px;' ".$KeyDown." $ModeDiscount ></td>";
				
						
				if ($SalesTTC == 1) 
					echo"   <td width='100px;' align='center'><input type='text' name='txtSorDtTotal[$i]' id='sordttotal[$i]' value='".$rowsdt[13]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' ".$KeyDown." ></td>";
				else
					echo"   <td width='100px;' align='center'><input type='text' name='txtSorDtTotal[$i]' id='sordttotal[$i]' value='".$rowsdt[11]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' ".$KeyDown." ></td>";
			} else{
				echo "<input type='hidden' name='txtSorDtPrice[$i]' id='price[$i]' value=''>";
				echo "<input type='hidden' name='txtSorDtDiscount[$i]' id='sordtdiscount[$i]' value=''>";
				echo "<input type='hidden' name='txtSorDtTotal[$i]' id='sordttotal[$i]' value=''>";
			}
				if ($Module_ProjectDt == 1) {
					echo"<td width='170px;' align='center'><input type='text' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='".$rowsdt[17]."' 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='170px;' align='center'><input type='text' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='".$rowsdt[18]."' 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='' >";
					echo "<input type='hidden' name='txtSorDtDiscount[$i]' id='sordtdiscount[$i]' value='' >";
					echo "<input type='hidden' name='txtSorDtTotal[$i]' id='sordttotal[$i]' value=''>";
				}
				
			if($SubItem_Production != 1 )
				echo"	<td width='250px;'><input type='text' name='txtSorDtRemark[$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>";	
			else 	echo"	<input type='hidden' name='txtSorDtRemark[$i]' id='remarkdt[$i]' value='".htmlspecialchars($rowsdt[5], ENT_QUOTES)."'  maxlength='200'  >";	
				
				echo"	<td width='25px;' align='center'><input type='checkbox' name='chkSorDtPromo[$i]' id='chkpromo[$i]' value='1'  onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown;  if ($rowsdt[28] == 1) echo " checked ";    echo" ></td>";			
				echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit[$i]'    onclick=\"SubmitRecordGrid('".$i."','".$filepath."', '".$form."', '".$PSorId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_NegativeSorder,$Login_NegativeQty,$Login_AllowPrice,$Module_SorderCheckQtyOnPost,$Allow_MinimumPrice,$Module_RestrictProjCost,$Module_RestrictCost,$txtClientDetail,$FI_SalesCheckSalesman,$txtClientPromotion,$Module_ShowWarehouseSalesorder); 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($SubItem_Production == 1 )
				echo"  <td width='25px;' align='center' valign='center' ></td> ";  
			if ($Module_Pack == 1)
				echo"  <td width='150px;' align='center'><span>&nbsp;</span></td>";
				
			echo "	<td width='170px;' align='left'>
						<input type='hidden' name='txtItemVat[$i]' id='itemvat[$i]' value='$txtItemVat[$i]' >
						<input type='hidden' name='txtItemMinPrice[$i]' id='itemminprice[$i]' value='$txtItemMinPrice[$i]' >
						<input type='hidden' name='txtItemNonStock[$i]' id='itemnonstock[$i]' value='$txtItemNonStock[$i]' >
						<input type='hidden' name='txtItemZeroPrice[$i]' id='itemzeroprice[$i]' value='$txtItemZeroPrice[$i]' >
						<input type='hidden' name='txtItemUnitCoef[$i]' id='itemunitcoef[$i]' value='$txtItemUnitCoef[$i]' >
						<input type='hidden' name='txtSorDtId[$i]' id='sordtid[$i]' value='$txtSorDtId[$i]' >
						<input type='hidden' name='sorderdt_clientdiscount[$i]' id='sorderdt_clientdiscount[$i]' value='$sorderdt_clientdiscount[$i]' style='width:60'>
						<input type='hidden' name='sorderdt_itemdiscount[$i]' id='sorderdt_itemdiscount[$i]' value='$sorderdt_itemdiscount[$i]' style='width:60' >
						<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($i);\" style='vertical-align:bottom;'/></span></label>
						<input type='text' name='txtItemCode[$i]' id='itemcode[$i]' value='$txtItemCode[$i]'   onblur='checkduplicate($i,this.value)'   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."','".$txtClientCode."'); 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>
						<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($i);\"><span style='font-weight:normal;'>Close</span></a></div>
						</div>
					</td>";
									
			echo"  	<td width='200px;' 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($Module_ShowWarehouseSalesorder==1)		
				echo"  	<td width='75px;' align='center'>
						<input type='text' name='txtWarehouseCode[$i]' id='warehousecode[$i]' value='$txtWarehouseCode[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:35px; 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>";
			else 
				echo" <input type='hidden' name='txtWarehouseCode[$i]' id='warehousecode[$i]' value='".$rowsdt[4]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecode[$i]','warehousename[$i]','warehouse');\" ".$KeyDown."   />";					
			
			if($Module_Heatno == 1)
				echo"  	<td width='150px;' align='center'>
							<input type='text' name='sorderdt_heatno[$i]' id='sorderdt_heatno[$i]' value='".$sorderdt_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='sorderdt_heatno[$i]' id='sorderdt_heatno[$i]' value=''  />";
				
			if (($Module_DoubleUnit == 1) ){
					echo"  <td width='60px;' align='center'><input type='text' name='txtItemUnit1' id='itemunit1[$i]' value='$txtItemUnit1' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' readonly></td>";
			} else {
					echo"  <input type='hidden' name='txtItemUnit1' id='itemunit1[$i]' value='$txtItemUnit1' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' readonly>";
					}
			if($sorder_export==1){
			$sorderdt_quantitybox=0;
			$sorderdt_itemunit=0;
			$sorderdt_itempackage='';
							echo"  <td width='60px;' align='center'><input type='text' name='sorderdt_quantitybox' id='sorderdt_quantitybox[$i]' value='$sorderdt_quantitybox' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' ".$KeyDown."  ></td>";
							echo"  <td width='60px;' align='center'><input type='text' name='sorderdt_itemunit' id='sorderdt_itemunit[$i]' value='$sorderdt_itemunit' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' ".$KeyDown."  ></td>";
							echo"  <td width='60px;' align='center'><input type='text' name='sorderdt_itempackage' id='sorderdt_itempackage[$i]' value='$sorderdt_itempackage' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' ".$KeyDown."  ></td>";
				}
			 else {
							echo"  <input type='hidden' name='sorderdt_quantitybox' id='sorderdt_quantitybox[$i]' value='$sorderdt_quantitybox' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' ".$KeyDown."  >";
							echo"  <input type='hidden' name='sorderdt_itemunit' id='sorderdt_itemunit[$i]' value='$sorderdt_itemunit' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' ".$KeyDown."  >";
							echo"  <input type='hidden' name='sorderdt_itempackage' id='sorderdt_itempackage[$i]' value='$sorderdt_itempackage' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' ".$KeyDown."  >";
							
				}
			if ($sorderproduction == 	1){	
				echo"	<td width='70px;' align='center'><input type='text' name='txtProdQty[$i]' id='itemprodqty[$i]' value='$txtProdQty[$i]' maxlength='20'   class='".$ClassI."' style='font-size:12px; width:60px; height:20px;' ".$KeyDown."></td>";
				echo"	<td width='80px;' align='center'><select name='txtSentProd[$i]' id='itemsentprod[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:75px; height:20px;' ".$KeyDown.">
						<option value='0'>Not Sent</option>
						<option value='1'>Sent</option>
						</select></td>";
			} else echo "<input type='hidden' name='txtProdQty[$i]' id='itemprodqty[$i]' value=''><input type='hidden' name='txtSentProd[$i]' id='itemsentprod[$i]' value=''>";
			
			echo"	<td width='70px;' align='center'><input type='text' name='txtSorDtOQty[$i]' id='itemorderedqty[$i]' value='$txtSorDtOQty[$i]' maxlength='20' onKeyup='CalcSorDtQty($i); CalcSorDtTotal($DecimalBase,$i);' onchange=\"CalcQty2($Module_Unit1Method,1,$i); SetModRecord('ModRec_G1','$i');\"  class='".$ClassI."' style='font-size:12px; width:60px; height:20px;' ".$KeyDown." $ModeModifyQty></td>";
			echo"   <td width='70px;' align='center'><input type='text' name='txtSorDtCQty[$i]' id='cancelledqty[$i]' value='$txtSorDtCQty[$i]' maxlength='20' onKeyup='CalcSorDtQty($i); CalcSorDtTotal($DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G1','$i');\"  class='".$ClassI."' style='font-size:12px; width:60px; height:20px;' ".$KeyDown."  ></td>";
			echo"	<td width='70px;' align='center'><input type='text' name='txtSorDtQty[$i]' id='sordtquantity[$i]' value='$txtSorDtQty[$i]' maxlength='20' class='".$ClassI."'   style='font-size:12px; font-weight:bold; text-align:center; border-width:0px; width:60px; height:20px;'  readonly></td>";
						
			  
			if ($Module_DoubleUnit == 1) {
				echo"  <td width='60px;' align='center'><input type='text' name='txtItemUnit2' id='itemunit2[$i]' value='$txtItemUnit2' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:50px; height:20px;' readonly></td>";
				echo"  <td width='75px;' align='center'><input type='text' name='txtSorDtQty2[$i]' id='unit2qty[$i]' value='$txtSorDtQty2[$i]' maxlength='20' onchange=\"CalcQty2('$Module_Unit1Method','2','$i'); SetModRecord('ModRec_G1','$i');\" onkeyup=\"changeQty2(this.value,'$i');\" class='".$ClassI."'  style='font-size:12px; width:60px; height:20px;' ".$KeyDown." ></td>";
			} else {
				echo "<input type='hidden' name='txtSorDtQty2[$i]' id='unit2qty[$i]' value='' >";
			}
		if($FI_DeliverySalesPrice == 1){	  
			echo"	<td width='100px;' align='center'><input type='text' name='txtSorDtPrice[$i]' id='price[$i]' value='$txtSorDtPrice[$i]' maxlength='20' onKeyup='CalcSorDtTotal($DecimalBase,$i);' class='".$ClassI."'  style='text-align:right; font-size:12px; width:90px; height:20px;' ".$KeyDown." $ModeModifySellPrice ></td>";
			echo"   <td width='80px;' align='center'><input type='text' name='txtItemLastSellPrice' id='lastprice[$i]' value='$txtItemLastSellPrice' maxlength='20' class='".$ClassI."'  style='text-align:right; font-size:12px; width:70px; height:20px;' readonly></td>";
					  
			echo"	<td width='65px;' align='center'><input type='text' name='txtSorDtDiscount[$i]'   onblur='UpdateDiscount($i,this.value)'  id='sordtdiscount[$i]' value='$txtSorDtDiscount[$i]' maxlength='20' onKeyup='CalcSorDtTotal($DecimalBase,$i);' onchange=\"SetModRecord('ModRec_G1','$i');\" class='".$ClassI."'   style='text-align:right; font-size:12px; width:60px; height:20px;' ".$KeyDown." $ModeDiscount ></td>";
			echo"   <td width='100px;' align='center'><input type='text' name='txtSorDtTotal[$i]' id='sordttotal[$i]' value='$txtSorDtTotal[$i]' maxlength='20' class='".$ClassI."'   style='text-align:right; font-size:12px; width:90px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
		} else {
			echo"<input type='hidden' name='txtSorDtPrice[$i]' id='price[$i]' value='' maxlength='20'></td>";
			echo"<input type='hidden' name='txtItemLastSellPrice' id='lastprice[$i]' value='' maxlength='20'>";
					  
			echo"<input type='hidden' name='txtSorDtDiscount[$i]' id='sordtdiscount[$i]' value='' maxlength='20'>";
			echo"<input type='hidden' name='txtSorDtTotal[$i]' id='sordttotal[$i]' value='' maxlength='20'>";
		
		}
			if ($Module_ProjectDt == 1) {
				echo"<td width='170px;' 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='170px;' 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($SubItem_Production != 1 ) 
				echo"	<td width='250px;'><input type='text' name='txtSorDtRemark[$i]' id='remarkdt[$i]' value='".htmlspecialchars($txtSorDtRemark[$i], ENT_QUOTES)."'  maxlength='200' class='".$ClassI."'  style='font-size:12px; width:245px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";	
			else echo"<input type='hidden' name='txtSorDtRemark[$i]' id='remarkdt[$i]' value='".htmlspecialchars($txtSorDtRemark[$i], ENT_QUOTES)."'  maxlength='200' class='".$ClassI."'  ></td>";	
			
			echo"	<td width='25px;' align='center'><input type='checkbox' name='chkSorDtPromo[$i]' id='chkpromo[$i]' value='1'  onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown."  ></td>";	
			echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit[$i]'     onclick=\"SubmitRecordGrid('".$i."','".$filepath."', '".$form."', '".$PSorId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_NegativeSorder,$Login_NegativeQty,$Login_AllowPrice,$Module_SorderCheckQtyOnPost,$Allow_MinimumPrice,$Module_RestrictProjCost,$Module_RestrictCost,$txtClientDetail,$FI_SalesCheckSalesman,$txtClientPromotion,$Module_ShowWarehouseSalesorder); 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,$PSorId,'datagrid',$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	
	echo"</div>";
	
	
}

function ShowSorderTotals($connection,$PSorId,$arrayparams,$arrayaccess){
	 
	$DecimalBase  = $arrayparams['DecimalBase'];
	$SalesTTC = $arrayparams['SalesTTC'];
	$Setup_VatPercentage = $arrayparams['Setup_VatPercentage'];
	$Module_AdditionalTaxes = $arrayparams['Module_AdditionalTaxes'];
	$ExportTransportToJV = $arrayparams['ExportTransportToJV'];
	$VatApplied = $arrayparams['VatApplied'];
	$AllowModifyVAT = $arrayparams['AllowModifyVAT'];
	$Login_ModifyDiscount = $arrayparams['Login_ModifyDiscount'];
		
	$txtClientCode   = $arrayparams['txtClientCode'];
	
	if ($Login_ModifyDiscount == 0)	$DiscountMode = ' readonly ';
	
	if ($PSorId != "") {		 
		$sub_query = " Select Round(if($SalesTTC=1,ifNull(Sorder_Taxable,0)*(1+$Setup_VatPercentage/100),ifNull(Sorder_Taxable,0)), ".$DecimalBase."), Round(ifNull(Sorder_NoneTaxable,0), ".$DecimalBase."), ".
					 " Round(if($SalesTTC=1,ifNull(Sorder_Taxable,0)*(1+$Setup_VatPercentage/100),ifNull(Sorder_Taxable,0)) + ifNull(Sorder_NoneTaxable,0), ".$DecimalBase.") As GrossTotal, ".
					 " Round(ifNull(Sorder_DiscountPer,0), ".$DecimalBase."), Round(ifNull(Sorder_DiscountAmount,0), ".$DecimalBase."),  ".
					 " ifNull(Sorder_VatChckbx,0) As Sorder_VatChckbx, Round(ifNull(Sorder_VAT,0), ".$DecimalBase.") As Sorder_VAT, ".
					 " Round((if($SalesTTC=1,ifNull(Sorder_Taxable,0)*(1+$Setup_VatPercentage/100),ifNull(Sorder_Taxable,0)) + ifNull(Sorder_NoneTaxable,0) + if($SalesTTC=1,0,IfNull(Sorder_VAT,0)) + ifNull(Sorder_TransportAmount,0) - IfNull(Sorder_DiscountAmount,0) + (ifNull(Sorder_Tax1,0) + ifNull(Sorder_Tax2,0) + ifNull(Sorder_Tax3,0) + ifNull(Sorder_Tax4,0) + ifNull(Sorder_Tax5,0))), ".$DecimalBase.") As Sorder_NetTotal,  ".
					 " Round((ifNull(Sorder_Tax1,0) + ifNull(Sorder_Tax2,0) + ifNull(Sorder_Tax3,0) + ifNull(Sorder_Tax4,0) + ifNull(Sorder_Tax5,0)), ".$DecimalBase.") As TotalTaxes,  ".
					 " Round(if($SalesTTC=1,ifNull(Sorder_TransportTTC,0),ifNull(Sorder_TransportAmount,0)), ".$DecimalBase.") As TransportAmt ".
					 " From Temp_Sorder As Sorder ".
					 " Where Sorder_ID = ".$PSorId;			 
				 
		//echo $sub_query;
		$sub_result = selectData($connection, $sub_query);
		
		$txtSorTaxable      = $sub_result[0];
		$txtSorNoneTaxable  = $sub_result[1];
		$txtSorGrossTotal   = $sub_result[2];
		$txtSorDiscount     = $sub_result[3];
		$txtSorDiscountAmt  = $sub_result[4];
		$txtSorVatChk       = $sub_result[5];
		$txtSorVat          = $sub_result[6];
		$txtSorNetTotal     = $sub_result[7];
		$txtSorTotalTaxes   = $sub_result[8];
		$txtSorTransportAmt = $sub_result[9];
	} else {
		$sub_query = " Select ifNull(Client_VAT,0) From Clients Where Ledger_Number = '".$txtClientCode."'";			 
		$sub_result = selectData($connection, $sub_query);
		$txtSorVatChk = $sub_result[0];
	}
	
	echo"<table border='0' style='table-layout:fixed;' cellspacing=0>
		<tr>
		<td id='total-top' style='width:240px;height:12px;'></td>
		</tr>
		<tr><td id='total-content' style='width:240px;height:12px;' valign='top'>
		<table border='0' style='table-layout:fixed;' cellspacing=0 >
			<col width=100>
			<col width=140>";
			
	echo"	
				<tr><td valign='center' align='right' width='35%'><span class='style10'>Taxable</span>&nbsp;</td>
					<td align='left' style='padding-top:1px;padding-bottom:1px;'><input type='text' id='taxable'  name='txtSorTaxable' value='$txtSorTaxable' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
				</tr>
				<tr><td valign='center' align='right' width='35%'><span class='style10'>None Taxable</span>&nbsp;</td> 
					<td align='left' style='padding-top:1px;padding-bottom:1px;'><input type='text' id='nontaxable' name='txtSorNoneTaxable' value='$txtSorNoneTaxable' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
				</tr>
				<tr><td valign='center' align='right' width='35%'><span class='style10'>Gross Total</span>&nbsp;</td> 
					<td align='left' style='padding-top:1px;padding-bottom:1px;'><input type='text' id='grosstotal' name='txtSorGrossTotal' value='$txtSorGrossTotal' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
				</tr>	
				<tr><td valign='center' align='right'  width='35%'><span class='style10'>Discount</span>&nbsp;</td> 
					<td align='left' style='padding-top:1px;padding-bottom:1px;'><input type='text' id='sordiscount' name='txtSorDiscount' value='$txtSorDiscount' maxlength='5' style='text-align:right; width:38px; height=20px;' onKeyup='CalcSorDiscount(1, $DecimalBase,$VatApplied,$Setup_VatPercentage,$SalesTTC);' $DiscountMode ><span class='style10'> %</span>
						<input type='text' id='sordiscountamt' name='txtSorDiscountAmt' value='$txtSorDiscountAmt' maxlength='20' style='text-align:right; width:58px; height=20px;' onKeyup='CalcSorDiscount(2, $DecimalBase,$VatApplied,$Setup_VatPercentage,$SalesTTC);' $DiscountMode ></td>
				</tr>";
				
	if ($ExportTransportToJV == 1) {
		echo"	<tr><td valign='center' align='right'  ><span class='style10'>Transport</span>&nbsp;</td> 
					<td align='left' ><input type='text' id='sortransportamt' name='txtSorTransportAmt' value='$txtSorTransportAmt' maxlength='20'  style='text-align:right; width:120px; height=20px;' onKeyup='CalcNetTotal($DecimalBase,$VatApplied,$Setup_VatPercentage,$SalesTTC);'></td>
				</tr>";
	} else {
		echo "	<input type='hidden' id='sortransportamt' name='txtSorTransportAmt' value='$txtSorTransportAmt'>";
	}
	
	echo"		<tr><td valign='center' align='right' width='35%'  style='padding-top:1px;padding-bottom:1px;'><span class='style10'>
						<input type='hidden' name='txtSorVatChk' id='txtSorVatChk' value='$txtSorVatChk' size='1'/>
						<input name='chkSorVat' type='checkbox' id='chkSorVat' value='1' onClick='SetSorVat($DecimalBase,$VatApplied,$Setup_VatPercentage,$SalesTTC);'"; 
						if($txtSorVatChk==1) echo " checked $AllowModifyVAT />";  else echo " $AllowModifyVAT />"; 
				  
	echo "				VAT $Setup_VatPercentage%&nbsp;</span>
					</td> 
					<td align='left'  style='padding-top:1px;padding-bottom:1px;'>
						<input type='text' id='sorvat' name='txtSorVat' value='$txtSorVat' maxlength='20' style='text-align:right; width:120px; height=20px;' >
					</td>
				</tr>";
	
	if ($Module_AdditionalTaxes == 1) {
		echo"	<tr>
					<td valign='center' align='right' width='35%'><span class='style10'>Taxes</span>&nbsp;</td> 
					<td align='left' style='padding-top:1px;padding-bottom:1px;'><input type='text' id='tax' name='txtSorTotalTaxes' value='$txtSorTotalTaxes' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
				</tr>";
	} else {
		echo "	<input type='hidden' name='txtSorTotalTaxes' value='$txtSorTotalTaxes'>";
	}
					
	echo "		<tr><td valign='middle' align='right' width='35%'><span class='style10'>Net Total</span>&nbsp;</td> 
					<td align='left'  style='padding-top:1px;padding-bottom:1px;'><input type='text' id='nettotal' name='txtSorNetTotal' value='$txtSorNetTotal' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;";
					
					if($txtSorNetTotal<0) echo " color:#FF0000;";
					
					
					echo" ' readonly></td>
				</tr> 
				  </table></td>
				</tr><tr>
					<td id='total-bottom' style='width:240px;height:12px;'></td>
				</tr></table></td></tr>";
			


}

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

}

?>
