<?php

 
session_start();
if($_SESSION['dbName']==""){
	header("location:../index.php");
}
 
include("config.inc.php");
include("function.inc.php");
include("Forms_DataGrid1.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");


//Read From Module Table
$querymodule=" Select ifNull(Module_TransferWithOneWh,0) As Module_TransferWithOneWh,ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter , ifNull(Module_RestrictProjCost,0) As Module_RestrictProjCost, ifNull(Module_RestrictCost,0) As Module_RestrictCost , module_serialno,ifNull(Module_NegativeQuantity,0) As Module_NegativeQuantity ,Module_TransferSorder  
				,ifNull(Module_DoubleUnit,0) As Module_DoubleUnit ,Module_TransferRequestPrice as Module_TransferRequestPrice, ifnull(Module_Heatno,0) as Module_Heatno , ifnull(Module_PostToJournal,0) as Module_PostToJournal 
				From Module ";
				

			//	echo $querymodule;exit;
	
				
$resultmodule=mysql_query($querymodule,$connection) or die($query." ".mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$ModuleProject=$Module_Project;
$ModuleCostCenter=$Module_CostCenter;

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


if ($transferrequest_id!='')
{		
	//echo $transferRequest_id;exit;
	$query="select Transferrequest_WarehouseTo from transferrequest where transferrequest_id = '".$transferrequest_id."'";
	$result=mysql_query($query) or die($query." ".mysql_error());
	$resultcheckwarehouse=mysql_fetch_array($result);
	$previousWarehouse = $resultcheckwarehouse[0];
	//fecho $previousWarehouse;
}	
	


$querylog="SELECT  FI_SalesVAT ,FI_RENTINVOICE as loginaccess, ifnull(FI_RENTINVOICEApp,0) as FI_RENTINVOICEApp, ifNull(Login_negativeQty,0) As Login_negativeQty,ifnull(Login_FastPrint,0) as Login_FastPrint , ifNull(ModifyVAT,0) As ModifyVAT, ifNull(Login_ModifyDiscount,0) As Login_ModifyDiscount from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
	$resultlog=mysql_query($querylog,$connection) or die($query." ".mysql_error());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}
 
	
if ($loginaccess=='' or $loginaccess==0 )
	header("location:menu.php");
	


$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($query." ".mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}


$querySalesSetup="Select ifNull(ShowCostCentLayout,0) As ShowCostCentLayout, ifnull(showBatch,0) showBatch From TransferSetup";
$resultSalesSetup=mysql_query($querySalesSetup,$connection) or die($query." ".mysql_error());
while($rowSalesSetup=mysql_fetch_array($resultSalesSetup)){
	extract($rowSalesSetup);
}


//FI_ProductionDel  FI_TransferMod FI_TransferApp
$querylog=" select ifNull(FI_TransferRequest,0) As FI_TransferRequest ,login_belongstogrp ,ifNull(Fi_Transferapp,0) As FI_TransferIns,ifNull(Fi_RmTransferapp,0) As FI_RmTransferIns, language".
          " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die($query." ".mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

$TrInsMode = '';
$TransType = 'Tr';

if ($FI_TransferIns == 0 and $TransType=='Tr')
	$TrInsMode = ' disabled ';
else
if ($FI_RmTransferIns == 0 and $TransType=='Rm')
	$TrInsMode = ' disabled ';

	
$query="SELECT costcent_code,costcent_name FROM costcent order by costcent_code";
$costcenterresult=mysql_query($query,$connection) or die($query." ".mysql_error());



// default project
$query="select project_code from ".$_SESSION['dbLabel'].".loginstk 
where default_project = 1 
and user_account='".$_SESSION['useraccount']."'";
//echo $query;
$defaultproject=mysql_query($query,$connection) or die($query." ".mysql_error());
$rows = mysql_fetch_row($defaultproject);
				
							$defaultprojectcode = $rows[0];
							
							if ($fromproject=='' && $Module_Project == 1)
								$fromproject = $defaultprojectcode;

$sqlproject = "select project_code,project_name
									from project
									where project_code in 
			(select project_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')
									";
							$resultdefaultproject=mysql_query($sqlproject,$connection) or die($query." ".mysql_error());
						//	echo $sqlproject;
$sqlproject1 = "select project_code,project_name
									from project
									where project_code in 
			(select project_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')
									";
			
		if(mysql_num_rows($resultdefaultproject)=="0")
			{
				$sqlproject = "select project_code,project_name
									from project
									";							
				$sqlproject1 = "select project_code,project_name
									from project
									";	
			}									
			else
			if (($edit=='yes' or sref!='') and $fromprojectedit!='')
			{
				$sqlproject = "select '".$fromprojectedit."' , '".$fromprojectnameedit."' from dual union " . $sqlproject;
				$sqlproject1 = "select '".$toprojectedit."' , '".$toprojectnameedit."' from dual union " . $sqlproject1;
			
			}
			//echo $sqlproject;
			$sqlproject = $sqlproject . " order by project_code ";
			$sqlproject1 = $sqlproject1 . " order by project_code ";
$projectresultfrom=mysql_query($sqlproject,$connection) or die($query." ".mysql_error());
$projectresultto=mysql_query($sqlproject1,$connection) or die($query." ".mysql_error());





//warehouse
$query="select warehouse_code from ".$_SESSION['dbLabel'].".loginstk where default_warehouse = 1 
and user_account='".$_SESSION['useraccount']."'";
//echo $query; exit;
							$defaultwarehouse=mysql_query($query,$connection) or die($query." ".mysql_error());
							$rows = mysql_fetch_row($defaultwarehouse);
							$defaultwarehousecode = $rows[0];
							
							//echo $actionmode;
if ($fromwarehouse=='' and $actionmode!='view')
	$fromwarehouse = $defaultwarehousecode;
			

$sql = "select warehouse_code,warehouse_name
		from warehouse
		where warehouse_code in (select warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')";
$resultdefaultwarehouse=mysql_query($sql,$connection) or die($query." ".mysql_error());
//echo $sql;
				
$sql1 = "select warehouse_code,warehouse_name
		from warehouse
		where warehouse_code in (select warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')";
$resultdefaultwarehouse=mysql_query($sql,$connection) or die($query." ".mysql_error());
				
if(mysql_num_rows($resultdefaultwarehouse)=="0")
{
	$sql = "select warehouse_code,warehouse_name
						from warehouse";
	$sql1 = "select warehouse_code,warehouse_name
						from warehouse";										
}	
else
if (($edit=='yes' or sref!='') and $fromwarehouseedit!=''){
	$sql = "select '".$fromwarehouseedit."' , '".$fromwarehousenameedit."' from dual union " . $sql;
	$sql1 = "select '".$towarehouseedit."' , '".$towarehousenameedit."' from dual union " . $sql1;
}
//$resultdefaultwarehouse=mysql_query($sql,$connection) or die(mysql_error());
	//$fromwarehouseedit		
//echo $sql."<br>";
//echo $sql1;
//exit;
$sql = $sql . " order by warehouse_code ";
$sql1 = $sql1 . " order by warehouse_code ";

$warehouseresultfrom=mysql_query($sql,$connection) or die($query." ".mysql_error());
$warehouseresultto=mysql_query($sql1,$connection) or die($query." ".mysql_error());
// end of warehouse

$actionmode = $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}   
$mainaction = $_POST["mainaction"]; if ($mainaction == ""){$mainaction = $_GET["mainaction"];}   
//$txtPurId = $_POST["txtPurId"]; if ($txtPurId == ""){$txtPurId = $_GET["txtPurId"];}    

if (empty($mainaction))
	$mainaction = 'insert';

	
if ($mainaction=='insert'){
		
			$query = "select TransferRequest_WarehouseFrom,TransferRequest_WarehouseTo
						from temp_transferRequest
						where 
						transferRequest_id = '".$transferrequest_id."'";
			
			$result=mysql_query($query,$connection) or die($query." ".mysql_error());
			$row=mysql_fetch_array($result);
				if ($fromwarehouse=='')
					$fromwarehouse = $row[0];
				if ($towarehouse=='')
					$towarehouse = $row[1];
}

	
$message = ereg_replace("'"," ",$message);


if (empty($transferrequest_date))	
	$transferrequest_date = displayToday();
	
	//$transfer_date = date();

	/*
	if ($actionmode=='' and $transfer_reference=='')
		$actionmode = 'insert';
	*/	

if ($actionmode == "post" && $transferrequest_id != '')	
	{
		$PreviewButtons = 'disabled';
	}
else
	{
		$PreviewButtons = 'enabled';
	}

if ((($actionmode == "submitrecord" || $actionmode == "edit" || $actionmode == "editdt" || $actionmode == "deletedt" || $actionmode == "post") && $transferrequest_id != '') 
or ($actionmode == "post" && $transferrequest_id != ''))
{
	// Read From Temp Tables For Selected Record				 

		$query = "select Transferrequest_Id,date_format(Transferrequest_Date,'%d/%m/%Y') as Transferrequest_Date,Transferrequest_Remark,Project_code1,Project_code2,temp_transferrequest.Costcenter_Code,
					Driver_Name,Vehicle_No,Transferrequest_WarehouseFrom,Transferrequest_WarehouseTo,transferrequest_reference,ToCostcenter_Code,Document_RefNo ,  DATE_FORMAT(datefrom,'%d/%m/%Y'), 
					DATE_FORMAT(dateto, '%d/%m/%Y'), client_code as clcode  , ledger_name  as clientname,currencycode  
					, Journal.Journal_ID, Journal.Journal_folio, Journal.Journal_refgovernment  from temp_transferrequest 
					left join clients on clients.ledger_number = client_code
					Left Join Journal on temp_transferrequest.Journal_id = Journal.Journal_ID
					where transferrequest_id = '".$transferrequest_id."'";
					
		if ($actionmode == "post" && $transferrequest_id != '')			
			{
					$query = "select Transferrequest_Id,date_format(Transferrequest_Date,'%d/%m/%Y'),Transferrequest_Remark,Project_code1,Project_code2,transferrequest.Costcenter_Code,
					Driver_Name,Vehicle_No,Transferrequest_WarehouseFrom,Transferrequest_WarehouseTo,transferrequest_reference,ToCostcenter_Code,Document_RefNo
					,  DATE_FORMAT(datefrom, '%d/%m/%Y'), DATE_FORMAT(dateto, '%d/%m/%Y') 
					,client_code as clcode  , ledger_name  as clientname  ,currencycode  , Journal.Journal_ID, Journal.Journal_folio, Journal.Journal_refgovernment 
					from transferrequest
					left join clients on clients.ledger_number = client_code
					 Left Join Journal on transferrequest.Journal_id = Journal.Journal_ID
					 
					where transferrequest_id = '".$transferrequest_id."'";
					
				//	echo $query;exit;
			}
			// echo $query;	exit;		
		$result=mysql_query($query,$connection) or die($query." ".mysql_error());
		$rows=mysql_fetch_array($result);
		extract($rows);
		
			$transferrequest_date = $rows[1];
			$fromproject = $rows[3];
			$toproject = $rows[4];
			$costcent = $rows[5];
			$tocostcent = $rows[11];
			$documentrefno = $rows[12];
			
			$_POST['inputfromwarehouse'] = $rows[8];
			$_POST['inputtowarehouse'] = $rows[9];
			$driver_name = $rows[6];
			
				$txtJvFolio	      =  "$Journal_folio"; //$rows[28];  /* Journal.Journal_ID, Journal.Journal_folio, Journal.Journal_refgovernment  */
	            $txtJvRef 	      =  "$Journal_refgovernment";   // $rows[29];
	
	
			
			$_POST['vehicle_no'] = $rows[7];
			
			$transferrequest_remark = $rows[2];
			$transferrequest_reference = $rows[10];
			$txtDatefrom = $rows[13];
			$txtDateto = $rows[14];
		    $txtClientCode = $clcode;
			$txtClientName = $clientname;
			$txtCurr = $currencycode;
		}

//Search/Cancel Mode	


if ($actionmode == "cancel" && $transferrequest_id != '') {
	$query = "DELETE FROM Temp_TransferrequestDt ".
			" WHERE transferrequest_id = ".$transferrequest_id;
	if (!updateData($connection, $query, true))
      	$message  = mysql_error(); 
 
	$query = "DELETE FROM Temp_transferrequest ".
			" WHERE transferrequest_id = ".$transferrequest_id;
	if (!updateData($connection, $query, true))
		$message  = mysql_error();   
	
	$transferrequest_id = '';
}








$querylang="select language, Reference, Project, Warehouse, Date as date_label, from_date, to_date, 
			Driver_Name as driver_label, Vehicle_No as vehicle_label, Remark,
			 Item, Description, Packaging_Nbr, nb_of_unit, qty, Unit, qtyexist, batchnb, heatnb,
			 save, cancel, clear_page, pending, search
	from ".$_SESSION['dbLabel'].".transferrequest_label where 
			language='$language'";

//echo $querylang;
$resultlang=mysql_query($querylang,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlang)){
		extract($rows);
		
	}

print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 


<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">



<script type="text/javascript" language="javascript">

function filltheform()
{
	 
	document.getElementsByName('transferrequest_date')[0].value = '05/09/2018';
	
	document.getElementsByName('fromproject')[0].value = 'NA';
	document.getElementsByName('toproject')[0].value = 'NA';
	document.getElementsByName('costcent')[0].value = 'test';
	document.getElementsByName('tocostcent')[0].value = 'test';
	document.getElementsByName('inputfromwarehouse')[0].value = 'Main';
	document.getElementsByName('inputtowarehouse')[0].value = 'rentware';
	document.getElementsByName('txtClientCode')[0].value = '4111000002';
	document.getElementsByName('txtClientName')[0].value = 'elias el khoury';
	document.getElementsByName('txtDatefrom')[0].value = '05/09/2018';
	document.getElementsByName('txtDateto')[0].value = '28/09/2018';
	document.getElementsByName('txtCurr')[0].value = 'GBP';
	document.getElementsByName('driver_name')[0].value = 'Rodolphe';
	document.getElementsByName('vehicle_no')[0].value = 'vehicule 1';
	document.getElementsByName('transferrequest_remark')[0].value = 'asdf';
 
}

function ChangeCurrency() {
	x = document.transferrequest;

	var txtSaDiscountAmt =  x.txtSaDiscountAmt.value;
	var txtSaDiscount = x.txtSaDiscount.value;
	var txtCurr = x.txtCurr.value;
	var base1 = x.base1.value;
	var base2 = x.base2.value;
	var transferrequest_id = x.transferrequest_id.value;
    var transferrequest_date = x.transferrequest_date.value;
	var txtCurr = x.txtCurr.value;
	var vatChk = x.txtSaVatChk.value;

	u = "form_rentinvoice_Actions.php?mode=changecurrency";
	
	u+= "&txtSaDiscountAmt="+txtSaDiscountAmt;
	u+= "&txtSaDiscount="+txtSaDiscount;		
	u+= "&base1=" +base1;
	u+= "&base2=" +base2;
	u+= "&transferrequest_id=" +transferrequest_id;		
	u+= "&txtDate=" +transferrequest_date;
	u+= "&txtCurr=" +txtCurr;
	u+= "&SSaVatChkbx=" +vatChk;
	if(transferrequest_id != ''){
		x.action=u;
		x.submit();
	}
	
	$.get( u, function( data ) {
 
	  console.log(data);
	});


		
		
}


function CalcSaDiscount(option, dec, vatapplied, vatperc, SalesTTC) {
	
	x = document.transferrequest;
	var vmode  = x.mainaction.value;
	x.txtSaDiscount_Temp.value='';
	var vmode1 = x.actionmode.value;
	
	var TaxAmt		 = x.txtSaTaxable.value;
	var GrossTotal	 = x.txtSaGrossTotal.value;
	var DisPer		 = x.txtSaDiscount.value;
	var DisAmt		 = x.txtSaDiscountAmt.value;
	var VatAmt		 = x.txtSaVat.value;
	var TaxesAmt   	 = x.txtSaTotalTaxes.value;
	var TransportAmt = x.txtSaTransportAmt.value;
	var BonusAmt	 = x.txtSaBonusAmt.value;
	
	if ((DisAmt*1 != DisAmt/1 || DisAmt < 0) ) {
		alert('Discount Amount should be a NUMERIC value');
		x.txtSaDiscountAmt.focus();
		return 0;
	}
	else if ((DisPer*1 != DisPer/1 || DisPer < 0) ) {
		alert('Discount Percentage should be a NUMERIC value');
		x.txtSaDiscount.focus();
		return 0;
	}
	
	
	if (TaxAmt == '') 		TaxAmt = 0;
	if (GrossTotal == '') 	GrossTotal = 0;
	if (DisPer == '') 		DisPer = 0;
	if (DisAmt == '') 		DisAmt = 0;
	if (TaxesAmt == '') 	TaxesAmt = 0;
	if (TransportAmt == '') TransportAmt = 0;
	if (BonusAmt == '') 	BonusAmt = 0;
	
	TaxAmt		 = parseFloat(TaxAmt);
	GrossTotal	 = parseFloat(GrossTotal);
	DisPer		 = parseFloat(DisPer);
	DisAmt		 = parseFloat(DisAmt);
	VatAmt		 = parseFloat(VatAmt);
	TaxesAmt	 = parseFloat(TaxesAmt);
	TransportAmt = parseFloat(TransportAmt);
	BonusAmt	 = parseFloat(BonusAmt);

	if (GrossTotal > 0 && (DisPer > 0 || DisAmt > 0)) {
		if (option == 1 )  //Option by Percentage Get The Amount
			x.txtSaDiscountAmt.value = roundNumber((GrossTotal*DisPer/100),dec);
		else if (option == 2 ){  //Option by Amount Get The Per
		    x.txtSaDiscount.value = roundNumber(((DisAmt/GrossTotal)*100),dec);
				
			if (DisAmt > 0)	x.txtSaDiscount.readOnly = true; 
			else  x.txtSaDiscount.readOnly = false;
					
		}
		
		// Calculation of Vat Amount and Net Total
		DisAmt = x.txtSaDiscountAmt.value;
		if (DisAmt == '') DisAmt = 0;
		DisAmt = parseFloat(DisAmt);
		
		// VatAmt = 0;
		// if (SalesTTC == 1) {		
		// 	if (vatapplied == 1 && TaxAmt > 0) {
		// 		VatAmt = roundNumber((((TaxAmt - DisAmt + TransportAmt + BonusAmt) / (1 + vatperc/100)) * (vatperc/100)),dec);
		// 	}
			
		// 	NetTotal = 	roundNumber((GrossTotal + TaxesAmt + TransportAmt + BonusAmt - DisAmt),dec);
			
		// }
		// else {
		// 	if (vatapplied == 1 && TaxAmt > 0) {
		// 		VatAmt = roundNumber(((TaxAmt - ((DisAmt - TransportAmt - BonusAmt)*TaxAmt/GrossTotal))*vatperc/100),dec);
		// 	} 
			
		// 	NetTotal = 	roundNumber((GrossTotal + VatAmt + TaxesAmt + TransportAmt + BonusAmt - DisAmt),dec);
		// }

		VatAmt = roundNumber(((TaxAmt - (DisAmt*TaxAmt/GrossTotal))*vatperc/100),dec);
		NetTotal = 	roundNumber((GrossTotal + VatAmt + TaxesAmt - DisAmt),dec);

		VatAmt 	 = parseFloat(VatAmt);
		NetTotal = parseFloat(NetTotal);
		x.txtSaVat.value      = formatNumber(VatAmt,dec);
		x.txtSaNetTotal.value = formatNumber(NetTotal,dec);
		
	}   
	
}

function CalcNetTotal(dec, vatapplied, vatperc, SalesTTC) {
	x = document.sales;
	
	var TaxAmt       = x.txtSaTaxable.value;
	var GrossTotal   = x.txtSaGrossTotal.value;
	var VatAmt       = x.txtSaVat.value;
	var DisAmt       = x.txtSaDiscountAmt.value;
	var NetTotal     = x.txtSaNetTotal.value;
	var TaxesAmt     = x.txtSaTotalTaxes.value;
	var TransportAmt = x.txtSaTransportAmt.value;
	var BonusAmt 	 = x.txtSaBonusAmt.value;
	
	if (TaxAmt == '')       TaxAmt = 0;
	if (GrossTotal == '')   GrossTotal = 0;
	if (VatAmt == '')       VatAmt = 0;
	if (DisAmt == '')       DisAmt = 0;
	if (NetTotal == '')     NetTotal = 0;
	if (TaxesAmt == '')     TaxesAmt = 0;
	if (TransportAmt == '') TransportAmt = 0;
	if (BonusAmt == '') 	BonusAmt = 0;
	
	TaxAmt 		 = parseFloat(TaxAmt);
	VatAmt 	 	 = parseFloat(VatAmt);
	NetTotal     = parseFloat(NetTotal);
	DisAmt       = parseFloat(DisAmt);
	GrossTotal   = parseFloat(GrossTotal);
	TaxesAmt     = parseFloat(TaxesAmt);
	TransportAmt = parseFloat(TransportAmt);
	BonusAmt 	 = parseFloat(BonusAmt);
	
	VatAmt = 0;
	
	if (SalesTTC == 1) {
		if (vatapplied == 1 && TaxAmt > 0) {
			VatAmt = roundNumber((((TaxAmt - DisAmt + TransportAmt + BonusAmt) / (1 + vatperc/100)) * (vatperc/100)),dec);
		}
			
		NetTotal = GrossTotal + TaxesAmt + TransportAmt + BonusAmt - DisAmt;
	} else {
		if (vatapplied == 1 && TaxAmt > 0) {
			VatAmt = roundNumber(((TaxAmt - ((DisAmt - TransportAmt - BonusAmt)*TaxAmt/GrossTotal))*vatperc/100),dec);
		}
			
		NetTotal = GrossTotal + VatAmt + TaxesAmt + TransportAmt + BonusAmt - DisAmt;
	}
	
	VatAmt 	   = parseFloat(VatAmt);
	NetTotal   = parseFloat(NetTotal);
	x.txtSaVat.value      = formatNumber(VatAmt,dec);	
	x.txtSaNetTotal.value = formatNumber(roundNumber(NetTotal,dec),dec);
	
	

}

function changeChkbx(){
	if(document.getElementById('chkSaVat').value==0)
		document.getElementById('chkSaVat').value=1;
	else
		document.getElementById('chkSaVat').value=0;
}
function SetSaVat(dec, vatapplied, vatperc, ModuleDelivery, SalesTTC) {
	x = document.transferrequest;
	var vmode  = x.mainaction.value;
	var vmode1 = x.actionmode.value;
	
	var TaxAmt       = x.txtSaTaxable.value;
	var GrossTotal   = x.txtSaGrossTotal.value;
	var VatAmt       = x.txtSaVat.value;
	var DisAmt       = x.txtSaDiscountAmt.value;
	var NetTotal     = x.txtSaNetTotal.value;
	var TaxesAmt     = x.txtSaTotalTaxes.value;
	var TransportAmt = x.txtSaTransportAmt.value;
	var BonusAmt     = x.txtSaBonusAmt.value;
	
	if (TaxAmt == '') 		TaxAmt = 0;
	if (GrossTotal == '') 	GrossTotal = 0;
	if (VatAmt == '') 		VatAmt = 0;
	if (DisAmt == '') 		DisAmt = 0;
	if (NetTotal == '') 	NetTotal = 0;
	if (TaxesAmt == '') 	TaxesAmt = 0;
	if (TransportAmt == '') TransportAmt = 0;
	if (BonusAmt == '') 	BonusAmt = 0;
	
	VatAmt		 = parseFloat(VatAmt);
	NetTotal	 = parseFloat(NetTotal);
	DisAmt		 = parseFloat(DisAmt);
	TaxAmt 		 = parseFloat(TaxAmt);
	GrossTotal 	 = parseFloat(GrossTotal);
	TaxesAmt 	 = parseFloat(TaxesAmt);
	TransportAmt = parseFloat(TransportAmt);
	BonusAmt	 = parseFloat(BonusAmt);
	
	if (x.chkSaVat.checked && ModuleDelivery == 0) {
	
		x.txtSaVatChk.value = 1;
		
		// Calculation of Vat Amount and Net Total
		
		VatAmt = 0;
		// if (SalesTTC == 1) {		
		// 	if (vatapplied == 1 && TaxAmt > 0) {
		// 		VatAmt = roundNumber((((TaxAmt - DisAmt + TransportAmt + BonusAmt) / (1 + vatperc/100)) * (vatperc/100)),dec);
		// 	}
			
		// }
		// else {
		// 	if (vatapplied == 1 && TaxAmt > 0) {
		// 		VatAmt = roundNumber(((TaxAmt - ((DisAmt - TransportAmt - BonusAmt)*TaxAmt/GrossTotal))*vatperc/100),dec);
		// 	} 
			
		// 	NetTotal = 	roundNumber((GrossTotal + VatAmt + TaxesAmt + TransportAmt + BonusAmt - DisAmt),dec);
		// }

		VatAmt = roundNumber(((TaxAmt - (DisAmt*TaxAmt/GrossTotal))*vatperc/100),dec);
		NetTotal = 	roundNumber((GrossTotal + VatAmt + TaxesAmt - DisAmt),dec);
		
		VatAmt	   = parseFloat(VatAmt);
		TaxAmt 	   = parseFloat(TaxAmt);
		GrossTotal = parseFloat(GrossTotal);
		NetTotal   = parseFloat(NetTotal);
		
		x.txtSaTaxable.value    = formatNumber(TaxAmt,dec);
		x.txtSaGrossTotal.value = formatNumber(GrossTotal,dec);
		x.txtSaVat.value        = formatNumber(VatAmt,dec);
		x.txtSaNetTotal.value   = formatNumber(NetTotal,dec);
			
		
	}
	else
	{
		x.txtSaVatChk.value = 0;
		
		if (SalesTTC == 1) {
			x.txtSaVat.value      = formatNumber(0,dec);
		}
		else {
			x.txtSaVat.value      = formatNumber(0,dec);
			x.txtSaNetTotal.value = formatNumber(roundNumber((NetTotal - VatAmt),dec),dec);
		}
		
	}  
	

}




function showlistClient(str){
	var vdate, vcode;
	vdate=document.transferrequest.transferrequest_date.value;
	vcode=encodeURIComponent(document.transferrequest.txtClientCode.value);
	vname=encodeURIComponent(document.transferrequest.txtClientName.value);
  
	window.open('List_SorClient.php?frm=500&item='+str+'&PLedger_name='+vname+'&PLedger_number='+vcode+'&TransDate='+vdate,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function FillData(prjct,cst){

var x =  document.transferrequest;
if (document.getElementById(prjct).value == '')
	document.getElementById(prjct).value =  x.inputfromwarehouse.value;
	
if (document.getElementById(cst).value == '')	
	document.getElementById(cst).value = x.inputtowarehouse.value;

}

function showsearchpage1(vtype,vtext1,vtext2,vtext3,vtext4,vtext5,vtext6,vwidth,vheight){

	
	
	
		var text2value = document.getElementById(vtext2).value;
		
		
	win = window.open('List_PurItems.php?PItem_Code=&PItem_Description='+text2value+'&item=6&vtype='+vtype+'&vtext1='+vtext1+'&vtext2='+vtext2+'&vtext3='+vtext3
						+'&vtext4='+vtext4+'&vtext5='+vtext5+'&vtext6='+vtext6
						+'&text1value=', 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();	
	}
	
	
function setprojectcode(val,vfield1,btnname){

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	var data = xmlhttp.responseText.split("[BRK]");
					var resp = data[1];
					
					if (resp==0)
						{
							document.getElementById(btnname).click();
						}
						

				}
		}
  }

xmlhttp.open("GET","Form_rentInvoice_Actions.php?vprojectcode="+val+"&actionmode=checkprojectcode",true);
xmlhttp.send();

}


function setitemcode(val,vfield1,vfield2,vfield3,vfield4,vfield5,vfield6,vgridname,btnname,btnname1,codedesc){

	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			{ 	var data = xmlhttp.responseText.split("[BRK]");
				var resp = data[1];
				
				if (resp==0)
					{
						if (codedesc==1)
							document.getElementById(btnname).click();
						else	
							document.getElementById(btnname1).click();
					}
					else
						{	
							if (codedesc==1)
								document.getElementById(vfield2).value = resp;
							else	
								document.getElementById(vfield1).value = resp;
						}	
					//showsearchpage('itemcode',vfield1,vfield2,vfield3,vfield4,vfield5,vfield6,800,500);

			}
		}
  	}


  	if (codedesc==1)
		xmlhttp.open("GET","Form_rentinvoice_Actions.php?vitemcode="+val+"&codedesc="+codedesc+"&actionmode=checkitemcode",true);
	else if (codedesc==2)
		xmlhttp.open("GET","Form_rentinvoice_Actions.php?vitemdesc="+val+"&codedesc="+codedesc+"&actionmode=checkitemcode",true);  
  
xmlhttp.send();

}


function calcTotal(vprice,vqty,indx){


var vprice = document.getElementById(vprice).value;


var vqty = document.getElementById(vqty).value;

var vamount = 'amount['+indx+']';

if (vprice=='')
	vprice = 0;
	
if (vqty=='')
	vqty = 0;
	
document.getElementById(vamount).value  = parseInt(vprice) * parseInt(vqty);


}

function showlistCostcenter(vtype,vtext1,vwidth,vheight,item){
  	var text1value = document.getElementById(vtext1).value;
	
	if (item=='')
		item = 2;
	win = window.open('List_Costcenter.php?PCostcent_Code='+text1value+'&item='+item+'&vtype='+vtype+'&vtext1='+vtext1
						+'&text1value='+text1value, 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();	

	
}




function setcostcentercode(val,vfield1,btnname){

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	var data = xmlhttp.responseText.split("[BRK]");
					var resp = data[1];
					
					if (resp==0)
						{
							document.getElementById(btnname).click();
						}
						
						//showsearchpage('itemcode',vfield1,vfield2,vfield3,vfield4,vfield5,vfield6,800,500);

				}
		}
  }

xmlhttp.open("GET","form_rentinvoice_actions.php?vcostcentercode="+val+"&actionmode=checkcostcentercode",true);
xmlhttp.send();

}

function clearprequestdt(vrec,VPurchaseTTC,Module_DoubleUnit){


var p_item_code = 'p_item_code['+vrec+']';
var p_item_description = 'p_item_description['+vrec+']';
var p_item_quantity = 'p_item_quantity['+vrec+']';
var Item_Unit2Qty = 'Item_Unit2Qty['+vrec+']';
var p_item_sellingprice1 = 'p_item_sellingprice1['+vrec+']';
var fromwarehouse = 'fromwarehouse['+vrec+']';
var towarehouse = 'towarehouse['+vrec+']';
var p_transferdt_remark = 'p_transferdt_remark['+vrec+']';
var Item_UnitSalesDesc = 'Item_UnitSalesDesc['+vrec+']';
var Item_UnitPurchaseDesc = 'Item_UnitPurchaseDesc['+vrec+']';



document.getElementById(p_item_code).value='';
document.getElementById(p_item_description).value='';
document.getElementById(p_item_quantity).value='';
document.getElementById(Item_Unit2Qty).value='';
document.getElementById(p_item_sellingprice1).value='';
document.getElementById(fromwarehouse).value='';
document.getElementById(towarehouse).value='';
document.getElementById(p_transferdt_remark).value='';
document.getElementById(Item_UnitSalesDesc).value='';
document.getElementById(Item_UnitPurchaseDesc).value='';

}

function submitTransReqDt(TrqstDtId,TrqstId,vrec,vmode,VPurchaseTTC,FIPurchaseCategory,filepath){

var STrqstDtId = TrqstDtId;

	if (vmode=='i')
			{		 
				var vactionmode = 'submitprqstdt';
				var actionmoded = 'i';
			}	
	else {
				var vactionmode = 'editdt';	
				var actionmoded = 'e';
		}
						

var p_item_code = 'p_item_code['+vrec+']';
var p_item_quantity = 'p_item_quantity['+vrec+']';

var p_itemprice = 'p_item_price['+vrec+']';



var p_item_sellingprice1 = 'p_item_sellingprice1['+vrec+']';

var fromwarehouse = 'fromwarehouse['+vrec+']';
var towarehouse = 'towarehouse['+vrec+']';

var p_transferdt_remark = 'p_transferdt_remark['+vrec+']';
var Item_Unit2Qty = 'Item_Unit2Qty['+vrec+']';

var p_transferdt_batchno 	 = 'p_transferdt_batchno['+vrec+']'; 
var p_transferdt_packagingno = 'p_transferdt_packagingno['+vrec+']';
var p_transferdt_nbrunit  	 = 'p_transferdt_nbrunit['+vrec+']';
var p_transferdt_heatno  	 = 'p_transferdt_heatno['+vrec+']';

if (document.getElementById(p_item_sellingprice1).value=='')
	document.getElementById(p_item_sellingprice1).value = '0';
	
var value1 = encodeURIComponent(document.getElementById(p_item_code).value);

	
var value500 = encodeURIComponent(document.getElementById(p_itemprice).value);

var value2 = document.getElementById(p_item_quantity).value;
var value3 = document.getElementById(p_item_sellingprice1).value;
var value4 = document.getElementById(fromwarehouse).value;
var value5 = document.getElementById(towarehouse).value;
var value6 = document.getElementById(p_transferdt_remark).value;
var value17 = document.getElementById(Item_Unit2Qty).value;;

var value19 = document.getElementById(p_transferdt_batchno).value;;
var value20 = document.getElementById(p_transferdt_packagingno).value;;
var value21 = document.getElementById(p_transferdt_nbrunit).value;;

if(document.getElementById(p_transferdt_heatno))
	var value22 = document.getElementById(p_transferdt_heatno).value;
else var value22 = '';

var x =  document.transferrequest;
var value7 = x.transferrequest_date.value;
var value8 = x.fromproject.value;
var value9 = x.costcent.value;
var value10 = x.documentrefno.value;
var value11 = x.toproject.value;
var value12 = x.tocostcent.value;
var value13 = x.inputfromwarehouse.value;
var value14 = x.inputtowarehouse.value;
var value15 = x.driver_name.value;
var value16 = x.transferrequest_remark.value;
var value18 = x.vehicle_no.value;

var value22 = x.txtCurr.value; //currency
var value23 = x.txtDatefrom.value;//date from
var value24 = x.txtDateto.value;//date to
var value25 = x.txtClientCode.value;// client code

var value26 = x.base1.value;
var value27 = x.base2.value;

var Setup_VatPercentage = x.Setup_VatPercentage.value;
var txtSaDiscountAmt = x.txtSaDiscountAmt.value;
var txtSaDiscount = x.txtSaDiscount.value;
var txtSaVatChk = x.txtSaVatChk.value;



		

if (value7=='')
{
			alert("Date is mandatory!");
			x.transferrequest_date.focus();
			return 0;
}
	
	
	
	
if (document.getElementById(p_item_code).value=='')
{
			alert("Item is mandatory!");
			document.getElementById(p_item_code).focus();
return 0;
}


// by rod 


if (document.getElementById('txtCurr').value=='')
{
			alert("Currency is mandatory!");
			document.getElementById('txtCurr').focus();
return 0;
}
 
 


 if (document.getElementById('txtDatefrom').value=='')
{
			alert("From Date is mandatory!");
			document.getElementById('txtDatefrom').focus();
return 0;
}


if (document.getElementById('txtDateto').value=='')
{
			alert("To date is mandatory!");
			document.getElementById('txtDateto').focus();
return 0;
}




 
 


if (document.getElementById(p_item_quantity).value=='')
{
			alert("Quantity is mandatory!");
			document.getElementById(p_item_quantity).focus();
return 0;
}
/*
if (document.getElementById(p_item_sellingprice1).value=='')
{
			alert("Price is mandatory!");
			document.getElementById(p_item_sellingprice1).focus();
return 0;
}
*/





var trqstsid = document.getElementById('transferrequest_id').value;
$("#Loader").addClass("ajaxsaving");

	var SubBtnID = 'imgSubmitPTransReqDt['+vrec+']';
	var SubBtnObj = document.getElementById(SubBtnID);
	$(SubBtnObj).unbind('click');
	$(SubBtnObj).removeAttr("onclick");	

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  

  
xmlhttp.onreadystatechange=function()
  {  
    
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				 		  
					if (vmode=='i')
					{  
					
							var data = xmlhttp.responseText.split("[BRK]");
							
							document.getElementById('transferrequest_id').value = data[1];
							document.getElementById('testdatagrid').innerHTML = data[0];
							
							
					
						//document.transferrequest.mainaction.value='edit';
						document.transferrequest.actionmode.value='edit';
					
						if (trqstsid==''){				
								document.transferrequest.action='form_rentinvoice.php';				
								document.transferrequest.submit();
								
						}
						else {
						
						//ReloadGrid(filepath,'transferrequest',trqstsid,'datagrid','','','ADD','','','','',0,'',function() {
							var focusedvrec = parseInt(vrec);
							var focused = 'p_item_code['+focusedvrec+']';
							document.getElementById(focused).focus();
						//});
						$("#Loader").removeClass("ajaxloading");
						//ReloadGridDt(filepath,'TRQ-totals','totalsdatagrid','totalsdatagrid',trqstsid,-1);
						//$("#Loader").removeClass("ajaxsaving");
						
						}
						
						document.transferrequest.action='form_rentinvoice.php';				
						document.transferrequest.submit();
					}	
					else {
					
							
						
							document.getElementById('testdatagrid').innerHTML =  xmlhttp.responseText;
							
							 
							//ReloadGrid(filepath,'transferrequest',trqstsid,'datagrid','','','ADD','','','','',0,'',function() {
											var focusedvrec = parseInt(vrec) ;
											var focused = 'p_item_code['+focusedvrec+']';
											document.getElementById(focused).focus();
										//});
							//ReloadGridDt(filepath,'TRQ-totals','totalsdatagrid','totalsdatagrid',trqstsid,-1);
										$("#Loader").removeClass("ajaxloading");
							location.reload();
						}						
					
					
									
					
					
									
				
		}
  }

 
//var value13 = x.inputfromwarehouse.value; 

//  actionmode =  vasubmitprqstdt ;


var str = "Form_rentinvoice_Actions.php?vmode="+vmode+"&value1="+value1+"&value2="+value2+"&value3="+value3
											+"&value4="+value4+"&value5="+value5+"&value6="+value6+"&value7="+value7+"&value8="+value8+"&value9="+value9
											+"&value10="+value10+"&value11="+value11+"&value12="+value12+"&value13="+value13
											+"&value14="+value14+"&value15="+value15+"&value16="+value16+"&value17="+value17+"&value18="+value18+"&TrqstId="+trqstsid
											+"&STrqstDtId="+STrqstDtId+"&transferrequestdt_id="+STrqstDtId+"&STrqstDtBatchno="+value19+"&STrqstDtPackagingno="+value20
											+"&STrqstDtNbrunit="+value21+"&STrqstDtHeatno="+value22
											+"&transferrequest_id="+trqstsid+"&actionmode="+vactionmode+"&actionmoded="+actionmoded+"&base1="+value26+"&base2="+value27;
											
str+= "&txtDatefrom="+document.getElementById('txtDatefrom').value;	
str+= "&txtDateto="+document.getElementById('txtDateto').value;	
str+= "&txtClientCode="+document.getElementById('txtClientCode').value;	 
str+= "&txtCurr="+document.getElementById('txtCurr').value;
str+= "&value500="+value500;									
							
str += "&Setup_VatPercentage="+Setup_VatPercentage+"&txtSaDiscountAmt="+txtSaDiscountAmt+"&txtSaDiscount="+txtSaDiscount+"&txtSaVatChk="+txtSaVatChk;		
							
							
// alert(str); return;
							
xmlhttp.open("GET",str,true);

xmlhttp.send();

    
}

function deletetrequestsdt(trqstid,trqstdtid, ItemPackCode, ItemCode,filepath){


	var x =  document.transferrequest;
		var value7 = x.transferrequest_date.value;
		var value8 = x.fromproject.value;
		var value9 = x.costcent.value;
		var value10 = x.documentrefno.value;
		var value11 = x.toproject.value;
		var value12 = x.tocostcent.value;
		var value13 = x.inputfromwarehouse.value;
		var value14 = x.inputtowarehouse.value;
		var value15 = x.driver_name.value;
		var value16 = x.transferrequest_remark.value;
		var value18 = x.vehicle_no.value;
		var value22 = x.txtCurr.value; //currency

		var Setup_VatPercentage = x.Setup_VatPercentage.value;
		var txtSaDiscountAmt = x.txtSaDiscountAmt.value;
		var txtSaDiscount = x.txtSaDiscount.value;
		var txtSaVatChk = x.txtSaVatChk.value;

	if (ItemPackCode != '')
	   vDelMsg = "Are you sure you want to Delete Pack Item "+ItemPackCode+" ?";
	else  
	   vDelMsg = "Are you sure you want to Delete Item "+ItemCode+" ?";
	   
	   
   
if (confirm ( vDelMsg ))
	{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 
							//document.getElementById('testdatagrid').innerHTML = xmlhttp.responseText;
							var data = xmlhttp.responseText.split('[BRK]');
							document.getElementById('testdatagrid').innerHTML = data[0];
								
							//ReloadGrid(filepath,'transferrequest',trqstid,'datagrid','','','ADD','','','','',0,'',function() {
							document.getElementById('SelectedRec').value='';		
							//});
							//$("#Loader").removeClass("ajaxloading");
							if(data[1]) location.reload();							
				}
		}
  }

	xmlhttp.open("GET","Form_rentInvoice_Actions.php?trqstid="+trqstid+"&actionmoded=d&transferrequestdt_id="+trqstdtid
					+"&value7="+value7+"&value8="+value8+"&value9="+value9
												+"&value10="+value10+"&value11="+value11
												+"&value12="+value12+"&value13="+value13
												+"&value14="+value14+"&value15="+value15
												+"&value16="+value16+"&value18="+value18
												+"&txtCurr="+value22+"&transferrequest_id="+trqstid
												+"&Setup_VatPercentage="+Setup_VatPercentage 
												+"&txtSaDiscountAmt="+txtSaDiscountAmt
												+"&txtSaDiscount="+txtSaDiscount 
												+"&txtSaVatChk="+txtSaVatChk
					,true);
	xmlhttp.send();

	}
}
	
	
function changeqty2(vnum,vitemunit,moduleunit1,indx){

itemunit = 'Item_Unit[' + indx + ']';
itemunit =document.getElementById(itemunit).value;
var itemunit2qty = 'Item_Unit2Qty[' + indx + ']';


var p_item_quantity = 'p_item_quantity[' + indx + ']';




if (vnum==1)
	{ 
	
if (document.getElementById(itemunit2qty).value!='')
return;
		
			if (moduleunit1==1 && itemunit !='')
					{
					var itemqty = document.getElementById(p_item_quantity).value;
					var xx = Number(itemqty) * Number(itemunit);

					document.getElementById(itemunit2qty).value = xx;
					}
			else {
				if (moduleunit1==0 && itemunit !='')
						{
							var itemqty = document.getElementById(p_item_quantity).value;
							var xx = Number(itemqty) / Number(itemunit);
							document.getElementById(itemunit2qty).value = xx;
						}
				}
	}
else {
if (document.getElementById(p_item_quantity).value!='')
return;
			if (moduleunit1==1 && itemunit !='')
					{
					var itemqty = document.getElementById(itemunit2qty).value;
					var xx = Number(itemqty) / Number(itemunit);

					document.getElementById(p_item_quantity).value = xx;
					}
			else {
				if (moduleunit1==0 && itemunit !='')
						{
							var itemqty = document.getElementById(itemunit2qty).value;
							var xx = Number(itemqty) * Number(itemunit);
							document.getElementById(p_item_quantity).value = xx;
						}
				}
	}

}

function showsearchpage(vtype,vtext1,vtext2,vtext3,vtext4,vtext5,vtext6,vtext7,vwidth,vheight){

	var text1value = document.getElementById(vtext1).value;
	if(document.getElementById("fromwarehouse"))
		var fromwh = document.getElementById("fromwarehouse").value;
	else var fromwh = '';
	
	var transferrequest_date = document.transferrequest.transferrequest_date.value;
	
	if (document.getElementById(vtext2))
		var text2value = document.getElementById(vtext2).value;
else
		var text2value = '';
		
		
	win = window.open('List_PurItems.php?PItem_Code='+text1value+'&PItem_Description=&item=6&transferrequest_date='+transferrequest_date+'&vtype='+vtype+'&vtext1='+vtext1+'&vtext2='+vtext2+'&vtext3='+vtext3
						+'&vtext4='+vtext4+'&vtext5='+vtext5+'&vtext6='+vtext6+'&vtext7='+vtext7
						+'&text1value='+text1value+'&fromwh='+fromwh, 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();	
	}
	
	
function dokeytransferrequest(e,obj,rowindx,columnslist,vbutname){





	//if (e.ctrlKey == false)
	//return;
	var vindx = rowindx;
	if (!e) { var e = window.Events;}
    var intKey = (window.Events) ? e.which : e.keyCode;


	var columnsarray=new Array();
	columnsarray = columnslist.split(",");
	var firstcell = columnsarray[0];
	var lastcell  = columnsarray[columnsarray.length-1];
	var arrayname = obj.id.split("[");

	if (( ((intKey == 37) || (intKey == 39)) && e.ctrlKey )  ||  (intKey == 13))
	{
		var cindx = columnsarray.indexOf(arrayname[0]);
		
		if (intKey == 37) { //left key
			var nextindx = Number(cindx) - 1;
		}
		if (intKey == 13 || intKey == 39) { //right key
			var nextindx = Number(cindx) + 1;
		}


		var nextitem = columnsarray[nextindx] + '[' + rowindx + ']' ;

		
		if (document.getElementById(nextitem)) {
			var nextobj = document.getElementById(nextitem);
			nextobj.focus();
			if(nextobj.type!='select-one')
			nextobj.select();
		}
		else { 
			var nextrow  = rowindx + 1;
			var nextcell = firstcell + '[' +  nextrow + ']';
				
			var imgname = 'imgSubmit' + vbutname + '[' +  rowindx + ']';
			
			document.getElementById(imgname).click();
			
			if (document.getElementById(nextcell) ) {
				document.getElementById(nextcell).focus();
				if(document.getElementById(nextcell).type!='select-one')
				document.getElementById(nextcell).select();
			}	
					
		}	
	}
	else if ( ((intKey == 38) || (intKey == 40)) && e.ctrlKey) {
		
		if (intKey == 38) 
			rowindx = rowindx - 1;
		if (intKey == 40) 
			rowindx = rowindx + 1;
			
		var nextitem =  arrayname[0] + '[' + rowindx + ']';
		if (document.getElementById(nextitem)) {
			var nextobj = document.getElementById(nextitem);
			nextobj.focus();
			if(nextobj.type!='select-one')
			nextobj.select();
		}	
	}

}

function SearchForPending(TransType){
    ClearForm('All');

    win = window.open('Form_RentInvoiceSearchpending.php?TransType='+TransType, 'Form_TransferRequestSearchPending', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1030,height=450,top=100');		
	
	win.creator = self;
	win.focus();		
			
}




function CancelRecord(){
	x = document.transferrequest;
	var vmode1 = x.actionmode.value;
	var TRId = x.transferrequest_id.value;
	
	if (confirm ( "Are you sure you want to Delete current pending Rent Invoice permenantly?"))
	{
		ClearForm('All');
		x.transferrequest_id.value = TRId;
		x.actionmode.value='cancel';
		var TransType = x.TransType.value;
		x.action='Form_rentinvoice.php?TransType='+TransType;
		x.submit();
	
	Form_TransferRequestSearchPending.close();
	Form_TransferRequestSearch.close();
	Loading.close();
	Item.close();
	Serial.close();
	mywindow.close();
	Form_TransferRequestSearchPending.close();
	
	}
    
}



function SearchForRef(){
    
	ClearForm('All');
    x = document.transferrequest;
	var TransType = x.TransType.value;
    win = window.open('Form_rentinvoiceSearch.php?TransType='+TransType, 'Form_TransferRequestSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=860,height=460,top=100');		
	win.creator = self;
	win.focus();		
			
}


function ClearForm(Option){
    x = document.transferrequest;
	var vmode = x.actionmode.value;
	
	if (Option == 'All') {
		
		x.transferrequest_date.value='';
		x.transferrequest_id.value='';
		x.transferrequest_reference.value='';
		x.fromproject.value='';
		x.toproject.value='';
		x.inputfromwarehouse.value='';
		x.inputtowarehouse.value='';
		x.costcent.value='';
		x.tocostcent.value='';
		x.driver_name.value='';
		x.vehicle_no.value='';
		x.transferrequest_remark.value='';
		x.documentrefno.value='';
		
		
		x.txtJvRef.value='';
		x.txtJvFolio.value='';
		
		
		x.txtClientCode.value = '';
		x.txtClientName.value = '';
		x.txtDatefrom.value = '';
		x.txtDateto.value = '';
		x.txtCurr.value = '';
		
		
		
		x.message.value='';
		x.actionmode.value = '';
		
		
		} 
}





function ClearPage(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		x = document.transferrequest;
		x.actionmode.value='';
		var TransType = x.TransType.value;
		x.action='form_rentinvoice.php?TransType='+TransType;
		x.submit();
	}	
}

function ClearPage1(){
	x = document.transferrequest;
	var msg = x.message.value;
	
	ClearForm('All');
	
	//x.actionmode.value='insert';
	var TransType = x.TransType.value;
	x.message.value=msg;
	x.action='form_rentinvoice.php?TransType='+TransType;
	x.submit();
}

function PrintTransfer(TrId,TrRef) {
	var str = '';
	var Vdetail=0;
	var TransType = document.transferrequest.TransType.value;
	//alert(TransType);
	
	//if (confirm ( "Do you want to Print Rent Invoice Ref "+TrRef+"?"))
	if (TransType!='Tr')
	if (confirm ( "Do you want to Print with detail?"))
	{
		Vdetail = 1;	
	}
	if (TransType=='Tr')
		Vdetail = 1;	
		str= 'form_rentinvoicepreview.php?transferrequest_id='+TrId+'&TransType='+TransType+'&detail='+Vdetail;
		window.open(str);
	
//ClearPage1();	
}



function PostChanges(ModuleProject, ModuleCostCenter, Module_RestrictProjCost, Module_RestrictCost){
	
 
	 
	var costcent= document.transferrequest.costcent.value;

	 
	
	var tocostcent= document.transferrequest.tocostcent.value;
	var fromwarehouse= document.transferrequest.inputfromwarehouse.value;
	
	var transferDate = document.transferrequest.transferrequest_date.value;
	
	var towarehouse= document.transferrequest.inputtowarehouse.value;
	var toproject = document.transferrequest.toproject.value;
	var fromproject = document.transferrequest.fromproject.value;
	var actionmode = document.transferrequest.actionmode.value;
	var transferrequest_id = document.transferrequest.transferrequest_id.value;
	var transferrequest_remark = document.transferrequest.transferrequest_remark.value;
	var transferrequest_date = document.transferrequest.transferrequest_date.value;
	var driver_name = document.transferrequest.driver_name.value;
	var vehicle_no = document.transferrequest.vehicle_no.value;
	var TransType = document.transferrequest.TransType.value;
	var documentrefno = document.transferrequest.documentrefno.value;
	var actionmoded = 'mi';
	var result = CheckFields(ModuleProject, ModuleCostCenter,Module_RestrictProjCost,Module_RestrictCost);
	fromwarehouse = fromwarehouse.replace('&','%26');
	towarehouse = towarehouse.replace('&','%26');
	var Setup_VatPercentage = document.transferrequest.Setup_VatPercentage.value;
	var txtSaDiscountAmt = document.transferrequest.txtSaDiscountAmt.value;
	var txtSaDiscount = document.transferrequest.txtSaDiscount.value;
	var txtSaVatChk = document.transferrequest.txtSaVatChk.value;

	if ( ((actionmode=='edit') ))
	   {
		if (result==1)
		if (confirm ( "Are you sure you want to Save current Rent Invoice?"))
		{
			
		document.transferrequest.actionmode.value='post';
		
		var str = '';
		str+= "&txtDatefrom=" + document.getElementById('txtDatefrom').value;	
        str+= "&txtDateto=" + document.getElementById('txtDateto').value;	
        str+= "&txtClientCode=" + document.getElementById('txtClientCode').value;	 
		str+= "&txtCurr=" + document.getElementById('txtCurr').value;
		str += "&Setup_VatPercentage="+Setup_VatPercentage+"&txtSaDiscountAmt="+txtSaDiscountAmt+"&txtSaDiscount="+txtSaDiscount+"&txtSaVatChk="+txtSaVatChk+"&transferDate="+transferDate;		
		
        // alert(str);
		 
		document.transferrequest.action= 'Form_rentinvoice_Actions.php?fromproject='+fromproject+'&toproject='+toproject
										+'&fromwarehouse='+fromwarehouse+'&towarehouse='+towarehouse+'&actionmoded='+actionmoded+'&transferrequest_id='+transferrequest_id
										+'&transferrequest_remark='+transferrequest_remark+'&transferrequest_date='+transferrequest_date
										+'&drivername='+driver_name+'&documentrefno='+documentrefno+'&vehicle_no='+vehicle_no+'&costcent='+costcent
										+'&tocostcent='+tocostcent+'&TransType='+TransType+str;
		document.transferrequest.submit();
		
		}
	   }
	  
}


function UpdateTrDt(item_withserial,transferdt_id,fromwarehouse,towarehouse){
	var costcent= document.transferrequest.costcent.value;
	var tocostcent= document.transferrequest.tocostcent.value;
	
	
	var toproject = document.transferrequest.toproject.value;
	var fromproject = document.transferrequest.fromproject.value;
	var actionmode = document.transferrequest.actionmode.value;
	var transferrequest_id = document.transferrequest.transferrequest_id.value;
	var transferrequest_remark = document.transferrequest.transferrequest_remark.value;
	var transferrequest_date = document.transferrequest.transferrequest_date.value;
	var driver_name = document.transferrequest.driver_name.value;
	var vehicle_no = document.transferrequest.vehicle_no.value;
	var transit = document.transferrequest.transit.value;
	var TransType = document.transferrequest.TransType.value;	
	var actionmoded = 'e';
	
	fromwarehouse = fromwarehouse.replace('&','%26');
	towarehouse = towarehouse.replace('&','%26');
	str1= 'Form_TransferItems.php?item=1&fromwarehouse='+fromwarehouse+'&towarehouse='+towarehouse+'&fromproject='+fromproject+'&toproject='+toproject+'&actionmode='+actionmode+'&transferrequest_id='+transferrequest_id+'&transferrequest_remark='+transferrequest_remark+'&transferrequest_date='+transferrequest_date+'&driver_name='+driver_name+'&vehicle_no='+vehicle_no+'&costcent='+costcent+'&transferrequestdt_id='+transferrequestdt_id+'&actionmoded='+actionmoded+'&item_withserial='+item_withserial+'&transit='+transit+'&tocostcent='+tocostcent+'&TransType='+TransType;
	
	width = screen.width - 250;
	height = screen.height - 350;
	
	window.open(str1,"Item", "width=" + width + ",height=" + height + ",screenX=0,left=150,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");


}
function DeleteTrDt(item_withserial,transferdt_id){
	var costcent= document.transferrequest.costcent.value;
	var tocostcent= document.transferrequest.tocostcent.value;
	var fromwarehouse= document.transferrequest.fromwarehouse.value;
	var towarehouse= document.transferrequest.towarehouse.value;
	var toproject = document.transferrequest.toproject.value;
	var fromproject = document.transferrequest.fromproject.value;
	var actionmode = document.transferrequest.actionmode.value;
	var transferrequest_id = document.transferrequest.transferrequest_id.value;
	var transferrequest_remark = document.transferrequest.transferrequest_remark.value;
	var transferrequest_date = document.transferrequest.transferrequest_date.value;
	var driver_name = document.transferrequest.driver_name.value;
	var vehicle_no = document.transferrequest.vehicle_no.value;
	var TransType = document.transferrequest.TransType.value;
	var documentrefno = document.transferrequest.documentrefno.value;
	var actionmoded = 'd';
	fromwarehouse = fromwarehouse.replace('&','%26');
	towarehouse = towarehouse.replace('&','%26');
	
	if (confirm ( "Are you sure you want to Delete current Item?"))
	{
	document.transferrequest.action= 'form_rentinvoice_actions.php?fromproject='+fromproject+'&toproject='+toproject+'&fromwarehouse='+fromwarehouse+'&towarehouse='+towarehouse+'&actionmode='+actionmode+'&transferrequest_id='+transferrequest_id+'&transferrequest_remark='+transferrequest_remark+'&transferrequest_date='+transferrequest_date+'&drivername='+driver_name+'&documentrefno='+documentrefno+'&vehicle_no='+vehicle_no+'&costcent='+costcent+'&actionmoded='+actionmoded+'&transferdt_id='+transferdt_id+'&item_withserial='+item_withserial+'&tocostcent='+tocostcent+'&TransType='+TransType;
	document.transferrequest.submit();
	}
}
function resubmit(){

document.transferrequest.submit();
}




function openitempage(TransType){
	var costcent= document.transferrequest.costcent.value;
	var tocostcent= document.transferrequest.tocostcent.value;
	var fromwarehouse= document.transferrequest.fromwarehouse.value;
	var towarehouse= document.transferrequest.towarehouse.value;
	var toproject = document.transferrequest.toproject.value;
	var fromproject = document.transferrequest.fromproject.value;
	var actionmode = document.transferrequest.actionmode.value;
	var transfer_id = document.transferrequest.transfer_id.value;
	var transfer_remark = document.transferrequest.transfer_remark.value;
	var transfer_date = document.transferrequest.transfer_date.value;
	var driver_name = document.transferrequest.driver_name.value;
	var vehicle_no = document.transferrequest.vehicle_no.value;
var documentrefno = document.transferrequest.documentrefno.value;
	fromwarehouse = fromwarehouse.replace('&','%26');
	towarehouse = towarehouse.replace('&','%26');
	
	
	  str1= 'Form_TransferItems.php?item=1&fromwarehouse='+fromwarehouse+'&towarehouse='+towarehouse+'&fromproject='+fromproject+'&toproject='+toproject+'&actionmode='+actionmode+'&transfer_id='+transfer_id+'&transfer_remark='+transfer_remark+'&transfer_date='+transferrequest_date+'&driver_name='+driver_name+'&documentrefno='+documentrefno+'&vehicle_no='+vehicle_no+'&costcent='+costcent+'&tocostcent='+tocostcent+'&TransType='+TransType;
	  width = screen.width - 100;
	  height = screen.height - 350;
	  window.open(str1,"Items", "width=" + width + ",height=" + height + ",screenX=0,left=250,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");
	
}

  
  
function CheckFields(ModuleProject, ModuleCostCenter,Module_RestrictProjCost,Module_RestrictCost){
 x = document.transferrequest;

 var STransDate = x.transferrequest_date.value; 
 var SFromProject = x.fromproject.value;
 var SToProject = x.toproject.value;
 var SFromWarehouse = x.inputfromwarehouse.value;
 var SToWarehouse = x.inputtowarehouse.value;
 
 var Scostcent = x.costcent.value;
 var SToCostCenter_code = x.tocostcent.value;
 var SModule_TransferWithOneWh = x.Module_TransferWithOneWh.value
 //alert(SModule_TransferWithOneWh);
 if (STransDate=='' )
	{
		alert("Date is mandatory!");
		x.transferrequest_date.focus();
		return 0;
	}
	else if (SFromProject=='' && ModuleProject==1 && Module_RestrictProjCost==1 )
	{
		alert("From Project is mandatory!");
		x.fromproject.focus();
		return 0;
	}
	else if (SToProject==''  && ModuleProject==1  && Module_RestrictProjCost==1 )
	{
		alert("To Project is mandatory!");
		x.toproject.focus();
		return 0;
	}
		else if (Scostcent=='' && ModuleCostCenter==1 && Module_RestrictCost==1)
	{
		alert("From CostCenter is mandatory!");
		x.costcent.focus();
		return 0;
	}
	else if (SToCostCenter_code==''  && ModuleCostCenter==1 && Module_RestrictCost==1)
	{
		alert("To CostCenter is mandatory!");
		x.tocostcent.focus();
		return 0;
	}
	else if (SFromWarehouse=='' && SModule_TransferWithOneWh==1)
	{
		alert("From Warehouse is mandatory!");
		x.inputfromwarehouse.focus();
		return 0;
	}
		else if (SToWarehouse==''  && SModule_TransferWithOneWh==1)
	{
		alert("To Warehouse is mandatory!");
		x.inputtowarehouse.focus();
		return 0;
	}
	else return 1;
}
/*
function showlistProject(str,prj){
var TransType = document.transferrequest.TransType.value;
window.open('List_TrsProject.php?item='+str+'&Project='+prj+'&TransType='+TransType,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
*/
function showlistProject(vtype,vtext1,vwidth,vheight,item){
  	var text1value = document.getElementById(vtext1).value;
	if (item=='')
		item = 2;
	win = window.open('List_Project.php?PProject_Code='+text1value+'&item='+item+'&vtype='+vtype+'&vtext1='+vtext1
						+'&text1value='+text1value, 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();		
}

function calTotal(index){
	var Price = document.getElementById('p_item_price['+index+']').value;
	var Qty = document.getElementById('p_item_quantity['+index+']').value;
	Price = parseFloat(Price);
	Qty = parseFloat(Qty);
	document.getElementById('itemtotalprice['+index+']').value = parseFloat(Price*Qty);
}
function setwarehousecode(val,vfield1,btnname){

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	var data = xmlhttp.responseText.split("[BRK]");
					var resp = data[1];
					
					if (resp==0)
						{
							document.getElementById(btnname).click();
						}
						
						//showsearchpage('itemcode',vfield1,vfield2,vfield3,vfield4,vfield5,vfield6,800,500);

				}
		}
  }

xmlhttp.open("GET","Form_rentInvoice_Actions.php?vwarehousecode="+val+"&actionmode=checkwarehousecode",true);
xmlhttp.send();

}


function showlistWarehouse(str,wrh){
var TransType = document.transferrequest.TransType.value;
var text1value = document.getElementById(wrh).value;

  window.open('List_TrsWarehouseGrid.php?item='+str+'&Warehouse='+wrh+'&TransType='+TransType+'&PLedger_number='+text1value,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Rent Invoice</title>


<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>


<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>

<link type="text/css" href="js/grid/scripts/jquery-ui.css" rel="stylesheet">
<script type="text/javascript" src="js/grid/scripts/jquery-ui.min.js"></script>





<script type="text/javascript" src="dropdown.js"></script>
<script type="text/javascript" language="javascript">
	
	
	$(document).ready(function() { 
		
	if (document.getElementById('p_item_code[1]'))
		document.getElementById('p_item_code[1]').focus();
		
	
		$(document).on('focusin', '.table-focus-g1', function() {
			AutoSaveRecordGrid(this.id,'SelectedRec','ModRec_G1','imgSubmitPTransReqDt');
			selRecordColor(this,'SelectedRec','SelectedRecColor');
		});
		
		//Set Scroll Positions on Page Load
		scrollToPage();
		
		$(window).scroll(function(){
			scrollPage();
		});
		
	
	});


function showlistBatchNo(str,PIndex) {
	x = document.transferrequest;
	
	XPos = (screen.availHeight - 400) / 2;
	YPos = (screen.availWidth - 580) / 2;
	
	vItemCode = encodeURIComponent(document.getElementById('p_item_code['+PIndex+']').value);
	if(x.inputfromwarehouse) vWarehouseCode = encodeURIComponent(document.getElementById('inputfromwarehouse').value);
	else if (document.getElementById('fromwarehousedt['+PIndex+']')) vWarehouseCode = encodeURIComponent(document.getElementById('fromwarehousedt['+PIndex+']').value);
	else vWarehouseCode='';
	window.open('List_BatchNo.php?frm=12&index='+PIndex+'&PItem_Code='+vItemCode+'&PWarehouseCode='+vWarehouseCode,'List_BatchNo','width=580,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,left='+YPos+',top='+XPos);
}
	
function setQty(index){
	var pckge   = document.getElementById("p_transferdt_packagingno["+index+"]").value;
	var unitnbr = document.getElementById("p_transferdt_nbrunit["+index+"]").value;
	var qty 	= 0;
	
	if(pckge == '') pckge = 0;
	else pckge = parseFloat(pckge);
	
	if(unitnbr == '') unitnbr = 0;
	else unitnbr = parseFloat(unitnbr);
	
	qty = pckge*unitnbr;
	document.getElementById("p_item_quantity["+index+"]").value = qty;
	
}	


function showlistHeatNo(PIndex) {
	XPos = (screen.availHeight - 550) / 2;
	YPos = (screen.availWidth - 850) / 2;
	
	var vHeatNoCode = encodeURIComponent(document.getElementById('p_transferdt_heatno['+PIndex+']').value);
	
	window.open('List_HeatNo.php?frm=13&index='+PIndex+'&PHeatNoCode='+vHeatNoCode+'&PHeatNo_Type=','List_HeatNo','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}
</script>


<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">

<style>



#table1:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	cursor:pointer;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;

}
#table2:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table3:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#tabledt1:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#tabledt2:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;

}

#tabledt3:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table5:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table6:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table7:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table8:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}

table.sample {
	border-width: 0px;
	border-spacing: 3px;
	border-style: double;
	border-color: gray;
	border-collapse: collapse;
	background-color: white;
}
table.sample th {
	border-width: 1px;
	padding: 0px;
	border-style: solid;
	border-color: #DCDCDC;
	-moz-border-radius: ;
}
table.sample td {
	border-width: 1px;
	padding: 0px;
	border-style: solid;
	border-color: #E5E5E5;
	-moz-border-radius: ;
}


tablesalary.sample {
	border-width: 0px;
	border-spacing: 3px;
	border-style: double;
	border-color: gray;
	border-collapse: collapse;
	background-color: white;
}
tablesalary.sample th {
	border-width: 1px;
	padding: 0px;
	border-style: solid;
	border-color: #DCDCDC;
	-moz-border-radius: ;
}
tablesalary.sample td {
	border-width: 1px;
	padding: 0px;
	border-style: solid;
	border-color: #E5E5E5;
	-moz-border-radius: ;
}


</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

</head>
<body>
<form name='transferrequest' method='post'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='transferrequest_id' id='transferrequest_id' value='$transferrequest_id'>
<input type='hidden' name='message' value='$message' size='200'>
<input type='hidden' name='login_belongstogrp' value='$login_belongstogrp' size='15'>
<input type='hidden' name='process' value='$process' size='15'>
<input type='hidden' name='previousWarehouse' value='$previousWarehouse' size='15'>
<input type='hidden' name='TransType' value='$TransType' size='15'>
<input type='hidden' name='txtSaId' value='$txtSaId' size='10'>
<input type="hidden" name="txtRef" value="$txtRef" size='10' readonly>
<input type = 'hidden' name = 'Setup_VatPercentage' value = '$Setup_VatPercentage' />
<input type = 'hidden' name = 'base1' value = '$base1' />
<input type = 'hidden' name = 'base2' value = '$base2' />
 
<input type='hidden' name='mainaction' value='$mainaction'>

			  <input type='hidden' name='txtJvFolio' value='$txtJvFolio' >
			  <input type='hidden' name='txtJvRef' value='$txtJvRef' >
			  
			  
 
 
  	



HERE;

//$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";


echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>";
		if ($TransType=='Tr'){
			echo"Rent Invoice ";
		 	echo " <input type='hidden' id='txtSaDiscount_Temp'  name='txtSaDiscount_Temp' value='$txtSaDiscount_Temp'> ";
		 }
			else
			if ($TransType=='Rm')
				echo"Material Issue-Factory Transfer";	
			echo"</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='30'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px' align='left'>";
	echo" <button type='button' id='btnClear' name='btnClear' onclick='ClearPage();return false;' title='Clear Page'><span><span>$clear_page</span></span></button>";	
	
echo"<button type='button' id='btnCancel' name='btnCancel' ";
if ($actionmode=='cancel' or $PreviewButtons=='disabled')
					echo " disabled ";
			
echo" onclick='CancelRecord();return false;' title='Cancel Changes'><span><span>$cancel</span></span></button>";	
				
echo"<button type='button' id='btnPost' name='btnPost' ";
		if ((($actionmode=='' || $actionmode=='cancel') && $mainaction!='edit') || $PreviewButtons=='disabled' || ($transferrequest_id == '' && $FI_RENTINVOICEApp==0))
					echo " disabled ";
	echo" onclick=\"PostChanges($ModuleProject, $ModuleCostCenter, $Module_RestrictProjCost,$Module_RestrictCost);\" title='Save Changes'><span><span>$save</span></span></button>";	
				

echo"<button type='button' id='btnSearch' name='btnSearch' ";
	if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit') 
		    echo " disabled ";
	echo" onclick='SearchForRef();return false;' title='Search By Reference'><span><span>$search</span></span></button>";

echo"<button type='button' id='btnPending' name='btnPending' ";	

        if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit')
		    echo " disabled ";
	echo" onclick='SearchForPending(\"$TransType\");return false;' title='Pending Rent Invoice'><span><span>$pending</span></span></button>";	


if ($actionmode == "post" && $transferrequest_id != '') 
{
	$qry="select transferrequest_reference from transferrequest where transferrequest_id = $transferrequest_id";
	
	$result=mysql_query($qry,$connection) or die(mysql_error());
		while($rows=mysql_fetch_array($result)){
				extract($rows);
												}	
		echo" <button type='button' id='btnPrint' name='btnPrint' onclick=PrintTransfer('".$transferrequest_id."','".$transferrequest_reference."');return false; title='Printing Rent Invoice'><span><span>Print</span></span></button>";												
				
}

//if ($Module_TransferSorder==1)
//	$type='button';
//	else
//	$type='hidden';

//echo" <button type='button' id='btnSearchSorder' name='btnSearchSorder' onclick='SearchConfirmedSorder($Module_RestrictProjCost, $Module_RestrictCost , $ModuleProject,$ModuleCostCenter,\"$TransType\");' title='Search Confirmed Preparation Order'><span><span>Load Preparation Order</span></span></button>";			
//echo"  &nbsp; <input name='btnSearchSorder' type='$type' id='btnSearchSorder' value='Load Preparation Order' onclick='SearchConfirmedSorder($Module_RestrictProjCost, $Module_RestrictCost , $ModuleProject,$ModuleCostCenter,\"$TransType\");' $style style='width: 180px;' title='Search Confirmed Preparation Order'  ";

                //if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit' )
				 //   echo " disabled ";
				//else
				//			    echo " enabled ";
		//echo " />";	
		
echo"	</td></tr></table>";
echo"</td></tr>";				

		
	echo"<tr><td id='content-body'>
<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
   <tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";	 

print <<<HERE
	
		
		<table border="0" style='table-layout:fixed'>	
		 <tr bgcolor="#F7F7F7" height='30'>
          <td width="9%" valign="center" align='left' bgcolor="#F7F7F7">
		  <span class="style1">$Reference&nbsp;<span class="style16">*</span></span></td>
		  <td><font face='Verdana' size='2'><b><br>$transferrequest_reference</b> 
HERE;

	if ($Module_PostToJournal == 1) {
 echo "  <span class='style1'><br>JV Ref.&nbsp;$txtJvRef <span class='style1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Folio.&nbsp;$txtJvFolio </span> ";		  
	}
 print <<<HERE
		  
		  
		  </font><input type="hidden" name="transferrequest_reference" value="$transferrequest_reference" readonly><input type="hidden" name="journal_id" value="$journal_id" ></td>
		 
HERE;
		  


 
 
  echo " <td>  &nbsp;</td>";
 if ($Module_Project == 1) 
		  echo"<td><span class='style1'>&nbsp;$Project&nbsp;</span><span class='style16'>*</span></td>";
 
 if ($Module_CostCenter == 1 && $ShowCostCentLayout == 1)  
	echo"<td><span class='style1'>Costcenter&nbsp;</span><span class='style16'>*</span></td>";
	 if ($Module_TransferWithOneWh==1)
		 echo "";
	
	
	echo"	  <td  style = '' rowspan='6' valign='top' >";

echo"	<div id='totals' style='width:240px; margin-top:3px; float:right;'>";
	ShowDeliveryTotals($connection,$transferrequest_id,$_SESSION['gdl_parameters'],$_SESSION['gdl_arrayaccess']);
echo"	</div>"; 

echo"	  </td> ";

print <<<HERE
		  
		</tr>
		<tr  height='30' bgcolor="#F7F7F7"><td width="8%" align="left"><span class="style1">$date_label&nbsp;<span class="style16">*</span></span></td>
		  <td><input type='text'  size='17' name='transferrequest_date'  value='$transferrequest_date' $PreviewButtons maxlength=10>
          <A HREF="#" onClick="displayCalendar(document.transferrequest.transferrequest_date,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
		  if ($PreviewButtons=='enabled')
		  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";
echo"		  </td>";

			
	echo"<td align='left' ><span class='style1'>$from_date</span></span></td>";
	
	if ($Module_Project == 1) 
	echo"<td align='left' > <span class='style1'>
	<input type='text' name='fromproject'  $PreviewButtons  id='fromproject' value='".htmlentities($fromproject)."'   onchange=setprojectcode(this.value,'fromproject','transfromprojectimg')  size='17' maxlength='20' /></span>
	<label><span class='style1'><img src='img/scroll-down-1.png' title=' Select Project '  id='transfromprojectimg' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistProject('project','fromproject','800','500',3)\"  $PreviewButtons/></span></label></td>";
else
	echo"<input type='hidden' name='fromproject' readonly $PreviewButtons  id='fromproject' value='".htmlentities($fromproject)."' size='17' maxlength='20' />";

if ($Module_CostCenter == 1 && $ShowCostCentLayout == 1)
	echo"<td><span class='style1'>
	<input type='text' $PreviewButtons name='costcent'  id='costcent' value='".htmlentities($costcent)."' size='17' maxlength='20' onchange=setcostcentercode(this.value,'costcent','imgcostcenterbtnheader') /></span>
	<label><span class='style1'><image src='img/scroll-down-1.png' title=' Select Costcenter ' id='imgcostcenterbtnheader' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  
	onclick=\"showlistCostcenter('costcenter','costcent','800','500',3) \"  $PreviewButtons/></span></label></td>		";
else
	echo"<input type='hidden' name='costcent' id='costcent' readonly $PreviewButtons value='".htmlentities($costcent)."' size='17' maxlength='20' />";


if ($Module_TransferWithOneWh == 0){
	// echo "<script> alert(1); </script>";
	echo "<input type='hidden' $PreviewButtons name='fromwarehouse' id='fromwarehouse'  value='".htmlentities($fromwarehouse)."'  >";
	
} else if ($Module_TransferWithOneWh==1) {
// :)
	}
	
echo'</tr>
<tr  height="30" bgcolor="#F7F7F7"><td width="8%" align="left" ><span class="style1">';
if ($TransType=='Rm')
	echo "Doc. Ref No";
echo'</span></td>';

echo"     <td align='left' >";
if ($TransType=='Rm')
	echo"<input type='text' name='documentrefno' id='documentrefno' $PreviewButtons value='$documentrefno'>";
else
	echo"<input type='hidden' name='documentrefno' id='documentrefno' $PreviewButtons value='$documentrefno'>";
echo"</td>";
	


echo"<td><span class='style1'>$to_date</span></td>";
if ($Module_Project == 1) 
{
	echo"<td><span class='style1'><input type='text' name='toproject'   id='toproject' $PreviewButtons value='".htmlentities($toproject)."' size='17' maxlength='20'   onchange=setprojectcode(this.value,'toproject','transtoprojectimg2')  /></span>";
	echo"</span>&nbsp;<label><span class='style1'><img src='img/scroll-down-1.png' id='transtoprojectimg2' title=' Select Project ' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onclick=\"showlistProject('project','toproject','800','500',3)\"   $PreviewButtons/></span></label></td>";
}
else
	echo"<input type='hidden' name='toproject' id='toproject' readonly $PreviewButtons value='".htmlentities($toproject)."' size='17' maxlength='20' />";


if ($Module_CostCenter == 1 && $ShowCostCentLayout == 1)
	echo"<td><span class='style1'>
		<input type='text' $PreviewButtons name='tocostcent'  id='tocostcent' value='".htmlentities($tocostcent)."' size='17' maxlength='20'  onchange=setcostcentercode(this.value,'tocostcent','imgcostcenterbtnheader2') /></span>
			<label><span class='style1'><image src='img/scroll-down-1.png' id='imgcostcenterbtnheader2' title=' Select Costcenter ' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"   onclick=\"showlistCostcenter('costcenter','tocostcent','800','500',3) \"  $PreviewButtons/></span></label></td>		";
else
echo"<input type='hidden' name='tocostcent' readonly id='tocostcent' $PreviewButtons value='".htmlentities($tocostcent)."' size='17' maxlength='20' />";

if ($Module_TransferWithOneWh == 0){
	echo "<input $PreviewButtons type='hidden' name='towarehouse' id='towarehouse' value='".htmlentities($towarehouse)."'>";
} else if ($Module_TransferWithOneWh==1){
// :)
}
echo'</tr>';



echo " <tr>";


echo " <td> <span class='style1'>$Warehouse  &nbsp;</span><span class='style16'>*</span></td> "; 
	
	
	
	
if ($Module_TransferWithOneWh==1){
		
	echo"<td colspan = '2'><label><span class = 'style1'>From:</span>&nbsp;
		<input type='text' placeholder = '' $PreviewButtons name='inputfromwarehouse' id='inputfromwarehouse' 
		onchange=\"setwarehousecode(this.value,'inputfromwarehouse','fromwarehouseimgheader');\" value='".($_POST['inputfromwarehouse'])."'  >
		<span class='style1'>"; 		
	echo"&nbsp;<img src='img/scroll-down-1.png' title=' Select Warehouse ' id='fromwarehouseimgheader' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"   onclick=\"showlistWarehouse('inputfromwarehouse','inputfromwarehouse','800','500') \" 	";

	if ($transferrequest_id!='') 
		echo " disabled ";	

	echo"/></span></label>";
	
	echo"</span></td>";
}
		
if ($Module_TransferWithOneWh==1){  
		
	echo"<td> <span class='style1'>";
	echo"<label>
		<span class=\"style1\">To:</span>
		<input $PreviewButtons type='text' name='inputtowarehouse' id='inputtowarehouse'  onchange=\"setwarehousecode(this.value,'inputtowarehouse','towarehouseimgheader');\" value='".$_POST['inputtowarehouse']."'>
		<span class='style1'>&nbsp;";
	echo"<img src='img/scroll-down-1.png' title=' Select Warehouse ' id='towarehouseimgheader' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"   onclick=\"showlistWarehouse('inputtowarehouse','inputtowarehouse','800','500') \"   $PreviewButtons/></span></label>";
	echo"</td>";		

}		
		  
		  

		  
				
echo "</tr>";


echo"   <tr bgcolor='#F7F7F7'>
		  <td align='left' ><span class='style1'>Client&nbsp;<span class='style16'>*</span></span></td>";
echo"     <td colspan='7' ><span class='style1'>";
echo"     <label>

           <input type='text'   name='txtClientCode' id='txtClientCode' value='$txtClientCode' onblur=''  style='width:95px;' maxlength='10'  onkeydown='return kdClient(0,event);'    />           
		   <input type='text'   name='txtClientName' id='txtClientName' value='$txtClientName' style='width:285px;'   onkeydown='return kdClient(1,event);'   />
		   <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Client ' id='lstClientCodeH' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistClient(1); ' /> </span></label>
		   <label><img src='img/btnopen.jpg' title='Select Client' id='lstClientNameH' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistClientName(1);' style='display:none;' /></label>
		   <input type='hidden' name='txtClientVat' id='txtClientVat' value='$txtClientVat' />
          </label>
          </span>
          </td>";
 
print <<<h
<tr>
 <td align="left"><span class="style1">From Date&nbsp;<span class="style16">*</span></span></td>
		  <td><input type='text' name='txtDatefrom' id='txtDatefrom' value='$txtDatefrom'  onBlur=checkDateFormat(this,$strt,$end)   onchange='' maxlength='10'  style='width:90px;'>
		                   <A HREF="#" onClick="displayCalendar(document.transferrequest.txtDatefrom,'dd/mm/yyyy',this);  return false; " NAME="anchor1" ID="anchor1"><img src='./img/cal.gif' border=0 align=center></A></td>
 

<td align="left"><span class="style1">To Date&nbsp;<span class="style16">*</span></span></td>
		  <td><input type='text' name='txtDateto' id='txtDateto' value='$txtDateto'  onBlur=checkDateFormat(this,$strt,$end)   onchange='' maxlength='10'  style='width:90px;'>
		                   <A HREF="#" onClick="displayCalendar(document.transferrequest.txtDateto,'dd/mm/yyyy',this);  return false; " NAME="anchor1" ID="anchor1"><img src='./img/cal.gif' border=0 align=center></A></td>						   
						   
</tr>
h;


echo"   </tr>";


		echo "<tr>";
		
$querycurrency="select Currency_code from currency order by currency_code";
$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error());


	    
	echo"     <td align='left' ><span class='style1'>Currency&nbsp;<span class='style16'>*</span></span></td>";
	echo"     <td ><span class='style1'><select name='txtCurr' id='txtCurr' style='width:60px;' onchange='ChangeCurrency();'>";
			echo"<option></option>";
			while($curf=mysql_fetch_row($resultcurrency)){
			echo"<option ";
				if ($txtCurr==$curf[0])
					echo " selected ";
				echo" value='$curf[0]'>$curf[0] </option>";
			}
			echo"</select></span></td>";
			
			
		echo "</tr>";
		echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>$driver_label</td><td>
		<input type='text' name='driver_name'  $PreviewButtons value='$driver_name'></td>
		<td></td><td colspan=2></td><td></td></tr>";
		echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>$vehicle_label</td><td><input type='text' $PreviewButtons name='vehicle_no' value='"; echo $_POST['vehicle_no']; echo"' ></td>
		<td colspan=3 class='style1'></td>
		<td></td>";
		//echo"<td bgcolor=#D8D8D8><span class='style1'>Total Amount</span></td>
		//echo"<td bgcolor=#D8D8D8><input type='text' name='totalamount' id='totalamount' value='$totalamount' readonly></td>
		echo"</tr>";
			
		echo"<tr bgcolor='#F7F7F7'  height='30'>
		<td  align='left' ><span class='style1'>$Remark</span></td><td colspan='8'><span class='style1'>
		<input type='text' name='transferrequest_remark'  $PreviewButtons size='130' value='".htmlspecialchars($transferrequest_remark, ENT_QUOTES)."'  ></td></tr>";	
		echo"</td></tr>";
echo"   </table></td></tr>";

echo"<tr bgcolor='#F7F7F7'  ><td >&nbsp;</td></tr>";


if ($fromwarehouse!='')
	{
		$get_ware = "select warehouse_transit as transit from warehouse where warehouse_code = '".$fromwarehouse."'";
		$result=mysql_query($get_ware,$connection) or die(mysql_error());
		while($rows=mysql_fetch_array($result)){
				extract($rows);
												}	
	}	

echo"<input type='hidden' name='transit' value='$transit'> ";	
echo"<input type='hidden' name='Module_TransferWithOneWh' value='$Module_TransferWithOneWh'> ";	

if ($PreviewButtons=='enabled')
{
if ($transit=='' or $transit==0)
	{
	$loadstatus='disabled';
	$unloadstatus='enabled';
	}
else
	{
	$loadstatus='enabled';
	$unloadstatus='disabled';
	}
}
else
{
	$loadstatus='disabled';
	$unloadstatus='disabled';
}
					
/////////////// buttttttonssssssssssssss ////////////
/*echo"   <tr bgcolor='#D8D8D8' height='30'><td  align='center'>";

echo"           <input type='button' id='btnClear' name='BtnClear' value='Clear Page'   onclick='ClearPage();' $style title='Clear Page'>";
				
echo"           <input type='button' name='btnCancel' id='btnCancel' value='Cancel' ";//cancel
				if ($actionmode=='cancel' or $PreviewButtons=='disabled')
					echo " disabled ";
				echo" onclick='CancelRecord();' $style title='Cancel Changes'>";
				
echo"           <input type='button' name='btnPost' id='btnPost' value='Save' ";//post
				if ((($actionmode=='' || $actionmode=='cancel') && $mainaction!='edit') or $PreviewButtons=='disabled')
					echo " disabled ";
				echo" onclick='PostChanges($ModuleProject, $ModuleCostCenter, $Module_RestrictProjCost,$Module_RestrictCost);' $style	title='Save Changes' />";

echo"           <input name='btnSearch' type='button' id='btnSearch' value='Search' onclick='SearchForRef();' $style title='Search By Reference' ";
                if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit') 
				    echo " disabled ";
		        echo " />";
				
echo"           <input name='btnPending' type='button' id='btnPending' value='Pending' onclick='SearchForPending(\"$TransType\");' $style title='Pending Rent Invoice' ";
                if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit')
				    echo " disabled ";
		        echo " />";				
				



if ($actionmode == "post" && $transferrequest_id != '') 
{
	$qry="select transferrequest_reference from transferrequest where transferrequest_id = $transferrequest_id";
	
	$result=mysql_query($qry,$connection) or die(mysql_error());
		while($rows=mysql_fetch_array($result)){
				extract($rows);
												}	
	echo"<input name='btnPrint' type='button' id='btnPrint' value='Print' onclick=PrintTransfer('".$transferrequest_id."','".$transferrequest_reference."')  $style title='Printing Rent Invoice' />";				
}

if ($Module_TransferSorder==1)
	$type='button';
	else
	$type='hidden';

	
echo"  &nbsp; <input name='btnSearchSorder' type='$type' id='btnSearchSorder' value='Load Preparation Order' onclick='SearchConfirmedSorder($Module_RestrictProjCost, $Module_RestrictCost , $ModuleProject,$ModuleCostCenter,\"$TransType\");' $style style='width: 180px;' title='Search Confirmed Preparation Order'  ";

                //if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit' )
				 //   echo " disabled ";
				//else
				//			    echo " enabled ";
		echo " />";	

echo"   </td>";


echo"</tr>";*/	



echo"   <tr bgcolor='#ffffff'><td colspan='10' valign='top' align='left'>";

echo"	<div id='datagrid' class='' style='width:1200px;text-align:left;' >";

//Show Items Grid

				
ShowTransferRequestDtGrid2($connection,'TRQ',$transferrequest_id,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2,$DecimalBase,$Module_DoubleUnit,$Module_ProjectDt,$Module_CostCenterDt,$PriceLabel,$Module_Unit1Method,$PurchaseTTC,$Module_TransferWithOneWh,$FIPurchaseCategory,$Module_TransferRequestPrice,$showBatch, $Module_Heatno);

echo"	  </div>"; 
echo"   </td></tr>"; 
		
	echo"   <tr><td colspan='9' valign='top'>";

echo"	<div id='testdatagrid' class='' style='width:1090px;' >";


echo"	  </div>"; 

echo"   </td></tr>"; 

echo"   </table></td></tr><tr height='30'><td align='center' id='content-bottom' ></td></tr>";  
echo" </table>  ";//end of last table menu
print <<<HERE
</form>
</body>

HERE;



if ($actionmode == "post" && $transferrequest_id != '' && $Login_FastPrint ==1 ) 
{
	$qry="select transferrequest_reference from transferrequest where transferrequest_id = $transferrequest_id";
	
	$result=mysql_query($qry,$connection) or die(mysql_error());
		while($rows=mysql_fetch_array($result)){
				extract($rows);
												}	
	
	echo '<script type="text/javascript" language="javascript">';
    echo ' PrintTransfer(\''.$transferrequest_id.'\',\''.$transferrequest_reference.'\'); ';
	echo ' ClearPage1(); ';
	echo '</script>';

}




function displayToday(){
	return strftime("%d")."/".strftime("%m")."/".strftime("%Y");
}

function selectData($conn, $query){
		$result = mysql_query($query, $conn);
		$cur = mysql_fetch_row($result);		
		return $cur;
	}
//Method to Insert/ Update/ Delete Record in Database
function updateData($conn, $query, $commit){
	if (mysql_query($query, $conn)){				
		return true;
	}else{
		return false;
	}
}






function ShowDeliveryTotals($connection,$PSaId,$arrayparams,$arrayaccess){
	
	$querySalesSetup=" Select SalesTTC, ClientCur, Warehouse As SetupDftWareHouse, ifNull(ExportTransportToJV,0) As ExportTransportToJV, ifNull(ExportBonusToJV,0) As ExportBonusToJV,".
				 " ifNull(Sale_MaxExceedQty,0) As Sale_MaxExceedQty, ifNull(ShowCostCentLayout,0) As ShowCostCentLayout, ifNull(packingXNbrOfUnit,0) As packingXNbrOfUnit, 
				   ifNull(showBatch,0) As showBatch, ifnull(showDestinatin,0) as showDestinatin FROM SalesSetup";
	$resultSalesSetup=mysql_query($querySalesSetup,$connection) or die(mysql_error()); 
	while($rowSalesSetup=mysql_fetch_array($resultSalesSetup)){
		extract($rowSalesSetup);
	}
	
	//Read From Module Table
	$querymodule=" Select ifNull(Module_AdditionalTaxes,0) As Module_AdditionalTaxes, ifNull(Module_Delivery,0) As Module_Delivery, 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_DeliveryWithSorder,0) As Module_DeliveryWithSorder,".
				" ifNull(Module_DirectStock,0) As Module_DirectStock, ifNull(Module_PrintWaybill,0) As Module_PrintWaybill, ifNull(Module_ShowBalance,0) As Module_ShowBalance,	".
				" ifNull(Module_SerialNo,0) As Module_SerialNo, ifNull(Module_PostToJournal,0) As Module_PostToJournal, ifNull(Module_ReferenceByProject,0) As Module_ReferenceByProject,".
				" ifNull(Module_CreditLimitByProj,0) As Module_CreditLimitByProj, ifNull(Module_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt, ".
				" ifNull(Module_DoubleUnit,0) As Module_DoubleUnit, ifNull(Module_ExpireDate,0) As Module_ExpireDate, ifNull(Module_Pack,0) As Module_Pack, ifNull(Module_Unit1Method,0) As Module_Unit1Method,  ".
				" ifNull(Module_DeliveryClosingQty,0) As Module_DeliveryClosingQty, ifNull(Module_ChangeInvoiceItems,0) As Module_ChangeInvoiceItems, ifNull(Module_NegativeQuantity,0) As Module_NegativeQuantity,".
				" ifNull(Module_VehicleWeight,0) As Module_VehicleWeight, ifNull(Module_LoadSoldItems,0) as Module_LoadSoldItems,ifNull(Module_ImportExcell,0) As Module_ImportExcell, ".
				" ifNull(Module_Heatno,0) As Module_Heatno, ifNull(Module_BatchNo,0) As Module_BatchNo,ifNull(module_autodiscount,0) As Module_AutoDiscount, ".
				" ifNull(Module_Sorderproduction,0) As Module_Sorderproduction,ifNull(module_SalesAutoReceipt,0) as module_SalesAutoReceipt, ifnull(Module_Weight,0) as Module_Weight,  ".
				" ifnull(module_chargesInTransfer,0) as module_chargesInTransfer ".
				" From Module "; 
			// 	echo $querymodule; exit;
	$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
	while($rowmodule=mysql_fetch_array($resultmodule)){
		extract($rowmodule);
	}
 

 
 
 /*
 
 $querylog="SELECT Fi_TransferRequest as loginaccess,ifNull(Login_negativeQty,0) 
 As Login_negativeQty,ifnull(Login_FastPrint,0) as Login_FastPrint , ifNull(ModifyVAT,0) As ModifyVAT,
 ifNull(Login_ModifyDiscount,0) As Login_ModifyDiscount from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount'].
 "' 	and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
	
 */
	$querymodule = "select Module_AdditionalTaxes , Module_Delivery , ";
	global $DecimalBase,$Setup_VatPercentage,$ModifyVAT,$Login_ModifyDiscount;
  	global $txtClientCode,$txtSaDiscount_Temp; global $FI_SalesVAT; global $Login_ModifyDiscount;
 
	$DecimalBase  =$DecimalBase;
	$SalesTTC =  $SalesTTC;
	$Setup_VatPercentage = $Setup_VatPercentage;
	
	$Module_AdditionalTaxes = $Module_AdditionalTaxes;
	$Module_Delivery = $Module_Delivery;
	$ExportTransportToJV = $ExportTransportToJV;
	$ExportBonusToJV = $ExportBonusToJV;
	
	$VatApplied =  "0";
	$AllowModifyVAT =  $ModifyVAT;
	$Login_ModifyDiscount = $Login_ModifyDiscount;
	
	$txtSaDiscount_Temp = $txtSaDiscount_Temp;
	
	$txtClientCode   = $txtClientCode;
	
	$querycostcent=" select costcent_applyvat ".
               " from costcent left join ".$_SESSION['dbLabel'].".loginstk on costcent.costcent_code like concat(loginstk.costcent_code,'%') ".
 			   " where user_account='".$_SESSION['useraccount']."' ".
 			   "";
			  
	$costcentres = mysql_query($querycostcent,$connection) or die(mysql_error());
	$rows=mysql_fetch_array($costcentres);
	$costcent_applyvat = $rows[0];
	if($costcent_applyvat=='')	$costcent_applyvat = 1;

 

 
	$FI_SalesVAT   = $FI_SalesVAT;
	;
	if($FI_SalesVAT==0) $AllowModifyVAT=' disabled ';
	if ($Login_ModifyDiscount == 0)	$DiscountMode = ' readonly ';
			
 		
	if ($PSaId != "") {	
	
    

 
 		/* $sub_query =
		" Select Round(if($SalesTTC=1,ifNull(null,0),ifNull(taxable,0)), ".$DecimalBase."), Round(ifNull(nonetaxable,0), ".$DecimalBase."), ".
					 " Round(if($SalesTTC=1,ifNull(null,0),ifNull(taxable,0)) + ifNull(nonetaxable), ".$DecimalBase.") As GrossTotal, ".
					 " Round(ifNull(Delivery_DiscountPer,0), ".$DecimalBase."), Round(ifNull(Delivery_DiscountAmount,0), ".$DecimalBase."),  ".
					 " ifNull(Delivery_VatChkbx,0) As Delivery_VatChkbx, Round(ifNull(Delivery_VAT,0), ".$DecimalBase.") As Delivery_VAT, ".
					 " Round((if($SalesTTC=1,ifNull(null),ifNull(taxable)) + ifNull(nonetaxable) + if($SalesTTC=1,0,IfNull(Delivery_VAT,0)) + ifNull(Delivery_TransportAmount,0) + IfNull(Delivery_BonusAmount,0) - IfNull(Delivery_DiscountAmount,0) + (ifNull(Delivery_Tax1,0) + ifNull(Delivery_Tax2,0) + ifNull(Delivery_Tax3,0) + ifNull(Delivery_Tax4,0) + ifNull(Delivery_Tax5,0))), ".$DecimalBase.") As Delivery_NetTotal,  ".
					 " Round((ifNull(Delivery_Tax1,0) + ifNull(Delivery_Tax2,0) + ifNull(Delivery_Tax3,0) + ifNull(Delivery_Tax4,0) + ifNull(Delivery_Tax5,0)), ".$DecimalBase.") As TotalTaxes,  ".
					 " Round(if($SalesTTC=1,ifNull(Delivery_TransportTTC,0),ifNull(Delivery_TransportAmount,0)), ".$DecimalBase.") As TransportAmt, ".
					 " Round(if($SalesTTC=1,ifNull(Delivery_BonusTTC,0),ifNull(Delivery_BonusAmount,0)), ".$DecimalBase.") As BonusAmt ".
					 " From temp_transferrequest As Deliveries ".
					 " Where Transferrequest_Id = ".$PSaId;	  	  */
			
		//echo $sub_query;exit;
		
		$sub_query = "select Round(ifnull(taxable,0) ,$DecimalBase)  as taxable , Round(ifnull(nonetaxable,0) ,$DecimalBase) as nonetaxable 
					, Round(ifnull(taxable,0) ,$DecimalBase) + Round(ifnull(nonetaxable,0) ,$DecimalBase)  as GrossTotal
					, Round(ifnull(discountper,0) ,$DecimalBase)    as discountper
					, Round(ifnull(discount,0) ,$DecimalBase)    as discountammount
					, Round(ifnull(vat,0) ,$DecimalBase)    as vat
					, Round(ifnull(taxable,0) ,$DecimalBase) + Round(ifnull(nonetaxable,0) ,$DecimalBase)  +  Round(ifnull(vat,0) ,$DecimalBase)  -  Round(ifnull(discount,0) ,$DecimalBase)";
		
		
		$sub_query .=" from temp_transferRequest where transferRequest_id = $PSaId";
		// echo $sub_query;
		
		$sub_query2 = " Select ifNull(Client_VAT,0) From Clients Where Ledger_Number = '".$txtClientCode."'";			 
		$sub_result2 = selectData($connection, $sub_query2);
		$txtSaVatChk = $sub_result2[0];
		if($costcent_applyvat==0)
			$txtSaVatChk=0;
		
		$sub_result = selectData($connection, $sub_query);
		
		$txtSaTaxable      = $sub_result[0];
		$txtSaNoneTaxable  = $sub_result[1];
		$txtSaGrossTotal   = $sub_result[2];
		$txtSaDiscount     = $sub_result[3];
		$txtSaDiscountAmt  = $sub_result[4];
		$txtSaVat          = $sub_result[5];
		$txtSaNetTotal     = $sub_result[6];

	}else{
		$sub_query = " Select ifNull(Client_VAT,0) From Clients Where Ledger_Number = '".$txtClientCode."'";			 
		$sub_result = selectData($connection, $sub_query);
		$txtSaVatChk = $sub_result[0];
		if($costcent_applyvat==0) $txtSaVatChk=0;
		
	}
	
	echo"<table border='0' style='table-layout:fixed;width:100px' cellspacing=0>
			<tr>
		<td id='total-top' style='width:240px;height:12px;'></td>
		</tr>
		<tr><td id='total-content' style='width:240px;height:12px;'>";
		
	echo"	<table valign='top' border='0' cellspacing=0 cellpadding=0 style='width:240px;'>
			<col width=90>
			<col width=140>
				<tr><td valign='center' align='right' width='40%'><span class='style10'>Taxable</span>&nbsp;</td>
					<td align='left' ><input type='text' id='taxable'  name='txtSaTaxable' value='$txtSaTaxable' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
				</tr>
				<tr><td valign='center' align='right' width='40%'><span class='style10'>None Taxable</span>&nbsp;</td> 
					<td align='left' ><input type='text' id='nontaxable' name='txtSaNoneTaxable' value='$txtSaNoneTaxable' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
				</tr>
				<tr><td valign='center' align='right' width='40%'><span class='style10'>Gross Total</span>&nbsp;</td> 
					<td align='left' ><input type='text' id='grosstotal' name='txtSaGrossTotal' value='$txtSaGrossTotal' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
				</tr>	
				<tr><td valign='center' align='right'  width='40%'><span class='style10'>Discount</span>&nbsp;</td> 
					<td align='left' ><input type='text' id='sadiscount' name='txtSaDiscount' value='$txtSaDiscount' maxlength='5' style='text-align:right; width:38px; height=20px;' onKeyup='CalcSaDiscount(1, $DecimalBase,$VatApplied,$Setup_VatPercentage,$SalesTTC);' $DiscountMode ><span class='style10'> %</span>
						<input type='text' id='sadiscountamt' name='txtSaDiscountAmt' value='$txtSaDiscountAmt' maxlength='20' style='text-align:right; width:58px; height=20px;' onKeyup='CalcSaDiscount(2, $DecimalBase,$VatApplied,$Setup_VatPercentage,$SalesTTC);' $DiscountMode ></td>
				</tr>";
				
	if ($ExportTransportToJV == 1) {
		echo"	<tr><td valign='center' align='right' width='40%' ><span class='style10'>Transport</span>&nbsp;</td> 
					<td align='left' ><input type='text' id='satransportamt' name='txtSaTransportAmt' value='$txtSaTransportAmt' 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='satransportamt' name='txtSaTransportAmt' value='$txtSaTransportAmt'>";
	}	

	if ($ExportBonusToJV == 1) {
		echo"	<tr><td valign='center' align='right' width='40%'><span class='style10'>Bonus</span>&nbsp;</td> 
					<td align='left' ><input type='text' id='sabonusamt' name='txtSaBonusAmt' value='$txtSaBonusAmt' 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='sabonusamt' name='txtSaBonusAmt' value='$txtSaBonusAmt'>";
	}
	
	echo"		<tr><td valign='center' align='right' width='40%' ><span class='style10'>
						<input type='hidden' name='txtSaVatChk' id='txtSaVatChk' value='$txtSaVatChk' size='1'/>
						<input name='chkSaVat' type='checkbox' id='chkSaVat' value='1' onClick='SetSaVat($DecimalBase,$VatApplied,$Setup_VatPercentage,$Module_Delivery,$SalesTTC);changeChkbx();'"; 
						if($txtSaVatChk==1) echo " checked  $AllowModifyVAT />";  else echo " $AllowModifyVAT />"; 
				  
	echo "				VAT $Setup_VatPercentage%&nbsp;</span>
					</td> 
					<td align='left' >
						<input type='text' id='savat' name='txtSaVat' value='$txtSaVat' maxlength='20' style='text-align:right; width:120px; height=20px;' >
					</td>
				</tr>";

	if ($Module_AdditionalTaxes == 1) {
		echo"	<tr>
					<td valign='center' align='right' width='40%'><span class='style10'>Taxes</span>&nbsp;</td> 
					<td align='left' ><input type='text' id='tax' name='txtSaTotalTaxes' value='$txtSaTotalTaxes' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
				</tr>";
	} else {
		echo "	<input type='hidden' name='txtSaTotalTaxes' value='$txtSaTotalTaxes'>";
	}
						
	echo "		<tr><td valign='middle' align='right' width='40%'><span class='style10'>Net Total</span>&nbsp;</td> 
					<td align='left' ><input type='text' id='nettotal' name='txtSaNetTotal' value='$txtSaNetTotal' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;";
					
			if($txtSaNetTotal<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>";
				
	/*				
	if($txtSaDiscount_Temp!=''){
	
	 
		print <<<HERE
				<script type="text/javascript" language="javascript">
				CalcSaDiscount(1, $DecimalBase,$VatApplied,$Setup_VatPercentage,$SalesTTC)	
				</script>
HERE;
}*/

}







function ShowTransferRequestDtGrid2($connection,$form,$transferrequest_id,$orderby,$startrange,$perpage,$option,$direction,$base1,$base2,$DecimalBase,$Module_DoubleUnit,$Module_ProjectDt,$Module_CostCenterDt,$PriceLabel,$Module_Unit1Method,$PurchaseTTC,$Module_TransferWithOneWh,$FIPurchaseCategory,$Module_TransferRequestPrice,$showBatch, $Module_Heatno){



 
 
	$querylog=" select language".
          " 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);
}

	$querylang="select language, Reference, Project, Warehouse, Date as date_label, from_date, to_date, 
			Driver_Name as driver_label, Vehicle_No as vehicle_label, Remark,
			 Item, Description, Packaging_Nbr, nb_of_unit, qty, Unit, qtyexist, batchnb, heatnb,
			 From_warehouse, to_warehouse, Price, totalamount
	from ".$_SESSION['dbLabel'].".transferrequest_label where 
			language='$language'";

//echo $querylang;
$resultlang=mysql_query($querylang,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlang)){
		extract($rows);
		
	}


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

	if ($perpage=='')
		$perpage = 20;
	
		
	$columnsarray = array("p_item_code","p_item_description");
	
	if($showBatch == 1){
		$columnsarray[] = 'p_transferdt_packagingno';
		$columnsarray[] = 'p_transferdt_nbrunit';
	}
	$columnsarray[] = 'p_item_quantity';
	if ($Module_DoubleUnit==1) {
		$columnsarray[] = 'Item_Unit2Qty';
	}
	$columnsarray[] = 'p_item_price';			
	if ($Module_TransferRequestPrice==1)
		$columnsarray[] = 'p_item_sellingprice1';
			
	if ($Module_TransferWithOneWh!=1) {
		$columnsarray[] = 'fromwarehouse';
		$columnsarray[] = 'towarehouse';
	}
		
	if($showBatch == 1){
		$columnsarray[] = 'p_transferdt_batchno';
	}	
	if($Module_Heatno == 1){
		$columnsarray[] = 'p_transferdt_heatno';
	}
			
		$columnsarray[] = "p_transferdt_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 = 'prqstdt_id';
	
	
	  
			$query = " Select a.TransferrequestDt_id,a.Transferrequest_Id,a.Transferrequest_Date,a.Item_code,a.TransferrequestDt_WarehouseFrom,
						a.TransferrequestDt_WarehouseTo,a.TransferrequestDt_Quantity,a.TransferrequestDt_Price as Price,a.Project_Code1,a.Project_Code2
						,a.Transferrequestdt_remark,items.item_description,items.item_withserialno
						,Logged_Code ,null,Items.Item_UnitSalesDesc ,Items.Item_UnitPurchaseDesc,Item_Unit2Qty,
						TransferrequestDt_BatchNo,TransferrequestDt_packagingNo,TransferrequestDt_nbrUnit, transferrequestdt_heatno
						from temp_transferrequestdt as a,items
						where transferrequest_id = '".$transferrequest_id."'
						and a.item_code=items.item_code
						order by transferrequestdt_id asc
						";
						//echo $query;
 


// echo $query;exit;
$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='main' >";
echo"	<div id='Loader' class=''><div></div></div>";
echo"<div id='prequestdtdiv' style='overflow:auto;width:1100px;height:200px;border:0px solid #000000;'>";
$widthTable = 970;
if ($showBatch == 1)   $widthTable += 150;
if ($Module_DoubleUnit==1) $widthTable += 270;
if ($Module_TransferWithOneWh!=1) $widthTable += 220;
if ($showBatch == 1) $widthTable += 120;
if ($Module_Heatno == 1) $widthTable += 115;

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

    echo"  <col width=30><col width=170><col width=320>";
	if ($showBatch == 1)   echo"<col width=75><col width=75>";
	echo "<col width=90><col width=90>";
	if ($Module_DoubleUnit==1)	 echo"<col width=100> <col width=170>"; 
	if ($Module_TransferWithOneWh!=1)   echo"<col width=120><col width=120>";

	if ($showBatch == 1)   echo"<col width=120>";
	if ($Module_Heatno == 1)   echo"<col width=115>";
	 echo"<col width=90><col width=250> <col width = 30>";

	

		  
	echo"<tr height='25px'>";
	echo"  <th bgcolor='#F7F7F7' align='left'>&nbsp;</th>";
	echo"  <th bgcolor='#F7F7F7' align='left'>$Item</th>";  
	echo"  <th bgcolor='#F7F7F7' align='left'>$Description</th>";
	if($showBatch == 1){
		echo"  <th bgcolor='#F7F7F7' align='center'>$Packaging_Nbr .</th>";			  
		echo"  <th bgcolor='#F7F7F7' align='center'>$nb_of_unit</th>";
	}
	echo"  <th bgcolor='#F7F7F7' align='left'>$qty</th>";
	echo"  <th bgcolor='#F7F7F7' align='left'>Price</th>";
	//   echo"  <th bgcolor='#F7F7F7' align='left'>$Unit</th>"; 
	//   echo"  <th bgcolor='#F7F7F7' align='left'>$qtyexist</th>";
	echo"  <th bgcolor='#F7F7F7' align='left'>Total</th>";		
		//echo"  <td bgcolor='#F7F7F7' align='left'><span class='style27'>Real Qty</td>";
		  
	if ($Module_DoubleUnit==1) {
		echo"  <th bgcolor='#F7F7F7' align='left'>$qty 2</th>";
		echo"  <th bgcolor='#F7F7F7' align='left'>$Unit 2</th>";
	}
		  
	if ($Module_TransferRequestPrice==1)
		echo"  <th bgcolor='#F7F7F7' align='center'>$Price</th>";
		  
	if ($Module_TransferRequestPrice==1)
		echo"  <th bgcolor='#F7F7F7' align='left'>$totalamount</th>";	  
	if ($Module_TransferWithOneWh!=1) {
		echo"  <th bgcolor='#F7F7F7' align='center'>$From_warehouse</th>";
		echo"  <th bgcolor='#F7F7F7' align='center'>$to_warehouse</th>";
	}
	if($showBatch == 1){
		echo"  <th bgcolor='#F7F7F7' align='center'>$batchnb</th>";
	}
	if ($Module_Heatno == 1) 	
	echo"  <th bgcolor='#F7F7F7' align='center'>$heatnb</th>";
	echo"  <th bgcolor='#F7F7F7' align='left'>$Remark</th>";	  
	echo"  <th bgcolor='#F7F7F7' align='left'>&nbsp;</th>";	  

	echo"</tr>";



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

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


						
						
	$transferrequestdt_id[$i] = $row[0];
	$transferrequestid[$i] = $row[1];
	//  $itemunitsalesdesc[$i] =  $row[0];
	$transferrequest_date[$i] = $row[2];
	$p_item_code[$i] = $row[3];
	$p_item_description[$i] = $row[11];
	$p_item_quantity[$i] = $row[6];
	$Item_Unit2Qty[$i] = $row[17];
	$p_item_sellingprice1[$i] = $row[7];
	$fromwarehouse[$i] = $row[4];
	$towarehouse[$i] = $row[5];
	$p_transferdt_remark[$i] = $row[10];
	$Item_UnitSalesDesc[$i] = $row[15];
	$Item_UnitPurchaseDesc[$i] = $row[16];
	
	$p_transferdt_batchno[$i] = $row[18];
	$p_transferdt_packagingno[$i] = $row[19];
	$p_transferdt_nbrunit[$i] = $row[20];
	$p_transferdt_heatno[$i] = $row[21]; // price 22
	$p_item_price[$i] = $row[7];
	
			
	//echo"<tr height='20px' id='prqstdt$i' onclick=\"returncolor(this,'SelectedRec','SelectedRecColor','$row[0]')\" style='background-color:$bgcolor'>";
	echo"<tr height='30px'  id='CurRec$i' class='$bgcolor table-focus-g1'>";

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

		
	echo"<td align='center'><span class='style4'><input type='text'   name='p_item_code[$i]' id='p_item_code[$i]' value='".$p_item_code[$i]."'   $KeyDown   class='roundedtext_amortization_small'   onchange=\"setitemcode(this.value,'p_item_code[$i]','p_item_description[$i]','Item_Unit[$i]','itemunitsalesdesc[$i]','itemunitpurchasedesc[$i]','i_unitcoef[$i]','','trqstdtitemcodeimage[$i]','trqstdtitemcodeimage1[$i]',1);SetModRecord('ModRec_G1','$i')\"  style='width:140px'></span>
		<img src='img/scroll-down-1.png' width='20' height='20' id='trqstdtitemcodeimage[$i]' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('itemcode','p_item_code[$i]','p_item_description[$i]','Item_Unit[$i]','itemunitsalesdesc[$i]','','','txtAvailableQty[$i]','800','500','".htmlentities($fromwarehouse[$i])."','$TransType')\">
			</td>";

	echo"<td align='center'><span class='style4'><input type='text' name='p_item_description[$i]' id='p_item_description[$i]' value='".$p_item_description[$i]."'  class='roundedtext_amortization_mediumlarge'    $KeyDown     onchange=\"setitemcode(this.value,'p_item_code[$i]','p_item_description[$i]','Item_Unit[$i]','itemunitsalesdesc[$i]','itemunitpurchasedesc[$i]','i_unitcoef[$i]','','trqstdtitemcodeimage[$i]','trqstdtitemcodeimage1[$i]',2);SetModRecord('ModRec_G1','$i')\" style='width:300px'> </span>
	<img src='img/scroll-down-1.png' width='20' hidden height='20' id='trqstdtitemcodeimage1[$i]' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage1('itemcode','p_item_code[$i]','p_item_description[$i]','Item_Unit[$i]','itemunitsalesdesc[$i]','itemunitpurchasedesc[$i]','i_unitcoef[$i]','800','500','".htmlentities($fromwarehouse[$i])."','$TransType')\">	
	";
	
	echo"</td>";

	{
		$data = substr($transferrequest_date[$i], 6, 4) . substr($transferrequest_date[$i], 3, 2) . substr($transferrequest_date[$i], 0, 2);
		
		$transfer_date1[$i] = substr($transferrequest_date[$i], 0, 10)." ".strftime("%H").":".strftime("%M").":".strftime("%S");
		//echo $transfer_date[$i]."<br>";

		$qry="select item_pack from items where item_code = '".$p_item_code[$i]."'";
		$resultlog=mysql_query($qry,$connection) or die(mysql_error());
			while($rows=mysql_fetch_array($resultlog)){
				extract($rows);
			}

		$min_sorder_qty[$i] = 0;
		$min_available_qty[$i] = 9999999999;
		$min_exists_qty[$i] = 9999999999;
		$available_qty[$i] = 0;
		$exist_qty[$i] = 0;
		
		if (empty($transferrequestdt_id)) $transferrequestdt_id = 0;
			$Qry_QtyAvailable[$i] = " Select QtyExistsWSorder_Temp('".$p_item_code[$i]."', '".$fromwarehouse[$i]."', '".$transferrequest_date[$i]."', 0, 'TR', '', '', 0) QtyExists From Dual ";
							
			$resultq = selectData($connection, $Qry_QtyAvailable[$i]);
			$min_available_qty[$i] = $resultq[0];
		
		$txtAvailableQty[$i] = $min_available_qty[$i]  - $resultTemp[0];
	
		$errorquantity=0;
		$PostNotAllowed='False';
		if (($txtAvailableQty[$i]	< $row[6] ) and (($Module_NegativeQuantity==0) or ($Login_negativeQty==0)) ){
			$PostNotAllowed='True';
			$errorquantity=1;
		}
	}
	if($showBatch == 1){
		echo"<td  align='center'><span class='style4'><input type='text'   $KeyDown     name='p_transferdt_packagingno[$i]' id='p_transferdt_packagingno[$i]' value='".$p_transferdt_packagingno[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" onkeyup=\"setQty('$i');\" style='width:70px;'> </span></td>";
		echo"<td  align='center'><span class='style4'><input type='text'   $KeyDown     name='p_transferdt_nbrunit[$i]' id='p_transferdt_nbrunit[$i]' value='".$p_transferdt_nbrunit[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" onkeyup=\"setQty('$i');\" style='width:70px;'> </span></td>";
	}else{
		echo "<input type='hidden'  name='p_transferdt_packagingno[$i]' id='p_transferdt_packagingno[$i]' value=''>";
		echo "<input type='hidden'  name='p_transferdt_nbrunit[$i]' id='p_transferdt_nbrunit[$i]' value=''>";
	}
	echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'   name='p_item_quantity[$i]' id='p_item_quantity[$i]' value='".$p_item_quantity[$i]."' style='width:80px'  onchange=\"changeqty2(1,'$Item_Unit','$Module_Unit1Method',$i);SetModRecord('ModRec_G1','$i');calcTotal('p_item_sellingprice1[$i]','p_item_quantity[$i]',$i);calTotal('$i')\" > </span></td>";
	
	
	// by rod 
	echo"<td  align='center' >
	<span class='style4'>
	<input type='text'   $KeyDown   class='roundedtext_amortization_small'   name='p_item_price[$i]' id='p_item_price[$i]' 
	value='".$p_item_price[$i]."' style='width:80px'  onchange=\"changeqty2(1,'$Item_Unit','$Module_Unit1Method',$i);
	SetModRecord('ModRec_G1','$i');calcTotal('p_item_sellingprice1[$i]','p_item_price[$i]',$i);calTotal('$i')\" > </input> 
	
	</span></td>";
	// end by rod
	$itemtotalprice[$i] = $p_item_quantity[$i] * $p_item_price[$i];
	// echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'   name='itemunitsalesdesc[$i]' id='itemunitsalesdesc[$i]' value='".$Item_UnitSalesDesc[$i]."' style='width:80px'  onchange=\"SetModRecord('ModRec_G1','$i');\" > </span></td>";
	// echo"<td align='center'><input type='text' name='txtAvailableQty[$i]' readonly id='txtAvailableQty[$i]' value='".$txtAvailableQty[$i]."' readonly style='border-width:0px' size=4></td>";
	echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'   name='itemtotalprice[$i]' id='itemtotalprice[$i]' value='".$itemtotalprice[$i]."' style='width:80px'  onchange=\"SetModRecord('ModRec_G1','$i')\" readonly> </span></td>";
	
	if ($Module_DoubleUnit==1) {
		echo"<td align='center'><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='Item_Unit2Qty[$i]'    onchange=\"changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i);calcTotal('p_item_sellingprice1[$i]','p_item_quantity[$i]',$i)\"   style='width:68px'  id='Item_Unit2Qty[$i]'  value='".$Item_Unit2Qty[$i]."'  size=4> </td>";
		echo"<td align='center'><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='Item_UnitPurchaseDesc[$i]'    onchange=changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i)   style='width:68px'  id='Item_UnitPurchaseDesc[$i]'  value='".$Item_UnitPurchaseDesc[$i]."'  size=4> </td>";
	}else{
		echo"<input type='hidden' name='Item_Unit2Qty[$i]'  id='Item_Unit2Qty[$i]'  onchange=changeqty2(2,'$Item_Unit[$i]',$Module_Unit1Method,$i)  value='".$Item_Unit2Qty[$i]."'  size=4>";
		
	}

	echo"	  <input type='hidden' name='p_item_quantity1[$i]'  id='p_item_quantity1[$i]' value='".$p_item_quantity1[$i]."'  size=4>";
	echo"	  <input type='hidden' name='Item_Unit[$i]' id='Item_Unit[$i]' value='".$Item_Unit[$i]."'  size=4>";
			
	$amount = '';
	$amount = $row[6] * $row[7];
			

	//$totalamount = $totalamount + $amount;
			
	if($Module_TransferRequestPrice==1)
		echo"<td align='center'><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='p_item_sellingprice1[$i]'    onchange=calcTotal('p_item_sellingprice1[$i]','p_item_quantity[$i]',$i)   style='width:80px'  id='p_item_sellingprice1[$i]'  value='".$p_item_sellingprice1[$i]."'  size=4> </td>";
	else
		echo"<input type='hidden'  name='p_item_sellingprice1[$i]'    onchange=calcTotal('p_item_sellingprice1[$i]','p_item_quantity[$i]',$i)   style='width:80px'  id='p_item_sellingprice1[$i]'  value='".$p_item_sellingprice1[$i]."'  size=4>";
	
	
	if($Module_TransferRequestPrice==1)
		echo"<td align='center'><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='amount[$i]'    onchange=changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i)   style='width:80px'  id='amount[$i]'  value='".$amount."'  size=4> </td>";
	else
		echo"<input type='hidden' name='amount[$i]'    onchange=changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i)   style='width:80px'  id='amount[$i]'  value='".$amount."'  size=4>";
		
	if ($Module_TransferWithOneWh==1)
		echo"<input type='hidden' name='fromwarehouse[$i]' id='fromwarehouse[$i]' value='".$fromwarehouse[$i]."' ;\"  > ";
	else{
		echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:80px'  name='fromwarehouse[$i]' id='fromwarehouse[$i]' value='".$fromwarehouse[$i]."' onchange=\"setwarehousecode(this.value,'fromwarehouse[$i]','imgwarehousebtn[$i]');SetModRecord('ModRec_G1','$i');\"  > </span>";
		
		echo"<img src='img/scroll-down-1.png' title=' Select Warehouse ' id='imgwarehousebtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistWarehouse('fromwarehouse','fromwarehouse[$i]','800','500') \" />
		</td>";
	}
	if ($Module_TransferWithOneWh==1)
	echo"<input type='hidden' name='towarehouse[$i]' id='towarehouse[$i]' value='".$towarehouse[$i]."' ;\"  > ";
	else{
	echo"<td align='center' ><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:80px'  name='towarehouse[$i]' id='towarehouse[$i]' value='".$towarehouse[$i]."' onchange=\"setwarehousecode(this.value,'towarehouse[$i]','imgwarehousebtn1[$i]');SetModRecord('ModRec_G1','$i');\"  > </span>
	<img src='img/scroll-down-1.png' title=' Select Warehouse ' id='imgwarehousebtn1[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistWarehouse('towarehouse','towarehouse[$i]','800','500') \" />
	</td>";
	}
		if($showBatch == 1){
			echo"<td align='center' ><span class='style4'><input type='text'   $KeyDown     name='p_transferdt_batchno[$i]' id='p_transferdt_batchno[$i]' value='".$p_transferdt_batchno[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" style='width:95px;' > </span>
			<label><span><img src='img/openlist.png' title='Select Batch No' id='lstBatchNo[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistBatchNo(2,$i); ' style='vertical-align:bottom;'/></span></label></td>";
	} else {
			echo "<input type='hidden'  name='p_transferdt_batchno[$i]' id='p_transferdt_batchno[$i]' value=''>";
		}
	if ($Module_Heatno == 1) {
			echo"<td align='center' ><span class='style4'><input type='text'   $KeyDown     name='p_transferdt_heatno[$i]' id='p_transferdt_heatno[$i]' value='".$p_transferdt_heatno[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" style='width:85px;' > </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='p_transferdt_heatno[$i]' id='p_transferdt_heatno[$i]' value=''>";
		} 
	echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   name='p_transferdt_remark[$i]' id='p_transferdt_remark[$i]' value='".$p_transferdt_remark[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" style='width:245px;' > </span></td>";
	
	echo"<td align='center'><img src='img/confirm.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitPTransReqDt[$i]' title='Save' onclick=\"submitTransReqDt('$transferrequestdt_id[$i]','$transferrequestid[$i]','$i','e','$PurchaseTTC','$FIPurchaseCategory','$filepath')\"></td>";
	echo"<input type='hidden'  name='transferrequestdt_id[$i]' id='transferrequestdt_id[$i]' value='".$transferrequestdt_id[$i]."' >";
	echo"</tr>";
	
	$i+=1;
}
		
	if (empty($warehousecode[$i])) { 
		if(!empty($_SESSION['prqstsetupdefaultWareHouse'] ))
			$warehousecode[$i] = $_SESSION['prqstsetupdefaultWareHouse'] ;
		else	
			$warehousecode[$i] = $_SESSION['prqstdefaultwarehouse'];
	}
			
	$k=1;
	$morelines = 1;
	//echo $morelines;
	while ($k <= $morelines){
		$recno = $i+1;
		if ($k==$morelines)
			$mode = 'i';
		else
			$mode = 'e';			
		
		$KeyDown   = 'onkeydown="return dokeytransferrequest(event,this,'.$i.',\''.$columnslist.'\',\'PTransReqDt\');"';

		echo"<tr height='30px' id='CurRec$i' class='$bgcolor table-focus-g1'>";
		echo"<td align=center><img src='img/undo-1.png' width=20 height=20 onmouseover=\"style.cursor='pointer'\" name='' title='Clear' onclick=\"clearprequestdt('$i','$PurchaseTTC','$Module_DoubleUnit')\"></td>";
		
		echo"<td align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'   onchange=\"setitemcode(this.value,'p_item_code[$i]','p_item_description[$i]','Item_Unit[$i]','itemunitsalesdesc[$i]','itemunitpurchasedesc[$i]','i_unitcoef[$i]','','trqstdtitemcodeimage[$i]','trqstdtitemcodeimage1[$i]',1);SetModRecord('ModRec_G1','$i')\"  onblur=\"FillData('fromwarehouse[$i]','towarehouse[$i]')\"  name='p_item_code[$i]' id='p_item_code[$i]' value='".$p_item_code[$i]."' style='width:140px'></span>
			<img src='img/scroll-down-1.png' width='20' height='20' id='trqstdtitemcodeimage[$i]' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage('itemcode','p_item_code[$i]','p_item_description[$i]','Item_Unit[$i]','itemunitsalesdesc[$i]','','','txtAvailableQty[$i]','800','500','".htmlentities($fromwarehouse[$i])."','$TransType');FillData('fromwarehouse[$i]','towarehouse[$i]')\">
				</td>";

		echo"<td align='center'><span class='style4'><input type='text'   class='roundedtext_amortization_mediumlarge'    $KeyDown     onchange=\"setitemcode(this.value,'p_item_code[$i]','p_item_description[$i]','Item_Unit[$i]','itemunitsalesdesc[$i]','itemunitpurchasedesc[$i]','i_unitcoef[$i]','','prqstdtitemcodeimage[$i]','trqstdtitemcodeimage1[$i]',2);SetModRecord('ModRec_G1','$i')\"     name='p_item_description[$i]' id='p_item_description[$i]' value='".$p_item_description[$i]."' style='width:300px'> </span>
		<img src='img/scroll-down-1.png' width='20' hidden height='20' id='trqstdtitemcodeimage1[$i]' onmouseover=\"style.cursor='pointer'\"  onclick=\"showsearchpage1('itemcode','p_item_code[$i]','p_item_description[$i]','Item_Unit[$i]','itemunitsalesdesc[$i]','itemunitpurchasedesc[$i]','i_unitcoef[$i]','800','500','".htmlentities($fromwarehouse[$i])."','$TransType')\">	";
			
	
		echo"</td>";
		if($showBatch == 1){
				 echo"<td  align='center'><span class='style4'><input type='text'   $KeyDown     name='p_transferdt_packagingno[$i]' id='p_transferdt_packagingno[$i]' value='".$p_transferdt_packagingno[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" onkeyup=\"setQty('$i');\" style='width:70px;'> </span></td>";
				 echo"<td  align='center'><span class='style4'><input type='text'   $KeyDown     name='p_transferdt_nbrunit[$i]' id='p_transferdt_nbrunit[$i]' value='".$p_transferdt_nbrunit[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" onkeyup=\"setQty('$i');\" style='width:70px;'> </span></td>";
		} else {
				 echo "<input type='hidden'  name='p_transferdt_packagingno[$i]' id='p_transferdt_packagingno[$i]' value=''>";
				 echo "<input type='hidden'  name='p_transferdt_nbrunit[$i]' id='p_transferdt_nbrunit[$i]' value=''>";
		}			
		echo"<td  align='center' >
			<span class='style4'>
			<input type='text'   $KeyDown   class='roundedtext_amortization_small'   name='p_item_quantity[$i]' id='p_item_quantity[$i]' 
			value='0' style='width:80px'  onchange=\"changeqty2(1,'$Item_Unit','$Module_Unit1Method',$i);
			SetModRecord('ModRec_G1','$i');calcTotal('p_item_sellingprice1[$i]'	,'p_item_quantity[$i]',$i);calTotal('$i')\" > </input> 
			
			</span></td>";
	

	// by rod 
		echo"<td  align='center' >
		<span class='style4'>
		<input type='text'   $KeyDown   class='roundedtext_amortization_small'   name='p_item_price[$i]' id='p_item_price[$i]' 
		value='0' style='width:80px'  onchange=\"changeqty2(1,'$Item_Unit','$Module_Unit1Method',$i);
		SetModRecord('ModRec_G1','$i');calcTotal('p_item_sellingprice1[$i]','p_item_price[$i]',$i);calTotal('$i')\" > </input> 
		
		</span></td>";
		// end by rod
	
	
		//echo"<td  align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_small'   name='itemunitsalesdesc[$i]' id='itemunitsalesdesc[$i]' value='".$Item_UnitSalesDesc[$i]."' style='width:80px'  onchange=\"SetModRecord('ModRec_G1','$i');\" > </span></td>";
		$itemtotalprice[$i] = $p_item_quantity[$i] * $p_item_price[$i];
		echo"<td  align='center'><span class='style4'><input type='text' $KeyDown class='roundedtext_amortization_small' name='itemtotalprice[$i]' id='itemtotalprice[$i]' value='".$itemtotalprice[$i]."' style='width:80px' value='0' onchange=\"SetModRecord('ModRec_G1','$i');\" readonly> </span></td>";

	
	
	
		if ($Module_DoubleUnit==1) {
			echo"<td  align='center'><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='Item_Unit2Qty[$i]'    onchange=\"changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i);calcTotal('p_item_sellingprice1[$i]','p_item_quantity[$i]',$i);\"   style='width:68px'  id='Item_Unit2Qty[$i]'  value='".$Item_Unit2Qty[$i]."'  size=4> </td>";
			echo"<td  align='center'><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='Item_UnitPurchaseDesc[$i]'    onchange=changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i)   style='width:68px'  id='Item_UnitPurchaseDesc[$i]'  value='".$Item_UnitPurchaseDesc[$i]."'  size=4> </td>";
		}
		else {
			echo"<input type='hidden' name='Item_Unit2Qty[$i]'  id='Item_Unit2Qty[$i]'  onchange=changeqty2(2,'$Item_Unit[$i]',$Module_Unit1Method,$i)  value='".$Item_Unit2Qty[$i]."'  size=4>";
		}

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

		if ($rowsdt[6]=='')		$rowsdt[6] = 0;
		if ($rowsdt[7]=='') 	$rowsdt[7] = 0;
		
			
		$amount[$i] = $rowsdt[6] * $rowsdt[7];
		//$totalamount = $totalamount + $amount;
				
		if($Module_TransferRequestPrice==1)
			echo"<td  align='center'><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='p_item_sellingprice1[$i]'    onchange=\"changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i);calcTotal('p_item_sellingprice1[$i]','p_item_quantity[$i]',$i)\"   style='width:80px'  id='p_item_sellingprice1[$i]'  value='".$p_item_sellingprice1[$i]."'  size=4> </td>";
		else
			echo"<input type='hidden' name='p_item_sellingprice1[$i]'    onchange=\"changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i);calcTotal('p_item_sellingprice1[$i]','p_item_quantity[$i]',$i)\"   style='width:80px'  id='p_item_sellingprice1[$i]'  value='".$p_item_sellingprice1[$i]."'  size=4>";

		if($Module_TransferRequestPrice==1)	
			echo"<td  align='center'><input type='text' $KeyDown   class='roundedtext_amortization_medium' name='amount[$i]'    onchange=changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i)   style='width:80px'  id='amount[$i]'  value='".$amount[$i]."'  size=4> </td>";
			else
			echo"<input type='hidden' name='amount[$i]'    onchange=changeqty2(2,'$Item_Unit',$Module_Unit1Method,$i)   style='width:80px'  id='amount[$i]'  value='".$amount[$i]."'  size=4>";
		
		
			
		if ($Module_TransferWithOneWh==1)
			echo"<input type='hidden' name='fromwarehouse[$i]' id='fromwarehouse[$i]' value='".$fromwarehouse[$i]."' ;\"  > ";
		else{
			echo"<td  align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:80px'  name='fromwarehouse[$i]' id='fromwarehouse[$i]' value='".$fromwarehouse[$i]."' onchange=\"setwarehousecode(this.value,'fromwarehouse[$i]','imgwarehousebtn[$i]');SetModRecord('ModRec_G1','$i');\"  > </span>";
			echo"<img src='img/scroll-down-1.png' title=' Select Warehouse ' id='imgwarehousebtn[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistWarehouse('fromwarehouse','fromwarehouse[$i]','800','500') \" />
			</td>";
		}
		
		if ($Module_TransferWithOneWh==1)
			echo"<input type='hidden' name='towarehouse[$i]' id='towarehouse[$i]' value='".$towarehouse[$i]."' ;\"  > ";
		else {
			echo"<td  align='center'><span class='style4'><input type='text'   $KeyDown   class='roundedtext_amortization_medium'   style='width:80px'  name='towarehouse[$i]' id='towarehouse[$i]' value='".$towarehouse[$i]."' onchange=\"setwarehousecode(this.value,'towarehouse[$i]','imgwarehousebtn1[$i]');SetModRecord('ModRec_G1','$i');\"  > </span>
				<img src='img/scroll-down-1.png' title=' Select Warehouse ' id='imgwarehousebtn1[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onclick=\"showlistWarehouse('towarehouse','towarehouse[$i]','800','500') \" />
				</td>";
		}
			if($showBatch == 1){
				echo"<td align='center' ><span class='style4'><input type='text'   $KeyDown     name='p_transferdt_batchno[$i]' id='p_transferdt_batchno[$i]' value='".$p_transferdt_batchno[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" style='width:95px;' > </span>
				<label><span><img src='img/openlist.png' title='Select Batch No' id='lstBatchNo[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistBatchNo(2,$i); ' style='vertical-align:bottom;'/></span></label></td>";
			} else {
				echo "<input type='hidden'  name='p_transferdt_batchno[$i]' id='p_transferdt_batchno[$i]' value=''>";
			}
		if ($Module_Heatno == 1) {
				echo"<td align='center' ><span class='style4'><input type='text'   $KeyDown     name='p_transferdt_heatno[$i]' id='p_transferdt_heatno[$i]' value='".$p_transferdt_heatno[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\" style='width:85px;' > </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='p_transferdt_heatno[$i]' id='p_transferdt_heatno[$i]' value=''>";
			}	
		echo"<td  align='center'><span class='style4'><input type='text'   $KeyDown     name='p_transferdt_remark[$i]' id='p_transferdt_remark[$i]' value='".$p_transferdt_remark[$i]."' onchange=\"SetModRecord('ModRec_G1','$i');\"  style='width:245px;'> </span></td>";
			
		echo"<td  align='center'><img src='img/confirm.png' onmouseover=\"style.cursor='pointer'\" name='' id='imgSubmitPTransReqDt[$i]' title='Save' onclick=\"return submitTransReqDt('$transferrequestdt_id[$i]','$transferrequestid[$i]','$i','i','$PurchaseTTC','$FIPurchaseCategory','$filepath');\"></td>";
		echo"<input type='hidden'  name='txtPreqDTId[$i]' id='txtPreqDTId[$i]' value='".$txtPreqDTId[$i]."' >";
		echo"</tr>";
		$i+=1;
		$k+=1;
	}	
	
	echo"</table></div></div>";
	

	

}

?>
