<?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 changeValue(rmadt_id){
	if(document.getElementById('chk_rmadt_id_'+rmadt_id).checked){
		document.getElementById('rmadt_id').value = rmadt_id;
	}
	
}
function receive(){
	var rmadt_id = document.getElementById('rmadt_id').value;
	var start = document.getElementById('start_par').value;
	var pagenumber = document.getElementById('pagenumber_par').value;
	var filter_by = document.getElementById('filter_by').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
	var receive_date = document.getElementById('receive_date').value;
	var c = confirm("Are you sure?");
	if(c){
	var str = "Form_ListRMAPendingItems_Actions.php?actionmode=receive&rmadt_id="+rmadt_id+"&receive_date="+receive_date+"&start="+start+"&pagenumber="+pagenumber+"&filter_by="+filter_by;
	var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) { 
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_pending').innerHTML = data[0];
		document.getElementById('receive_usercode').value = data[1];
		document.getElementById('receive_date').value = data[2];
		document.getElementById('receive_usercode').readOnly = true;
		document.getElementById('receive_date').readOnly = true;
		document.getElementById('chk_rmadt_id_'+rmadt_id).checked = true;
	  }
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
  }
}
function deliver(){
	var rmadt_id = document.getElementById('rmadt_id').value;
	var start = document.getElementById('start_par').value;
	var pagenumber = document.getElementById('pagenumber_par').value;
	var filter_by = document.getElementById('filter_by').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
	var deliver_date = document.getElementById('deliver_date').value;
	var c = confirm("Are you sure?");
	if(c){
	var str = "Form_ListRMAPendingItems_Actions.php?actionmode=deliver&rmadt_id="+rmadt_id+"&deliver_date="+deliver_date+"&start="+start+"&pagenumber="+pagenumber+"&filter_by="+filter_by;
	var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) { 
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_pending').innerHTML = data[0];
		document.getElementById('deliver_usercode').value = data[1];
		document.getElementById('deliver_date').value = data[2];
		document.getElementById('deliver_usercode').readOnly = true;
		document.getElementById('deliver_date').readOnly = true;
		document.getElementById('chk_rmadt_id_'+rmadt_id).checked = true;
	  }
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
  }
}
function displayDate(rmadt_id){
	var str = "Form_ListRMAPendingItems_Actions.php?actionmode=displaydates&rmadt_id="+rmadt_id;
	var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('receive_usercode').value = data[0];
		document.getElementById('receive_date').value = data[1];
		document.getElementById('receive_usercode').readOnly = true;
		document.getElementById('receive_date').readOnly = true;
		document.getElementById('deliver_usercode').value = data[2];
		document.getElementById('deliver_date').value = data[3];
		document.getElementById('deliver_usercode').readOnly = true;
		document.getElementById('deliver_date').readOnly = true;
	  }
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}
function chkFilter(value){
	document.getElementById('start_par').value = 0;
	document.getElementById('pagenumber_par').value = 1;
	var start = document.getElementById('start_par').value;
	var pagenumber = document.getElementById('pagenumber_par').value;
	var str = "Form_ListReturnRMAPendingItems_Actions.php?actionmode=gofilterby&filter_by="+value+"&start="+start+"&pagenumber="+pagenumber;
	document.getElementById('filter_by').value = value;
	var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_pending').innerHTML = data[0];
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}
function moveNext(){
	document.getElementById('start_par').value = Number(document.getElementById('start_par').value) + 20;
	document.getElementById('pagenumber_par').value = Number(document.getElementById('pagenumber_par').value) + 1;
	var start = document.getElementById('start_par').value;
	var pagenumber = document.getElementById('pagenumber_par').value;
	var search_type = document.getElementById('search_type').value;
	var search_location = document.getElementById('search_location').value;
	var str = "Form_ListReturnRMALocation_Actions.php?actionmode=movenext&start="+start+"&pagenumber="+pagenumber+"&search_type="+search_type+"&search_location="+search_location;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_location').innerHTML = data[0];
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}
function movePrev(){
	document.getElementById('start_par').value = Number(document.getElementById('start_par').value) - 20;
	document.getElementById('pagenumber_par').value = Number(document.getElementById('pagenumber_par').value) - 1;
	var start = document.getElementById('start_par').value;
	var pagenumber = document.getElementById('pagenumber_par').value;
	var search_type = document.getElementById('search_type').value;
	var search_location = document.getElementById('search_location').value;
	var str = "Form_ListReturnRMALocation_Actions.php?actionmode=moveprev&start="+start+"&pagenumber="+pagenumber+"&search_type="+search_type+"&search_location="+search_location;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_location').innerHTML = data[0];
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}
function addDates(){
	var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!

var yyyy = today.getFullYear();
if(dd<10){
    dd='0'+dd;
} 
if(mm<10){
    mm='0'+mm;
} 
var today = dd+'/'+mm+'/'+yyyy;
	var search_location = document.getElementById('search_location').value;
	var search_type     = document.getElementById('search_type').value;
	if(search_type == "Expected_Date" || search_type == "Received_Date"){
		document.getElementById('search_location').value = today;
		document.getElementById('date_icon').style.display = "inline-block";
	}
	else{
		//document.getElementById('search_location').value = "";
		document.getElementById('date_icon').style.display = "none";
	}
}
function searchRMALocation(){
	var search_location = document.getElementById('search_location').value;
	var search_type     = document.getElementById('search_type').value;
	var str = "Form_ListReturnRMALocation_Actions.php?actionmode=searchrmalocation&search_type="+search_type+"&search_location="+search_location;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_location').innerHTML = data[0];
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}
</script>

<title>Return RMA Location</title>
</head>
<body>
<input type='hidden' name='actionmode' id='actionmode' value='insert'>
<input type='hidden' name='RMA_Id' id='RMA_Id' value=''>
HERE;




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

$strt = $_SESSION['StartFinancial_Date'];
$end = $_SESSION['EndFinancial_Date'];
$curr_date = date("d/m/Y");

$query_setup  = "select base1, base2 from setup";
$result_setup = mysql_query($query_setup, $connection); 
$row_setup    = mysql_fetch_array($result_setup);
extract($row_setup);
$date = date("d/m/Y");
echo"<tr><td id='content-body' style='text-align: left'>
<table width=600 style='margin-left: 48px;'>
<tr>
<td style='font-size: 14px; font-weight: bold'>Search</td>
<td style='width: 240px;'><input type='text' name='search_location' id='search_location' style='width: 200px; height: 25px;' onkeyup=\"searchRMALocation()\" onchange=\"searchRMALocation()\" /> <span id='date_icon' style='display: none'><A HREF='#' onClick=\"displayCalendar(document.getElementById('search_location'),'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A></span></td>
<td style='width: 240px;'><select name='search_type' id='search_type' style='width: 200px; height: 25px;' onchange=\"searchRMALocation(); addDates()\">
<option value=''></option>
<option value='RMA_Ref'>RMA Ref</option>
<option value='Expected_Date'>Expected Date</option>
<option value='Received_Date'>Received Date</option>
<option value='Project'>Project</option>
<option value='Client_Code'>Client Code</option>
<option value='Client_Name'>Client Name</option>
<option value='Remark'>Remark</option>
<option value='Engineer_Name'>Engineer Name</option>
<option value='Item_code'>Item Code</option>
<option value='Item_Description'>Item Description</option>
<option value='Service_Center'>Service Center</option>
<option value='Repair'>Repair</option>
<option value='Status'>Status</option>
</select></td>
</tr>
</table>

<div style='height: 10px;'></div>";
echo "<input type='hidden' id='rmadt_id' value='' />";
echo"<div id='list_location'>";
drawReturnRMALocation($connection);
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;

?>