<?php
include("../include/session.php");
	
	$d = date("d");
	$m = date("m");
	$y = date("Y");
	$modDate=date('Y-m-d');
	$active="1";
	
	$item_name = trim($_SESSION['item_name']); 
	$category = trim($_SESSION['category']);
	$subCat = trim($_SESSION['subCategory']);
	$unit = trim($_SESSION['unit']);
	$location = trim($_SESSION['location']);
	$minimumStock = trim($_SESSION['minimumStock']);
	$maximumStock = trim($_SESSION['maximumStock']);
	
	$date = date("Y-m-d");
	$price = trim($_SESSION['price']);
	$sales_price = trim($_SESSION['sales_price']);
	$productSpecs = trim($_SESSION['productSpecs']);
	
	date_default_timezone_set('Africa/Gaborone');
	$entryDate = date("Y-m-d H:i:s",time()-3600); 
	$quantity ="0";
	$entry="10";
	$reference='';
		
	$table_name = $_SESSION['db_prefix']."_store_items";		
		$stockQuery = "INSERT INTO $table_name (item_name, category, subCategory, location, unit, minimumStock, maximumStock, add_date, lastModDate,  price, price_2, productSpecs, stockTake, register) VALUES ( trim('".$item_name."'), '".$category."', '".$subCat."', '".$location."','".$unit."', '".$minimumStock."', '".$maximumStock."', '".$date."', '".$date."', '".$price."', '".$sales_price."', trim('".$productSpecs."'), 'S', '".$_SESSION['register']."' )";
	$stockResult = mySQL_query($stockQuery);
		
	
    $id_query = "SELECT store_item_id  FROM $table_name ORDER BY store_item_id DESC LIMIT 1  ";
    $id_result = mySQL_query($id_query);
    $store_item_id = mysql_result($id_result, 0, "store_item_id");
		
	$table_name2 = $_SESSION['db_prefix']."_item_history";	
	$historyQuery = "INSERT INTO $table_name2 (store_item_id, entry, reference, quantity, total, price, price_2, date, entryDate, userId) VALUES ('".$store_item_id."', '".$entry."', '".$reference."','".$quantity."', '".$quantity."', '".$price."','".$sales_price."', '".$date."','".$entryDate."','".$_SESSION['username']."')";
	$historyResult = mySQL_query($historyQuery);	

	$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 ('".$entryDate."' ,'".$_SESSION['username']."', '70', '".$store_item_id."' ,'','','' )";
	$trackingResult = mySQL_query($trackingQuery);
	
	
	if (isset($_GET['new_button']) )
	   {
		 $action='storeWizbase.php?error=0&p=1&s=0';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		$action='store_item_display.php?store_item_id='.$store_item_id ;
	  }
	 
	
?>
<?php
     $_SESSION['item_name'] ="";
	 $_SESSION['color'] ="";
     $_SESSION['suppliersName'] = "";
	 $_SESSION['category'] = "";
	 $_SESSION['subCategory'] = "";
	 $_SESSION['location'] = "";
	 $_SESSION['unit'] = "";
	 $_SESSION['quantity'] = "";
	 $_SESSION['minimumStock'] = "";
	 $_SESSION['maximumStock'] = "";
	 $_SESSION['price'] = "";
	 $_SESSION['date'] = "";
	 $_SESSION['productSpecs'] = "";
	 $_SESSION['p'] = 1;
	 $_SESSION['error']=0;
	 $_SESSION['changed']="";
	 $_SESSION['changed2']="";
	 
?>

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