63 |
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.
|
63 |
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 |
|
182 |
ilm |
16 |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
|
63 |
ilm |
17 |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext;
|
|
|
18 |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager;
|
|
|
19 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
90 |
ilm |
20 |
import org.openconcerto.utils.DecimalUtils;
|
63 |
ilm |
21 |
|
|
|
22 |
import java.math.BigDecimal;
|
73 |
ilm |
23 |
import java.math.RoundingMode;
|
63 |
ilm |
24 |
|
|
|
25 |
public class PrixUnitaireRemiseProvider extends UserInitialsValueProvider {
|
|
|
26 |
|
149 |
ilm |
27 |
public static int UNITAIRE_REMISE = 0;
|
|
|
28 |
public static int TOTAL_NON_ACOMPTE = 1;
|
182 |
ilm |
29 |
public static int UNITAIRE_REMISE_TTC = 2;
|
|
|
30 |
public static int UNITAIRE_TTC = 3;
|
149 |
ilm |
31 |
public final int type;
|
|
|
32 |
|
|
|
33 |
public PrixUnitaireRemiseProvider(int t) {
|
|
|
34 |
this.type = t;
|
|
|
35 |
}
|
|
|
36 |
|
63 |
ilm |
37 |
@Override
|
|
|
38 |
public Object getValue(SpreadSheetCellValueContext context) {
|
|
|
39 |
SQLRowAccessor row = context.getRow();
|
182 |
ilm |
40 |
if (this.type == UNITAIRE_REMISE || this.type == UNITAIRE_REMISE_TTC) {
|
|
|
41 |
return getPrixUnitaire(row, true);
|
|
|
42 |
} else if (this.type == UNITAIRE_TTC) {
|
|
|
43 |
return getPrixUnitaire(row, false);
|
149 |
ilm |
44 |
} else {
|
|
|
45 |
return getPrixTotalOrigin(row);
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public Object getPrixTotalOrigin(SQLRowAccessor row) {
|
67 |
ilm |
50 |
final BigDecimal pv = row.getBigDecimal("PV_HT");
|
182 |
ilm |
51 |
if (pv == null) {
|
|
|
52 |
return null;
|
|
|
53 |
}
|
73 |
ilm |
54 |
BigDecimal remise = (BigDecimal) row.getObject("POURCENT_REMISE");
|
182 |
ilm |
55 |
if (pv == null || remise == null) {
|
73 |
ilm |
56 |
remise = BigDecimal.ZERO;
|
|
|
57 |
}
|
67 |
ilm |
58 |
BigDecimal acompte = BigDecimal.ONE;
|
149 |
ilm |
59 |
|
|
|
60 |
BigDecimal result = BigDecimal.ONE.subtract(remise.movePointLeft(2)).multiply(pv, DecimalUtils.HIGH_PRECISION).multiply(acompte, DecimalUtils.HIGH_PRECISION);
|
|
|
61 |
|
|
|
62 |
return result.multiply(row.getBigDecimal("QTE_UNITAIRE")).multiply(new BigDecimal(row.getInt("QTE"))).setScale(2, RoundingMode.HALF_UP);
|
|
|
63 |
}
|
|
|
64 |
|
182 |
ilm |
65 |
public Object getPrixUnitaire(SQLRowAccessor row, boolean withRemise) {
|
149 |
ilm |
66 |
final BigDecimal pv = row.getBigDecimal("PV_HT");
|
182 |
ilm |
67 |
if (pv == null) {
|
|
|
68 |
return null;
|
|
|
69 |
}
|
149 |
ilm |
70 |
BigDecimal remise = (BigDecimal) row.getObject("POURCENT_REMISE");
|
182 |
ilm |
71 |
if (remise == null || !withRemise) {
|
149 |
ilm |
72 |
remise = BigDecimal.ZERO;
|
|
|
73 |
}
|
|
|
74 |
BigDecimal acompte = BigDecimal.ONE;
|
73 |
ilm |
75 |
if (row.getTable().contains("POURCENT_ACOMPTE") && row.getObject("POURCENT_ACOMPTE") != null) {
|
67 |
ilm |
76 |
acompte = ((BigDecimal) row.getObject("POURCENT_ACOMPTE")).movePointLeft(2);
|
|
|
77 |
}
|
90 |
ilm |
78 |
BigDecimal result = BigDecimal.ONE.subtract(remise.movePointLeft(2)).multiply(pv, DecimalUtils.HIGH_PRECISION).multiply(acompte, DecimalUtils.HIGH_PRECISION);
|
67 |
ilm |
79 |
|
182 |
ilm |
80 |
if (this.type == UNITAIRE_REMISE_TTC) {
|
|
|
81 |
float t = TaxeCache.getCache().getTauxFromId(row.getForeignID("ID_TAXE"));
|
|
|
82 |
result = result.multiply(new BigDecimal(t).movePointLeft(2).add(BigDecimal.ONE));
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
final BigDecimal setScale = result.setScale(2, RoundingMode.HALF_UP);
|
|
|
86 |
return setScale;
|
63 |
ilm |
87 |
}
|
|
|
88 |
|
|
|
89 |
public static void register() {
|
182 |
ilm |
90 |
SpreadSheetCellValueProviderManager.put("PrixUnitaireTTC", new PrixUnitaireRemiseProvider(UNITAIRE_TTC));
|
149 |
ilm |
91 |
SpreadSheetCellValueProviderManager.put("PrixUnitaireRemise", new PrixUnitaireRemiseProvider(UNITAIRE_REMISE));
|
182 |
ilm |
92 |
SpreadSheetCellValueProviderManager.put("PrixUnitaireRemiseTTC", new PrixUnitaireRemiseProvider(UNITAIRE_REMISE_TTC));
|
149 |
ilm |
93 |
SpreadSheetCellValueProviderManager.put("PrixTotalSansAcompte", new PrixUnitaireRemiseProvider(TOTAL_NON_ACOMPTE));
|
63 |
ilm |
94 |
}
|
|
|
95 |
}
|