From e40850e0b26bcc1078fc061f175448adefd07ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 4 Jan 2025 01:14:06 +0100 Subject: [PATCH] Dont require trailer for EIGP114 barcodes, as digikey does not seem to put them onto their barcodes --- .../EIGP114BarcodeScanResult.php | 14 ++++---- .../BarcodeRedirectorTest.php | 2 +- .../BarcodeScanHelperTest.php | 2 +- .../EIGP114BarcodeScanResultTest.php} | 32 ++++++++++++++++--- 4 files changed, 36 insertions(+), 14 deletions(-) rename tests/Services/LabelSystem/{Barcodes => BarcodeScanner}/BarcodeRedirectorTest.php (98%) rename tests/Services/LabelSystem/{Barcodes => BarcodeScanner}/BarcodeScanHelperTest.php (99%) rename tests/Services/LabelSystem/{Barcodes/EIGP114BarcodeTest.php => BarcodeScanner/EIGP114BarcodeScanResultTest.php} (68%) diff --git a/src/Services/LabelSystem/BarcodeScanner/EIGP114BarcodeScanResult.php b/src/Services/LabelSystem/BarcodeScanner/EIGP114BarcodeScanResult.php index c636cc3f..0764401a 100644 --- a/src/Services/LabelSystem/BarcodeScanner/EIGP114BarcodeScanResult.php +++ b/src/Services/LabelSystem/BarcodeScanner/EIGP114BarcodeScanResult.php @@ -247,7 +247,8 @@ class EIGP114BarcodeScanResult implements BarcodeScanResultInterface } /** - * Checks if the given input is a valid format06 formatted data + * Checks if the given input is a valid format06 formatted data. + * This just perform a simple check for the header, the content might be malformed still. * @param string $input * @return bool */ @@ -258,10 +259,7 @@ class EIGP114BarcodeScanResult implements BarcodeScanResultInterface return false; } - //Code must end with - if(!str_ends_with($input, "\u{1E}\u{04}")){ - return false; - } + //Digikey does not put a trailer onto the barcode, so we just check for the header return true; } @@ -278,8 +276,10 @@ class EIGP114BarcodeScanResult implements BarcodeScanResultInterface throw new \InvalidArgumentException("The given input is not a valid format06 code"); } - //Remove the trailer - $input = substr($input, 5, -2); + //Remove the trailer, if present + if (str_ends_with($input, "\u{1E}\u{04}")){ + $input = substr($input, 5, -2); + } //Split the input into the different fields (using the separator) $parts = explode("\u{1D}", $input); diff --git a/tests/Services/LabelSystem/Barcodes/BarcodeRedirectorTest.php b/tests/Services/LabelSystem/BarcodeScanner/BarcodeRedirectorTest.php similarity index 98% rename from tests/Services/LabelSystem/Barcodes/BarcodeRedirectorTest.php rename to tests/Services/LabelSystem/BarcodeScanner/BarcodeRedirectorTest.php index cf2a87be..58030f93 100644 --- a/tests/Services/LabelSystem/Barcodes/BarcodeRedirectorTest.php +++ b/tests/Services/LabelSystem/BarcodeScanner/BarcodeRedirectorTest.php @@ -39,7 +39,7 @@ declare(strict_types=1); * along with this program. If not, see . */ -namespace App\Tests\Services\LabelSystem\Barcodes; +namespace App\Tests\Services\LabelSystem\BarcodeScanner; use App\Entity\LabelSystem\LabelSupportedElement; use App\Services\LabelSystem\BarcodeScanner\BarcodeRedirector; diff --git a/tests/Services/LabelSystem/Barcodes/BarcodeScanHelperTest.php b/tests/Services/LabelSystem/BarcodeScanner/BarcodeScanHelperTest.php similarity index 99% rename from tests/Services/LabelSystem/Barcodes/BarcodeScanHelperTest.php rename to tests/Services/LabelSystem/BarcodeScanner/BarcodeScanHelperTest.php index e24c960b..a90a3bac 100644 --- a/tests/Services/LabelSystem/Barcodes/BarcodeScanHelperTest.php +++ b/tests/Services/LabelSystem/BarcodeScanner/BarcodeScanHelperTest.php @@ -39,7 +39,7 @@ declare(strict_types=1); * along with this program. If not, see . */ -namespace App\Tests\Services\LabelSystem\Barcodes; +namespace App\Tests\Services\LabelSystem\BarcodeScanner; use App\Entity\LabelSystem\LabelSupportedElement; use App\Services\LabelSystem\BarcodeScanner\BarcodeScanHelper; diff --git a/tests/Services/LabelSystem/Barcodes/EIGP114BarcodeTest.php b/tests/Services/LabelSystem/BarcodeScanner/EIGP114BarcodeScanResultTest.php similarity index 68% rename from tests/Services/LabelSystem/Barcodes/EIGP114BarcodeTest.php rename to tests/Services/LabelSystem/BarcodeScanner/EIGP114BarcodeScanResultTest.php index 9eca7104..aa5e4fbc 100644 --- a/tests/Services/LabelSystem/Barcodes/EIGP114BarcodeTest.php +++ b/tests/Services/LabelSystem/BarcodeScanner/EIGP114BarcodeScanResultTest.php @@ -18,12 +18,12 @@ * along with this program. If not, see . */ -namespace App\Tests\Services\LabelSystem\Barcodes; +namespace App\Tests\Services\LabelSystem\BarcodeScanner; use App\Services\LabelSystem\BarcodeScanner\EIGP114BarcodeScanResult; use PHPUnit\Framework\TestCase; -class EIGP114BarcodeTest extends TestCase +class EIGP114BarcodeScanResultTest extends TestCase { public function testGuessBarcodeVendor(): void @@ -85,11 +85,12 @@ class EIGP114BarcodeTest extends TestCase $this->assertFalse(EIGP114BarcodeScanResult::isFormat06Code('')); $this->assertFalse(EIGP114BarcodeScanResult::isFormat06Code('test')); $this->assertFalse(EIGP114BarcodeScanResult::isFormat06Code('12232435ew4rf')); - //Missing trailer - $this->assertFalse(EIGP114BarcodeScanResult::isFormat06Code("[)>\x1E06\x1DP596-777A1-ND\x1D1PXAF4444\x1DQ3\x1D10D1452\x1D1TBF1103\x1D4LUS")); - //Valid code + //Valid code (with trailer) $this->assertTrue(EIGP114BarcodeScanResult::isFormat06Code("[)>\x1E06\x1DP596-777A1-ND\x1D1PXAF4444\x1DQ3\x1D10D1452\x1D1TBF1103\x1D4LUS\x1E\x04")); + + //Valid code (digikey, without trailer) + $this->assertTrue(EIGP114BarcodeScanResult::isFormat06Code("[)>\x1e06\x1dPQ1045-ND\x1d1P364019-01\x1d30PQ1045-ND\x1dK12432 TRAVIS FOSS P\x1d1K85732873\x1d10K103332956\x1d9D231013\x1d1TQJ13P\x1d11K1\x1d4LTW\x1dQ3\x1d11ZPICK\x1d12Z7360988\x1d13Z999999\x1d20Z0000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); } public function testParseFormat06CodeInvalid(): void @@ -129,4 +130,25 @@ class EIGP114BarcodeTest extends TestCase $this->assertEquals('BF1103', $barcode->lotCode); $this->assertEquals('US', $barcode->countryOfOrigin); } + + public function testDigikeyParsing(): void + { + $barcode = EIGP114BarcodeScanResult::parseFormat06Code("[)>\x1e06\x1dPQ1045-ND\x1d1P364019-01\x1d30PQ1045-ND\x1dK12432 TRAVIS FOSS P\x1d1K85732873\x1d10K103332956\x1d9D231013\x1d1TQJ13P\x1d11K1\x1d4LTW\x1dQ3\x1d11ZPICK\x1d12Z7360988\x1d13Z999999\x1d20Z0000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); + + $this->assertEquals('digikey', $barcode->guessBarcodeVendor()); + + $this->assertEquals('Q1045-ND', $barcode->customerPartNumber); + $this->assertEquals('364019-01', $barcode->supplierPartNumber); + $this->assertEquals(3, $barcode->quantity); + $this->assertEquals('231013', $barcode->dateCode); + $this->assertEquals('QJ13P', $barcode->lotCode); + $this->assertEquals('TW', $barcode->countryOfOrigin); + $this->assertEquals('Q1045-ND', $barcode->digikeyPartNumber); + $this->assertEquals('85732873', $barcode->digikeySalesOrderNumber); + $this->assertEquals('103332956', $barcode->digikeyInvoiceNumber); + $this->assertEquals('PICK', $barcode->digikeyLabelType); + $this->assertEquals('7360988', $barcode->digikeyPartID); + $this->assertEquals('999999', $barcode->digikeyNA); + $this->assertEquals('0000000000000000000000000000000000000000000000000000000000000000000000000000000000000', $barcode->digikeyPadding); + } }