Compare commits
No commits in common. "db41fb525fdf13ccb4d52efeb93d709cc1bf6948" and "d75cb0a32fd28a9630b9bdf7e5f8e2011e17965d" have entirely different histories.
db41fb525f
...
d75cb0a32f
@ -173,7 +173,7 @@ public class ShoppingList
|
|||||||
return resultList;
|
return resultList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean sendViaEmail()
|
public boolean send()
|
||||||
{
|
{
|
||||||
StringBuilder shoppingListString = new StringBuilder();
|
StringBuilder shoppingListString = new StringBuilder();
|
||||||
|
|
||||||
|
@ -59,9 +59,6 @@ public class ShoppingListEntry
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(amount <= 0 && unit != null && !unit.isDummy)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
conn = DatabaseHandler.getInstance().getConnection();
|
conn = DatabaseHandler.getInstance().getConnection();
|
||||||
|
|
||||||
if(!combinationExists(this.getParentList(), this.getProduct(), this.getUnit()))
|
if(!combinationExists(this.getParentList(), this.getProduct(), this.getUnit()))
|
||||||
@ -88,7 +85,7 @@ public class ShoppingListEntry
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return updateAmount(false);
|
return updateAmount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
@ -116,9 +113,6 @@ public class ShoppingListEntry
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(amount <= 0 && unit != null && !unit.isDummy)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
conn = DatabaseHandler.getInstance().getConnection();
|
conn = DatabaseHandler.getInstance().getConnection();
|
||||||
|
|
||||||
if(this.getAmount() == 0 || this.getUnit().isDummy())
|
if(this.getAmount() == 0 || this.getUnit().isDummy())
|
||||||
@ -133,7 +127,7 @@ public class ShoppingListEntry
|
|||||||
|
|
||||||
long numAffectedRows = preparedStmt.executeUpdate();
|
long numAffectedRows = preparedStmt.executeUpdate();
|
||||||
Miscellaneous.logEvent("AMOUNT OF UPDATED ROWS: " + numAffectedRows, 5);
|
Miscellaneous.logEvent("AMOUNT OF UPDATED ROWS: " + numAffectedRows, 5);
|
||||||
// ResultSet rs = preparedStmt.getGeneratedKeys();
|
ResultSet rs = preparedStmt.getGeneratedKeys();
|
||||||
// if (numAffectedRows > 0)
|
// if (numAffectedRows > 0)
|
||||||
// {
|
// {
|
||||||
preparedStmt.close();
|
preparedStmt.close();
|
||||||
@ -143,9 +137,7 @@ public class ShoppingListEntry
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(combinationExists(this.getParentList(), this.getProduct(), this.getUnit()))
|
if(combinationExists(this.getParentList(), this.getProduct(), this.getUnit()))
|
||||||
return updateAmount(true);
|
return updateAmount();
|
||||||
else
|
|
||||||
return true; // Combination to be deleted does not exist. So what?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
@ -167,7 +159,7 @@ public class ShoppingListEntry
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean updateAmount(boolean delete)
|
protected boolean updateAmount()
|
||||||
{
|
{
|
||||||
String query = "SELECT * FROM listEntries WHERE listId=? AND productId=? AND unit=?";
|
String query = "SELECT * FROM listEntries WHERE listId=? AND productId=? AND unit=?";
|
||||||
|
|
||||||
@ -187,22 +179,13 @@ public class ShoppingListEntry
|
|||||||
if(res.next())
|
if(res.next())
|
||||||
{
|
{
|
||||||
float currentAmount = res.getFloat("amount");
|
float currentAmount = res.getFloat("amount");
|
||||||
|
if(currentAmount + this.getAmount() > 0)
|
||||||
boolean condition = true;
|
|
||||||
if(delete)
|
|
||||||
condition = currentAmount - this.getAmount() > 0;
|
|
||||||
|
|
||||||
if(condition)
|
|
||||||
{
|
{
|
||||||
// Update the amount
|
// Update the amount
|
||||||
String updateQuery = "UPDATE listEntries set amount=? WHERE listId=? AND productId=? AND unit=?";
|
String updateQuery = "UPDATE listEntries set amount=? WHERE listId=? AND productId=? AND unit=?";
|
||||||
preparedStmt = conn.prepareStatement(updateQuery);
|
preparedStmt = conn.prepareStatement(updateQuery);
|
||||||
|
|
||||||
if(delete)
|
|
||||||
preparedStmt.setFloat(1, currentAmount - this.getAmount());
|
|
||||||
else
|
|
||||||
preparedStmt.setFloat(1, currentAmount + this.getAmount());
|
preparedStmt.setFloat(1, currentAmount + this.getAmount());
|
||||||
|
|
||||||
preparedStmt.setLong(2, this.getParentList().getId());
|
preparedStmt.setLong(2, this.getParentList().getId());
|
||||||
preparedStmt.setLong(3, this.getProduct().getId());
|
preparedStmt.setLong(3, this.getProduct().getId());
|
||||||
preparedStmt.setLong(4, this.getUnit().getId());
|
preparedStmt.setLong(4, this.getUnit().getId());
|
||||||
@ -226,7 +209,7 @@ public class ShoppingListEntry
|
|||||||
String updateQuery = "DELETE FROM listEntries WHERE listId=? AND productId=? AND unit=?";
|
String updateQuery = "DELETE FROM listEntries WHERE listId=? AND productId=? AND unit=?";
|
||||||
preparedStmt = conn.prepareStatement(updateQuery);
|
preparedStmt = conn.prepareStatement(updateQuery);
|
||||||
|
|
||||||
preparedStmt.setLong(1, this.getParentList().getId());
|
preparedStmt.setLong(1, this.getProduct().getId());
|
||||||
preparedStmt.setLong(2, this.getProduct().getId());
|
preparedStmt.setLong(2, this.getProduct().getId());
|
||||||
preparedStmt.setLong(3, this.getUnit().getId());
|
preparedStmt.setLong(3, this.getUnit().getId());
|
||||||
|
|
||||||
@ -242,8 +225,6 @@ public class ShoppingListEntry
|
|||||||
preparedStmt.close();
|
preparedStmt.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
preparedStmt.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,6 +254,8 @@ public class ShoppingListEntry
|
|||||||
|
|
||||||
ResultSet res = preparedStmt.executeQuery();
|
ResultSet res = preparedStmt.executeQuery();
|
||||||
|
|
||||||
|
boolean found = false;
|
||||||
|
|
||||||
if(res.next())
|
if(res.next())
|
||||||
entryAmount = res.getLong("combinationAmount");
|
entryAmount = res.getLong("combinationAmount");
|
||||||
|
|
||||||
@ -289,18 +272,4 @@ public class ShoppingListEntry
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
if(this.getUnit() != null)
|
|
||||||
{
|
|
||||||
if(!this.getUnit().isDummy())
|
|
||||||
return String.valueOf(getAmount()) + " " + getUnit().getMainName() + " " + getProduct().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
return getProduct().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -75,28 +75,25 @@ public class Start
|
|||||||
Unit u = Unit.getByName(unitName);
|
Unit u = Unit.getByName(unitName);
|
||||||
Product p = Product.getByName(productName);
|
Product p = Product.getByName(productName);
|
||||||
|
|
||||||
|
if(list == null)
|
||||||
|
exitWithError(Settings.languageBlock.get("couldNotCreateList"));
|
||||||
|
|
||||||
|
if(p == null)
|
||||||
|
exitWithError(Settings.languageBlock.get("productNotFound") + " " + productName);
|
||||||
|
|
||||||
ShoppingListEntry entry = new ShoppingListEntry();
|
ShoppingListEntry entry = new ShoppingListEntry();
|
||||||
entry.setParentList(list);
|
entry.setParentList(list);
|
||||||
entry.setProduct(p);
|
entry.setProduct(p);
|
||||||
entry.setAmount(amount);
|
entry.setAmount(amount);
|
||||||
entry.setUnit(u);
|
entry.setUnit(u);
|
||||||
|
|
||||||
if(amount > 0 && (u == null || u.isDummy))
|
|
||||||
entry.setUnit(Unit.getPieceUnit());
|
|
||||||
|
|
||||||
if(list == null)
|
|
||||||
exitWithError(Settings.languageBlock.get("couldNotCreateList"));
|
|
||||||
|
|
||||||
if(p == null)
|
|
||||||
exitWithError(Settings.languageBlock.get("productNotFound") + " " + entry.toString());
|
|
||||||
|
|
||||||
if(entry.create())
|
if(entry.create())
|
||||||
{
|
{
|
||||||
DatabaseHandler.getInstance().disconnect();
|
DatabaseHandler.getInstance().disconnect();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
exitWithError(Settings.languageBlock.get("couldNotAddProdToList") + " " + entry.toString());
|
exitWithError(Settings.languageBlock.get("couldNotAddProdToList") + " " + productName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
System.out.println(Settings.languageBlock.get("noProdSpecified"));
|
System.out.println(Settings.languageBlock.get("noProdSpecified"));
|
||||||
@ -106,72 +103,26 @@ public class Start
|
|||||||
{
|
{
|
||||||
ShoppingList list = ShoppingList.getMostRecentList();
|
ShoppingList list = ShoppingList.getMostRecentList();
|
||||||
Product p = Product.getByName(productName);
|
Product p = Product.getByName(productName);
|
||||||
Unit u = Unit.getByName(unitName);
|
|
||||||
|
|
||||||
ShoppingListEntry entry = new ShoppingListEntry();
|
|
||||||
entry.setParentList(list);
|
|
||||||
entry.setProduct(p);
|
|
||||||
entry.setAmount(amount);
|
|
||||||
entry.setUnit(u);
|
|
||||||
|
|
||||||
if(amount > 0 && (u == null || u.isDummy))
|
|
||||||
entry.setUnit(Unit.getPieceUnit());
|
|
||||||
|
|
||||||
if(list == null)
|
if(list == null)
|
||||||
exitWithError(Settings.languageBlock.get("couldNotCreateList"));
|
exitWithError(Settings.languageBlock.get("couldNotCreateList"));
|
||||||
|
|
||||||
if(p == null)
|
if(p == null)
|
||||||
exitWithError(Settings.languageBlock.get("productNotFound") + " " + entry.toString());
|
exitWithError(Settings.languageBlock.get("productNotFound") + " " + productName);
|
||||||
|
|
||||||
|
for(ShoppingListEntry entry : list.getEntries())
|
||||||
|
{bestehende reduzieren
|
||||||
|
if(entry.getProduct().equals(p))
|
||||||
|
{
|
||||||
if(entry.delete())
|
if(entry.delete())
|
||||||
{
|
{
|
||||||
DatabaseHandler.getInstance().disconnect();
|
DatabaseHandler.getInstance().disconnect();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
exitWithError(Settings.languageBlock.get("productNotFound") + " " + productName);
|
else
|
||||||
|
Miscellaneous.logEvent(Settings.languageBlock.get("couldNotRemoveProdFromList") + " " + productName, 2);
|
||||||
// for(ShoppingListEntry entry : list.getEntries())
|
}
|
||||||
// {
|
}
|
||||||
// if(entry.getProduct().equals(p))
|
|
||||||
// {
|
|
||||||
// if(entry.delete())
|
|
||||||
// {
|
|
||||||
// DatabaseHandler.getInstance().disconnect();
|
|
||||||
// System.exit(0);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// Miscellaneous.logEvent(Settings.languageBlock.get("couldNotRemoveProdFromList") + " " + productName, 2);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// exitWithError(Settings.languageBlock.get("couldNotRemoveProdFromList") + " " + entry.toString());
|
|
||||||
|
|
||||||
// for(ShoppingListEntry entry : list.getEntries())
|
|
||||||
// {
|
|
||||||
// if(entry.getProduct().equals(p))
|
|
||||||
// {
|
|
||||||
// if(amount > 0 && u != null && !u.isDummy())
|
|
||||||
// {
|
|
||||||
// /*
|
|
||||||
// * Amount and unit specified. Adjust entries that may exist.
|
|
||||||
// */
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// /*
|
|
||||||
// * No amount unit or unit specified. Delete all existing entries
|
|
||||||
// * of that product from the list.
|
|
||||||
// */
|
|
||||||
// if(entry.delete())
|
|
||||||
// {
|
|
||||||
// DatabaseHandler.getInstance().disconnect();
|
|
||||||
// System.exit(0);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// Miscellaneous.logEvent(Settings.languageBlock.get("couldNotRemoveProdFromList") + " " + productName, 2);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// If it wasn't on the list - why care?
|
// If it wasn't on the list - why care?
|
||||||
DatabaseHandler.getInstance().disconnect();
|
DatabaseHandler.getInstance().disconnect();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
@ -180,7 +131,7 @@ public class Start
|
|||||||
System.out.println(Settings.languageBlock.get("noProdSpecified"));
|
System.out.println(Settings.languageBlock.get("noProdSpecified"));
|
||||||
break;
|
break;
|
||||||
case "sendList":
|
case "sendList":
|
||||||
if(ShoppingList.getMostRecentList().sendViaEmail())
|
if(ShoppingList.getMostRecentList().send())
|
||||||
{
|
{
|
||||||
// System.out.println("Liste wurde verschickt.");
|
// System.out.println("Liste wurde verschickt.");
|
||||||
DatabaseHandler.getInstance().disconnect();
|
DatabaseHandler.getInstance().disconnect();
|
||||||
|
@ -19,7 +19,6 @@ static ArrayList<Unit> unitCache = null;
|
|||||||
String abbreviation;
|
String abbreviation;
|
||||||
boolean isDefault;
|
boolean isDefault;
|
||||||
boolean isDummy;
|
boolean isDummy;
|
||||||
boolean isPiece;
|
|
||||||
|
|
||||||
public long getId()
|
public long getId()
|
||||||
{
|
{
|
||||||
@ -30,14 +29,6 @@ static ArrayList<Unit> unitCache = null;
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMainName()
|
|
||||||
{
|
|
||||||
if(name.contains(";"))
|
|
||||||
return name.split(";")[0];
|
|
||||||
else
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName()
|
public String getName()
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
@ -74,15 +65,6 @@ static ArrayList<Unit> unitCache = null;
|
|||||||
this.isDummy = isDummy;
|
this.isDummy = isDummy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPiece()
|
|
||||||
{
|
|
||||||
return isPiece;
|
|
||||||
}
|
|
||||||
public void setPiece(boolean isPiece)
|
|
||||||
{
|
|
||||||
this.isPiece = isPiece;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArrayList<Unit> readAllUnits()
|
public static ArrayList<Unit> readAllUnits()
|
||||||
{
|
{
|
||||||
if(unitCache == null)
|
if(unitCache == null)
|
||||||
@ -115,7 +97,6 @@ static ArrayList<Unit> unitCache = null;
|
|||||||
u.setAbbreviation(res.getString("abbreviation"));
|
u.setAbbreviation(res.getString("abbreviation"));
|
||||||
u.setDefault(res.getInt("isDefault") == 1);
|
u.setDefault(res.getInt("isDefault") == 1);
|
||||||
u.setDummy(res.getInt("isDummy") == 1);
|
u.setDummy(res.getInt("isDummy") == 1);
|
||||||
u.setPiece(res.getInt("isPiece") == 1);
|
|
||||||
|
|
||||||
unitCache.add(u);
|
unitCache.add(u);
|
||||||
}
|
}
|
||||||
@ -152,14 +133,11 @@ static ArrayList<Unit> unitCache = null;
|
|||||||
|
|
||||||
for(Unit u : readAllUnits())
|
for(Unit u : readAllUnits())
|
||||||
{
|
{
|
||||||
for(String unitSynonym : u.getName().split(";"))
|
if(u.getName().equalsIgnoreCase(unitName))
|
||||||
{
|
|
||||||
if(unitSynonym.equalsIgnoreCase(unitName))
|
|
||||||
return u;
|
return u;
|
||||||
else if(unitSynonym.equalsIgnoreCase(unitName.replace("-", " ")))
|
else if(u.getName().equalsIgnoreCase(unitName.replace("-", " ")))
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -167,9 +145,6 @@ static ArrayList<Unit> unitCache = null;
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
if(getName().contains(";"))
|
|
||||||
return getName().split(";")[0];
|
|
||||||
else
|
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +161,7 @@ static ArrayList<Unit> unitCache = null;
|
|||||||
|
|
||||||
public boolean create()
|
public boolean create()
|
||||||
{
|
{
|
||||||
String query = "INSERT INTO units (name, abbreviation, isDefault, isDummy, isPiece) VALUES (?, ?, ?, ?, ?)";
|
String query = "INSERT INTO units (name, abbreviation, isDefault, isDummy) VALUES (?, ?, ?, ?)";
|
||||||
Connection conn = DatabaseHandler.getInstance().getConnection();
|
Connection conn = DatabaseHandler.getInstance().getConnection();
|
||||||
PreparedStatement preparedStmt = null;
|
PreparedStatement preparedStmt = null;
|
||||||
try
|
try
|
||||||
@ -205,11 +180,6 @@ static ArrayList<Unit> unitCache = null;
|
|||||||
else
|
else
|
||||||
preparedStmt.setInt(4, 0);
|
preparedStmt.setInt(4, 0);
|
||||||
|
|
||||||
if(this.isPiece)
|
|
||||||
preparedStmt.setInt(5, 1);
|
|
||||||
else
|
|
||||||
preparedStmt.setInt(5, 0);
|
|
||||||
|
|
||||||
preparedStmt.executeUpdate();
|
preparedStmt.executeUpdate();
|
||||||
ResultSet rs = preparedStmt.getGeneratedKeys();
|
ResultSet rs = preparedStmt.getGeneratedKeys();
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
@ -249,26 +219,4 @@ static ArrayList<Unit> unitCache = null;
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Unit getDefaultUnit()
|
|
||||||
{
|
|
||||||
for(Unit u : readAllUnits())
|
|
||||||
{
|
|
||||||
if(u.isDefault())
|
|
||||||
return u;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Unit getPieceUnit()
|
|
||||||
{
|
|
||||||
for(Unit u : readAllUnits())
|
|
||||||
{
|
|
||||||
if(u.isPiece())
|
|
||||||
return u;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -26,19 +26,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($_GET['command']))
|
if(isset($_GET['command']) && $_GET['command'] == "printProductList" || $_GET['command'] == "printRhasspyProductList")
|
||||||
{
|
|
||||||
if($_GET['command'] == "printProductList" || $_GET['command'] == "printRhasspyProductList")
|
|
||||||
{
|
{
|
||||||
displayProductList();
|
displayProductList();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
else if($_GET['command'] == "printUnitList")
|
|
||||||
{
|
|
||||||
displayUnitList();
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
@ -103,16 +95,12 @@
|
|||||||
{
|
{
|
||||||
case "addToList":
|
case "addToList":
|
||||||
$productId = $_POST['productToAdd'];
|
$productId = $_POST['productToAdd'];
|
||||||
$amount = $_POST['amountToAdd'];
|
addToList($productId);
|
||||||
$unitId = $_POST['unitToAdd'];
|
|
||||||
addToList($productId, $amount, $unitId);
|
|
||||||
break;
|
break;
|
||||||
case "removeFromList":
|
case "removeFromList":
|
||||||
$productId = $_POST['productToRemove'];
|
$productId = $_POST['productToRemove'];
|
||||||
$listId = $_POST['listId'];
|
$listId = $_POST['listId'];
|
||||||
$amount = $_POST['productAmountToRemove'];
|
removeFromList($productId, $listId);
|
||||||
$unit = $_POST['productUnitToRemove'];
|
|
||||||
removeFromList($productId, $listId, $amount, $unit);
|
|
||||||
break;
|
break;
|
||||||
case "displayShoppingList":
|
case "displayShoppingList":
|
||||||
displayShoppingList();
|
displayShoppingList();
|
||||||
@ -151,29 +139,16 @@
|
|||||||
mysqli_close(DBLink::getDbLink());
|
mysqli_close(DBLink::getDbLink());
|
||||||
|
|
||||||
|
|
||||||
function createList()
|
function addToList($productId)
|
||||||
{
|
{
|
||||||
$SQL_command = "INSERT INTO `lists` (creationTime) VALUES (".round(microtime(true) * 1000).")";
|
if($productId > 0)
|
||||||
if (DBLink::getDbLink()->query($SQL_command))
|
|
||||||
{
|
{
|
||||||
echo "List created.<br>";
|
$SQL_command;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
if(oneListExists())
|
||||||
}
|
$SQL_command = "INSERT IGNORE INTO listEntries (listId, productId) VALUES ((SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1), ".$productId.")";
|
||||||
|
else
|
||||||
|
$SQL_command = "INSERT IGNORE INTO listEntries (listId, productId) VALUES ((INSERT INTO `lists` (creationTime) VALUES (".round(microtime(true) * 1000).") RETURN @id, ".$productId."))";
|
||||||
function addToList($productId, $amount, $unitId)
|
|
||||||
{
|
|
||||||
if($productId > 0 && $amount != 0 && isset($unitId) && strlen($unitId) > 0)
|
|
||||||
{
|
|
||||||
if(!oneListExists())
|
|
||||||
createList();
|
|
||||||
|
|
||||||
if(!entryCombinationExists($productId, $unitId))
|
|
||||||
{
|
|
||||||
$SQL_command = "INSERT IGNORE INTO listEntries (listId, productId, amount, unit) VALUES ((SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1), ".$productId.", ".$amount.", ".$unitId.")";
|
|
||||||
|
|
||||||
if (DBLink::getDbLink()->query($SQL_command))
|
if (DBLink::getDbLink()->query($SQL_command))
|
||||||
echo "Product added to list.<br>";
|
echo "Product added to list.<br>";
|
||||||
@ -181,49 +156,17 @@
|
|||||||
echo "Product could not be added to list.<br>";
|
echo "Product could not be added to list.<br>";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
echo "Select a product.";
|
||||||
/*
|
|
||||||
update command that adds the amount to the already existing amount
|
|
||||||
if amount is negative -> subtract from existing amount. if resulting amount <= 0 ->
|
|
||||||
*/
|
|
||||||
|
|
||||||
$SQL_command = "SELECT amount FROM listEntries WHERE listId=(SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1) AND productId=".$productId." AND unit=".$unitId;
|
|
||||||
|
|
||||||
$mysqli_result = DBLink::getDbLink()->query($SQL_command);
|
|
||||||
if ($row = mysqli_fetch_object($mysqli_result))
|
|
||||||
{
|
|
||||||
if($row->amount + $amount > 0)
|
|
||||||
{
|
|
||||||
$SQL_command = "UPDATE listEntries set amount=".($row->amount + $amount)." WHERE listId=(SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1) AND productId=".$productId." AND unit=".$unitId;
|
|
||||||
|
|
||||||
if (DBLink::getDbLink()->query($SQL_command))
|
|
||||||
echo "Product added to existing entry on list.<br>";
|
|
||||||
else
|
|
||||||
echo "Product could not be added to existing entry on list.<br>";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$SQL_command = "DELETE FROM listEntries WHERE listId=(SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1) AND productId=".$productId." AND unit=".$unitId;
|
|
||||||
if (DBLink::getDbLink()->query($SQL_command))
|
|
||||||
echo "Product removed from list as too many pieces of this item have been removed.<br>";
|
|
||||||
else
|
|
||||||
echo "Product could not be removed from list (too many pieces of this itme have been removed).<br>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
echo "Specifiy product, amount and unit.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function removeFromList($productId, $listId, $amount, $unitId)
|
function removeFromList($productId, $listId)
|
||||||
{
|
{
|
||||||
if($productId > 0 && $amount != null && $unitId > 0)
|
if($productId > 0)
|
||||||
{
|
{
|
||||||
if(oneListExists())
|
if(oneListExists())
|
||||||
{
|
{
|
||||||
$SQL_command = "DELETE FROM listEntries WHERE listId=".$listId." AND productId=".$productId." AND amount=".$amount." AND unit=".$unitId;
|
$SQL_command = "DELETE FROM listEntries WHERE listId=".$listId." AND productId=".$productId;
|
||||||
|
|
||||||
if (DBLink::getDbLink()->query($SQL_command))
|
if (DBLink::getDbLink()->query($SQL_command))
|
||||||
echo "Product removed from list.<br>";
|
echo "Product removed from list.<br>";
|
||||||
@ -236,21 +179,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function entryCombinationExists($productId, $unitId)
|
|
||||||
{
|
|
||||||
$SQL_command = "SELECT COUNT(listId) as entryAmount FROM listEntries WHERE listId=(SELECT id FROM `lists` ORDER BY creationTime DESC LIMIT 1) AND productId=".$productId." AND unit=".$unitId;
|
|
||||||
|
|
||||||
$mysqli_result = DBLink::getDbLink()->query($SQL_command);
|
|
||||||
if ($row = mysqli_fetch_object($mysqli_result))
|
|
||||||
{
|
|
||||||
if($row->entryAmount > 0)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function oneListExists()
|
function oneListExists()
|
||||||
{
|
{
|
||||||
$SQL_command = "SELECT COUNT(id) as listAmount FROM lists";
|
$SQL_command = "SELECT COUNT(id) as listAmount FROM lists";
|
||||||
@ -279,9 +207,7 @@
|
|||||||
|
|
||||||
function displayShoppingList($listId, $justCreatedProductId)
|
function displayShoppingList($listId, $justCreatedProductId)
|
||||||
{
|
{
|
||||||
echo " <h2>Shopping list</h2>
|
echo " <form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">
|
||||||
|
|
||||||
<form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">
|
|
||||||
<input type=\"hidden\" id=\"command\" name=\"command\" value=\"addToList\" />
|
<input type=\"hidden\" id=\"command\" name=\"command\" value=\"addToList\" />
|
||||||
<select name=\"productToAdd\" id=\"productToAdd\">
|
<select name=\"productToAdd\" id=\"productToAdd\">
|
||||||
<option value=\"0\">Select product to add</option>
|
<option value=\"0\">Select product to add</option>
|
||||||
@ -299,27 +225,6 @@
|
|||||||
echo "<option value=\"".$row->id."\">".$row->name."</option>";
|
echo "<option value=\"".$row->id."\">".$row->name."</option>";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo " </select>
|
|
||||||
|
|
||||||
<input type=\"number\" step=\"any\" id=\"amountToAdd\" name=\"amountToAdd\" value=\"1.0\" />
|
|
||||||
|
|
||||||
<select name=\"unitToAdd\" id=\"unitToAdd\">
|
|
||||||
<option value=\"0\">Select unit to add</option>
|
|
||||||
";
|
|
||||||
|
|
||||||
$SQL_command = "SELECT * FROM `units` ORDER BY name ASC";
|
|
||||||
$mysqli_result = DBLink::getDbLink()->query($SQL_command);
|
|
||||||
while ($row = mysqli_fetch_object($mysqli_result))
|
|
||||||
{
|
|
||||||
$currentId = (int)$row->id;
|
|
||||||
$unitArray = explode(";", $row->name);
|
|
||||||
|
|
||||||
if($row->isDefault == 1 || (isset($justCreatedUnitId) && $justCreatedUnitId === $currentId))
|
|
||||||
echo "<option value=\"".$row->id."\" selected>".$unitArray[0]."</option>";
|
|
||||||
else
|
|
||||||
echo "<option value=\"".$row->id."\">".$unitArray[0]."</option>";
|
|
||||||
}
|
|
||||||
|
|
||||||
echo " </select>
|
echo " </select>
|
||||||
<input type=\"submit\" value=\"add\" />
|
<input type=\"submit\" value=\"add\" />
|
||||||
</form>";
|
</form>";
|
||||||
@ -355,70 +260,47 @@
|
|||||||
echo "<br />";
|
echo "<br />";
|
||||||
}
|
}
|
||||||
|
|
||||||
$SQL_command = "SELECT * FROM listEntries
|
$SQL_command = "SELECT * FROM listEntries INNER JOIN products ON listEntries.productId=products.id INNER JOIN storeTypes ON products.storeTypeId = storeTypes.id WHERE listEntries.listId=".$listId." ORDER BY storeTypes.name, products.name ASC";
|
||||||
INNER JOIN products ON listEntries.productId=products.id
|
|
||||||
INNER JOIN storeTypes ON products.storeTypeId = storeTypes.id
|
|
||||||
INNER JOIN units ON units.id = listEntries.unit
|
|
||||||
WHERE listEntries.listId=".$listId." ORDER BY storeTypes.name, products.name ASC";
|
|
||||||
|
|
||||||
$mysqli_result = DBLink::getDbLink()->query($SQL_command);
|
$mysqli_result = DBLink::getDbLink()->query($SQL_command);
|
||||||
|
|
||||||
$lastShop="";
|
$lastShop="";
|
||||||
|
|
||||||
$found = false;
|
|
||||||
while ($row = mysqli_fetch_array($mysqli_result))
|
while ($row = mysqli_fetch_array($mysqli_result))
|
||||||
{
|
{
|
||||||
if(!$found)
|
if(isset($lastShop) && $lastShop != "" && $row[7] != $lastShop)
|
||||||
$found = true;
|
|
||||||
|
|
||||||
if(isset($lastShop) && $lastShop != "" && $row[9] != $lastShop)
|
|
||||||
echo "</table>";
|
echo "</table>";
|
||||||
|
|
||||||
if(!isset($lastShop) || $row[9] != $lastShop)
|
if(!isset($lastShop) || $row[7] != $lastShop)
|
||||||
{
|
{
|
||||||
$lastShop = $row[9];
|
$lastShop = $row[7];
|
||||||
echo $lastShop."<br>================";
|
echo $lastShop."<br>================";
|
||||||
echo "<table border=\"0\">";
|
echo "<table border=\"0\">";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "<tr>";
|
echo "<tr>
|
||||||
|
<td style=\"vertical-align:top;\">".$row[3]."</td>
|
||||||
if($row[14] == 1)
|
|
||||||
echo "<td style=\"vertical-align:top;\" colspan=\"3\">".$row[5]."</td>";
|
|
||||||
else
|
|
||||||
echo "
|
|
||||||
<td style=\"vertical-align:top;\">".$row[2]."</td>
|
|
||||||
<td style=\"vertical-align:top;\">".$row[12]."</td>
|
|
||||||
<td style=\"vertical-align:top;\">".$row[5]."</td>";
|
|
||||||
|
|
||||||
echo "
|
|
||||||
<td style=\"vertical-align:top;\">
|
<td style=\"vertical-align:top;\">
|
||||||
<form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">
|
<form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">
|
||||||
<input type=\"hidden\" id=\"command\" name=\"command\" value=\"removeFromList\" />
|
<input type=\"hidden\" id=\"command\" name=\"command\" value=\"removeFromList\" />
|
||||||
<input type=\"hidden\" id=\"listId\" name=\"listId\" value=\"".$listId."\" />
|
<input type=\"hidden\" id=\"listId\" name=\"listId\" value=\"".$listId."\" />
|
||||||
<input type=\"hidden\" id=\"productToRemove\" name=\"productToRemove\" value=\"".$row[1]."\" />
|
<input type=\"hidden\" id=\"productToRemove\" name=\"productToRemove\" value=\"".$row[1]."\" />
|
||||||
<input type=\"hidden\" id=\"productAmountToRemove\" name=\"productAmountToRemove\" value=\"".$row[2]."\" />
|
|
||||||
<input type=\"hidden\" id=\"productUnitToRemove\" name=\"productUnitToRemove\" value=\"".$row[10]."\" />
|
|
||||||
<input class=\"smallButton\" type=\"submit\" value=\"remove\" />
|
<input class=\"smallButton\" type=\"submit\" value=\"remove\" />
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>";
|
</tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if($found)
|
|
||||||
echo "</table>";
|
echo "</table>";
|
||||||
else
|
|
||||||
echo "<i>No entries in this list, yet.</i>";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
echo "<i>No list exists, yet.</i>";
|
echo "No list exists, yet.";
|
||||||
}
|
}
|
||||||
|
|
||||||
function showDataMaintenance()
|
function showDataMaintenance()
|
||||||
{
|
{
|
||||||
echo "<hr />";
|
echo "<hr />";
|
||||||
|
|
||||||
echo " <h2>Data maintenance</h2>
|
echo " <h2>Data maintenance</h3>
|
||||||
|
|
||||||
<h3>Create new list</h3>
|
<h3>Create new list</h3>
|
||||||
|
|
||||||
@ -507,33 +389,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function displayUnitList()
|
|
||||||
{
|
|
||||||
$SQL_Befehl = "SELECT name FROM units ORDER BY name ASC";
|
|
||||||
|
|
||||||
$mysqli_result = DBLink::getDbLink()->query($SQL_Befehl);
|
|
||||||
|
|
||||||
$lastShop="";
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_object($mysqli_result))
|
|
||||||
{
|
|
||||||
$unitArray = explode(";", $row->name);
|
|
||||||
if(count($unitArray) == 1)
|
|
||||||
echo $unitArray[0]."\n";
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$tbp = "";
|
|
||||||
for($i=1; $i<count($unitArray); $i++)
|
|
||||||
$tbp .= $unitArray[$i]."|";
|
|
||||||
|
|
||||||
$tbp = trim($tbp, "|");
|
|
||||||
|
|
||||||
echo "(".$tbp."):".$unitArray[0]."\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function createNewShoppingList()
|
function createNewShoppingList()
|
||||||
{
|
{
|
||||||
$date = new DateTime();
|
$date = new DateTime();
|
||||||
|
@ -1,32 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
SHOPPINGITEM=""
|
SHOPPINGITEM=""
|
||||||
AMOUNT=""
|
|
||||||
UNIT=""
|
|
||||||
SITEID=""
|
SITEID=""
|
||||||
PARAMS=""
|
PARAMS=""
|
||||||
SESSIONID=""
|
SESSIONID=""
|
||||||
|
|
||||||
while (( "$#" )); do
|
while (( "$#" )); do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--shoppingAmount)
|
|
||||||
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
|
|
||||||
AMOUNT=$2
|
|
||||||
shift 2
|
|
||||||
else
|
|
||||||
echo "Error: Argument for $1 is missing" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
--shoppingUnit)
|
|
||||||
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
|
|
||||||
UNIT=$2
|
|
||||||
shift 2
|
|
||||||
else
|
|
||||||
echo "Error: Argument for $1 is missing" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
--shoppingProduct)
|
--shoppingProduct)
|
||||||
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
|
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
|
||||||
SHOPPINGITEM=$2
|
SHOPPINGITEM=$2
|
||||||
@ -73,21 +53,7 @@ then
|
|||||||
echo "Was soll ich auf die Liste setzen?"
|
echo "Was soll ich auf die Liste setzen?"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
lengthAmount=${#AMOUNT}
|
|
||||||
lengthUnit=${#UNIT}
|
|
||||||
|
|
||||||
if [ $lengthAmount -gt 0 ]
|
|
||||||
then
|
|
||||||
if [ $lengthUnit -gt 0 ]
|
|
||||||
then
|
|
||||||
java -jar /home/pi/hc_scripts/ShoppingList.jar --action addToList --shoppingAmount $AMOUNT --shoppingUnit $UNIT --shoppingProduct $SHOPPINGITEM
|
|
||||||
else
|
|
||||||
java -jar /home/pi/hc_scripts/ShoppingList.jar --action addToList --shoppingAmount $AMOUNT --shoppingProduct $SHOPPINGITEM
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
java -jar /home/pi/hc_scripts/ShoppingList.jar --action addToList --shoppingProduct $SHOPPINGITEM
|
java -jar /home/pi/hc_scripts/ShoppingList.jar --action addToList --shoppingProduct $SHOPPINGITEM
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$?" -eq "0" ]
|
if [ "$?" -eq "0" ]
|
||||||
then
|
then
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -1,32 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
SHOPPINGITEM=""
|
SHOPPINGITEM=""
|
||||||
AMOUNT=""
|
|
||||||
UNIT=""
|
|
||||||
SITEID=""
|
SITEID=""
|
||||||
PARAMS=""
|
PARAMS=""
|
||||||
SESSIONID=""
|
SESSIONID=""
|
||||||
|
|
||||||
while (( "$#" )); do
|
while (( "$#" )); do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--shoppingAmount)
|
|
||||||
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
|
|
||||||
AMOUNT=$2
|
|
||||||
shift 2
|
|
||||||
else
|
|
||||||
echo "Error: Argument for $1 is missing" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
--shoppingUnit)
|
|
||||||
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
|
|
||||||
UNIT=$2
|
|
||||||
shift 2
|
|
||||||
else
|
|
||||||
echo "Error: Argument for $1 is missing" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
--shoppingProduct)
|
--shoppingProduct)
|
||||||
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
|
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
|
||||||
SHOPPINGITEM=$2
|
SHOPPINGITEM=$2
|
||||||
@ -73,21 +53,7 @@ then
|
|||||||
echo "Was soll ich von der Liste streichen?"
|
echo "Was soll ich von der Liste streichen?"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
lengthAmount=${#AMOUNT}
|
|
||||||
lengthUnit=${#UNIT}
|
|
||||||
|
|
||||||
if [ $lengthAmount -gt 0 ]
|
|
||||||
then
|
|
||||||
if [ $lengthUnit -gt 0 ]
|
|
||||||
then
|
|
||||||
java -jar /home/pi/hc_scripts/ShoppingList.jar --action removeFromList --shoppingAmount $AMOUNT --shoppingUnit $UNIT --shoppingProduct $SHOPPINGITEM
|
|
||||||
else
|
|
||||||
java -jar /home/pi/hc_scripts/ShoppingList.jar --action removeFromList --shoppingAmount $AMOUNT --shoppingProduct $SHOPPINGITEM
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
java -jar /home/pi/hc_scripts/ShoppingList.jar --action removeFromList --shoppingProduct $SHOPPINGITEM
|
java -jar /home/pi/hc_scripts/ShoppingList.jar --action removeFromList --shoppingProduct $SHOPPINGITEM
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$?" -eq "0" ]
|
if [ "$?" -eq "0" ]
|
||||||
then
|
then
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
Reference in New Issue
Block a user