OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 177 Rev 180
Line 14... Line 14...
14
 package org.openconcerto.erp.core.finance.accounting.element;
14
 package org.openconcerto.erp.core.finance.accounting.element;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18
import org.openconcerto.erp.core.finance.accounting.ui.AnalytiqueItemTable;
18
import org.openconcerto.erp.core.finance.accounting.ui.AnalytiqueItemTable;
-
 
19
import org.openconcerto.erp.core.finance.accounting.ui.ComptabiliteWorkflowPreferencePanel;
-
 
20
import org.openconcerto.erp.core.finance.accounting.ui.PropoLettrage;
19
import org.openconcerto.erp.core.finance.accounting.ui.SaisieKmItemTable;
21
import org.openconcerto.erp.core.finance.accounting.ui.SaisieKmItemTable;
20
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieKm;
22
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieKm;
-
 
23
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProvider;
-
 
24
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProviderManager;
-
 
25
import org.openconcerto.erp.preferences.DefaultNXProps;
21
import org.openconcerto.sql.Configuration;
26
import org.openconcerto.sql.Configuration;
22
import org.openconcerto.sql.element.BaseSQLComponent;
27
import org.openconcerto.sql.element.BaseSQLComponent;
23
import org.openconcerto.sql.element.SQLComponent;
28
import org.openconcerto.sql.element.SQLComponent;
24
import org.openconcerto.sql.element.SQLElement;
29
import org.openconcerto.sql.element.SQLElement;
25
import org.openconcerto.sql.model.SQLBase;
30
import org.openconcerto.sql.model.SQLBase;
-
 
31
import org.openconcerto.sql.model.SQLName;
26
import org.openconcerto.sql.model.SQLRow;
32
import org.openconcerto.sql.model.SQLRow;
27
import org.openconcerto.sql.model.SQLRowAccessor;
33
import org.openconcerto.sql.model.SQLRowAccessor;
28
import org.openconcerto.sql.model.SQLRowValues;
34
import org.openconcerto.sql.model.SQLRowValues;
29
import org.openconcerto.sql.model.SQLSelect;
35
import org.openconcerto.sql.model.SQLSelect;
30
import org.openconcerto.sql.model.SQLTable;
36
import org.openconcerto.sql.model.SQLTable;
-
 
37
import org.openconcerto.sql.model.TableRef;
31
import org.openconcerto.sql.model.UndefinedRowValuesCache;
38
import org.openconcerto.sql.model.UndefinedRowValuesCache;
32
import org.openconcerto.sql.model.Where;
39
import org.openconcerto.sql.model.Where;
-
 
40
import org.openconcerto.sql.request.UpdateBuilder;
33
import org.openconcerto.sql.sqlobject.ElementComboBox;
41
import org.openconcerto.sql.sqlobject.ElementComboBox;
34
import org.openconcerto.sql.utils.SQLUtils;
42
import org.openconcerto.sql.utils.SQLUtils;
35
import org.openconcerto.sql.view.list.RowValuesTableModel;
43
import org.openconcerto.sql.view.list.RowValuesTableModel;
36
import org.openconcerto.ui.DefaultGridBagConstraints;
44
import org.openconcerto.ui.DefaultGridBagConstraints;
37
import org.openconcerto.ui.JDate;
45
import org.openconcerto.ui.JDate;
Line 430... Line 438...
430
                        });
438
                        });
431
                        return null;
439
                        return null;
432
                    }
440
                    }
433
                });
441
                });
434
                this.updateEcriture(getTable().getRow(id));
442
                this.updateEcriture(getTable().getRow(id));
-
 
443
 
435
            } catch (SQLException exn) {
444
            } catch (SQLException exn) {
436
                ExceptionHandler.handle("Erreur lors de la création des écritures associées à la saisie au kilometre.", exn);
445
                ExceptionHandler.handle("Erreur lors de la création des écritures associées à la saisie au kilometre.", exn);
437
            }
446
            }
-
 
447
            boolean showPropoLettrage = Boolean.valueOf(DefaultNXProps.getInstance().getProperty(ComptabiliteWorkflowPreferencePanel.LETTRAGE_PROPO_KM));
-
 
448
            if (showPropoLettrage) {
-
 
449
                if (id > SQLRow.NONEXISTANT_ID) {
-
 
450
                    final SQLRow rowKM = getTable().getRow(id);
-
 
451
                    SwingUtilities.invokeLater(new Runnable() {
-
 
452
 
-
 
453
                        @Override
-
 
454
                        public void run() {
-
 
455
                            PropoLettrage lettragePropo = new PropoLettrage(getElement().getDirectory().getElement(EcritureSQLElement.class));
-
 
456
                            lettragePropo.transfert(rowKM);
-
 
457
                        }
-
 
458
                    });
-
 
459
 
-
 
460
                }
-
 
461
            }
438
            return id;
462
            return id;
439
        }
463
        }
440
 
464
 
441
        @Override
465
        @Override
442
        public Set<String> getPartialResetNames() {
466
        public Set<String> getPartialResetNames() {
Line 464... Line 488...
464
        public void update() {
488
        public void update() {
465
            super.update();
489
            super.update();
466
            this.tableKm.updateField("ID_SAISIE_KM", getSelectedID());
490
            this.tableKm.updateField("ID_SAISIE_KM", getSelectedID());
467
            System.err.println("UPDATE ECRITURE");
491
            System.err.println("UPDATE ECRITURE");
468
            this.updateEcriture(getElement().getTable().getRow(getSelectedID()));
492
            this.updateEcriture(getElement().getTable().getRow(getSelectedID()));
-
 
493
            boolean showPropoLettrage = Boolean.valueOf(DefaultNXProps.getInstance().getProperty(ComptabiliteWorkflowPreferencePanel.LETTRAGE_PROPO_KM));
-
 
494
            if (showPropoLettrage) {
-
 
495
                SQLRow rowKM = getTable().getRow(getSelectedID());
-
 
496
                SwingUtilities.invokeLater(new Runnable() {
-
 
497
 
-
 
498
                    @Override
-
 
499
                    public void run() {
-
 
500
                        PropoLettrage lettragePropo = new PropoLettrage(getElement().getDirectory().getElement(EcritureSQLElement.class));
-
 
501
                        lettragePropo.transfert(rowKM);
-
 
502
                    }
-
 
503
                });
-
 
504
            }
469
        }
505
        }
470
 
506
 
471
        private Date dTemp = null;
507
        private Date dTemp = null;
472
 
508
 
473
        @Override
509
        @Override
Line 519... Line 555...
519
 
555
 
520
                            // Mise à jour du nom de la pièce
556
                            // Mise à jour du nom de la pièce
521
                            final SQLRow mvt = rowSaisieKm.getForeign("ID_MOUVEMENT");
557
                            final SQLRow mvt = rowSaisieKm.getForeign("ID_MOUVEMENT");
522
                            final SQLRow piece = mvt.getForeign("ID_PIECE");
558
                            final SQLRow piece = mvt.getForeign("ID_PIECE");
523
                            String labelSaisie = rowSaisieKm.getString("NOM");
559
                            String labelSaisie = rowSaisieKm.getString("NOM");
-
 
560
                            AccountingRecordsProvider provider = AccountingRecordsProviderManager.get(GenerationMvtSaisieKm.ID);
-
 
561
 
-
 
562
                            SQLRowValues rowValsPiece = piece.asRowValues();
524
                            piece.createEmptyUpdateRow().put("NOM", (labelSaisie.length() == 0 ? "Saisie au km " : labelSaisie)).commit();
563
                            rowValsPiece.put("NOM", (labelSaisie.length() == 0 ? "Saisie au km " : labelSaisie));
-
 
564
                            if (provider != null) {
-
 
565
                                provider.putPieceLabel(rowSaisieKm, rowValsPiece);
-
 
566
                            }
525
 
567
 
-
 
568
                            rowValsPiece.commit();
526
                            // Mise à jour des écritures
569
                            // Mise à jour des écritures
527
                            for (SQLRow rowKmElement : myListKmItem) {
570
                            for (SQLRow rowKmElement : myListKmItem) {
528
 
571
 
529
                                int idCpt = ComptePCESQLElement.getId(rowKmElement.getString("NUMERO"), rowKmElement.getString("NOM"));
572
                                int idCpt = ComptePCESQLElement.getId(rowKmElement.getString("NUMERO"), rowKmElement.getString("NOM"));
530
 
573
 
Line 579... Line 622...
579
                                    for (SQLRow sqlRow : l) {
622
                                    for (SQLRow sqlRow : l) {
580
                                        if (sqlRow.getID() == rowKmElement.getInt("ID_ECRITURE")) {
623
                                        if (sqlRow.getID() == rowKmElement.getInt("ID_ECRITURE")) {
581
                                            listEcr.remove(sqlRow);
624
                                            listEcr.remove(sqlRow);
582
                                        }
625
                                        }
583
                                    }
626
                                    }
-
 
627
 
584
                                }
628
                                }
585
 
629
 
586
                            }
630
                            }
-
 
631
                            // Suppression des lettrages déséquilibré (ex : si on modifie un
-
 
632
                            // montant d'une écriture lettrée)
-
 
633
                            SQLSelect sel = new SQLSelect();
-
 
634
                            sel.addSelect(ecritureTable.getField("LETTRAGE"));
-
 
635
                            sel.addGroupBy(ecritureTable.getField("LETTRAGE"));
-
 
636
                            final TableRef aliasEcrTable = sel.getAlias(ecritureTable);
-
 
637
                            final String quoteDebit = new SQLName(aliasEcrTable.getAlias(), "DEBIT").quote();
-
 
638
                            final String quoteCredit = new SQLName(aliasEcrTable.getAlias(), "CREDIT").quote();
-
 
639
 
-
 
640
                            sel.setHaving(Where.createRaw("SUM (" + quoteCredit + ") != SUM(" + quoteDebit + ")", aliasEcrTable.getField("DEBIT")));
-
 
641
 
-
 
642
                            List<String> resultBadLettrage = getElement().getTable().getDBSystemRoot().getDataSource().executeCol(sel.asString());
-
 
643
                            if (resultBadLettrage != null && !resultBadLettrage.isEmpty()) {
-
 
644
                                UpdateBuilder update = new UpdateBuilder(ecritureTable);
-
 
645
                                update.setObject(ecritureTable.getField("LETTRAGE"), "");
-
 
646
                                update.setObject(ecritureTable.getField("DATE_LETTRAGE"), null);
-
 
647
                                Where w = new Where(ecritureTable.getField("LETTRAGE"), resultBadLettrage);
-
 
648
                                update.setWhere(w);
-
 
649
                                getElement().getTable().getDBSystemRoot().getDataSource().execute(update.asString());
-
 
650
                            }
-
 
651
 
-
 
652
                        }
-
 
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());
587
                        }
673
                        }
588
 
674
 
589
                        if (!listEcr.isEmpty()) {
675
                        if (!listEcr.isEmpty()) {
590
                            final EcritureSQLElement e = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement(ecritureTable);
676
                            final EcritureSQLElement e = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement(ecritureTable);
591
                            for (SQLRow sqlRow : listEcr) {
677
                            for (SQLRow sqlRow : listEcr) {