OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 93 | Rev 142 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
67 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.SpreadSheetCellValueProviderManager;
18
import org.openconcerto.sql.model.SQLRowAccessor;
19
 
20
public class AdresseFullClientValueProvider extends AdresseClientProvider {
21
 
94 ilm 22
    private final int type;
23
    private final boolean withName;
67 ilm 24
 
94 ilm 25
    public AdresseFullClientValueProvider(int type, boolean withName) {
67 ilm 26
        this.type = type;
94 ilm 27
        this.withName = withName;
67 ilm 28
    }
29
 
30
    @Override
31
    public Object getValue(SpreadSheetCellValueContext context) {
80 ilm 32
        final SQLRowAccessor r = getAdresse(context.getRow(), this.type);
93 ilm 33
        String result = "";
94 ilm 34
        if (this.withName) {
35
            result = context.getRow().getForeign("ID_CLIENT").getString("NOM") + "\n";
36
        }
93 ilm 37
        if (r.getString("LIBELLE").trim().length() > 0) {
38
            result = r.getString("LIBELLE") + "\n";
90 ilm 39
        }
93 ilm 40
        if (r.getString("DEST").trim().length() > 0) {
41
            result = r.getString("DEST") + "\n";
42
        }
43
        if (r.getString("RUE").trim().length() > 0) {
94 ilm 44
            result += r.getString("RUE") + "\n";
93 ilm 45
        }
73 ilm 46
        result += "\n" + r.getString("CODE_POSTAL");
47
        result += " ";
94 ilm 48
        if (r.getTable().contains("DISTRICT")) {
49
            result += r.getString("DISTRICT") + " ";
50
        }
73 ilm 51
        result += r.getString("VILLE");
52
        if (r.getBoolean("HAS_CEDEX")) {
53
            result += " Cedex";
54
            String cedex = r.getString("CEDEX");
55
            if (cedex != null && cedex.trim().length() > 0) {
56
                result += " " + cedex;
67 ilm 57
            }
58
        }
94 ilm 59
        if (r.getTable().contains("PROVINCE")) {
60
            result += "\n";
61
            if (r.getString("PROVINCE").trim().length() > 0) {
62
                result += r.getString("PROVINCE") + " ";
63
            }
67 ilm 64
 
94 ilm 65
            if (r.getTable().contains("DEPARTEMENT")) {
66
                result += r.getString("DEPARTEMENT");
67
            }
68
        }
69
 
70
        if (r.getString("PAYS").trim().length() > 0) {
71
            result += "\n" + r.getString("PAYS");
72
        }
73
 
67 ilm 74
        return result;
75
    }
76
 
77
    public static void register() {
94 ilm 78
        SpreadSheetCellValueProviderManager.put("address.customer.full", new AdresseFullClientValueProvider(ADRESSE_PRINCIPALE, false));
79
        SpreadSheetCellValueProviderManager.put("address.customer.invoice.full", new AdresseFullClientValueProvider(ADRESSE_FACTURATION, false));
80
        SpreadSheetCellValueProviderManager.put("address.customer.shipment.full", new AdresseFullClientValueProvider(ADRESSE_LIVRAISON, false));
81
        SpreadSheetCellValueProviderManager.put("address.customer.full.withname", new AdresseFullClientValueProvider(ADRESSE_PRINCIPALE, true));
82
        SpreadSheetCellValueProviderManager.put("address.customer.invoice.full.withname", new AdresseFullClientValueProvider(ADRESSE_FACTURATION, true));
83
        SpreadSheetCellValueProviderManager.put("address.customer.shipment.full.withname", new AdresseFullClientValueProvider(ADRESSE_LIVRAISON, true));
67 ilm 84
    }
85
}