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