From 3b0470266523398eba67b8a552315e0e3689c266 Mon Sep 17 00:00:00 2001 From: MarcoE Date: Wed, 16 Sep 2026 18:07:43 +0200 Subject: [PATCH] Decodifica PLU dai barcode CODE128 a 7 cifre Oltre alle etichette a peso variabile (EAN13/CODE128 a 13 cifre), ora vengono riconosciuti i CODE128 di 7 cifre che iniziano con '2': si scarta il prefisso e restano le 6 cifre del PLU, come per DecodeEanPeso. --- .../Core/BarcodeReader/BarcodeManager.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/SteUp.Shared/Core/BarcodeReader/BarcodeManager.cs b/SteUp.Shared/Core/BarcodeReader/BarcodeManager.cs index ea9009e..51db2bf 100644 --- a/SteUp.Shared/Core/BarcodeReader/BarcodeManager.cs +++ b/SteUp.Shared/Core/BarcodeReader/BarcodeManager.cs @@ -26,6 +26,8 @@ public class BarcodeManager( if (IsEanPeso(dto)) stringValue = DecodeEanPeso(stringValue); + else if (IsPlu(dto)) + stringValue = DecodePlu(stringValue); messenger.Send(new NewScannerMessage(stringValue)); }, @@ -39,14 +41,29 @@ public class BarcodeManager( (IsEtichetta128(barcodeScan) || IsEan13(barcodeScan)) && barcodeScan.StringValue is { Length: 13 } && barcodeScan.StringValue.StartsWith('2'); + private static bool IsPlu(BarcodeScanDto barcodeScan) => + IsCode128(barcodeScan) && barcodeScan.StringValue is { Length: 7 } && barcodeScan.StringValue.StartsWith('2'); + private static bool IsEtichetta128(BarcodeScanDto barcodeScan) => barcodeScan.Type is BarcodeType.CODE128 or BarcodeType.EAN128; + private static bool IsCode128(BarcodeScanDto barcodeScan) => + barcodeScan.Type == BarcodeType.CODE128; + private static bool IsEan13(BarcodeScanDto barcodeScan) => barcodeScan.Type == BarcodeType.EAN13; private static string DecodeEanPeso(string? barcode) { - return barcode is not { Length: 13 } ? throw new Exception("Errore durante il parse del barcode (" + barcode + ")") : barcode.Substring(1, 6); + return barcode is not { Length: 13 } + ? throw new Exception("Errore durante il parse del barcode (" + barcode + ")") + : barcode.Substring(1, 6); + } + + private static string DecodePlu(string? barcode) + { + return barcode is not { Length: 7 } + ? throw new Exception("Errore durante il parse del barcode (" + barcode + ")") + : barcode.Substring(1, 6); } } \ No newline at end of file