diff --git a/src/Form/LabelSystem/ScanDialogType.php b/src/Form/LabelSystem/ScanDialogType.php index 007dad9a..5230dd5a 100644 --- a/src/Form/LabelSystem/ScanDialogType.php +++ b/src/Form/LabelSystem/ScanDialogType.php @@ -71,6 +71,7 @@ class ScanDialogType extends AbstractType null => 'scan_dialog.mode.auto', BarcodeSourceType::INTERNAL => 'scan_dialog.mode.internal', BarcodeSourceType::IPN => 'scan_dialog.mode.ipn', + BarcodeSourceType::VENDOR => 'scan_dialog.mode.vendor', }, ]); diff --git a/src/Services/LabelSystem/Barcodes/BarcodeScanHelper.php b/src/Services/LabelSystem/Barcodes/BarcodeScanHelper.php index 4a2b2c37..b53d3f02 100644 --- a/src/Services/LabelSystem/Barcodes/BarcodeScanHelper.php +++ b/src/Services/LabelSystem/Barcodes/BarcodeScanHelper.php @@ -43,6 +43,7 @@ namespace App\Services\LabelSystem\Barcodes; use App\Entity\LabelSystem\LabelSupportedElement; use App\Entity\Parts\Part; +use App\Entity\Parts\PartLot; use Doctrine\ORM\EntityManagerInterface; use InvalidArgumentException; @@ -82,6 +83,9 @@ final class BarcodeScanHelper if ($type === BarcodeSourceType::INTERNAL) { return $this->parseInternalBarcode($input) ?? throw new InvalidArgumentException('Could not parse barcode'); } + if ($type === BarcodeSourceType::VENDOR) { + return $this->parseVendorBarcode($input) ?? throw new InvalidArgumentException('Could not parse barcode'); + } if ($type === BarcodeSourceType::IPN) { return $this->parseIPNBarcode($input) ?? throw new InvalidArgumentException('Could not parse barcode'); } @@ -93,13 +97,38 @@ final class BarcodeScanHelper return $result; } + //Try to parse as vendor barcode + $result = $this->parseVendorBarcode($input); + if ($result !== null) { + return $result; + } + //Try to parse as IPN barcode $result = $this->parseIPNBarcode($input); if ($result !== null) { return $result; } - throw new InvalidArgumentException('Unknown barcode format'); + throw new InvalidArgumentException('Unknown barcode'); + } + + private function parseVendorBarcode(string $input): ?BarcodeScanResult + { + $lot_repo = $this->entityManager->getRepository(PartLot::class); + //Find only the first result + $results = $lot_repo->findBy(['vendor_barcode' => $input], limit: 1); + + if (count($results) === 0) { + return null; + } + //We found a part, so use it to create the result + $lot = $results[0]; + + return new BarcodeScanResult( + target_type: LabelSupportedElement::PART_LOT, + target_id: $lot->getID(), + source_type: BarcodeSourceType::VENDOR + ); } private function parseIPNBarcode(string $input): ?BarcodeScanResult diff --git a/src/Services/LabelSystem/Barcodes/BarcodeSourceType.php b/src/Services/LabelSystem/Barcodes/BarcodeSourceType.php index 4778f0cd..20ba316a 100644 --- a/src/Services/LabelSystem/Barcodes/BarcodeSourceType.php +++ b/src/Services/LabelSystem/Barcodes/BarcodeSourceType.php @@ -32,4 +32,9 @@ enum BarcodeSourceType case INTERNAL; /** This barcode is containing an internal part number (IPN) */ case IPN; + /** + * This barcode is a custom barcode from a third party like a vendor, which was set via the vendor_barcode + * field of a part lot. + */ + case VENDOR; } \ No newline at end of file diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index 919e14c3..7197f3b7 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -11945,5 +11945,11 @@ Please note, that you can not impersonate a disabled user. If you try you will g If this lot already have a barcode (e.g. put there by the vendor), you can input its content here, to easily scan it. + + + scan_dialog.mode.vendor + Vendor barcode (configured in part lot) + +