mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Allow to scan barcodes, whose content where defined in the vendor_barcode field
This commit is contained in:
parent
d12bde2b1e
commit
0b178b46f2
4 changed files with 42 additions and 1 deletions
|
@ -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',
|
||||
},
|
||||
|
||||
]);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -11945,5 +11945,11 @@ Please note, that you can not impersonate a disabled user. If you try you will g
|
|||
<target>If this lot already have a barcode (e.g. put there by the vendor), you can input its content here, to easily scan it.</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="2d3cSdD" name="scan_dialog.mode.vendor">
|
||||
<segment>
|
||||
<source>scan_dialog.mode.vendor</source>
|
||||
<target>Vendor barcode (configured in part lot)</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</file>
|
||||
</xliff>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue