Skip to content

Commit 36e409d

Browse files
author
richayles
authored
Adjust CODE_128 to handle odd number of digits
This is a change so that handling for CODE_128 auto takes into account an odd number of digits after an initial string. This then works for international DPD shipping integration "NOTE: If the postcode is all numeric, use subset B for the first 2 digits of the data string, e.g. %0, followed by subset C for the rest of the barcode." Example %008099915501071048275101276 Previously this would output * SUBSET B = %, length 1 * SUBSET C = 00809991550107104827510127, length 26 * SUBSET B = 6, length 1 Now expected outcome is * SUBSET B = %0, length 2 * SUBSET C = 08099915501071048275101276, length 26
1 parent f754cbd commit 36e409d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/BarcodeGenerator.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,12 +1281,21 @@ protected function barcode_c128($code, $type = '')
12811281
$end_offset = 0;
12821282
foreach ($numseq[1] as $val) {
12831283
$offset = $val[1];
1284+
1285+
// numeric sequence
1286+
$slen = strlen($val[0]);
1287+
if (($slen % 2) != 0) {
1288+
// the length must be even
1289+
++$offset;
1290+
$val[0] = substr($val[0],1);
1291+
}
1292+
12841293
if ($offset > $end_offset) {
12851294
// non numeric sequence
12861295
$sequence = array_merge($sequence,
12871296
$this->get128ABsequence(substr($code, $end_offset, ($offset - $end_offset))));
12881297
}
1289-
// numeric sequence
1298+
// numeric sequence fallback
12901299
$slen = strlen($val[0]);
12911300
if (($slen % 2) != 0) {
12921301
// the length must be even

0 commit comments

Comments
 (0)