From e40979a874bc0d6d94a103938d424d3a4a83d541 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Thu, 4 Jan 2018 12:51:36 +0100 Subject: [PATCH] Allow arbitrary text in shopping list --- GrocyDbMigrator.php | 26 ++++++++++++++++++++++++++ views/shoppinglist.php | 8 ++++++-- views/shoppinglistform.php | 11 ++++++++--- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/GrocyDbMigrator.php b/GrocyDbMigrator.php index 35e23ee1..81dc9e61 100644 --- a/GrocyDbMigrator.php +++ b/GrocyDbMigrator.php @@ -160,6 +160,32 @@ class GrocyDbMigrator GROUP BY battery_id ORDER BY MAX(tracked_time) DESC;" ); + + self::ExecuteMigrationWhenNeeded($pdo, 16, " + ALTER TABLE shopping_list RENAME TO shopping_list_old;" + ); + + self::ExecuteMigrationWhenNeeded($pdo, 17, " + CREATE TABLE shopping_list ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, + product_id INTEGER, + note TEXT, + amount INTEGER NOT NULL DEFAULT 0, + amount_autoadded INTEGER NOT NULL DEFAULT 0, + row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime')) + )" + ); + + self::ExecuteMigrationWhenNeeded($pdo, 18, " + INSERT INTO shopping_list + (product_id, amount, amount_autoadded, row_created_timestamp) + SELECT product_id, amount, amount_autoadded, row_created_timestamp + FROM shopping_list_old" + ); + + self::ExecuteMigrationWhenNeeded($pdo, 19, " + DROP TABLE shopping_list_old;" + ); } private static function ExecuteMigrationWhenNeeded(PDO $pdo, int $migrationId, string $sql) diff --git a/views/shoppinglist.php b/views/shoppinglist.php index 5dba5ccf..e0718d88 100644 --- a/views/shoppinglist.php +++ b/views/shoppinglist.php @@ -17,6 +17,7 @@ # Product Amount + Note @@ -31,10 +32,13 @@ - product_id)->name; ?> + product_id)) echo GrocyPhpHelper::FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->name; ?> - amount + $listItem->amount_autoadded . ' ' . GrocyPhpHelper::FindObjectInArrayByPropertyValue($quantityunits, 'id', GrocyPhpHelper::FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->qu_id_purchase)->name; ?> + amount + $listItem->amount_autoadded; if (!empty($listItem->product_id)) echo ' ' . GrocyPhpHelper::FindObjectInArrayByPropertyValue($quantityunits, 'id', GrocyPhpHelper::FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->qu_id_purchase)->name; ?> + + + note; ?> diff --git a/views/shoppinglistform.php b/views/shoppinglistform.php index 37de5e67..93e6a512 100644 --- a/views/shoppinglistform.php +++ b/views/shoppinglistform.php @@ -12,7 +12,7 @@
- @@ -22,11 +22,16 @@
- - + +
+
+ + +
+