OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
181 ilm 1
/*
2
 * Copyright 2015 Robin Stuart
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
 * in compliance with the License. You may obtain a copy of the License at
6
 *
7
 * http://www.apache.org/licenses/LICENSE-2.0
8
 *
9
 * Unless required by applicable law or agreed to in writing, software distributed under the License
10
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
 * or implied. See the License for the specific language governing permissions and limitations under
12
 * the License.
13
 */
14
package uk.org.okapibarcode.backend;
15
 
16
/**
17
 * PZN8 is a Code 39 based symbology used by the pharmaceutical industry in Germany. PZN8 encodes a
18
 * 7 digit number and includes a modulo-10 check digit.
19
 *
20
 * @author <a href="mailto:rstuart114@gmail.com">Robin Stuart</a>
21
 */
22
public class Pharmazentralnummer extends Symbol {
23
 
24
    /*
25
     * Pharmazentral Nummer is a Code 3 of 9 symbol with an extra check digit. Now generates PZN-8.
26
     */
27
 
28
    @Override
29
    protected void encode() {
30
        final int l = this.content.length();
31
        String localstr;
32
        int zeroes, count = 0, check_digit;
33
        final Code3Of9 c = new Code3Of9();
34
 
35
        if (l > 7) {
36
            throw new OkapiException("Input data too long");
37
        }
38
 
39
        if (!this.content.matches("[0-9]+")) {
40
            throw new OkapiException("Invalid characters in input");
41
        }
42
 
43
        localstr = "-";
44
        zeroes = 7 - l + 1;
45
        for (int i = 1; i < zeroes; i++) {
46
            localstr += '0';
47
        }
48
 
49
        localstr += this.content;
50
 
51
        for (int i = 1; i < 8; i++) {
52
            count += i * Character.getNumericValue(localstr.charAt(i));
53
        }
54
 
55
        check_digit = count % 11;
56
        if (check_digit == 11) {
57
            check_digit = 0;
58
        }
59
        if (check_digit == 10) {
60
            throw new OkapiException("Not a valid PZN identifier");
61
        }
62
 
63
        infoLine("Check Digit: " + check_digit);
64
 
65
        localstr += (char) (check_digit + '0');
66
 
67
        c.setContent(localstr);
68
 
69
        this.readable = "PZN" + localstr;
70
        this.pattern = new String[1];
71
        this.pattern[0] = c.pattern[0];
72
        this.row_count = 1;
73
        this.row_height = new int[1];
74
        this.row_height[0] = -1;
75
    }
76
}