forked from jevuu/e-ceipt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
737 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
/build | ||
/captures | ||
.externalNativeBuild | ||
PHP/conn.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
require "conn.php"; | ||
|
||
//Get user | ||
//By ID | ||
echo "<p>GET John Doe BY userID <br />"; | ||
$qString = "SELECT name FROM users WHERE userID = 1"; | ||
$resultName = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($resultName) > 0){ | ||
$row = mysqli_fetch_row($resultName); | ||
echo "Found: " . $row[0] . "<br />"; | ||
}else{ | ||
echo "No user found. <br />"; | ||
} | ||
echo "</p>"; | ||
|
||
//By name | ||
echo "<p>GET John Doe BY name <br />"; | ||
$qString = "SELECT name FROM users WHERE name = 'John Doe'"; | ||
$resultName = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($resultName) > 0){ | ||
$row = mysqli_fetch_row($resultName); | ||
echo "Found: " . $row[0] . "<br />"; | ||
}else{ | ||
echo "No user found. <br />"; | ||
} | ||
echo "</p>"; | ||
|
||
//Get items | ||
echo "<p>Get all items<br />"; | ||
$qString = "SELECT name, description FROM items"; | ||
$resultItems = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($resultItems) > 0){ | ||
while($row = mysqli_fetch_row($resultItems)){ | ||
echo "Found Item: " . $row[0] . " - " . $row[1] . "<br />"; | ||
} | ||
}else{ | ||
echo "No items found. <br />"; | ||
} | ||
echo "</p>"; | ||
|
||
//Get all items in DB, show creators | ||
echo "<p>Get all items from database from creator John Doe<br />"; | ||
$qString = "SELECT i.name, u.name | ||
FROM items i | ||
INNER JOIN users u ON i.userID = u.userID | ||
WHERE i.userID = 1 "; | ||
$resultItems = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($resultItems) > 0){ | ||
while($row = mysqli_fetch_row($resultItems)){ | ||
echo "Found Item: " . $row[0] . " was created by " . $row[1] . "<br />"; | ||
} | ||
}else{ | ||
echo "No items found. <br />"; | ||
} | ||
echo "</p>"; | ||
|
||
//Build a receipt | ||
echo "<p>Build an example receipt for John Doe.<br />"; | ||
$userID = 1; | ||
$receiptID = 1; | ||
$qString = "SELECT u.name, r.receiptID, r.creationDate, r.totalCost, r.tax | ||
FROM users u | ||
INNER JOIN receipts r ON r.userID = u.userID | ||
WHERE u.userID =" . $userID . " AND r.receiptID =" . $receiptID; | ||
$result = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($result) > 0){ | ||
$row = mysqli_fetch_row($result); | ||
$totalCost = $row[3]; | ||
$tax = $row[4]; | ||
echo "<table border=1><tr><th colspan=2>Receipt for " . $row[0] . "</th></tr>"; | ||
echo "<tr><td>Receipt: " . $row[1] . "</td><td> Created on: " . $row[2] . "</td></tr>"; | ||
|
||
$qString = "SELECT i.name, i.description, i.price | ||
FROM items i | ||
INNER JOIN receiptItems ri ON ri.itemID = i.itemID | ||
INNER JOIN receipts r ON r.receiptID = ri.receiptID | ||
WHERE r.receiptID =" . $receiptID; | ||
$result = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($result) > 0){ | ||
if ($totalCost > 0) | ||
$dontSum = true; | ||
while($row = mysqli_fetch_row($result)){ | ||
echo "<tr><td>" . $row[0] . "<br />" . $row[1] . "</td><td>" . $row[2] . "</td></tr>"; | ||
if(!$dontSum) | ||
$totalCost += $row[2]; | ||
} | ||
}else{ | ||
echo "<tr><td colspan=2> No items found. </td></tr>"; | ||
} | ||
echo "<tr><td>Total</td><td>" . $totalCost . "</td></tr>"; | ||
echo "</table>"; | ||
}else{ | ||
echo "No data found."; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?php | ||
|
||
require "conn.php"; | ||
|
||
echo "<hr /><h2>Create a user named Donatello, create a receipt for him, add items to receipt, display receipt, delete Donatello (and all receipts and items)</h2>"; | ||
|
||
$uID = 0; | ||
$rID = 0; | ||
$iID = array(); | ||
|
||
//BIG TEST BELOW | ||
//Create user | ||
$userName = "Donatello"; | ||
$qString = "INSERT INTO users (`name`,`creationDate`) VALUES ('" . $userName . "', CURRENT_DATE)"; | ||
mysqli_query($conn, $qString); | ||
|
||
$qString = "SELECT userID FROM users WHERE name='" . $userName. "'"; | ||
$result = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($result) == 1){ | ||
$row = mysqli_fetch_row($result); | ||
$uID = $row[0]; | ||
echo "User created! User ID: " . $uID . "<br /><br />"; | ||
}else{ | ||
echo "Failed to create user or multiple users.<br /><br />"; | ||
} | ||
|
||
//Create receipt | ||
$qString = "INSERT INTO receipts (`userID`, `creationDate`) VALUES(" . $uID . ", CURRENT_DATE)"; | ||
mysqli_query($conn, $qString); | ||
|
||
$qString = "SELECT receiptID FROM receipts WHERE userID =" . $uID; //This only works because only one receipt was ever created for this user. Won't work in real world. | ||
$result = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($result) == 1){ | ||
$row = mysqli_fetch_row($result); | ||
$rID = $row[0]; | ||
echo "Receipt created! Receipt ID: " . $rID . "<br /><br />"; | ||
}else{ | ||
echo "Failed to create receipt, or multiple receipts.<br /><br />"; | ||
} | ||
|
||
//Add items | ||
$qString = "INSERT INTO items(`userID`, `name`, `price`) VALUES(" . $uID . ", 'Bread', '8.50'), (" . $uID . ", 'Milk', '9.50')"; | ||
mysqli_query($conn, $qString); | ||
|
||
$qString = "SELECT itemID FROM items WHERE userID = " . $uID; | ||
$result = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($result) == 2){ | ||
echo "Success! Two items created."; | ||
while($row = mysqli_fetch_row($result)){ | ||
array_push($iID, $row[0]); | ||
} | ||
}else{ | ||
echo "Error, no items or not 2 items created.<br /><br />"; | ||
} | ||
|
||
//Link tables | ||
$qString = "INSERT INTO receiptItems(`receiptID`, `itemID`) VALUES(" . $rID . "," . $iID[0] . "), (" . $rID . "," . $iID[1] . ")"; | ||
mysqli_query($conn, $qString); | ||
|
||
//Build receipt | ||
echo "<p>Build an example receipt for Donatello.<br />"; | ||
$qString = "SELECT u.name, r.creationDate, r.totalCost, r.tax | ||
FROM users u | ||
INNER JOIN receipts r ON r.userID = u.userID | ||
WHERE u.userID =" . $uID . " AND r.receiptID =" . $rID; | ||
$result = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($result) > 0){ | ||
$row = mysqli_fetch_row($result); | ||
$totalCost = $row[2]; | ||
$tax = $row[3]; | ||
echo "<table border=1><tr><th colspan=2>Receipt for " . $row[0] . "</th></tr>"; | ||
echo "<tr><td colspan=2> Created on: " . $row[1] . "</td></tr>"; | ||
|
||
$qString = "SELECT i.name, i.description, i.price | ||
FROM items i | ||
INNER JOIN receiptItems ri ON ri.itemID = i.itemID | ||
INNER JOIN receipts r ON r.receiptID = ri.receiptID | ||
WHERE r.receiptID =" . $rID; | ||
$result = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($result) > 0){ | ||
if ($totalCost > 0) | ||
$dontSum = true; | ||
while($row = mysqli_fetch_row($result)){ | ||
echo "<tr><td>" . $row[0] . "<br />" . $row[1] . "</td><td>" . $row[2] . "</td></tr>"; | ||
if(!$dontSum) | ||
$totalCost += $row[2]; | ||
} | ||
}else{ | ||
echo "<tr><td colspan=2> No items found. </td></tr>"; | ||
} | ||
echo "<tr><td>Total</td><td>" . $totalCost . "</td></tr>"; | ||
echo "</table><br /><br />"; | ||
}else{ | ||
echo "No data found. <br /><br />"; | ||
} | ||
|
||
//Delete Dontello | ||
echo "Delete Donatello by userID, which should automatically delete all receipts and items belonging to him. <br /><br />"; | ||
|
||
$qString = "DELETE FROM users WHERE userID = " . $uID; | ||
mysqli_query($conn, $qString); | ||
|
||
$qString = "SELECT name FROM users WHERE userID = " . $uID; | ||
$result = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($result) == 0){ | ||
echo "Donatello was deleted! <br />"; | ||
}else{ | ||
echo "Donatello was not deleted! <br />"; | ||
} | ||
|
||
$qString = "SELECT receiptID FROM receipts WHERE userID = " . $uID; | ||
$result = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($result) == 0){ | ||
echo "Donatello's receipt was deleted! <br />"; | ||
}else{ | ||
echo "Donatello receipt was not deleted! <br />"; | ||
} | ||
|
||
$qString = "SELECT itemID FROM items WHERE userID = " . $uID; | ||
$result = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($result) == 0){ | ||
echo "Donatello's items were deleted! <br />"; | ||
}else{ | ||
echo "Donatello's items were not deleted! <br />"; | ||
} | ||
|
||
$qString = "SELECT itemID FROM receiptItems WHERE receiptID = " . $rID; | ||
$result = mysqli_query($conn, $qString); | ||
if(mysqli_num_rows($result) == 0){ | ||
echo "Donatello's data in link table for receipt and items was deleted! <br />"; | ||
}else{ | ||
echo "Donatello's data in link table for receipt and items was not deleted! <br />"; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<html> | ||
<head> | ||
<title> | ||
e-Ceipt Data Entry Test Form | ||
</title> | ||
</head> | ||
|
||
<body> | ||
<form action="testResult.php" method="post"> | ||
Customer name: <input type="text" name="userName" placeholder="Enter a name"><br /> | ||
Items purchased: (For every item name, a price MUST be present)<br /> | ||
<ol> | ||
<li><input type="text" name="items[itemName][]" placeholder="Item name">...<input type="text" name="items[itemPrice][]" placeholder="Price"></li> | ||
<li><input type="text" name="items[itemName][]" placeholder="Item name">...<input type="text" name="items[itemPrice][]" placeholder="Price"></li> | ||
<li><input type="text" name="items[itemName][]" placeholder="Item name">...<input type="text" name="items[itemPrice][]" placeholder="Price"></li> | ||
<li><input type="text" name="items[itemName][]" placeholder="Item name">...<input type="text" name="items[itemPrice][]" placeholder="Price"></li> | ||
<li><input type="text" name="items[itemName][]" placeholder="Item name">...<input type="text" name="items[itemPrice][]" placeholder="Price"></li> | ||
</ol> | ||
<input type="submit"> | ||
</form> | ||
</body> | ||
</html> |
Oops, something went wrong.