1 |
/*
|
1 |
/*
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
3 |
*
|
3 |
*
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
5 |
*
|
5 |
*
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
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
|
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
|
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.
|
9 |
* language governing permissions and limitations under the License.
|
10 |
*
|
10 |
*
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
12 |
*/
|
12 |
*/
|
13 |
|
13 |
|
14 |
package org.openconcerto.erp.generationDoc.provider;
|
14 |
package org.openconcerto.erp.generationDoc.provider;
|
15 |
|
15 |
|
16 |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext;
|
16 |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext;
|
17 |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager;
|
17 |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager;
|
18 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
18 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
19 |
|
19 |
|
20 |
public class AdresseFullClientValueProvider extends AdresseClientProvider {
|
20 |
public class AdresseFullClientValueProvider extends AdresseClientProvider {
|
21 |
|
21 |
|
22 |
private final int type;
|
22 |
private final int type;
|
23 |
private final boolean withName;
|
23 |
private final boolean withName;
|
- |
|
24 |
private final boolean noCountry;
|
24 |
|
25 |
|
25 |
public AdresseFullClientValueProvider(int type, boolean withName) {
|
26 |
public AdresseFullClientValueProvider(int type, boolean withName, boolean noCountry) {
|
26 |
this.type = type;
|
27 |
this.type = type;
|
27 |
this.withName = withName;
|
28 |
this.withName = withName;
|
- |
|
29 |
this.noCountry = noCountry;
|
28 |
}
|
30 |
}
|
29 |
|
31 |
|
30 |
@Override
|
32 |
@Override
|
31 |
public Object getValue(SpreadSheetCellValueContext context) {
|
33 |
public Object getValue(SpreadSheetCellValueContext context) {
|
32 |
final SQLRowAccessor r = getAdresse(context.getRow(), this.type);
|
34 |
final SQLRowAccessor r = getAdresse(context.getRow(), this.type);
|
33 |
String result = "";
|
35 |
String result = "";
|
34 |
if (this.withName) {
|
36 |
if (this.withName) {
|
35 |
result = context.getRow().getForeign("ID_CLIENT").getString("NOM") + "\n";
|
37 |
result = context.getRow().getForeign("ID_CLIENT").getString("NOM") + "\n\n";
|
36 |
}
|
38 |
}
|
37 |
result = getFormattedAddress(r, result);
|
39 |
result = getFormattedAddress(r, result, !this.noCountry);
|
38 |
|
40 |
|
39 |
return result;
|
41 |
return result;
|
40 |
}
|
42 |
}
|
41 |
|
43 |
|
42 |
public static String getFormattedAddress(final SQLRowAccessor rAddress, String prefix) {
|
44 |
public static String getFormattedAddress(final SQLRowAccessor rAddress, String prefix) {
|
- |
|
45 |
return getFormattedAddress(rAddress, prefix, true);
|
- |
|
46 |
}
|
- |
|
47 |
|
- |
|
48 |
public static String getFormattedAddress(final SQLRowAccessor rAddress, String prefix, boolean withCountry) {
|
43 |
String result = prefix;
|
49 |
String result = prefix;
|
44 |
if (getStringTrimmed(rAddress, "LIBELLE").length() > 0) {
|
50 |
boolean notEmptyLib = getStringTrimmed(rAddress, "LIBELLE").length() > 0;
|
- |
|
51 |
if (notEmptyLib) {
|
45 |
result = getStringTrimmed(rAddress, "LIBELLE") + "\n";
|
52 |
result = getStringTrimmed(rAddress, "LIBELLE") + "\n";
|
46 |
}
|
53 |
}
|
47 |
if (getStringTrimmed(rAddress, "DEST").length() > 0) {
|
54 |
boolean notEmptyDest = getStringTrimmed(rAddress, "DEST").length() > 0;
|
- |
|
55 |
if (notEmptyDest) {
|
48 |
result = getStringTrimmed(rAddress, "DEST") + "\n";
|
56 |
result = getStringTrimmed(rAddress, "DEST") + "\n";
|
49 |
}
|
57 |
}
|
50 |
if (getStringTrimmed(rAddress, "RUE").length() > 0) {
|
58 |
boolean notEmptyRue = getStringTrimmed(rAddress, "RUE").length() > 0;
|
- |
|
59 |
if (notEmptyRue) {
|
51 |
result += getStringTrimmed(rAddress, "RUE") + "\n";
|
60 |
result += getStringTrimmed(rAddress, "RUE") + "\n";
|
52 |
}
|
61 |
}
|
53 |
result += "\n" + getStringTrimmed(rAddress, "CODE_POSTAL");
|
62 |
result += notEmptyDest && notEmptyLib && notEmptyLib ? ("\n" + getStringTrimmed(rAddress, "CODE_POSTAL")) : getStringTrimmed(rAddress, "CODE_POSTAL");
|
54 |
result += " ";
|
63 |
result += " ";
|
55 |
if (rAddress.getTable().contains("DISTRICT")) {
|
64 |
if (rAddress.getTable().contains("DISTRICT")) {
|
56 |
result += getStringTrimmed(rAddress, "DISTRICT") + " ";
|
65 |
result += getStringTrimmed(rAddress, "DISTRICT") + " ";
|
57 |
}
|
66 |
}
|
58 |
result += getStringTrimmed(rAddress, "VILLE");
|
67 |
result += getStringTrimmed(rAddress, "VILLE");
|
59 |
if (rAddress.getBoolean("HAS_CEDEX")) {
|
68 |
if (rAddress.getBoolean("HAS_CEDEX")) {
|
60 |
result += " Cedex";
|
69 |
result += " Cedex";
|
61 |
String cedex = getStringTrimmed(rAddress, "CEDEX");
|
70 |
String cedex = getStringTrimmed(rAddress, "CEDEX");
|
62 |
if (cedex.length() > 0) {
|
71 |
if (cedex.length() > 0) {
|
63 |
result += " " + cedex;
|
72 |
result += " " + cedex;
|
64 |
}
|
73 |
}
|
65 |
}
|
74 |
}
|
66 |
if (rAddress.getTable().contains("PROVINCE")) {
|
75 |
if (rAddress.getTable().contains("PROVINCE")) {
|
- |
|
76 |
String province = getStringTrimmed(rAddress, "PROVINCE");
|
- |
|
77 |
boolean department = rAddress.getTable().contains("DEPARTEMENT");
|
- |
|
78 |
if (province.length() > 0 || (department && getStringTrimmed(rAddress, "DEPARTEMENT").length() > 0)) {
|
67 |
result += "\n";
|
79 |
result += "\n";
|
- |
|
80 |
}
|
68 |
if (getStringTrimmed(rAddress, "PROVINCE").length() > 0) {
|
81 |
if (province.length() > 0) {
|
- |
|
82 |
|
69 |
result += getStringTrimmed(rAddress, ("PROVINCE")) + " ";
|
83 |
result += getStringTrimmed(rAddress, ("PROVINCE")) + " ";
|
70 |
}
|
84 |
}
|
71 |
|
85 |
|
72 |
if (rAddress.getTable().contains("DEPARTEMENT")) {
|
86 |
if (department && getStringTrimmed(rAddress, "DEPARTEMENT").length() > 0) {
|
- |
|
87 |
|
73 |
result += getStringTrimmed(rAddress, "DEPARTEMENT");
|
88 |
result += getStringTrimmed(rAddress, "DEPARTEMENT");
|
74 |
}
|
89 |
}
|
75 |
}
|
90 |
}
|
76 |
|
91 |
|
77 |
if (getStringTrimmed(rAddress, "PAYS").length() > 0) {
|
92 |
if (withCountry && getStringTrimmed(rAddress, "PAYS").length() > 0) {
|
78 |
result += "\n" + getStringTrimmed(rAddress, "PAYS");
|
93 |
result += "\n" + getStringTrimmed(rAddress, "PAYS");
|
79 |
}
|
94 |
}
|
80 |
return result;
|
95 |
return result;
|
81 |
}
|
96 |
}
|
82 |
|
97 |
|
83 |
public static String getStringTrimmed(SQLRowAccessor r, String field) {
|
98 |
public static String getStringTrimmed(SQLRowAccessor r, String field) {
|
84 |
String result = r.getString(field);
|
99 |
String result = r.getString(field);
|
85 |
if (result == null)
|
100 |
if (result == null)
|
86 |
return "";
|
101 |
return "";
|
87 |
return result.trim();
|
102 |
return result.trim();
|
88 |
}
|
103 |
}
|
89 |
|
104 |
|
90 |
public static void register() {
|
105 |
public static void register() {
|
91 |
SpreadSheetCellValueProviderManager.put("address.customer.full", new AdresseFullClientValueProvider(ADRESSE_PRINCIPALE, false));
|
106 |
SpreadSheetCellValueProviderManager.put("address.customer.full", new AdresseFullClientValueProvider(ADRESSE_PRINCIPALE, false, false));
|
92 |
SpreadSheetCellValueProviderManager.put("address.customer.invoice.full", new AdresseFullClientValueProvider(ADRESSE_FACTURATION, false));
|
107 |
SpreadSheetCellValueProviderManager.put("address.customer.invoice.full", new AdresseFullClientValueProvider(ADRESSE_FACTURATION, false, false));
|
93 |
SpreadSheetCellValueProviderManager.put("address.customer.shipment.full", new AdresseFullClientValueProvider(ADRESSE_LIVRAISON, 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));
|
94 |
SpreadSheetCellValueProviderManager.put("address.customer.full.withname", new AdresseFullClientValueProvider(ADRESSE_PRINCIPALE, true));
|
112 |
SpreadSheetCellValueProviderManager.put("address.customer.full.withname", new AdresseFullClientValueProvider(ADRESSE_PRINCIPALE, true, false));
|
95 |
SpreadSheetCellValueProviderManager.put("address.customer.invoice.full.withname", new AdresseFullClientValueProvider(ADRESSE_FACTURATION, true));
|
113 |
SpreadSheetCellValueProviderManager.put("address.customer.invoice.full.withname", new AdresseFullClientValueProvider(ADRESSE_FACTURATION, true, false));
|
96 |
SpreadSheetCellValueProviderManager.put("address.customer.shipment.full.withname", new AdresseFullClientValueProvider(ADRESSE_LIVRAISON, true));
|
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));
|
97 |
}
|
118 |
}
|
98 |
}
|
119 |
}
|