diff --git a/controllers/StockApiController.php b/controllers/StockApiController.php
index 10735f21..ef2b425f 100644
--- a/controllers/StockApiController.php
+++ b/controllers/StockApiController.php
@@ -5,6 +5,7 @@ namespace Grocy\Controllers;
use Grocy\Controllers\Users\User;
use Grocy\Services\StockService;
use Grocy\Helpers\WebhookRunner;
+use Grocy\Helpers\Grocycode;
class StockApiController extends BaseApiController
{
@@ -611,6 +612,46 @@ class StockApiController extends BaseApiController
return $this->FilteredApiResponse($response, $this->getStockService()->GetProductStockLocations($args['productId'], $allowSubproductSubstitution), $request->getQueryParams());
}
+ public function ProductPrintLabel(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
+ {
+ $product = $this->getDatabase()->products()->where('id', $args['productId'])->fetch();
+
+ $webhookData = array_merge([
+ 'product' => $product->name,
+ 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $product->id)),
+ ], GROCY_LABEL_PRINTER_PARAMS);
+
+ if (GROCY_LABEL_PRINTER_RUN_SERVER)
+ {
+ (new WebhookRunner())->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON);
+ }
+
+ return $this->ApiResponse($response, $webhookData);
+ }
+
+ public function StockEntryPrintLabel(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
+ {
+ $stockEntry = $this->getDatabase()->stock()->where('id', $args['entryId'])->fetch();
+ $product = $this->getDatabase()->products()->where('id', $stockEntry->product_id)->fetch();
+
+ $webhookData = array_merge([
+ 'product' => $product->name,
+ 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $stockEntry->product_id, [$stockEntry->stock_id])),
+ ], GROCY_LABEL_PRINTER_PARAMS);
+
+ if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
+ {
+ $webhookData['duedate'] = $this->getLocalizationService()->__t('DD') . ': ' . $stockEntry->best_before_date;
+ }
+
+ if (GROCY_LABEL_PRINTER_RUN_SERVER)
+ {
+ (new WebhookRunner())->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON);
+ }
+
+ return $this->ApiResponse($response, $webhookData);
+ }
+
public function RemoveProductFromShoppingList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
User::checkPermission($request, User::PERMISSION_SHOPPINGLIST_ITEMS_DELETE);
diff --git a/localization/de/strings.po b/localization/de/strings.po
index c103006c..ba6f8d3f 100644
--- a/localization/de/strings.po
+++ b/localization/de/strings.po
@@ -2397,4 +2397,10 @@ msgid "DD"
msgstr "MHD"
msgid "Print stock label"
+msgstr "Etikett drucken"
+
+msgid "Print Product Label"
+msgstr "Produkt-Etikett drucken"
+
+msgid "Print stock entry label"
msgstr "Etikett drucken"
\ No newline at end of file
diff --git a/localization/strings.pot b/localization/strings.pot
index 21be827b..0c94cd1e 100644
--- a/localization/strings.pot
+++ b/localization/strings.pot
@@ -2109,3 +2109,9 @@ msgstr ""
msgid "Print stock label"
msgstr ""
+
+msgid "Print Product Label"
+msgstr ""
+
+msgid "Print stock entry label"
+msgstr ""
diff --git a/public/viewjs/stockentries.js b/public/viewjs/stockentries.js
index 152c3434..5a3aedfe 100644
--- a/public/viewjs/stockentries.js
+++ b/public/viewjs/stockentries.js
@@ -124,6 +124,21 @@ $(document).on("click", ".stock-name-cell", function(e)
$("#stockentry-productcard-modal").modal("show");
});
+$(document).on('click', '.stockentry-grocycode-stockentry-label-print', function(e)
+{
+ e.preventDefault();
+ document.activeElement.blur();
+
+ var stockId = $(e.currentTarget).attr('data-stock-id');
+ Grocy.Api.Get('stock/entry/' + stockId + '/printlabel', function(labelData)
+ {
+ if (Grocy.Webhooks.labelprinter !== undefined)
+ {
+ Grocy.FrontendHelpers.RunWebhook(Grocy.Webhooks.labelprinter, labelData);
+ }
+ });
+});
+
function RefreshStockEntryRow(stockRowId)
{
Grocy.Api.Get("stock/entry/" + stockRowId,
diff --git a/public/viewjs/stockoverview.js b/public/viewjs/stockoverview.js
index 8fdc6b5d..284d6a8a 100755
--- a/public/viewjs/stockoverview.js
+++ b/public/viewjs/stockoverview.js
@@ -101,6 +101,21 @@ $("#search").on("keyup", Delay(function()
stockOverviewTable.search(value).draw();
}, 200));
+$(document).on('click', '.stockentry-grocycode-product-label-print', function(e)
+{
+ e.preventDefault();
+ document.activeElement.blur();
+
+ var productId = $(e.currentTarget).attr('data-product-id');
+ Grocy.Api.Get('stock/products/' + productId + '/printlabel', function(labelData)
+ {
+ if (Grocy.Webhooks.labelprinter !== undefined)
+ {
+ Grocy.FrontendHelpers.RunWebhook(Grocy.Webhooks.labelprinter, labelData);
+ }
+ });
+});
+
$(document).on('click', '.product-consume-button', function(e)
{
e.preventDefault();
diff --git a/routes.php b/routes.php
index 0f2c4739..be0b6f98 100644
--- a/routes.php
+++ b/routes.php
@@ -208,6 +208,8 @@ $app->group('/api', function (RouteCollectorProxy $group) {
$group->get('/stock/transactions/{transactionId}', '\Grocy\Controllers\StockApiController:StockTransactions');
$group->post('/stock/transactions/{transactionId}/undo', '\Grocy\Controllers\StockApiController:UndoTransaction');
$group->get('/stock/barcodes/external-lookup/{barcode}', '\Grocy\Controllers\StockApiController:ExternalBarcodeLookup');
+ $group->get('/stock/products/{productId}/printlabel', '\Grocy\Controllers\StockApiController:ProductPrintLabel');
+ $group->get('/stock/entry/{entryId}/printlabel', '\Grocy\Controllers\StockApiController:StockEntryPrintLabel');
// Shopping list
$group->post('/stock/shoppinglist/add-missing-products', '\Grocy\Controllers\StockApiController:AddMissingProductsToShoppingList');
diff --git a/services/StockService.php b/services/StockService.php
index 23c321fb..f50b4620 100644
--- a/services/StockService.php
+++ b/services/StockService.php
@@ -183,11 +183,15 @@ class StockService extends BaseService
if (GROCY_FEATURE_FLAG_LABELPRINTER && GROCY_LABEL_PRINTER_RUN_SERVER && $runWebhook)
{
$webhookData = array_merge([
- 'product' => $productDetails->product->name,
- 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockId])),
- 'duedate' => $this->getLocalizationService()->__t('DD') . ': ' . $bestBeforeDate,
+ 'product' => $stockEntry->product()->name,
+ 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $stockEntry->product_id, [$stockEntry->stock_id])),
], GROCY_LABEL_PRINTER_PARAMS);
+ if (GROCY_FEATURE_FLAG_BEST_BEFORE_DATE_TRACKING)
+ {
+ $webhookData['duedate'] = $this->getLocalizationService()->__t('DD') . ': ' . $bestBeforeDate;
+ }
+
(new WebhookRunner())->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON);
}
diff --git a/views/stockentries.blade.php b/views/stockentries.blade.php
index 13fcaad8..b9abeec3 100644
--- a/views/stockentries.blade.php
+++ b/views/stockentries.blade.php
@@ -190,6 +190,14 @@
href="{{ $U('/stockentry/' . $stockEntry->id . '/grocycode?download=true') }}">
{{ $__t('Download stock entry grocycode') }}
+ @if(GROCY_FEATURE_FLAG_LABELPRINTER)
+
+ {{ $__t('Print stock entry label') }}
+
+ @endif
{{ $__t('Download product grocycode') }}
+ @if(GROCY_FEATURE_FLAG_LABELPRINTER)
+
+ {{ $__t('Print Product Label') }}
+
+ @endif