OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Rev 177 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 174
Line 19... Line 19...
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.SQLRowValues;
-
 
25
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
-
 
26
import org.openconcerto.sql.model.SQLTable;
24
import org.openconcerto.sql.model.SQLTable;
27
import org.openconcerto.sql.preferences.SQLPreferences;
25
import org.openconcerto.sql.preferences.SQLPreferences;
28
import org.openconcerto.utils.DecimalUtils;
26
import org.openconcerto.utils.DecimalUtils;
29
import org.openconcerto.utils.Tuple2;
27
import org.openconcerto.utils.Tuple2;
30
 
28
 
31
import java.math.BigDecimal;
29
import java.math.BigDecimal;
32
import java.math.RoundingMode;
30
import java.math.RoundingMode;
33
import java.util.Collection;
31
import java.util.Collection;
34
import java.util.HashMap;
32
import java.util.HashMap;
35
import java.util.HashSet;
33
import java.util.HashSet;
36
import java.util.List;
-
 
37
import java.util.Map;
34
import java.util.Map;
38
import java.util.Set;
35
import java.util.Set;
39
 
36
 
40
public class TotalCalculator {
37
public class TotalCalculator {
41
 
38
 
Line 177... Line 174...
177
    public void setRowDefaultCptProduit(SQLRowAccessor rowDefaultCptProduit) {
174
    public void setRowDefaultCptProduit(SQLRowAccessor rowDefaultCptProduit) {
178
        this.rowDefaultCptProduit = rowDefaultCptProduit;
175
        this.rowDefaultCptProduit = rowDefaultCptProduit;
179
    }
176
    }
180
 
177
 
181
    public void retoreRowDefaultCptProduit() {
178
    public void retoreRowDefaultCptProduit() {
182
        this.rowDefaultCptProduit = rowDefaultCptProduitStandard;
179
        this.rowDefaultCptProduit = this.rowDefaultCptProduitStandard;
183
    }
180
    }
184
 
181
 
185
    /**
182
    /**
186
     * Définition d'une remise HT à appliquer
183
     * Définition d'une remise HT à appliquer
187
     * 
184
     * 
Line 192... Line 189...
192
        this.remiseHT = remiseHT;
189
        this.remiseHT = remiseHT;
193
        this.remiseRestante = remiseHT;
190
        this.remiseRestante = remiseHT;
194
        this.totalHTAvantRemise = totalHTAvantRemise;
191
        this.totalHTAvantRemise = totalHTAvantRemise;
195
    }
192
    }
196
 
193
 
-
 
194
    public void addTVAAdjust(BigDecimal tvaFix) {
-
 
195
 
-
 
196
        final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(this.compteTable);
-
 
197
 
-
 
198
        SQLRowAccessor tva = TaxeCache.getCache().getFirstTaxe();
-
 
199
 
-
 
200
        SQLRowAccessor rowCptTva;
-
 
201
        if (this.intraComm) {
-
 
202
 
-
 
203
            // Intra comm TTC=HT et solde de TVA
-
 
204
            rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED_INTRA"));
-
 
205
            if (rowCptTva == null || rowCptTva.isUndefined()) {
-
 
206
                rowCptTva = this.rowDefaultCptTVADeductible;
-
 
207
            }
-
 
208
 
-
 
209
            SQLRowAccessor rowCptTvaIntra = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE_INTRA"));
-
 
210
            if (rowCptTvaIntra == null || rowCptTvaIntra.isUndefined()) {
-
 
211
                rowCptTvaIntra = this.rowDefaultCptTVADeductible;
-
 
212
            }
-
 
213
 
-
 
214
            if (this.mapHtTVAIntra.get(rowCptTvaIntra) == null) {
-
 
215
                this.mapHtTVAIntra.put(rowCptTvaIntra, tvaFix);
-
 
216
            } else {
-
 
217
                BigDecimal l = this.mapHtTVAIntra.get(rowCptTvaIntra);
-
 
218
                this.mapHtTVAIntra.put(rowCptTvaIntra, l.add(tvaFix));
-
 
219
            }
-
 
220
 
-
 
221
        } else if (this.achat) {
-
 
222
            rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED"));
-
 
223
            if (rowCptTva == null || rowCptTva.isUndefined()) {
-
 
224
                rowCptTva = this.rowDefaultCptTVADeductible;
-
 
225
            }
-
 
226
        } else {
-
 
227
            rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE"));
-
 
228
            if (rowCptTva == null || rowCptTva.isUndefined()) {
-
 
229
                rowCptTva = this.rowDefaultCptTVACollecte;
-
 
230
            }
-
 
231
        }
-
 
232
        if (this.mapHtTVA.get(rowCptTva) == null) {
-
 
233
            this.mapHtTVA.put(rowCptTva, tvaFix);
-
 
234
        } else {
-
 
235
            BigDecimal l = this.mapHtTVA.get(rowCptTva);
-
 
236
            this.mapHtTVA.put(rowCptTva, l.add(tvaFix));
-
 
237
        }
-
 
238
 
-
 
239
        this.totalTTC = this.totalTTC.add(tvaFix);
-
 
240
 
-
 
241
    }
-
 
242
 
197
    /**
243
    /**
198
     * Gestion de la vente de service
244
     * Gestion de la vente de service
199
     * 
245
     * 
200
     * @param b
246
     * @param b
201
     */
247
     */
Line 262... Line 308...
262
    /**
308
    /**
263
     * Mise en cache des comptes de TVA
309
     * Mise en cache des comptes de TVA
264
     */
310
     */
265
    private void fetchTVA() {
311
    private void fetchTVA() {
266
        mapTVA = new HashMap<Integer, SQLRowAccessor>();
312
        mapTVA = new HashMap<Integer, SQLRowAccessor>();
-
 
313
        Set<SQLRowAccessor> taxes = TaxeCache.getCache().getAllTaxe();
-
 
314
        for (SQLRowAccessor sqlRowAccessor : taxes) {
-
 
315
            mapTVA.put(sqlRowAccessor.getID(), sqlRowAccessor);
-
 
316
        }
267
        SQLRowValues rowVals = new SQLRowValues(tvaTable);
317
        // SQLRowValues rowVals = new SQLRowValues(this.tvaTable);
268
        SQLRowValues rowValsC1 = new SQLRowValues(compteTable);
318
        // SQLRowValues rowValsC1 = new SQLRowValues(this.compteTable);
269
        rowValsC1.put("NUMERO", null);
319
        // rowValsC1.put("NUMERO", null);
270
        rowValsC1.put("ID", null);
320
        // rowValsC1.put("ID", null);
271
 
321
        //
272
        SQLRowValues rowValsC2 = new SQLRowValues(compteTable);
322
        // SQLRowValues rowValsC2 = new SQLRowValues(this.compteTable);
273
        rowValsC2.put("NUMERO", null);
323
        // rowValsC2.put("NUMERO", null);
274
        rowValsC2.put("ID", null);
324
        // rowValsC2.put("ID", null);
275
 
325
        //
276
        SQLRowValues rowValsC3 = new SQLRowValues(compteTable);
326
        // SQLRowValues rowValsC3 = new SQLRowValues(this.compteTable);
277
        rowValsC3.put("NUMERO", null);
327
        // rowValsC3.put("NUMERO", null);
278
        rowValsC3.put("ID", null);
328
        // rowValsC3.put("ID", null);
279
        SQLRowValues rowValsC4 = new SQLRowValues(compteTable);
329
        // SQLRowValues rowValsC4 = new SQLRowValues(this.compteTable);
280
        rowValsC4.put("NUMERO", null);
330
        // rowValsC4.put("NUMERO", null);
281
        rowValsC4.put("ID", null);
331
        // rowValsC4.put("ID", null);
282
 
332
        //
283
        rowVals.put(tvaTable.getKey().getName(), null);
333
        // rowVals.put(this.tvaTable.getKey().getName(), null);
284
        rowVals.put("ID_COMPTE_PCE_COLLECTE", rowValsC1);
334
        // rowVals.put("ID_COMPTE_PCE_COLLECTE", rowValsC1);
285
        rowVals.put("ID_COMPTE_PCE_DED", rowValsC2);
335
        // rowVals.put("ID_COMPTE_PCE_DED", rowValsC2);
286
        rowVals.put("ID_COMPTE_PCE_VENTE", rowValsC3);
336
        // rowVals.put("ID_COMPTE_PCE_VENTE", rowValsC3);
287
        rowVals.put("ID_COMPTE_PCE_VENTE_SERVICE", rowValsC4);
337
        // rowVals.put("ID_COMPTE_PCE_VENTE_SERVICE", rowValsC4);
288
 
338
        //
289
        if (tvaTable.contains("ID_COMPTE_PCE_COLLECTE_INTRA")) {
339
        // if (this.tvaTable.contains("ID_COMPTE_PCE_COLLECTE_INTRA")) {
290
            SQLRowValues rowValsC1Intra = new SQLRowValues(compteTable);
340
        // SQLRowValues rowValsC1Intra = new SQLRowValues(this.compteTable);
291
            rowValsC1Intra.put("NUMERO", null);
341
        // rowValsC1Intra.put("NUMERO", null);
292
            rowValsC1Intra.put("ID", null);
342
        // rowValsC1Intra.put("ID", null);
293
            rowVals.put("ID_COMPTE_PCE_COLLECTE_INTRA", rowValsC1Intra);
343
        // rowVals.put("ID_COMPTE_PCE_COLLECTE_INTRA", rowValsC1Intra);
294
            SQLRowValues rowValsC2Intra = new SQLRowValues(compteTable);
344
        // SQLRowValues rowValsC2Intra = new SQLRowValues(this.compteTable);
295
            rowValsC2Intra.put("NUMERO", null);
345
        // rowValsC2Intra.put("NUMERO", null);
296
            rowValsC2Intra.put("ID", null);
346
        // rowValsC2Intra.put("ID", null);
297
            rowVals.put("ID_COMPTE_PCE_DED_INTRA", rowValsC2Intra);
347
        // rowVals.put("ID_COMPTE_PCE_DED_INTRA", rowValsC2Intra);
298
        }
348
        // }
299
        SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(rowVals);
349
        // SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(rowVals);
300
        List<SQLRowValues> rowValsList = fetch.fetch();
350
        // List<SQLRowValues> rowValsList = fetch.fetch();
301
 
351
        //
302
        for (SQLRowValues sqlRowValues : rowValsList) {
352
        // for (SQLRowValues sqlRowValues : rowValsList) {
303
            mapTVA.put(sqlRowValues.getID(), sqlRowValues);
353
        // mapTVA.put(sqlRowValues.getID(), sqlRowValues);
304
        }
354
        // }
305
        lastTVAfetchedTime = System.currentTimeMillis();
355
        lastTVAfetchedTime = System.currentTimeMillis();
306
    }
356
    }
307
 
357
 
308
    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) {
309
 
359
 
Line 333... Line 383...
333
                SQLRowAccessor rowCptTvaIntra = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE_INTRA"));
383
                SQLRowAccessor rowCptTvaIntra = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE_INTRA"));
334
                if (rowCptTvaIntra == null || rowCptTvaIntra.isUndefined()) {
384
                if (rowCptTvaIntra == null || rowCptTvaIntra.isUndefined()) {
335
                    rowCptTvaIntra = this.rowDefaultCptTVADeductible;
385
                    rowCptTvaIntra = this.rowDefaultCptTVADeductible;
336
                }
386
                }
337
 
387
 
338
                if (mapHtTVAIntra.get(rowCptTvaIntra) == null) {
388
                if (this.mapHtTVAIntra.get(rowCptTvaIntra) == null) {
339
                    mapHtTVAIntra.put(rowCptTvaIntra, totalTVA);
389
                    this.mapHtTVAIntra.put(rowCptTvaIntra, totalTVA);
340
                } else {
390
                } else {
341
                    BigDecimal l = mapHtTVAIntra.get(rowCptTvaIntra);
391
                    BigDecimal l = this.mapHtTVAIntra.get(rowCptTvaIntra);
342
                    mapHtTVAIntra.put(rowCptTvaIntra, l.add(totalTVA));
392
                    this.mapHtTVAIntra.put(rowCptTvaIntra, l.add(totalTVA));
343
                }
393
                }
344
 
394
 
345
                ttc = ht;
395
                ttc = ht;
346
            } else if (this.achat) {
396
            } else if (this.achat) {
347
                rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED"));
397
                rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_DED"));
Line 352... Line 402...
352
                rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE"));
402
                rowCptTva = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_COLLECTE"));
353
                if (rowCptTva == null || rowCptTva.isUndefined()) {
403
                if (rowCptTva == null || rowCptTva.isUndefined()) {
354
                    rowCptTva = this.rowDefaultCptTVACollecte;
404
                    rowCptTva = this.rowDefaultCptTVACollecte;
355
                }
405
                }
356
            }
406
            }
357
            if (mapHtTVA.get(rowCptTva) == null) {
407
            if (this.mapHtTVA.get(rowCptTva) == null) {
358
                mapHtTVA.put(rowCptTva, totalTVA);
408
                this.mapHtTVA.put(rowCptTva, totalTVA);
359
            } else {
409
            } else {
360
                BigDecimal l = mapHtTVA.get(rowCptTva);
410
                BigDecimal l = this.mapHtTVA.get(rowCptTva);
361
                mapHtTVA.put(rowCptTva, l.add(totalTVA));
411
                this.mapHtTVA.put(rowCptTva, l.add(totalTVA));
362
            }
412
            }
363
            if (ht.signum() != 0) {
413
            if (ht.signum() != 0) {
364
                if (mapHtTVARowTaux.get(tva) == null) {
414
                if (this.mapHtTVARowTaux.get(tva) == null) {
365
                    mapHtTVARowTaux.put(tva, Tuple2.create(ht, totalTVA));
415
                    this.mapHtTVARowTaux.put(tva, Tuple2.create(ht, totalTVA));
366
                } else {
416
                } else {
367
                    Tuple2<BigDecimal, BigDecimal> l = mapHtTVARowTaux.get(tva);
417
                    Tuple2<BigDecimal, BigDecimal> l = this.mapHtTVARowTaux.get(tva);
368
                    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)));
369
                }
419
                }
370
            }
420
            }
371
            if (selection) {
421
            if (selection) {
372
                if (mapHtTVASel.get(rowCptTva) == null) {
422
                if (this.mapHtTVASel.get(rowCptTva) == null) {
373
                    mapHtTVASel.put(rowCptTva, totalTVA);
423
                    this.mapHtTVASel.put(rowCptTva, totalTVA);
374
                } else {
424
                } else {
375
                    BigDecimal l = mapHtTVASel.get(rowCptTva);
425
                    BigDecimal l = this.mapHtTVASel.get(rowCptTva);
376
                    mapHtTVASel.put(rowCptTva, l.add(totalTVA));
426
                    this.mapHtTVASel.put(rowCptTva, l.add(totalTVA));
377
                }
427
                }
378
            }
428
            }
379
        }
429
        }
380
 
430
 
381
        if (mapHt.get(cptArticle) == null) {
431
        if (this.mapHt.get(cptArticle) == null) {
382
            mapHt.put(cptArticle, ht);
432
            this.mapHt.put(cptArticle, ht);
383
        } else {
433
        } else {
384
            BigDecimal l = mapHt.get(cptArticle);
434
            BigDecimal l = this.mapHt.get(cptArticle);
385
            mapHt.put(cptArticle, l.add(ht));
435
            this.mapHt.put(cptArticle, l.add(ht));
386
        }
436
        }
387
 
437
 
388
        this.totalTTC = this.totalTTC.add(ttc);
438
        this.totalTTC = this.totalTTC.add(ttc);
389
        this.totalHTSansFActurable = this.totalHTSansFActurable.add(htSansFacturable);
439
        this.totalHTSansFActurable = this.totalHTSansFActurable.add(htSansFacturable);
390
        if (selection) {
440
        if (selection) {
391
 
441
 
392
            if (mapHtSel.get(cptArticle) == null) {
442
            if (this.mapHtSel.get(cptArticle) == null) {
393
                mapHtSel.put(cptArticle, ht);
443
                this.mapHtSel.put(cptArticle, ht);
394
            } else {
444
            } else {
395
                BigDecimal l = mapHtSel.get(cptArticle);
445
                BigDecimal l = this.mapHtSel.get(cptArticle);
396
                mapHtSel.put(cptArticle, l.add(ht));
446
                this.mapHtSel.put(cptArticle, l.add(ht));
397
            }
447
            }
398
            this.totalTTCSel = this.totalTTCSel.add(ttc);
448
            this.totalTTCSel = this.totalTTCSel.add(ttc);
399
        }
449
        }
400
    }
450
    }
401
 
451
 
Line 417... Line 467...
417
        if (rowAccessorLine.getFields().contains("NIVEAU") && rowAccessorLine.getInt("NIVEAU") != 1) {
467
        if (rowAccessorLine.getFields().contains("NIVEAU") && rowAccessorLine.getInt("NIVEAU") != 1) {
418
            return;
468
            return;
419
        }
469
        }
420
 
470
 
421
        // Total HT de la ligne
471
        // Total HT de la ligne
422
        BigDecimal totalLineHT = rowAccessorLine.getObject(fieldHT) == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject(fieldHT);
472
        BigDecimal totalLineHT = rowAccessorLine.getObject(this.fieldHT) == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject(this.fieldHT);
423
        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");
424
 
474
 
425
        BigDecimal totalLineHTSansFacturable = totalLineHT;
475
        BigDecimal totalLineHTSansFacturable = totalLineHT;
426
        if (!achat) {
476
        if (!this.achat) {
427
            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");
428
            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");
429
            int qte = rowAccessorLine.getInt("QTE");
479
            int qte = rowAccessorLine.getInt("QTE");
430
            totalLineHTSansFacturable = totalLineHTSansFacturable.multiply(qteUV).multiply(new BigDecimal(qte));
480
            totalLineHTSansFacturable = totalLineHTSansFacturable.multiply(qteUV).multiply(new BigDecimal(qte));
431
        }
481
        }
432
        // Prix Unitaire de la ligne
482
        // Prix Unitaire de la ligne
433
        // 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
434
        BigDecimal totalHALigne = rowAccessorLine.getObject(fieldHA) == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject(fieldHA);
484
        BigDecimal totalHALigne = rowAccessorLine.getObject(this.fieldHA) == null ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject(this.fieldHA);
435
 
485
 
436
        Boolean service = rowAccessorLine.getBoolean(FIELD_SERVICE);
486
        Boolean service = rowAccessorLine.getBoolean(FIELD_SERVICE);
437
 
487
 
438
        BigDecimal totalLineDevise = (fieldDevise == null || rowAccessorLine.getObject(fieldDevise) == null) ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject(fieldDevise);
488
        BigDecimal totalLineDevise = (this.fieldDevise == null || rowAccessorLine.getObject(this.fieldDevise) == null) ? BigDecimal.ZERO : (BigDecimal) rowAccessorLine.getObject(this.fieldDevise);
439
 
489
 
440
        Number nPoids = (Number) rowAccessorLine.getObject(FIELD_POIDS);
490
        Number nPoids = (Number) rowAccessorLine.getObject(FIELD_POIDS);
441
 
491
 
442
        // Si il y a une remise à appliquer
492
        // Si il y a une remise à appliquer
443
        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) {
Line 470... Line 520...
470
                idTVA = foreignTVA.getID();
520
                idTVA = foreignTVA.getID();
471
            }
521
            }
472
        }
522
        }
473
        SQLRowAccessor tva = mapTVA.get(idTVA);
523
        SQLRowAccessor tva = mapTVA.get(idTVA);
474
 
524
 
475
        SQLRowAccessor cpt = (achat ? this.rowDefaultCptAchat : this.rowDefaultCptProduit);
525
        SQLRowAccessor cpt = (this.achat ? this.rowDefaultCptAchat : this.rowDefaultCptProduit);
476
        final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(cpt.getTable());
526
        final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(cpt.getTable());
477
 
527
 
478
        if (!achat) {
528
        if (!this.achat) {
479
            // Total Service
529
            // Total Service
480
            if (bServiceActive != null && bServiceActive && service != null && service.booleanValue()) {
530
            if (this.bServiceActive != null && this.bServiceActive && service != null && service.booleanValue()) {
481
                totalService = totalService.add(totalLineHT);
531
                this.totalService = this.totalService.add(totalLineHT);
482
                cpt = this.rowDefaultCptService;
532
                cpt = this.rowDefaultCptService;
483
                if (tva != null && !tva.isForeignEmpty("ID_COMPTE_PCE_VENTE_SERVICE")) {
533
                if (tva != null && !tva.isForeignEmpty("ID_COMPTE_PCE_VENTE_SERVICE")) {
484
                    cpt = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_VENTE_SERVICE"));
534
                    cpt = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_VENTE_SERVICE"));
485
                }
535
                }
486
            } else {
536
            } else {
Line 489... Line 539...
489
                    cpt = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_VENTE"));
539
                    cpt = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_VENTE"));
490
                }
540
                }
491
 
541
 
492
            }
542
            }
493
        }
543
        }
-
 
544
 
-
 
545
        // Compte PCE défini directement sur la ligne
-
 
546
        boolean compteSpec = false;
-
 
547
        if (rowAccessorLine.getTable().contains("ID_COMPTE_PCE") && rowAccessorLine.getObject("ID_COMPTE_PCE") != null && !rowAccessorLine.isForeignEmpty("ID_COMPTE_PCE")) {
-
 
548
            compteSpec = true;
-
 
549
            cpt = cacheForTableCompte.getRowFromId(rowAccessorLine.getForeignID("ID_COMPTE_PCE"));
-
 
550
        }
494
        if (article != null && !article.isUndefined()) {
551
        if (article != null && !article.isUndefined()) {
-
 
552
            if (!compteSpec) {
495
            SQLRowAccessor cptCatComptable = null;
553
                SQLRowAccessor cptCatComptable = null;
496
            // TODO Optimiser les requetes
554
                // TODO Optimiser les requetes
497
            if (rowCatComptable != null && !rowCatComptable.isUndefined()) {
555
                if (this.rowCatComptable != null && !this.rowCatComptable.isUndefined()) {
498
                String suffix = (this.achat ? "_ACHAT" : "_VENTE");
556
                    String suffix = (this.achat ? "_ACHAT" : "_VENTE");
499
                Collection<? extends SQLRowAccessor> rows = article.getReferentRows(compteTable.getTable("ARTICLE_CATEGORIE_COMPTABLE"));
557
                    Collection<? extends SQLRowAccessor> rows = article.getReferentRows(this.compteTable.getTable("ARTICLE_CATEGORIE_COMPTABLE"));
500
                for (SQLRowAccessor sqlRowAccessor : rows) {
558
                    for (SQLRowAccessor sqlRowAccessor : rows) {
501
                    if (sqlRowAccessor.getForeignID("ID_CATEGORIE_COMPTABLE") == this.rowCatComptable.getID()) {
559
                        if (sqlRowAccessor.getForeignID("ID_CATEGORIE_COMPTABLE") == this.rowCatComptable.getID()) {
502
                        cptCatComptable = cacheForTableCompte.getRowFromId(rowCatComptable.getForeignID("ID_COMPTE_PCE" + suffix));
560
                            cptCatComptable = cacheForTableCompte.getRowFromId(this.rowCatComptable.getForeignID("ID_COMPTE_PCE" + suffix));
503
                    }
561
                        }
504
                }
562
                    }
505
            }
563
                }
506
 
564
 
507
            if (cptCatComptable == null) {
565
                if (cptCatComptable == null) {
Line 526... Line 584...
526
                    }
584
                        }
527
                }
585
                    }
528
            } else {
586
                } else {
529
                cpt = cptCatComptable;
587
                    cpt = cptCatComptable;
530
            }
588
                }
-
 
589
            }
531
            if (!achat) {
590
            if (!this.achat) {
532
                SQLRowAccessor taxeCompl = (article.getFields().contains("ID_TAXE_COMPLEMENTAIRE") && article.getObject("ID_TAXE_COMPLEMENTAIRE") != null
591
                SQLRowAccessor taxeCompl = (article.getFields().contains("ID_TAXE_COMPLEMENTAIRE") && article.getObject("ID_TAXE_COMPLEMENTAIRE") != null
533
                        && !article.isForeignEmpty("ID_TAXE_COMPLEMENTAIRE") ? article.getForeign("ID_TAXE_COMPLEMENTAIRE") : null);
592
                        && !article.isForeignEmpty("ID_TAXE_COMPLEMENTAIRE") ? article.getForeign("ID_TAXE_COMPLEMENTAIRE") : null);
534
                if (taxeCompl != null && !taxeCompl.isUndefined()) {
593
                if (taxeCompl != null && !taxeCompl.isUndefined()) {
535
 
594
 
536
                    Map<SQLRowAccessor, BigDecimal> mapCptTaxeValue = this.mapHtTaxeCompl.get(cpt);
595
                    Map<SQLRowAccessor, BigDecimal> mapCptTaxeValue = this.mapHtTaxeCompl.get(cpt);
Line 546... Line 605...
546
                    mapCptTaxeValue.put(taxeCompl, b);
605
                    mapCptTaxeValue.put(taxeCompl, b);
547
                }
606
                }
548
            }
607
            }
549
        }
608
        }
550
 
609
 
551
        if (achat) {
610
        if (!compteSpec) {
552
            // Total Service
611
            // Total Service
553
            if (bServiceActive != null && bServiceActive) {
612
            if (this.bServiceActive != null && this.bServiceActive) {
554
                if (service != null && service.booleanValue()) {
613
                if (service != null && service.booleanValue()) {
555
                    totalService = totalService.add(totalLineHT);
614
                    this.totalService = this.totalService.add(totalLineHT);
556
                    cpt = this.rowDefaultCptService;
615
                    cpt = this.rowDefaultCptService;
557
                }
616
                }
558
            }
617
            }
559
        }
618
        }
560
 
619
 
561
        // Total HA
620
        // Total HA
562
        this.totalHA = this.totalHA.add(totalHALigne);
621
        this.totalHA = this.totalHA.add(totalHALigne);
563
 
622
 
564
        // Total Devise
623
        // Total Devise
565
        if (totalLineDevise != null) {
624
        if (totalLineDevise != null) {
566
            totalDevise = totalDevise.add(totalLineDevise);
625
            this.totalDevise = this.totalDevise.add(totalLineDevise);
567
        }
626
        }
568
 
627
 
569
        // Total Poids
628
        // Total Poids
570
 
629
 
571
        totalPoids += nPoids == null ? 0 : nPoids.doubleValue();
630
        this.totalPoids += nPoids == null ? 0 : nPoids.doubleValue();
572
 
631
 
573
        // Eco-contribution
632
        // Eco-contribution
574
        this.totalEco = this.totalEco.add(totalLineEco);
633
        this.totalEco = this.totalEco.add(totalLineEco);
575
 
634
 
576
        // Calcul total sélectionné
635
        // Calcul total sélectionné
577
        boolean selection = containsInt(selectedRows, lineNumber);
636
        boolean selection = containsInt(this.selectedRows, lineNumber);
578
        if (selection) {
637
        if (selection) {
579
 
638
 
580
            totalHASel = totalHASel.add(totalHALigne);
639
            this.totalHASel = this.totalHASel.add(totalHALigne);
581
 
640
 
582
            if (bServiceActive != null && bServiceActive) {
641
            if (this.bServiceActive != null && this.bServiceActive) {
583
                if (service != null && service.booleanValue()) {
642
                if (service != null && service.booleanValue()) {
584
                    totalServiceSel = totalServiceSel.add(totalLineHT);
643
                    this.totalServiceSel = this.totalServiceSel.add(totalLineHT);
585
                }
644
                }
586
            }
645
            }
587
            this.totalEcoSel = this.totalEcoSel.add(totalLineEco);
646
            this.totalEcoSel = this.totalEcoSel.add(totalLineEco);
588
 
647
 
589
            if (totalLineDevise != null) {
648
            if (totalLineDevise != null) {
590
                totalDeviseSel = totalDeviseSel.add(totalLineDevise);
649
                this.totalDeviseSel = this.totalDeviseSel.add(totalLineDevise);
591
            }
650
            }
592
        }
651
        }
593
 
652
 
594
        addHT(totalLineHT, totalLineHTSansFacturable, tva, cpt, selection);
653
        addHT(totalLineHT, totalLineHTSansFacturable, tva, cpt, selection);
595
    }
654
    }
Line 600... Line 659...
600
    public void checkResult() {
659
    public void checkResult() {
601
        BigDecimal ht = getTotalHT();
660
        BigDecimal ht = getTotalHT();
602
        BigDecimal tva = getTotalTVA();
661
        BigDecimal tva = getTotalTVA();
603
        BigDecimal totalTTC2 = getTotalTTC();
662
        BigDecimal totalTTC2 = getTotalTTC();
604
        BigDecimal reste = totalTTC2.subtract(ht.add(tva));
663
        BigDecimal reste = totalTTC2.subtract(ht.add(tva));
605
        if (!intraComm && reste.compareTo(BigDecimal.ZERO) != 0) {
664
        if (!this.intraComm && reste.compareTo(BigDecimal.ZERO) != 0) {
606
            System.err.print("Ecarts: " + reste + "(HT:" + ht);
665
            System.err.print("Ecarts: " + reste + "(HT:" + ht);
607
            System.err.print(" TVA:" + tva);
666
            System.err.print(" TVA:" + tva);
608
            System.err.println(" TTC:" + totalTTC2);
667
            System.err.println(" TTC:" + totalTTC2);
609
 
668
 
610
            // TODO Check if row already exist in MAP ??
669
            // TODO Check if row already exist in MAP ??
Line 622... Line 681...
622
            }
681
            }
623
        }
682
        }
624
    }
683
    }
625
 
684
 
626
    public BigDecimal getTotalDevise() {
685
    public BigDecimal getTotalDevise() {
627
        return totalDevise;
686
        return this.totalDevise;
628
    }
687
    }
629
 
688
 
630
    public BigDecimal getTotalDeviseSel() {
689
    public BigDecimal getTotalDeviseSel() {
631
        return totalDeviseSel;
690
        return this.totalDeviseSel;
632
    }
691
    }
633
 
692
 
634
    public BigDecimal getTotalHA() {
693
    public BigDecimal getTotalHA() {
635
        return totalHA;
694
        return this.totalHA;
636
    }
695
    }
637
 
696
 
638
    public BigDecimal getTotalHASel() {
697
    public BigDecimal getTotalHASel() {
639
        return totalHASel;
698
        return this.totalHASel;
640
    }
699
    }
641
 
700
 
642
    public double getTotalPoids() {
701
    public double getTotalPoids() {
643
        return totalPoids;
702
        return this.totalPoids;
644
    }
703
    }
645
 
704
 
646
    public BigDecimal getTotalService() {
705
    public BigDecimal getTotalService() {
647
        return totalService;
706
        return this.totalService;
648
    }
707
    }
649
 
708
 
650
    public BigDecimal getTotalServiceSel() {
709
    public BigDecimal getTotalServiceSel() {
651
        return totalServiceSel;
710
        return this.totalServiceSel;
652
    }
711
    }
653
 
712
 
654
    public Map<SQLRowAccessor, Map<SQLRowAccessor, BigDecimal>> getMapHtTaxeCompl() {
713
    public Map<SQLRowAccessor, Map<SQLRowAccessor, BigDecimal>> getMapHtTaxeCompl() {
655
        return mapHtTaxeCompl;
714
        return this.mapHtTaxeCompl;
656
    }
715
    }
657
 
716
 
658
    public BigDecimal getTotalHT() {
717
    public BigDecimal getTotalHT() {
659
        BigDecimal ht = BigDecimal.ZERO;
718
        BigDecimal ht = BigDecimal.ZERO;
660
        for (SQLRowAccessor row : this.mapHt.keySet()) {
719
        for (SQLRowAccessor row : this.mapHt.keySet()) {
Line 679... Line 738...
679
    public BigDecimal getTotalEcoSel() {
738
    public BigDecimal getTotalEcoSel() {
680
        return this.totalEcoSel.setScale(2, RoundingMode.HALF_UP);
739
        return this.totalEcoSel.setScale(2, RoundingMode.HALF_UP);
681
    }
740
    }
682
 
741
 
683
    public BigDecimal getTotalHTSansFActurable() {
742
    public BigDecimal getTotalHTSansFActurable() {
684
        return totalHTSansFActurable;
743
        return this.totalHTSansFActurable;
685
    }
744
    }
686
 
745
 
687
    public BigDecimal getTotalTTC() {
746
    public BigDecimal getTotalTTC() {
688
        return this.totalTTC.setScale(2, RoundingMode.HALF_UP);
747
        return this.totalTTC.setScale(2, RoundingMode.HALF_UP);
689
    }
748
    }
Line 709... Line 768...
709
 
768
 
710
        return this.totalTTCSel.setScale(2, RoundingMode.HALF_UP);
769
        return this.totalTTCSel.setScale(2, RoundingMode.HALF_UP);
711
    }
770
    }
712
 
771
 
713
    public Map<SQLRowAccessor, BigDecimal> getMapHt() {
772
    public Map<SQLRowAccessor, BigDecimal> getMapHt() {
714
        return mapHt;
773
        return this.mapHt;
715
    }
774
    }
716
 
775
 
717
    public Map<SQLRowAccessor, Tuple2<BigDecimal, BigDecimal>> getMapHtTVARowTaux() {
776
    public Map<SQLRowAccessor, Tuple2<BigDecimal, BigDecimal>> getMapHtTVARowTaux() {
718
        return mapHtTVARowTaux;
777
        return this.mapHtTVARowTaux;
719
    }
778
    }
720
 
779
 
721
    public Map<SQLRowAccessor, BigDecimal> getMapHtTVA() {
780
    public Map<SQLRowAccessor, BigDecimal> getMapHtTVA() {
722
        return mapHtTVA;
781
        return this.mapHtTVA;
723
    }
782
    }
724
 
783
 
725
    public Map<SQLRowAccessor, BigDecimal> getMapHtTVAIntra() {
784
    public Map<SQLRowAccessor, BigDecimal> getMapHtTVAIntra() {
726
        return mapHtTVAIntra;
785
        return this.mapHtTVAIntra;
727
    }
786
    }
728
}
787
}