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