mirror of
https://github.com/grocy/grocy.git
synced 2026-04-05 12:26:15 +02:00
Grocycode: Default settings for label printing
This commit is contained in:
parent
dc5114fd2f
commit
01a9d43ebb
|
|
@ -141,9 +141,9 @@ class StockApiController extends BaseApiController
|
||||||
$transactionType = $requestBody['transactiontype'];
|
$transactionType = $requestBody['transactiontype'];
|
||||||
}
|
}
|
||||||
$runPrinterWebhook = false;
|
$runPrinterWebhook = false;
|
||||||
if (array_key_exists('print_stock_label', $requestBody) && boolval($requestBody['print_stock_label']))
|
if (array_key_exists('print_stock_label', $requestBody) && intval($requestBody['print_stock_label']))
|
||||||
{
|
{
|
||||||
$runPrinterWebhook = true;
|
$runPrinterWebhook = intval($requestBody['print_stock_label']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$transactionId = $this->getStockService()->AddProduct($args['productId'], $requestBody['amount'], $bestBeforeDate, $transactionType, $purchasedDate, $price, $locationId, $shoppingLocationId, $unusedTransactionId, $runPrinterWebhook);
|
$transactionId = $this->getStockService()->AddProduct($args['productId'], $requestBody['amount'], $bestBeforeDate, $transactionType, $purchasedDate, $price, $locationId, $shoppingLocationId, $unusedTransactionId, $runPrinterWebhook);
|
||||||
|
|
|
||||||
|
|
@ -2403,4 +2403,22 @@ msgid "Print Product Label"
|
||||||
msgstr "Produkt-Etikett drucken"
|
msgstr "Produkt-Etikett drucken"
|
||||||
|
|
||||||
msgid "Print stock entry label"
|
msgid "Print stock entry label"
|
||||||
msgstr "Etikett drucken"
|
msgstr "Etikett drucken"
|
||||||
|
|
||||||
|
msgid "Stock label"
|
||||||
|
msgstr "Etikett"
|
||||||
|
|
||||||
|
msgid "No Label"
|
||||||
|
msgstr "Kein Etikett"
|
||||||
|
|
||||||
|
msgid "Single Label"
|
||||||
|
msgstr "Ein Etikett pro Einkauf"
|
||||||
|
|
||||||
|
msgid "Label per Unit"
|
||||||
|
msgstr "Ein Etikett pro Mengeneinheit"
|
||||||
|
|
||||||
|
msgid "Allow label printing per unit"
|
||||||
|
msgstr "Erlaube Etikettendruck pro Mengeneinheit"
|
||||||
|
|
||||||
|
msgid "Allow printing of one label per unit in a purchase (after conversion). E.g. 1 purchased pack adding 10 pieces of stock would print 10 labels."
|
||||||
|
msgstr "Erlaube Etikettendruck pro Mengeneinheit nach Umrechnung. Beispiel: 1 gekauftes Paket, das 10 Einheiten hinzufügt, druckt 10 Etiketten."
|
||||||
|
|
@ -2115,3 +2115,21 @@ msgstr ""
|
||||||
|
|
||||||
msgid "Print stock entry label"
|
msgid "Print stock entry label"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Stock label"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "No Label"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Single Label"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Label per Unit"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Allow label printing per unit"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Allow printing of one label per unit in a purchase (after conversion). E.g. 1 purchased pack adding 10 pieces of stock would print 10 labels."
|
||||||
|
msgstr ""
|
||||||
|
|
|
||||||
11
migrations/0128.sql
Normal file
11
migrations/0128.sql
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
ALTER TABLE products
|
||||||
|
ADD default_print_stock_label INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
UPDATE products
|
||||||
|
SET default_print_stock_label = 0;
|
||||||
|
|
||||||
|
ALTER TABLE products
|
||||||
|
ADD allow_label_per_unit INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
UPDATE products
|
||||||
|
SET allow_label_per_unit = 0;
|
||||||
|
|
@ -476,14 +476,22 @@ Grocy.FrontendHelpers.DeleteUserSetting = function(settingsKey, reloadPageOnSucc
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Grocy.FrontendHelpers.RunWebhook = function(webhook, data)
|
Grocy.FrontendHelpers.RunWebhook = function(webhook, data, repetitions = 1)
|
||||||
{
|
{
|
||||||
Object.assign(data, webhook.extra_data);
|
Object.assign(data, webhook.extra_data);
|
||||||
|
var hasAlreadyFailed = false;
|
||||||
|
|
||||||
$.post(webhook.hook, data).fail(function(req, status, errorThrown)
|
for (i = 0; i < repetitions; i++)
|
||||||
{
|
{
|
||||||
Grocy.FrontendHelpers.ShowGenericError(__t("Unable to connect to webhook.", { "status": status, "errorThrown": errorThrown }));
|
$.post(webhook.hook, data).fail(function(req, status, errorThrown)
|
||||||
});
|
{
|
||||||
|
if (!hasAlreadyFailed)
|
||||||
|
{
|
||||||
|
hasAlreadyFailed = true;
|
||||||
|
Grocy.FrontendHelpers.ShowGenericError(__t("Unable to connect to webhook.", { "status": status, "errorThrown": errorThrown }));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).on("keyup paste change", "input, textarea", function()
|
$(document).on("keyup paste change", "input, textarea", function()
|
||||||
|
|
|
||||||
|
|
@ -403,6 +403,22 @@ $('#qu_id_stock').change(function(e)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#allow_label_per_unit').on('change', function()
|
||||||
|
{
|
||||||
|
if (this.checked)
|
||||||
|
{
|
||||||
|
$('#label-option-per-unit').prop("disabled", false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ($('#default_print_stock_label').val() == "2")
|
||||||
|
{
|
||||||
|
$("#default_print_stock_label").val("0");
|
||||||
|
}
|
||||||
|
$('#label-option-per-unit').prop("disabled", true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$(window).on("message", function(e)
|
$(window).on("message", function(e)
|
||||||
{
|
{
|
||||||
var data = e.originalEvent.data;
|
var data = e.originalEvent.data;
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,16 @@ $('#save-purchase-button').on('click', function(e)
|
||||||
{
|
{
|
||||||
post_data.duedate = __t('DD') + ': ' + result[0].best_before_date
|
post_data.duedate = __t('DD') + ': ' + result[0].best_before_date
|
||||||
}
|
}
|
||||||
Grocy.FrontendHelpers.RunWebhook(Grocy.Webhooks.labelprinter, post_data);
|
|
||||||
|
if (jsonForm.print_stock_label > 0)
|
||||||
|
{
|
||||||
|
var reps = 1;
|
||||||
|
if (jsonForm.print_stock_label == 2)
|
||||||
|
{
|
||||||
|
reps = Math.floor(jsonData.amount);
|
||||||
|
}
|
||||||
|
Grocy.FrontendHelpers.RunWebhook(Grocy.Webhooks.labelprinter, post_data, reps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -295,6 +304,23 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABELPRINTER)
|
||||||
|
{
|
||||||
|
$("#print_stock_label").val(productDetails.product.default_print_stock_label);
|
||||||
|
if (productDetails.product.allow_label_per_unit)
|
||||||
|
{
|
||||||
|
if ($('#default_print_stock_label').val() == "2")
|
||||||
|
{
|
||||||
|
$("#default_print_stock_label").val("0");
|
||||||
|
}
|
||||||
|
$('#label-option-per-unit').prop("disabled", true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$('#label-option-per-unit').prop("disabled", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$("#display_amount").focus();
|
$("#display_amount").focus();
|
||||||
|
|
||||||
Grocy.FrontendHelpers.ValidateForm('purchase-form');
|
Grocy.FrontendHelpers.ValidateForm('purchase-form');
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ class StockService extends BaseService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function AddProduct(int $productId, float $amount, $bestBeforeDate, $transactionType, $purchasedDate, $price, $locationId = null, $shoppingLocationId = null, &$transactionId = null, $runWebhook = false, &$webhookData = null)
|
public function AddProduct(int $productId, float $amount, $bestBeforeDate, $transactionType, $purchasedDate, $price, $locationId = null, $shoppingLocationId = null, &$transactionId = null, $runWebhook = 0)
|
||||||
{
|
{
|
||||||
if (!$this->ProductExists($productId))
|
if (!$this->ProductExists($productId))
|
||||||
{
|
{
|
||||||
|
|
@ -182,17 +182,28 @@ class StockService extends BaseService
|
||||||
|
|
||||||
if (GROCY_FEATURE_FLAG_LABELPRINTER && GROCY_LABEL_PRINTER_RUN_SERVER && $runWebhook)
|
if (GROCY_FEATURE_FLAG_LABELPRINTER && GROCY_LABEL_PRINTER_RUN_SERVER && $runWebhook)
|
||||||
{
|
{
|
||||||
|
$reps = 1;
|
||||||
|
if ($runWebhook == 2)
|
||||||
|
{ // 2 == run $amount times
|
||||||
|
$reps = intval(floor($amount));
|
||||||
|
}
|
||||||
|
|
||||||
$webhookData = array_merge([
|
$webhookData = array_merge([
|
||||||
'product' => $stockEntry->product()->name,
|
'product' => $productDetails->product->name,
|
||||||
'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $stockEntry->product_id, [$stockEntry->stock_id])),
|
'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockId])),
|
||||||
], GROCY_LABEL_PRINTER_PARAMS);
|
], GROCY_LABEL_PRINTER_PARAMS);
|
||||||
|
|
||||||
if (GROCY_FEATURE_FLAG_BEST_BEFORE_DATE_TRACKING)
|
if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
|
||||||
{
|
{
|
||||||
$webhookData['duedate'] = $this->getLocalizationService()->__t('DD') . ': ' . $bestBeforeDate;
|
$webhookData['duedate'] = $this->getLocalizationService()->__t('DD') . ': ' . $bestBeforeDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
(new WebhookRunner())->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON);
|
$runner = new WebhookRunner();
|
||||||
|
|
||||||
|
for ($i = 0; $i < $reps; $i++)
|
||||||
|
{
|
||||||
|
$runner->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $transactionId;
|
return $transactionId;
|
||||||
|
|
|
||||||
|
|
@ -405,6 +405,53 @@
|
||||||
'entity' => 'products'
|
'entity' => 'products'
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@if(GROCY_FEATURE_FLAG_LABELPRINTER)
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="custom-control custom-checkbox">
|
||||||
|
<input @if($mode=='edit'
|
||||||
|
&&
|
||||||
|
$product->allow_label_per_unit == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="allow_label_per_unit" name="allow_label_per_unit" value="1">
|
||||||
|
<label class="form-check-label custom-control-label"
|
||||||
|
for="allow_label_per_unit">{{ $__t('Allow label printing per unit') }} <i class="fas fa-question-circle text-muted"
|
||||||
|
data-toggle="tooltip"
|
||||||
|
title="{{ $__t('Allow printing of one label per unit in a purchase (after conversion). E.g. 1 purchased pack adding 10 pieces of stock would print 10 labels.') }}"></i>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@php
|
||||||
|
$no_label = "";
|
||||||
|
$single_label = "";
|
||||||
|
$per_unit_label = "";
|
||||||
|
$disable_per_unit = "";
|
||||||
|
|
||||||
|
if($mode == 'edit') {
|
||||||
|
switch($product->default_print_stock_label) {
|
||||||
|
case 0: $no_label = "selected"; break;
|
||||||
|
case 1: $single_label = "selected"; break;
|
||||||
|
case 2: $per_unit_label = "selected"; break;
|
||||||
|
default: break; // yolo
|
||||||
|
}
|
||||||
|
if($product->allow_label_per_unit == 0) {
|
||||||
|
$disable_per_unit="disabled";
|
||||||
|
$per_unit_label = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="default_print_stock_label">{{ $__t('Stock label') }}</label>
|
||||||
|
<select class="form-control"
|
||||||
|
id="default_print_stock_label"
|
||||||
|
name="default_print_stock_label">
|
||||||
|
<option value="0" {{ $no_label }}>{{ $__t('No Label') }}</option>
|
||||||
|
<option value="1" {{ $single_label }}>{{ $__t('Single Label') }}</option>
|
||||||
|
<option value="2" {{ $per_unit_label }} {{ $disable_per_unit }}
|
||||||
|
id="label-option-per-unit">{{ $__t('Label per Unit') }}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="custom-control custom-checkbox">
|
<div class="custom-control custom-checkbox">
|
||||||
<input @if($mode=='edit'
|
<input @if($mode=='edit'
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<script>
|
<script>
|
||||||
Grocy.QuantityUnits = {!! json_encode($quantityUnits) !!};
|
Grocy.QuantityUnits = {!! json_encode($quantityUnits) !!};
|
||||||
Grocy.QuantityUnitConversionsResolved = {!! json_encode($quantityUnitConversionsResolved) !!};
|
Grocy.QuantityUnitConversionsResolved = {!! json_encode($quantityUnitConversionsResolved) !!};
|
||||||
Grocy.DefaultMinAmount = '{{ $DEFAULT_MIN_AMOUNT }}';
|
Grocy.DefaultMinAmount = '{{ $DEFAULT_MIN_AMOUNT }}';
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -149,17 +149,17 @@ Grocy.QuantityUnits = {!! json_encode($quantityUnits) !!};
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(GROCY_FEATURE_FLAG_LABELPRINTER)
|
@if(GROCY_FEATURE_FLAG_LABELPRINTER)
|
||||||
<div class="form-group mt-n2">
|
<div class="form-group">
|
||||||
<div class="custom-control custom-checkbox">
|
<label for="print_stock_label">{{ $__t('Stock label') }}</label>
|
||||||
<input class="form-check-input custom-control-input"
|
<select class="form-control"
|
||||||
type="checkbox"
|
id="print_stock_label"
|
||||||
id="print_stock_label"
|
name="print_stock_label">
|
||||||
name="print_stock_label"
|
<option value="0">{{ $__t('No Label') }}</option>
|
||||||
value="1">
|
<option value="1">{{ $__t('Single Label') }}</option>
|
||||||
<label class="form-check-label custom-control-label"
|
<option value="2"
|
||||||
for="print_stock_label">{{ $__t("Print stock label") }}
|
id="label-option-per-unit">{{ $__t('Label per Unit') }}</option>
|
||||||
</label>
|
</select>
|
||||||
</div>
|
<div class="invalid-feedback">{{ $__t('A quantity unit is required') }}</div>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user