<?PHP

// include server parameters
require('includes/configure.php');
require(DIR_WS_FUNCTIONS . 'database.php');
// make a connection to the database... now
zen_db_connect() or die('Unable to connect to database server!');

if($_SERVER['REQUEST_METHOD'] == 'POST'){
	
	$sales_id=$_POST['X-S_TORIHIKI_NO'];
	$tranid=$_POST['X-TRANID'];
	$refapproved=$_POST['X-REFAPPROVED'];
	$refforwarded=$_POST['X-REFFORWARDED'];
	$errcode=$_POST['X-ERRCODE'];
	$errinfo=$_POST['X-ERRINFO'];
	$errlevel=$_POST['X-ERRLEVEL'];
	$r_code=$_POST['X-R_CODE'];
	$rec_type=$_POST['REC_TYPE'];
	$x_amount=$_POST['X-AMOUNT'];
	$x_tax=$_POST['X-TAX'];
	$x_total=$_POST['X-TOTAL'];
	$today = date('Y-m-d H:i:s');
	
	$result = mysql_query("INSERT INTO remise_result VALUES('','$sales_id','$tranid','$refapproved','$refforwarded','$errcode','$errinfo','$errlevel','$r_code','$rec_type','$x_amount','$x_tax','$x_total','','','','$today')");
	
	if(! $result ){
		mysql_query("CREATE TABLE remise_result (
			num int(11) auto_increment primary key,
			sales_id varchar(20),
			tranid varchar(30),
			refapproved varchar(10),
			refforwarded varchar(10),
			errcode varchar(5),
			errinfo varchar(10),
			errlevel varchar(2),
			r_code varchar(10),
			rec_type varchar(5),
			x_amount varchar(10),
			x_tax varchar(10),
			x_total varchar(10),
			status varchar(10),
			opt1 varchar(20),
			opt2 varchar(20),
			create_date date)"
			);
		$result = mysql_query("INSERT INTO remise_result VALUES('','$sales_id','$tranid','$refapproved','$refforwarded','$errcode','$errinfo','$errlevel','$r_code','$rec_type','$x_amount','$x_tax','$x_total','','','','$today')");
	
	}
	
		mysql_close();
	
	if($result){
		print "<SDBKDATA>STATUS=800</SDBKDATA>";
	}
	
}


?>