diff --git a/changelog/70_UNRELEASED_xxxx.xx.xx.md b/changelog/70_UNRELEASED_xxxx.xx.xx.md index 9d02b17f..17d9bcba 100644 --- a/changelog/70_UNRELEASED_xxxx.xx.xx.md +++ b/changelog/70_UNRELEASED_xxxx.xx.xx.md @@ -21,6 +21,9 @@ - Changed that when the ingredient option "Only check if any amount is in stock" is enabled, costs and calories are now based on the original entered amount instead of an "virtual" fixed amount of `1` - When using the "Add as barcode to existing product" workflow on a purchase transaction, the selected quantity unit and the entered amount is now also added to the new barcode - When using the "Add as barcode to existing product" workflow on a purchase or inventory transaction, the entered note is now also added to the new barcode +- New product option "Auto reprint stock entry label" + - When enabled, auto-changing the due date of a stock entry (by opening/freezing/thawing and having corresponding default due days set) will reprint its label (only server side label printer WebHooks are supported) + - Defaults to disabled, so no changed behavior when not configured - Added a new option "Reprint stock entry label" on the stock entry edit page (will print the correspondind stock entry label on save) - This option will be automatically set on changing the entry's due date - Fixed that hiding the "Purchased date" column (table options) on the stock entries page didn't work diff --git a/grocy.openapi.json b/grocy.openapi.json index 68a81ccc..fd2fda91 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -4468,6 +4468,9 @@ "treat_opened_as_out_of_stock": { "type": "integer" }, + "auto_reprint_stock_label": { + "type": "integer" + }, "no_own_stock": { "type": "integer" }, diff --git a/localization/strings.pot b/localization/strings.pot index 926c2f5c..7f0142ca 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -2359,3 +2359,9 @@ msgstr "" msgid "Reprint stock entry label" msgstr "" + +msgid "Auto reprint stock entry label" +msgstr "" + +msgid "When enabled, auto-changing the due date of a stock entry (by opening/freezing/thawing and having corresponding default due days set) will reprint its label" +msgstr "" diff --git a/migrations/0212.sql b/migrations/0212.sql new file mode 100644 index 00000000..252c9011 --- /dev/null +++ b/migrations/0212.sql @@ -0,0 +1,2 @@ +ALTER TABLE products +ADD auto_reprint_stock_label TINYINT NOT NULL DEFAULT 0 CHECK(auto_reprint_stock_label IN (0, 1)); diff --git a/services/StockService.php b/services/StockService.php index fbb36337..c67bc115 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -1013,6 +1013,22 @@ class StockService extends BaseService { $newBestBeforeDate = $stockEntry->best_before_date; } + + if (GROCY_FEATURE_FLAG_LABEL_PRINTER && GROCY_LABEL_PRINTER_RUN_SERVER && $productDetails->product->auto_reprint_stock_label == 1 && $newBestBeforeDate != $stockEntry->best_before_date) + { + $webhookData = array_merge([ + 'product' => $productDetails->product->name, + 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockEntry->stock_id])), + ], GROCY_LABEL_PRINTER_PARAMS); + + if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) + { + $webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $newBestBeforeDate; + } + + $runner = new WebhookRunner(); + $runner->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON); + } } if ($allowSubproductSubstitution && $stockEntry->product_id != $productId) @@ -1292,7 +1308,6 @@ class StockService extends BaseService } $newBestBeforeDate = $stockEntry->best_before_date; - if (GROCY_FEATURE_FLAG_STOCK_PRODUCT_FREEZING) { $locationFrom = $this->getDatabase()->locations()->where('id', $locationIdFrom)->fetch(); @@ -1316,6 +1331,22 @@ class StockService extends BaseService { $newBestBeforeDate = date('Y-m-d', strtotime('+' . $productDetails->product->default_best_before_days_after_thawing . ' days')); } + + if (GROCY_FEATURE_FLAG_LABEL_PRINTER && GROCY_LABEL_PRINTER_RUN_SERVER && $productDetails->product->auto_reprint_stock_label == 1 && $stockEntry->best_before_date != $newBestBeforeDate) + { + $webhookData = array_merge([ + 'product' => $productDetails->product->name, + 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockEntry->stock_id])), + ], GROCY_LABEL_PRINTER_PARAMS); + + if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) + { + $webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $newBestBeforeDate; + } + + $runner = new WebhookRunner(); + $runner->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON); + } } $correlationId = uniqid(); diff --git a/views/productform.blade.php b/views/productform.blade.php index c1fcf3ee..72e542e7 100644 --- a/views/productform.blade.php +++ b/views/productform.blade.php @@ -521,6 +521,20 @@ intval($product->default_stock_label_type) == 2 ) selected="selected" @endif value="2">{{ $__t('Label per unit') }} + +