Subversion Repositories cheapmusic

Rev

Rev 121 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 121 Rev 134
Line 130... Line 130...
130
 
130
 
131
    public static function GTINCalcCheckDigit($p_sGTINCode) {
131
    public static function GTINCalcCheckDigit($p_sGTINCode) {
132
        $p_sGTINCode = (string)trim($p_sGTINCode);
132
        $p_sGTINCode = (string)trim($p_sGTINCode);
133
        if (preg_match('/[^0-9]/', $p_sGTINCode)) return false;
133
        if (preg_match('/[^0-9]/', $p_sGTINCode)) return false;
134
 
134
 
135
        $p_sGTINCode .= '0';
135
        $p_sGTINCode .= 'X';
136
        $sGTINCode = trim($p_sGTINCode);
136
        $sGTINCode = trim($p_sGTINCode);
137
        $length = strlen($sGTINCode);
137
        $length = strlen($sGTINCode);
138
        if (($length > 11 && $length <= 14) || $length == 8) {
138
        if (($length > 11 && $length <= 14) || $length == 8) {
139
            $zeroes = 18 - $length;
139
            $zeroes = 18 - $length;
140
            $length = null;
140
            $length = null;
Line 143... Line 143...
143
                $fill .= "0";
143
                $fill .= "0";
144
            }
144
            }
145
            $zeroes = null;
145
            $zeroes = null;
146
            $sGTINCode = $fill . $sGTINCode;
146
            $sGTINCode = $fill . $sGTINCode;
147
            $fill = null;
147
            $fill = null;
-
 
148
        } else {
-
 
149
            return false;
148
        }
150
        }
149
        $iCalculation = 0;
151
        $iCalculation = 0;
150
        for ($i = 0;$i < (strlen($sGTINCode) - 1);$i++) {
152
        for ($i = 0;$i < (strlen($sGTINCode) - 1);$i++) {
151
            $iCalculation += $i % 2 ? $sGTINCode[$i] * 1 : $sGTINCode[$i] * 3;
153
            $iCalculation += $i % 2 ? $sGTINCode[$i] * 1 : $sGTINCode[$i] * 3;
152
        }
154
        }