<?php
include('../include/session.php');

date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s", time()); 

$line_num = $_GET['line_num'];
$order_no = $_GET['order_no'];

$i=0;
while ($i<$line_num) {
	
	$delivery_no = $_GET['delivery_no'.$i];
    $pallets = $_GET['pallets_text'.$i];
	
	if ($pallets>0) {
	
	$table_name = $_SESSION['db_prefix']."_pallets";
	$return_query = "UPDATE $table_name SET return_date = '".$entry_date."', ret_quantity = ret_quantity + '".$pallets."'  WHERE delivery_no = '".$delivery_no."' ";
	execsql($return_query);
		
	$table_name = $_SESSION['db_prefix']."_pallets_returned";
	$pallets_return_query = "INSERT INTO $table_name (delivery_no, ret_quantity, return_date ) VALUES ('".$delivery_no."', '".$pallets."', '".$entry_date."'  ) ";
	execsql($pallets_return_query);
	
	$table_name = $_SESSION['db_prefix']."_tracking_store";
	$trackingQuery = "INSERT INTO $table_name (entry_date, branch, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' , 'Francistown', '".$_SESSION['username']."', '26', '".$delivery_no."', '".$order_no."' ,'".$pallets."','' )";
	$trackingResult = mySQL_query($trackingQuery);	
	
	}
	
	$i++;
}


	if (isset($_GET['close_button']) )
	   { ?>
       <script>
	 		 window.location="store_main.php?date=0&branch=&subCatSelect=Tiles";
		</script>
        <?php		 
	   }
	   
	   if (isset($_GET['new_button']) )
	   {  ?>
       <script>
	          window.location="pallets_return.php?branch=Francistown&new=0&order_no=";
	   </script>
        <?php		 
	   }
	   ?>
