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
177 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.generationDoc.provider;
15
 
16
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext;
17
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProvider;
18
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager;
19
import org.openconcerto.sql.model.SQLRowAccessor;
20
import org.openconcerto.utils.Tuple2;
21
 
22
public class IbanProvider implements SpreadSheetCellValueProvider {
23
 
24
    private static Tuple2<Integer, Integer> CODE_PAYS = Tuple2.create(0, 2);
25
    private static Tuple2<Integer, Integer> CLE_IBAN = Tuple2.create(2, 4);
26
    private static Tuple2<Integer, Integer> CODE_BANQUE = Tuple2.create(4, 9);
27
    private static Tuple2<Integer, Integer> CODE_GUICHET = Tuple2.create(9, 14);
28
    private static Tuple2<Integer, Integer> NUMERO_COMPTE = Tuple2.create(14, 25);
29
    private static Tuple2<Integer, Integer> CLE_RIB = Tuple2.create(25, 27);
30
 
31
    private final Tuple2<Integer, Integer> currentTuple;
32
 
33
    public IbanProvider(Tuple2<Integer, Integer> tuple) {
34
        this.currentTuple = tuple;
35
    }
36
 
37
    public Object getValue(SpreadSheetCellValueContext context) {
38
        final SQLRowAccessor row = context.getRow();
39
 
40
        String iban = row.getString("IBAN").trim().replaceAll(" ", "");
41
 
42
        if (iban.length() >= this.currentTuple.get1()) {
43
            return iban.substring(this.currentTuple.get0(), this.currentTuple.get1());
44
        } else {
45
            return "";
46
        }
47
    }
48
 
49
    public static void register() {
50
        SpreadSheetCellValueProviderManager.put("iban.codepays", new IbanProvider(CODE_PAYS));
51
        SpreadSheetCellValueProviderManager.put("iban.cleiban", new IbanProvider(CLE_IBAN));
52
        SpreadSheetCellValueProviderManager.put("iban.codebanque", new IbanProvider(CODE_BANQUE));
53
        SpreadSheetCellValueProviderManager.put("iban.codeguichet", new IbanProvider(CODE_GUICHET));
54
        SpreadSheetCellValueProviderManager.put("iban.numerocompte", new IbanProvider(NUMERO_COMPTE));
55
        SpreadSheetCellValueProviderManager.put("iban.clerib", new IbanProvider(CLE_RIB));
56
    }
57
 
58
    public static void main(String[] args) {
59
        String iban = "FR763000401587000260111220";
60
        System.err.println(iban.substring(CODE_PAYS.get0(), CODE_PAYS.get1()));
61
        System.err.println(iban.substring(CLE_IBAN.get0(), CLE_IBAN.get1()));
62
        System.err.println(iban.substring(CODE_BANQUE.get0(), CODE_BANQUE.get1()));
63
        System.err.println(iban.substring(CODE_GUICHET.get0(), CODE_GUICHET.get1()));
64
        System.err.println(iban.substring(NUMERO_COMPTE.get0(), NUMERO_COMPTE.get1()));
65
        if (iban.length() >= CLE_RIB.get1()) {
66
            System.err.println(iban.substring(CLE_RIB.get0(), CLE_RIB.get1()));
67
        }
68
    }
69
}