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