From 031dc83aa9d135003a40a169a623189314c56a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1ndly=20Gerg=C5=91?= Date: Thu, 20 Mar 2025 10:30:46 +0200 Subject: [PATCH] Added option to include details in the webhook sent to label printers --- config-dist.php | 1 + controllers/BatteriesApiController.php | 5 +++++ controllers/ChoresApiController.php | 5 +++++ controllers/StockApiController.php | 11 +++++++++++ services/StockService.php | 24 ++++++++++++++++++++++++ 5 files changed, 46 insertions(+) diff --git a/config-dist.php b/config-dist.php index 717222ca..ad891e91 100644 --- a/config-dist.php +++ b/config-dist.php @@ -111,6 +111,7 @@ Setting('LABEL_PRINTER_WEBHOOK', ''); // The URI that Grocy will POST to when as Setting('LABEL_PRINTER_RUN_SERVER', true); // Whether the webhook will be called server- or client-side Setting('LABEL_PRINTER_PARAMS', ['font_family' => 'Source Sans Pro (Regular)']); // Additional parameters supplied to the webhook Setting('LABEL_PRINTER_HOOK_JSON', false); // TRUE to use JSON or FALSE to use normal POST request variables +Setting('LABEL_PRINTER_INCLUDE_DETAILS', false); // TRUE to include details for the object as well // Thermal printer options diff --git a/controllers/BatteriesApiController.php b/controllers/BatteriesApiController.php index b5cd7430..323b0638 100644 --- a/controllers/BatteriesApiController.php +++ b/controllers/BatteriesApiController.php @@ -76,6 +76,11 @@ class BatteriesApiController extends BaseApiController 'grocycode' => (string)(new Grocycode(Grocycode::BATTERY, $args['batteryId'])), ], GROCY_LABEL_PRINTER_PARAMS); + if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) + { + $webhookData['details'] = $this->getBatteriesService()->GetBatteryDetails($battery->id); + } + if (GROCY_LABEL_PRINTER_RUN_SERVER) { (new WebhookRunner())->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON); diff --git a/controllers/ChoresApiController.php b/controllers/ChoresApiController.php index e8a6d2f7..9472452e 100644 --- a/controllers/ChoresApiController.php +++ b/controllers/ChoresApiController.php @@ -127,6 +127,11 @@ class ChoresApiController extends BaseApiController 'grocycode' => (string)(new Grocycode(Grocycode::CHORE, $args['choreId'])), ], GROCY_LABEL_PRINTER_PARAMS); + if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) + { + $webhookData['details'] = $this->getChoresService()->GetChoreDetails($chore->id); + } + if (GROCY_LABEL_PRINTER_RUN_SERVER) { (new WebhookRunner())->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON); diff --git a/controllers/StockApiController.php b/controllers/StockApiController.php index 27fd5b26..ff9db643 100644 --- a/controllers/StockApiController.php +++ b/controllers/StockApiController.php @@ -679,6 +679,11 @@ class StockApiController extends BaseApiController 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $product->id)), ], GROCY_LABEL_PRINTER_PARAMS); + if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) + { + $webhookData['details'] = $this->getStockService()->GetProductDetails($product->id); + } + if (GROCY_LABEL_PRINTER_RUN_SERVER) { (new WebhookRunner())->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON); @@ -704,6 +709,12 @@ class StockApiController extends BaseApiController 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $stockEntry->product_id, [$stockEntry->stock_id])), ], GROCY_LABEL_PRINTER_PARAMS); + if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) + { + $webhookData['details'] = $this->getStockService()->GetProductDetails($product->id); + $webhookData['details']['stock_entry'] = $stockEntry; + } + if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) { $webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $stockEntry->best_before_date; diff --git a/services/StockService.php b/services/StockService.php index 70f2cf24..8bbb9f9d 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -229,6 +229,12 @@ class StockService extends BaseService 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockId])), ], GROCY_LABEL_PRINTER_PARAMS); + if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) + { + $webhookData['details'] = $productDetails; + $webhookData['details']['stock_entry'] = $stockRow; + } + if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) { $webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $bestBeforeDate; @@ -280,6 +286,12 @@ class StockService extends BaseService 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockId])), ], GROCY_LABEL_PRINTER_PARAMS); + if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) + { + $webhookData['details'] = $productDetails; + $webhookData['details']['stock_entry'] = $stockRow; + } + if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) { $webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $bestBeforeDate; @@ -1011,6 +1023,12 @@ class StockService extends BaseService 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockEntry->stock_id])), ], GROCY_LABEL_PRINTER_PARAMS); + if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) + { + $webhookData['details'] = $productDetails; + $webhookData['details']['stock_entry'] = $stockEntry; + } + if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) { $webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $newBestBeforeDate; @@ -1323,6 +1341,12 @@ class StockService extends BaseService 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockEntry->stock_id])), ], GROCY_LABEL_PRINTER_PARAMS); + if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) + { + $webhookData['details'] = $productDetails; + $webhookData['details']['stock_entry'] = $stockEntry; + } + if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) { $webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $newBestBeforeDate;