$SQL_command = "INSERT INTO `lists` (creationTime) VALUES (".round(microtime(true) * 1000).")";
if (DBLink::getDbLink()->query($SQL_command))
{
$SQL_command;
echo "List created.<br>";
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."))";
$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))
echo "Product added to list.<br>";
else
echo "Product could not be added to list.<br>";
}
else
echo "Product could not be added to list.<br>";
{
/*
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;
$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 "Select a product.";
echo "Specifiy product, amount and unit.";
}
function removeFromList($productId, $listId)
function removeFromList($productId, $listId, $amount, $unitId)
$SQL_command = "DELETE FROM listEntries WHERE listId=".$listId." AND productId=".$productId;
$SQL_command = "DELETE FROM listEntries WHERE listId=".$listId." AND productId=".$productId." AND amount=".$amount." AND unit=".$unitId;
if (DBLink::getDbLink()->query($SQL_command))
echo "Product removed from list.<br>";
@ -179,6 +236,21 @@
}
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;
$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";
$SQL_command = "SELECT * FROM listEntries
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";