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


$actionmode    = $_GET['actionmode'];
$searchserial  = $_GET['searchserial'];
$start         = $_GET['start'];
$pagenumber    = $_GET['pagenumber'];
$serial_number = $_GET['serial_number'];
if($actionmode == "searchserial"){
   drawListSerialNo($connection, $searchserial, $start, $pagenumber);
   echo "[BRK]";
}
else
	if($actionmode == "movenext"){
		drawListSerialNo($connection, $searchserial, $start, $pagenumber);
        echo "[BRK]";
	}
	else
	if($actionmode == "moveprev"){
		drawListSerialNo($connection, $searchserial, $start, $pagenumber);
        echo "[BRK]";
	}
	else
		if($actionmode == "getinvoice"){
			$query_module  = "select module_delivery from module";
			$result_module = mysql_query($query_module, $connection); 
			$row_module    = mysql_fetch_array($result_module);
			extract($row_module);
			
			if($module_delivery == 1){
				$query = "select sales.sale_reference as InvRef, date_format(sales.sale_date, '%d/%m/%Y') as InvDate
				          from sales inner join salesdt on salesdt.sale_id = sales.sale_id
						  inner join purchasesserialno on purchasesserialno.purchasedt_id = salesdt.saledt_id
						  where purchasesserialno.serialno_code = '$serial_number'";
			}
			else{
				$query = "select deliveries.delivery_reference as InvRef, date_format(deliveries.delivery_date, '%d/%m/%Y') as InvDate
				          from deliveries inner join deliverydt on deliverydt.delivery_id = deliveries.delivery_id
						  inner join purchasesserialno on purchasesserialno.purchasedt_id = deliverydt.deliverydt_id
						  where purchasesserialno.serialno_code = '$serial_number'";
			}
			$result = mysql_query($query, $connection);
			$row    = mysql_fetch_array($result);
			extract($row);
			
			echo $InvRef;
			echo "[BRK]";
			echo $InvDate;
			echo "[BRK]";
		}
?>