OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 177 Rev 180
Line 16... Line 16...
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
17
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
18
import org.openconcerto.erp.core.common.ui.DeviseNiceTableCellRenderer;
18
import org.openconcerto.erp.core.common.ui.DeviseNiceTableCellRenderer;
19
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
19
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
20
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
20
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
-
 
21
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
21
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
22
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
22
import org.openconcerto.erp.core.finance.accounting.model.LettrageModel;
23
import org.openconcerto.erp.core.finance.accounting.model.LettrageModel;
23
import org.openconcerto.erp.model.ISQLCompteSelector;
24
import org.openconcerto.erp.model.ISQLCompteSelector;
24
import org.openconcerto.erp.rights.ComptaUserRight;
25
import org.openconcerto.erp.rights.ComptaUserRight;
-
 
26
import org.openconcerto.erp.utils.LowerCaseFormatFilter;
25
import org.openconcerto.erp.utils.UpperCaseFormatFilter;
27
import org.openconcerto.erp.utils.UpperCaseFormatFilter;
26
import org.openconcerto.sql.Configuration;
28
import org.openconcerto.sql.Configuration;
27
import org.openconcerto.sql.element.SQLElement;
29
import org.openconcerto.sql.element.SQLElement;
28
import org.openconcerto.sql.element.SQLElementDirectory;
30
import org.openconcerto.sql.element.SQLElementDirectory;
29
import org.openconcerto.sql.model.SQLBase;
31
import org.openconcerto.sql.model.SQLBase;
30
import org.openconcerto.sql.model.SQLRow;
32
import org.openconcerto.sql.model.SQLRow;
-
 
33
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
34
import org.openconcerto.sql.model.SQLRowListRSH;
31
import org.openconcerto.sql.model.SQLRowValues;
35
import org.openconcerto.sql.model.SQLRowValues;
-
 
36
import org.openconcerto.sql.model.SQLSelect;
32
import org.openconcerto.sql.model.SQLSystem;
37
import org.openconcerto.sql.model.SQLSystem;
33
import org.openconcerto.sql.model.SQLTable;
38
import org.openconcerto.sql.model.SQLTable;
-
 
39
import org.openconcerto.sql.model.UndefinedRowValuesCache;
34
import org.openconcerto.sql.model.Where;
40
import org.openconcerto.sql.model.Where;
35
import org.openconcerto.sql.request.ComboSQLRequest;
41
import org.openconcerto.sql.request.ComboSQLRequest;
36
import org.openconcerto.sql.users.rights.UserRightsManager;
42
import org.openconcerto.sql.users.rights.UserRightsManager;
-
 
43
import org.openconcerto.sql.view.EditFrame;
-
 
44
import org.openconcerto.sql.view.EditPanel.EditMode;
-
 
45
import org.openconcerto.sql.view.EditPanelListener;
37
import org.openconcerto.sql.view.list.IListe;
46
import org.openconcerto.sql.view.list.IListe;
-
 
47
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
-
 
48
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
38
import org.openconcerto.ui.DefaultGridBagConstraints;
49
import org.openconcerto.ui.DefaultGridBagConstraints;
39
import org.openconcerto.ui.FontUtils;
50
import org.openconcerto.ui.FontUtils;
40
import org.openconcerto.ui.JDate;
51
import org.openconcerto.ui.JDate;
41
import org.openconcerto.ui.TitledSeparator;
52
import org.openconcerto.ui.TitledSeparator;
42
import org.openconcerto.ui.warning.JLabelWarning;
53
import org.openconcerto.ui.warning.JLabelWarning;
-
 
54
import org.openconcerto.utils.ExceptionHandler;
-
 
55
import org.openconcerto.utils.ListMap;
43
import org.openconcerto.utils.text.DocumentFilterList;
56
import org.openconcerto.utils.text.DocumentFilterList;
44
import org.openconcerto.utils.text.DocumentFilterList.FilterType;
57
import org.openconcerto.utils.text.DocumentFilterList.FilterType;
45
import org.openconcerto.utils.text.SimpleDocumentListener;
58
import org.openconcerto.utils.text.SimpleDocumentListener;
46
 
59
 
47
import java.awt.Color;
60
import java.awt.Color;
Line 61... Line 74...
61
import java.beans.PropertyChangeListener;
74
import java.beans.PropertyChangeListener;
62
import java.sql.SQLException;
75
import java.sql.SQLException;
63
import java.text.ParseException;
76
import java.text.ParseException;
64
import java.util.ArrayList;
77
import java.util.ArrayList;
65
import java.util.Date;
78
import java.util.Date;
-
 
79
import java.util.HashMap;
66
import java.util.List;
80
import java.util.List;
-
 
81
import java.util.Map;
-
 
82
import java.util.Map.Entry;
67
 
83
 
68
import javax.swing.AbstractAction;
84
import javax.swing.AbstractAction;
69
import javax.swing.BorderFactory;
85
import javax.swing.BorderFactory;
70
import javax.swing.ButtonGroup;
86
import javax.swing.ButtonGroup;
71
import javax.swing.JButton;
87
import javax.swing.JButton;
Line 83... Line 99...
83
import javax.swing.text.MaskFormatter;
99
import javax.swing.text.MaskFormatter;
84
 
100
 
85
public class LettragePanel extends JPanel {
101
public class LettragePanel extends JPanel {
86
 
102
 
87
    private ListPanelEcritures ecriturePanel;
103
    private ListPanelEcritures ecriturePanel;
88
    private JTextField codeLettrage;
104
    private JTextField codeLettrage, codeLettragePartiel;
89
    private ISQLCompteSelector selCompte;
105
    private ISQLCompteSelector selCompte;
90
    private JCheckBox boxValidEcriture, boxAddSousCompte;
106
    private JCheckBox boxValidEcriture, boxAddSousCompte;
91
    private JPanel warningPanel, warningSolde;
107
    private JPanel warningPanel, warningSolde;
92
 
108
 
93
    private final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
109
    private final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
Line 99... Line 115...
99
    private final static int ecritureNonLettree = 2;
115
    private final static int ecritureNonLettree = 2;
100
 
116
 
101
    private int modeSelect;
117
    private int modeSelect;
102
    private LettrageModel model;
118
    private LettrageModel model;
103
    private JButton buttonLettrer;
119
    private JButton buttonLettrer;
-
 
120
    private final JButton buttonRegler = new JButton("Régler");
104
    private JDate dateDeb, dateFin, dateLettrage;
121
    private JDate dateDeb, dateFin, dateLettrage;
105
 
122
 
106
    public LettragePanel() {
123
    public LettragePanel() {
107
        this(ComptePCESQLElement.getId("4"));
124
        this(ComptePCESQLElement.getId("4"));
108
    }
125
    }
Line 160... Line 177...
160
        c.gridx++;
177
        c.gridx++;
161
        c.weightx = 1;
178
        c.weightx = 1;
162
        this.add(this.codeLettrage, c);
179
        this.add(this.codeLettrage, c);
163
        this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());
180
        this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());
164
 
181
 
-
 
182
        JLabel labelCodepartiel = new JLabel("Code lettrage partiel");
-
 
183
        labelCodepartiel.setHorizontalAlignment(SwingConstants.RIGHT);
-
 
184
        c.gridx++;
-
 
185
        c.gridwidth = 1;
-
 
186
        c.weightx = 0;
-
 
187
        this.add(labelCodepartiel, c);
-
 
188
 
-
 
189
        this.codeLettragePartiel = new JTextField(10);
-
 
190
        DocumentFilterList.add((AbstractDocument) this.codeLettragePartiel.getDocument(), new LowerCaseFormatFilter(), FilterType.SIMPLE_FILTER);
-
 
191
        c.gridx++;
-
 
192
        c.weightx = 1;
-
 
193
        this.add(this.codeLettragePartiel, c);
-
 
194
        this.codeLettragePartiel.setText(getNextCodeLettragePartiel());
-
 
195
 
165
        // Warning si aucun code rentré
196
        // Warning si aucun code rentré
166
        createPanelWarning();
197
        createPanelWarning();
167
        c.gridwidth = GridBagConstraints.REMAINDER;
198
        c.gridwidth = GridBagConstraints.REMAINDER;
168
        c.weightx = 0;
199
        c.weightx = 0;
169
        c.gridx++;
200
        c.gridx++;
Line 321... Line 352...
321
        c.gridx++;
352
        c.gridx++;
322
        c.gridwidth = GridBagConstraints.REMAINDER;
353
        c.gridwidth = GridBagConstraints.REMAINDER;
323
        this.add(this.boxValidEcriture, c);
354
        this.add(this.boxValidEcriture, c);
324
 
355
 
325
        JPanel panelButton = new JPanel();
356
        JPanel panelButton = new JPanel();
-
 
357
        panelButton.add(this.buttonRegler, c);
326
 
358
 
327
        // Boutton lettrer
359
        // Boutton lettrer
328
 
360
 
329
        panelButton.add(this.buttonLettrer, c);
361
        panelButton.add(this.buttonLettrer, c);
330
 
362
 
Line 353... Line 385...
353
            }
385
            }
354
        });
386
        });
355
        this.add(buttonClose, c);
387
        this.add(buttonClose, c);
356
        this.buttonLettrer.addActionListener(new ActionListener() {
388
        this.buttonLettrer.addActionListener(new ActionListener() {
357
            public void actionPerformed(ActionEvent e) {
389
            public void actionPerformed(ActionEvent e) {
358
 
-
 
-
 
390
                try {
359
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
391
                    int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
-
 
392
                    actionLettrage(rowIndex, false);
-
 
393
                } catch (SQLException e1) {
-
 
394
                    ExceptionHandler.handle("Erreur de lettrage", e1);
-
 
395
                }
-
 
396
 
-
 
397
            }
-
 
398
        });
-
 
399
 
-
 
400
        this.buttonRegler.addActionListener(new ActionListener() {
-
 
401
            public void actionPerformed(ActionEvent e) {
-
 
402
 
-
 
403
                final List<SQLRowValues> res = LettragePanel.this.ecriturePanel.getListe().getSelectedRows();
-
 
404
 
-
 
405
                final SQLTable tableKm = LettragePanel.this.ecriturePanel.getListe().getSource().getPrimaryTable().getTable("SAISIE_KM");
-
 
406
                SQLRowValues rowValsKm = new SQLRowValues(tableKm);
-
 
407
                rowValsKm.put("DATE", new Date());
-
 
408
                rowValsKm.put("ID_JOURNAL", JournalSQLElement.BANQUES);
-
 
409
 
-
 
410
                long solde = LettragePanel.this.model.getSoldeSelection();
-
 
411
 
-
 
412
                final SQLTable tableKmItem = tableKm.getTable("SAISIE_KM_ELEMENT");
-
 
413
                List<String> pieces = new ArrayList<>();
-
 
414
 
-
 
415
                for (SQLRowValues sqlRowValues : res) {
-
 
416
                    SQLRowValues rowValsKmItemTiers = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(tableKmItem));
-
 
417
                    rowValsKmItemTiers.put("NUMERO", sqlRowValues.getForeign("ID_COMPTE_PCE").getString("NUMERO"));
-
 
418
                    rowValsKmItemTiers.put("NOM", sqlRowValues.getForeign("ID_COMPTE_PCE").getString("NOM"));
-
 
419
                    final String pieceNom;
-
 
420
                    if (sqlRowValues.getString("NOM_PIECE").trim().length() > 0) {
-
 
421
                        pieceNom = sqlRowValues.getString("NOM_PIECE");
-
 
422
                    } else {
-
 
423
                        pieceNom = sqlRowValues.getForeign("ID_MOUVEMENT").getForeign("ID_PIECE").getString("NOM");
-
 
424
                    }
-
 
425
                    rowValsKmItemTiers.put("NOM_PIECE", pieceNom);
-
 
426
                    if (pieceNom != null && pieceNom.trim().length() > 0) {
-
 
427
                        pieces.add(pieceNom);
-
 
428
                    }
-
 
429
                    rowValsKmItemTiers.put("CREDIT", sqlRowValues.getLong("DEBIT"));
-
 
430
                    rowValsKmItemTiers.put("DEBIT", sqlRowValues.getLong("CREDIT"));
-
 
431
                    if (rowValsKmItemTiers.getTable().contains("MONTANT_ECHEANCE")) {
-
 
432
                        rowValsKmItemTiers.put("MONTANT_ECHEANCE", sqlRowValues.getLong("CREDIT"));
-
 
433
                    }
-
 
434
                    rowValsKmItemTiers.put("ID_SAISIE_KM", rowValsKm);
-
 
435
                }
-
 
436
 
-
 
437
                SQLRowValues rowValsKmItemBq = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(tableKmItem));
-
 
438
                boolean achat = solde < 0;
-
 
439
                // Compte bq
-
 
440
                int idPce = tableKm.getTable("TYPE_REGLEMENT").getRow(2).getInt("ID_COMPTE_PCE_" + (achat ? "FOURN" : "CLIENT"));
-
 
441
                if (idPce <= 1) {
-
 
442
                    try {
-
 
443
                        idPce = ComptePCESQLElement.getIdComptePceDefault("VenteCB");
-
 
444
                    } catch (Exception e1) {
-
 
445
                        // TODO Auto-generated catch block
-
 
446
                        e1.printStackTrace();
-
 
447
                    }
-
 
448
                }
-
 
449
                final SQLTable tableAccount = tableKmItem.getTable("COMPTE_PCE");
-
 
450
                SQLRow rowCptBq = tableAccount.getRow(idPce);
-
 
451
                rowValsKmItemBq.put("NUMERO", rowCptBq.getString("NUMERO"));
-
 
452
                rowValsKmItemBq.put("NOM", rowCptBq.getString("NOM"));
-
 
453
                if (!pieces.isEmpty()) {
-
 
454
                    StringBuilder build = new StringBuilder();
-
 
455
                    int nbPieces = pieces.size();
-
 
456
                    int i = 0;
-
 
457
                    for (String string : pieces) {
-
 
458
                        build.append(string);
-
 
459
                        i++;
-
 
460
                        if (i < nbPieces) {
-
 
461
                            build.append(", ");
-
 
462
                        }
-
 
463
 
-
 
464
                    }
-
 
465
                    rowValsKmItemBq.put("NOM_PIECE", build.toString());
-
 
466
                }
-
 
467
 
-
 
468
                if (solde > 0) {
-
 
469
                    rowValsKmItemBq.put("CREDIT", solde);
-
 
470
                    rowValsKmItemBq.put("DEBIT", 0L);
-
 
471
                } else {
-
 
472
                    rowValsKmItemBq.put("DEBIT", -solde);
-
 
473
                    rowValsKmItemBq.put("CREDIT", 0L);
-
 
474
                }
-
 
475
                rowValsKmItemBq.put("ID_SAISIE_KM", rowValsKm);
-
 
476
 
-
 
477
                EditFrame frame = new EditFrame(Configuration.getInstance().getDirectory().getElement("SAISIE_KM"), EditMode.CREATION);
-
 
478
                frame.getSQLComponent().select(rowValsKm);
-
 
479
                frame.setVisible(true);
-
 
480
                frame.addEditPanelListener(new EditPanelListener() {
-
 
481
 
-
 
482
                    @Override
-
 
483
                    public void modified() {
-
 
484
                        // TODO Auto-generated method stub
-
 
485
 
-
 
486
                    }
-
 
487
 
-
 
488
                    @Override
-
 
489
                    public void inserted(int id) {
-
 
490
                        List<SQLRow> rowsInserted = tableKm.getRow(id).getReferentRows(tableKmItem);
-
 
491
                        List<String> piece = new ArrayList<>();
-
 
492
                        List<SQLRowAccessor> rowsToLettre = new ArrayList<>();
-
 
493
                        long solde = 0;
-
 
494
                        for (SQLRowValues sqlRowValues : res) {
-
 
495
                            rowsToLettre.add(sqlRowValues);
-
 
496
                            final String nomPiece = sqlRowValues.getString("NOM_PIECE");
-
 
497
                            if (sqlRowValues.getForeign("ID_COMPTE_PCE").getString("NUMERO").startsWith("4") && nomPiece.trim().length() > 0) {
-
 
498
                                piece.add(nomPiece);
-
 
499
                            }
-
 
500
                            solde += sqlRowValues.getLong("DEBIT");
-
 
501
                            solde -= sqlRowValues.getLong("CREDIT");
-
 
502
                        }
-
 
503
 
-
 
504
                        for (SQLRow sqlRow : rowsInserted) {
-
 
505
                            SQLRow rowEcr = sqlRow.getForeign("ID_ECRITURE");
-
 
506
 
-
 
507
                            final String nomPiece = sqlRow.getString("NOM_PIECE");
-
 
508
                            if (rowEcr.getString("COMPTE_NUMERO").startsWith("4")) {
-
 
509
                                solde += rowEcr.getLong("DEBIT");
-
 
510
                                solde -= rowEcr.getLong("CREDIT");
-
 
511
                                if (nomPiece.trim().length() > 0) {
-
 
512
                                    piece.add(nomPiece);
-
 
513
                                }
-
 
514
                                rowsToLettre.add(rowEcr);
-
 
515
                            }
-
 
516
                        }
-
 
517
 
-
 
518
                        if (solde == 0) {
-
 
519
                            final String codeLettre = codeLettrage.getText().trim();
-
 
520
 
-
 
521
                            for (SQLRowAccessor row2 : rowsToLettre) {
-
 
522
 
-
 
523
                                SQLRowValues rowVals = new SQLRowValues(row2.getTable());
-
 
524
 
-
 
525
                                // Lettrage
-
 
526
                                // On lettre ou relettre la ligne avec le code saisi
-
 
527
                                if (codeLettre.length() > 0) {
-
 
528
                                    rowVals.put("LETTRAGE_PARTIEL", "");
-
 
529
                                    rowVals.put("LETTRAGE", codeLettre);
-
 
530
                                    rowVals.put("DATE_LETTRAGE", dateLettrage.getDate());
-
 
531
                                    try {
-
 
532
                                        rowVals.update(row2.getID());
-
 
533
                                    } catch (SQLException e1) {
-
 
534
 
-
 
535
                                        e1.printStackTrace();
-
 
536
                                    }
-
 
537
                                }
-
 
538
                            }
-
 
539
                            // Mise à jour du code de lettrage
-
 
540
                            SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
-
 
541
                            SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
-
 
542
                            rowVals.put("CODE_LETTRAGE", codeLettre);
-
 
543
                            try {
-
 
544
                                rowVals.update();
-
 
545
                            } catch (SQLException e) {
-
 
546
                                e.printStackTrace();
-
 
547
                            }
-
 
548
                            codeLettrage.setText(getNextCodeLettrage());
-
 
549
 
-
 
550
                            model.updateTotauxCompte();
-
 
551
                        } else {
-
 
552
                            String codeLettreP = codeLettragePartiel.getText().trim();
-
 
553
                            String codeLettre = codeLettrage.getText().trim();
-
 
554
 
-
 
555
                            SQLSelect selEcr = new SQLSelect();
-
 
556
                            SQLTable tableEcr = tableKm.getTable("ECRITURE");
-
 
557
                            selEcr.addSelect(tableEcr.getKey());
-
 
558
                            selEcr.addSelect(tableEcr.getField("NOM_PIECE"));
-
 
559
                            selEcr.addSelect(tableEcr.getField("DEBIT"));
-
 
560
                            selEcr.addSelect(tableEcr.getField("CREDIT"));
-
 
561
                            selEcr.addSelect(tableEcr.getField("LETTRAGE"));
-
 
562
                            selEcr.addSelect(tableEcr.getField("LETTRAGE_PARTIEL"));
-
 
563
                            Where w2 = new Where(tableEcr.getField("NOM_PIECE"), piece);
-
 
564
                            w2 = w2.and(new Where(tableEcr.getField("COMPTE_NUMERO"), "LIKE", "40%").or(new Where(tableEcr.getField("COMPTE_NUMERO"), "LIKE", "41%")));
-
 
565
                            w2 = w2.and(new Where(tableEcr.getField("DATE_LETTRAGE"), "=", (Object) null));
-
 
566
                            selEcr.setWhere(w2);
-
 
567
 
-
 
568
                            List<SQLRow> rows = SQLRowListRSH.execute(selEcr);
-
 
569
                            ListMap<String, SQLRow> mapPiece = new ListMap<>();
-
 
570
                            Map<String, Long> soldePiece = new HashMap<>();
-
 
571
                            for (SQLRow sqlRow : rows) {
-
 
572
                                String pieceName = sqlRow.getString("NOM_PIECE");
-
 
573
                                mapPiece.add(pieceName, sqlRow);
-
 
574
                                long soldeRow = sqlRow.getLong("DEBIT") - sqlRow.getLong("CREDIT");
-
 
575
                                if (soldePiece.containsKey(pieceName)) {
-
 
576
                                    soldePiece.put(pieceName, soldePiece.get(pieceName) + soldeRow);
-
 
577
                                } else {
-
 
578
                                    soldePiece.put(pieceName, soldeRow);
-
 
579
                                }
-
 
580
                            }
-
 
581
 
-
 
582
                            for (Entry<String, List<SQLRow>> entry : mapPiece.entrySet()) {
-
 
583
 
-
 
584
                                if (soldePiece.get(entry.getKey()) == 0) {
-
 
585
                                    try {
-
 
586
                                        for (SQLRow rowEcr : entry.getValue()) {
-
 
587
                                            SQLRowValues rowVals = rowEcr.createEmptyUpdateRow();
-
 
588
 
-
 
589
                                            // Lettrage
-
 
590
                                            // On lettre ou relettre la ligne avec le code saisi
-
 
591
                                            if (codeLettre.length() > 0) {
-
 
592
                                                rowVals.put("LETTRAGE_PARTIEL", "");
-
 
593
                                                rowVals.put("LETTRAGE", codeLettre);
-
 
594
                                                rowVals.put("DATE_LETTRAGE", dateLettrage.getDate());
-
 
595
                                                rowVals.update();
-
 
596
                                            }
-
 
597
                                        }
-
 
598
                                        // Mise à jour du code de lettrage
-
 
599
                                        SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
-
 
600
                                        SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
-
 
601
                                        rowVals.put("CODE_LETTRAGE", codeLettre);
-
 
602
                                        rowVals.update();
-
 
603
 
-
 
604
                                        codeLettre = getNextCodeLettrage();
-
 
605
                                    } catch (SQLException e) {
-
 
606
                                        e.printStackTrace();
-
 
607
                                    }
-
 
608
                                } else {
-
 
609
                                    try {
-
 
610
                                        for (SQLRow rowEcr : entry.getValue()) {
-
 
611
                                            SQLRowValues rowVals = rowEcr.createEmptyUpdateRow();
-
 
612
 
-
 
613
                                            // Lettrage
-
 
614
                                            // On lettre ou relettre la ligne avec le code saisi
-
 
615
                                            if (codeLettreP.length() > 0) {
360
 
616
 
361
                // System.err.println("Action lettrage sur " + i);
617
                                                rowVals.put("LETTRAGE_PARTIEL", codeLettreP);
362
                actionLettrage(rowIndex);
618
                                                rowVals.update();
363
 
619
 
364
            }
620
                                            }
-
 
621
                                        }
-
 
622
                                        // Mise à jour du code de lettrage
-
 
623
                                        SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
-
 
624
                                        SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
-
 
625
                                        rowVals.put("CODE_LETTRAGE_PARTIEL", codeLettreP);
-
 
626
                                        rowVals.update();
-
 
627
                                        codeLettreP = getNextCodeLettragePartiel();
-
 
628
                                    } catch (SQLException e) {
-
 
629
                                        e.printStackTrace();
-
 
630
                                    }
-
 
631
                                }
-
 
632
                            }
-
 
633
                            codeLettrage.setText(getNextCodeLettrage());
-
 
634
 
-
 
635
                            codeLettragePartiel.setText(getNextCodeLettragePartiel());
-
 
636
                            model.updateTotauxCompte();
-
 
637
                        }
-
 
638
                    }
-
 
639
 
-
 
640
                    @Override
-
 
641
                    public void deleted() {
-
 
642
                        // TODO Auto-generated method stub
-
 
643
 
-
 
644
                    }
-
 
645
 
-
 
646
                    @Override
-
 
647
                    public void cancelled() {
-
 
648
                        // TODO Auto-generated method stub
-
 
649
 
-
 
650
                    }
-
 
651
                });
-
 
652
            }
365
        });
653
        });
366
 
654
 
367
        buttonDelettrer.addActionListener(new ActionListener() {
655
        buttonDelettrer.addActionListener(new ActionListener() {
368
            public void actionPerformed(ActionEvent e) {
656
            public void actionPerformed(ActionEvent e) {
369
 
657
 
370
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
658
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
371
                actionDelettrage(rowIndex);
659
                actionDelettrage(rowIndex, false);
372
            }
660
            }
373
        });
661
        });
374
 
662
 
375
        // Changement de compte
663
        // Changement de compte
376
        this.selCompte.addValueListener(new PropertyChangeListener() {
664
        this.selCompte.addValueListener(new PropertyChangeListener() {
Line 395... Line 683...
395
 
683
 
396
                LettragePanel.this.model.updateSelection(idRows);
684
                LettragePanel.this.model.updateSelection(idRows);
397
                LettragePanel.this.warningSolde.setVisible(LettragePanel.this.model.getSoldeSelection() != 0);
685
                LettragePanel.this.warningSolde.setVisible(LettragePanel.this.model.getSoldeSelection() != 0);
398
                buttonDelettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0);
686
                buttonDelettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0);
399
                LettragePanel.this.buttonLettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0);
687
                LettragePanel.this.buttonLettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0);
-
 
688
                LettragePanel.this.buttonRegler.setEnabled(!LettragePanel.this.ecriturePanel.getListe().getSelectedRows().isEmpty());
400
            }
689
            }
401
        });
690
        });
402
 
691
 
403
        // action sur la IListe
692
        // action sur la IListe
404
        this.ecriturePanel.getListe().getJTable().addKeyListener(new KeyAdapter() {
693
        this.ecriturePanel.getListe().getJTable().addKeyListener(new KeyAdapter() {
Line 432... Line 721...
432
        changeListRequest();
721
        changeListRequest();
433
        this.warningPanel.setVisible((this.codeLettrage.getText().trim().length() == 0));
722
        this.warningPanel.setVisible((this.codeLettrage.getText().trim().length() == 0));
434
        this.buttonLettrer.setEnabled((this.codeLettrage.getText().trim().length() != 0));
723
        this.buttonLettrer.setEnabled((this.codeLettrage.getText().trim().length() != 0));
435
    }
724
    }
436
 
725
 
-
 
726
    private String getNextCodeLettragePartiel() {
-
 
727
        return Configuration.getInstance().getDirectory().getElement(NumerotationAutoSQLElement.class).getNextCodeLettragePartiel();
-
 
728
    }
-
 
729
 
-
 
730
    private String getNextCodeLettrage() {
-
 
731
        return Configuration.getInstance().getDirectory().getElement(NumerotationAutoSQLElement.class).getNextCodeLettrage();
-
 
732
    }
-
 
733
 
437
    /* Menu clic Droit */
734
    /* Menu clic Droit */
438
    private void addActionMenuDroit() {
735
    private void addActionMenuDroit() {
439
        // JPopupMenu menu = new JPopupMenu();
736
        // JPopupMenu menu = new JPopupMenu();
440
 
737
 
441
        this.ecriturePanel.getListe().addRowAction(new AbstractAction("Voir la source") {
738
        PredicateRowAction action = new PredicateRowAction(new AbstractAction() {
442
            public void actionPerformed(ActionEvent e) {
739
            public void actionPerformed(ActionEvent e) {
443
 
740
 
444
                SQLRow rowEcr = LettragePanel.this.ecriturePanel.getListe().fetchSelectedRow();
741
                SQLRow rowEcr = LettragePanel.this.ecriturePanel.getListe().fetchSelectedRow();
445
                MouvementSQLElement.showSource(rowEcr.getInt("ID_MOUVEMENT"));
742
                MouvementSQLElement.showSource(rowEcr.getInt("ID_MOUVEMENT"));
446
            }
743
            }
447
        }, "financing.accouning.entries.source.show");
744
        }, false, "financing.accouning.entries.source.show");
-
 
745
        action.setPredicate(IListeEvent.getSingleSelectionPredicate());
-
 
746
 
-
 
747
        this.ecriturePanel.getListe().addIListeAction(action);
448
 
748
 
449
        // if (this.codeLettrage.getText().trim().length() != 0) {
-
 
450
        final AbstractAction abstractAction = new AbstractAction() {
749
        final AbstractAction abstractAction = new AbstractAction() {
451
            public void actionPerformed(ActionEvent e) {
750
            public void actionPerformed(ActionEvent e) {
452
 
751
 
-
 
752
                try {
-
 
753
                    int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
-
 
754
                    actionLettrage(rowIndex, false);
-
 
755
                } catch (SQLException e1) {
-
 
756
                    ExceptionHandler.handle("erreur de lettrage", e1);
-
 
757
                }
-
 
758
            }
-
 
759
        };
-
 
760
        PredicateRowAction actionLettre = new PredicateRowAction(abstractAction, false, "financing.accouning.entries.match");
-
 
761
        actionLettre.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
-
 
762
        this.ecriturePanel.getListe().addIListeAction(actionLettre);
-
 
763
 
-
 
764
        final AbstractAction abstractActionPartiel = new AbstractAction("Lettrage Partiel") {
-
 
765
            public void actionPerformed(ActionEvent e) {
-
 
766
 
-
 
767
                try {
453
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
768
                    int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
454
                actionLettrage(rowIndex);
769
                    actionLettrage(rowIndex, true);
-
 
770
                } catch (SQLException e1) {
-
 
771
                    ExceptionHandler.handle("erreur de lettrage", e1);
-
 
772
                }
455
            }
773
            }
456
        };
774
        };
457
        this.ecriturePanel.getListe().addRowAction(abstractAction, "financing.accouning.entries.match");
775
        PredicateRowAction actionLettreP = new PredicateRowAction(abstractActionPartiel, false, "financing.accouning.entries.match.partial");
-
 
776
        actionLettreP.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
-
 
777
        this.ecriturePanel.getListe().addIListeAction(actionLettreP);
-
 
778
 
458
        // }
779
        // }
459
        this.codeLettrage.getDocument().addDocumentListener(new SimpleDocumentListener() {
780
        this.codeLettrage.getDocument().addDocumentListener(new SimpleDocumentListener() {
460
            @Override
781
            @Override
461
            public void update(DocumentEvent e) {
782
            public void update(DocumentEvent e) {
462
                abstractAction.setEnabled(LettragePanel.this.codeLettrage.getText().trim().length() > 0);
783
                abstractAction.setEnabled(LettragePanel.this.codeLettrage.getText().trim().length() > 0);
Line 465... Line 786...
465
 
786
 
466
        this.ecriturePanel.getListe().addRowAction(new AbstractAction("Délettrer") {
787
        this.ecriturePanel.getListe().addRowAction(new AbstractAction("Délettrer") {
467
            public void actionPerformed(ActionEvent e) {
788
            public void actionPerformed(ActionEvent e) {
468
 
789
 
469
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
790
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
470
                actionDelettrage(rowIndex);
791
                actionDelettrage(rowIndex, false);
471
            }
792
            }
472
        }, "financing.accouning.entries.unmatch");
793
        }, "financing.accouning.entries.unmatch");
473
 
794
 
-
 
795
        this.ecriturePanel.getListe().addRowAction(new AbstractAction("Délettrer partiel") {
-
 
796
            public void actionPerformed(ActionEvent e) {
-
 
797
 
-
 
798
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
-
 
799
                actionDelettrage(rowIndex, true);
-
 
800
            }
474
        // menu.show(mE.getComponent(), mE.getPoint().x, mE.getPoint().y);
801
        }, "financing.accouning.entries.unmatch.partial");
-
 
802
 
475
    }
803
    }
476
 
804
 
477
    /* Panel Warning no numero releve */
805
    /* Panel Warning no numero releve */
478
    private void createPanelWarning() {
806
    private void createPanelWarning() {
479
 
807
 
Line 523... Line 851...
523
        c.gridx++;
851
        c.gridx++;
524
        this.warningSolde.add(warningNoCodeText, c);
852
        this.warningSolde.add(warningNoCodeText, c);
525
    }
853
    }
526
 
854
 
527
    // Lettre la ligne passée en parametre
855
    // Lettre la ligne passée en parametre
-
 
856
 
528
    private void actionLettrage(int[] rowIndex) {
857
    private void actionLettrage(int[] rowIndex, boolean partiel) throws SQLException {
-
 
858
 
-
 
859
        String codeLettre;
-
 
860
        if (partiel) {
-
 
861
            codeLettre = this.codeLettragePartiel.getText().trim();
-
 
862
        } else {
529
        String codeLettre = this.codeLettrage.getText().trim();
863
            codeLettre = this.codeLettrage.getText().trim();
-
 
864
        }
-
 
865
        // FIXME : transaction
530
 
866
 
531
        List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);
867
        List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);
532
 
868
 
533
        long solde = 0;
869
        long solde = 0;
534
        for (int i = 0; i < rowIndex.length; i++) {
870
        for (int i = 0; i < rowIndex.length; i++) {
Line 538... Line 874...
538
 
874
 
539
            solde += ((Long) row.getObject("DEBIT")).longValue();
875
            solde += ((Long) row.getObject("DEBIT")).longValue();
540
            solde -= ((Long) row.getObject("CREDIT")).longValue();
876
            solde -= ((Long) row.getObject("CREDIT")).longValue();
541
        }
877
        }
542
 
878
 
543
        if (solde == 0) {
879
        if (partiel || solde == 0) {
544
 
880
 
545
            for (SQLRow row2 : rowsSelected) {
881
            for (SQLRow row2 : rowsSelected) {
546
 
882
 
547
                SQLRowValues rowVals = new SQLRowValues(this.tableEcr);
883
                SQLRowValues rowVals = new SQLRowValues(this.tableEcr);
548
 
884
 
Line 553... Line 889...
553
                    // Si la ligne est en brouillard on valide le mouvement associé
889
                    // Si la ligne est en brouillard on valide le mouvement associé
554
                    if (this.boxValidEcriture.isSelected() && (!row2.getBoolean("VALIDE"))) {
890
                    if (this.boxValidEcriture.isSelected() && (!row2.getBoolean("VALIDE"))) {
555
                        EcritureSQLElement.validationEcritures(row2.getInt("ID_MOUVEMENT"));
891
                        EcritureSQLElement.validationEcritures(row2.getInt("ID_MOUVEMENT"));
556
                    }
892
                    }
557
 
893
 
-
 
894
                    if (partiel) {
-
 
895
                        rowVals.put("LETTRAGE_PARTIEL", codeLettre);
-
 
896
                    } else {
558
                    rowVals.put("LETTRAGE", codeLettre);
897
                        rowVals.put("LETTRAGE", codeLettre);
559
                    rowVals.put("DATE_LETTRAGE", this.dateLettrage.getDate());
898
                        rowVals.put("DATE_LETTRAGE", this.dateLettrage.getDate());
-
 
899
                    }
560
                    try {
900
                    try {
561
                        rowVals.update(row2.getID());
901
                        rowVals.update(row2.getID());
562
                    } catch (SQLException e1) {
902
                    } catch (SQLException e1) {
563
 
903
 
564
                        e1.printStackTrace();
904
                        e1.printStackTrace();
Line 566... Line 906...
566
                }
906
                }
567
            }
907
            }
568
            // Mise à jour du code de lettrage
908
            // Mise à jour du code de lettrage
569
            SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
909
            SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
570
            SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
910
            SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
-
 
911
            if (partiel) {
-
 
912
                rowVals.put("CODE_LETTRAGE_PARTIEL", codeLettre);
-
 
913
            } else {
571
            rowVals.put("CODE_LETTRAGE", codeLettre);
914
                rowVals.put("CODE_LETTRAGE", codeLettre);
-
 
915
            }
572
            try {
916
            try {
573
                rowVals.update();
917
                rowVals.update();
574
            } catch (SQLException e) {
918
            } catch (SQLException e) {
575
                e.printStackTrace();
919
                e.printStackTrace();
576
            }
920
            }
577
            this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());
921
            this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());
578
 
922
 
-
 
923
            if (partiel) {
-
 
924
                this.codeLettragePartiel.setText(getNextCodeLettragePartiel());
-
 
925
            } else {
-
 
926
                this.codeLettrage.setText(getNextCodeLettrage());
-
 
927
            }
-
 
928
 
579
            this.model.updateTotauxCompte();
929
            this.model.updateTotauxCompte();
580
        }
930
        }
581
    }
931
    }
582
 
932
 
583
    protected MaskFormatter createFormatter() {
933
    protected MaskFormatter createFormatter() {
Line 590... Line 940...
590
        }
940
        }
591
        return formatter;
941
        return formatter;
592
    }
942
    }
593
 
943
 
594
    // Pointe la ligne passée en parametre
944
    // Pointe la ligne passée en parametre
595
    private void actionDelettrage(int[] rowIndex) {
945
    private void actionDelettrage(int[] rowIndex, boolean partiel) {
596
 
946
 
597
        List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);
947
        List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);
598
 
948
 
599
        long solde = 0;
949
        long solde = 0;
600
        for (int i = 0; i < rowIndex.length; i++) {
950
        for (int i = 0; i < rowIndex.length; i++) {
Line 604... Line 954...
604
 
954
 
605
            solde += ((Long) row.getObject("DEBIT")).longValue();
955
            solde += ((Long) row.getObject("DEBIT")).longValue();
606
            solde -= ((Long) row.getObject("CREDIT")).longValue();
956
            solde -= ((Long) row.getObject("CREDIT")).longValue();
607
        }
957
        }
608
 
958
 
609
        if (solde == 0) {
959
        if (partiel || solde == 0) {
610
            for (SQLRow row : rowsSelected) {
960
            for (SQLRow row : rowsSelected) {
611
 
961
 
612
                SQLRowValues rowVals = new SQLRowValues(this.tableEcr);
962
                SQLRowValues rowVals = new SQLRowValues(this.tableEcr);
-
 
963
                if (partiel) {
-
 
964
                    // Dépointage
-
 
965
                    if (row.getString("LETTRAGE_PARTIEL").trim().length() != 0) {
613
 
966
 
-
 
967
                        rowVals.put("LETTRAGE_PARTIEL", "");
-
 
968
                        try {
-
 
969
                            rowVals.update(row.getID());
-
 
970
                        } catch (SQLException e1) {
-
 
971
                            e1.printStackTrace();
-
 
972
                        }
-
 
973
                    }
-
 
974
                } else {
614
                // Dépointage
975
                    // Dépointage
615
                if (row.getString("LETTRAGE").trim().length() != 0) {
976
                    if (row.getString("LETTRAGE").trim().length() != 0) {
616
 
977
 
617
                    rowVals.put("LETTRAGE", "");
978
                        rowVals.put("LETTRAGE", "");
618
                    rowVals.put("DATE_LETTRAGE", null);
979
                        rowVals.put("DATE_LETTRAGE", null);
Line 622... Line 983...
622
                        e1.printStackTrace();
983
                            e1.printStackTrace();
623
                    }
984
                        }
624
                }
985
                    }
625
            }
986
                }
626
        }
987
            }
-
 
988
        }
627
        this.model.updateTotauxCompte();
989
        this.model.updateTotauxCompte();
628
    }
990
    }
629
 
991
 
630
    /*
992
    /*
631
     * MaJ de la requete pour remplir la IListe en fonction du compte sélectionner et du mode de
993
     * MaJ de la requete pour remplir la IListe en fonction du compte sélectionner et du mode de