mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-20 17:19:34 +00:00
Dont require trailer for EIGP114 barcodes, as digikey does not seem to put them onto their barcodes
This commit is contained in:
parent
e5d91dc8fc
commit
e40850e0b2
4 changed files with 36 additions and 14 deletions
|
|
@ -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
|
* @param string $input
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
|
@ -258,10 +259,7 @@ class EIGP114BarcodeScanResult implements BarcodeScanResultInterface
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Code must end with <RS><EOT>
|
//Digikey does not put a trailer onto the barcode, so we just check for the header
|
||||||
if(!str_ends_with($input, "\u{1E}\u{04}")){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -278,8 +276,10 @@ class EIGP114BarcodeScanResult implements BarcodeScanResultInterface
|
||||||
throw new \InvalidArgumentException("The given input is not a valid format06 code");
|
throw new \InvalidArgumentException("The given input is not a valid format06 code");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Remove the trailer
|
//Remove the trailer, if present
|
||||||
|
if (str_ends_with($input, "\u{1E}\u{04}")){
|
||||||
$input = substr($input, 5, -2);
|
$input = substr($input, 5, -2);
|
||||||
|
}
|
||||||
|
|
||||||
//Split the input into the different fields (using the <GS> separator)
|
//Split the input into the different fields (using the <GS> separator)
|
||||||
$parts = explode("\u{1D}", $input);
|
$parts = explode("\u{1D}", $input);
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ declare(strict_types=1);
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\Tests\Services\LabelSystem\Barcodes;
|
namespace App\Tests\Services\LabelSystem\BarcodeScanner;
|
||||||
|
|
||||||
use App\Entity\LabelSystem\LabelSupportedElement;
|
use App\Entity\LabelSystem\LabelSupportedElement;
|
||||||
use App\Services\LabelSystem\BarcodeScanner\BarcodeRedirector;
|
use App\Services\LabelSystem\BarcodeScanner\BarcodeRedirector;
|
||||||
|
|
@ -39,7 +39,7 @@ declare(strict_types=1);
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\Tests\Services\LabelSystem\Barcodes;
|
namespace App\Tests\Services\LabelSystem\BarcodeScanner;
|
||||||
|
|
||||||
use App\Entity\LabelSystem\LabelSupportedElement;
|
use App\Entity\LabelSystem\LabelSupportedElement;
|
||||||
use App\Services\LabelSystem\BarcodeScanner\BarcodeScanHelper;
|
use App\Services\LabelSystem\BarcodeScanner\BarcodeScanHelper;
|
||||||
|
|
@ -18,12 +18,12 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\Tests\Services\LabelSystem\Barcodes;
|
namespace App\Tests\Services\LabelSystem\BarcodeScanner;
|
||||||
|
|
||||||
use App\Services\LabelSystem\BarcodeScanner\EIGP114BarcodeScanResult;
|
use App\Services\LabelSystem\BarcodeScanner\EIGP114BarcodeScanResult;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class EIGP114BarcodeTest extends TestCase
|
class EIGP114BarcodeScanResultTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testGuessBarcodeVendor(): void
|
public function testGuessBarcodeVendor(): void
|
||||||
|
|
@ -85,11 +85,12 @@ class EIGP114BarcodeTest extends TestCase
|
||||||
$this->assertFalse(EIGP114BarcodeScanResult::isFormat06Code(''));
|
$this->assertFalse(EIGP114BarcodeScanResult::isFormat06Code(''));
|
||||||
$this->assertFalse(EIGP114BarcodeScanResult::isFormat06Code('test'));
|
$this->assertFalse(EIGP114BarcodeScanResult::isFormat06Code('test'));
|
||||||
$this->assertFalse(EIGP114BarcodeScanResult::isFormat06Code('12232435ew4rf'));
|
$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"));
|
$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
|
public function testParseFormat06CodeInvalid(): void
|
||||||
|
|
@ -129,4 +130,25 @@ class EIGP114BarcodeTest extends TestCase
|
||||||
$this->assertEquals('BF1103', $barcode->lotCode);
|
$this->assertEquals('BF1103', $barcode->lotCode);
|
||||||
$this->assertEquals('US', $barcode->countryOfOrigin);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue