<?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'];
$cash_sale_no = $_GET['cash_sale_no_text'];
$product_item_id = $_GET['product_item_id_text'];
$item_type = $_GET['item_type_text'];
$product_price = $_GET['product_price'];
$line = $_GET['line'];

$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines_temp";
$delete_line_query = "DELETE FROM $table_name WHERE  line = '".$line."' AND user_name = '".$_SESSION['username']."' "; 
$delete_line_result = $con->query($delete_line_query);


$_SESSION['list_product_item_id_'.$line] = $product_item_id;

$k=0;
while ($k<$line_num) {
$product_store_line_id = $_GET['product_store_line_id_text'.$k];
$batch_code = $_GET['batch_code_text'.$k];
$qty = $_GET['del_qty_text'.$k];


if ($qty>0) {
	

	
$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines_temp";
$add_query = "INSERT INTO $table_name (line, cash_sale_no, product_item_id, item_type, price, quantity, batch_code, product_store_line_id, user_name) VALUES ('".$line."', '".$cash_sale_no."', '".$product_item_id."', '".$item_type."', '".$product_price."', '".$qty."', '".$batch_code."', '".$product_store_line_id."', '".$_SESSION['username']."') ";
$add_result = $con->query($add_query);
}

//$table_name = $_SESSION['db_prefix']."_tracking_production";
//$tracking_query = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '68', '".$design_no."' , '".$store_item_id."','','".$qty."' )";
//$tracking_result = $con->query($tracking_query);

$k++;
}
?>


<script language="javascript" type="text/javascript">
        window.location="../store/newCashWizbase.php?p=3&s=&list_product_item_id=<?php echo $_SESSION['list_product_item_id_'.$line] ?>";
</script>