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 634... Line 634...
634
                            sel.addSelect(ecritureTable.getField("LETTRAGE"));
634
                            sel.addSelect(ecritureTable.getField("LETTRAGE"));
635
                            sel.addGroupBy(ecritureTable.getField("LETTRAGE"));
635
                            sel.addGroupBy(ecritureTable.getField("LETTRAGE"));
636
                            final TableRef aliasEcrTable = sel.getAlias(ecritureTable);
636
                            final TableRef aliasEcrTable = sel.getAlias(ecritureTable);
637
                            final String quoteDebit = new SQLName(aliasEcrTable.getAlias(), "DEBIT").quote();
637
                            final String quoteDebit = new SQLName(aliasEcrTable.getAlias(), "DEBIT").quote();
638
                            final String quoteCredit = new SQLName(aliasEcrTable.getAlias(), "CREDIT").quote();
638
                            final String quoteCredit = new SQLName(aliasEcrTable.getAlias(), "CREDIT").quote();
639
 
-
 
-
 
639
                            sel.setWhere(Where.isNotNull(ecritureTable.getField("LETTRAGE")).and(new Where(ecritureTable.getField("LETTRAGE"), "!=", "")));
640
                            sel.setHaving(Where.createRaw("SUM (" + quoteCredit + ") != SUM(" + quoteDebit + ")", aliasEcrTable.getField("DEBIT")));
640
                            sel.setHaving(Where.createRaw("SUM (" + quoteCredit + ") != SUM(" + quoteDebit + ")", aliasEcrTable.getField("DEBIT")));
641
 
641
 
642
                            List<String> resultBadLettrage = getElement().getTable().getDBSystemRoot().getDataSource().executeCol(sel.asString());
642
                            List<String> resultBadLettrage = getElement().getTable().getDBSystemRoot().getDataSource().executeCol(sel.asString());
643
                            if (resultBadLettrage != null && !resultBadLettrage.isEmpty()) {
643
                            if (resultBadLettrage != null && !resultBadLettrage.isEmpty()) {
-
 
644
 
644
                                UpdateBuilder update = new UpdateBuilder(ecritureTable);
645
                                UpdateBuilder update = new UpdateBuilder(ecritureTable);
645
                                update.setObject(ecritureTable.getField("LETTRAGE"), "");
646
                                update.setObject(ecritureTable.getField("LETTRAGE"), "");
646
                                update.setObject(ecritureTable.getField("DATE_LETTRAGE"), null);
647
                                update.setObject(ecritureTable.getField("DATE_LETTRAGE"), null);
647
                                Where w = new Where(ecritureTable.getField("LETTRAGE"), resultBadLettrage);
648
                                Where w = new Where(ecritureTable.getField("LETTRAGE"), resultBadLettrage);
648
                                update.setWhere(w);
649
                                update.setWhere(w);
649
                                getElement().getTable().getDBSystemRoot().getDataSource().execute(update.asString());
650
                                getElement().getTable().getDBSystemRoot().getDataSource().execute(update.asString());
650
                            }
-
 
651
 
651
 
652
                        }
652
                            }
653
 
653
 
654
                        // Suppression des lettrages déséquilibré (ex : si on modifie un
-
 
655
                        // montant d'une écriture lettrée)
-
 
656
                        SQLSelect sel = new SQLSelect();
-
 
657
                        sel.addSelect(ecritureTable.getField("LETTRAGE"));
-
 
658
                        sel.addGroupBy(ecritureTable.getField("LETTRAGE"));
-
 
659
                        final TableRef aliasEcrTable = sel.getAlias(ecritureTable);
-
 
660
                        final String quoteDebit = new SQLName(aliasEcrTable.getAlias(), "DEBIT").quote();
-
 
661
                        final String quoteCredit = new SQLName(aliasEcrTable.getAlias(), "CREDIT").quote();
-
 
662
                        sel.setWhere(Where.isNotNull(ecritureTable.getField("LETTRAGE")).and(new Where(ecritureTable.getField("LETTRAGE"), "!=", "")));
-
 
663
                        sel.setHaving(Where.createRaw("SUM (" + quoteCredit + ") != SUM(" + quoteDebit + ")", aliasEcrTable.getField("DEBIT")));
-
 
664
 
-
 
665
                        List<String> resultBadLettrage = getTable().getDBSystemRoot().getDataSource().executeCol(sel.asString());
-
 
666
                        if (resultBadLettrage != null && !resultBadLettrage.isEmpty()) {
-
 
667
                            UpdateBuilder update = new UpdateBuilder(ecritureTable);
-
 
668
                            update.setObject(ecritureTable.getField("LETTRAGE"), "");
-
 
669
                            update.setObject(ecritureTable.getField("DATE_LETTRAGE"), null);
-
 
670
                            Where w = new Where(ecritureTable.getField("LETTRAGE"), resultBadLettrage);
-
 
671
                            update.setWhere(w);
-
 
672
                            getTable().getDBSystemRoot().getDataSource().execute(update.asString());
-
 
673
                        }
654
                        }
674
 
655
 
675
                        if (!listEcr.isEmpty()) {
656
                        if (!listEcr.isEmpty()) {
676
                            final EcritureSQLElement e = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement(ecritureTable);
657
                            final EcritureSQLElement e = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement(ecritureTable);
677
                            for (SQLRow sqlRow : listEcr) {
658
                            for (SQLRow sqlRow : listEcr) {