OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | 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;
182 ilm 24
    private final boolean noCountry;
67 ilm 25
 
182 ilm 26
    public AdresseFullClientValueProvider(int type, boolean withName, boolean noCountry) {
67 ilm 27
        this.type = type;
94 ilm 28
        this.withName = withName;
182 ilm 29
        this.noCountry = noCountry;
67 ilm 30
    }
31
 
32
    @Override
33
    public Object getValue(SpreadSheetCellValueContext context) {
80 ilm 34
        final SQLRowAccessor r = getAdresse(context.getRow(), this.type);
93 ilm 35
        String result = "";
94 ilm 36
        if (this.withName) {
182 ilm 37
            result = context.getRow().getForeign("ID_CLIENT").getString("NOM") + "\n\n";
94 ilm 38
        }
182 ilm 39
        result = getFormattedAddress(r, result, !this.noCountry);
142 ilm 40
 
41
        return result;
42
    }
43
 
44
    public static String getFormattedAddress(final SQLRowAccessor rAddress, String prefix) {
182 ilm 45
        return getFormattedAddress(rAddress, prefix, true);
46
    }
47
 
48
    public static String getFormattedAddress(final SQLRowAccessor rAddress, String prefix, boolean withCountry) {
142 ilm 49
        String result = prefix;
182 ilm 50
        boolean notEmptyLib = getStringTrimmed(rAddress, "LIBELLE").length() > 0;
51
        if (notEmptyLib) {
142 ilm 52
            result = getStringTrimmed(rAddress, "LIBELLE") + "\n";
90 ilm 53
        }
182 ilm 54
        boolean notEmptyDest = getStringTrimmed(rAddress, "DEST").length() > 0;
55
        if (notEmptyDest) {
142 ilm 56
            result = getStringTrimmed(rAddress, "DEST") + "\n";
93 ilm 57
        }
182 ilm 58
        boolean notEmptyRue = getStringTrimmed(rAddress, "RUE").length() > 0;
59
        if (notEmptyRue) {
142 ilm 60
            result += getStringTrimmed(rAddress, "RUE") + "\n";
93 ilm 61
        }
182 ilm 62
        result += notEmptyDest && notEmptyLib && notEmptyLib ? ("\n" + getStringTrimmed(rAddress, "CODE_POSTAL")) : getStringTrimmed(rAddress, "CODE_POSTAL");
73 ilm 63
        result += " ";
142 ilm 64
        if (rAddress.getTable().contains("DISTRICT")) {
65
            result += getStringTrimmed(rAddress, "DISTRICT") + " ";
94 ilm 66
        }
142 ilm 67
        result += getStringTrimmed(rAddress, "VILLE");
68
        if (rAddress.getBoolean("HAS_CEDEX")) {
73 ilm 69
            result += " Cedex";
142 ilm 70
            String cedex = getStringTrimmed(rAddress, "CEDEX");
71
            if (cedex.length() > 0) {
73 ilm 72
                result += " " + cedex;
67 ilm 73
            }
74
        }
142 ilm 75
        if (rAddress.getTable().contains("PROVINCE")) {
182 ilm 76
            String province = getStringTrimmed(rAddress, "PROVINCE");
77
            boolean department = rAddress.getTable().contains("DEPARTEMENT");
78
            if (province.length() > 0 || (department && getStringTrimmed(rAddress, "DEPARTEMENT").length() > 0)) {
79
                result += "\n";
80
            }
81
            if (province.length() > 0) {
82
 
142 ilm 83
                result += getStringTrimmed(rAddress, ("PROVINCE")) + " ";
94 ilm 84
            }
67 ilm 85
 
182 ilm 86
            if (department && getStringTrimmed(rAddress, "DEPARTEMENT").length() > 0) {
87
 
142 ilm 88
                result += getStringTrimmed(rAddress, "DEPARTEMENT");
94 ilm 89
            }
90
        }
91
 
182 ilm 92
        if (withCountry && getStringTrimmed(rAddress, "PAYS").length() > 0) {
142 ilm 93
            result += "\n" + getStringTrimmed(rAddress, "PAYS");
94 ilm 94
        }
67 ilm 95
        return result;
96
    }
97
 
142 ilm 98
    public static String getStringTrimmed(SQLRowAccessor r, String field) {
99
        String result = r.getString(field);
100
        if (result == null)
101
            return "";
102
        return result.trim();
103
    }
104
 
67 ilm 105
    public static void register() {
182 ilm 106
        SpreadSheetCellValueProviderManager.put("address.customer.full", new AdresseFullClientValueProvider(ADRESSE_PRINCIPALE, false, false));
107
        SpreadSheetCellValueProviderManager.put("address.customer.invoice.full", new AdresseFullClientValueProvider(ADRESSE_FACTURATION, false, false));
108
        SpreadSheetCellValueProviderManager.put("address.customer.shipment.full", new AdresseFullClientValueProvider(ADRESSE_LIVRAISON, false, false));
109
        SpreadSheetCellValueProviderManager.put("address.customer.full.nocountry", new AdresseFullClientValueProvider(ADRESSE_PRINCIPALE, false, true));
110
        SpreadSheetCellValueProviderManager.put("address.customer.invoice.full.nocountry", new AdresseFullClientValueProvider(ADRESSE_FACTURATION, false, true));
111
        SpreadSheetCellValueProviderManager.put("address.customer.shipment.full.nocountry", new AdresseFullClientValueProvider(ADRESSE_LIVRAISON, false, true));
112
        SpreadSheetCellValueProviderManager.put("address.customer.full.withname", new AdresseFullClientValueProvider(ADRESSE_PRINCIPALE, true, false));
113
        SpreadSheetCellValueProviderManager.put("address.customer.invoice.full.withname", new AdresseFullClientValueProvider(ADRESSE_FACTURATION, true, false));
114
        SpreadSheetCellValueProviderManager.put("address.customer.shipment.full.withname", new AdresseFullClientValueProvider(ADRESSE_LIVRAISON, true, false));
115
        SpreadSheetCellValueProviderManager.put("address.customer.full.withname.nocountry", new AdresseFullClientValueProvider(ADRESSE_PRINCIPALE, true, true));
116
        SpreadSheetCellValueProviderManager.put("address.customer.invoice.full.withname.nocountry", new AdresseFullClientValueProvider(ADRESSE_FACTURATION, true, true));
117
        SpreadSheetCellValueProviderManager.put("address.customer.shipment.full.withname.nocountry", new AdresseFullClientValueProvider(ADRESSE_LIVRAISON, true, true));
67 ilm 118
    }
119
}