Commit 46c8bff2 authored by trh010's avatar trh010

edited stock shelves and refinded checkout+admin

parent 3a708ee3
File mode changed from 100644 to 100755
...@@ -17,9 +17,7 @@ ...@@ -17,9 +17,7 @@
$result = mysql_query("SELECT DISTINCT count FROM GroceryShelves WHERE item='$item';"); $result = mysql_query("SELECT DISTINCT count FROM GroceryShelves WHERE item='$item';");
if (!$result) die("Query1 failed!" . mysql_error()); if (!$result) die("Query1 failed!" . mysql_error());
$row = mysql_fetch_row($result); $row = mysql_fetch_row($result);
$num_on_shelves = intval($row[0]); $num_on_shelves = intval($row[0]);
//echo "<br>".$item . "<br>" . $quantity . "<br>" . $num_in_stock . "<br>";
// if we can update the database // if we can update the database
if($num_in_stock > $quantity and $num_in_stock > 0){ if($num_in_stock > $quantity and $num_in_stock > 0){
...@@ -27,14 +25,19 @@ ...@@ -27,14 +25,19 @@
// update GroceryShelves // update GroceryShelves
$new_onShelves_quant = $num_on_shelves + $quantity; $new_onShelves_quant = $num_on_shelves + $quantity;
//echo $new_onShelves_quant . "<br>"; //echo $new_onShelves_quant . "<br>";
$result = mysql_query("UPDATE GroceryShelves SET GroceryShelves.count=($new_onShelves_quant) WHERE item='$item';"); if($num_on_shelves == 0){
if (!$result) die("Query2 failed!" . mysql_error()); $result = mysql_query("INSERT INTO GroceryShelves (item,count)VALUES ('$item',$new_onShelves_quant);");
if (!$result) die("Query2 failed!" . mysql_error());
} else {
$result = mysql_query("UPDATE GroceryShelves SET GroceryShelves.count=($new_onShelves_quant) WHERE item='$item';");
if (!$result) die("Query2 failed!" . mysql_error());
}
// update StockShelves // update StockShelves
$new_inStock_quant = $num_in_stock - $quantity; $new_inStock_quant = $num_in_stock - $quantity;
$result = mysql_query("UPDATE StockShelves SET StockShelves.count=($new_inStock_quant) WHERE item='$item';"); $result = mysql_query("UPDATE StockShelves SET StockShelves.count=($new_inStock_quant) WHERE item='$item';");
if (!$result) die("Query3 failed!" . mysql_error()); if (!$result) die("Query3 failed!" . mysql_error());
} }
$url = "../stocker.php"; $url = "../stocker.php";
while (ob_get_status()) while (ob_get_status())
......
...@@ -105,21 +105,21 @@ ...@@ -105,21 +105,21 @@
} }
echo "</tbody>\n</table>"; echo "</tbody>\n</table>";
mysql_free_result($result); mysql_free_result($result);
?> ?>
<h2>Active Carts</h2> <h2>Active Carts</h2>
<?php <?php
$result = mysql_query("Select cartID, customerName, item, itemQuantity FROM ( $result = mysql_query("Select cartID, customerName, item, itemQuantity FROM (
SELECT A.cartID, item, itemQuantity, customerID SELECT A.cartID, item, itemQuantity, customerID
FROM (SELECT * FROM Customers FROM (SELECT * FROM Customers
WHERE cartID NOT IN (SELECT cartID WHERE cartID NOT IN (SELECT cartID
FROM FROM
CheckedOut)) A CheckedOut)) A
LEFT JOIN Carts B LEFT JOIN Carts B
ON A.cartID = B.cartID ON A.cartID = B.cartID
ORDER BY A.cartID)C ORDER BY A.cartID)C
JOIN JOIN
CustomerInfo D CustomerInfo D
ON C.customerID=D.customerID ON C.customerID=D.customerID
ORDER BY cartID;"); ORDER BY cartID;");
if (!$result) if (!$result)
die("Query to show tuples from table failed!" . mysql_error()); die("Query to show tuples from table failed!" . mysql_error());
...@@ -144,6 +144,7 @@ ...@@ -144,6 +144,7 @@
mysql_free_result($result); mysql_free_result($result);
?> ?>
<h2>All Carts Ever</h2> <h2>All Carts Ever</h2>
<p><b>note: </b>empty carts are not displayed here</p>
<?php <?php
$result = mysql_query("SELECT * FROM Carts ORDER BY cartID ASC;"); $result = mysql_query("SELECT * FROM Carts ORDER BY cartID ASC;");
if (!$result) if (!$result)
...@@ -169,7 +170,7 @@ ...@@ -169,7 +170,7 @@
mysql_free_result($result); mysql_free_result($result);
?> ?>
<h2>Checkout Log</h2> <h2>Checkout Log</h2>
<p><b>note: </b>the cartID (which is the primary key of this table) is the second column</p> <p><b>note: </b>the cartID (which is the primary key of this table) is the second column</p>
<?php <?php
$result = mysql_query("SELECT * FROM CheckedOut ORDER BY cartID ASC;"); $result = mysql_query("SELECT * FROM CheckedOut ORDER BY cartID ASC;");
if (!$result) if (!$result)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment