Added option to include details in the webhook sent to label printers

This commit is contained in:
Fándly Gergő 2025-03-20 10:30:46 +02:00
parent 541318e964
commit 031dc83aa9
5 changed files with 46 additions and 0 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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;