<?php
include ("../../include/session.php");
include ("../../include/db.php");
if (!$session->isAdmin()) {
	header("Location: ../main.php");
} else {
	$saleId = mysql_real_escape_string($_POST['saleId']);
	$productId = mysql_real_escape_string($_POST['productId']);
	//		$empId = mysql_real_escape_string($_POST['empId']);
	$orderNo = mysql_real_escape_string($_POST['order']);
	$client = mysql_real_escape_string($_POST['client']);
	$quantity = mysql_real_escape_string($_POST['quantity']);
	$price = mysql_real_escape_string($_POST['price']);
	$comments = mysql_real_escape_string($_POST['comments']);
	$delNote = mysql_real_escape_string($_POST['delNote']);
	$date = isset ($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
	$q2 = "SELECT quantity FROM products WHERE productId = '$productId'";
	$result2 = execsql($q2);
	$totalQuantity = mysql_result($result2, 0, "quantity") - $quantity;

//	$q1 = "UPDATE products SET quantity = quantity - '$quantity' WHERE productId = '$productId'";


	$q = "UPDATE orders SET productId = '$productId', client = '$client', orderNo = '$orderNo', delNote = '$delNote', quantity = '$quantity', price = '$price', comments = '$comments', date = '$date', value = '$client' WHERE saleId = '$saleId'";
//	$q = "INSERT INTO sales (productId, client, orderNo, delNote, quantity, price, comments, date, value) VALUES ('" . $productId . "', '$client','" . $orderNo . "', '" . $delNote . "' ,'" . $quantity . "','" . $price . "', '$comments', '" . $date . "', '$client')";
//	$q3 = "INSERT INTO itemhistory (productId, details, quantity, total, date) VALUES ('" . $productId . "', 'Order: " . $orderNo . "','" . $quantity . "','" . $totalQuantity . "','" . $date . "')";
	$return = mysql_real_escape_string($_POST['submitok']);
	
//	echo $q;

	$result = execsql($q);
//	$resultQ = execsql($q1);
//	$resultH = execsql($q3);
	if ($result) {
		if ($return == "Save and New") {
			$cat = mysql_real_escape_string($_POST['cat']);
			header("Location: ../editDelNote.php?delNote=$delNote");
		} else {
						header("Location: ../displayDelNote.php?delNote=$delNote");
		}
	}
}
?>