<?php
include("../include/session.php");
	
	$query = "SELECT productId FROM products ORDER BY productId DESC LIMIT 1 ";
	$result = mySQL_query($query) or die ("Error in query:   $Query . * ". mySQL_error());
	$productId = mysql_result($result, 0, "productId");
	$productId= $productId+1;
	
	if (isset($_GET['new_button']) )
	   {
		 $action='storeWiz0.php';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		$action='stockItemDisplay.php?productId='.$productId ;
	  }
	
	
	$d = date("d");
	$m = date("m");
	$y = date("Y");
	$modDate=date('Y-m-d');
	$active="1";
	
	if ($_SESSION['category'] == "Tiles and Accessories"){
	   	  $productName = $_SESSION['productName']." ".$_SESSION['color'];
	}
	else {
	   $productName = $_SESSION['productName'];
	   }
	$category = $_SESSION['category'];
	$subCat = $_SESSION['subCategory'];
	$unit = $_SESSION['unit'];
	$shelf = $_SESSION['shelf'];
	$minimumStock = $_SESSION['minimumStock'];
	$dep = $_SESSION['depreciation'];
	$returnable = $_SESSION['returnable'];
	$date = date("Y-m-d");
	$price = $_SESSION['price'];
	$productSpecs = $_SESSION['productSpecs'];
	$userId = $_SESSION['username'];
	date_default_timezone_set('Africa/Khartoum');
	$entryDate = date("Y-m-d H:i:s",time()-3600); 
	$quantity ="0";
	$entry="10";
	$reference="";
		
		$stockQuery = "INSERT INTO products (productId, productName, category, subCategory, shelf, unit, returnable, minimumStock, depreciation, date, price, productSpecs) VALUES ('$productId', '$productName', '".$category."', '".$subCat."', '".$shelf."','".$unit."','".$returnable."', '$minimumStock', '".$dep."','".$date."', '$price', '$productSpecs')";
	$stockResult = mySQL_query($stockQuery);
		
		
	$historyQuery = "INSERT INTO itemhistory (productId, details, entry, reference, quantity, total, date, entryDate, userId) VALUES ('".$productId."','','".$entry."', '".$reference."','".$quantity."', '".$quantity."','".$date."','".$entryDate."','".$userId."')";
	$historyResult = mySQL_query($historyQuery);	

	
	$actionQuery = "INSERT INTO action_tracking (entry_date, user, action, details) VALUES ('".$entryDate."' ,'".$userId."','New stock item' ,'".$productName."' )";
	$actionResult = mySQL_query($actionQuery);
	
?>
<?php
    $_SESSION['productName'] ="";
	 $_SESSION['color'] ="";
     $_SESSION['suppliersName'] = "";
	 $_SESSION['category'] = "";
	 $_SESSION['subCategory'] = "";
	 $_SESSION['shelf'] = "";
	 $_SESSION['unit'] = "";
	 $_SESSION['returnable'] = "";
	 $_SESSION['quantity'] = "";
	 $_SESSION['minimumStock'] = "";
	 $_SESSION['price'] = "";
	 $_SESSION['depreciation'] = "";
	 $_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>
