M3 Integration fixes
This commit is contained in:
@@ -229,24 +229,7 @@ class UtilitiesController extends Controller
|
||||
// Build GS1 18 Digits Code
|
||||
$gs1_128_bc_1 = '00' . $packageType . $manufactID . $gS1SEQUENCEID;
|
||||
|
||||
// Calculate Check Digit
|
||||
$digits = str_split($gs1_128_bc_1);
|
||||
$sum = 0;
|
||||
$length = count($digits);
|
||||
|
||||
// Loop through each digit starting from the right
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$digit = $digits[$length - $i - 1];
|
||||
// Assign a weight of 3 or 1 alternately
|
||||
$weight = ($i % 2 == 0) ? 3 : 1;
|
||||
// Add the product of the digit and its weight to the sum
|
||||
$sum += $digit * $weight;
|
||||
}
|
||||
// Calculate the remainder when sum is divided by 10
|
||||
$remainder = $sum % 10;
|
||||
// If remainder is 0, check digit is 0; otherwise, subtract remainder from 10
|
||||
$checkDigit = ($remainder == 0) ? 0 : 10 - $remainder;
|
||||
// End Check Digit Calculation
|
||||
$checkDigit = self::gs1CheckDigit($gs1_128_bc_1);
|
||||
|
||||
// SSCC 18 Digits Code
|
||||
$gs1_128_bc = $gs1_128_bc_1 . $checkDigit;
|
||||
@@ -377,6 +360,23 @@ class UtilitiesController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
private static function gs1CheckDigit(string $value): int
|
||||
{
|
||||
$digits = str_split($value);
|
||||
$sum = 0;
|
||||
$length = count($digits);
|
||||
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$digit = (int) $digits[$length - $i - 1];
|
||||
$weight = $i % 2 === 0 ? 3 : 1;
|
||||
$sum += $digit * $weight;
|
||||
}
|
||||
|
||||
$remainder = $sum % 10;
|
||||
|
||||
return $remainder === 0 ? 0 : 10 - $remainder;
|
||||
}
|
||||
|
||||
public static function generateGS128Tst(Request $request)
|
||||
{
|
||||
print_r('>>> Generate PDF');
|
||||
|
||||
Reference in New Issue
Block a user