Skip to content

Commit

Permalink
Fixed checksum calculation for ITF14 barcode type
Browse files Browse the repository at this point in the history
source: How to calculate a check digit manually
https://www.gs1.org/services/how-calculate-check-digit-manually
  • Loading branch information
vitkutny committed Jul 17, 2024
1 parent 0cc7fbd commit acaf80f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Types/TypeITF14.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit acaf80f

Please sign in to comment.