<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("Functions_Trans.php");
//include("Forms_DataGrid.php");
include("Forms_RMA_DataGrid.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}
$query_language  = "select user_account, Language from ".$_SESSION['dbLabel'].".login  where user_account = '".$_SESSION['useraccount']."'";
$result_language = mysql_query($query_language, $connection); 
$row_language    = mysql_fetch_array($result_language);
extract($row_language);

$query_journal_labels  = "select Language, label0 as Ref1, TypeRef as TypeRef1, label3 as Folio1, label2 as Date1, label1 as Type1, Project as Project1, Disp_2_1 as Costcenter2, Remark as Remark1, ManualNo as ManualNo1, Disp_1 as LedgerNo1, LedgerName as LedgerName1, Disp_4_1 as DescX, Disp_3 as Curr1, D_C as DC1, Disp_5 as Amount1, Disp_1_3 as ValueDate1, ManualNo as ManualNo1, Desc1 as Desc1,
                          NoRecords, Perpage, Page, Disp_2_2 as Perce, Disp_1_1 as CheckNo, Disp_1_2 as Bankk, Label4 as Debitt, Label5 as Creditt, Disp_4 as Balancee
                          from ".$_SESSION['dbLabel'].".journal_label
                          where Language = '".$Language."'";
$result_journal_labels = mysql_query($query_journal_labels, $connection);
$row_journal_labels    = mysql_fetch_array($result_journal_labels);
extract($row_journal_labels);

$_SESSION['query_journal_labels'] = $query_journal_labels;

$query_navigator = "SELECT LANGUAGE,
       ClearPage,
       Excel,
       Save,
       Print,
       Addd,
       Search,
       Pending,
       CopyJV,
       PaymentRequests,
       ExportExcel,
	   cancell
FROM ".$_SESSION['dbLabel'].".mainform_label
WHERE LANGUAGE = '".$Language."'";
$result_navigator = mysql_query($query_navigator, $connection);
$row_navigator    = mysql_fetch_array($result_navigator);
extract($row_navigator);

//echo $Costcenter1; exit;
$query_project  = "select Journal as Journal1, ResultsPage as ResultsPage1
                   from ".$_SESSION['dbLabel'].".mainform_label
				   where Language = '".$Language."'";
$result_project = mysql_query($query_project, $connection);
$row_project    = mysql_fetch_array($result_project);
extract($row_project);

$querylog="SELECT FA_Journal as loginaccess 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);
}
if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
	
$querylog=" select ifNull(FA_JournalApp,0) As FA_JournalApp, ifNull(Login_FastPrint,0) As Login_FastPrint, ifNull(FA_LedgerAccess,0) As FA_LedgerAccess ".
		  " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

	
//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, Journal_DefaultCur ".
             " from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_RestrictProjCost,0) As Module_RestrictProjCost, ifNull(Module_RestrictCost,0) As Module_RestrictCost, ".
			 " ifNull(Module_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt, ".
			 " ifNull(module_referencebycostcenter,0) As Module_ReferenceByCostCenter, ".
			 " ifNull(module_checks,0) As Module_checks, ".
			 " ifNull(Module_ShowBalance,0) As Module_ShowBalance, ifNull(Module_ImportExcell,0) As Module_ImportExcell, ifNull(Module_bill,0) As Module_bill ".
			" ,ifNull(module_journalRate,0) As module_journalRate,ifNull(module_ledgerrestrictcur,0) As module_ledgerrestrictcur  ".	
			" From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

//Read From TransSetup Table							
$querytranssetup= " select DefaultCur, DefaultProject as StpDefaultProject, DefaultCostcenter as StpDefaultCostcenter, ifnull(Hide_ValueDate,0) Hide_ValueDate,  ifnull(Hide_Base2,0) Hide_Base2
					from transsetup where JournalType = 'JV'";
$resulttranssetup=mysql_query($querytranssetup,$connection) or die(mysql_error());
while($rowtranssetup=mysql_fetch_array($resulttranssetup)){
	extract($rowtranssetup);
}

/// Journal Type
$queryjourtype="select type_name from jourtype where ifnull(type_visible,0) = 1 ";
$resultjourtype=mysql_query($queryjourtype,$connection)	or die( mysql_error($connection));



//Get Default Project
$querydflproject="select project_code as defaultproject from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_project=1 ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}

//Get Default Coscenter
$querydflcostcent="select costcent_code as defaultcostcent from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_costcenter=1 ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}

$vMainCompanyName=explode('_',$_SESSION['dbName']);  
$DirCompany  = $vMainCompanyName[0];
preg_match_all('!\d+!', $vMainCompanyName[1] ,$DirYears );
$fromdate =  '01/01/'.$DirYears[0][0];
$todate = date('d/m/Y'); 


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


<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


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

<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>

<script type="text/javascript" src="js/tabsClass/tabber.js"></script>
<link rel="stylesheet" href="js/tabsClass/tabber.css" type="text/css" />

<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" language="javascript">
$(document).ready(function() { 
		
		$(document).on('focus', '.date', function() {
			$('.date').datepick({showTrigger: '#calImg'});
		});
		
		$(document).on('focusin', '.table-focus-g1', function() {
			AutoSaveRecordGrid(this.id,'SelectedRec','ModRec_G1','imgSubmit');
			selRecordColor(this,'SelectedRec','SelectedRecColor');
		});
		$(document).on('focusin', '.table-focus-g2', function() { 
			AutoSaveRecordGrid(this.id,'SelectedRec_G2','ModRec_G2','imgSubmit_D');
			selRecordColor(this,'SelectedRec_G2','SelectedRecColor_G2');
		});
		$(document).on('focusin', '.table-focus-g3', function() {
			AutoSaveRecordGrid(this.id,'SelectedRec_G3','ModRec_G3','imgSubmit_C');
			selRecordColor(this,'SelectedRec_G3','SelectedRecColor_G3');
		});
		$(document).on('focusin', '.table-focus-g4', function() {
			AutoSaveRecordGrid(this.id,'SelectedRec_G4','ModRec_G4','imgSubmit_B');
			selRecordColor(this,'SelectedRec_G4','SelectedRecColor_G4');
		});
});	
function clearPage(){
	var c = confirm("Are you sure?");
	if(c){
		document.location.href="Form_ReturnRMA.php";
	}
}
function openListItems(frm){
	var str = "List_SorItems.php?frm="+frm+"&ItemType=All";
	window.open(str, 'myWindow', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=880,height=500,top=50');
}	

function clearGrid(){
	document.getElementById('item_code').value ="";
    document.getElementById('item_description').value ="";
    document.getElementById('RMADt_Remark').value ="";	
	document.getElementById('RMADt_Charge').value ="";
	document.getElementById('RMADt_Charge2').value ="";
	document.getElementById('RMADt_PickedUpBy').value ="";
	document.getElementById('rmadt_notes').value ="";
	document.getElementById('rmadt_received').value ="";
	document.getElementById('rmadt_problem').value ="";
	document.getElementById('rmadt_solution').value ="";
	document.getElementById('rmadt_physicalDamage').value ="";
	document.getElementById('rmadt_DOA').value ="";
	document.getElementById('rmadt_informedon').value ="";
	document.getElementById('rmadt_repliedon').value ="";
	document.getElementById('rmadt_backfromsrvon').value ="";
	document.getElementById('rmadt_servicecenter').value ="";
	document.getElementById('RMADT_PROBLEMCATEGORY').value ="";
}
function saveRmaDtInsert(){
	//var x = document.rma;
	var actionmode = document.getElementById('actionmode').value;
	var RMA_Id = document.getElementById('RMA_Id').value;
	var actionmode2 = "insertdt";
	var RMA_Date = document.getElementById('RMA_Date').value;
	var RMA_No = document.getElementById('RMA_No').value;
	var RMA_PromissDate = document.getElementById('RMA_PromissDate').value;
	var client_code = document.getElementById('client_code').value;
	var client_name = document.getElementById('client_name').value;
	var Currency_code = document.getElementById('Currency_code').value;
	var Rmacharge_amount = document.getElementById('Rmacharge_amount').value;
	var Client_Email = document.getElementById('Client_Email').value;
	var RMA_ClientTelephone = document.getElementById('RMA_ClientTelephone').value;
	var RMA_ClientMobile = document.getElementById('RMA_ClientMobile').value;
	var Rma_Remark = document.getElementById('Rma_Remark').value;
	var txtemail = document.getElementById('txtemail').value;
	var txtsubject = document.getElementById('txtsubject').value;
	var textengineer = document.getElementById('textengineer').value;
	var item_code = document.getElementById('item_code').value;
	var item_description = document.getElementById('item_description').value;
	var RMADt_Remark = document.getElementById('RMADt_Remark').value;
	var RMADt_Charge = document.getElementById('RMADt_Charge').value;
	var RMADt_Charge2 = document.getElementById('RMADt_Charge2').value;
	var RMADt_PickedUpBy = document.getElementById('RMADt_PickedUpBy').value;
	var rmadt_notes = document.getElementById('rmadt_notes').value;
	var rmadt_received = document.getElementById('rmadt_received').value;
	var rmadt_problem = document.getElementById('rmadt_problem').value;
	var rmadt_solution = document.getElementById('rmadt_solution').value;
	var rmadt_physicalDamage = document.getElementById('rmadt_physicalDamage').value;
	var rmadt_DOA = document.getElementById('rmadt_DOA').value;
	var rmadt_informedon = document.getElementById('rmadt_informedon').value;
	var rmadt_repliedon = document.getElementById('rmadt_repliedon').value;
	var rmadt_backfromsrvon = document.getElementById('rmadt_backfromsrvon').value;
	var rmadt_servicecenter = document.getElementById('rmadt_servicecenter').value;
	var RMADT_PROBLEMCATEGORY = document.getElementById('RMADT_PROBLEMCATEGORY').value;
	var RMADt_Quantity = document.getElementById('RMADt_Quantity').value;
	var Outside_Item = document.getElementById('Outside_Item').value;
	var Serial_Number = document.getElementById('Serial_Number').value;
	var Invoice_Date = document.getElementById('Invoice_Date').value;
	var Invoice_Number = document.getElementById('Invoice_Number').value;
	var Rmadt_Warranty = document.getElementById('Rmadt_Warranty').value;
	//alert(RMA_Date);
	if(actionmode == "insert"){
		if(client_code == ""){
			alert("Client is required!");
			return false;
		}
		else
			if(RMA_Date == ""){
				alert("RMA Date is required!");
				return false;
			}
			else
				if(RMA_PromissDate == ""){
					alert("Promiss Date is required!");
					return false;
				}
				else
					if(RMA_No == ""){
						alert("RMA No is required!");
						return false;
					}
					else
						if(Currency_code == ""){
							alert("Currency is required!");
							return false;
						}
						else
							if(Rmacharge_amount == ""){
								alert("Charge Amount is required!");
								return false;
							}
	}
	if(item_code == ""){
		alert("Item is required!");
		return false;
	}
	else
		if(RMADt_Quantity == "" || RMADt_Quantity <= 0){
			alert("Quantity is required and should be more than 0!");
			return false;
		}
		else
			if(RMADT_PROBLEMCATEGORY == ""){
				alert("Problem Category is required!");
				return false;
			}
	else{
	var str = "Form_ReturnRMA_Actions.php?actionmode="+actionmode+"&RMA_Id="+RMA_Id+"&actionmode2="+actionmode2+"&RMA_Date="+RMA_Date+"&RMA_No="+RMA_No+
	           "&RMA_PromissDate="+RMA_PromissDate+"&client_code="+client_code+"&client_name="+client_name+"&Currency_code="+Currency_code+"&Rmacharge_amount="+Rmacharge_amount+
			   "&Client_Email="+Client_Email+"&RMA_ClientTelephone="+RMA_ClientTelephone+"&RMA_ClientMobile="+RMA_ClientMobile+"&Rma_Remark="+Rma_Remark+"&txtemail="+txtemail+
			   "txtsubject="+txtsubject+"&textengineer="+textengineer+"&item_code="+item_code+"&item_description="+item_description+"&RMADt_Remark="+RMADt_Remark+"&RMADt_Charge="+RMADt_Charge+
			   "&RMADt_Charge2="+RMADt_Charge2+"&RMADt_PickedUpBy="+RMADt_PickedUpBy+"&rmadt_notes="+rmadt_notes+"&rmadt_received="+rmadt_received+"&rmadt_problem="+rmadt_problem+
			   "&rmadt_solution="+rmadt_solution+"&rmadt_physicalDamage="+rmadt_physicalDamage+"&rmadt_DOA="+rmadt_DOA+"&rmadt_informedon="+rmadt_informedon+"&rmadt_repliedon="+rmadt_repliedon+
			   "&rmadt_backfromsrvon="+rmadt_backfromsrvon+"&rmadt_servicecenter="+rmadt_servicecenter+"&RMADT_PROBLEMCATEGORY="+RMADT_PROBLEMCATEGORY+"&RMADt_Quantity="+RMADt_Quantity+
			   "&Outside_Item="+Outside_Item+"&Serial_Number="+Serial_Number+"&Invoice_Date="+Invoice_Date+"&Invoice_Number="+Invoice_Number+"&Rmadt_Warranty="+Rmadt_Warranty;
	var xhttp = new XMLHttpRequest();
	//alert(str);exit;
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) { 
		var data = xhttp.responseText.split('[BRK]');
		//alert(data[0]);exit;
		
		document.getElementById('list_rmadt').innerHTML = data[0];
		document.getElementById('actionmode').value = "edit";
		document.getElementById('RMA_Id').value = data[1];
		document.getElementById('RMA_ref').innerHTML = data[2];
		document.getElementById('item_code').focus();
		document.getElementById('btnsearch').style.display = "none";
		document.getElementById('btnpending').style.display = "none";
		document.getElementById('btncancel').style.display = "inline-block";
		}
  };
  xhttp.open("GET", str, true);
  xhttp.send();
	}
}	
function updateRMADt(rmadt_id){
	var RMA_Id = document.getElementById('RMA_Id').value;
	var item_code = document.getElementById('item_code_'+rmadt_id).value;
	var item_description = document.getElementById('item_description_'+rmadt_id).value;
	var RMADt_Remark = document.getElementById('RMADt_Remark_'+rmadt_id).value;
	var RMADt_Charge = document.getElementById('RMADt_Charge_'+rmadt_id).value;
	var RMADt_Charge2 = document.getElementById('RMADt_Charge2_'+rmadt_id).value;
	var RMADt_PickedUpBy = document.getElementById('RMADt_PickedUpBy_'+rmadt_id).value;
	var rmadt_notes = document.getElementById('rmadt_notes_'+rmadt_id).value;
	var rmadt_received = document.getElementById('rmadt_received_'+rmadt_id).value;
	var rmadt_problem = document.getElementById('rmadt_problem_'+rmadt_id).value;
	var rmadt_solution = document.getElementById('rmadt_solution_'+rmadt_id).value;
	var rmadt_physicalDamage = document.getElementById('rmadt_physicalDamage_'+rmadt_id).value;
	var rmadt_DOA = document.getElementById('rmadt_DOA_'+rmadt_id).value;
	var rmadt_informedon = document.getElementById('rmadt_informedon_'+rmadt_id).value;
	var rmadt_repliedon = document.getElementById('rmadt_repliedon_'+rmadt_id).value;
	var rmadt_backfromsrvon = document.getElementById('rmadt_backfromsrvon_'+rmadt_id).value;
	var rmadt_servicecenter = document.getElementById('rmadt_servicecenter_'+rmadt_id).value;
	var RMADT_PROBLEMCATEGORY = document.getElementById('RMADT_PROBLEMCATEGORY_'+rmadt_id).value;
	var RMADt_Quantity = document.getElementById('RMADt_Quantity_'+rmadt_id).value;
	var Outside_Item = document.getElementById('Outside_Item_'+rmadt_id).value;
	var Serial_Number = document.getElementById('Serial_Number_'+rmadt_id).value;
	var Invoice_Date = document.getElementById('Invoice_Date_'+rmadt_id).value;
	var Invoice_Number = document.getElementById('Invoice_Number_'+rmadt_id).value;
	var Rmadt_Warranty = document.getElementById('Rmadt_Warranty_'+rmadt_id).value;
	var RMADt_Repaire = document.getElementById('RMADt_Repaire_'+rmadt_id).value;
	var NewSerial_Number = document.getElementById('NewSerial_Number_'+rmadt_id).value;
	var rmadt_return = document.getElementById('rmadt_return_'+rmadt_id).value;
	if(item_code == ""){
		alert("Item is required!");
		return false;
	}
	else
		if(RMADt_Quantity == "" || RMADt_Quantity <= 0){
			alert("Quantity is required and should be more than 0!");
			return false;
		}
		else
			if(RMADT_PROBLEMCATEGORY == ""){
				alert("Problem Category is required!");
				return false;
			}
			else
				if(RMADt_Repaire == ""){
					alert("Repair is required!");
				}
	else{
		var actionmode2 = "edit";
		document.getElementById('list_pending_items').value = (document.getElementById('list_pending_items').value).replace(rmadt_id+",", "");
		var str = "Form_ReturnRMA_Actions.php?&actionmode2="+actionmode2+"&item_code="+item_code+"&item_description="+item_description+"&RMADt_Remark="+RMADt_Remark+"&RMADt_Charge="+RMADt_Charge+
			   "&RMADt_Charge2="+RMADt_Charge2+"&RMADt_PickedUpBy="+RMADt_PickedUpBy+"&rmadt_notes="+rmadt_notes+"&rmadt_received="+rmadt_received+"&rmadt_problem="+rmadt_problem+
			   "&rmadt_solution="+rmadt_solution+"&rmadt_physicalDamage="+rmadt_physicalDamage+"&rmadt_DOA="+rmadt_DOA+"&rmadt_informedon="+rmadt_informedon+"&rmadt_repliedon="+rmadt_repliedon+
			   "&rmadt_backfromsrvon="+rmadt_backfromsrvon+"&rmadt_servicecenter="+rmadt_servicecenter+"&RMADT_PROBLEMCATEGORY="+RMADT_PROBLEMCATEGORY+"&RMADt_Quantity="+RMADt_Quantity+
			   "&Outside_Item="+Outside_Item+"&RMADt_Id="+rmadt_id+"&RMA_Id="+RMA_Id+"&Serial_Number="+Serial_Number+"&Invoice_Date="+Invoice_Date+"&Invoice_Number="+Invoice_Number+"&Rmadt_Warranty="+Rmadt_Warranty+"&RMADt_Repaire="+RMADt_Repaire+"&NewSerial_Number="+NewSerial_Number+"&RmaDt_Return="+rmadt_return;
	var xhttp = new XMLHttpRequest();
	//alert(str);exit;
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) { 
		var data = xhttp.responseText.split('[BRK]');
		//alert(data[0]);exit;
		document.getElementById('list_rmadt').innerHTML = data[0];
		//alert(data[0]);
		document.getElementById('item_code').focus();
		}
  };
  xhttp.open("GET", str, true);
  xhttp.send();
	}
}
function openListCustomers(){
	var str = "List_SorClient.php?frm=9";
	window.open(str, 'mywindow', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=990,height=600,top=60,left=100');
}
function openListItems2(frm, rmadt_id){
	var str = "List_SorItems.php?frm="+frm+"&ItemType=All&rmadt_id="+rmadt_id;
	window.open(str, 'myWindow', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=880,height=500,top=50');
}
function chkOutsideItem(){
	if(document.getElementById('chk_Outside_Item').checked){
		document.getElementById('Outside_Item').value = 1;
	}
	else{
		document.getElementById('Outside_Item').value = 0;
	}
}
function chkOutsideItem2(rmadt_id){
	if(document.getElementById('chk_Outside_Item_'+rmadt_id).checked){
		document.getElementById('Outside_Item_'+rmadt_id).value = 1;
	}
	else{
		document.getElementById('Outside_Item_'+rmadt_id).value = 0;
	}
}
function searchItem(e){
	if(e.keyCode == 13){
		//alert("test");
		//var x = document.rma;
		var item_code = document.getElementById('item_code').value;
		var client_code = document.getElementById('client_code').value;
		var Currency_code = document.getElementById('Currency_code').value;
		var RMA_Date = document.getElementById('RMA_Date').value;
		var RMADt_Quantity = document.getElementById('RMADt_Quantity').value;
		var str = "Form_ReturnRMA_Actions.php?actionmode=searchitem&item_code="+item_code+"&client_code="+client_code+"&RMA_Date="+RMA_Date+"&Currency_code="+Currency_code+"&RMADt_Quantity="+RMADt_Quantity;
		var xhttp = new XMLHttpRequest();
	//alert(str);exit;
	if(client_code == ""){
		alert("Please choose a client");
	}
	else{
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) { 
		var data = xhttp.responseText.split('[BRK]');
		if(data[0] > 0){
			document.getElementById('item_code').value = data[1];
			document.getElementById('item_description').value = data[2];
			document.getElementById('RMADt_Charge').value = data[3];
			document.getElementById('RMADt_Charge2').value = data[3];
			//return false;
		}
		else{
			openListItems(12);
			//return false;
		}
		
		}
  };
  xhttp.open("GET", str, true);
  xhttp.send();
	}
	}
	
	
}
function searchItem2(e, rmadt_id){
	if(e.keyCode == 13){
		//alert("test");
		//var x = document.rma;
		var item_code = document.getElementById('item_code_'+rmadt_id).value;
		var client_code = document.getElementById('client_code').value;
		var Currency_code = document.getElementById('Currency_code').value;
		var RMA_Date = document.getElementById('RMA_Date').value;
		var RMADt_Quantity = document.getElementById('RMADt_Quantity_'+rmadt_id).value;
		var str = "Form_ReturnRMA_Actions.php?actionmode=searchitem&item_code="+item_code+"&client_code="+client_code+"&Currency_code="+Currency_code+"&RMA_Date="+RMA_Date+"&RMADt_Quantity="+RMADt_Quantity;
		var xhttp = new XMLHttpRequest();
	//alert(str);exit;
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) { 
		var data = xhttp.responseText.split('[BRK]');
		if(data[0] > 0){
			document.getElementById('item_code_'+rmadt_id).value = data[1];
			document.getElementById('item_description_'+rmadt_id).value = data[2];
			document.getElementById('RMADt_Charge_'+rmadt_id).value = data[3];
			document.getElementById('RMADt_Charge2_'+rmadt_id).value = data[3];
			//return false;
		}
		else{
			openListItems2('13', rmadt_id);
			//return false;
		}
		
		}
  };
  xhttp.open("GET", str, true);
  xhttp.send();
	}
	
	
}
function deleteRMADt(rmadt_id){
	//var x = document.rma;
	var RMA_Id = document.getElementById('RMA_Id').value;
	var str = "Form_ReturnRMA_Actions.php?actionmode2=delete&RMA_Id="+RMA_Id+"&RMADt_Id="+rmadt_id;
	var c = confirm("Are you sure?");
	if(c){
	var xhttp = new XMLHttpRequest();
	//alert(str);exit;
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) { 
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_rmadt').innerHTML = data[0];
		}
  };
  xhttp.open("GET", str, true);
  xhttp.send();
	}
}
function moveNextField(v, e){
	if(e.keyCode == 13){
		
	if(v == 1){
		//alert("test");
		document.getElementById('item_description').focus();
	}
	else
		if(v == 2){
		//alert("test");
		document.getElementById('RMADt_Quantity').focus();
	    }
		else
		    if(v == 3){
		    //alert("test");
		    document.getElementById('RMADt_Remark').focus();
	        }
			else
		    if(v == 4){
		    //alert("test");
		    document.getElementById('RMADt_Charge').focus();
	        }
			else
		    if(v == 5){
		    //alert("test");
		    document.getElementById('RMADt_Charge2').focus();
	        }
			else
		    if(v == 6){
		    //alert("test");
		    document.getElementById('Serial_Number').focus();
	        }
			else
		    if(v == 7){
		    //alert("test");
		    document.getElementById('Invoice_Date').focus();
	        }
			else
		    if(v == 8){
		    //alert("test");
		    document.getElementById('Invoice_Number').focus();
	        }
			else
		    if(v == 9){
		    //alert("test");
		    document.getElementById('RMADt_PickedUpBy').focus();
	        }
			else
		    if(v == 10){
		    //alert("test");
		    document.getElementById('rmadt_notes').focus();
	        }
			else
		    if(v == 11){
		    //alert("test");
		    document.getElementById('rmadt_received').focus();
	        }
			else
		    if(v == 12){
		    //alert("test");
		    document.getElementById('rmadt_problem').focus();
	        }
			else
		    if(v == 13){
		    //alert("test");
		    document.getElementById('rmadt_solution').focus();
	        }
		
			else
		    if(v == 14){
		    //alert("test");
		    document.getElementById('rmadt_informedon').focus();
	        }
			else
		    if(v == 15){
		    //alert("test");
		    document.getElementById('rmadt_repliedon').focus();
	        }
			else
		    if(v == 16){
		    //alert("test");
		    document.getElementById('rmadt_backfromsrvon').focus();
	        }
			else
		    if(v == 17){
		    //alert("test");
		    document.getElementById('rmadt_servicecenter').focus();
	        }
			else
		    if(v == 18){
		    //alert("test");
		    document.getElementById('RMADT_PROBLEMCATEGORY').focus();
	        }
			else
		    if(v == 19){
		    //alert("test");
		    saveRmaDtInsert();
	        }
			
	
  }
}

function moveNextField2(v, e, rmadt_id){
	if(e.keyCode == 13){
		
	if(v == 1){
		//alert("test");
		document.getElementById('item_description_'+rmadt_id).focus();
	}
	else
		if(v == 2){
		//alert("test");
		document.getElementById('RMADt_Repaire_'+rmadt_id).focus();
	    }
	else
		if(v == 3){
		//alert("test");
		document.getElementById('RMADt_Quantity_'+rmadt_id).focus();
	    }
		else
		    if(v == 4){
		    //alert("test");
		    document.getElementById('RMADt_Remark_'+rmadt_id).focus();
	        }
			else
		    if(v == 5){
		    //alert("test");
		    document.getElementById('RMADt_Charge_'+rmadt_id).focus();
	        }
			else
		    if(v == 6){
		    //alert("test");
		    document.getElementById('RMADt_Charge2_'+rmadt_id).focus();
	        }
			else
		    if(v == 7){
		    //alert("test");
		    document.getElementById('Serial_Number_'+rmadt_id).focus();
	        }
			else
		    if(v == 8){
		    //alert("test");
		    document.getElementById('Invoice_Date_'+rmadt_id).focus();
	        }
			else
		    if(v == 9){
		    //alert("test");
		    document.getElementById('Invoice_Number_'+rmadt_id).focus();
	        }
			else
		    if(v == 10){
		    //alert("test");
		    document.getElementById('RMADt_PickedUpBy_'+rmadt_id).focus();
	        }
			else
		    if(v == 11){
		    //alert("test");
		    document.getElementById('rmadt_notes_'+rmadt_id).focus();
	        }
			else
		    if(v == 12){
		    //alert("test");
		    document.getElementById('rmadt_received_'+rmadt_id).focus();
	        }
			else
		    if(v == 13){
		    //alert("test");
		    document.getElementById('rmadt_problem_'+rmadt_id).focus();
	        }
			else
		    if(v == 14){
		    //alert("test");
		    document.getElementById('rmadt_solution_'+rmadt_id).focus();
	        }
		
			else
		    if(v == 15){
		    //alert("test");
		    document.getElementById('rmadt_informedon_'+rmadt_id).focus();
	        }
			else
		    if(v == 16){
		    //alert("test");
		    document.getElementById('rmadt_repliedon_'+rmadt_id).focus();
	        }
			else
		    if(v == 17){
		    //alert("test");
		    document.getElementById('rmadt_backfromsrvon_'+rmadt_id).focus();
	        }
			else
		    if(v == 18){
		    //alert("test");
		    document.getElementById('rmadt_servicecenter_'+rmadt_id).focus();
	        }
			else
		    if(v == 19){
		    //alert("test");
		    document.getElementById('RMADT_PROBLEMCATEGORY_'+rmadt_id).focus();
	        }
			else
		    if(v == 20){
		    //alert("test");
		    updateRMADt(rmadt_id);
	        }
			
	
  }
}
function cancelRMA(){
	var RMA_Id = document.getElementById('RMA_Id').value;
	var str = "Form_ReturnRMA_Actions.php?actionmode=cancelrma&RMA_Id="+RMA_Id;
	var c = confirm("Are you sure of deleting the current pending RMA?");
	if(c){
	var xhttp = new XMLHttpRequest();
	//alert(str);exit;
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) { 
		var data = xhttp.responseText.split('[BRK]');
		if(data[0] == 1){
			document.location.href = "Form_ReturnRMA.php";
		}
	}
  };
  xhttp.open("GET", str, true);
  xhttp.send();
	}
}
function chkRmadtPhysicalDamage(){
	if(document.getElementById('chk_rmadt_physicalDamage').checked){
		document.getElementById('rmadt_physicalDamage').value = 1;
	}
	else{
		document.getElementById('rmadt_physicalDamage').value = 0;
	}
}
function chkRmadtPhysicalDamage2(rmadt_id){
	if(document.getElementById('chk_rmadt_physicalDamage_'+rmadt_id).checked){
		document.getElementById('rmadt_physicalDamage_'+rmadt_id).value = 1;
	}
	else{
		document.getElementById('rmadt_physicalDamage_'+rmadt_id).value = 0;
	}
}
function chkRmadtDOA(){
	if(document.getElementById('chk_rmadt_DOA').checked){
		document.getElementById('rmadt_DOA').value = 1;
	}
	else{
		document.getElementById('rmadt_DOA').value = 0;
	}
}
function chkRmadtDOA2(rmadt_id){
	if(document.getElementById('chk_rmadt_DOA_'+rmadt_id).checked){
		document.getElementById('rmadt_DOA_'+rmadt_id).value = 1;
	}
	else{
		document.getElementById('rmadt_DOA_'+rmadt_id).value = 0;
	}
}
function saveRMA(){
	var RMA_Id = document.getElementById('RMA_Id').value;
	var RMA_Date = document.getElementById('RMA_Date').value;
	var RMA_No = document.getElementById('RMA_No').value;
	var RMA_PromissDate = document.getElementById('RMA_PromissDate').value;
	var client_code = document.getElementById('client_code').value;
	var client_name = document.getElementById('client_name').value;
	var Currency_code = document.getElementById('Currency_code').value;
	var Rmacharge_amount = document.getElementById('Rmacharge_amount').value;
	var Client_Email = document.getElementById('Client_Email').value;
	var RMA_ClientTelephone = document.getElementById('RMA_ClientTelephone').value;
	var RMA_ClientMobile = document.getElementById('RMA_ClientMobile').value;
	var Rma_Remark = document.getElementById('Rma_Remark').value;
	var txtemail = document.getElementById('txtemail').value;
	var txtsubject = document.getElementById('txtsubject').value;
	var textengineer = document.getElementById('textengineer').value;
	var textengineer2 = document.getElementById('textengineer2').value;
	var number_of_items = document.getElementById('number_of_items').value;
	var list_pending_items = document.getElementById('list_pending_items').value;
	var Rma_Remark2 = document.getElementById('Rma_Remark2').value;
	alert("Rmacharge_amount="+Rmacharge_amount);
	if(client_code == ""){
			alert("Client is required!");
			return false;
		}
		else
			if(RMA_Date == ""){
				alert("RMA Date is required!");
				return false;
			}
			else
				if(RMA_PromissDate == ""){
					alert("Promiss Date is required!");
					return false;
				}
				
					else
						if(Currency_code == ""){
							alert("Currency is required!");
							return false;
						}
						else
								if(RMA_ClientTelephone == "" && RMA_ClientMobile == ""){
									alert("Telephone / Mobile is required!");
									return false;
								}
	else						
	if(number_of_items <= 0){
		alert("Please add items!");
	}
	else
		if(list_pending_items != ""){
			alert("Please save the pending items marked on red!");
			var list_arr = list_pending_items.split(",");
			for(var i=0;i<list_arr.length;i++){
				//alert('row_'+list_arr[i]);
				document.getElementById('row_'+list_arr[i]).style.background = "#ff0000";
			}
		}
	else{
		var c = confirm("Are you sure you want to save the current Return RMA?");
		if(c){
		var str = "Form_ReturnRMA_Actions.php?actionmode=saverma&RMA_Id="+RMA_Id+"&RMA_Date="+RMA_Date+"&RMA_No="+RMA_No+
	           "&RMA_PromissDate="+RMA_PromissDate+"&client_code="+client_code+"&client_name="+client_name+"&Currency_code="+Currency_code+"&Rmacharge_amount="+Rmacharge_amount+
			   "&Client_Email="+Client_Email+"&RMA_ClientTelephone="+RMA_ClientTelephone+"&RMA_ClientMobile="+RMA_ClientMobile+"&Rma_Remark="+Rma_Remark+"&txtemail="+txtemail+
			   "&txtsubject="+txtsubject+"&textengineer="+textengineer+"&Rma_Remark2="+Rma_Remark2+"&textengineer2="+textengineer2;
		var xhttp = new XMLHttpRequest();
	     //alert(str);exit;
         xhttp.onreadystatechange = function() {
         if (xhttp.readyState == 4 && xhttp.status == 200) {
			 var data = xhttp.responseText.split('[BRK]');
			 //document.write(data[0]);
			 alert(data[0]);
			 if(data[1] == 1){
				 if(confirm("Do you want to print the Return RMA sheet?")){
					 window.open("Form_ReturnRMAPreview.php?&rma_id="+data[2]);
				 }
				 document.location.href="Form_ReturnRMA.php";
			 }
		 }
        };
       xhttp.open("GET", str, true);
       xhttp.send();
		}
	}
}
function searchRMA(){
	var str = "ListOfReturnRMA.php?to_type=MR";
	window.open(str, 'myWindow', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1100,height=600,top=50');
}
function openPendingList(){
	var str = "ListOfPendingReturnRMA.php";
	window.open(str, 'myWindow', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1100,height=600,top=50');
}
function chkRmadtWarranty2(rmadt_id){
	if(document.getElementById('chk_Rmadt_Warranty_'+rmadt_id).checked){
		document.getElementById('Rmadt_Warranty_'+rmadt_id).value = 1;
	}
	else{
		document.getElementById('Rmadt_Warranty_'+rmadt_id).value = 0;
	}
}
function chkRmadtWarranty(){
	if(document.getElementById('chk_Rmadt_Warranty').checked){
		document.getElementById('Rmadt_Warranty').value = 1;
	}
	else{
		document.getElementById('Rmadt_Warranty').value = 0;
	}
}
function changeCurrency(){
	var Currency_code = document.getElementById('Currency_code').value;
	var RMA_Id = document.getElementById('RMA_Id').value;
	var RMA_Date = document.getElementById('RMA_Date').value;
	if(Currency_code == ""){
		alert("Please choose a currency!");
	}
	else{
		var str = "Form_ReturnRMA_Actions.php?actionmode=changecurrency&Currency_code="+Currency_code+"&RMA_Id="+RMA_Id+"&RMA_Date="+RMA_Date;
		var xhttp = new XMLHttpRequest();
	     //alert(str);exit;
         xhttp.onreadystatechange = function() {
         if (xhttp.readyState == 4 && xhttp.status == 200) {
			 var data = xhttp.responseText.split('[BRK]');
			 document.getElementById('list_rmadt').innerHTML = data[0];
			 document.getElementById('Rmacharge_amount').value = data[1];
			 }
        };
       xhttp.open("GET", str, true);
       xhttp.send();
	}
}
function openRMAList(){
    var str = "ListToLoadRMA.php";
	window.open(str, 'myWindow', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1100,height=600,top=50');
}
function modifyRMADt(rmadt_id, rma_id){
	var str = "ListOfRMAdtRPC.php?rma_id="+rma_id+"&rmadt_id="+rmadt_id;
	window.open(str, 'myWindow', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1100,height=600,top=50');
}
function searchClient(e){
	if(e.keyCode == 13){
		var client_code = document.getElementById('client_code').value;
		var str = "Form_ReturnRMA_Actions.php?actionmode=searchclient&client_code="+client_code;
		var xhttp = new XMLHttpRequest();
         xhttp.onreadystatechange = function() {
         if (xhttp.readyState == 4 && xhttp.status == 200) {
			 var data = xhttp.responseText.split('[BRK]');
			 if(data[0] == 0){
				 openListCustomers();
			 }
			 else{
				 document.getElementById('client_code').value = data[1];
				 document.getElementById('client_name').value = data[2];
			 }
			 }
        };
       xhttp.open("GET", str, true);
       xhttp.send();
	}
}
function openListProblemCategory(frm){
	var str = "List_ProblemCategory.php?frm="+frm;
	window.open(str, 'myWindow2', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=871,height=500,top=50');
}
function openListProblemCategory2(frm, rmadt_id){
	var str = "List_ProblemCategory.php?frm="+frm+"&rmadt_id="+rmadt_id;
	window.open(str, 'myWindow2', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=871,height=500,top=50');
}
function searchproblem(e){
	if(e.keyCode==13){
	var RMADT_PROBLEMCATEGORY = document.getElementById('RMADT_PROBLEMCATEGORY').value;
	var str = "Form_RMA_Actions.php?actionmode=searchproblem&RMADT_PROBLEMCATEGORY="+RMADT_PROBLEMCATEGORY;
	var xhttp = new XMLHttpRequest();
         xhttp.onreadystatechange = function() {
         if (xhttp.readyState == 4 && xhttp.status == 200) {
			 var data = xhttp.responseText.split('[BRK]');
			 if(data[0] == 0){
				 openListProblemCategory(1);
				 
			 }
			 else{
				 document.getElementById('RMADT_PROBLEMCATEGORY').value = data[1];
				 moveNextField('19', e);
			 }
		  }
        };
       xhttp.open("GET", str, true);
       xhttp.send();
	}
}
function searchproblem2(e, rmadt_id){
	if(e.keyCode==13){
	var RMADT_PROBLEMCATEGORY = document.getElementById('RMADT_PROBLEMCATEGORY_'+rmadt_id).value;
	var str = "Form_RMA_Actions.php?actionmode=searchproblem&RMADT_PROBLEMCATEGORY="+RMADT_PROBLEMCATEGORY;
	var xhttp = new XMLHttpRequest();
         xhttp.onreadystatechange = function() {
         if (xhttp.readyState == 4 && xhttp.status == 200) {
			 var data = xhttp.responseText.split('[BRK]');
			 if(data[0] == 0){
				 openListProblemCategory2(2, rmadt_id);
				 
			 }
			 else{
				 document.getElementById('RMADT_PROBLEMCATEGORY_'+rmadt_id).value = data[1];
				 moveNextField2('10', e, rmadt_id);
			 }
		  }
        };
       xhttp.open("GET", str, true);
       xhttp.send();
	}
}
function addPending(rmadt_id, e){
	if(e.keyCode != 13){
		var list_pending_items = document.getElementById('list_pending_items').value;
		if(list_pending_items.includes(rmadt_id + ",") == false){
			document.getElementById('list_pending_items').value = document.getElementById('list_pending_items').value + rmadt_id + ","; 
		}
	}
}
function openPendingList2(){
	var str = "Form_ListReturnRMAPendingItems.php";
	window.open(str);
}
function openRMALocations(){
	var str = "Form_ListReturnRMALocation.php";
	window.open(str);
}
function openReception(){
	var str = "Form_ListReturnRMAReception.php";
	window.open(str);
}
function chkRmadtReturn2(rmadt_id){
	if(document.getElementById('chk_return_DOA_'+rmadt_id).checked){
		document.getElementById('rmadt_return_'+rmadt_id).value = 1;
	}
	else{
		document.getElementById('rmadt_return_'+rmadt_id).value = 0;
	}
}
function openEngineer(){
	var str = "List_ProblemCategory.php?type=E&frm=5";
	window.open(str, 'myWindow', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=880,height=500,top=50');
}
function openRMA(rma_id){
	var str = "Form_ReturnRMA_Actions.php?actionmode=inserttotemp&RMA_Id="+rma_id;
	var xhttp = new XMLHttpRequest();
	//alert(str);exit;
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) { 
		var data = xhttp.responseText.split('[BRK]');
		
	var str2 = "Form_RMA.php?RMA_Id="+rma_id;
	window.open(str2);
		}
  };
  xhttp.open("GET", str, true);
  xhttp.send();
	
}
</script>

<title>Return RMA</title>
</head>
<body>
HERE;
if($ReturnRMA_Id != "") $actionmode = "edit"; else $actionmode="insert";
echo "<input type='hidden' name='actionmode' id='actionmode' value='$actionmode'>
<input type='hidden' name='RMA_Id' id='RMA_Id' value='$ReturnRMA_Id'>";

$ReturnRMA_Id = $_GET['ReturnRMA_Id'];
if($ReturnRMA_Id != ""){
$query_select  = "select RMA_Id, RMA_Reference, date_format(RMA_Date, '%d/%m/%Y') as RMA_Date, Rma_RMAREF, date_format(RMA_PROMISEDDATE, '%d/%m/%Y') as RMA_PROMISEDDATE, temp_rma.Client_Code, clients.ledger_name as ClientName, temp_rma.Currency_code,
	                    Rmacharge_amount, Rmacharge_amountbase1, Rmacharge_amountbase2, temp_rma.client_Email as Client_Email, temp_rma.Client_Tel as RMA_ClientTelephone,
					    temp_rma.Client_Cell as RMA_ClientMobile, Rma_Remark, RMA_email as RMA_email, RMA_subject, Rma_EngineerName, rma_type, RMA_BelongsToGroup, Rma_Remark2, problemcategory.PROBLEMCATEGORY_NAME as EngName
					    from temp_rma left join clients on clients.ledger_number = temp_rma.client_code
						left join problemcategory on problemcategory.user_code = temp_rma.Rma_EngineerName
					    where rma_id = '$ReturnRMA_Id'";
	  //echo $query_select;exit;
	  $result_select = mysql_query($query_select, $connection);
	  $row_select    = mysql_fetch_array($result_select);
	  extract($row_select);
}
//echo "RMA_Reference= ".$RMA_Reference;
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:16px;'>
		<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:16px;'>
				<td style='width:38px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>Return RMA</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";
	  

echo"<tr>
		<td  height='13'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				
				<td>";
	


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

if($ReturnRMA_Id != ""){
	$curr_date = $RMA_Date;
	$display2 = "display: inline-block;";
	$curr_date2 = $RMA_PROMISEDDATE;
	$display3 = "display: none;";
}
else{
	$curr_date = date("d/m/Y");
	$display2 = "display: none";
	$curr_date2 = date("d/m/Y");
	$display3 = "display: inlin-block;";
}

$strt = $_SESSION['StartFinancial_Date'];
$end = $_SESSION['EndFinancial_Date'];


$query_setup  = "select base1, base2 from setup";
$result_setup = mysql_query($query_setup, $connection); 
$row_setup    = mysql_fetch_array($result_setup);
extract($row_setup);
$query_access  = "select FI_ReturnRMA, FI_ReturnRMAApp, FI_ReturnRMAMod, FI_ReturnRMADel from ".$_SESSION['dbLabel'].".login where user_account = '".$_SESSION['useraccount']."' and Login_Schema = '".strtoupper($_SESSION['dbName'])."'";
$result_access = mysql_query($query_access, $connection);
$row_access    = mysql_fetch_array($result_access);
extract($row_access);
if($FI_ReturnRMAApp != 1){
	$display = "display: none";
}
echo"<tr><td id='content-body'>
<table width=93% style='margin: auto'>
<tr>
<td colspan=7><button onclick=\"clearPage(); return false;\"><span><span>Clear Page</span></span></button>
<span id='list_buttons'>
<span id='btnsearch' style='$display3'><button onclick=\"searchRMA(); return false;\"><span><span>Search</span></span></button></span>
<span id='btncancel' style='$display2'><button onclick=\"cancelRMA(); return false;\"><span><span>Cancel</span></span></button></span>
<span id='btnsave' style='$display2'><button onclick=\"saveRMA(); return false;\"><span><span>Save</span></span></button></span>
<span id='btnpending' style='$display3'><button onclick=\"openPendingList(); return false;\"><span><span>Pending</span></span></button></span>
<span id='btnload' style='$display $display3'><button onclick=\"openRMAList(); return false;\"><span><span>Load RMA</span></span></button></span>
<span id='btnlistpending'><button onclick=\"openPendingList2(); return false;\"><span><span>List of Pending Items</span></span></button></span>
<span id='btnlistlocation'><button onclick=\"openRMALocations(); return false;\"><span><span>Return RMA Locations</span></span></button></span>
<span id='btnlistreception'><button onclick=\"openReception(); return false;\"><span><span>RMA Reception</span></span></button></span>
<span id='btnopenrma' style='dispaly: inline-block'></span>
</span>
</td>
</tr>
<tr style='height: 15px'>
<td colspan=7></td>
</tR>
<tr>
<td style='font-weight: bold; font-size: 12px; width: 100px'>Reference <font color='red'>*</font></td>
<td style='font-weight: bold; font-size: 12px; width: 100px' id='RMA_ref'>$RMA_Reference</td>
<td style='font-weight: bold; font-size: 12px; width: 100px'>Date <font color='red'>*</font></td>
<td style='font-weight: bold; font-size: 12px;'><input type='text' name='RMA_Date' id='RMA_Date' value='$curr_date' style='width: 148px' /> <A HREF='#' onClick=\"displayCalendar(document.getElementById('RMA_Date'),'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A></td>
<td style='font-weight: bold; font-size: 12px; width: 100px'>RMA No.</td>
<td style='font-weight: bold; font-size: 12px;'><input type='text' name='RMA_No' id='RMA_No' value='$Rma_RMAREF' /></td>
<td style='font-weight: bold; font-size: 12px; width: 100px'>Promiss Date <font color='red'>*</font></td>
<td style='font-weight: bold; font-size: 12px;'><input type='text' name='RMA_PromissDate' id='RMA_PromissDate' value='$curr_date2' /> <A HREF='#' onClick=\"displayCalendar(document.getElementById('RMA_PromissDate'),'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A></td>
</tr>
<tr>
<td style='font-weight: bold; font-size: 12px;'>Client <font color='red'>*</font></td>
<td style='font-weight: bold; font-size: 12px;' colspan=3><input type='text' name='client_code' id='client_code' value='$Client_Code' style='width: 100px' onkeyup=\"searchClient(event)\" />
<input type='text' name='client_name' id='client_name' style='width: 252px' value='$ClientName' />&nbsp;<img src='img/btnopen.jpg' width=20 style='cursor: pointer; vertical-align: top' onclick=\"openListCustomers()\" /> 
</td>
<td style='font-weight: bold; font-size: 12px;'>Currency <font color='red'>*</font></td>
<td><select name='Currency_code' id='Currency_code' style='width: 172px' onchange=\"changeCurrency()\">
<option value=''></option>";
$query_currency  = "select currency_code as CurrencyCode from currency";
$result_currency = mysql_query($query_currency, $connection); 
while($row_currency = mysql_fetch_array($result_currency)){
	extract($row_currency);
	if($ReturnRMA_Id == ""){
	if($CurrencyCode == $base2){
		$selected = "selected='selected'";
	}
	else{
		$selected = "";
	}
	}
	else{
		if($CurrencyCode == $Currency_code){
		$selected = "selected='selected'";
	}
	else{
		$selected = "";
	}
	}
	echo "<option value='$CurrencyCode' $selected>$CurrencyCode</option>";
}
if($Rmacharge_amount == "") $Rmacharge_amount = "0.00";
echo"</select>&nbsp;<input type='hidden' name='Rmacharge_amount' id='Rmacharge_amount' style='width: 107px; text-align: right' value='$Rmacharge_amount' /></td>
<td style='font-weight: bold; font-size: 12px;'>Technical E-mail</td>
<td><input type='text' name='Client_Email' id='Client_Email' value='$Client_Email' /></td>
</tr>
<tr>
<td colspan=4></td>
<td style='font-weight: bold; font-size: 12px;'>Telephone <font color='red'>*</font></td>
<td><input type='text' name='RMA_ClientTelephone' id='RMA_ClientTelephone' value='$RMA_ClientTelephone' /></td>";
if($RMA_TotalCharge=="") $RMA_TotalCharge = 0.00;
echo "
<td style='font-weight: bold; font-size: 12px;'>Total Charge</td>
<td><input type='text' name='RMATotalCharge' id='RMATotalCharge' value='$RMA_TotalCharge'/></td>
</tr>
<tr>
<td colspan=4></td>
<td style='font-weight: bold; font-size: 12px;'>Mobile <font color='red'>*</font></td>
<td><input type='text' name='RMA_ClientMobile' id='RMA_ClientMobile' value='$RMA_ClientMobile' /></td>
</tr>
<tr>
<td style='font-weight: bold; font-size: 12px;'>Remark</td>
<td style='font-weight: bold; font-size: 12px;' colspan=3><input type='text' name='Rma_Remark' id='Rma_Remark' style='width: 97%' value='$Rma_Remark' /></td>
<td style='font-weight: bold; font-size: 12px;'>E-mail</td>
<td style='font-weight: bold; font-size: 12px;'><input type='text' name='txtemail' id='txtemail' /></td>
<td style='font-weight: bold; font-size: 12px;'>Subject</td>
<td style='font-weight: bold; font-size: 12px;'><input type='text' name='txtsubject' id='txtsubject' value='$RMA_subject' /></td>
</tr>
<tr>
<td style='font-weight: bold; font-size: 12px;'>Engineer</td>
<td colspan=3><input type='hidden' id='textengineer2' value='$Rma_EngineerName' /><input type='text' name='textengineer' id='textengineer' readonly style='width: 90%' value='$EngName' /> <img src='img/btnopen.jpg' width=20 style='cursor: pointer; $display' onclick=\"openEngineer()\" /></td>
<td  style='font-weight: bold; font-size: 12px;'>Remark <br>(300 char)</td>
<td colspan='3'><input type='text' name='Rma_Remark2' id='Rma_Remark2' style='width: 95%' value='$Rma_Remark2' /></td>
<td></td>
</tr>
<tr style='height: 15px;'>
<th></th>
</tR>
<tr>
<td colspan=8 style='font-size: 13px'><b><u>N.B.:</u></b> U: Exchange, Upgrade, Return Sales, Repair. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;X: Return to client unrepaired. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R: Repaired without Spare Parts.</td>
</tr>
</table>
<input type='hidden' id='list_pending_items' value='' />
<div id='list_rmadt' style='height: 280px; overflow-y: scroll; width:1090px; overflow-x: scroll; margin: auto; margin-top: 25px; '>";
drawReturnRMADt($connection, $ReturnRMA_Id);
echo"</div>
		</td></tr>";

echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";
include("footer.php");	
echo" </table>  ";//end of last table menu





print <<<HERE


</body>
</html>

HERE;

?>