<?php
include('../include/session.php');
date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s", time()); 

$cust_id = $_GET['cust_id_text'];
$return_qty = $_GET['return_qty_text'];
$return_date = $_GET['return_date'];

$table_name = $_SESSION['db_prefix']."_pallets_balance";
$no_query = "SELECT entry_reference FROM $table_name WHERE entry_type = 'ret' ORDER BY entry_reference DESC LIMIT 1 ";
$no_result = mySQL_query($no_query);
$no_num = mysql_num_rows($no_result);
if ($no_num == 0) {
	 $entry_reference = 1000;
}
else {
	$entry_reference = mysql_result($no_result, 0, "entry_reference") + 1;
}

$table_name = $_SESSION['db_prefix']."_pallets_balance";
$return_query = "INSERT INTO $table_name (entry_reference, entry_type, cust_id, ret_qty, ret_date ) VALUES ('".$entry_reference."', 'ret', '".$cust_id."', '".$return_qty."', '".$return_date."' ) ";
execsql($return_query);

$table_name = $_SESSION['db_prefix']."_tracking_store";
$trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '40', '".$entry_reference."', '".$cust_id."' ,'".$return_qty."', '".$return_date."' )";
$trackingResult = mySQL_query($trackingQuery);	

include('../include/pallet_return_alert.php');


?>

<script language="javascript" type="text/javascript">
        
		  window.location="return_pallets_display?entry_reference=<?php echo $entry_reference ?>";
        
       </script>