- Модуль: ui
- Путь к файлу: ~/bitrix/modules/ui/lib/barcode/barcodegenerator.php
- Класс: BitrixUIBarcodeBarcodeGenerator
- Вызов: BarcodeGenerator::ean_13_normalize
private function ean_13_normalize($data) {
$data = preg_replace('/[^0-9*]/', '', $data);
/* Set length to 13 digits. */
if (strlen($data) < 13) {
return '0' . $this->upc_a_normalize($data);
} else if (strlen($data) > 13) {
$left = substr($data, 0, 7);
$right = substr($data, -6);
$data = $left . $right;
}
/* Replace * with missing or check digit. */
while (($o = strrpos($data, '*')) !== false) {
$checksum = 0;
for ($i = 0; $i < 13; $i++) {
$digit = (int)$data[$i];
$checksum += (($i % 2) ? 3 : 1) * $digit;
}
$checksum *= (($o % 2) ? 3 : 9);
$left = substr($data, 0, $o);
$center = substr($checksum, -1);
$right = substr($data, $o + 1);
$data = $left . $center . $right;
}
return $data;
}