Пример #1
0
function getCododigoConControl($cadena)
{
    $iSum = 0;
    $iDigit = 0;
    $EAN = $cadena;
    for ($i = strlen($EAN); $i >= 1; $i--) {
        $iDigit = substr($EAN, $i - 1, 1);
        if ($i % 2 == 0) {
            $iSum = $iSum + $iDigit * 3;
        } else {
            $iSum = $iSum + $iDigit * 1;
        }
    }
    $iCheckSum = (10 - $iSum % 10) % 10;
    return $cadena . $iCheckSum;
}
$code = getvar('code');
$codes = explode('-', $code);
$temp = "000" . $codes[0] . $codes[1];
$code = getCododigoConControl("000" . $codes[0] . $codes[1]);
if (!$code) {
    $code = '123456789012';
}
barcode_print($code, getvar('encoding'), getvar('scale'), getvar('mode'));
/*
 * call
 * http://........./barcode.php?code=012345678901
 *   or
 * http://........./barcode.php?code=012345678901&encoding=EAN&scale=4&mode=png
 *
 */
Пример #2
0
    $iSum = 0;
    $iDigit = 0;
    $EAN = $cadena;
    for ($i = strlen($EAN); $i >= 1; $i--) {
        $iDigit = substr($EAN, $i - 1, 1);
        if ($i % 2 == 0) {
            $iSum = $iSum + $iDigit * 3;
        } else {
            $iSum = $iSum + $iDigit * 1;
        }
    }
    $iCheckSum = (10 - $iSum % 10) % 10;
    return $cadena . $iCheckSum;
}
$code = getvar('code');
$codes = explode('-', $code);
$anp = sprintf("%03d", $_SESSION['session'][7]);
$temp = $anp . $codes[1] . $codes[2];
// 3 para anp, 5 para codigo, 4 anio = 12 num
$code = getCododigoConControl($temp);
if (!$code) {
    $code = '123456789012';
}
barcode_print($code, getvar('encoding'), getvar('scale'), getvar('mode'));
/*
 * call
 * http://........./barcode.php?code=012345678901
 *   or
 * http://........./barcode.php?code=012345678901&encoding=EAN&scale=4&mode=png
 *
 */