Skip to content

Commit

Permalink
Merge pull request #12 from jevuu/master
Browse files Browse the repository at this point in the history
Merge My Changes
  • Loading branch information
AlistairCG committed Jul 29, 2018
2 parents c72f194 + edf43b7 commit cec26b5
Show file tree
Hide file tree
Showing 90 changed files with 6,023 additions and 758 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/build
/captures
.externalNativeBuild
oldPHP
PHP/conn.php
app/google-services.json
.git.zip
45 changes: 45 additions & 0 deletions .idea/assetWizardSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 22 additions & 14 deletions PHP/addReceipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

$json = file_get_contents('php://input');
$obj = json_decode($json);
$userName = $obj->{'userName'};
$userID = $obj->{'userID'};
$receiptDate = $obj->{'date'}; //This must be a date object
$totalCost = $obj->{'totalCost'};
$tax = $obj->{'tax'};
$businessName = $obj->{'businessName'};
$items = $obj->{'items'};

//
$uID = 0;
$uID = $userID;
$rID = 0;
$iID = array();

Expand All @@ -35,55 +35,63 @@
}
*/

// GET USER ID
/*// GET USER ID
$qUsersString = "SELECT userID FROM users WHERE userName = '$userName'";
$result = mysqli_query($conn, $qUsersString);
$row = mysqli_fetch_row($result);
$uID = $row[0];
//echo "User ID found: " . $uID;

*/
// INSERT RECEIPT
$qReceiptString = "INSERT INTO receipts (`userID`, `creationDate`, `totalCost`, `tax`)
VALUES(" . $uID . ", '$receiptDate', " . $totalCost . ", " . $tax . ")";
$qReceiptString = "INSERT INTO receipts (`userID`, `businessName`, `creationDate`, `totalCost`, `tax`)
VALUES('$uID', '$businessName', '$receiptDate', " . $totalCost . ", " . $tax . ")";
if(mysqli_query($conn, $qReceiptString) === FALSE){
echo "An error occured creating the receipt.";
echo "An error occured creating the receipt. \n '$businessName'";
}

// GET receiptID
$qReceiptString = "SELECT receiptID FROM receipts WHERE userID = " . $uID . " ORDER BY receiptID DESC LIMIT 1";
$qReceiptString = "SELECT receiptID FROM receipts WHERE userID = '$uID' ORDER BY receiptID DESC LIMIT 1";
$result = mysqli_query($conn, $qReceiptString);
$row = mysqli_fetch_row($result);
$rID = $row[0];
//echo "Receipt ID found: " . $rID;


//Add items by first building the query string.
$qItemsString = "INSERT INTO items(`userID`, `name`, `description`, `price`) VALUES";
$itemCount = count($items); //Loop through $items and append data from it into the string
/*for($itm = 0; $itm < $itemCount; $itm++){
print_r($items);
echo $items[$itm]->price;
}*/
foreach($items as $key => $itm){
$itemName = $itm['name'];
$itemDesc = $itm['description'];
$itemPrice = $itm['price'];
$qItemsString .= "(" . $uID .", '$itemName', '$itemDesc', " . $itemPrice . ")";
$itemName = $itm->itemName;
$itemDesc = $itm->itemDesc;
$itemPrice = $itm->itemPrice;
$qItemsString = $qItemsString . "('$uID', '$itemName', '$itemDesc', " . $itemPrice . ")";
if($key < $itemCount - 1){
$qItemsString = $qItemsString . ", ";
}
}
echo $qItemsString;

if(mysqli_query($conn, $qItemsString) === FALSE){
echo "An error has occured. Unable to insert items into database.";
}

//Get the itemIDs of the new items
$qString = "SELECT itemID FROM items WHERE userID = " . $uID ." ORDER BY itemID DESC LIMIT " . $itemCount;
$qString = "SELECT itemID FROM items WHERE userID = '$uID' ORDER BY itemID DESC LIMIT " . $itemCount;
$result = mysqli_query($conn, $qString);
while($row = mysqli_fetch_row($result)){
array_push($iID, $row[0]);
//echo "Item ID found: " . $iID[0];
//echo "Item ID found: " . $row[0];
}

//Link tables
$qLinkString = "INSERT INTO receiptItems(`receiptID`, `itemID`) VALUES";
for($i = 0; $i < $itemCount; $i++){
$qLinkString .= "(" . $rID . "," . $iID[$i] . ")";
//echo "Linking receipt: " . $rID . " with item: " . $iID[$i];
if($i < $itemCount - 1){
$qLinkString .= ", ";
}
Expand Down
24 changes: 24 additions & 0 deletions PHP/deleteReceipt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

require "conn.php";

$json = file_get_contents('php://input');
$obj = json_decode($json);
$rID = $obj->{'receiptID'};

//Delete receipt
$qString = "DELETE FROM receipts WHERE receiptID = " . $rID;
if(mysqli_query($conn, $qString) === FALSE){
echo "Failed to delete receipt.";
}

//Test deletion
/*$qString = "SELECT FROM receipts WHERE receiptID = " . $rID;
$result = mysqli_query($conn, $qString);
if(mysqli_num_rows($result) == 0){
echo "Receipt was deleted! <br />";
}else{
echo "Receipt was not deleted! <br />";
}*/

?>
21 changes: 21 additions & 0 deletions PHP/deleteUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

require "conn.php";

$json = file_get_contents('php://input');
$obj = json_decode($json);
$userID = $obj->{'userID'};

$qString = "DELETE FROM users WHERE userID = '$uID'";
mysqli_query($conn, $qString);

//Test deletion
$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 />";
}

?>
65 changes: 65 additions & 0 deletions PHP/getOneReceipt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

require "conn.php";

//Get userName from JSON
$json = file_get_contents('php://input');
$obj = json_decode($json);
$rID = $obj->{'receiptID'};

//If userName doesn't exist, use grab from John Doe. ONLY FOR TESTING PURPOSES. REMOVE IN FINAL
if($rID == ""){
$rID = "1";
}

//Get one receipt by receiptID
//$qString = "SELECT u.name, r.receiptID, r.creationDate, r.totalCost, r.tax, r.businessID
$qString = "SELECT u.name, r.receiptID, r.creationDate, r.totalCost, r.tax, r.businessName
FROM users u
INNER JOIN receipts r ON r.userID = u.userID
WHERE r.receiptID= '$rID'" ;
$qReceipt= mysqli_query($conn, $qString);
$receipt= mysqli_fetch_row($qReceipt);

/*Get business name from Business table
$qString = "SELECT u.name
FROM users u
INNER JOIN businesses b ON b.userID = u.userID
WHERE b.businessID = $receipt[5] limit 1";
$qBusiness = mysqli_query($conn, $qString);
$businessName = mysqli_fetch_object($qBusiness);
*/

//Build an array of items from the receipt
//Then push into the "items" array
$items = array();
$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 =" . $receipt[1];
$qReceiptItems= mysqli_query($conn, $qString);
while($receiptItem= mysqli_fetch_row($qReceiptItems)){
$tempItem = [
'itemName' => $receiptItem[0],
'itemDesc' => $receiptItem[1],
'itemPrice' => $receiptItem[2]
];
array_push($items, $tempItem);
}

//Build the receipt
$receipt = [
'name' => $receipt[0],
'receiptID' => $receipt[1],
'date' => $receipt[2],
'totalCost' => $receipt[3],
'tax' => $receipt[4],
'items' => $items,
//'businessName' => $businessName->name //Not used as business is stored in receipt now
'businessName' => $receipt[5]
];

//Display the data in json format
echo json_encode($receipt);
?>
16 changes: 10 additions & 6 deletions PHP/getUserReceipts.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,33 @@
//Get userName from JSON
$json = file_get_contents('php://input');
$obj = json_decode($json);
$userName = $obj->{'userName'};
$userID = $obj->{'userID'};

//If userName doesn't exist, use grab from John Doe. ONLY FOR TESTING PURPOSES. REMOVE IN FINAL
if($userName == ""){
$userName = "johnDoe";
if($userID == ""){
$userID = "1";
}

//Array of receipts to pass back
$receipts = array();

//Get all receipts from userName
$qString = "SELECT u.name, r.receiptID, r.creationDate, r.totalCost, r.tax, r.businessID
//$qString = "SELECT u.name, r.receiptID, r.creationDate, r.totalCost, r.tax, r.businessID
$qString = "SELECT u.name, r.receiptID, r.creationDate, r.totalCost, r.tax, r.businessName
FROM users u
INNER JOIN receipts r ON r.userID = u.userID
WHERE u.userName= '$userName'" ;
WHERE u.userID= '$userID'" ;
$qReceipt= mysqli_query($conn, $qString);
while($receipt= mysqli_fetch_row($qReceipt)){

/*Get business name from Business table
$qString = "SELECT u.name
FROM users u
INNER JOIN businesses b ON b.userID = u.userID
WHERE b.businessID = $receipt[5] limit 1";
$qBusiness = mysqli_query($conn, $qString);
$businessName = mysqli_fetch_object($qBusiness);
*/

//Build an array of items from the receipt
//Then push into the "items" array
Expand Down Expand Up @@ -56,7 +59,8 @@
'totalCost' => $receipt[3],
'tax' => $receipt[4],
'items' => $items,
'businessName' => $businessName->name
//'businessName' => $businessName->name //Not used as business is stored in receipt now
'businessName' => $receipt[5]
];
array_push($receipts, $tempReceipt);
}
Expand Down
27 changes: 14 additions & 13 deletions PHP/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
//Get from JSON object the username, nam, and email
$json = file_get_contents('php://input');
$obj = json_decode($json);
$userName = $obj->{'userName'};
$name = $obj->{'name'}
$userID = $obj->{'userID'};
$name = $obj->{'name'};
$email = $obj->{'email'};

//If they don't exist, just enter dummy data. THIS IS ONLY FOR TESTING PURPOSES. REMOVE IN FINAL
if($userName == ""){
$userName = "regTest";
if($userID == ""){
$userID = "regTest";
}
if($name == ""){
$name = "registration test";
Expand All @@ -20,20 +21,20 @@
}

//Create user, return info
$qString = "INSERT INTO users (`userName`,`name`,`creationDate`,`email`) VALUES ('" . $userName . "','" . $name . "', CURRENT_DATE,'" . $email . "')";
$qString = "INSERT INTO users (`userID`,`name`,`creationDate`,`email`) VALUES ('" . $userID . "','" . $name . "', CURRENT_DATE,'" . $email . "')";
mysqli_query($conn, $qString);

$qString = "SELECT userID, userName, name, creationDate FROM users WHERE name='" . $userName. "'";
/*
$qString = "SELECT userID, name, creationDate, email FROM users WHERE userID='" . $userID. "'";
$result = mysqli_query($conn, $qString);
if(mysqli_num_rows($result) == 1){
$row = mysqli_fetch_row($result);
$uID = $row[0];
$uName = $row[1]
$gname = $row[2]
$date = $row[3]
echo "User created! <br />User ID: " . $uID . " <br />Username: " . $uName . "<br />Real name: " . $gname . "<br />Created on: " . $date . "<br /><br />";
$gName = $row[1]
$date = $row[2]
$email = $row[3]
echo "User created! <br />User ID: " . $uID . " <br />Name: " . $gName . "<br />Created on: " . $date . "<br /> Email: " . $email . "<br /><br />";
}else{
echo "Failed to create user or multiple users.<br /><br />";
echo "Failed to create user or multiple users.<br /><br />" . $userID . $name . $email;
}

*/
?>
9 changes: 9 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ android {
sourceCompatibility 1.8
targetCompatibility 1.8
}

buildToolsVersion '27.0.3' // Older versions may give compile errors
}

dependencies {
Expand Down Expand Up @@ -48,6 +50,13 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
// implementation 'com.android.support:appcompat-v7:25.3.1' // Minimum 23+ is required
}

repositories {
jcenter()
}

apply plugin: 'com.google.gms.google-services'
Loading

0 comments on commit cec26b5

Please sign in to comment.