<?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']);
	$width  = trim($_SESSION['width']);
	$depth  = trim($_SESSION['depth']);
	$area  = trim($_SESSION['plate_area']);
	$length  = trim($_SESSION['length']); 
	$class  = trim($_SESSION['class']);
	$location = trim($_SESSION['location']);
	$minimumStock = trim($_SESSION['minimumStock']);
	$dep = trim($_SESSION['depreciation']);
	$returnable = trim($_SESSION['returnable']);
	$date = date("Y-m-d");
	$price = trim($_SESSION['price']);
	$productSpecs = trim($_SESSION['productSpecs']);
	if ($class == 'La') {$length = 0;}
	
	date_default_timezone_set('Africa/Khartoum');
	$entryDate = date("Y-m-d H:i:s",time()-3600); 
	$quantity ="0";
	$entry="10";
	$reference='';
	$volume = ($width/1000) * ($depth/1000) * ($length/1000);
	$bulk_price='0.00';
	
	$table_name = $_SESSION['db_prefix']."_store_items";		
		$stockQuery = "INSERT INTO $table_name (item_name, width, depth, length, class, area, volume, category, subCategory, location, unit, returnable, minimumStock, depreciation, date, price, price_2, bulk_price,  productSpecs, stockTake) VALUES ( '".$item_name."', '".$depth."',  '".$width."', '".$length."', '".$class."','".$area."','".$volume."', '".$category."', '".$subCat."', '".$location."','".$unit."','".$returnable."', '".$minimumStock."', '".$dep."','".$date."', '".$price."', '".$price."', '".$bulk_price."', '".$productSpecs."', 'S' )";
	$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, date, entryDate, userId) VALUES ('".$store_item_id."', '".$entry."', '".$reference."','".$quantity."', '".$quantity."', '".$price."', '".$date."','".$entryDate."','".$_SESSION['username']."')";
	$historyResult = mySQL_query($historyQuery);	

	$table_name = $_SESSION['db_prefix']."_tracking_store";
	$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '10', '".$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['class'] = "";
	 
	 $_SESSION['plate_area'] = "";
	 
	 $_SESSION['length'] = "";
	 $_SESSION['width'] = "";
	 $_SESSION['depth'] = "";
	 $_SESSION['length'] = "";
	
	 $_SESSION['quantity'] = "";
	 $_SESSION['minimumStock'] = "";
	 $_SESSION['price'] = "";
	 
	 $_SESSION['date'] = "";
	 $_SESSION['productSpecs'] = "";
	 
	 $volume = '';
	$bulk_price='';
	 
?>

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