<?php

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

if (!empty($_GET["action"])) {
	$dftorderby   = $_GET["dftorderby"];
	$action 	  = $_GET["action"];
	$orderby 	  = $_GET["orderby"];
	$morelines	  = $_GET["morelines"];
	$startrange   = $_GET["startrange"];
	$perpage 	  = $_GET["perpage"];
	$totalrows    = $_GET["totalrows"];
	$direction    = $_GET["direction"];
	$filepath     = $_GET["filepath"];
	$transid      = $_GET["transid"];
	$transdtid    = $_GET["transdtid"];
	$form      	  = $_GET["form"];
	
	
	
	include("config.inc.php");
	include("Functions_Sales.php");
	
	$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
	mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");
	
	
	if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
		mysql_query("SET NAMES 'utf8'"); 
		mysql_query('SET CHARACTER SET utf8'); 
		mysql_set_charset('utf8', $connection);
	}

	//echo $_SESSION['dbName']."<br>";
	
	if ($form == 'MReq') {
		$querylog=" select ifNull(FI_PurchaseRequestApp,0) As FI_PurchaseRequestApp, ifNull(FI_PRequestConfirmed,0) As FI_PRequestConfirmed, ".
			  " ifNull(FI_PurchaseCategory,0) As FI_PurchaseCategory, ifNull(Login_FastPrint,0) As Login_FastPrint ".
			  " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
	$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}
		
	//Read From Setup Table							
	/*$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ".
				 " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup ";
	$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
	while($rowsetup=mysql_fetch_array($resultsetup)){
		extract($rowsetup);
	}*/

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

	//Read From PurchaseSetup Table
	$queryPurchaseSetup="Select PurchaseTTC From PurchaseSetup";
	$resultPurchaseSetup=mysql_query($queryPurchaseSetup,$connection) or die(mysql_error());
	while($rowPurchaseSetup=mysql_fetch_array($resultPurchaseSetup)){
		extract($rowPurchaseSetup);
	}

		ShowMReqDtGrid($connection,$form,$transid,$orderby,$startrange,$perpage,$option,$direction,$_SESSION['gdl_parameters']);
	}
	else if ($form == 'MReq-totals') {
		ShowMReqDtTotalsGrid($connection,$form,$transid,$_SESSION["PurchaseTTC"],$_SESSION["VatApplied"],$_SESSION["Setup_VatPercentage"],$_SESSION["DecimalBase"]);
	}
	

}

function showDataGridFooter($filepath,$form,$transid,$gridid,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction) {
	
	echo"<div  style='background-color:C8C8C8;width:1100'>
			<table width='100%' border=0 >
			<tr>";
	
	$rangefrom = ($startrange + 1);
	if (($startrange + $perpage) >= $totalrows) $rangeto = $totalrows; else $rangeto = ($startrange + $perpage);
				
	if ($totalrows > 0)			
		echo"	<td align='left' style='width:350px; padding-left:10px;'><span class='toolbar_style'>View ".$rangefrom." - ".$rangeto." of ".$totalrows."</span></td>";
	else
		echo"	<td align='left' style='width:350px; padding-left:10px;'><span class='toolbar_style'>No records to view</span></td>";
	
	echo"		<td align='center' style='width:120px;'><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';

								
				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>
					 </select></span>
				</td>';
				
	echo"		<td  style='width:100px;border-right:1px solid #000000;text-align:right;'>";
				
				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:100px;'>";
			
			
				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:150px;'>&nbsp;<span class='toolbar_style'>Page $currentpage / $totalpages</span></td>";
	

	
	echo"		<td style='text-align:center; width:60px;'><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:210px; padding-right:10px;'>&nbsp;</td>";
	
	echo"	</tr>";
	echo"	</table></div>";

}

function ShowMReqDtGrid($connection,$form,$MReqId,$orderby,$startrange,$perpage,$option,$direction,$arrayparams){
	
	$base1 							= $arrayparams['base1'];
	$base2 							= $arrayparams['base2'];
	$DecimalBase 					= $arrayparams['DecimalBase'];
	$Module_DoubleUnit 				= $arrayparams['Module_DoubleUnit'];
	$Module_ProjectDt 				= $arrayparams['Module_ProjectDt'];
	$Module_CostCenterDt 			= $arrayparams['Module_CostCenterDt'];
	$PriceLabel 					= $arrayparams['PriceLabel'];
	$Module_Unit1Method 			= $arrayparams['Module_Unit1Method'];
	$PurchaseTTC 					= $arrayparams['PurchaseTTC'];
	$FIPurchaseCategory 			= $arrayparams['FIPurchaseCategory'];
	$Module_PurchaseRequestPrice 	= $arrayparams['Module_PurchaseRequestPrice'];
	$Module_Pack 					= $arrayparams['Module_Pack'];
	$Module_Heatno 					= $arrayparams['Module_Heatno'];
	
	//Read From PurchaseSetup Table
	$queryPurchaseSetup="Select ifNull(ShowCostCentLayout,0) As ShowCostCentLayout From PurchaseSetup ";
	$resultPurchaseSetup=mysql_query($queryPurchaseSetup,$connection) or die(mysql_error());
	while($rowPurchaseSetup=mysql_fetch_array($resultPurchaseSetup)){
		extract($rowPurchaseSetup);
	}

	$query="Select ifNull(Module_CancelledQty,0) As Module_CancelledQty From Module ";
	$result=mysql_query($query,$connection) or die(mysql_error());
	while($row=mysql_fetch_array($result)){
		extract($row);
	}

	$ClassI = 'grid_roundedtext2';
	$filepath = 'Forms_DataGrid_MaterailReq.php';
	
	
	$PriceLabel = 'Price';	
	if ($PurchaseTTC == 1)  $PriceLabel = 'Price TTC';	
	
	
	if ($startrange=='')	$startrange = 0;
		
	if ($direction == 'asc')
		$direction = 'desc';
	else if ($direction == 'desc')
		$direction = 'asc';
	else $direction = 'asc';

	if ($perpage=='')
		$perpage = 20;
	
		
			
	if ($Module_PurchaseRequestPrice==1) {
	if ($PurchaseTTC == 1) {
	$columnsarray = array("itemcode"						,"itemdescription"						,"mreqdtitemdescription"
						,"warehousecode"						,"mreqdtOquantity"						);
			
	if($Module_CancelledQty==1) {
		$columnsarray[] = "mreqdtCquantity";
		$columnsarray[] = "itemunit2qty";
		}
						
						
		$columnsarray[] = "mreqdtpricettc";
		$columnsarray[] = "mreqdtdiscount";
		$columnsarray[] = "mreqdttotalttc";
	if($Module_Heatno == 1)
			$columnsarray[] = "mreqdtheatno";
							
	if ($Module_ProjectDt==1)
		$columnsarray[] = "mreqdtprojectcode";						
		
	if ($Module_CostCenterDt==1 && $ShowCostCentLayout == 1)		
		$columnsarray[] = "mreqdtcostcentercode";
	
	$columnsarray[] = "mreqdt_RequiredDate";
	$columnsarray[] = "mreqdt_Remark";
		}				
	else {
	$columnsarray = array("itemcode","itemdescription","mreqdtitemdescription","warehousecode","mreqdtOquantity");
	if($Module_CancelledQty==1) {
		$columnsarray[] = "mreqdtCquantity";
		$columnsarray[] = "itemunit2qty";
	}
	$columnsarray[] = "mreqdtprice";
	$columnsarray[] = "mreqdtdiscount";
	$columnsarray[] = "mreqdttotal";
					
	if($Module_Heatno == 1)
			$columnsarray[] = "mreqdtheatno";
		
	if ($Module_ProjectDt==1)
		$columnsarray[] = "mreqdtprojectcode";
	
	if ($Module_CostCenterDt==1 && $ShowCostCentLayout == 1)
		$columnsarray[] =  "mreqdtcostcentercode";
	$columnsarray[] = "mreqdt_RequiredDate";
	$columnsarray[] =  "mreqdt_Remark";
					
		}			
	}
	else if ($Module_PurchaseRequestPrice==0) {
	if ($PurchaseTTC == 1) {
	$columnsarray = array("itemcode"						,"itemdescription"						,"mreqdtitemdescription"
						,"warehousecode"						,"mreqdtOquantity");

		if($Module_CancelledQty==1)	 {
			$columnsarray[] = "mreqdtCquantity";
			$columnsarray[] = "itemunit2qty";
		}			
		if($Module_Heatno == 1)
			$columnsarray[] = "mreqdtheatno";
						
		if ($Module_ProjectDt==1)
			$columnsarray[] = "mreqdtprojectcode";
		
		if ($Module_CostCenterDt==1 && $ShowCostCentLayout == 1)
			$columnsarray[] =  "mreqdtcostcentercode";
		$columnsarray[] = "mreqdt_RequiredDate";	
		$columnsarray[] =  "mreqdt_Remark";
		}
		else {
		$columnsarray = array("itemcode"						,"itemdescription"		,"mreqdtitemdescription"		,"warehousecode"
						,"mreqdtOquantity"	);
						
						
		if($Module_CancelledQty==1)	 {
			$columnsarray[] = "mreqdtCquantity";
			$columnsarray[] = "itemunit2qty";
		}
		if($Module_Heatno == 1)
			$columnsarray[] = "mreqdtheatno";
		
		if ($Module_ProjectDt==1)
			$columnsarray[] = "mreqdtprojectcode";
		
		if ($Module_CostCenterDt==1 && $ShowCostCentLayout == 1)
			$columnsarray[] =  "mreqdtcostcentercode";
		$columnsarray[] = "mreqdt_RequiredDate";	
		$columnsarray[] =  "mreqdt_Remark";
						
					}	
	}
	
	
	$columnslist = implode(',', $columnsarray);

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


if ($orderby=='')
	$orderby = 'mreqdt_id';
	
	
	  
			$query = " Select materialreqdt.MReqDt_id, materialreqdt.Item_CodePacked, materialreqdt.Item_code, Items.Item_Description, materialreqdt.Warehouse_Code, ".
					   " MReqDt_Remark, MReqDt_Quantity, Round(MReqDt_Price, ".$DecimalBase."), Round(MReqDt_PriceTTC, ".$DecimalBase."), ".
					   " Round(MReqDt_Discount, ".$DecimalBase."), ".
					   " Round(((MReqDt_Quantity*MReqDt_Price)-((MReqDt_Quantity*MReqDt_Price*ifNull(MReqDt_Discount,0))/100)), ".$DecimalBase.") As Total, ".
					   " Round(((MReqDt_Quantity*MReqDt_PriceTTC)-((MReqDt_Quantity*MReqDt_PriceTTC*ifNull(MReqDt_Discount,0))/100)), ".$DecimalBase.") As TotalTTC, ".
					   " materialreqdt.Item_Unit2Qty, Item_UnitPurchaseDesc, Item_UnitSalesDesc, materialreqdt.Project_code, materialreqdt.CostCent_Code, materialreqdt.Item_description ".
					   " ,materialreqdt.MReqDt_OQuantity,materialreqdt.MReqDt_CQuantity,MReqDt_unitsalesdesc, MReqDt_heatno, date_format(MReqDt_RequiredDate, '%d/%m/%Y') ".
					   " From temp_materialreqdt As materialreqdt Left Join Items on materialreqdt.Item_code = Items.Item_code ".
					   " Where materialreqdt.MReq_id = '".$MReqId."' ".
					   " Order By materialreqdt.MReqDt_id Asc ";
//echo $query;	
$result=mysql_query($query,$connection)  or die(mysql_error());
$totalrows = mysql_num_rows($result);

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

$i=0;
//echo"<input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='strt' id='strt' value='$strt'><input type='hidden' name='end' id='end'  value='$end'>";
echo"<div id='prequestdtdiv' style='overflow:auto;width:1090px;height:200px;border:0px solid black;'>";

$widthTable = 1105;
if ($Module_Pack == 1) $widthTable += 120;
if ($Module_CancelledQty == 1) $widthTable += 145;
if ($Module_DoubleUnit == 1) $widthTable += 145;
if ($Module_PurchaseRequestPrice == 1) $widthTable += 240;
if ($Module_Heatno == 1) $widthTable += 120;
if ($Module_ProjectDt == 1) $widthTable += 120;
if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1) $widthTable += 120;

$widthTable = $widthTable."px";
	
echo"<table border='0' align='center'   class='grid_data'  width=$widthTable style='table-layout:fixed;font-size:10px;border:0px solid black;border-spacing:0;' cellpadding='0' cellspacing='1'>";

echo"	<col width=30>";

if ($Module_Pack == 1)
	echo" <col width=120>";
	
echo" 	<col width=150>
		<col width=200>
		<col width=140>
		<col width=100>
		<col width=80>";

echo"<col width=80>";

if($Module_CancelledQty==1) {
	echo" <col width=70>
		  <col width=75>";
}
if ($Module_DoubleUnit == 1)
	echo" <col width=70>
		  <col width=75>";
		  
if ($Module_PurchaseRequestPrice==1)		  
	echo"<col width=80>
		 <col width=80>
		 <col width=80>";
if($Module_Heatno == 1)	  echo "<col width=120>";

if ($Module_ProjectDt == 1)	echo" <col width=120>";

if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1)	echo "<col width=120>";
	echo "<col width=100>";
	echo "<col width=200><col width=25>";

	

		  
		echo"<tr bgcolor='#D8D8D8' height='25'>";
		echo"  <th bgcolor='#D8D8D8' align='left'><span class='style27'>&nbsp;</th>";
		
		if ($Module_Pack == 1)
			echo"  <th bgcolor='#D8D8D8' align='left'><b>Item Code Packed</b></th>";
			
		echo"  <th bgcolor='#D8D8D8' align='left'><b>Item</b></th>";
		echo"  <th bgcolor='#D8D8D8' align='left'><b>Description</b></th>";
		echo"  <th bgcolor='#D8D8D8' align='left'><b>New Item</b></th>";
		echo"  <th bgcolor='#D8D8D8' align='center'><b>WH</b></th>";
		
		//if ($Module_DoubleUnit == 1)
			echo"  <th bgcolor='#D8D8D8' align='center'><b>Unit1</b></th>";
			
		echo"  <th bgcolor='#D8D8D8' align='center'><b>Ordered Qty</b></th>";
		
		if($Module_CancelledQty==1) {
			echo"  <th bgcolor='#D8D8D8' align='center'><b>Cancelled Qty</b></th>";
			echo"  <th bgcolor='#D8D8D8' align='center'><b>Qty</b></th>";
		}
		
		if ($Module_DoubleUnit == 1) {
			echo"  <th bgcolor='#D8D8D8' align='center'><b>Unit2</b></th>";
			echo"  <th bgcolor='#D8D8D8' align='center'><b>Unit2 Qty</b></th>";
		}
		
		if ($Module_PurchaseRequestPrice==1)  {
		echo"  <th bgcolor='#D8D8D8' align='center'><b>$PriceLabel</b></th>";
		echo"  <th bgcolor='#D8D8D8' align='center'><b>Disc(%)</b></th>";
		echo"  <th bgcolor='#D8D8D8' align='center'><b>Total</b></th>";
		}
		if($Module_Heatno == 1)
			echo"  <th bgcolor='#D8D8D8' align='center'><b>Heat No.</b></th>";
		if ($Module_ProjectDt == 1)	
			echo"  <th bgcolor='#D8D8D8' align='center'><b>Project</b></th>";
		if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1)
			echo"  <th bgcolor='#D8D8D8' align='center'><b>CostCenter</b></th>";
			
			echo"  <th bgcolor='#D8D8D8' align='center'><b>Required Date</b></th>";
			echo"  <th bgcolor='#D8D8D8' align='center'><b>Remark</b></th>";
			
			echo"  <th bgcolor='#D8D8D8' align='center'></span></th>";
			
        echo"</tr>";
			



	$i=0;
	$j=1;
	
	echo"
		
		 <input type='hidden' name='SelectedRec' id='SelectedRec' value='$SelectedRec'>
		 <input type='hidden' name='SelectedRecColor' id='SelectedRecColor' value='$SelectedRecColor'>
		 <input type='hidden' name='ModRec_G1' id='ModRec_G1' value='$ModRec_G1'>		 
		 <input type='hidden' name='Module_PurchaseRequestPrice' id='Module_PurchaseRequestPrice' value='$Module_PurchaseRequestPrice'>		 
		 ";

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

			$txtMreqDTId[$i] = $row[0];
			$itemcodepacked[$i] = $row[1];
			$itemcode[$i] = $row[2];
			$itemdescription[$i] = $row[3];
			$warehousecode[$i] = $row[4];
			
			
			
			
			$mreqdtquantity[$i] = $row[6];
			$itemunitpurchasedesc[$i] = $row[13];
			$itemunit2qty[$i] = $row[12];
			$mreqdtpricettc[$i] = $row[8];
			$mreqdtprice[$i] = $row[7];
			$mreqdtdiscount[$i] = $row[9];
			$mreqdttotal[$i] = $row[10];
			$mreqdttotalttc[$i] = $row[11];
			$mreqdtprojectcode[$i] = $row[15];
			$mreqdtcostcentercode[$i] = $row[16];
			
			$mreqdt_Remark[$i] = $row[5];
			
			$mreqdtitemdescription[$i] = $row[17];
			
			$prequestdt_unitsalesdesc[$i] = $row[20];
			$mreqdtheatno[$i] = $row[21];			
			$mreqdt_RequiredDate[$i] = $row[22];	
			
			if($itemcode[$i]!='')
				$readonly='readonly';
				else
				$readonly='';
				
			if($itemcode[$i]=='')
				$itemunitsalesdesc[$i] = $prequestdt_unitsalesdesc[$i];
			else
				$itemunitsalesdesc[$i] = $row[14];			
			
			$mreqdtOquantity[$i] = $row[18];
			$mreqdtCquantity[$i] = $row[19];

			
			//echo"<tr height='20px' id='mreqdt$i' onclick=\"returncolor(this,'SelectedRec','SelectedRecColor','$row[0]')\" style='background-color:$bgcolor'>";
			echo"<tr id='CurRec$i' class='$bgcolor table-focus-g1'>";
		
						
			$recno = $i+1;
			$recno = $perpage * (($startrange / $perpage)) + 1 + $i;
			
			echo"<td  align=center onclick=\"deleteprequestsdt('$MReqId','$row[0]','".$itemcodepacked[$i]."','".$itemcode[$i]."','$filepath'); return false;\"><img src='img/delete.png' onmouseover=\"style.cursor='pointer'\" name='' title='Delete' ></td>";
		
			if ($Module_Pack == 1)
				echo"<td ><span class='style4'><input type='text'   class='roundedtext_amortization_medium' readonly   $KeyDown  name='itemcodepacked[$i]' id='itemcodepacked[$i]' value='".$itemcodepacked[$i]."' style='width:115px'> </span></td>";
			else
				echo"<input type='hidden'  name='itemcodepacked[$i]' id='itemcodepacked[$i]' value='".$itemcodepacked[$i]."'>";
			
			
			echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'   onchange=\"setitemcode(this.value,'itemcode[$i]','itemdescription[$i]','item_vat[$i]','itemunitsalesdesc[$i]','itemunitpurchasedesc[$i]','i_unitcoef[$i]','','mreqdtitemcodeimage[$i]','mreqdtitemcodeimage1[$i]',1,7);SetModRecord('ModRec_G1','$i')\"    name='itemcode[$i]' id='itemcode[$i]' value='".$itemcode[$i]."' style='width:125px'></span>
				<img src='img/scroll-down-1.png' width='20' height='20' id='mreqdtitemcodeimage[$i]' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('itemcode','itemcode[$i]','itemdescription[$i]','item_vat[$i]','itemunitsalesdesc[$i]','itemunitpurchasedesc[$i]','i_unitcoef[$i]','800','500')\">
					</td>";
			
			echo"<td ><span class='style4'><input type='text'   class='roundedtext_amortization_mediumlarge'    $KeyDown     onchange=\"setitemcode(this.value,'itemcode[$i]','itemdescription[$i]','item_vat[$i]','itemunitsalesdesc[$i]','itemunitpurchasedesc[$i]','i_unitcoef[$i]','','mreqdtitemcodeimage[$i]','mreqdtitemcodeimage1[$i]',2,7);SetModRecord('ModRec_G1','$i')\"     name='itemdescription[$i]' id='itemdescription[$i]' value='".$itemdescription[$i]."' style='width:195px'> </span></td>";					
			echo"<td ><span class='style4'><input type='text'   class='roundedtext_amortization_mediumlarge'    $KeyDown    name='mreqdtitemdescription[$i]' id='mreqdtitemdescription[$i]' value='".$mreqdtitemdescription[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');CheckItemCode(this,'$i')\" style='width:140px'> </span></td>";					

		
			
			
			echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='warehousecode[$i]' id='warehousecode[$i]' value='".$warehousecode[$i]."' onchange=\"setwarehousecode(this.value,'warehousecode[$i]','imgwarehousebtn[$i]');SetModRecord('ModRec_G1','$i');\"  > </span>
			<img src='img/scroll-down-1.png' title=' Select Warehouse ' id='imgwarehousebtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistWarehouse('warehousecode','warehousecode[$i]','800','500') \" />
			</td>";

			
			//if ($Module_DoubleUnit == 1)
				echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='itemunitsalesdesc[$i]' id='itemunitsalesdesc[$i]' value='".$itemunitsalesdesc[$i]."' $readonly  onfocus='checkstatus($i)'  > </span></td>";
				//else
				//echo"<input type='hidden' class='roundedtext_amortization_medium'     name='itemunitsalesdesc[$i]' id='itemunitsalesdesc[$i]' value='".$itemunitsalesdesc[$i]."' readonly style='width:60px'> ";
		
				
				echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtOquantity[$i]' id='mreqdtOquantity[$i]' value='".$mreqdtOquantity[$i]."'  maxlength='20' onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  onchange=\"CalcQty2($i,$Module_Unit1Method,1);SetModRecord('ModRec_G1','$i');\" > </span></td>";
				
				if($Module_CancelledQty==1) {
					echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:68px'  name='mreqdtCquantity[$i]' id='mreqdtCquantity[$i]' value='".$mreqdtCquantity[$i]."'  maxlength='20' onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  onchange=\"CalcQty2($i,$Module_Unit1Method,1);SetModRecord('ModRec_G1','$i');\"  > </span></td>";
					echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:68px'  name='mreqdtquantity[$i]' id='mreqdtquantity[$i]' value='".$mreqdtquantity[$i]."'  maxlength='20'  readonly onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  onchange=\"CalcQty2($i,$Module_Unit1Method,1);SetModRecord('ModRec_G1','$i');\" > </span></td>";
				} else {
					$mreqdtCquantity[$i] = 0;
					echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='mreqdtCquantity[$i]' id='mreqdtCquantity[$i]' value='".$mreqdtCquantity[$i]."'  maxlength='20' onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  onchange=\"CalcQty2($i,$Module_Unit1Method,1);SetModRecord('ModRec_G1','$i');\" > </span>";
					echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'  name='mreqdtquantity[$i]' id='mreqdtquantity[$i]' value='".$mreqdtquantity[$i]."'  maxlength='20'  readonly onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  onchange=\"CalcQty2($i,$Module_Unit1Method,1);SetModRecord('ModRec_G1','$i');\" > </span>";
				}
		
		
				if ($Module_DoubleUnit == 1) { 
					echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='itemunitpurchasedesc[$i]' id='itemunitpurchasedesc[$i]' value='".$itemunitpurchasedesc[$i]."'  readonly  > </span></td>";
					echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='itemunit2qty[$i]' id='itemunit2qty[$i]' value='".$itemunit2qty[$i]."'   maxlength='20' onchange=\"CalcQty2($i,$Module_Unit1Method,2);SetModRecord('ModRec_G1','$i');\"  > </span></td>";
				}
				else 
				{
					echo"<span class='style4'><input type='hidden'      class='roundedtext_amortization_medium'   style='width:70px'  name='itemunitpurchasedesc[$i]' id='itemunitpurchasedesc[$i]' value='".$itemunitpurchasedesc[$i]."'  readonly  style='width:60px'> </span>";
					echo"<span class='style4'><input type='hidden'      class='roundedtext_amortization_medium'   style='width:70px'  name='itemunit2qty[$i]' id='itemunit2qty[$i]' value='".$itemunit2qty[$i]."'   maxlength='20' onchange=\"CalcQty2($i,$Module_Unit1Method,2);SetModRecord('ModRec_G1','$i');\"  > </span>";
				}
				
				if ($Module_PurchaseRequestPrice==1) {
				if ($PurchaseTTC == 1) 
					echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtpricettc[$i]' id='mreqdtpricettc[$i]' value='".$mreqdtpricettc[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  > </span></td>";
				else
					echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtprice[$i]' id='mreqdtprice[$i]' value='".$mreqdtprice[$i]."'   maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i');\" onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  > </span></td>";


				echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtdiscount[$i]' id='mreqdtdiscount[$i]' value='".$mreqdtdiscount[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'   > </span></td>";					

				
				if ($PurchaseTTC == 1) 
					echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdttotalttc[$i]' id='mreqdttotalttc[$i]' value='".$mreqdttotalttc[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" > </span></td>";
				else
					echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdttotal[$i]' id='mreqdttotal[$i]' value='".$mreqdttotal[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" > </span></td>";
				
				}
				else {
				if ($PurchaseTTC == 1) 
					echo"<input type='hidden'      class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtpricettc[$i]' id='mreqdtpricettc[$i]' value='".$mreqdtpricettc[$i]."'   > ";
				else
					echo"<input type='hidden'    class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtprice[$i]' id='mreqdtprice[$i]' value='".$mreqdtprice[$i]."'   maxlength='20' >";


				echo"<input type='hidden'     class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtdiscount[$i]' id='mreqdtdiscount[$i]' value='".$mreqdtdiscount[$i]."' >";					

				
				if ($PurchaseTTC == 1) 
					echo"<input type='hidden'     class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdttotalttc[$i]' id='mreqdttotalttc[$i]' value='".$mreqdttotalttc[$i]."' >";
				else
					echo"<input type='hidden'      class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdttotal[$i]' id='mreqdttotal[$i]' value='".$mreqdttotal[$i]."' >";				
				}

								
				echo"<input type='hidden'   style='width:70px'  name='item_vat[$i]' id='item_vat[$i]' value='".$item_vat[$i]."'  > </span>";					
				echo"<input type='hidden'   style='width:70px'  name='i_unitcoef[$i]' id='i_unitcoef[$i]' value='".$i_unitcoef[$i]."'  > </span>";					
				
				if($Module_Heatno == 1)
					echo"<td align='center' ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:85px'  name='mreqdtheatno[$i]' id='mreqdtheatno[$i]' value='".$mreqdtheatno[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" >  </span>
					<label><span><img src='img/openlist.png' title='Select Heat No' 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='mreqdtheatno[$i]' id='mreqdtheatno[$i]' value=''> </span>";					
				
				if ($Module_ProjectDt == 1)	
					echo"<td ><span class='style4'><input type='text'   $KeyDown  class='roundedtext_amortization_medium'    style='width:90px'  name='mreqdtprojectcode[$i]' id='mreqdtprojectcode[$i]' value='".$mreqdtprojectcode[$i]."'   onchange=\"setprojectcode(this.value,'mreqdtprojectcode[$i]','imgprojectbtn[$i]');SetModRecord('ModRec_G1','$i');\" > </span>
					<img src='img/scroll-down-1.png' title=' Select Project ' id='imgprojectbtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistProject('project','mreqdtprojectcode[$i]','800','500',3) \" />			
					</td>";
				else echo"<input type='hidden' style='width:70px'  name='mreqdtprojectcode[$i]' id='mreqdtprojectcode[$i]' value='".$mreqdtprojectcode[$i]."'  style='width:60px'> </span>"; 
				
				if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1)
					echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:90px'  name='mreqdtcostcentercode[$i]' id='mreqdtcostcentercode[$i]' value='".$mreqdtcostcentercode[$i]."'    onchange=\"setcostcentercode(this.value,'mreqdtcostcentercode[$i]','imgcostcenterbtn[$i]');SetModRecord('ModRec_G1','$i')\" > 
					<img src='img/scroll-down-1.png' title=' Select Costcenter ' id='imgcostcenterbtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistCostcenter('costcenter','mreqdtcostcentercode[$i]','800','500',3) \" />
					</span></td>";
				else	echo"<input type='hidden'    name='mreqdtcostcentercode[$i]' id='mreqdtcostcentercode[$i]' value='".$mreqdtcostcentercode[$i]."' > ";
			
			echo"<td align='center'><span class='style4'><input type='text' name='mreqdt_RequiredDate[$i]' id='mreqdt_RequiredDate[$i]' value='$mreqdt_RequiredDate[$i]' maxlength='10' onchange=\"SetModRecord('ModRec_G1','$i');\" class='roundedtext_amortization_medium date' style='font-size:12px; width:80px; height:20px;'  $KeyDown readonly ></span></td>";
			echo"<td ><span class='style4'><input type='text'    style='width:195px'  $KeyDown   class='roundedtext_amortization_medium'   name='mreqdt_Remark[$i]' id='mreqdt_Remark[$i]' value='".$mreqdt_Remark[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" > </span></td>";
					
			
			
			
			echo"<td><img src='img/confirm.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitMReqDt[$i]' title='Save' onclick=\"submitMReqDt('$txtMreqDTId[$i]','$txtPreqId','$i','e','$PurchaseTTC','$FIPurchaseCategory','$filepath')\"></td>";
			echo"<input type='hidden'  name='txtMreqDTId[$i]' id='txtMreqDTId[$i]' value='".$txtMreqDTId[$i]."' >";
			echo"</tr>";
			
			
			$i+=1;
		}
		
		$prei = $i-1;
		if ($warehousecode[$prei] !='')
			$warehousecode[$i] = $warehousecode[$prei];
		else
		if (empty($warehousecode[$i])) { 
			if(!empty($_SESSION['prqstdefaultwarehouse'] ))
				$warehousecode[$i] = $_SESSION['prqstdefaultwarehouse'];
			else if(!empty($_SESSION['prqstsetupdefaultWareHouse'] ))
					$warehousecode[$i] = $_SESSION['prqstsetupdefaultWareHouse'] ;
			}
			
	$k=1;
		$morelines = 1;
		//echo $morelines;
		while ($k <= $morelines) {
			$recno = $i+1;
			if ($k==$morelines)
				$mode = 'i';
			else
				$mode = 'e';			
			
			$KeyDown   = 'onkeydown="return dokeypurchaserequest(event,this,'.$i.',\''.$columnslist.'\',\'MReqDt\');"';

			echo"<tr height='30' id='CurRec$i' class='$bgcolor table-focus-g1'>";
			echo"<td align=center><img src='img/undo-1.png' width=20 height=20 onmouseover=\"style.cursor='pointer'\" name='' title='Clear' onclick=\"clearprequestdt('$i','$PurchaseTTC','$FIPurchaseCategory')\"></td>";
			
			if ($Module_Pack == 1)
				echo"<td align='center'><span class='style4'><input type='text'   class='roundedtext_amortization_medium'   readonly   $KeyDown  name='itemcodepacked[$i]' id='itemcodepacked[$i]' value='".$itemcodepacked[$i]."' style='width:115px'> </span></td>";
			else
				echo"<input type='hidden'  name='itemcodepacked[$i]' id='itemcodepacked[$i]' value='".$itemcodepacked[$i]."'>";
			
			
			echo"<td ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'   onchange=\"setitemcode(this.value,'itemcode[$i]','itemdescription[$i]','item_vat[$i]','itemunitsalesdesc[$i]','itemunitpurchasedesc[$i]','i_unitcoef[$i]','','mreqdtitemcodeimage[$i]','mreqdtitemcodeimage1[$i]',1,7);SetModRecord('ModRec_G1','$i');\" onblur=\"FillDetail('mreqdtprojectcode[$i]','mreqdtcostcentercode[$i]')\"   name='itemcode[$i]' id='itemcode[$i]' value='".$itemcode[$i]."' style='width:125px'></span>
				<img src='img/scroll-down-1.png' width='20' height='20' id='mreqdtitemcodeimage[$i]' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('itemcode','itemcode[$i]','itemdescription[$i]','item_vat[$i]','itemunitsalesdesc[$i]','itemunitpurchasedesc[$i]','i_unitcoef[$i]','800','500');FillDetail('mreqdtprojectcode[$i]','mreqdtcostcentercode[$i]')\">
					</td>";
			
			echo"<td align='center'><span class='style4'><input type='text'   class='roundedtext_amortization_mediumlarge'    $KeyDown     onchange=\"setitemcode(this.value,'itemcode[$i]','itemdescription[$i]','item_vat[$i]','itemunitsalesdesc[$i]','itemunitpurchasedesc[$i]','i_unitcoef[$i]','','mreqdtitemcodeimage[$i]','mreqdtitemcodeimage1[$i]',2,7);SetModRecord('ModRec_G1','$i')\"     name='itemdescription[$i]' id='itemdescription[$i]' value='".$itemdescription[$i]."' style='width:195px'> </span>
			<img src='img/scroll-down-1.png' width='20' hidden height='20' id='mreqdtitemcodeimage1[$i]' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage1('itemcode','itemcode[$i]','itemdescription[$i]','item_vat[$i]','itemunitsalesdesc[$i]','itemunitpurchasedesc[$i]','i_unitcoef[$i]','800','500')\">
			</td>";					
			echo"<td align='center'><span class='style4'><input type='text'   class='roundedtext_amortization_mediumlarge'    $KeyDown    name='mreqdtitemdescription[$i]' id='mreqdtitemdescription[$i]' value='".$mreqdtitemdescription[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');FillDetail('mreqdtprojectcode[$i]','mreqdtcostcentercode[$i]');CheckItemCode(this,'$i')\" style='width:135px'> </span></td>";					
		
			
			
			echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='warehousecode[$i]' id='warehousecode[$i]' value='".$warehousecode[$i]."'   onchange=\"setwarehousecode(this.value,'warehousecode[$i]','imgwarehousebtn[$i]');SetModRecord('ModRec_G1','$i')\"  > </span>
			<img src='img/scroll-down-1.png' title=' Select Warehouse ' id='imgwarehousebtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistWarehouse('warehousecode','warehousecode[$i]','800','500') \" />
			</td>";
			
			//if ($Module_DoubleUnit == 1)
				echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='itemunitsalesdesc[$i]' id='itemunitsalesdesc[$i]' value='".$itemunitsalesdesc[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" readonly onfocus='checkstatus($i)' > </span></td>";
			//else
				//echo"<input type='hidden'   class='roundedtext_amortization_medium'   style='width:70px'  name='itemunitsalesdesc[$i]' id='itemunitsalesdesc[$i]' value='".$itemunitsalesdesc[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" readonly style='width:60px'> </span>";
				
				
				echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtOquantity[$i]' id='mreqdtOquantity[$i]' value='".$mreqdtOquantity[$i]."'  maxlength='20' onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  onchange=\"CalcQty2($i,$Module_Unit1Method,1);SetModRecord('ModRec_G1','$i')\"  > </span></td>";
				
				if($Module_CancelledQty==1) {
					echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:68px'  name='mreqdtCquantity[$i]' id='mreqdtCquantity[$i]' value='".$mreqdtCquantity[$i]."'  maxlength='20' onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  onchange=\"CalcQty2($i,$Module_Unit1Method,1);SetModRecord('ModRec_G1','$i')\"  > </span></td>";
					echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:68px'  name='mreqdtquantity[$i]' id='mreqdtquantity[$i]' value='".$mreqdtquantity[$i]."'  maxlength='20' readonly onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  onchange=\"CalcQty2($i,$Module_Unit1Method,1);SetModRecord('ModRec_G1','$i')\"  > </span></td>";
				} else {
					$mreqdtCquantity[$i] = 0;
					echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'   name='mreqdtCquantity[$i]' id='mreqdtCquantity[$i]' value='".$mreqdtCquantity[$i]."'  maxlength='20' onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  onchange=\"CalcQty2($i,$Module_Unit1Method,1);SetModRecord('ModRec_G1','$i')\"   > </span>";
					echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'   name='mreqdtquantity[$i]' id='mreqdtquantity[$i]' value='".$mreqdtquantity[$i]."'  maxlength='20' readonly onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  onchange=\"CalcQty2($i,$Module_Unit1Method,1);SetModRecord('ModRec_G1','$i')\"   > </span>";
				
				}
		
		
				if ($Module_DoubleUnit == 1) { 
					echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='itemunitpurchasedesc[$i]' id='itemunitpurchasedesc[$i]' value='".$itemunitpurchasedesc[$i]."'  readonly  style='width:60px'> </span></td>";
					echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='itemunit2qty[$i]' id='itemunit2qty[$i]' value='".$itemunit2qty[$i]."'   maxlength='20' onchange=\"CalcQty2($i,$Module_Unit1Method,2);SetModRecord('ModRec_G1','$i')\"  > </span></td>";
				}
				else {
					echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='itemunitpurchasedesc[$i]' id='itemunitpurchasedesc[$i]' value='".$itemunitpurchasedesc[$i]."' > </span>";
					echo"<span class='style4'><input type='hidden'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='itemunit2qty[$i]' id='itemunit2qty[$i]' value='".$itemunit2qty[$i]."'   maxlength='20' onchange=\"CalcQty2($i,$Module_Unit1Method,2);SetModRecord('ModRec_G1','$i')\"  > </span>";
				}
				
				if ($Module_PurchaseRequestPrice==1) {
				if ($PurchaseTTC == 1) 
					echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtpricettc[$i]' id='mreqdtpricettc[$i]' value='".$mreqdtpricettc[$i]."'  onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  onchange=\"SetModRecord('ModRec_G1','$i');\" style='width:60px'> </span></td>";
				else
					echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtprice[$i]' id='mreqdtprice[$i]' value='".$mreqdtprice[$i]."'   maxlength='20' onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'  onchange=\"SetModRecord('ModRec_G1','$i');\" style='width:60px'> </span></td>";


				echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtdiscount[$i]' id='mreqdtdiscount[$i]' value='".$mreqdtdiscount[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" onBlur='CalcPorDtTotal($i,$DecimalBase,$PurchaseTTC);'   style='width:60px'> </span></td>";					

				
				if ($PurchaseTTC == 1) 
					echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdttotalttc[$i]' id='mreqdttotalttc[$i]' value='".$mreqdttotalttc[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" style='width:60px'> </span></td>";
				else
					echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdttotal[$i]' id='mreqdttotal[$i]' value='".$mreqdttotal[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" style='width:60px'> </span></td>";
				}
				else {
				if ($PurchaseTTC == 1) 
					echo"<input type='hidden'      class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtpricettc[$i]' id='mreqdtpricettc[$i]' value='".$mreqdtpricettc[$i]."' > ";
				else
					echo"<input type='hidden'    class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtprice[$i]' id='mreqdtprice[$i]' value='".$mreqdtprice[$i]."'   maxlength='20' >";


				echo"<input type='hidden'     class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdtdiscount[$i]' id='mreqdtdiscount[$i]' value='".$mreqdtdiscount[$i]."' >";					

				
				if ($PurchaseTTC == 1) 
					echo"<input type='hidden'     class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdttotalttc[$i]' id='mreqdttotalttc[$i]' value='".$mreqdttotalttc[$i]."' >";
				else
					echo"<input type='hidden'      class='roundedtext_amortization_medium'   style='width:70px'  name='mreqdttotal[$i]' id='mreqdttotal[$i]' value='".$mreqdttotal[$i]."' >";				
				}


				
			echo"<input type='hidden'   style='width:70px'  name='item_vat[$i]' id='item_vat[$i]' value='".$item_vat[$i]."' > </span>";					
			echo"<input type='hidden'   style='width:70px'  name='i_unitcoef[$i]' id='i_unitcoef[$i]' value='".$i_unitcoef[$i]."' > </span>";					
				
					$ii = $i-1;
					
					if ($mreqdtprojectcode[$ii]!='')
						$mreqdtprojectcode[$i] = $mreqdtprojectcode[$ii];
						
					if ($mreqdtcostcentercode[$ii]!='')
						$mreqdtcostcentercode[$i] = $mreqdtcostcentercode[$ii];
						
					
					
					if ($mreqdtprojectcode[$i]=='')
						$mreqdtprojectcode[$i] = $_SESSION['prqstdefaultproject'];

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

				if ($Module_CostCenterDt == 1 && $ShowCostCentLayout == 1)
					echo"<td  align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:90px'  name='mreqdtcostcentercode[$i]' id='mreqdtcostcentercode[$i]' value='".$mreqdtcostcentercode[$i]."'    onchange=\"setcostcentercode(this.value,'mreqdtcostcentercode[$i]','imgcostcenterbtn[$i]');SetModRecord('ModRec_G1','$i')\"  > 
					<img src='img/scroll-down-1.png' title=' Select Costcenter ' id='imgcostcenterbtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistCostcenter('costcenter','mreqdtcostcentercode[$i]','800','500',3) \" />
					</span></td>";
			
			
				echo"<td align='center'><span class='style4'><input type='text' name='mreqdt_RequiredDate[$i]' id='mreqdt_RequiredDate[$i]' value='$mreqdt_RequiredDate[$i]' maxlength='10' onchange=\"SetModRecord('ModRec_G1','$i');\" class='roundedtext_amortization_medium date' style='font-size:12px; width:80px; height:20px;'  $KeyDown readonly >
			 </span></td>";
			
			echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium' style='width:190px'   name='mreqdt_Remark[$i]' id='mreqdt_Remark[$i]' value='".$mreqdt_Remark[$i]."'  onchange=\"SetModRecord('ModRec_G1','$i');\"> </span></td>";
					
			echo"<td><img src='img/confirm.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitMReqDt[$i]' title='Save' onclick=\"return submitMReqDt('$txtMreqDTId[$i]','$txtPreqId','$i','i','$PurchaseTTC','$FIPurchaseCategory','$filepath');\"></td>";
			echo"<input type='hidden'  name='txtMreqDTId[$i]' id='txtMreqDTId[$i]' value='".$txtMreqDTId[$i]."' >";
			echo"</tr>";
		$i+=1;
		$k+=1;
		}	
	
	echo"</table></div>";
	

	

}

function ShowMReqDtTotalsGrid($connection,$form,$txtMReqId,$PurchaseTTC,$VatApplied,$Setup_VatPercentage,$DecimalBase){


	$query = " Select MReq_id, MReq_reference, Date_Format(MReq_date,'%d/%m/%Y') As MReqdate, ".
	         " Date_Format(MReq_RequestDate,'%d/%m/%Y') As RequestDate, MReq_RequestBy, materialreq.Currency_code, ".
			 " Null, Null, Null, ".
			 " Null, Null, MReq_remark, materialreq.Project_Code, materialreq.Costcent_code,  ".
			 " null , ifNull(MReq_Import,0), ifNull(MReq_Status,'A'), ".
			 " Status_Remark, MReq_DeliveryPlace, MReq_DeliveryContact,  ".
			 " Round(MReq_Taxable, ".$DecimalBase."), Round(MReq_NoneTaxable, ".$DecimalBase."), ".
			 " Round(MReq_Total, ".$DecimalBase.") As GrossTotal, ".
			 " Round(MReq_DiscountPer, ".$DecimalBase."), Round(MReq_DiscountAmount, ".$DecimalBase."),  ".
			 " ifNull(MReq_VATChckbx,0) As MReq_VATChckbx, Round(MReq_Vat, ".$DecimalBase.") As MReq_Vat, ".
			 " Round((IfNull(MReq_Total,0) + IfNull(MReq_Vat,0) - IfNull(MReq_DiscountAmount,0) + (ifNull(MReq_Tax1,0) + ifNull(MReq_Tax2,0) + ifNull(MReq_Tax3,0) + ifNull(MReq_Tax4,0) + ifNull(MReq_Tax5,0))), ".$DecimalBase.") As Prequest_NetTotal,  ".
			 " Round((ifNull(MReq_Tax1,0) + ifNull(MReq_Tax2,0) + ifNull(MReq_Tax3,0) + ifNull(MReq_Tax4,0) + ifNull(MReq_Tax5,0)), ".$DecimalBase.") As TotalTaxes  ".
			 " From Temp_materialreq As materialreq ".
	         " Where MReq_id = '".$txtMReqId."'";
			 
			 
			 
	//echo $query;
	$result=mysql_query($query,$connection) or die(mysql_error());
    $rows=mysql_fetch_array($result);
	
	$txtMReqId       = $rows[0];
	$txtRef         = $rows[1];
	$txtDate        = $rows[2];
	$txtRequestDate = $rows[3];
	$txtRequestBy   = $rows[4];
	$txtCurr        = $rows[5];
	
	
	$txtRemark          = $rows[11];
	$txtProjectCode     = $rows[12];
	$txtCostCentCode    = $rows[13];
	
	$txtMReqCategory     = $rows[15];
	$txtMReqStatus       = $rows[16];
	$txtStatusRemark    = $rows[17];
	$txtDeliveryPlace   = $rows[18];
	$txtDeliveryContact = $rows[19];
	
	$txtReqTaxable     = $rows[20];
	$txtReqNoneTaxable = $rows[21];
	$txtReqGrossTotal  = $rows[22];
	$txtReqDiscount    = $rows[23];
	$txtReqDiscountAmt = $rows[24];
	$ChkReqVat         = $rows[25];
	$txtReqVat         = $rows[26];
	$txtReqNetTotal    = $rows[27];
	$txtReqTotalTaxes  = $rows[28];
	
	
	
print <<<HERE
<table border='0' style='table-layout:fixed;width:100px' cellspacing=0>
<tr>
		<td id='total-top' style='width:240px;height:12px;'></td>
		</tr>
		<tr><td id='total-content' style='width:240px;height:12px;'>
<table border='0' style='table-layout:fixed;' cellspacing=0 >
			<col width=90>
			<col width=140>
			
			<tr  height='20'>
			 <td valign='center' align='right' ><span class='style10'>Taxable</span>&nbsp;</td> 
			 <td align='left'><input type='text' name='txtReqTaxable' value='$txtReqTaxable' maxlength='20' readonly  style='text-align:right; width:120px; height=20px;background:#C6D4E5;'></td>
		  </tr>
		  <tr   height='25'>
			 <td valign='center' align='right' ><span class='style10'>None Taxable</span>&nbsp;</td> 
 			 <td align='left'><input type='text' name='txtReqNoneTaxable' value='$txtReqNoneTaxable' maxlength='20' readonly  style='text-align:right; width:120px; height=20px;background:#C6D4E5;'></td>

		  </tr>
		  <tr   height='20'>
			 <td valign='center' align='right' ><span class='style10'>Gross Total</span>&nbsp;</td> 
			 <td align='left'><input type='text' name='txtReqGrossTotal' value='$txtReqGrossTotal' maxlength='20' readonly  style='text-align:right; width:120px; height=20px;background:#C6D4E5;'></td>
		  </tr>
		  <tr  height='20'>
			 <td valign='center' align='right' ><span class='style10'>Discount</span>&nbsp;</td> 
			 <td align='left'><input type='text' name='txtReqDiscount' value='$txtReqDiscount' maxlength='5'  style='text-align:right; width:40px; height=18px;' onKeyup='CalcPorDiscount(1, $DecimalBase,$VatApplied,$Setup_VatPercentage);' ><span class='style10'>%</span>
			                  <input type='text' name='txtReqDiscountAmt' value='$txtReqDiscountAmt' maxlength='20' style='text-align:right; width:64px; height=18px;' onKeyup='CalcPorDiscount(2, $DecimalBase,$VatApplied,$Setup_VatPercentage);' ></td>
		  </tr>

HERE;

echo "    <tr   height='20'>
			 <td valign='center' align='right' ><input type='checkbox' name='ChkReqVat' id='ChkReqVat' value='1' onClick='SetPorVat($DecimalBase,$VatApplied,$Setup_VatPercentage,$PurchaseTTC);'   "; 
	          if($ChkReqVat==1) echo "checked />"; else echo " />";   
echo "   	 <span class='style10'>VAT $Setup_VatPercentage%</span>&nbsp;</td> 
			 <td align='left'>
			   <input type='text' name='txtReqVat' value='$txtReqVat' maxlength='20'  maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' >
			 </td>";
echo "  </tr>";
		  
	if ($Module_AdditionalTaxes == 1) {
		echo"<tr  height='20'>
			   <td valign='center' align='right' ><span class='style10'>Taxes</span>&nbsp;</td> 
			   <td align='left'><input type='text' name='txtReqTotalTaxes' value='$txtReqTotalTaxes' maxlength='20' readonly  maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;'></td>
		     </tr>";
	} else {
		echo "<input type='hidden' name='txtReqTotalTaxes' value='$txtReqTotalTaxes'>";
	}

echo"     <tr   height='25'>
			 <td valign='center' align='right' ><span class='style10'>Net Total</span>&nbsp;</td> 
			 <td align='left'><input type='text' name='txtReqNetTotal' value='$txtReqNetTotal' maxlength='20' readonly  maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;";
			 
			if($txtReqNetTotal<0) echo " color:#FF0000;";
			 
			 
			 echo"'></td>
		  </tr>
		  
		  </table></td>
				</tr><tr>
					<td id='total-bottom' style='width:240px;height:12px;'></td>
				</tr></table></td></tr>";


}

?>