OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 149 Rev 151
Line 13... Line 13...
13
 
13
 
14
 package org.openconcerto.erp.generationEcritures;
14
 package org.openconcerto.erp.generationEcritures;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
17
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
-
 
18
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
18
import org.openconcerto.erp.core.common.ui.TotalCalculator;
19
import org.openconcerto.erp.core.common.ui.TotalCalculator;
19
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
20
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
20
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
21
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
21
import org.openconcerto.erp.generationEcritures.provider.AnalytiqueProvider;
22
import org.openconcerto.erp.generationEcritures.provider.AnalytiqueProvider;
22
import org.openconcerto.erp.generationEcritures.provider.AnalytiqueProviderManager;
23
import org.openconcerto.erp.generationEcritures.provider.AnalytiqueProviderManager;
23
import org.openconcerto.erp.preferences.DefaultNXProps;
24
import org.openconcerto.erp.preferences.DefaultNXProps;
24
import org.openconcerto.erp.preferences.GestionPieceCommercialePanel;
25
import org.openconcerto.erp.preferences.GestionPieceCommercialePanel;
25
import org.openconcerto.sql.Configuration;
26
import org.openconcerto.sql.Configuration;
-
 
27
import org.openconcerto.sql.element.SQLElement;
-
 
28
import org.openconcerto.sql.model.SQLBackgroundTableCache;
26
import org.openconcerto.sql.model.SQLBase;
29
import org.openconcerto.sql.model.SQLBase;
27
import org.openconcerto.sql.model.SQLRow;
30
import org.openconcerto.sql.model.SQLRow;
28
import org.openconcerto.sql.model.SQLRowAccessor;
31
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
32
import org.openconcerto.sql.model.SQLRowListRSH;
29
import org.openconcerto.sql.model.SQLRowValues;
33
import org.openconcerto.sql.model.SQLRowValues;
30
import org.openconcerto.sql.model.SQLSelect;
34
import org.openconcerto.sql.model.SQLSelect;
31
import org.openconcerto.sql.model.SQLTable;
35
import org.openconcerto.sql.model.SQLTable;
-
 
36
import org.openconcerto.sql.model.Where;
32
import org.openconcerto.sql.users.UserManager;
37
import org.openconcerto.sql.users.UserManager;
33
import org.openconcerto.utils.ExceptionHandler;
38
import org.openconcerto.utils.ExceptionHandler;
34
 
39
 
35
import java.math.BigDecimal;
40
import java.math.BigDecimal;
36
import java.math.RoundingMode;
41
import java.math.RoundingMode;
Line 577... Line 582...
577
            }
582
            }
578
        }
583
        }
579
 
584
 
580
        this.mEcritures.put("ID_COMPTE_PCE", idPce);
585
        this.mEcritures.put("ID_COMPTE_PCE", idPce);
581
    }
586
    }
-
 
587
 
-
 
588
    protected void lettrageAuto(List<Integer> pieceIDs, Date d) {
-
 
589
        final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
-
 
590
        final SQLRow rowPrefsCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(tablePrefCompte).getRowFromId(2);
-
 
591
 
-
 
592
        if (rowPrefsCompte.getBoolean("AUTO_LETTRAGE")) {
-
 
593
            SQLSelect selEcr = new SQLSelect();
-
 
594
            SQLTable tableEcr = base.getTable("ECRITURE");
-
 
595
            selEcr.addSelect(tableEcr.getKey());
-
 
596
            selEcr.addSelect(tableEcr.getField("DEBIT"));
-
 
597
            selEcr.addSelect(tableEcr.getField("CREDIT"));
-
 
598
            selEcr.addSelect(tableEcr.getField("LETTRAGE"));
-
 
599
            SQLTable tableCpte = base.getTable("COMPTE_PCE");
-
 
600
            Where w2 = new Where(base.getTable("MOUVEMENT").getField("ID_PIECE"), pieceIDs);
-
 
601
            w2 = w2.and(new Where(tableEcr.getField("ID_MOUVEMENT"), "=", base.getTable("MOUVEMENT").getKey()));
-
 
602
            w2 = w2.and(new Where(tableEcr.getField("ID_COMPTE_PCE"), "=", tableCpte.getKey()));
-
 
603
            w2 = w2.and(new Where(tableCpte.getField("NUMERO"), "LIKE", "40%").or(new Where(tableCpte.getField("NUMERO"), "LIKE", "41%")));
-
 
604
            w2 = w2.and(new Where(tableEcr.getField("DATE_LETTRAGE"), "=", (Object) null));
-
 
605
            selEcr.setWhere(w2);
-
 
606
            long solde = -1;
-
 
607
            List<SQLRow> ecr = SQLRowListRSH.execute(selEcr);
-
 
608
            if (!ecr.isEmpty()) {
-
 
609
                solde = 0;
-
 
610
                for (SQLRow sqlRow2 : ecr) {
-
 
611
                    solde += sqlRow2.getLong("DEBIT");
-
 
612
                    solde -= sqlRow2.getLong("CREDIT");
-
 
613
                }
-
 
614
            }
-
 
615
            if (solde == 0) {
-
 
616
 
-
 
617
                String codeLettre = NumerotationAutoSQLElement.getNextCodeLettrage();
-
 
618
 
-
 
619
                for (SQLRow sqlRow2 : ecr) {
-
 
620
                    SQLRowValues rowValsEcr = sqlRow2.asRowValues();
-
 
621
                    // Lettrage
-
 
622
                    // On lettre ou relettre la ligne avec le code saisi
-
 
623
                    if (codeLettre.length() > 0) {
-
 
624
 
-
 
625
                        rowValsEcr.put("LETTRAGE", codeLettre);
-
 
626
                        rowValsEcr.put("DATE_LETTRAGE", d);
-
 
627
                        try {
-
 
628
                            rowValsEcr.update();
-
 
629
                        } catch (SQLException e1) {
-
 
630
 
-
 
631
                            e1.printStackTrace();
-
 
632
                        }
-
 
633
                    }
-
 
634
                    // Mise à jour du code de lettrage
-
 
635
                    SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
-
 
636
                    SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
-
 
637
                    rowVals.put("CODE_LETTRAGE", codeLettre);
-
 
638
                    try {
-
 
639
                        rowVals.update();
-
 
640
                    } catch (SQLException ex) {
-
 
641
                        ex.printStackTrace();
-
 
642
                    }
-
 
643
 
-
 
644
                }
-
 
645
 
-
 
646
            }
-
 
647
        }
-
 
648
    }
582
}
649
}