OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 180 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 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;
24
import org.openconcerto.sql.model.SQLTable;
26
import org.openconcerto.sql.model.SQLTable;
-
 
27
import org.openconcerto.sql.model.Where;
25
import org.openconcerto.sql.preferences.SQLPreferences;
28
import org.openconcerto.sql.preferences.SQLPreferences;
26
import org.openconcerto.utils.DecimalUtils;
29
import org.openconcerto.utils.DecimalUtils;
27
import org.openconcerto.utils.Tuple2;
30
import org.openconcerto.utils.Tuple2;
28
 
31
 
29
import java.math.BigDecimal;
32
import java.math.BigDecimal;
30
import java.math.RoundingMode;
33
import java.math.RoundingMode;
31
import java.util.Collection;
34
import java.util.Collection;
32
import java.util.HashMap;
35
import java.util.HashMap;
33
import java.util.HashSet;
36
import java.util.HashSet;
-
 
37
import java.util.List;
34
import java.util.Map;
38
import java.util.Map;
35
import java.util.Set;
39
import java.util.Set;
36
 
40
 
37
public class TotalCalculator {
41
public class TotalCalculator {
38
 
42
 
Line 522... Line 526...
522
        }
526
        }
523
        SQLRowAccessor tva = mapTVA.get(idTVA);
527
        SQLRowAccessor tva = mapTVA.get(idTVA);
524
 
528
 
525
        SQLRowAccessor cpt = (this.achat ? this.rowDefaultCptAchat : this.rowDefaultCptProduit);
529
        SQLRowAccessor cpt = (this.achat ? this.rowDefaultCptAchat : this.rowDefaultCptProduit);
526
        final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(cpt.getTable());
530
        final SQLBackgroundTableCacheItem cacheForTableCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(cpt.getTable());
527
 
-
 
-
 
531
        boolean compteCategorieTaxeSpecifique = false;
528
        if (!this.achat) {
532
        if (!this.achat) {
529
            // Total Service
533
            // Total Service
530
            if (this.bServiceActive != null && this.bServiceActive && service != null && service.booleanValue()) {
534
            if (this.bServiceActive != null && this.bServiceActive && service != null && service.booleanValue()) {
531
                this.totalService = this.totalService.add(totalLineHT);
535
                this.totalService = this.totalService.add(totalLineHT);
532
                cpt = this.rowDefaultCptService;
536
                cpt = this.rowDefaultCptService;
Line 538... Line 542...
538
                if (tva != null && !tva.isForeignEmpty("ID_COMPTE_PCE_VENTE")) {
542
                if (tva != null && !tva.isForeignEmpty("ID_COMPTE_PCE_VENTE")) {
539
                    cpt = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_VENTE"));
543
                    cpt = cacheForTableCompte.getRowFromId(tva.getForeignID("ID_COMPTE_PCE_VENTE"));
540
                }
544
                }
541
 
545
 
542
            }
546
            }
-
 
547
 
-
 
548
            // Récupération du compte par défaut dans les liaisons taxe catégorie comptable (ex
-
 
549
            // utilisé pour la caisse Altena)
-
 
550
            if (tva != null && !tva.isUndefined() && this.rowCatComptable != null && !this.rowCatComptable.isUndefined()) {
-
 
551
                final SQLTable tableTaxeCat = this.rowCatComptable.getTable().getTable("TAXE_CATEGORIE_COMPTABLE");
-
 
552
                SQLRowValues rowVals = new SQLRowValues(tableTaxeCat);
-
 
553
                rowVals.putNulls(tableTaxeCat.getFieldsName());
-
 
554
                final List<SQLRowValues> fetchTaxeCat = SQLRowValuesListFetcher.create(rowVals)
-
 
555
                        .fetch(new Where(tableTaxeCat.getField("ID_CATEGORIE_COMPTABLE"), "=", this.rowCatComptable.getID()).and(new Where(tableTaxeCat.getField("ID_TAXE"), "=", tva.getID())));
-
 
556
                if (!fetchTaxeCat.isEmpty()) {
-
 
557
 
-
 
558
                    final Number foreignID = fetchTaxeCat.get(0).getNonEmptyForeignIDNumber("ID_COMPTE_PCE_VENTE");
-
 
559
                    if (foreignID != null) {
-
 
560
                        cpt = cacheForTableCompte.getRowFromId(foreignID.intValue());
-
 
561
                        compteCategorieTaxeSpecifique = true;
-
 
562
                    }
-
 
563
                }
-
 
564
            }
543
        }
565
        }
544
 
566
 
545
        // Compte PCE défini directement sur la ligne
567
        // Compte PCE défini directement sur la ligne
546
        boolean compteSpec = false;
568
        boolean compteSpec = false;
547
        if (rowAccessorLine.getTable().contains("ID_COMPTE_PCE") && rowAccessorLine.getObject("ID_COMPTE_PCE") != null && !rowAccessorLine.isForeignEmpty("ID_COMPTE_PCE")) {
569
        if (rowAccessorLine.getTable().contains("ID_COMPTE_PCE") && rowAccessorLine.getObject("ID_COMPTE_PCE") != null && !rowAccessorLine.isForeignEmpty("ID_COMPTE_PCE")) {
548
            compteSpec = true;
570
            compteSpec = true;
549
            cpt = cacheForTableCompte.getRowFromId(rowAccessorLine.getForeignID("ID_COMPTE_PCE"));
571
            cpt = cacheForTableCompte.getRowFromId(rowAccessorLine.getForeignID("ID_COMPTE_PCE"));
550
        }
572
        }
551
        if (article != null && !article.isUndefined()) {
573
        if (article != null && !article.isUndefined()) {
552
            if (!compteSpec) {
574
            if (!compteSpec) {
553
                SQLRowAccessor cptCatComptable = null;
575
                SQLRowAccessor cptCatComptable = compteCategorieTaxeSpecifique ? cpt : null;
554
                // TODO Optimiser les requetes
576
                // TODO Optimiser les requetes
555
                if (this.rowCatComptable != null && !this.rowCatComptable.isUndefined()) {
577
                if (!compteCategorieTaxeSpecifique && this.rowCatComptable != null && !this.rowCatComptable.isUndefined()) {
556
                    String suffix = (this.achat ? "_ACHAT" : "_VENTE");
578
                    String suffix = (this.achat ? "_ACHAT" : "_VENTE");
557
                    if (!this.rowCatComptable.isForeignEmpty("ID_COMPTE_PCE" + suffix)) {
579
                    if (!this.rowCatComptable.isForeignEmpty("ID_COMPTE_PCE" + suffix)) {
558
                        cptCatComptable = cacheForTableCompte.getRowFromId(this.rowCatComptable.getForeignID("ID_COMPTE_PCE" + suffix));
580
                        cptCatComptable = cacheForTableCompte.getRowFromId(this.rowCatComptable.getForeignID("ID_COMPTE_PCE" + suffix));
559
                    }
581
                    }
560
                    Collection<? extends SQLRowAccessor> rows = article.getReferentRows(this.compteTable.getTable("ARTICLE_CATEGORIE_COMPTABLE"));
582
                    Collection<? extends SQLRowAccessor> rows = article.getReferentRows(this.compteTable.getTable("ARTICLE_CATEGORIE_COMPTABLE"));