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 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.core.common.ui;
|
14 |
package org.openconcerto.erp.core.common.ui;
|
15 |
|
15 |
|
16 |
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
|
16 |
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
|
17 |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
|
17 |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
|
18 |
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
|
18 |
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
|
19 |
import org.openconcerto.sql.Configuration;
|
19 |
import org.openconcerto.sql.Configuration;
|
20 |
import org.openconcerto.sql.model.SQLBackgroundTableCache;
|
20 |
import org.openconcerto.sql.model.SQLBackgroundTableCache;
|
21 |
import org.openconcerto.sql.model.SQLBackgroundTableCacheItem;
|
21 |
import org.openconcerto.sql.model.SQLBackgroundTableCacheItem;
|
22 |
import org.openconcerto.sql.model.SQLRow;
|
22 |
import org.openconcerto.sql.model.SQLRow;
|
23 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
23 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
24 |
import org.openconcerto.sql.model.SQLTable;
|
24 |
import org.openconcerto.sql.model.SQLTable;
|
25 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
25 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
26 |
import org.openconcerto.utils.DecimalUtils;
|
26 |
import org.openconcerto.utils.DecimalUtils;
|
27 |
import org.openconcerto.utils.Tuple2;
|
27 |
import org.openconcerto.utils.Tuple2;
|
28 |
|
28 |
|
29 |
import java.math.BigDecimal;
|
29 |
import java.math.BigDecimal;
|
30 |
import java.math.RoundingMode;
|
30 |
import java.math.RoundingMode;
|
31 |
import java.util.Collection;
|
31 |
import java.util.Collection;
|
32 |
import java.util.HashMap;
|
32 |
import java.util.HashMap;
|
33 |
import java.util.HashSet;
|
33 |
import java.util.HashSet;
|
34 |
import java.util.Map;
|
34 |
import java.util.Map;
|
35 |
import java.util.Set;
|
35 |
import java.util.Set;
|
36 |
|
36 |
|
37 |
public class TotalCalculator {
|
37 |
public class TotalCalculator {
|
38 |
|
38 |
|
39 |
private static String FIELD_SERVICE = "SERVICE";
|
39 |
private static String FIELD_SERVICE = "SERVICE";
|
40 |
private static String FIELD_POIDS = "T_POIDS";
|
40 |
private static String FIELD_POIDS = "T_POIDS";
|
41 |
private final String fieldHT, fieldHA, fieldDevise;
|
41 |
private final String fieldHT, fieldHA, fieldDevise;
|
42 |
private boolean imputEcart = true;
|
42 |
private boolean imputEcart = true;
|
43 |
private SQLRowAccessor rowDefaultCptProduit, rowDefaultCptService, rowDefaultCptTVACollecte, rowDefaultCptTVADeductible, rowDefaultCptAchat;
|
43 |
private SQLRowAccessor rowDefaultCptProduit, rowDefaultCptService, rowDefaultCptTVACollecte, rowDefaultCptTVADeductible, rowDefaultCptAchat;
|
44 |
|
44 |
|
45 |
private final SQLRowAccessor rowCatComptable;
|
45 |
private final SQLRowAccessor rowCatComptable;
|
46 |
|
46 |
|
47 |
private SQLRowAccessor rowDefaultCptProduitStandard;
|
47 |
private SQLRowAccessor rowDefaultCptProduitStandard;
|
48 |
|
48 |
|
49 |
private double totalPoids;
|
49 |
private double totalPoids;
|
50 |
|
50 |
|
51 |
private BigDecimal totalDevise, totalDeviseSel;
|
51 |
private BigDecimal totalDevise, totalDeviseSel;
|
52 |
private BigDecimal totalHA, totalHASel;
|
52 |
private BigDecimal totalHA, totalHASel;
|
53 |
private BigDecimal totalEco, totalEcoSel;
|
53 |
private BigDecimal totalEco, totalEcoSel;
|
54 |
private BigDecimal totalService, totalServiceSel;
|
54 |
private BigDecimal totalService, totalServiceSel;
|
55 |
private BigDecimal totalHTSansFActurable, totalTTC, totalTTCSel;
|
55 |
private BigDecimal totalHTSansFActurable, totalTTC, totalTTCSel;
|
56 |
private long remiseHT, remiseRestante;
|
56 |
private long remiseHT, remiseRestante;
|
57 |
private final boolean achat;
|
57 |
private final boolean achat;
|
58 |
|
58 |
|
59 |
// Total des HT par comptes
|
59 |
// Total des HT par comptes
|
60 |
private Map<SQLRowAccessor, BigDecimal> mapHt = new HashMap<SQLRowAccessor, BigDecimal>();
|
60 |
private Map<SQLRowAccessor, BigDecimal> mapHt = new HashMap<SQLRowAccessor, BigDecimal>();
|
61 |
private Map<SQLRowAccessor, BigDecimal> mapHtSel = new HashMap<SQLRowAccessor, BigDecimal>();
|
61 |
private Map<SQLRowAccessor, BigDecimal> mapHtSel = new HashMap<SQLRowAccessor, BigDecimal>();
|
62 |
|
62 |
|
63 |
// Total des TVA par comptes
|
63 |
// Total des TVA par comptes
|
64 |
private Map<SQLRowAccessor, BigDecimal> mapHtTVA = new HashMap<SQLRowAccessor, BigDecimal>();
|
64 |
private Map<SQLRowAccessor, BigDecimal> mapHtTVA = new HashMap<SQLRowAccessor, BigDecimal>();
|
65 |
private Map<SQLRowAccessor, Map<SQLRowAccessor, BigDecimal>> mapHtTaxeCompl = new HashMap<SQLRowAccessor, Map<SQLRowAccessor, BigDecimal>>();
|
65 |
private Map<SQLRowAccessor, Map<SQLRowAccessor, BigDecimal>> mapHtTaxeCompl = new HashMap<SQLRowAccessor, Map<SQLRowAccessor, BigDecimal>>();
|
66 |
private Map<SQLRowAccessor, BigDecimal> mapHtTVAIntra = new HashMap<SQLRowAccessor, BigDecimal>();
|
66 |
private Map<SQLRowAccessor, BigDecimal> mapHtTVAIntra = new HashMap<SQLRowAccessor, BigDecimal>();
|
67 |
private Map<SQLRowAccessor, BigDecimal> mapHtTVASel = new HashMap<SQLRowAccessor, BigDecimal>();
|
67 |
private Map<SQLRowAccessor, BigDecimal> mapHtTVASel = new HashMap<SQLRowAccessor, BigDecimal>();
|
68 |
|
68 |
|
69 |
// Total HT par TVA
|
69 |
// Total HT par TVA
|
70 |
private Map<SQLRowAccessor, Tuple2<BigDecimal, BigDecimal>> mapHtTVARowTaux = new HashMap<SQLRowAccessor, Tuple2<BigDecimal, BigDecimal>>();
|
70 |
private Map<SQLRowAccessor, Tuple2<BigDecimal, BigDecimal>> mapHtTVARowTaux = new HashMap<SQLRowAccessor, Tuple2<BigDecimal, BigDecimal>>();
|
71 |
private int[] selectedRows;
|
71 |
private int[] selectedRows;
|
72 |
|
72 |
|
73 |
private Boolean bServiceActive;
|
73 |
private Boolean bServiceActive;
|
74 |
private BigDecimal totalHTAvantRemise;
|
74 |
private BigDecimal totalHTAvantRemise;
|
75 |
private boolean intraComm = false;
|
75 |
private boolean intraComm = false;
|
76 |
|
76 |
|
77 |
public TotalCalculator(String fieldHA, String fieldHT, String fieldDeviseTotal, SQLRowAccessor rowCatComptable) {
|
77 |
public TotalCalculator(String fieldHA, String fieldHT, String fieldDeviseTotal, SQLRowAccessor rowCatComptable) {
|
78 |
this(fieldHA, fieldHT, fieldDeviseTotal, false, null, rowCatComptable);
|
78 |
this(fieldHA, fieldHT, fieldDeviseTotal, false, null, rowCatComptable);
|
79 |
}
|
79 |
}
|
80 |
|
80 |
|
81 |
public void setRowDefaultCptService(SQLRowAccessor rowDefaultCptService) {
|
81 |
public void setRowDefaultCptService(SQLRowAccessor rowDefaultCptService) {
|
82 |
this.rowDefaultCptService = rowDefaultCptService;
|
82 |
this.rowDefaultCptService = rowDefaultCptService;
|
83 |
}
|
83 |
}
|
84 |
|
84 |
|
85 |
public void setIntraComm(boolean intraComm) {
|
85 |
public void setIntraComm(boolean intraComm) {
|
86 |
this.intraComm = intraComm;
|
86 |
this.intraComm = intraComm;
|
87 |
}
|
87 |
}
|
88 |
|
88 |
|
89 |
public TotalCalculator(String fieldHA, String fieldHT, String fieldDeviseTotal, boolean achat, SQLRowAccessor defaultCompte, SQLRowAccessor rowCatComptable) {
|
89 |
public TotalCalculator(String fieldHA, String fieldHT, String fieldDeviseTotal, boolean achat, SQLRowAccessor defaultCompte, SQLRowAccessor rowCatComptable) {
|
90 |
|
90 |
|
91 |
this.achat = achat;
|
91 |
this.achat = achat;
|
92 |
initValues();
|
92 |
initValues();
|
93 |
|
93 |
|
94 |
this.fieldDevise = fieldDeviseTotal;
|
94 |
this.fieldDevise = fieldDeviseTotal;
|
95 |
this.fieldHA = fieldHA;
|
95 |
this.fieldHA = fieldHA;
|
96 |
this.fieldHT = fieldHT;
|
96 |
this.fieldHT = fieldHT;
|
97 |
final SQLTable tablePrefCompte = Configuration.getInstance().getRoot().findTable("PREFS_COMPTE");
|
97 |
final SQLTable tablePrefCompte = Configuration.getInstance().getRoot().findTable("PREFS_COMPTE");
|
98 |
final SQLBackgroundTableCacheItem cacheForTablePref = SQLBackgroundTableCache.getInstance().getCacheForTable(tablePrefCompte);
|
98 |
final SQLBackgroundTableCacheItem cacheForTablePref = SQLBackgroundTableCache.getInstance().getCacheForTable(tablePrefCompte);
|
99 |
final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(tablePrefCompte.getTable("COMPTE_PCE"));
|
99 |
final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(tablePrefCompte.getTable("COMPTE_PCE"));
|
100 |
final SQLRow rowPrefsCompte = cacheForTablePref.getRowFromId(2);
|
100 |
final SQLRow rowPrefsCompte = cacheForTablePref.getRowFromId(2);
|
101 |
|
101 |
|
102 |
SQLPreferences prefs = SQLPreferences.getMemCached(tablePrefCompte.getDBRoot());
|
102 |
SQLPreferences prefs = SQLPreferences.getMemCached(tablePrefCompte.getDBRoot());
|
103 |
this.imputEcart = prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.IMPUT_ECART, true);
|
103 |
this.imputEcart = prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.IMPUT_ECART, true);
|
104 |
|
104 |
|
105 |
// FIXME faire un fetcher pour ne pas faire 5 requetes (1 par getForeign)
|
105 |
// FIXME faire un fetcher pour ne pas faire 5 requetes (1 par getForeign)
|
106 |
// Comptes par défaut
|
106 |
// Comptes par défaut
|
107 |
this.rowDefaultCptService = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_VENTE_SERVICE"));
|
107 |
this.rowDefaultCptService = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_VENTE_SERVICE"));
|
108 |
if (this.rowDefaultCptService == null || this.rowDefaultCptService.isUndefined()) {
|
108 |
if (this.rowDefaultCptService == null || this.rowDefaultCptService.isUndefined()) {
|
109 |
try {
|
109 |
try {
|
110 |
this.rowDefaultCptService = ComptePCESQLElement.getRowComptePceDefault("VentesServices");
|
110 |
this.rowDefaultCptService = ComptePCESQLElement.getRowComptePceDefault("VentesServices");
|
111 |
} catch (Exception e) {
|
111 |
} catch (Exception e) {
|
112 |
e.printStackTrace();
|
112 |
e.printStackTrace();
|
113 |
}
|
113 |
}
|
114 |
}
|
114 |
}
|
115 |
|
115 |
|
116 |
this.rowCatComptable = rowCatComptable;
|
116 |
this.rowCatComptable = rowCatComptable;
|
117 |
|
117 |
|
118 |
if (defaultCompte == null || defaultCompte.isUndefined()) {
|
118 |
if (defaultCompte == null || defaultCompte.isUndefined()) {
|
119 |
|
119 |
|
120 |
if (rowCatComptable != null && !rowCatComptable.isUndefined() && !rowCatComptable.isForeignEmpty("ID_COMPTE_PCE_VENTE")) {
|
120 |
if (rowCatComptable != null && !rowCatComptable.isUndefined() && !rowCatComptable.isForeignEmpty("ID_COMPTE_PCE_VENTE")) {
|
121 |
this.rowDefaultCptProduit = cacheForTableCompte.getRowFromId(rowCatComptable.getForeignID("ID_COMPTE_PCE_VENTE"));
|
121 |
this.rowDefaultCptProduit = cacheForTableCompte.getRowFromId(rowCatComptable.getForeignID("ID_COMPTE_PCE_VENTE"));
|
122 |
} else {
|
122 |
} else {
|
123 |
this.rowDefaultCptProduit = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_VENTE_PRODUIT"));
|
123 |
this.rowDefaultCptProduit = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_VENTE_PRODUIT"));
|
124 |
if (this.rowDefaultCptProduit == null || this.rowDefaultCptProduit.isUndefined()) {
|
124 |
if (this.rowDefaultCptProduit == null || this.rowDefaultCptProduit.isUndefined()) {
|
125 |
try {
|
125 |
try {
|
126 |
this.rowDefaultCptProduit = ComptePCESQLElement.getRowComptePceDefault("VentesProduits");
|
126 |
this.rowDefaultCptProduit = ComptePCESQLElement.getRowComptePceDefault("VentesProduits");
|
127 |
} catch (Exception e) {
|
127 |
} catch (Exception e) {
|
128 |
e.printStackTrace();
|
128 |
e.printStackTrace();
|
129 |
}
|
129 |
}
|
130 |
}
|
130 |
}
|
131 |
}
|
131 |
}
|
132 |
} else {
|
132 |
} else {
|
133 |
this.rowDefaultCptProduit = defaultCompte;
|
133 |
this.rowDefaultCptProduit = defaultCompte;
|
134 |
}
|
134 |
}
|
135 |
this.rowDefaultCptProduitStandard = this.rowDefaultCptProduit;
|
135 |
this.rowDefaultCptProduitStandard = this.rowDefaultCptProduit;
|
136 |
|
136 |
|
137 |
this.rowDefaultCptTVACollecte = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_TVA_VENTE"));
|
137 |
this.rowDefaultCptTVACollecte = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_TVA_VENTE"));
|
138 |
if (this.rowDefaultCptTVACollecte == null || this.rowDefaultCptTVACollecte.isUndefined()) {
|
138 |
if (this.rowDefaultCptTVACollecte == null || this.rowDefaultCptTVACollecte.isUndefined()) {
|
139 |
try {
|
139 |
try {
|
140 |
this.rowDefaultCptTVACollecte = ComptePCESQLElement.getRowComptePceDefault("TVACollectee");
|
140 |
this.rowDefaultCptTVACollecte = ComptePCESQLElement.getRowComptePceDefault("TVACollectee");
|
141 |
} catch (Exception e) {
|
141 |
} catch (Exception e) {
|
142 |
e.printStackTrace();
|
142 |
e.printStackTrace();
|
143 |
}
|
143 |
}
|
144 |
}
|
144 |
}
|
145 |
|
145 |
|
146 |
this.rowDefaultCptTVADeductible = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_TVA_ACHAT"));
|
146 |
this.rowDefaultCptTVADeductible = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_TVA_ACHAT"));
|
147 |
if (this.rowDefaultCptTVADeductible == null || this.rowDefaultCptTVADeductible.isUndefined()) {
|
147 |
if (this.rowDefaultCptTVADeductible == null || this.rowDefaultCptTVADeductible.isUndefined()) {
|
148 |
try {
|
148 |
try {
|
149 |
this.rowDefaultCptTVADeductible = ComptePCESQLElement.getRowComptePceDefault("TVADeductible");
|
149 |
this.rowDefaultCptTVADeductible = ComptePCESQLElement.getRowComptePceDefault("TVADeductible");
|
150 |
} catch (Exception e) {
|
150 |
} catch (Exception e) {
|
151 |
e.printStackTrace();
|
151 |
e.printStackTrace();
|
152 |
}
|
152 |
}
|
153 |
}
|
153 |
}
|
154 |
|
154 |
|
155 |
if (defaultCompte == null || defaultCompte.isUndefined()) {
|
155 |
if (defaultCompte == null || defaultCompte.isUndefined()) {
|
156 |
if (rowCatComptable != null && !rowCatComptable.isUndefined() && !rowCatComptable.isForeignEmpty("ID_COMPTE_PCE_ACHAT")) {
|
156 |
if (rowCatComptable != null && !rowCatComptable.isUndefined() && !rowCatComptable.isForeignEmpty("ID_COMPTE_PCE_ACHAT")) {
|
157 |
this.rowDefaultCptProduit = cacheForTableCompte.getRowFromId(rowCatComptable.getForeignID("ID_COMPTE_PCE_ACHAT"));
|
157 |
this.rowDefaultCptProduit = cacheForTableCompte.getRowFromId(rowCatComptable.getForeignID("ID_COMPTE_PCE_ACHAT"));
|
158 |
} else {
|
158 |
} else {
|
159 |
this.rowDefaultCptAchat = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_ACHAT"));
|
159 |
this.rowDefaultCptAchat = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_ACHAT"));
|
160 |
if (this.rowDefaultCptAchat == null || this.rowDefaultCptAchat.isUndefined()) {
|
160 |
if (this.rowDefaultCptAchat == null || this.rowDefaultCptAchat.isUndefined()) {
|
161 |
try {
|
161 |
try {
|
162 |
this.rowDefaultCptAchat = ComptePCESQLElement.getRowComptePceDefault("Achats");
|
162 |
this.rowDefaultCptAchat = ComptePCESQLElement.getRowComptePceDefault("Achats");
|
163 |
} catch (Exception e) {
|
163 |
} catch (Exception e) {
|
164 |
e.printStackTrace();
|
164 |
e.printStackTrace();
|
165 |
}
|
165 |
}
|
166 |
}
|
166 |
}
|
167 |
}
|
167 |
}
|
168 |
} else {
|
168 |
} else {
|
169 |
this.rowDefaultCptAchat = defaultCompte;
|
169 |
this.rowDefaultCptAchat = defaultCompte;
|
170 |
}
|
170 |
}
|
171 |
|
171 |
|
172 |
}
|
172 |
}
|
173 |
|
173 |
|
174 |
public void setRowDefaultCptProduit(SQLRowAccessor rowDefaultCptProduit) {
|
174 |
public void setRowDefaultCptProduit(SQLRowAccessor rowDefaultCptProduit) {
|
175 |
this.rowDefaultCptProduit = rowDefaultCptProduit;
|
175 |
this.rowDefaultCptProduit = rowDefaultCptProduit;
|
176 |
}
|
176 |
}
|
177 |
|
177 |
|
178 |
public void retoreRowDefaultCptProduit() {
|
178 |
public void retoreRowDefaultCptProduit() {
|
179 |
this.rowDefaultCptProduit = this.rowDefaultCptProduitStandard;
|
179 |
this.rowDefaultCptProduit = this.rowDefaultCptProduitStandard;
|
180 |
}
|
180 |
}
|
181 |
|
181 |
|
182 |
/**
|
182 |
/**
|
183 |
* Définition d'une remise HT à appliquer
|
183 |
* Définition d'une remise HT à appliquer
|
184 |
*
|
184 |
*
|
185 |
* @param remiseHT montant de la remise en cents
|
185 |
* @param remiseHT montant de la remise en cents
|
186 |
* @param totalHTAvantRemise montant de la facture avant remise
|
186 |
* @param totalHTAvantRemise montant de la facture avant remise
|
187 |
*/
|
187 |
*/
|
188 |
public void setRemise(long remiseHT, BigDecimal totalHTAvantRemise) {
|
188 |
public void setRemise(long remiseHT, BigDecimal totalHTAvantRemise) {
|
189 |
this.remiseHT = remiseHT;
|
189 |
this.remiseHT = remiseHT;
|
190 |
this.remiseRestante = remiseHT;
|
190 |
this.remiseRestante = remiseHT;
|
191 |
this.totalHTAvantRemise = totalHTAvantRemise;
|
191 |
this.totalHTAvantRemise = totalHTAvantRemise;
|
192 |
}
|
192 |
}
|
193 |
|
193 |
|
194 |
public void addTVAAdjust(BigDecimal tvaFix) {
|
194 |
public void addTVAAdjust(BigDecimal tvaFix) {
|
195 |
|
195 |
|
196 |
final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(this.compteTable);
|
196 |
final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(this.compteTable);
|
197 |
|
197 |
|
198 |
SQLRowAccessor tva = TaxeCache.getCache().getFirstTaxe();
|
198 |
SQLRowAccessor tva = TaxeCache.getCache().getFirstTaxe();
|
199 |
|
199 |
|
200 |
SQLRowAccessor rowCptTva;
|
200 |
SQLRowAccessor rowCptTva;
|
201 |
if (this.intraComm) {
|
201 |
if (this.intraComm) {
|
202 |
|
202 |
|
203 |
// Intra comm TTC=HT et solde de TVA
|
203 |
// Intra comm TTC=HT et solde de TVA
|
204 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED_INTRA"));
|
204 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED_INTRA"));
|
205 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
205 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
206 |
rowCptTva = this.rowDefaultCptTVADeductible;
|
206 |
rowCptTva = this.rowDefaultCptTVADeductible;
|
207 |
}
|
207 |
}
|
208 |
|
208 |
|
209 |
SQLRowAccessor rowCptTvaIntra = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE_INTRA"));
|
209 |
SQLRowAccessor rowCptTvaIntra = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE_INTRA"));
|
210 |
if (rowCptTvaIntra == null || rowCptTvaIntra.isUndefined()) {
|
210 |
if (rowCptTvaIntra == null || rowCptTvaIntra.isUndefined()) {
|
211 |
rowCptTvaIntra = this.rowDefaultCptTVADeductible;
|
211 |
rowCptTvaIntra = this.rowDefaultCptTVADeductible;
|
212 |
}
|
212 |
}
|
213 |
|
213 |
|
214 |
if (this.mapHtTVAIntra.get(rowCptTvaIntra) == null) {
|
214 |
if (this.mapHtTVAIntra.get(rowCptTvaIntra) == null) {
|
215 |
this.mapHtTVAIntra.put(rowCptTvaIntra, tvaFix);
|
215 |
this.mapHtTVAIntra.put(rowCptTvaIntra, tvaFix);
|
216 |
} else {
|
216 |
} else {
|
217 |
BigDecimal l = this.mapHtTVAIntra.get(rowCptTvaIntra);
|
217 |
BigDecimal l = this.mapHtTVAIntra.get(rowCptTvaIntra);
|
218 |
this.mapHtTVAIntra.put(rowCptTvaIntra, l.add(tvaFix));
|
218 |
this.mapHtTVAIntra.put(rowCptTvaIntra, l.add(tvaFix));
|
219 |
}
|
219 |
}
|
220 |
|
220 |
|
221 |
} else if (this.achat) {
|
221 |
} else if (this.achat) {
|
222 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED"));
|
222 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED"));
|
223 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
223 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
224 |
rowCptTva = this.rowDefaultCptTVADeductible;
|
224 |
rowCptTva = this.rowDefaultCptTVADeductible;
|
225 |
}
|
225 |
}
|
226 |
} else {
|
226 |
} else {
|
227 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE"));
|
227 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE"));
|
228 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
228 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
229 |
rowCptTva = this.rowDefaultCptTVACollecte;
|
229 |
rowCptTva = this.rowDefaultCptTVACollecte;
|
230 |
}
|
230 |
}
|
231 |
}
|
231 |
}
|
232 |
if (this.mapHtTVA.get(rowCptTva) == null) {
|
232 |
if (this.mapHtTVA.get(rowCptTva) == null) {
|
233 |
this.mapHtTVA.put(rowCptTva, tvaFix);
|
233 |
this.mapHtTVA.put(rowCptTva, tvaFix);
|
234 |
} else {
|
234 |
} else {
|
235 |
BigDecimal l = this.mapHtTVA.get(rowCptTva);
|
235 |
BigDecimal l = this.mapHtTVA.get(rowCptTva);
|
236 |
this.mapHtTVA.put(rowCptTva, l.add(tvaFix));
|
236 |
this.mapHtTVA.put(rowCptTva, l.add(tvaFix));
|
237 |
}
|
237 |
}
|
238 |
|
238 |
|
239 |
this.totalTTC = this.totalTTC.add(tvaFix);
|
239 |
this.totalTTC = this.totalTTC.add(tvaFix);
|
240 |
|
240 |
|
241 |
}
|
241 |
}
|
242 |
|
242 |
|
243 |
/**
|
243 |
/**
|
244 |
* Gestion de la vente de service
|
244 |
* Gestion de la vente de service
|
245 |
*
|
245 |
*
|
246 |
* @param b
|
246 |
* @param b
|
247 |
*/
|
247 |
*/
|
248 |
public void setServiceActive(boolean b) {
|
248 |
public void setServiceActive(boolean b) {
|
249 |
this.bServiceActive = b;
|
249 |
this.bServiceActive = b;
|
250 |
}
|
250 |
}
|
251 |
|
251 |
|
252 |
/**
|
252 |
/**
|
253 |
* Remise à zéro des valeurs de calcul
|
253 |
* Remise à zéro des valeurs de calcul
|
254 |
*/
|
254 |
*/
|
255 |
public void initValues() {
|
255 |
public void initValues() {
|
256 |
this.remiseHT = 0;
|
256 |
this.remiseHT = 0;
|
257 |
this.remiseRestante = 0;
|
257 |
this.remiseRestante = 0;
|
258 |
this.totalHTAvantRemise = BigDecimal.ZERO;
|
258 |
this.totalHTAvantRemise = BigDecimal.ZERO;
|
259 |
|
259 |
|
260 |
this.selectedRows = null;
|
260 |
this.selectedRows = null;
|
261 |
|
261 |
|
262 |
this.totalHTSansFActurable = BigDecimal.ZERO;
|
262 |
this.totalHTSansFActurable = BigDecimal.ZERO;
|
263 |
this.totalTTC = BigDecimal.ZERO;
|
263 |
this.totalTTC = BigDecimal.ZERO;
|
264 |
this.totalTTCSel = BigDecimal.ZERO;
|
264 |
this.totalTTCSel = BigDecimal.ZERO;
|
265 |
|
265 |
|
266 |
this.totalEco = BigDecimal.ZERO;
|
266 |
this.totalEco = BigDecimal.ZERO;
|
267 |
this.totalEcoSel = BigDecimal.ZERO;
|
267 |
this.totalEcoSel = BigDecimal.ZERO;
|
268 |
|
268 |
|
269 |
this.totalHA = BigDecimal.ZERO;
|
269 |
this.totalHA = BigDecimal.ZERO;
|
270 |
this.totalHASel = BigDecimal.ZERO;
|
270 |
this.totalHASel = BigDecimal.ZERO;
|
271 |
|
271 |
|
272 |
this.totalService = BigDecimal.ZERO;
|
272 |
this.totalService = BigDecimal.ZERO;
|
273 |
this.totalServiceSel = BigDecimal.ZERO;
|
273 |
this.totalServiceSel = BigDecimal.ZERO;
|
274 |
|
274 |
|
275 |
this.totalDeviseSel = BigDecimal.ZERO;
|
275 |
this.totalDeviseSel = BigDecimal.ZERO;
|
276 |
this.totalDevise = BigDecimal.ZERO;
|
276 |
this.totalDevise = BigDecimal.ZERO;
|
277 |
|
277 |
|
278 |
this.totalPoids = 0;
|
278 |
this.totalPoids = 0;
|
279 |
|
279 |
|
280 |
// Total des HT par comptes
|
280 |
// Total des HT par comptes
|
281 |
this.mapHt.clear();
|
281 |
this.mapHt.clear();
|
282 |
this.mapHtSel.clear();
|
282 |
this.mapHtSel.clear();
|
283 |
|
283 |
|
284 |
// Total des TVA par comptes
|
284 |
// Total des TVA par comptes
|
285 |
this.mapHtTVA.clear();
|
285 |
this.mapHtTVA.clear();
|
286 |
this.mapHtTaxeCompl.clear();
|
286 |
this.mapHtTaxeCompl.clear();
|
287 |
this.mapHtTVAIntra.clear();
|
287 |
this.mapHtTVAIntra.clear();
|
288 |
this.mapHtTVARowTaux.clear();
|
288 |
this.mapHtTVARowTaux.clear();
|
289 |
this.mapHtTVASel.clear();
|
289 |
this.mapHtTVASel.clear();
|
290 |
|
290 |
|
291 |
}
|
291 |
}
|
292 |
|
292 |
|
293 |
public void setSelectedRows(int[] selectedRows) {
|
293 |
public void setSelectedRows(int[] selectedRows) {
|
294 |
this.selectedRows = selectedRows;
|
294 |
this.selectedRows = selectedRows;
|
295 |
}
|
295 |
}
|
296 |
|
296 |
|
297 |
public void addEchantillon(BigDecimal ht, SQLRowAccessor tva) {
|
297 |
public void addEchantillon(BigDecimal ht, SQLRowAccessor tva) {
|
298 |
addHT(ht, ht, tva, this.rowDefaultCptProduit, false);
|
298 |
addHT(ht, ht, tva, this.rowDefaultCptProduit, false);
|
299 |
}
|
299 |
}
|
300 |
|
300 |
|
301 |
// Cache de TVA
|
301 |
// Cache de TVA
|
302 |
private static Map<Integer, SQLRowAccessor> mapTVA;
|
302 |
private static Map<Integer, SQLRowAccessor> mapTVA;
|
303 |
private static long lastTVAfetchedTime = 0;
|
303 |
private static long lastTVAfetchedTime = 0;
|
304 |
|
304 |
|
305 |
final SQLTable tvaTable = Configuration.getInstance().getRoot().findTable("TAXE");
|
305 |
final SQLTable tvaTable = Configuration.getInstance().getRoot().findTable("TAXE");
|
306 |
final SQLTable compteTable = Configuration.getInstance().getRoot().findTable("COMPTE_PCE");
|
306 |
final SQLTable compteTable = Configuration.getInstance().getRoot().findTable("COMPTE_PCE");
|
307 |
|
307 |
|
308 |
/**
|
308 |
/**
|
309 |
* Mise en cache des comptes de TVA
|
309 |
* Mise en cache des comptes de TVA
|
310 |
*/
|
310 |
*/
|
311 |
private void fetchTVA() {
|
311 |
private void fetchTVA() {
|
312 |
mapTVA = new HashMap<Integer, SQLRowAccessor>();
|
312 |
mapTVA = new HashMap<Integer, SQLRowAccessor>();
|
313 |
Set<SQLRowAccessor> taxes = TaxeCache.getCache().getAllTaxe();
|
313 |
Set<SQLRowAccessor> taxes = TaxeCache.getCache().getAllTaxe();
|
314 |
for (SQLRowAccessor sqlRowAccessor : taxes) {
|
314 |
for (SQLRowAccessor sqlRowAccessor : taxes) {
|
315 |
mapTVA.put(sqlRowAccessor.getID(), sqlRowAccessor);
|
315 |
mapTVA.put(sqlRowAccessor.getID(), sqlRowAccessor);
|
316 |
}
|
316 |
}
|
317 |
// SQLRowValues rowVals = new SQLRowValues(this.tvaTable);
|
317 |
// SQLRowValues rowVals = new SQLRowValues(this.tvaTable);
|
318 |
// SQLRowValues rowValsC1 = new SQLRowValues(this.compteTable);
|
318 |
// SQLRowValues rowValsC1 = new SQLRowValues(this.compteTable);
|
319 |
// rowValsC1.put("NUMERO", null);
|
319 |
// rowValsC1.put("NUMERO", null);
|
320 |
// rowValsC1.put("ID", null);
|
320 |
// rowValsC1.put("ID", null);
|
321 |
//
|
321 |
//
|
322 |
// SQLRowValues rowValsC2 = new SQLRowValues(this.compteTable);
|
322 |
// SQLRowValues rowValsC2 = new SQLRowValues(this.compteTable);
|
323 |
// rowValsC2.put("NUMERO", null);
|
323 |
// rowValsC2.put("NUMERO", null);
|
324 |
// rowValsC2.put("ID", null);
|
324 |
// rowValsC2.put("ID", null);
|
325 |
//
|
325 |
//
|
326 |
// SQLRowValues rowValsC3 = new SQLRowValues(this.compteTable);
|
326 |
// SQLRowValues rowValsC3 = new SQLRowValues(this.compteTable);
|
327 |
// rowValsC3.put("NUMERO", null);
|
327 |
// rowValsC3.put("NUMERO", null);
|
328 |
// rowValsC3.put("ID", null);
|
328 |
// rowValsC3.put("ID", null);
|
329 |
// SQLRowValues rowValsC4 = new SQLRowValues(this.compteTable);
|
329 |
// SQLRowValues rowValsC4 = new SQLRowValues(this.compteTable);
|
330 |
// rowValsC4.put("NUMERO", null);
|
330 |
// rowValsC4.put("NUMERO", null);
|
331 |
// rowValsC4.put("ID", null);
|
331 |
// rowValsC4.put("ID", null);
|
332 |
//
|
332 |
//
|
333 |
// rowVals.put(this.tvaTable.getKey().getName(), null);
|
333 |
// rowVals.put(this.tvaTable.getKey().getName(), null);
|
334 |
// rowVals.put("ID_COMPTE_PCE_COLLECTE", rowValsC1);
|
334 |
// rowVals.put("ID_COMPTE_PCE_COLLECTE", rowValsC1);
|
335 |
// rowVals.put("ID_COMPTE_PCE_DED", rowValsC2);
|
335 |
// rowVals.put("ID_COMPTE_PCE_DED", rowValsC2);
|
336 |
// rowVals.put("ID_COMPTE_PCE_VENTE", rowValsC3);
|
336 |
// rowVals.put("ID_COMPTE_PCE_VENTE", rowValsC3);
|
337 |
// rowVals.put("ID_COMPTE_PCE_VENTE_SERVICE", rowValsC4);
|
337 |
// rowVals.put("ID_COMPTE_PCE_VENTE_SERVICE", rowValsC4);
|
338 |
//
|
338 |
//
|
339 |
// if (this.tvaTable.contains("ID_COMPTE_PCE_COLLECTE_INTRA")) {
|
339 |
// if (this.tvaTable.contains("ID_COMPTE_PCE_COLLECTE_INTRA")) {
|
340 |
// SQLRowValues rowValsC1Intra = new SQLRowValues(this.compteTable);
|
340 |
// SQLRowValues rowValsC1Intra = new SQLRowValues(this.compteTable);
|
341 |
// rowValsC1Intra.put("NUMERO", null);
|
341 |
// rowValsC1Intra.put("NUMERO", null);
|
342 |
// rowValsC1Intra.put("ID", null);
|
342 |
// rowValsC1Intra.put("ID", null);
|
343 |
// rowVals.put("ID_COMPTE_PCE_COLLECTE_INTRA", rowValsC1Intra);
|
343 |
// rowVals.put("ID_COMPTE_PCE_COLLECTE_INTRA", rowValsC1Intra);
|
344 |
// SQLRowValues rowValsC2Intra = new SQLRowValues(this.compteTable);
|
344 |
// SQLRowValues rowValsC2Intra = new SQLRowValues(this.compteTable);
|
345 |
// rowValsC2Intra.put("NUMERO", null);
|
345 |
// rowValsC2Intra.put("NUMERO", null);
|
346 |
// rowValsC2Intra.put("ID", null);
|
346 |
// rowValsC2Intra.put("ID", null);
|
347 |
// rowVals.put("ID_COMPTE_PCE_DED_INTRA", rowValsC2Intra);
|
347 |
// rowVals.put("ID_COMPTE_PCE_DED_INTRA", rowValsC2Intra);
|
348 |
// }
|
348 |
// }
|
349 |
// SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(rowVals);
|
349 |
// SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(rowVals);
|
350 |
// List<SQLRowValues> rowValsList = fetch.fetch();
|
350 |
// List<SQLRowValues> rowValsList = fetch.fetch();
|
351 |
//
|
351 |
//
|
352 |
// for (SQLRowValues sqlRowValues : rowValsList) {
|
352 |
// for (SQLRowValues sqlRowValues : rowValsList) {
|
353 |
// mapTVA.put(sqlRowValues.getID(), sqlRowValues);
|
353 |
// mapTVA.put(sqlRowValues.getID(), sqlRowValues);
|
354 |
// }
|
354 |
// }
|
355 |
lastTVAfetchedTime = System.currentTimeMillis();
|
355 |
lastTVAfetchedTime = System.currentTimeMillis();
|
356 |
}
|
356 |
}
|
357 |
|
357 |
|
358 |
private void addHT(BigDecimal ht, BigDecimal htSansFacturable, SQLRowAccessor tva, SQLRowAccessor cptArticle, boolean selection) {
|
358 |
private void addHT(BigDecimal ht, BigDecimal htSansFacturable, SQLRowAccessor tva, SQLRowAccessor cptArticle, boolean selection) {
|
359 |
|
359 |
|
360 |
BigDecimal ttc;
|
360 |
BigDecimal ttc;
|
361 |
BigDecimal totalTVA;
|
361 |
BigDecimal totalTVA;
|
362 |
final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(cptArticle.getTable());
|
362 |
final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(cptArticle.getTable());
|
363 |
|
363 |
|
364 |
if (tva == null || tva.isUndefined()) {
|
364 |
if (tva == null || tva.isUndefined()) {
|
365 |
ttc = ht;
|
365 |
ttc = ht;
|
366 |
totalTVA = BigDecimal.ZERO;
|
366 |
totalTVA = BigDecimal.ZERO;
|
367 |
} else {
|
367 |
} else {
|
368 |
BigDecimal tauxTVA = BigDecimal.valueOf(TaxeCache.getCache().getTauxFromId(tva.getID())).movePointLeft(2);
|
368 |
BigDecimal tauxTVA = BigDecimal.valueOf(TaxeCache.getCache().getTauxFromId(tva.getID())).movePointLeft(2);
|
369 |
ttc = tauxTVA.add(BigDecimal.ONE).multiply(ht, DecimalUtils.HIGH_PRECISION);
|
369 |
ttc = tauxTVA.add(BigDecimal.ONE).multiply(ht, DecimalUtils.HIGH_PRECISION);
|
370 |
totalTVA = ttc.subtract(ht);
|
370 |
totalTVA = ttc.subtract(ht);
|
371 |
}
|
371 |
}
|
372 |
|
372 |
|
373 |
if (tva != null && !tva.isUndefined()) {
|
373 |
if (tva != null && !tva.isUndefined()) {
|
374 |
SQLRowAccessor rowCptTva;
|
374 |
SQLRowAccessor rowCptTva;
|
375 |
if (this.intraComm) {
|
375 |
if (this.intraComm) {
|
376 |
|
376 |
|
377 |
// Intra comm TTC=HT et solde de TVA
|
377 |
// Intra comm TTC=HT et solde de TVA
|
378 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED_INTRA"));
|
378 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED_INTRA"));
|
379 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
379 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
380 |
rowCptTva = this.rowDefaultCptTVADeductible;
|
380 |
rowCptTva = this.rowDefaultCptTVADeductible;
|
381 |
}
|
381 |
}
|
382 |
|
382 |
|
383 |
SQLRowAccessor rowCptTvaIntra = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE_INTRA"));
|
383 |
SQLRowAccessor rowCptTvaIntra = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE_INTRA"));
|
384 |
if (rowCptTvaIntra == null || rowCptTvaIntra.isUndefined()) {
|
384 |
if (rowCptTvaIntra == null || rowCptTvaIntra.isUndefined()) {
|
385 |
rowCptTvaIntra = this.rowDefaultCptTVADeductible;
|
385 |
rowCptTvaIntra = this.rowDefaultCptTVADeductible;
|
386 |
}
|
386 |
}
|
387 |
|
387 |
|
388 |
if (this.mapHtTVAIntra.get(rowCptTvaIntra) == null) {
|
388 |
if (this.mapHtTVAIntra.get(rowCptTvaIntra) == null) {
|
389 |
this.mapHtTVAIntra.put(rowCptTvaIntra, totalTVA);
|
389 |
this.mapHtTVAIntra.put(rowCptTvaIntra, totalTVA);
|
390 |
} else {
|
390 |
} else {
|
391 |
BigDecimal l = this.mapHtTVAIntra.get(rowCptTvaIntra);
|
391 |
BigDecimal l = this.mapHtTVAIntra.get(rowCptTvaIntra);
|
392 |
this.mapHtTVAIntra.put(rowCptTvaIntra, l.add(totalTVA));
|
392 |
this.mapHtTVAIntra.put(rowCptTvaIntra, l.add(totalTVA));
|
393 |
}
|
393 |
}
|
394 |
|
394 |
|
395 |
ttc = ht;
|
395 |
ttc = ht;
|
396 |
} else if (this.achat) {
|
396 |
} else if (this.achat) {
|
397 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED"));
|
397 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED"));
|
398 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
398 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
399 |
rowCptTva = this.rowDefaultCptTVADeductible;
|
399 |
rowCptTva = this.rowDefaultCptTVADeductible;
|
400 |
}
|
400 |
}
|
401 |
} else {
|
401 |
} else {
|
402 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE"));
|
402 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE"));
|
403 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
403 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
404 |
rowCptTva = this.rowDefaultCptTVACollecte;
|
404 |
rowCptTva = this.rowDefaultCptTVACollecte;
|
405 |
}
|
405 |
}
|
406 |
}
|
406 |
}
|
407 |
if (this.mapHtTVA.get(rowCptTva) == null) {
|
407 |
if (this.mapHtTVA.get(rowCptTva) == null) {
|
408 |
this.mapHtTVA.put(rowCptTva, totalTVA);
|
408 |
this.mapHtTVA.put(rowCptTva, totalTVA);
|
409 |
} else {
|
409 |
} else {
|
410 |
BigDecimal l = this.mapHtTVA.get(rowCptTva);
|
410 |
BigDecimal l = this.mapHtTVA.get(rowCptTva);
|
411 |
this.mapHtTVA.put(rowCptTva, l.add(totalTVA));
|
411 |
this.mapHtTVA.put(rowCptTva, l.add(totalTVA));
|
412 |
}
|
412 |
}
|
413 |
if (ht.signum() != 0) {
|
413 |
if (ht.signum() != 0) {
|
414 |
if (this.mapHtTVARowTaux.get(tva) == null) {
|
414 |
if (this.mapHtTVARowTaux.get(tva) == null) {
|
415 |
this.mapHtTVARowTaux.put(tva, Tuple2.create(ht, totalTVA));
|
415 |
this.mapHtTVARowTaux.put(tva, Tuple2.create(ht, totalTVA));
|
416 |
} else {
|
416 |
} else {
|
417 |
Tuple2<BigDecimal, BigDecimal> l = this.mapHtTVARowTaux.get(tva);
|
417 |
Tuple2<BigDecimal, BigDecimal> l = this.mapHtTVARowTaux.get(tva);
|
418 |
this.mapHtTVARowTaux.put(tva, Tuple2.create(ht.add(l.get0()), l.get1().add(totalTVA)));
|
418 |
this.mapHtTVARowTaux.put(tva, Tuple2.create(ht.add(l.get0()), l.get1().add(totalTVA)));
|
419 |
}
|
419 |
}
|
420 |
}
|
420 |
}
|
421 |
if (selection) {
|
421 |
if (selection) {
|
422 |
if (this.mapHtTVASel.get(rowCptTva) == null) {
|
422 |
if (this.mapHtTVASel.get(rowCptTva) == null) {
|
423 |
this.mapHtTVASel.put(rowCptTva, totalTVA);
|
423 |
this.mapHtTVASel.put(rowCptTva, totalTVA);
|
424 |
} else {
|
424 |
} else {
|
425 |
BigDecimal l = this.mapHtTVASel.get(rowCptTva);
|
425 |
BigDecimal l = this.mapHtTVASel.get(rowCptTva);
|
426 |
this.mapHtTVASel.put(rowCptTva, l.add(totalTVA));
|
426 |
this.mapHtTVASel.put(rowCptTva, l.add(totalTVA));
|
427 |
}
|
427 |
}
|
428 |
}
|
428 |
}
|
429 |
}
|
429 |
}
|
430 |
|
430 |
|
431 |
if (this.mapHt.get(cptArticle) == null) {
|
431 |
if (this.mapHt.get(cptArticle) == null) {
|
432 |
this.mapHt.put(cptArticle, ht);
|
432 |
this.mapHt.put(cptArticle, ht);
|
433 |
} else {
|
433 |
} else {
|
434 |
BigDecimal l = this.mapHt.get(cptArticle);
|
434 |
BigDecimal l = this.mapHt.get(cptArticle);
|
435 |
this.mapHt.put(cptArticle, l.add(ht));
|
435 |
this.mapHt.put(cptArticle, l.add(ht));
|
436 |
}
|
436 |
}
|
437 |
|
437 |
|
438 |
this.totalTTC = this.totalTTC.add(ttc);
|
438 |
this.totalTTC = this.totalTTC.add(ttc);
|
439 |
this.totalHTSansFActurable = this.totalHTSansFActurable.add(htSansFacturable);
|
439 |
this.totalHTSansFActurable = this.totalHTSansFActurable.add(htSansFacturable);
|
440 |
if (selection) {
|
440 |
if (selection) {
|
441 |
|
441 |
|
442 |
if (this.mapHtSel.get(cptArticle) == null) {
|
442 |
if (this.mapHtSel.get(cptArticle) == null) {
|
443 |
this.mapHtSel.put(cptArticle, ht);
|
443 |
this.mapHtSel.put(cptArticle, ht);
|
444 |
} else {
|
444 |
} else {
|
445 |
BigDecimal l = this.mapHtSel.get(cptArticle);
|
445 |
BigDecimal l = this.mapHtSel.get(cptArticle);
|
446 |
this.mapHtSel.put(cptArticle, l.add(ht));
|
446 |
this.mapHtSel.put(cptArticle, l.add(ht));
|
447 |
}
|
447 |
}
|
448 |
this.totalTTCSel = this.totalTTCSel.add(ttc);
|
448 |
this.totalTTCSel = this.totalTTCSel.add(ttc);
|
449 |
}
|
449 |
}
|
450 |
}
|
450 |
}
|
451 |
|
451 |
|
452 |
private static boolean containsInt(int[] tab, int i) {
|
452 |
private static boolean containsInt(int[] tab, int i) {
|
453 |
if (tab == null) {
|
453 |
if (tab == null) {
|
454 |
return false;
|
454 |
return false;
|
455 |
}
|
455 |
}
|
456 |
|
456 |
|
457 |
for (int j = 0; j < tab.length; j++) {
|
457 |
for (int j = 0; j < tab.length; j++) {
|
458 |
if (tab[j] == i) {
|
458 |
if (tab[j] == i) {
|
459 |
return true;
|
459 |
return true;
|
460 |
}
|
460 |
}
|
461 |
}
|
461 |
}
|
462 |
return false;
|
462 |
return false;
|
463 |
}
|
463 |
}
|
464 |
|
464 |
|
465 |
public void addLine(SQLRowAccessor rowAccessorLine, SQLRowAccessor article, int lineNumber, boolean last) {
|
465 |
public void addLine(SQLRowAccessor rowAccessorLine, SQLRowAccessor article, int lineNumber, boolean last) {
|
466 |
|
466 |
|
467 |
if (rowAccessorLine.getFields().contains("NIVEAU") && rowAccessorLine.getInt("NIVEAU") != 1) {
|
467 |
if (rowAccessorLine.getFields().contains("NIVEAU") && rowAccessorLine.getInt("NIVEAU") != 1) {
|
468 |
return;
|
468 |
return;
|
469 |
}
|
469 |
}
|
470 |
|
470 |
|
471 |
// Total HT de la ligne
|
471 |
// Total HT de la ligne
|
472 |
BigDecimal totalLineHT = rowAccessorLine.getObject(this.fieldHT) == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject(this.fieldHT);
|
472 |
BigDecimal totalLineHT = rowAccessorLine.getObject(this.fieldHT) == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject(this.fieldHT);
|
473 |
BigDecimal totalLineEco = rowAccessorLine.getObject("T_ECO_CONTRIBUTION") == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject("T_ECO_CONTRIBUTION");
|
473 |
BigDecimal totalLineEco = rowAccessorLine.getObject("T_ECO_CONTRIBUTION") == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject("T_ECO_CONTRIBUTION");
|
474 |
|
474 |
|
475 |
BigDecimal totalLineHTSansFacturable = totalLineHT;
|
475 |
BigDecimal totalLineHTSansFacturable = totalLineHT;
|
476 |
if (!this.achat) {
|
476 |
if (!this.achat) {
|
477 |
totalLineHTSansFacturable = rowAccessorLine.getObject("PV_HT") == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject("PV_HT");
|
477 |
totalLineHTSansFacturable = rowAccessorLine.getObject("PV_HT") == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject("PV_HT");
|
478 |
BigDecimal qteUV = rowAccessorLine.getObject("QTE_UNITAIRE") == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject("QTE_UNITAIRE");
|
478 |
BigDecimal qteUV = rowAccessorLine.getObject("QTE_UNITAIRE") == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject("QTE_UNITAIRE");
|
479 |
int qte = rowAccessorLine.getInt("QTE");
|
479 |
int qte = rowAccessorLine.getInt("QTE");
|
480 |
totalLineHTSansFacturable = totalLineHTSansFacturable.multiply(qteUV).multiply(new BigDecimal(qte));
|
480 |
totalLineHTSansFacturable = totalLineHTSansFacturable.multiply(qteUV).multiply(new BigDecimal(qte));
|
481 |
}
|
481 |
}
|
482 |
// Prix Unitaire de la ligne
|
482 |
// Prix Unitaire de la ligne
|
483 |
// TODO voir pour passer le prix total et non le prix unitaire
|
483 |
// TODO voir pour passer le prix total et non le prix unitaire
|
484 |
BigDecimal totalHALigne = rowAccessorLine.getObject(this.fieldHA) == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject(this.fieldHA);
|
484 |
BigDecimal totalHALigne = rowAccessorLine.getObject(this.fieldHA) == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject(this.fieldHA);
|
485 |
|
485 |
|
486 |
Boolean service = rowAccessorLine.getBoolean(FIELD_SERVICE);
|
486 |
Boolean service = rowAccessorLine.getBoolean(FIELD_SERVICE);
|
487 |
|
487 |
|
488 |
BigDecimal totalLineDevise = (this.fieldDevise == null || rowAccessorLine.getObject(this.fieldDevise) == null) ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject(this.fieldDevise);
|
488 |
BigDecimal totalLineDevise = (this.fieldDevise == null || rowAccessorLine.getObject(this.fieldDevise) == null) ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject(this.fieldDevise);
|
489 |
|
489 |
|
490 |
Number nPoids = (Number) rowAccessorLine.getObject(FIELD_POIDS);
|
490 |
Number nPoids = (Number) rowAccessorLine.getObject(FIELD_POIDS);
|
491 |
|
491 |
|
492 |
// Si il y a une remise à appliquer
|
492 |
// Si il y a une remise à appliquer
|
493 |
if (this.remiseHT != 0 && this.remiseRestante > 0 && this.totalHTAvantRemise != null && this.totalHTAvantRemise.signum() != 0) {
|
493 |
if (this.remiseHT != 0 && this.remiseRestante > 0 && this.totalHTAvantRemise != null && this.totalHTAvantRemise.signum() != 0) {
|
494 |
|
494 |
|
495 |
// Si c'est la derniere ligne, on applique le restant de la remise
|
495 |
// Si c'est la derniere ligne, on applique le restant de la remise
|
496 |
if (last) {
|
496 |
if (last) {
|
497 |
totalLineHT = totalLineHT.subtract(new BigDecimal(this.remiseRestante).movePointLeft(2));
|
497 |
totalLineHT = totalLineHT.subtract(new BigDecimal(this.remiseRestante).movePointLeft(2));
|
498 |
totalLineHTSansFacturable = totalLineHTSansFacturable.subtract(new BigDecimal(this.remiseRestante).movePointLeft(2));
|
498 |
totalLineHTSansFacturable = totalLineHTSansFacturable.subtract(new BigDecimal(this.remiseRestante).movePointLeft(2));
|
499 |
this.remiseRestante = 0;
|
499 |
this.remiseRestante = 0;
|
500 |
} else {
|
500 |
} else {
|
501 |
BigDecimal percent = totalLineHT.divide(this.totalHTAvantRemise, DecimalUtils.HIGH_PRECISION);
|
501 |
BigDecimal percent = totalLineHT.divide(this.totalHTAvantRemise, DecimalUtils.HIGH_PRECISION);
|
502 |
|
502 |
|
503 |
BigDecimal remiseApply = percent.multiply(new BigDecimal(this.remiseHT), DecimalUtils.HIGH_PRECISION).setScale(0, RoundingMode.HALF_UP);
|
503 |
BigDecimal remiseApply = percent.multiply(new BigDecimal(this.remiseHT), DecimalUtils.HIGH_PRECISION).setScale(0, RoundingMode.HALF_UP);
|
504 |
totalLineHT = totalLineHT.subtract(remiseApply.movePointLeft(2));
|
504 |
totalLineHT = totalLineHT.subtract(remiseApply.movePointLeft(2));
|
505 |
totalLineHTSansFacturable = totalLineHTSansFacturable.subtract(remiseApply.movePointLeft(2));
|
505 |
totalLineHTSansFacturable = totalLineHTSansFacturable.subtract(remiseApply.movePointLeft(2));
|
506 |
this.remiseRestante -= remiseApply.longValue();
|
506 |
this.remiseRestante -= remiseApply.longValue();
|
507 |
}
|
507 |
}
|
508 |
}
|
508 |
}
|
509 |
|
509 |
|
510 |
// TODO : generaliser le cache
|
510 |
// TODO : generaliser le cache
|
511 |
if (mapTVA == null || lastTVAfetchedTime + 30 * 1000 < System.currentTimeMillis()) {
|
511 |
if (mapTVA == null || lastTVAfetchedTime + 30 * 1000 < System.currentTimeMillis()) {
|
512 |
fetchTVA();
|
512 |
fetchTVA();
|
513 |
}
|
513 |
}
|
514 |
Integer idTVA = null;
|
514 |
Integer idTVA = null;
|
515 |
if (rowAccessorLine.getObject("ID_TAXE") != null && !rowAccessorLine.isForeignEmpty("ID_TAXE")) {
|
515 |
if (rowAccessorLine.getObject("ID_TAXE") != null && !rowAccessorLine.isForeignEmpty("ID_TAXE")) {
|
516 |
idTVA = rowAccessorLine.getForeignID("ID_TAXE");
|
516 |
idTVA = rowAccessorLine.getForeignID("ID_TAXE");
|
517 |
} else {
|
517 |
} else {
|
518 |
final SQLRowAccessor foreignTVA = rowAccessorLine.getForeign("ID_TAXE");
|
518 |
final SQLRowAccessor foreignTVA = rowAccessorLine.getForeign("ID_TAXE");
|
519 |
if (foreignTVA != null) {
|
519 |
if (foreignTVA != null) {
|
520 |
idTVA = foreignTVA.getID();
|
520 |
idTVA = foreignTVA.getID();
|
521 |
}
|
521 |
}
|
522 |
}
|
522 |
}
|
523 |
SQLRowAccessor tva = mapTVA.get(idTVA);
|
523 |
SQLRowAccessor tva = mapTVA.get(idTVA);
|
524 |
|
524 |
|
525 |
SQLRowAccessor cpt = (this.achat ? this.rowDefaultCptAchat : this.rowDefaultCptProduit);
|
525 |
SQLRowAccessor cpt = (this.achat ? this.rowDefaultCptAchat : this.rowDefaultCptProduit);
|
526 |
final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(cpt.getTable());
|
526 |
final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(cpt.getTable());
|
527 |
|
527 |
|
528 |
if (!this.achat) {
|
528 |
if (!this.achat) {
|
529 |
// Total Service
|
529 |
// Total Service
|
530 |
if (this.bServiceActive != null && this.bServiceActive && service != null && service.booleanValue()) {
|
530 |
if (this.bServiceActive != null && this.bServiceActive && service != null && service.booleanValue()) {
|
531 |
this.totalService = this.totalService.add(totalLineHT);
|
531 |
this.totalService = this.totalService.add(totalLineHT);
|
532 |
cpt = this.rowDefaultCptService;
|
532 |
cpt = this.rowDefaultCptService;
|
533 |
if (tva != null && !tva.isForeignEmpty("ID_COMPTE_PCE_VENTE_SERVICE")) {
|
533 |
if (tva != null && !tva.isForeignEmpty("ID_COMPTE_PCE_VENTE_SERVICE")) {
|
534 |
cpt = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_VENTE_SERVICE"));
|
534 |
cpt = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_VENTE_SERVICE"));
|
535 |
}
|
535 |
}
|
536 |
} else {
|
536 |
} else {
|
537 |
// Compte defini par défaut dans la TVA
|
537 |
// Compte defini par défaut dans la TVA
|
538 |
if (tva != null && !tva.isForeignEmpty("ID_COMPTE_PCE_VENTE")) {
|
538 |
if (tva != null && !tva.isForeignEmpty("ID_COMPTE_PCE_VENTE")) {
|
539 |
cpt = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_VENTE"));
|
539 |
cpt = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_VENTE"));
|
540 |
}
|
540 |
}
|
541 |
|
541 |
|
542 |
}
|
542 |
}
|
543 |
}
|
543 |
}
|
544 |
|
544 |
|
545 |
// Compte PCE défini directement sur la ligne
|
545 |
// Compte PCE défini directement sur la ligne
|
546 |
boolean compteSpec = false;
|
546 |
boolean compteSpec = false;
|
547 |
if (rowAccessorLine.getTable().contains("ID_COMPTE_PCE") && rowAccessorLine.getObject("ID_COMPTE_PCE") != null && !rowAccessorLine.isForeignEmpty("ID_COMPTE_PCE")) {
|
547 |
if (rowAccessorLine.getTable().contains("ID_COMPTE_PCE") && rowAccessorLine.getObject("ID_COMPTE_PCE") != null && !rowAccessorLine.isForeignEmpty("ID_COMPTE_PCE")) {
|
548 |
compteSpec = true;
|
548 |
compteSpec = true;
|
549 |
cpt = cacheForTableCompte.getRowFromId(rowAccessorLine.getForeignID("ID_COMPTE_PCE"));
|
549 |
cpt = cacheForTableCompte.getRowFromId(rowAccessorLine.getForeignID("ID_COMPTE_PCE"));
|
550 |
}
|
550 |
}
|
551 |
if (article != null && !article.isUndefined()) {
|
551 |
if (article != null && !article.isUndefined()) {
|
552 |
if (!compteSpec) {
|
552 |
if (!compteSpec) {
|
553 |
SQLRowAccessor cptCatComptable = null;
|
553 |
SQLRowAccessor cptCatComptable = null;
|
554 |
// TODO Optimiser les requetes
|
554 |
// TODO Optimiser les requetes
|
555 |
if (this.rowCatComptable != null && !this.rowCatComptable.isUndefined()) {
|
555 |
if (this.rowCatComptable != null && !this.rowCatComptable.isUndefined()) {
|
556 |
String suffix = (this.achat ? "_ACHAT" : "_VENTE");
|
556 |
String suffix = (this.achat ? "_ACHAT" : "_VENTE");
|
557 |
if (!this.rowCatComptable.isForeignEmpty("ID_COMPTE_PCE" + suffix)) {
|
557 |
if (!this.rowCatComptable.isForeignEmpty("ID_COMPTE_PCE" + suffix)) {
|
558 |
cptCatComptable = cacheForTableCompte.getRowFromId(this.rowCatComptable.getForeignID("ID_COMPTE_PCE" + suffix));
|
558 |
cptCatComptable = cacheForTableCompte.getRowFromId(this.rowCatComptable.getForeignID("ID_COMPTE_PCE" + suffix));
|
559 |
}
|
559 |
}
|
560 |
Collection<? extends SQLRowAccessor> rows = article.getReferentRows(this.compteTable.getTable("ARTICLE_CATEGORIE_COMPTABLE"));
|
560 |
Collection<? extends SQLRowAccessor> rows = article.getReferentRows(this.compteTable.getTable("ARTICLE_CATEGORIE_COMPTABLE"));
|
561 |
for (SQLRowAccessor sqlRowAccessor : rows) {
|
561 |
for (SQLRowAccessor sqlRowAccessor : rows) {
|
562 |
if (sqlRowAccessor.getForeignID("ID_CATEGORIE_COMPTABLE") == this.rowCatComptable.getID()) {
|
562 |
if (sqlRowAccessor.getForeignID("ID_CATEGORIE_COMPTABLE") == this.rowCatComptable.getID()) {
|
563 |
if (!sqlRowAccessor.isForeignEmpty("ID_COMPTE_PCE" + suffix)) {
|
563 |
if (!sqlRowAccessor.isForeignEmpty("ID_COMPTE_PCE" + suffix)) {
|
564 |
cptCatComptable = cacheForTableCompte.getRowFromId(sqlRowAccessor.getForeignID("ID_COMPTE_PCE" + suffix));
|
564 |
cptCatComptable = cacheForTableCompte.getRowFromId(sqlRowAccessor.getForeignID("ID_COMPTE_PCE" + suffix));
|
565 |
}
|
565 |
}
|
566 |
}
|
566 |
}
|
567 |
}
|
567 |
}
|
568 |
}
|
568 |
}
|
569 |
if (cptCatComptable == null) {
|
569 |
if (cptCatComptable == null) {
|
570 |
String suffix = (this.achat ? "_ACHAT" : "");
|
570 |
String suffix = (this.achat ? "_ACHAT" : "");
|
571 |
SQLRowAccessor compteArticle = cacheForTableCompte.getRowFromId(article.getForeignID("ID_COMPTE_PCE" + suffix));
|
571 |
SQLRowAccessor compteArticle = cacheForTableCompte.getRowFromId(article.getForeignID("ID_COMPTE_PCE" + suffix));
|
572 |
if (compteArticle != null && !compteArticle.isUndefined()) {
|
572 |
if (compteArticle != null && !compteArticle.isUndefined()) {
|
573 |
cpt = compteArticle;
|
573 |
cpt = compteArticle;
|
574 |
} else {
|
574 |
} else {
|
- |
|
575 |
final SQLBackgroundTableCacheItem cacheForTableFamille = SQLBackgroundTableCache.getInstance().getCacheForTable(article.getTable().getForeignTable("ID_FAMILLE_ARTICLE"));
|
- |
|
576 |
|
575 |
SQLRowAccessor familleArticle = article.getForeign("ID_FAMILLE_ARTICLE");
|
577 |
SQLRowAccessor familleArticle = cacheForTableFamille.getRowFromId(article.getForeignID("ID_FAMILLE_ARTICLE"));
|
576 |
Set<SQLRowAccessor> unique = new HashSet<SQLRowAccessor>();
|
578 |
Set<SQLRowAccessor> unique = new HashSet<SQLRowAccessor>();
|
577 |
while (familleArticle != null && !familleArticle.isUndefined() && !unique.contains(familleArticle)) {
|
579 |
while (familleArticle != null && !familleArticle.isUndefined() && !unique.contains(familleArticle)) {
|
578 |
|
580 |
|
579 |
unique.add(familleArticle);
|
581 |
unique.add(familleArticle);
|
580 |
if (familleArticle.getObject("ID_COMPTE_PCE" + suffix) != null && !familleArticle.isForeignEmpty("ID_COMPTE_PCE" + suffix)) {
|
582 |
if (familleArticle.getObject("ID_COMPTE_PCE" + suffix) != null && !familleArticle.isForeignEmpty("ID_COMPTE_PCE" + suffix)) {
|
581 |
SQLRowAccessor compteFamilleArticle = cacheForTableCompte.getRowFromId(familleArticle.getForeignID("ID_COMPTE_PCE" + suffix));
|
583 |
SQLRowAccessor compteFamilleArticle = cacheForTableCompte.getRowFromId(familleArticle.getForeignID("ID_COMPTE_PCE" + suffix));
|
582 |
if (compteFamilleArticle != null && !compteFamilleArticle.isUndefined()) {
|
584 |
if (compteFamilleArticle != null && !compteFamilleArticle.isUndefined()) {
|
583 |
cpt = compteFamilleArticle;
|
585 |
cpt = compteFamilleArticle;
|
584 |
break;
|
586 |
break;
|
585 |
}
|
587 |
}
|
586 |
}
|
588 |
}
|
587 |
familleArticle = familleArticle.getForeign("ID_FAMILLE_ARTICLE_PERE");
|
589 |
familleArticle = cacheForTableFamille.getRowFromId(familleArticle.getForeignID("ID_FAMILLE_ARTICLE_PERE"));
|
588 |
}
|
590 |
}
|
589 |
}
|
591 |
}
|
590 |
} else {
|
592 |
} else {
|
591 |
cpt = cptCatComptable;
|
593 |
cpt = cptCatComptable;
|
592 |
}
|
594 |
}
|
593 |
}
|
595 |
}
|
594 |
if (!this.achat) {
|
596 |
if (!this.achat) {
|
595 |
SQLRowAccessor taxeCompl = (article.getFields().contains("ID_TAXE_COMPLEMENTAIRE") && article.getObject("ID_TAXE_COMPLEMENTAIRE") != null
|
597 |
SQLRowAccessor taxeCompl = (article.getFields().contains("ID_TAXE_COMPLEMENTAIRE") && article.getObject("ID_TAXE_COMPLEMENTAIRE") != null
|
596 |
&& !article.isForeignEmpty("ID_TAXE_COMPLEMENTAIRE") ? article.getForeign("ID_TAXE_COMPLEMENTAIRE") : null);
|
598 |
&& !article.isForeignEmpty("ID_TAXE_COMPLEMENTAIRE") ? article.getForeign("ID_TAXE_COMPLEMENTAIRE") : null);
|
597 |
if (taxeCompl != null && !taxeCompl.isUndefined()) {
|
599 |
if (taxeCompl != null && !taxeCompl.isUndefined()) {
|
598 |
|
600 |
|
599 |
Map<SQLRowAccessor, BigDecimal> mapCptTaxeValue = this.mapHtTaxeCompl.get(cpt);
|
601 |
Map<SQLRowAccessor, BigDecimal> mapCptTaxeValue = this.mapHtTaxeCompl.get(cpt);
|
600 |
if (mapCptTaxeValue == null) {
|
602 |
if (mapCptTaxeValue == null) {
|
601 |
mapCptTaxeValue = new HashMap<SQLRowAccessor, BigDecimal>();
|
603 |
mapCptTaxeValue = new HashMap<SQLRowAccessor, BigDecimal>();
|
602 |
this.mapHtTaxeCompl.put(cpt, mapCptTaxeValue);
|
604 |
this.mapHtTaxeCompl.put(cpt, mapCptTaxeValue);
|
603 |
}
|
605 |
}
|
604 |
BigDecimal b = mapCptTaxeValue.get(taxeCompl);
|
606 |
BigDecimal b = mapCptTaxeValue.get(taxeCompl);
|
605 |
if (b == null) {
|
607 |
if (b == null) {
|
606 |
b = BigDecimal.ZERO;
|
608 |
b = BigDecimal.ZERO;
|
607 |
}
|
609 |
}
|
608 |
b = b.add(totalLineHT);
|
610 |
b = b.add(totalLineHT);
|
609 |
mapCptTaxeValue.put(taxeCompl, b);
|
611 |
mapCptTaxeValue.put(taxeCompl, b);
|
610 |
}
|
612 |
}
|
611 |
}
|
613 |
}
|
612 |
}
|
614 |
}
|
613 |
|
615 |
|
614 |
if (!compteSpec) {
|
616 |
if (!compteSpec) {
|
615 |
// Total Service
|
617 |
// Total Service
|
616 |
if (this.bServiceActive != null && this.bServiceActive) {
|
618 |
if (this.bServiceActive != null && this.bServiceActive) {
|
617 |
if (service != null && service.booleanValue()) {
|
619 |
if (service != null && service.booleanValue()) {
|
618 |
this.totalService = this.totalService.add(totalLineHT);
|
620 |
this.totalService = this.totalService.add(totalLineHT);
|
619 |
cpt = this.rowDefaultCptService;
|
621 |
cpt = this.rowDefaultCptService;
|
620 |
}
|
622 |
}
|
621 |
}
|
623 |
}
|
622 |
}
|
624 |
}
|
623 |
|
625 |
|
624 |
// Total HA
|
626 |
// Total HA
|
625 |
this.totalHA = this.totalHA.add(totalHALigne);
|
627 |
this.totalHA = this.totalHA.add(totalHALigne);
|
626 |
|
628 |
|
627 |
// Total Devise
|
629 |
// Total Devise
|
628 |
if (totalLineDevise != null) {
|
630 |
if (totalLineDevise != null) {
|
629 |
this.totalDevise = this.totalDevise.add(totalLineDevise);
|
631 |
this.totalDevise = this.totalDevise.add(totalLineDevise);
|
630 |
}
|
632 |
}
|
631 |
|
633 |
|
632 |
// Total Poids
|
634 |
// Total Poids
|
633 |
|
635 |
|
634 |
this.totalPoids += nPoids == null ? 0 : nPoids.doubleValue();
|
636 |
this.totalPoids += nPoids == null ? 0 : nPoids.doubleValue();
|
635 |
|
637 |
|
636 |
// Eco-contribution
|
638 |
// Eco-contribution
|
637 |
this.totalEco = this.totalEco.add(totalLineEco);
|
639 |
this.totalEco = this.totalEco.add(totalLineEco);
|
638 |
|
640 |
|
639 |
// Calcul total sélectionné
|
641 |
// Calcul total sélectionné
|
640 |
boolean selection = containsInt(this.selectedRows, lineNumber);
|
642 |
boolean selection = containsInt(this.selectedRows, lineNumber);
|
641 |
if (selection) {
|
643 |
if (selection) {
|
642 |
|
644 |
|
643 |
this.totalHASel = this.totalHASel.add(totalHALigne);
|
645 |
this.totalHASel = this.totalHASel.add(totalHALigne);
|
644 |
|
646 |
|
645 |
if (this.bServiceActive != null && this.bServiceActive) {
|
647 |
if (this.bServiceActive != null && this.bServiceActive) {
|
646 |
if (service != null && service.booleanValue()) {
|
648 |
if (service != null && service.booleanValue()) {
|
647 |
this.totalServiceSel = this.totalServiceSel.add(totalLineHT);
|
649 |
this.totalServiceSel = this.totalServiceSel.add(totalLineHT);
|
648 |
}
|
650 |
}
|
649 |
}
|
651 |
}
|
650 |
this.totalEcoSel = this.totalEcoSel.add(totalLineEco);
|
652 |
this.totalEcoSel = this.totalEcoSel.add(totalLineEco);
|
651 |
|
653 |
|
652 |
if (totalLineDevise != null) {
|
654 |
if (totalLineDevise != null) {
|
653 |
this.totalDeviseSel = this.totalDeviseSel.add(totalLineDevise);
|
655 |
this.totalDeviseSel = this.totalDeviseSel.add(totalLineDevise);
|
654 |
}
|
656 |
}
|
655 |
}
|
657 |
}
|
656 |
|
658 |
|
657 |
addHT(totalLineHT, totalLineHTSansFacturable, tva, cpt, selection);
|
659 |
addHT(totalLineHT, totalLineHTSansFacturable, tva, cpt, selection);
|
658 |
}
|
660 |
}
|
659 |
|
661 |
|
660 |
/**
|
662 |
/**
|
661 |
* Vérifie si ht + tva = ttc
|
663 |
* Vérifie si ht + tva = ttc
|
662 |
*/
|
664 |
*/
|
663 |
public void checkResult() {
|
665 |
public void checkResult() {
|
664 |
BigDecimal ht = getTotalHT();
|
666 |
BigDecimal ht = getTotalHT();
|
665 |
BigDecimal tva = getTotalTVA();
|
667 |
BigDecimal tva = getTotalTVA();
|
666 |
BigDecimal totalTTC2 = getTotalTTC();
|
668 |
BigDecimal totalTTC2 = getTotalTTC();
|
667 |
BigDecimal reste = totalTTC2.subtract(ht.add(tva));
|
669 |
BigDecimal reste = totalTTC2.subtract(ht.add(tva));
|
668 |
if (!this.intraComm && reste.compareTo(BigDecimal.ZERO) != 0) {
|
670 |
if (!this.intraComm && reste.compareTo(BigDecimal.ZERO) != 0) {
|
669 |
System.err.print("Ecarts: " + reste + "(HT:" + ht);
|
671 |
System.err.print("Ecarts: " + reste + "(HT:" + ht);
|
670 |
System.err.print(" TVA:" + tva);
|
672 |
System.err.print(" TVA:" + tva);
|
671 |
System.err.println(" TTC:" + totalTTC2);
|
673 |
System.err.println(" TTC:" + totalTTC2);
|
672 |
|
674 |
|
673 |
// TODO Check if row already exist in MAP ??
|
675 |
// TODO Check if row already exist in MAP ??
|
674 |
if (!this.imputEcart) {
|
676 |
if (!this.imputEcart) {
|
675 |
for (SQLRowAccessor rHT : this.mapHt.keySet()) {
|
677 |
for (SQLRowAccessor rHT : this.mapHt.keySet()) {
|
676 |
BigDecimal input = this.mapHt.get(rHT);
|
678 |
BigDecimal input = this.mapHt.get(rHT);
|
677 |
if (input != null && input.signum() != 0) {
|
679 |
if (input != null && input.signum() != 0) {
|
678 |
this.mapHt.put(rHT, input.add(reste));
|
680 |
this.mapHt.put(rHT, input.add(reste));
|
679 |
break;
|
681 |
break;
|
680 |
}
|
682 |
}
|
681 |
}
|
683 |
}
|
682 |
} else {
|
684 |
} else {
|
683 |
SQLRow row = ComptePCESQLElement.getRow("758", "Ecarts arrondis");
|
685 |
SQLRow row = ComptePCESQLElement.getRow("758", "Ecarts arrondis");
|
684 |
this.mapHt.put(row, reste);
|
686 |
this.mapHt.put(row, reste);
|
685 |
}
|
687 |
}
|
686 |
}
|
688 |
}
|
687 |
}
|
689 |
}
|
688 |
|
690 |
|
689 |
public BigDecimal getTotalDevise() {
|
691 |
public BigDecimal getTotalDevise() {
|
690 |
return this.totalDevise;
|
692 |
return this.totalDevise;
|
691 |
}
|
693 |
}
|
692 |
|
694 |
|
693 |
public BigDecimal getTotalDeviseSel() {
|
695 |
public BigDecimal getTotalDeviseSel() {
|
694 |
return this.totalDeviseSel;
|
696 |
return this.totalDeviseSel;
|
695 |
}
|
697 |
}
|
696 |
|
698 |
|
697 |
public BigDecimal getTotalHA() {
|
699 |
public BigDecimal getTotalHA() {
|
698 |
return this.totalHA;
|
700 |
return this.totalHA;
|
699 |
}
|
701 |
}
|
700 |
|
702 |
|
701 |
public BigDecimal getTotalHASel() {
|
703 |
public BigDecimal getTotalHASel() {
|
702 |
return this.totalHASel;
|
704 |
return this.totalHASel;
|
703 |
}
|
705 |
}
|
704 |
|
706 |
|
705 |
public double getTotalPoids() {
|
707 |
public double getTotalPoids() {
|
706 |
return this.totalPoids;
|
708 |
return this.totalPoids;
|
707 |
}
|
709 |
}
|
708 |
|
710 |
|
709 |
public BigDecimal getTotalService() {
|
711 |
public BigDecimal getTotalService() {
|
710 |
return this.totalService;
|
712 |
return this.totalService;
|
711 |
}
|
713 |
}
|
712 |
|
714 |
|
713 |
public BigDecimal getTotalServiceSel() {
|
715 |
public BigDecimal getTotalServiceSel() {
|
714 |
return this.totalServiceSel;
|
716 |
return this.totalServiceSel;
|
715 |
}
|
717 |
}
|
716 |
|
718 |
|
717 |
public Map<SQLRowAccessor, Map<SQLRowAccessor, BigDecimal>> getMapHtTaxeCompl() {
|
719 |
public Map<SQLRowAccessor, Map<SQLRowAccessor, BigDecimal>> getMapHtTaxeCompl() {
|
718 |
return this.mapHtTaxeCompl;
|
720 |
return this.mapHtTaxeCompl;
|
719 |
}
|
721 |
}
|
720 |
|
722 |
|
721 |
public BigDecimal getTotalHT() {
|
723 |
public BigDecimal getTotalHT() {
|
722 |
BigDecimal ht = BigDecimal.ZERO;
|
724 |
BigDecimal ht = BigDecimal.ZERO;
|
723 |
for (SQLRowAccessor row : this.mapHt.keySet()) {
|
725 |
for (SQLRowAccessor row : this.mapHt.keySet()) {
|
724 |
ht = ht.add(this.mapHt.get(row).setScale(2, RoundingMode.HALF_UP));
|
726 |
ht = ht.add(this.mapHt.get(row).setScale(2, RoundingMode.HALF_UP));
|
725 |
}
|
727 |
}
|
726 |
|
728 |
|
727 |
return ht;
|
729 |
return ht;
|
728 |
}
|
730 |
}
|
729 |
|
731 |
|
730 |
public BigDecimal getTotalTVA() {
|
732 |
public BigDecimal getTotalTVA() {
|
731 |
BigDecimal tva = BigDecimal.ZERO;
|
733 |
BigDecimal tva = BigDecimal.ZERO;
|
732 |
for (SQLRowAccessor row : this.mapHtTVA.keySet()) {
|
734 |
for (SQLRowAccessor row : this.mapHtTVA.keySet()) {
|
733 |
tva = tva.add(this.mapHtTVA.get(row).setScale(2, RoundingMode.HALF_UP));
|
735 |
tva = tva.add(this.mapHtTVA.get(row).setScale(2, RoundingMode.HALF_UP));
|
734 |
}
|
736 |
}
|
735 |
return tva;
|
737 |
return tva;
|
736 |
}
|
738 |
}
|
737 |
|
739 |
|
738 |
public BigDecimal getTotalEco() {
|
740 |
public BigDecimal getTotalEco() {
|
739 |
return this.totalEco.setScale(2, RoundingMode.HALF_UP);
|
741 |
return this.totalEco.setScale(2, RoundingMode.HALF_UP);
|
740 |
}
|
742 |
}
|
741 |
|
743 |
|
742 |
public BigDecimal getTotalEcoSel() {
|
744 |
public BigDecimal getTotalEcoSel() {
|
743 |
return this.totalEcoSel.setScale(2, RoundingMode.HALF_UP);
|
745 |
return this.totalEcoSel.setScale(2, RoundingMode.HALF_UP);
|
744 |
}
|
746 |
}
|
745 |
|
747 |
|
746 |
public BigDecimal getTotalHTSansFActurable() {
|
748 |
public BigDecimal getTotalHTSansFActurable() {
|
747 |
return this.totalHTSansFActurable;
|
749 |
return this.totalHTSansFActurable;
|
748 |
}
|
750 |
}
|
749 |
|
751 |
|
750 |
public BigDecimal getTotalTTC() {
|
752 |
public BigDecimal getTotalTTC() {
|
751 |
return this.totalTTC.setScale(2, RoundingMode.HALF_UP);
|
753 |
return this.totalTTC.setScale(2, RoundingMode.HALF_UP);
|
752 |
}
|
754 |
}
|
753 |
|
755 |
|
754 |
public BigDecimal getTotalHTSel() {
|
756 |
public BigDecimal getTotalHTSel() {
|
755 |
BigDecimal ht = BigDecimal.ZERO;
|
757 |
BigDecimal ht = BigDecimal.ZERO;
|
756 |
for (SQLRowAccessor row : this.mapHtSel.keySet()) {
|
758 |
for (SQLRowAccessor row : this.mapHtSel.keySet()) {
|
757 |
ht = ht.add(this.mapHtSel.get(row).setScale(2, RoundingMode.HALF_UP));
|
759 |
ht = ht.add(this.mapHtSel.get(row).setScale(2, RoundingMode.HALF_UP));
|
758 |
}
|
760 |
}
|
759 |
|
761 |
|
760 |
return ht;
|
762 |
return ht;
|
761 |
}
|
763 |
}
|
762 |
|
764 |
|
763 |
public BigDecimal getTotalTVASel() {
|
765 |
public BigDecimal getTotalTVASel() {
|
764 |
BigDecimal tva = BigDecimal.ZERO;
|
766 |
BigDecimal tva = BigDecimal.ZERO;
|
765 |
for (SQLRowAccessor row : this.mapHtTVASel.keySet()) {
|
767 |
for (SQLRowAccessor row : this.mapHtTVASel.keySet()) {
|
766 |
tva = tva.add(this.mapHtTVASel.get(row).setScale(2, RoundingMode.HALF_UP));
|
768 |
tva = tva.add(this.mapHtTVASel.get(row).setScale(2, RoundingMode.HALF_UP));
|
767 |
}
|
769 |
}
|
768 |
return tva;
|
770 |
return tva;
|
769 |
}
|
771 |
}
|
770 |
|
772 |
|
771 |
public BigDecimal getTotalTTCSel() {
|
773 |
public BigDecimal getTotalTTCSel() {
|
772 |
|
774 |
|
773 |
return this.totalTTCSel.setScale(2, RoundingMode.HALF_UP);
|
775 |
return this.totalTTCSel.setScale(2, RoundingMode.HALF_UP);
|
774 |
}
|
776 |
}
|
775 |
|
777 |
|
776 |
public Map<SQLRowAccessor, BigDecimal> getMapHt() {
|
778 |
public Map<SQLRowAccessor, BigDecimal> getMapHt() {
|
777 |
return this.mapHt;
|
779 |
return this.mapHt;
|
778 |
}
|
780 |
}
|
779 |
|
781 |
|
780 |
public Map<SQLRowAccessor, Tuple2<BigDecimal, BigDecimal>> getMapHtTVARowTaux() {
|
782 |
public Map<SQLRowAccessor, Tuple2<BigDecimal, BigDecimal>> getMapHtTVARowTaux() {
|
781 |
return this.mapHtTVARowTaux;
|
783 |
return this.mapHtTVARowTaux;
|
782 |
}
|
784 |
}
|
783 |
|
785 |
|
784 |
public Map<SQLRowAccessor, BigDecimal> getMapHtTVA() {
|
786 |
public Map<SQLRowAccessor, BigDecimal> getMapHtTVA() {
|
785 |
return this.mapHtTVA;
|
787 |
return this.mapHtTVA;
|
786 |
}
|
788 |
}
|
787 |
|
789 |
|
788 |
public Map<SQLRowAccessor, BigDecimal> getMapHtTVAIntra() {
|
790 |
public Map<SQLRowAccessor, BigDecimal> getMapHtTVAIntra() {
|
789 |
return this.mapHtTVAIntra;
|
791 |
return this.mapHtTVAIntra;
|
790 |
}
|
792 |
}
|
791 |
}
|
793 |
}
|