diff --git a/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php b/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php index 2389c6e2..9fb49d33 100644 --- a/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php +++ b/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php @@ -69,15 +69,15 @@ class BarcodeContentGenerator /** * Returns a Code that can be used in a 1D barcode. - * The return value has a format of "L-000123" + * The return value has a format of "L0123" * @param AbstractDBElement $target * @return string */ public function get1DBarcodeContent(AbstractDBElement $target): string { $prefix = $this->classToString(self::PREFIX_MAP, $target); - $id = sprintf('%06d', $target->getID()); - return $prefix . '-' . $id; + $id = sprintf('%04d', $target->getID()); + return $prefix . $id; } protected function classToString(array $map, object $target): string diff --git a/src/Services/LabelSystem/Barcodes/BarcodeNormalizer.php b/src/Services/LabelSystem/Barcodes/BarcodeNormalizer.php index 8edd4e2d..aad138bb 100644 --- a/src/Services/LabelSystem/Barcodes/BarcodeNormalizer.php +++ b/src/Services/LabelSystem/Barcodes/BarcodeNormalizer.php @@ -48,7 +48,18 @@ class BarcodeNormalizer return [$matches[1], (int) $matches[2]]; } - //New Code39 barcodes use L-000001 format + //New Code39 barcode use L0001 format + if (preg_match('#^([A-Z])(\d{4,})$#', $input, $matches)) { + $prefix = $matches[1]; + $id = (int) $matches[2]; + + if (!isset(self::PREFIX_TYPE_MAP[$prefix])) { + throw new \InvalidArgumentException('Unknown prefix ' . $prefix); + } + return [self::PREFIX_TYPE_MAP[$prefix], $id]; + } + + //During development the L-000001 format was used if (preg_match('#^(\w)-(\d{6,})$#', $input, $matches)) { $prefix = $matches[1]; $id = (int) $matches[2]; diff --git a/tests/Services/LabelSystem/BarcodeParserTest.php b/tests/Services/LabelSystem/BarcodeParserTest.php index bd0a4b13..aa62909b 100644 --- a/tests/Services/LabelSystem/BarcodeParserTest.php +++ b/tests/Services/LabelSystem/BarcodeParserTest.php @@ -32,8 +32,5 @@ class BarcodeParserTest extends TestCase { } - - public function testNormalizeBarcodeContent() - { - } + } diff --git a/tests/Services/LabelSystem/Barcodes/BarcodeNormalizerTest.php b/tests/Services/LabelSystem/Barcodes/BarcodeNormalizerTest.php index da773b99..b1d78760 100644 --- a/tests/Services/LabelSystem/Barcodes/BarcodeNormalizerTest.php +++ b/tests/Services/LabelSystem/Barcodes/BarcodeNormalizerTest.php @@ -44,7 +44,12 @@ class BarcodeNormalizerTest extends WebTestCase [['part', 123], 'https://localhost:8000/scan/part/123'], [['location', 4], 'http://foo.bar/part-db/scan/location/4'], [['under_score', 10], 'http://test/part-db/sub/scan/under_score/10/'], - //New Code39 barcodes: + //Current Code39 format: + [['lot', 10], 'L0010'], + [['lot', 123], 'L0123'], + [['lot', 123456], 'L123456'], + [['part', 2], 'P0002'], + //Development phase Code39 barcodes: [['lot', 10], 'L-000010'], [['lot', 10], 'Lß000010'], [['part', 123], 'P-000123'],