Line 15... |
Line 15... |
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;
|
- |
|
21 |
import org.openconcerto.sql.model.SQLBackgroundTableCacheItem;
|
20 |
import org.openconcerto.sql.model.SQLRow;
|
22 |
import org.openconcerto.sql.model.SQLRow;
|
21 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
23 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
22 |
import org.openconcerto.sql.model.SQLRowValues;
|
24 |
import org.openconcerto.sql.model.SQLRowValues;
|
23 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
25 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
24 |
import org.openconcerto.sql.model.SQLTable;
|
26 |
import org.openconcerto.sql.model.SQLTable;
|
Line 26... |
Line 28... |
26 |
import org.openconcerto.utils.DecimalUtils;
|
28 |
import org.openconcerto.utils.DecimalUtils;
|
27 |
import org.openconcerto.utils.Tuple2;
|
29 |
import org.openconcerto.utils.Tuple2;
|
28 |
|
30 |
|
29 |
import java.math.BigDecimal;
|
31 |
import java.math.BigDecimal;
|
30 |
import java.math.RoundingMode;
|
32 |
import java.math.RoundingMode;
|
- |
|
33 |
import java.util.Collection;
|
31 |
import java.util.HashMap;
|
34 |
import java.util.HashMap;
|
32 |
import java.util.HashSet;
|
35 |
import java.util.HashSet;
|
33 |
import java.util.List;
|
36 |
import java.util.List;
|
34 |
import java.util.Map;
|
37 |
import java.util.Map;
|
35 |
import java.util.Set;
|
38 |
import java.util.Set;
|
Line 40... |
Line 43... |
40 |
private static String FIELD_POIDS = "T_POIDS";
|
43 |
private static String FIELD_POIDS = "T_POIDS";
|
41 |
private final String fieldHT, fieldHA, fieldDevise;
|
44 |
private final String fieldHT, fieldHA, fieldDevise;
|
42 |
private boolean imputEcart = true;
|
45 |
private boolean imputEcart = true;
|
43 |
private SQLRowAccessor rowDefaultCptProduit, rowDefaultCptService, rowDefaultCptTVACollecte, rowDefaultCptTVADeductible, rowDefaultCptAchat;
|
46 |
private SQLRowAccessor rowDefaultCptProduit, rowDefaultCptService, rowDefaultCptTVACollecte, rowDefaultCptTVADeductible, rowDefaultCptAchat;
|
44 |
|
47 |
|
- |
|
48 |
private final SQLRowAccessor rowCatComptable;
|
- |
|
49 |
|
45 |
private SQLRowAccessor rowDefaultCptProduitStandard;
|
50 |
private SQLRowAccessor rowDefaultCptProduitStandard;
|
46 |
|
51 |
|
47 |
private double totalPoids;
|
52 |
private double totalPoids;
|
48 |
|
53 |
|
49 |
private BigDecimal totalDevise, totalDeviseSel;
|
54 |
private BigDecimal totalDevise, totalDeviseSel;
|
Line 70... |
Line 75... |
70 |
|
75 |
|
71 |
private Boolean bServiceActive;
|
76 |
private Boolean bServiceActive;
|
72 |
private BigDecimal totalHTAvantRemise;
|
77 |
private BigDecimal totalHTAvantRemise;
|
73 |
private boolean intraComm = false;
|
78 |
private boolean intraComm = false;
|
74 |
|
79 |
|
75 |
public TotalCalculator(String fieldHA, String fieldHT, String fieldDeviseTotal) {
|
80 |
public TotalCalculator(String fieldHA, String fieldHT, String fieldDeviseTotal, SQLRowAccessor rowCatComptable) {
|
76 |
this(fieldHA, fieldHT, fieldDeviseTotal, false, null);
|
81 |
this(fieldHA, fieldHT, fieldDeviseTotal, false, null, rowCatComptable);
|
77 |
}
|
82 |
}
|
78 |
|
83 |
|
79 |
public void setRowDefaultCptService(SQLRowAccessor rowDefaultCptService) {
|
84 |
public void setRowDefaultCptService(SQLRowAccessor rowDefaultCptService) {
|
80 |
this.rowDefaultCptService = rowDefaultCptService;
|
85 |
this.rowDefaultCptService = rowDefaultCptService;
|
81 |
}
|
86 |
}
|
82 |
|
87 |
|
83 |
public void setIntraComm(boolean intraComm) {
|
88 |
public void setIntraComm(boolean intraComm) {
|
84 |
this.intraComm = intraComm;
|
89 |
this.intraComm = intraComm;
|
85 |
}
|
90 |
}
|
86 |
|
91 |
|
87 |
public TotalCalculator(String fieldHA, String fieldHT, String fieldDeviseTotal, boolean achat, SQLRowAccessor defaultCompte) {
|
92 |
public TotalCalculator(String fieldHA, String fieldHT, String fieldDeviseTotal, boolean achat, SQLRowAccessor defaultCompte, SQLRowAccessor rowCatComptable) {
|
88 |
|
93 |
|
89 |
this.achat = achat;
|
94 |
this.achat = achat;
|
90 |
initValues();
|
95 |
initValues();
|
91 |
|
96 |
|
92 |
this.fieldDevise = fieldDeviseTotal;
|
97 |
this.fieldDevise = fieldDeviseTotal;
|
93 |
this.fieldHA = fieldHA;
|
98 |
this.fieldHA = fieldHA;
|
94 |
this.fieldHT = fieldHT;
|
99 |
this.fieldHT = fieldHT;
|
95 |
final SQLTable tablePrefCompte = Configuration.getInstance().getRoot().findTable("PREFS_COMPTE");
|
100 |
final SQLTable tablePrefCompte = Configuration.getInstance().getRoot().findTable("PREFS_COMPTE");
|
- |
|
101 |
final SQLBackgroundTableCacheItem cacheForTablePref = SQLBackgroundTableCache.getInstance().getCacheForTable(tablePrefCompte);
|
- |
|
102 |
final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(tablePrefCompte.getTable("COMPTE_PCE"));
|
96 |
final SQLRow rowPrefsCompte = tablePrefCompte.getRow(2);
|
103 |
final SQLRow rowPrefsCompte = cacheForTablePref.getRowFromId(2);
|
- |
|
104 |
|
97 |
SQLPreferences prefs = SQLPreferences.getMemCached(tablePrefCompte.getDBRoot());
|
105 |
SQLPreferences prefs = SQLPreferences.getMemCached(tablePrefCompte.getDBRoot());
|
98 |
this.imputEcart = prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.IMPUT_ECART, true);
|
106 |
this.imputEcart = prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.IMPUT_ECART, true);
|
99 |
|
107 |
|
100 |
// FIXME faire un fetcher pour ne pas faire 5 requetes (1 par getForeign)
|
108 |
// FIXME faire un fetcher pour ne pas faire 5 requetes (1 par getForeign)
|
101 |
// Comptes par défaut
|
109 |
// Comptes par défaut
|
102 |
this.rowDefaultCptService = rowPrefsCompte.getForeign("ID_COMPTE_PCE_VENTE_SERVICE");
|
110 |
this.rowDefaultCptService = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_VENTE_SERVICE"));
|
103 |
if (this.rowDefaultCptService == null || this.rowDefaultCptService.isUndefined()) {
|
111 |
if (this.rowDefaultCptService == null || this.rowDefaultCptService.isUndefined()) {
|
104 |
try {
|
112 |
try {
|
105 |
this.rowDefaultCptService = ComptePCESQLElement.getRowComptePceDefault("VentesServices");
|
113 |
this.rowDefaultCptService = ComptePCESQLElement.getRowComptePceDefault("VentesServices");
|
106 |
} catch (Exception e) {
|
114 |
} catch (Exception e) {
|
107 |
e.printStackTrace();
|
115 |
e.printStackTrace();
|
108 |
}
|
116 |
}
|
109 |
}
|
117 |
}
|
110 |
|
118 |
|
- |
|
119 |
this.rowCatComptable = rowCatComptable;
|
- |
|
120 |
|
111 |
if (defaultCompte == null || defaultCompte.isUndefined()) {
|
121 |
if (defaultCompte == null || defaultCompte.isUndefined()) {
|
- |
|
122 |
|
- |
|
123 |
if (rowCatComptable != null && !rowCatComptable.isUndefined() && !rowCatComptable.isForeignEmpty("ID_COMPTE_PCE_VENTE")) {
|
- |
|
124 |
this.rowDefaultCptProduit = cacheForTableCompte.getRowFromId(rowCatComptable.getForeignID("ID_COMPTE_PCE_VENTE"));
|
- |
|
125 |
} else {
|
112 |
this.rowDefaultCptProduit = rowPrefsCompte.getForeign("ID_COMPTE_PCE_VENTE_PRODUIT");
|
126 |
this.rowDefaultCptProduit = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_VENTE_PRODUIT"));
|
113 |
if (this.rowDefaultCptProduit == null || this.rowDefaultCptProduit.isUndefined()) {
|
127 |
if (this.rowDefaultCptProduit == null || this.rowDefaultCptProduit.isUndefined()) {
|
114 |
try {
|
128 |
try {
|
115 |
this.rowDefaultCptProduit = ComptePCESQLElement.getRowComptePceDefault("VentesProduits");
|
129 |
this.rowDefaultCptProduit = ComptePCESQLElement.getRowComptePceDefault("VentesProduits");
|
116 |
} catch (Exception e) {
|
130 |
} catch (Exception e) {
|
117 |
e.printStackTrace();
|
131 |
e.printStackTrace();
|
118 |
}
|
132 |
}
|
119 |
}
|
133 |
}
|
- |
|
134 |
}
|
120 |
} else {
|
135 |
} else {
|
121 |
this.rowDefaultCptProduit = defaultCompte;
|
136 |
this.rowDefaultCptProduit = defaultCompte;
|
122 |
}
|
137 |
}
|
123 |
this.rowDefaultCptProduitStandard = this.rowDefaultCptProduit;
|
138 |
this.rowDefaultCptProduitStandard = this.rowDefaultCptProduit;
|
124 |
|
139 |
|
125 |
this.rowDefaultCptTVACollecte = rowPrefsCompte.getForeign("ID_COMPTE_PCE_TVA_VENTE");
|
140 |
this.rowDefaultCptTVACollecte = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_TVA_VENTE"));
|
126 |
if (this.rowDefaultCptTVACollecte == null || this.rowDefaultCptTVACollecte.isUndefined()) {
|
141 |
if (this.rowDefaultCptTVACollecte == null || this.rowDefaultCptTVACollecte.isUndefined()) {
|
127 |
try {
|
142 |
try {
|
128 |
this.rowDefaultCptTVACollecte = ComptePCESQLElement.getRowComptePceDefault("TVACollectee");
|
143 |
this.rowDefaultCptTVACollecte = ComptePCESQLElement.getRowComptePceDefault("TVACollectee");
|
129 |
} catch (Exception e) {
|
144 |
} catch (Exception e) {
|
130 |
e.printStackTrace();
|
145 |
e.printStackTrace();
|
131 |
}
|
146 |
}
|
132 |
}
|
147 |
}
|
133 |
|
148 |
|
134 |
this.rowDefaultCptTVADeductible = rowPrefsCompte.getForeign("ID_COMPTE_PCE_TVA_ACHAT");
|
149 |
this.rowDefaultCptTVADeductible = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_TVA_ACHAT"));
|
135 |
if (this.rowDefaultCptTVADeductible == null || this.rowDefaultCptTVADeductible.isUndefined()) {
|
150 |
if (this.rowDefaultCptTVADeductible == null || this.rowDefaultCptTVADeductible.isUndefined()) {
|
136 |
try {
|
151 |
try {
|
137 |
this.rowDefaultCptTVADeductible = ComptePCESQLElement.getRowComptePceDefault("TVADeductible");
|
152 |
this.rowDefaultCptTVADeductible = ComptePCESQLElement.getRowComptePceDefault("TVADeductible");
|
138 |
} catch (Exception e) {
|
153 |
} catch (Exception e) {
|
139 |
e.printStackTrace();
|
154 |
e.printStackTrace();
|
140 |
}
|
155 |
}
|
141 |
}
|
156 |
}
|
142 |
|
157 |
|
143 |
if (defaultCompte == null || defaultCompte.isUndefined()) {
|
158 |
if (defaultCompte == null || defaultCompte.isUndefined()) {
|
- |
|
159 |
if (rowCatComptable != null && !rowCatComptable.isUndefined() && !rowCatComptable.isForeignEmpty("ID_COMPTE_PCE_ACHAT")) {
|
- |
|
160 |
this.rowDefaultCptProduit = cacheForTableCompte.getRowFromId(rowCatComptable.getForeignID("ID_COMPTE_PCE_ACHAT"));
|
- |
|
161 |
} else {
|
144 |
this.rowDefaultCptAchat = rowPrefsCompte.getForeign("ID_COMPTE_PCE_ACHAT");
|
162 |
this.rowDefaultCptAchat = cacheForTableCompte.getRowFromId(rowPrefsCompte.getForeignID("ID_COMPTE_PCE_ACHAT"));
|
145 |
if (this.rowDefaultCptAchat == null || this.rowDefaultCptAchat.isUndefined()) {
|
163 |
if (this.rowDefaultCptAchat == null || this.rowDefaultCptAchat.isUndefined()) {
|
146 |
try {
|
164 |
try {
|
147 |
this.rowDefaultCptAchat = ComptePCESQLElement.getRowComptePceDefault("Achats");
|
165 |
this.rowDefaultCptAchat = ComptePCESQLElement.getRowComptePceDefault("Achats");
|
148 |
} catch (Exception e) {
|
166 |
} catch (Exception e) {
|
149 |
e.printStackTrace();
|
167 |
e.printStackTrace();
|
150 |
}
|
168 |
}
|
151 |
}
|
169 |
}
|
- |
|
170 |
}
|
152 |
} else {
|
171 |
} else {
|
153 |
this.rowDefaultCptAchat = defaultCompte;
|
172 |
this.rowDefaultCptAchat = defaultCompte;
|
154 |
}
|
173 |
}
|
155 |
|
174 |
|
156 |
}
|
175 |
}
|
Line 288... |
Line 307... |
288 |
|
307 |
|
289 |
private void addHT(BigDecimal ht, BigDecimal htSansFacturable, SQLRowAccessor tva, SQLRowAccessor cptArticle, boolean selection) {
|
308 |
private void addHT(BigDecimal ht, BigDecimal htSansFacturable, SQLRowAccessor tva, SQLRowAccessor cptArticle, boolean selection) {
|
290 |
|
309 |
|
291 |
BigDecimal ttc;
|
310 |
BigDecimal ttc;
|
292 |
BigDecimal totalTVA;
|
311 |
BigDecimal totalTVA;
|
- |
|
312 |
final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(cptArticle.getTable());
|
293 |
|
313 |
|
294 |
if (tva == null || tva.isUndefined()) {
|
314 |
if (tva == null || tva.isUndefined()) {
|
295 |
ttc = ht;
|
315 |
ttc = ht;
|
296 |
totalTVA = BigDecimal.ZERO;
|
316 |
totalTVA = BigDecimal.ZERO;
|
297 |
} else {
|
317 |
} else {
|
Line 303... |
Line 323... |
303 |
if (tva != null && !tva.isUndefined()) {
|
323 |
if (tva != null && !tva.isUndefined()) {
|
304 |
SQLRowAccessor rowCptTva;
|
324 |
SQLRowAccessor rowCptTva;
|
305 |
if (this.intraComm) {
|
325 |
if (this.intraComm) {
|
306 |
|
326 |
|
307 |
// Intra comm TTC=HT et solde de TVA
|
327 |
// Intra comm TTC=HT et solde de TVA
|
308 |
rowCptTva = tva.getForeign("ID_COMPTE_PCE_DED_INTRA");
|
328 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED_INTRA"));
|
309 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
329 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
310 |
rowCptTva = this.rowDefaultCptTVADeductible;
|
330 |
rowCptTva = this.rowDefaultCptTVADeductible;
|
311 |
}
|
331 |
}
|
312 |
|
332 |
|
313 |
SQLRowAccessor rowCptTvaIntra = tva.getForeign("ID_COMPTE_PCE_COLLECTE_INTRA");
|
333 |
SQLRowAccessor rowCptTvaIntra = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE_INTRA"));
|
314 |
if (rowCptTvaIntra == null || rowCptTvaIntra.isUndefined()) {
|
334 |
if (rowCptTvaIntra == null || rowCptTvaIntra.isUndefined()) {
|
315 |
rowCptTvaIntra = this.rowDefaultCptTVADeductible;
|
335 |
rowCptTvaIntra = this.rowDefaultCptTVADeductible;
|
316 |
}
|
336 |
}
|
- |
|
337 |
|
317 |
if (mapHtTVAIntra.get(rowCptTvaIntra) == null) {
|
338 |
if (mapHtTVAIntra.get(rowCptTvaIntra) == null) {
|
318 |
mapHtTVAIntra.put(rowCptTvaIntra, totalTVA);
|
339 |
mapHtTVAIntra.put(rowCptTvaIntra, totalTVA);
|
- |
|
340 |
} else {
|
- |
|
341 |
BigDecimal l = mapHtTVAIntra.get(rowCptTvaIntra);
|
- |
|
342 |
mapHtTVAIntra.put(rowCptTvaIntra, l.add(totalTVA));
|
319 |
}
|
343 |
}
|
320 |
|
344 |
|
321 |
ht = ttc;
|
345 |
ttc = ht;
|
322 |
} else if (this.achat) {
|
346 |
} else if (this.achat) {
|
323 |
rowCptTva = tva.getForeign("ID_COMPTE_PCE_DED");
|
347 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED"));
|
324 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
348 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
325 |
rowCptTva = this.rowDefaultCptTVADeductible;
|
349 |
rowCptTva = this.rowDefaultCptTVADeductible;
|
326 |
}
|
350 |
}
|
327 |
} else {
|
351 |
} else {
|
328 |
rowCptTva = tva.getForeign("ID_COMPTE_PCE_COLLECTE");
|
352 |
rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE"));
|
329 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
353 |
if (rowCptTva == null || rowCptTva.isUndefined()) {
|
330 |
rowCptTva = this.rowDefaultCptTVACollecte;
|
354 |
rowCptTva = this.rowDefaultCptTVACollecte;
|
331 |
}
|
355 |
}
|
332 |
}
|
356 |
}
|
333 |
if (mapHtTVA.get(rowCptTva) == null) {
|
357 |
if (mapHtTVA.get(rowCptTva) == null) {
|
Line 435... |
Line 459... |
435 |
|
459 |
|
436 |
// TODO : generaliser le cache
|
460 |
// TODO : generaliser le cache
|
437 |
if (mapTVA == null || lastTVAfetchedTime + 30 * 1000 < System.currentTimeMillis()) {
|
461 |
if (mapTVA == null || lastTVAfetchedTime + 30 * 1000 < System.currentTimeMillis()) {
|
438 |
fetchTVA();
|
462 |
fetchTVA();
|
439 |
}
|
463 |
}
|
440 |
final SQLRowAccessor foreignTVA = rowAccessorLine.getForeign("ID_TAXE");
|
- |
|
441 |
Integer idTVA = null;
|
464 |
Integer idTVA = null;
|
- |
|
465 |
if (rowAccessorLine.getObject("ID_TAXE") != null && !rowAccessorLine.isForeignEmpty("ID_TAXE")) {
|
- |
|
466 |
idTVA = rowAccessorLine.getForeignID("ID_TAXE");
|
- |
|
467 |
} else {
|
- |
|
468 |
final SQLRowAccessor foreignTVA = rowAccessorLine.getForeign("ID_TAXE");
|
442 |
if (foreignTVA != null) {
|
469 |
if (foreignTVA != null) {
|
443 |
idTVA = foreignTVA.getID();
|
470 |
idTVA = foreignTVA.getID();
|
444 |
}
|
471 |
}
|
- |
|
472 |
}
|
445 |
SQLRowAccessor tva = mapTVA.get(idTVA);
|
473 |
SQLRowAccessor tva = mapTVA.get(idTVA);
|
446 |
|
474 |
|
447 |
SQLRowAccessor cpt = (achat ? this.rowDefaultCptAchat : this.rowDefaultCptProduit);
|
475 |
SQLRowAccessor cpt = (achat ? this.rowDefaultCptAchat : this.rowDefaultCptProduit);
|
- |
|
476 |
final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(cpt.getTable());
|
- |
|
477 |
|
448 |
if (!achat) {
|
478 |
if (!achat) {
|
449 |
// Total Service
|
479 |
// Total Service
|
450 |
if (bServiceActive != null && bServiceActive && service != null && service.booleanValue()) {
|
480 |
if (bServiceActive != null && bServiceActive && service != null && service.booleanValue()) {
|
451 |
totalService = totalService.add(totalLineHT);
|
481 |
totalService = totalService.add(totalLineHT);
|
452 |
cpt = this.rowDefaultCptService;
|
482 |
cpt = this.rowDefaultCptService;
|
453 |
if (tva != null && !tva.isForeignEmpty("ID_COMPTE_PCE_VENTE_SERVICE")) {
|
483 |
if (tva != null && !tva.isForeignEmpty("ID_COMPTE_PCE_VENTE_SERVICE")) {
|
454 |
cpt = tva.getForeign("ID_COMPTE_PCE_VENTE_SERVICE");
|
484 |
cpt = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_VENTE_SERVICE"));
|
455 |
}
|
485 |
}
|
456 |
} else {
|
486 |
} else {
|
457 |
// Compte defini par défaut dans la TVA
|
487 |
// Compte defini par défaut dans la TVA
|
458 |
if (tva != null && !tva.isForeignEmpty("ID_COMPTE_PCE_VENTE")) {
|
488 |
if (tva != null && !tva.isForeignEmpty("ID_COMPTE_PCE_VENTE")) {
|
459 |
cpt = tva.getForeign("ID_COMPTE_PCE_VENTE");
|
489 |
cpt = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_VENTE"));
|
460 |
}
|
490 |
}
|
461 |
|
491 |
|
462 |
}
|
492 |
}
|
463 |
}
|
493 |
}
|
464 |
if (article != null && !article.isUndefined()) {
|
494 |
if (article != null && !article.isUndefined()) {
|
- |
|
495 |
SQLRowAccessor cptCatComptable = null;
|
- |
|
496 |
// TODO Optimiser les requetes
|
- |
|
497 |
if (rowCatComptable != null && !rowCatComptable.isUndefined()) {
|
- |
|
498 |
String suffix = (this.achat ? "_ACHAT" : "_VENTE");
|
- |
|
499 |
Collection<? extends SQLRowAccessor> rows = article.getReferentRows(compteTable.getTable("ARTICLE_CATEGORIE_COMPTABLE"));
|
- |
|
500 |
for (SQLRowAccessor sqlRowAccessor : rows) {
|
- |
|
501 |
if (sqlRowAccessor.getForeignID("ID_CATEGORIE_COMPTABLE") == this.rowCatComptable.getID()) {
|
- |
|
502 |
cptCatComptable = cacheForTableCompte.getRowFromId(rowCatComptable.getForeignID("ID_COMPTE_PCE" + suffix));
|
- |
|
503 |
}
|
- |
|
504 |
}
|
- |
|
505 |
}
|
- |
|
506 |
|
- |
|
507 |
if (cptCatComptable == null) {
|
465 |
String suffix = (this.achat ? "_ACHAT" : "");
|
508 |
String suffix = (this.achat ? "_ACHAT" : "");
|
466 |
SQLRowAccessor compteArticle = article.getForeign("ID_COMPTE_PCE" + suffix);
|
509 |
SQLRowAccessor compteArticle = cacheForTableCompte.getRowFromId(article.getForeignID("ID_COMPTE_PCE" + suffix));
|
467 |
if (compteArticle != null && !compteArticle.isUndefined()) {
|
510 |
if (compteArticle != null && !compteArticle.isUndefined()) {
|
468 |
cpt = compteArticle;
|
511 |
cpt = compteArticle;
|
469 |
} else {
|
512 |
} else {
|
470 |
SQLRowAccessor familleArticle = article.getForeign("ID_FAMILLE_ARTICLE");
|
513 |
SQLRowAccessor familleArticle = article.getForeign("ID_FAMILLE_ARTICLE");
|
471 |
Set<SQLRowAccessor> unique = new HashSet<SQLRowAccessor>();
|
514 |
Set<SQLRowAccessor> unique = new HashSet<SQLRowAccessor>();
|
472 |
while (familleArticle != null && !familleArticle.isUndefined() && !unique.contains(familleArticle)) {
|
515 |
while (familleArticle != null && !familleArticle.isUndefined() && !unique.contains(familleArticle)) {
|
473 |
|
516 |
|
474 |
unique.add(familleArticle);
|
517 |
unique.add(familleArticle);
|
- |
|
518 |
if (familleArticle.getObject("ID_COMPTE_PCE" + suffix) != null && !familleArticle.isForeignEmpty("ID_COMPTE_PCE" + suffix)) {
|
475 |
SQLRowAccessor compteFamilleArticle = familleArticle.getForeign("ID_COMPTE_PCE" + suffix);
|
519 |
SQLRowAccessor compteFamilleArticle = cacheForTableCompte.getRowFromId(familleArticle.getForeignID("ID_COMPTE_PCE" + suffix));
|
476 |
if (compteFamilleArticle != null && !compteFamilleArticle.isUndefined()) {
|
520 |
if (compteFamilleArticle != null && !compteFamilleArticle.isUndefined()) {
|
477 |
cpt = compteFamilleArticle;
|
521 |
cpt = compteFamilleArticle;
|
478 |
break;
|
522 |
break;
|
479 |
}
|
523 |
}
|
480 |
|
- |
|
- |
|
524 |
}
|
481 |
familleArticle = familleArticle.getForeign("ID_FAMILLE_ARTICLE_PERE");
|
525 |
familleArticle = familleArticle.getForeign("ID_FAMILLE_ARTICLE_PERE");
|
482 |
}
|
526 |
}
|
483 |
}
|
527 |
}
|
- |
|
528 |
} else {
|
- |
|
529 |
cpt = cptCatComptable;
|
- |
|
530 |
}
|
484 |
if (!achat) {
|
531 |
if (!achat) {
|
485 |
SQLRowAccessor taxeCompl = (article.getFields().contains("ID_TAXE_COMPLEMENTAIRE") && article.getObject("ID_TAXE_COMPLEMENTAIRE") != null
|
532 |
SQLRowAccessor taxeCompl = (article.getFields().contains("ID_TAXE_COMPLEMENTAIRE") && article.getObject("ID_TAXE_COMPLEMENTAIRE") != null
|
486 |
&& !article.isForeignEmpty("ID_TAXE_COMPLEMENTAIRE") ? article.getForeign("ID_TAXE_COMPLEMENTAIRE") : null);
|
533 |
&& !article.isForeignEmpty("ID_TAXE_COMPLEMENTAIRE") ? article.getForeign("ID_TAXE_COMPLEMENTAIRE") : null);
|
487 |
if (taxeCompl != null && !taxeCompl.isUndefined()) {
|
534 |
if (taxeCompl != null && !taxeCompl.isUndefined()) {
|
488 |
|
535 |
|