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



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

$receive_id = $_GET['receive_id'];
$store_item_id = $_GET['store_item_id_select0'];
$qty = $_GET['qty_text'];

$table_name = $_SESSION['db_prefix']."_store_items";
$item_query = "SELECT item_name, subCategory, price FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
$item_result = mySQL_query($item_query);
$item_name = mysql_result($item_result, 0, "item_name");
$sub_category = mysql_result($item_result, 0, "subCategory");
$price = mysql_result($item_result, 0, "price");


$table_name = $_SESSION['db_prefix']."_receive_store_lines";
$check_query = "SELECT receive_line_id FROM $table_name WHERE receive_id = '".$receive_id."' AND store_item_id = '".$store_item_id."'  ";
$check_result = mySQL_query($check_query);
$check_num = mysql_num_rows($check_result);

if ($check_num==0) {

$table_name = $_SESSION['db_prefix']."_receive_store_lines";
$add_query = "INSERT INTO $table_name (receive_id, store_item_id,  quantity) VALUES ('".$receive_id."', '".$store_item_id."', '".$qty."' ) ";
execsql($add_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']."', '32', '".$receive_id."' , '".$store_item_id."','','".$qty."' )";
execsql($trackingQuery);

$error=0;

}
else {
$error=1;
}


?>


<script language="javascript" type="text/javascript">
       window.location="../store/edit_receive_note.php?receive_id=<?php echo $receive_id ?>&e=<?php echo $error ?>";
</script>