From acaf80faf87a183ce285d276ea443ad5ecee6aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Kutn=C3=BD?= Date: Wed, 17 Jul 2024 20:31:21 +0200 Subject: [PATCH] Fixed checksum calculation for ITF14 barcode type source: How to calculate a check digit manually https://www.gs1.org/services/how-calculate-check-digit-manually --- src/Types/TypeITF14.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Types/TypeITF14.php b/src/Types/TypeITF14.php index ff395d9..12d6054 100644 --- a/src/Types/TypeITF14.php +++ b/src/Types/TypeITF14.php @@ -73,8 +73,8 @@ private function getChecksum(string $code): string $total = 0; for ($charIndex = 0; $charIndex <= (strlen($code) - 1); $charIndex++) { - $integerOfChar = intval($code . substr($charIndex, 1)); - $total += $integerOfChar * (($charIndex === 0 || $charIndex % 2 === 0) ? 3 : 1); + $integerOfChar = intval($code[$charIndex]); + $total += $integerOfChar * ($charIndex % 2 === 0 ? 3 : 1); } $checksum = 10 - ($total % 10);