80 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
80 |
ilm |
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.core.common.ui.NumericFormat;
|
|
|
17 |
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement;
|
|
|
18 |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext;
|
|
|
19 |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProvider;
|
|
|
20 |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager;
|
|
|
21 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
22 |
|
|
|
23 |
import java.math.BigDecimal;
|
|
|
24 |
|
|
|
25 |
public class FormatedGlobalQtyTotalProvider implements SpreadSheetCellValueProvider {
|
|
|
26 |
|
132 |
ilm |
27 |
private final boolean shortName, alwaysShowOnZeroQty, pieceName;
|
80 |
ilm |
28 |
|
180 |
ilm |
29 |
public static enum Type {
|
182 |
ilm |
30 |
NORMAL, SHIPMENT, REMAIND
|
83 |
ilm |
31 |
}
|
|
|
32 |
|
180 |
ilm |
33 |
public final Type type;
|
83 |
ilm |
34 |
|
|
|
35 |
private FormatedGlobalQtyTotalProvider(Type t, boolean shortName) {
|
132 |
ilm |
36 |
this(t, shortName, false, false);
|
93 |
ilm |
37 |
}
|
|
|
38 |
|
132 |
ilm |
39 |
private FormatedGlobalQtyTotalProvider(Type t, boolean shortName, boolean alwaysShowOnZeroQty, boolean withPieceName) {
|
80 |
ilm |
40 |
this.shortName = shortName;
|
83 |
ilm |
41 |
this.type = t;
|
93 |
ilm |
42 |
this.alwaysShowOnZeroQty = alwaysShowOnZeroQty;
|
132 |
ilm |
43 |
this.pieceName = withPieceName;
|
80 |
ilm |
44 |
}
|
|
|
45 |
|
185 |
ilm |
46 |
private final BigDecimal cent = new BigDecimal(100);
|
|
|
47 |
|
80 |
ilm |
48 |
public Object getValue(SpreadSheetCellValueContext context) {
|
|
|
49 |
final SQLRowAccessor row = context.getRow();
|
|
|
50 |
final BigDecimal pv = row.getBigDecimal("PV_HT");
|
185 |
ilm |
51 |
final BigDecimal pR = row.getBigDecimal("POURCENT_REMISE");
|
|
|
52 |
if (!this.alwaysShowOnZeroQty && pv != null && pv.compareTo(BigDecimal.ZERO) == 0 && (pR == null || pR.compareTo(cent) != 0)) {
|
80 |
ilm |
53 |
return null;
|
|
|
54 |
}
|
|
|
55 |
|
182 |
ilm |
56 |
final String field;
|
|
|
57 |
if (this.type == Type.NORMAL) {
|
|
|
58 |
field = "QTE";
|
|
|
59 |
} else if (row.getTable().contains("QTE_LIVREE")) {
|
|
|
60 |
field = "QTE_LIVREE";
|
|
|
61 |
} else if (row.getTable().contains("QTE_ORIGINE")) {
|
|
|
62 |
field = "QTE_ORIGINE";
|
|
|
63 |
} else {
|
|
|
64 |
return null;
|
|
|
65 |
}
|
93 |
ilm |
66 |
if (row.getObject(field) == null) {
|
|
|
67 |
return null;
|
|
|
68 |
}
|
80 |
ilm |
69 |
|
182 |
ilm |
70 |
int qte = row.getInt(field);
|
|
|
71 |
if (this.type == Type.REMAIND) {
|
|
|
72 |
if (row.getObject("QTE") != null) {
|
|
|
73 |
if (field.equalsIgnoreCase("QTE_ORIGINE")) {
|
|
|
74 |
qte = qte - row.getInt("QTE");
|
|
|
75 |
} else {
|
|
|
76 |
qte = row.getInt("QTE") - qte;
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
}
|
93 |
ilm |
80 |
|
132 |
ilm |
81 |
if (!this.pieceName && row.getInt("ID_UNITE_VENTE") == UniteVenteArticleSQLElement.A_LA_PIECE) {
|
80 |
ilm |
82 |
return String.valueOf(qte);
|
|
|
83 |
}
|
|
|
84 |
String result = "";
|
180 |
ilm |
85 |
if (this.alwaysShowOnZeroQty || qte != 0) {
|
|
|
86 |
result += qte + " x ";
|
83 |
ilm |
87 |
final BigDecimal qteUV = row.getBigDecimal("QTE_UNITAIRE");
|
|
|
88 |
|
|
|
89 |
result += NumericFormat.getQtyDecimalFormat().format(qteUV);
|
|
|
90 |
final SQLRowAccessor rMode = row.getForeign("ID_UNITE_VENTE");
|
|
|
91 |
result += " " + ((this.shortName) ? rMode.getString("CODE") : rMode.getString("NOM"));
|
|
|
92 |
// 3 x 5.5 meters
|
|
|
93 |
// 1 x 6.3 meters -> 6.3 meters
|
80 |
ilm |
94 |
}
|
|
|
95 |
return result;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
public static void register() {
|
132 |
ilm |
99 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.short.with.quantity", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true, true, false));
|
83 |
ilm |
100 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.short", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true));
|
|
|
101 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit", new FormatedGlobalQtyTotalProvider(Type.NORMAL, false));
|
|
|
102 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.deliver.short", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, true));
|
|
|
103 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.deliver", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, false));
|
180 |
ilm |
104 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.deliver.short.with.quantity", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, true, true, true));
|
182 |
ilm |
105 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.remainder.short", new FormatedGlobalQtyTotalProvider(Type.REMAIND, true));
|
|
|
106 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.remainder", new FormatedGlobalQtyTotalProvider(Type.REMAIND, false));
|
|
|
107 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.remainder.short.with.quantity", new FormatedGlobalQtyTotalProvider(Type.REMAIND, true, true, true));
|
132 |
ilm |
108 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.short.with.quantity", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true, true, true));
|
|
|
109 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.short", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true, false, true));
|
|
|
110 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed", new FormatedGlobalQtyTotalProvider(Type.NORMAL, false, false, true));
|
|
|
111 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.deliver.short", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, true, false, true));
|
|
|
112 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.deliver", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, false, false, true));
|
182 |
ilm |
113 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.remainder.short", new FormatedGlobalQtyTotalProvider(Type.REMAIND, true, false, true));
|
|
|
114 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.remainder", new FormatedGlobalQtyTotalProvider(Type.REMAIND, false, false, true));
|
80 |
ilm |
115 |
}
|
|
|
116 |
}
|