<?php
session_start();
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");

print <<<HERE
<head>
<title>Search RMA</title>
<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>

<script>
function openListCustomers(frm){
	var str = "List_SorClient.php?frm="+frm;
	window.open(str, 'myWindow2', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=880,height=500,top=50');
}
function moveNext(){
	document.getElementById('start').value = Number(document.getElementById('start').value) + 10;
	document.getElementById('pagenumber').value = Number(document.getElementById('pagenumber').value) + 1;
	var start = document.getElementById('start').value;
	var pagenumber = document.getElementById('pagenumber').value;
	var reference = document.getElementById('reference').value;
	var date = document.getElementById('date').value;
	var client_code = document.getElementById('client_code').value;
	var str = "ListOfRMA_Actions.php?actionmode=movenext&start="+start+"&pagenumber="+pagenumber+"&reference="+reference+"&date="+date+"&client_code="+client_code;
	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('listrma').innerHTML = data[0];
		}
  };
  xhttp.open("GET", str, true);
  xhttp.send();
}
function movePrev(){
	document.getElementById('start').value = Number(document.getElementById('start').value) - 10;
	document.getElementById('pagenumber').value = Number(document.getElementById('pagenumber').value) - 1;
	var start = document.getElementById('start').value;
	var pagenumber = document.getElementById('pagenumber').value;
	var reference = document.getElementById('reference').value;
	var date = document.getElementById('date').value;
	var client_code = document.getElementById('client_code').value;
	var str = "ListOfRMA_Actions.php?actionmode=moveprev&start="+start+"&pagenumber="+pagenumber+"&reference="+reference+"&date="+date+"&client_code="+client_code;
	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('listrma').innerHTML = data[0];
		}
  };
  xhttp.open("GET", str, true);
  xhttp.send();
}
function displayDetails(rma_id){
	var str = "ListOfRMA_Actions.php?actionmode=showrmadt&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]');
		
		document.getElementById('details_'+rma_id).innerHTML = data[0];
		$("#details_"+rma_id).toggle("medium");
		}
  };
  xhttp.open("GET", str, true);
  xhttp.send();
}
function searchRMA(){
	var reference = document.getElementById('reference').value;
	var date = document.getElementById('date').value;
	var client_code = document.getElementById('client_code').value;
	var str = "ListOfRMA_Actions.php?actionmode=searchrma&reference="+reference+"&date="+date+"&client_code="+client_code;
	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('listrma').innerHTML = data[0];
		}
  };
  xhttp.open("GET", str, true);
  xhttp.send();
}
function deleteRMA(rma_id){
	var reference = document.getElementById('reference').value;
	var date = document.getElementById('date').value;
	var client_code = document.getElementById('client_code').value;
	var c = confirm("Are you sure?");
	if(c){
	var str = "ListOfRMA_Actions.php?actionmode=deleterma&reference="+reference+"&date="+date+"&client_code="+client_code+"&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]');
		document.getElementById('listrma').innerHTML = data[0];
		}
  };
  xhttp.open("GET", str, true);
  xhttp.send();
	}
}
function editRMA(rma_id){
	var to_type = document.getElementById('to_type').value;
	var str = "Form_RMA_Actions.php?actionmode=setedit&RMA_Id="+rma_id+"&to_type="+to_type;
	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]);
		if(data[16] == "MR"){
			opener.document.getElementById('actionmode').value = "insert";
		}
		else{
		opener.document.getElementById('actionmode').value = "edit";
		}
		opener.document.getElementById('RMA_Id').value = data[0];
		opener.document.getElementById('RMA_ref').innerHTML = data[1];
		opener.document.getElementById('RMA_Date').value = data[2];
		opener.document.getElementById('RMA_No').value = data[3];
		opener.document.getElementById('RMA_PromissDate').value = data[4];
		opener.document.getElementById('client_name').value = data[5];
		opener.document.getElementById('Currency_code').value = data[6];
		opener.document.getElementById('Rmacharge_amount').value = data[7];
		opener.document.getElementById('Client_Email').value = data[8];
		opener.document.getElementById('RMA_ClientTelephone').value = data[9];
		opener.document.getElementById('RMA_ClientMobile').value = data[10];
		opener.document.getElementById('Rma_Remark').value = data[11];
		opener.document.getElementById('txtsubject').value = data[12];
		opener.document.getElementById('textengineer').value = data[13];
		opener.document.getElementById('client_code').value = data[15];
		opener.document.getElementById('list_rmadt').innerHTML = data[14];
		opener.document.getElementById('Rma_Remark2').value = data[17];
		opener.document.getElementById('txtemail').value = data[18];
		opener.document.getElementById('textengineer2').value = data[19];
		//opener.document.getElementById('Client_Email').value = data[8];
		opener.document.getElementById('btnsearch').style.display = "none";
		opener.document.getElementById('btnpending').style.display = "none";
		opener.document.getElementById('btncancel').style.display = "inline-block";
		opener.document.getElementById('btnsave').style.display = "inline-block";
		opener.document.getElementById('btnload').style.display = "none";
		if(data[20]!=""){
			opener.document.getElementById('btngotoreturnrma').innerHTML = "<button onclick=\"openReturnRMA("+data[20]+"); return false;\"><span><span>Return RMA</span></span></button>";
		}
		window.close();
		}
  };
  xhttp.open("GET", str, true);
  xhttp.send();
	
}
function printPreview(rma_id){
	var str = "Form_RMAPreview.php?rma_id="+rma_id;
	window.open(str);
}
</script>
<script src="jquery.min.js"></script>
<style>
.button{
	border-radius: 15px;
	border: none;
	box-shadow: 3px 4px 17px #888888;
	background: #016a84;
	cursor: pointer;
	width: 120px;
	color: #FFFFFF;
	padding: 8px;
	height: auto;
}
</style>
</head>
HERE;
echo"<body>
<table width=1090 style='border-collapse: collapse'>
<tr>
<th colspan=9 style='font-family: Arial; padding: 5px; background: #016a84; color: #ffffff;'>List of RMAs</th>
</tr>
<tr>
<th colspan=9 style='background: #dddddd'>
<table>
<tr>
<td style='width: 100px; font-weight: bold; font-size: 14px; font-family: Arial'>Reference</td>
<td><input type='text' name='reference' id='reference'></td>
<td style='width: 20px'></td>
<td style='width: 100px; font-weight: bold; font-size: 14px; font-family: Arial'>Date</td>
<td><input type='text' name='date' id='date' /> <A HREF='#' onClick=\"displayCalendar(document.getElementById('date'),'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A></td>
<td style='width: 20px'></td>
<td style='width: 100px; font-weight: bold; font-size: 14px; font-family: Arial'>Client</td>
<td><input type='text' name='client_code' id='client_code' style='width: 100px'/> <input type='text' name='client_name' id='client_name' style='width: 200px'/> <img src='img/btnopen.jpg' width=20 style='vertical-align: middle; cursor: pointer' onclick=\"openListCustomers(10)\" /></td>


</tr>
</table>
</th>

</tr>
<tr>
<th colspan=9 style='background: #dddddd; padding: 10px'>
<button class='button' onclick=\"searchRMA()\">Search</button>
</th>
</tr>
<tr>";
$query_access  = "select FI_RMA, FI_RMAApp, FI_RMAMod, FI_RMADel 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);
echo "<input type='hidden' id='to_type' value='".$_GET['to_type']."' />";
echo"<th colspan=9 id='listrma'>";
drawListRMA($connection, $FI_RMA, $FI_RMAApp, $FI_RMAMod, $FI_RMADel);
echo"</th>
</tr>

</table>
</body>
</html>";
?>