80 |
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.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 |
|
|
|
27 |
private final boolean shortName;
|
|
|
28 |
|
83 |
ilm |
29 |
private static enum Type {
|
|
|
30 |
NORMAL, SHIPMENT
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
private final Type type;
|
|
|
34 |
|
|
|
35 |
private FormatedGlobalQtyTotalProvider(Type t, boolean shortName) {
|
80 |
ilm |
36 |
this.shortName = shortName;
|
83 |
ilm |
37 |
this.type = t;
|
80 |
ilm |
38 |
}
|
|
|
39 |
|
|
|
40 |
public Object getValue(SpreadSheetCellValueContext context) {
|
|
|
41 |
final SQLRowAccessor row = context.getRow();
|
|
|
42 |
final BigDecimal pv = row.getBigDecimal("PV_HT");
|
|
|
43 |
if (pv.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
44 |
return null;
|
|
|
45 |
}
|
|
|
46 |
|
83 |
ilm |
47 |
final int qte = row.getInt(this.type == Type.NORMAL ? "QTE" : "QTE_LIVREE");
|
80 |
ilm |
48 |
|
|
|
49 |
if (row.getInt("ID_UNITE_VENTE") == UniteVenteArticleSQLElement.A_LA_PIECE) {
|
|
|
50 |
return String.valueOf(qte);
|
|
|
51 |
}
|
|
|
52 |
String result = "";
|
83 |
ilm |
53 |
if (qte > 0) {
|
|
|
54 |
if (qte > 1) {
|
|
|
55 |
result += qte + " x ";
|
|
|
56 |
}
|
|
|
57 |
final BigDecimal qteUV = row.getBigDecimal("QTE_UNITAIRE");
|
|
|
58 |
|
|
|
59 |
result += NumericFormat.getQtyDecimalFormat().format(qteUV);
|
|
|
60 |
final SQLRowAccessor rMode = row.getForeign("ID_UNITE_VENTE");
|
|
|
61 |
result += " " + ((this.shortName) ? rMode.getString("CODE") : rMode.getString("NOM"));
|
|
|
62 |
// 3 x 5.5 meters
|
|
|
63 |
// 1 x 6.3 meters -> 6.3 meters
|
80 |
ilm |
64 |
}
|
|
|
65 |
return result;
|
|
|
66 |
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
public static void register() {
|
83 |
ilm |
70 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.short", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true));
|
|
|
71 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit", new FormatedGlobalQtyTotalProvider(Type.NORMAL, false));
|
|
|
72 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.deliver.short", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, true));
|
|
|
73 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.deliver", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, false));
|
80 |
ilm |
74 |
}
|
|
|
75 |
}
|