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 MergedGlobalQtyTotalProvider implements SpreadSheetCellValueProvider {
|
|
|
26 |
|
|
|
27 |
private final boolean shortName;
|
132 |
ilm |
28 |
private final boolean pieceName;
|
80 |
ilm |
29 |
|
132 |
ilm |
30 |
public MergedGlobalQtyTotalProvider(boolean shortName, boolean pieceName) {
|
80 |
ilm |
31 |
this.shortName = shortName;
|
132 |
ilm |
32 |
this.pieceName = pieceName;
|
80 |
ilm |
33 |
}
|
|
|
34 |
|
|
|
35 |
public Object getValue(SpreadSheetCellValueContext context) {
|
|
|
36 |
final SQLRowAccessor row = context.getRow();
|
182 |
ilm |
37 |
// FIXME pb si on est dans achat avec le check PV_HT
|
80 |
ilm |
38 |
final BigDecimal pv = row.getBigDecimal("PV_HT");
|
182 |
ilm |
39 |
if (pv != null && pv.compareTo(BigDecimal.ZERO) == 0) {
|
80 |
ilm |
40 |
return null;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
final int qte = row.getInt("QTE");
|
132 |
ilm |
44 |
if (!pieceName && row.getInt("ID_UNITE_VENTE") == UniteVenteArticleSQLElement.A_LA_PIECE) {
|
80 |
ilm |
45 |
return String.valueOf(qte);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
final BigDecimal qteUV = row.getBigDecimal("QTE_UNITAIRE");
|
|
|
49 |
final BigDecimal mergedQty = qteUV.multiply(new BigDecimal(qte));
|
|
|
50 |
String result = NumericFormat.getQtyDecimalFormat().format(mergedQty);
|
|
|
51 |
|
|
|
52 |
final SQLRowAccessor rMode = row.getForeign("ID_UNITE_VENTE");
|
|
|
53 |
result += " " + ((this.shortName) ? rMode.getString("CODE") : rMode.getString("NOM"));
|
|
|
54 |
// 3 x 5.5 meters -> 16.5 meters
|
|
|
55 |
return result;
|
|
|
56 |
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
public static void register() {
|
132 |
ilm |
60 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.merged", new MergedGlobalQtyTotalProvider(false, false));
|
|
|
61 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.merged.short", new MergedGlobalQtyTotalProvider(true, false));
|
|
|
62 |
|
|
|
63 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.merged", new MergedGlobalQtyTotalProvider(false, true));
|
|
|
64 |
SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.merged.short", new MergedGlobalQtyTotalProvider(true, true));
|
80 |
ilm |
65 |
}
|
|
|
66 |
|
|
|
67 |
}
|