OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 151 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
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
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.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.finance.accounting.ui;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
18
import org.openconcerto.erp.core.common.ui.DeviseNiceTableCellRenderer;
19
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
20
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
21
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
22
import org.openconcerto.erp.core.finance.accounting.model.LettrageModel;
23
import org.openconcerto.erp.model.ISQLCompteSelector;
24
import org.openconcerto.erp.rights.ComptaUserRight;
25
import org.openconcerto.erp.utils.UpperCaseFormatFilter;
26
import org.openconcerto.sql.Configuration;
27
import org.openconcerto.sql.element.SQLElement;
149 ilm 28
import org.openconcerto.sql.element.SQLElementDirectory;
18 ilm 29
import org.openconcerto.sql.model.SQLBase;
30
import org.openconcerto.sql.model.SQLRow;
31
import org.openconcerto.sql.model.SQLRowValues;
149 ilm 32
import org.openconcerto.sql.model.SQLSystem;
18 ilm 33
import org.openconcerto.sql.model.SQLTable;
34
import org.openconcerto.sql.model.Where;
149 ilm 35
import org.openconcerto.sql.request.ComboSQLRequest;
144 ilm 36
import org.openconcerto.sql.users.rights.UserRightsManager;
19 ilm 37
import org.openconcerto.sql.view.list.IListe;
18 ilm 38
import org.openconcerto.ui.DefaultGridBagConstraints;
151 ilm 39
import org.openconcerto.ui.FontUtils;
18 ilm 40
import org.openconcerto.ui.JDate;
41
import org.openconcerto.ui.TitledSeparator;
42
import org.openconcerto.ui.warning.JLabelWarning;
43
import org.openconcerto.utils.text.DocumentFilterList;
19 ilm 44
import org.openconcerto.utils.text.DocumentFilterList.FilterType;
18 ilm 45
import org.openconcerto.utils.text.SimpleDocumentListener;
46
 
47
import java.awt.Color;
48
import java.awt.Component;
49
import java.awt.Dimension;
50
import java.awt.GridBagConstraints;
51
import java.awt.GridBagLayout;
52
import java.awt.Insets;
53
import java.awt.Window;
54
import java.awt.event.ActionEvent;
55
import java.awt.event.ActionListener;
56
import java.awt.event.KeyAdapter;
57
import java.awt.event.KeyEvent;
58
import java.awt.event.MouseAdapter;
59
import java.awt.event.MouseEvent;
60
import java.beans.PropertyChangeEvent;
61
import java.beans.PropertyChangeListener;
62
import java.sql.SQLException;
63
import java.text.ParseException;
64
import java.util.ArrayList;
65
import java.util.Date;
66
import java.util.List;
67
 
68
import javax.swing.AbstractAction;
69
import javax.swing.BorderFactory;
70
import javax.swing.ButtonGroup;
71
import javax.swing.JButton;
72
import javax.swing.JCheckBox;
73
import javax.swing.JLabel;
74
import javax.swing.JPanel;
75
import javax.swing.JRadioButton;
76
import javax.swing.JScrollPane;
77
import javax.swing.JTable;
78
import javax.swing.JTextField;
79
import javax.swing.SwingConstants;
80
import javax.swing.SwingUtilities;
81
import javax.swing.event.DocumentEvent;
82
import javax.swing.text.AbstractDocument;
83
import javax.swing.text.MaskFormatter;
84
 
85
public class LettragePanel extends JPanel {
86
 
87
    private ListPanelEcritures ecriturePanel;
88
    private JTextField codeLettrage;
89
    private ISQLCompteSelector selCompte;
90
    private JCheckBox boxValidEcriture, boxAddSousCompte;
91
    private JPanel warningPanel, warningSolde;
92
 
93
    private final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
94
    private final SQLTable tableEcr = this.base.getTable("ECRITURE");
95
    private final SQLTable tableComptePCE = this.base.getTable("COMPTE_PCE");
96
 
97
    private final static int allEcriture = 0;
98
    private final static int ecritureLettree = 1;
99
    private final static int ecritureNonLettree = 2;
100
 
101
    private int modeSelect;
102
    private LettrageModel model;
103
    private JButton buttonLettrer;
104
    private JDate dateDeb, dateFin, dateLettrage;
105
 
106
    public LettragePanel() {
177 ilm 107
        this(ComptePCESQLElement.getId("4"));
108
    }
109
 
110
    public LettragePanel(int idCompte) {
18 ilm 111
        this.setLayout(new GridBagLayout());
112
        GridBagConstraints c = new DefaultGridBagConstraints();
149 ilm 113
        final SQLElementDirectory directory = Configuration.getInstance().getDirectory();
18 ilm 114
 
115
        this.modeSelect = allEcriture;
116
 
117
        // Selection du compte à lettrer
118
        JLabel labelPointageCompte = new JLabel("Lettrage du compte");
119
        labelPointageCompte.setHorizontalAlignment(SwingConstants.RIGHT);
120
 
121
        this.add(labelPointageCompte, c);
122
        this.selCompte = new ISQLCompteSelector();
149 ilm 123
        SQLElement eltCpt = directory.getElement("COMPTE_PCE");
124
        final ComboSQLRequest createComboRequest = eltCpt.createComboRequest();
125
        String function = "REGEXP";
126
        if (Configuration.getInstance().getBase().getServer().getSQLSystem() == SQLSystem.POSTGRESQL) {
127
            function = "~";
128
        }
129
        createComboRequest.setWhere(new Where(eltCpt.getTable().getField("NUMERO"), function, "^4.*$"));
130
        this.selCompte.init(eltCpt, createComboRequest);
177 ilm 131
        this.selCompte.setValue(idCompte);
18 ilm 132
 
133
        c.gridx++;
134
        c.weightx = 1;
135
        c.gridwidth = GridBagConstraints.REMAINDER;
136
        this.add(this.selCompte, c);
137
 
138
        c.gridwidth = 1;
139
 
140
        // Gestion du lettrage
141
        c.insets = new Insets(2, 2, 1, 2);
142
        TitledSeparator sepGestionLettrage = new TitledSeparator("Gestion du lettrage");
143
        c.fill = GridBagConstraints.HORIZONTAL;
144
        c.gridy++;
145
        c.gridx = 0;
146
        c.gridwidth = GridBagConstraints.REMAINDER;
147
        this.add(sepGestionLettrage, c);
148
 
149
        // Code de lettrage
150
        JLabel labelCode = new JLabel("Code lettrage");
151
        labelCode.setHorizontalAlignment(SwingConstants.RIGHT);
152
        c.gridx = 0;
153
        c.gridy++;
154
        c.gridwidth = 1;
155
        c.weightx = 0;
156
        this.add(labelCode, c);
157
 
158
        this.codeLettrage = new JTextField(10);
159
        DocumentFilterList.add((AbstractDocument) this.codeLettrage.getDocument(), new UpperCaseFormatFilter(), FilterType.SIMPLE_FILTER);
160
        c.gridx++;
161
        c.weightx = 1;
162
        this.add(this.codeLettrage, c);
163
        this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());
164
 
165
        // Warning si aucun code rentré
166
        createPanelWarning();
167
        c.gridwidth = GridBagConstraints.REMAINDER;
168
        c.weightx = 0;
169
        c.gridx++;
170
        this.add(this.warningPanel, c);
171
 
172
        // Date de lettrage
173
        JLabel labelDate = new JLabel("Date");
174
        labelDate.setHorizontalAlignment(SwingConstants.RIGHT);
175
        c.gridx = 0;
176
        c.gridy++;
177
        c.weightx = 0;
178
        c.gridwidth = 1;
179
        this.add(labelDate, c);
180
        this.dateLettrage = new JDate(true);
181
        c.gridx++;
182
        this.add(this.dateLettrage, c);
183
 
184
        // Warning si solde non nul
185
        c.gridx++;
186
        createPanelWarningSolde();
187
        c.gridwidth = GridBagConstraints.REMAINDER;
188
        c.weightx = 0;
189
        this.add(this.warningSolde, c);
190
 
191
        c.gridwidth = 1;
192
 
193
        TitledSeparator sepPeriode = new TitledSeparator("Filtre ");
194
        c.gridy++;
195
        c.gridx = 0;
196
        c.anchor = GridBagConstraints.WEST;
197
        c.gridwidth = GridBagConstraints.REMAINDER;
198
        c.fill = GridBagConstraints.HORIZONTAL;
199
        this.add(sepPeriode, c);
200
 
201
        JPanel panelSelectEcritures = createPanelSelectionEcritures();
202
        c.gridy++;
203
        c.gridx = 0;
204
        c.gridwidth = 1;
205
        c.weightx = 0;
206
 
207
        JLabel labelEcr = new JLabel("Ecritures");
208
        labelEcr.setHorizontalAlignment(SwingConstants.RIGHT);
209
        this.add(labelEcr, c);
210
        c.gridx++;
211
        c.weightx = 1;
212
        c.gridwidth = GridBagConstraints.REMAINDER;
213
        c.fill = GridBagConstraints.NONE;
214
        this.add(panelSelectEcritures, c);
215
 
216
        JPanel panelPeriode = new JPanel();
217
        // Date de début
218
        this.dateDeb = new JDate();
219
        c.gridy++;
220
        c.gridx = 0;
221
        c.gridwidth = 1;
222
        c.weightx = 0;
223
        JLabel labelPerio = new JLabel("Période du ");
224
        labelPerio.setHorizontalAlignment(SwingConstants.RIGHT);
225
        c.fill = GridBagConstraints.HORIZONTAL;
226
        this.add(labelPerio, c);
227
 
228
        panelPeriode.add(this.dateDeb);
229
        this.dateDeb.addValueListener(new PropertyChangeListener() {
230
            public void propertyChange(PropertyChangeEvent evt) {
231
                changeListRequest();
232
            }
233
        });
234
 
235
        // Date de fin
236
        this.dateFin = new JDate(true);
237
        panelPeriode.add(new JLabel("au"));
238
        this.dateFin.addValueListener(new PropertyChangeListener() {
239
            public void propertyChange(PropertyChangeEvent evt) {
240
                changeListRequest();
241
            }
242
        });
243
 
244
        panelPeriode.add(this.dateFin);
245
        c.gridx++;
246
        c.gridwidth = GridBagConstraints.REMAINDER;
247
        c.weightx = 1;
248
        c.fill = GridBagConstraints.NONE;
249
        this.add(panelPeriode, c);
250
 
251
        c.gridx = 0;
252
        c.gridy++;
253
        this.boxAddSousCompte = new JCheckBox("Ajouter les sous comptes");
254
        this.boxAddSousCompte.addActionListener(new ActionListener() {
255
            public void actionPerformed(ActionEvent e) {
256
                // TODO Auto-generated method stub
257
                changeListRequest();
258
            }
259
        });
260
 
261
        this.add(this.boxAddSousCompte, c);
262
 
263
        TitledSeparator sepEcriture = new TitledSeparator("Ecritures ");
264
        c.gridy++;
265
        c.gridx = 0;
266
        c.weightx = 1;
267
        c.gridwidth = GridBagConstraints.REMAINDER;
268
        c.fill = GridBagConstraints.HORIZONTAL;
269
        this.add(sepEcriture, c);
270
 
271
        // Liste des ecritures
149 ilm 272
        final EcritureSQLElement ecritureElem = directory.getElement(EcritureSQLElement.class);
19 ilm 273
        this.ecriturePanel = new ListPanelEcritures(ecritureElem, new IListe(ecritureElem.createLettrageTableSource()));
18 ilm 274
        c.gridx = 0;
275
        c.gridy++;
276
        c.weighty = 1;
277
        c.weightx = 1;
278
        c.fill = GridBagConstraints.BOTH;
279
        c.gridwidth = GridBagConstraints.REMAINDER;
280
        this.ecriturePanel.getListe().setPreferredSize(new Dimension(this.ecriturePanel.getListe().getPreferredSize().width, 200));
281
        this.add(this.ecriturePanel, c);
282
 
283
        // JTable Totaux
284
        c.gridy++;
285
        c.gridx = 0;
286
        c.weighty = 0;
287
        c.weightx = 1;
288
        c.fill = GridBagConstraints.BOTH;
289
        c.gridwidth = 3;
290
        c.gridheight = 3;
291
        this.model = new LettrageModel(this.selCompte.getSelectedId());
292
        JTable table = new JTable(this.model);
151 ilm 293
        table.setRowHeight(FontUtils.getPreferredRowHeight(table));
18 ilm 294
        // AlternateTableCellRenderer.setAllColumns(table);
295
        for (int i = 0; i < table.getColumnCount(); i++) {
296
            // if (table.getColumnClass(i) == Long.class || table.getColumnClass(i) ==
297
            // BigInteger.class) {
298
            table.getColumnModel().getColumn(i).setCellRenderer(new DeviseNiceTableCellRenderer());
299
            // }
300
        }
301
        JScrollPane sPane = new JScrollPane(table);
302
 
303
        // TODO Gerer la taille des colonnes
304
        Dimension d = new Dimension(table.getPreferredSize().width, table.getPreferredSize().height + table.getTableHeader().getPreferredSize().height + 4);
305
        sPane.setPreferredSize(d);
306
        this.add(sPane, c);
307
 
308
        // Legende
309
        c.gridx = 4;
310
        c.gridwidth = 1;
311
        c.anchor = GridBagConstraints.EAST;
312
        c.fill = GridBagConstraints.NONE;
313
        c.weightx = 0;
314
        this.add(createPanelLegende(), c);
315
 
316
        c.gridheight = 1;
317
        final JButton buttonDelettrer = new JButton("Délettrer");
318
        this.buttonLettrer = new JButton("Lettrer");
319
        // Validation des ecritures pointées
320
        this.boxValidEcriture = new JCheckBox("Valider les écritures lettrées");
321
        c.gridx++;
322
        c.gridwidth = GridBagConstraints.REMAINDER;
323
        this.add(this.boxValidEcriture, c);
324
 
325
        JPanel panelButton = new JPanel();
326
 
327
        // Boutton lettrer
328
 
329
        panelButton.add(this.buttonLettrer, c);
330
 
331
        // Boutton Delettrer
332
 
333
        panelButton.add(buttonDelettrer, c);
334
 
335
        c.gridy++;
336
        c.gridx = 5;
337
        c.gridwidth = GridBagConstraints.REMAINDER;
338
        c.gridheight = 1;
339
        c.weightx = 1;
340
        c.fill = GridBagConstraints.NONE;
341
        c.anchor = GridBagConstraints.EAST;
342
        this.add(panelButton, c);
343
 
344
        c.gridy++;
345
        c.anchor = GridBagConstraints.SOUTHEAST;
346
        JButton buttonClose = new JButton("Fermer");
347
        buttonClose.addActionListener(new ActionListener() {
348
 
349
            @Override
350
            public void actionPerformed(ActionEvent e) {
351
                ((Window) SwingUtilities.getRoot((Component) e.getSource())).dispose();
352
 
353
            }
354
        });
355
        this.add(buttonClose, c);
356
        this.buttonLettrer.addActionListener(new ActionListener() {
357
            public void actionPerformed(ActionEvent e) {
358
 
359
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
360
 
361
                // System.err.println("Action lettrage sur " + i);
362
                actionLettrage(rowIndex);
363
 
364
            }
365
        });
366
 
367
        buttonDelettrer.addActionListener(new ActionListener() {
368
            public void actionPerformed(ActionEvent e) {
369
 
370
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
371
                actionDelettrage(rowIndex);
372
            }
373
        });
374
 
375
        // Changement de compte
376
        this.selCompte.addValueListener(new PropertyChangeListener() {
377
            public void propertyChange(PropertyChangeEvent evt) {
378
 
379
                changeListRequest();
380
            };
381
        });
382
 
383
        // Action Souris sur la IListe
384
 
385
        addActionMenuDroit();
386
        this.ecriturePanel.getListe().getJTable().addMouseListener(new MouseAdapter() {
387
 
388
            public void mouseReleased(MouseEvent e) {
389
                System.err.println("Mouse released");
390
                int[] selectedRows = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
391
                int[] idRows = new int[selectedRows.length];
392
                for (int i = 0; i < idRows.length; i++) {
393
                    idRows[i] = LettragePanel.this.ecriturePanel.getListe().idFromIndex(selectedRows[i]);
394
                }
395
 
396
                LettragePanel.this.model.updateSelection(idRows);
397
                LettragePanel.this.warningSolde.setVisible(LettragePanel.this.model.getSoldeSelection() != 0);
398
                buttonDelettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0);
399
                LettragePanel.this.buttonLettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0);
400
            }
401
        });
402
 
403
        // action sur la IListe
404
        this.ecriturePanel.getListe().getJTable().addKeyListener(new KeyAdapter() {
405
            public void keyReleased(KeyEvent e) {
406
 
407
                System.err.println("Key released");
408
                int[] selectedRows = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
409
                int[] idRows = new int[selectedRows.length];
410
                for (int i = 0; i < idRows.length; i++) {
411
                    idRows[i] = LettragePanel.this.ecriturePanel.getListe().idFromIndex(selectedRows[i]);
412
                }
413
 
414
                LettragePanel.this.model.updateSelection(idRows);
415
                LettragePanel.this.warningPanel.setVisible((LettragePanel.this.codeLettrage.getText().trim().length() == 0));
416
                LettragePanel.this.warningSolde.setVisible(LettragePanel.this.model.getSoldeSelection() != 0);
417
            }
418
        });
419
 
420
        // Gestion du code
421
        this.codeLettrage.getDocument().addDocumentListener(new SimpleDocumentListener() {
422
 
423
            @Override
424
            public void update(DocumentEvent e) {
425
                // TODO Auto-generated method stub
426
                LettragePanel.this.warningPanel.setVisible((LettragePanel.this.codeLettrage.getText().trim().length() == 0));
427
                LettragePanel.this.buttonLettrer.setEnabled((LettragePanel.this.codeLettrage.getText().trim().length() != 0));
428
            }
429
 
430
        });
431
 
432
        changeListRequest();
433
        this.warningPanel.setVisible((this.codeLettrage.getText().trim().length() == 0));
434
        this.buttonLettrer.setEnabled((this.codeLettrage.getText().trim().length() != 0));
435
    }
436
 
437
    /* Menu clic Droit */
438
    private void addActionMenuDroit() {
439
        // JPopupMenu menu = new JPopupMenu();
440
 
441
        this.ecriturePanel.getListe().addRowAction(new AbstractAction("Voir la source") {
442
            public void actionPerformed(ActionEvent e) {
443
 
80 ilm 444
                SQLRow rowEcr = LettragePanel.this.ecriturePanel.getListe().fetchSelectedRow();
18 ilm 445
                MouvementSQLElement.showSource(rowEcr.getInt("ID_MOUVEMENT"));
446
            }
67 ilm 447
        }, "financing.accouning.entries.source.show");
18 ilm 448
 
449
        // if (this.codeLettrage.getText().trim().length() != 0) {
67 ilm 450
        final AbstractAction abstractAction = new AbstractAction() {
18 ilm 451
            public void actionPerformed(ActionEvent e) {
452
 
453
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
454
                actionLettrage(rowIndex);
455
            }
456
        };
67 ilm 457
        this.ecriturePanel.getListe().addRowAction(abstractAction, "financing.accouning.entries.match");
18 ilm 458
        // }
459
        this.codeLettrage.getDocument().addDocumentListener(new SimpleDocumentListener() {
460
            @Override
461
            public void update(DocumentEvent e) {
462
                abstractAction.setEnabled(LettragePanel.this.codeLettrage.getText().trim().length() > 0);
463
            }
464
        });
465
 
466
        this.ecriturePanel.getListe().addRowAction(new AbstractAction("Délettrer") {
467
            public void actionPerformed(ActionEvent e) {
468
 
469
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
470
                actionDelettrage(rowIndex);
471
            }
67 ilm 472
        }, "financing.accouning.entries.unmatch");
18 ilm 473
 
474
        // menu.show(mE.getComponent(), mE.getPoint().x, mE.getPoint().y);
475
    }
476
 
477
    /* Panel Warning no numero releve */
478
    private void createPanelWarning() {
479
 
480
        this.warningPanel = new JPanel();
481
        this.warningPanel.setLayout(new GridBagLayout());
482
        // this.warningPanel.setBorder(BorderFactory.createTitledBorder("Warning"));
483
 
484
        GridBagConstraints c = new GridBagConstraints();
485
        c.anchor = GridBagConstraints.WEST;
486
        c.fill = GridBagConstraints.NONE;
487
        c.gridheight = 1;
488
        c.gridwidth = 1;
489
        c.gridx = 0;
490
        c.gridy = 0;
491
        c.weightx = 0;
492
        c.weighty = 0;
493
 
494
        final JLabel warningNoCodeImg = new JLabelWarning();
495
        warningNoCodeImg.setHorizontalAlignment(SwingConstants.RIGHT);
496
        this.warningPanel.add(warningNoCodeImg, c);
497
        final JLabel warningNoCodeText = new JLabel("Impossible de lettrer tant que le code de lettrage n'est pas saisi!");
498
        c.gridx++;
499
        this.warningPanel.add(warningNoCodeText, c);
500
    }
501
 
502
    /* Panel Warning solde invalide */
503
    private void createPanelWarningSolde() {
504
 
505
        this.warningSolde = new JPanel();
506
        this.warningSolde.setLayout(new GridBagLayout());
507
        // this.warningPanel.setBorder(BorderFactory.createTitledBorder("Warning"));
508
 
509
        GridBagConstraints c = new GridBagConstraints();
510
        c.anchor = GridBagConstraints.WEST;
511
        c.fill = GridBagConstraints.NONE;
512
        c.gridheight = 1;
513
        c.gridwidth = 1;
514
        c.gridx = 0;
515
        c.gridy = 0;
516
        c.weightx = 0;
517
        c.weighty = 0;
518
 
519
        final JLabel warningNoCodeImg = new JLabelWarning();
520
        warningNoCodeImg.setHorizontalAlignment(SwingConstants.RIGHT);
521
        this.warningSolde.add(warningNoCodeImg, c);
522
        final JLabel warningNoCodeText = new JLabel("Impossible de lettrer tant que le solde sélectionné n'est pas nul!");
523
        c.gridx++;
524
        this.warningSolde.add(warningNoCodeText, c);
525
    }
526
 
527
    // Lettre la ligne passée en parametre
528
    private void actionLettrage(int[] rowIndex) {
529
        String codeLettre = this.codeLettrage.getText().trim();
530
 
531
        List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);
532
 
533
        long solde = 0;
534
        for (int i = 0; i < rowIndex.length; i++) {
535
            int id = this.ecriturePanel.getListe().idFromIndex(rowIndex[i]);
536
            SQLRow row = this.tableEcr.getRow(id);
537
            rowsSelected.add(row);
538
 
539
            solde += ((Long) row.getObject("DEBIT")).longValue();
540
            solde -= ((Long) row.getObject("CREDIT")).longValue();
541
        }
542
 
543
        if (solde == 0) {
544
 
545
            for (SQLRow row2 : rowsSelected) {
546
 
547
                SQLRowValues rowVals = new SQLRowValues(this.tableEcr);
548
 
549
                // Lettrage
550
                // On lettre ou relettre la ligne avec le code saisi
551
                if (codeLettre.length() > 0) {
552
 
553
                    // Si la ligne est en brouillard on valide le mouvement associé
554
                    if (this.boxValidEcriture.isSelected() && (!row2.getBoolean("VALIDE"))) {
555
                        EcritureSQLElement.validationEcritures(row2.getInt("ID_MOUVEMENT"));
556
                    }
557
 
558
                    rowVals.put("LETTRAGE", codeLettre);
559
                    rowVals.put("DATE_LETTRAGE", this.dateLettrage.getDate());
560
                    try {
561
                        rowVals.update(row2.getID());
562
                    } catch (SQLException e1) {
563
 
564
                        e1.printStackTrace();
565
                    }
566
                }
567
            }
568
            // Mise à jour du code de lettrage
569
            SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
570
            SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
571
            rowVals.put("CODE_LETTRAGE", codeLettre);
572
            try {
573
                rowVals.update();
574
            } catch (SQLException e) {
575
                e.printStackTrace();
576
            }
577
            this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());
578
 
579
            this.model.updateTotauxCompte();
580
        }
581
    }
582
 
583
    protected MaskFormatter createFormatter() {
584
        MaskFormatter formatter = null;
585
        try {
586
            formatter = new MaskFormatter("UUU");
587
        } catch (ParseException e) {
588
            // TODO Auto-generated catch block
589
            e.printStackTrace();
590
        }
591
        return formatter;
592
    }
593
 
594
    // Pointe la ligne passée en parametre
595
    private void actionDelettrage(int[] rowIndex) {
596
 
597
        List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);
598
 
599
        long solde = 0;
600
        for (int i = 0; i < rowIndex.length; i++) {
601
            int id = this.ecriturePanel.getListe().idFromIndex(rowIndex[i]);
602
            SQLRow row = this.tableEcr.getRow(id);
603
            rowsSelected.add(row);
604
 
605
            solde += ((Long) row.getObject("DEBIT")).longValue();
606
            solde -= ((Long) row.getObject("CREDIT")).longValue();
607
        }
608
 
609
        if (solde == 0) {
610
            for (SQLRow row : rowsSelected) {
611
 
612
                SQLRowValues rowVals = new SQLRowValues(this.tableEcr);
613
 
614
                // Dépointage
615
                if (row.getString("LETTRAGE").trim().length() != 0) {
616
 
617
                    rowVals.put("LETTRAGE", "");
618
                    rowVals.put("DATE_LETTRAGE", null);
619
                    try {
620
                        rowVals.update(row.getID());
621
                    } catch (SQLException e1) {
622
                        e1.printStackTrace();
623
                    }
624
                }
625
            }
626
        }
627
        this.model.updateTotauxCompte();
628
    }
629
 
630
    /*
631
     * MaJ de la requete pour remplir la IListe en fonction du compte sélectionner et du mode de
632
     * sélection
633
     */
634
    private void changeListRequest() {
635
        Object idCpt = this.selCompte.getSelectedId();
636
 
637
        SQLRow row = this.tableComptePCE.getRow(Integer.valueOf(idCpt.toString()));
638
 
639
        // filtre de selection
640
        Where w = new Where(this.tableEcr.getField("ID_COMPTE_PCE"), "=", this.tableComptePCE.getKey());
641
 
144 ilm 642
        if (!UserRightsManager.getCurrentUserRights().haveRight(ComptaUserRight.ACCES_NOT_RESCTRICTED_TO_411)) {
18 ilm 643
            // TODO Show Restricted acces in UI
644
            w = w.and(new Where(this.tableEcr.getField("COMPTE_NUMERO"), "LIKE", "411%"));
645
        }
646
 
647
        if (row != null) {
648
            String num = row.getString("NUMERO");
649
            Where w2;
650
            if (this.boxAddSousCompte.isSelected()) {
651
                w2 = new Where(this.tableComptePCE.getField("NUMERO"), "LIKE", num + "%");
652
            } else {
653
                w2 = new Where(this.tableComptePCE.getField("NUMERO"), "=", num);
654
            }
655
            w = w.and(w2);
656
        } else {
657
            w = w.and(new Where(this.tableComptePCE.getKey(), "=", idCpt));
658
        }
659
 
144 ilm 660
        if (this.tableEcr.getFields().contains("HIDE_LETTRAGE")) {
661
            w = w.and(new Where(this.tableEcr.getField("HIDE_LETTRAGE"), "=", Boolean.FALSE));
662
        }
663
 
18 ilm 664
        // final Calendar cal = Calendar.getInstance();
665
        // cal.setTimeInMillis(this.rangeSlide.getValue(0));
666
        //
667
        // Date dInf = cal.getTime();
668
        // cal.setTimeInMillis(this.rangeSlide.getValue(1));
669
        // Date dSup = cal.getTime();
670
 
671
        // w = w.and(new Where(this.tableEcr.getField("DATE"), dInf, dSup));
672
 
673
        Date d1 = this.dateDeb.getValue();
674
        Date d2 = this.dateFin.getValue();
675
 
676
        if (d1 == null && d2 != null) {
677
            w = w.and(new Where(this.tableEcr.getField("DATE"), "<=", d2));
678
        } else {
679
            if (d1 != null && d2 == null) {
680
                w = w.and(new Where(this.tableEcr.getField("DATE"), ">=", d1));
681
            } else {
682
                if (d1 != null && d2 != null) {
683
                    w = w.and(new Where(this.tableEcr.getField("DATE"), d1, d2));
684
                }
685
            }
686
        }
687
 
688
        if (this.modeSelect == ecritureLettree) {
689
            w = w.and(new Where(this.tableEcr.getField("LETTRAGE"), "!=", ""));
690
        } else {
691
            if (this.modeSelect == ecritureNonLettree) {
692
 
693
                Where wLettre = new Where(this.tableEcr.getField("LETTRAGE"), "=", "");
694
                String s = null;
695
                wLettre = wLettre.or(new Where(this.tableEcr.getField("LETTRAGE"), "=", s));
696
                w = w.and(wLettre);
697
            }
698
        }
699
 
19 ilm 700
        this.ecriturePanel.getListe().getRequest().setWhere(w);
151 ilm 701
        this.ecriturePanel.getListe().setModificationAllowed(false);
18 ilm 702
 
703
        this.model.setIdCompte(Integer.parseInt(idCpt.toString()));
704
    }
705
 
706
    /*
707
     * Panel de sélection du mode d'affichage des ecritures
708
     */
709
    private JPanel createPanelSelectionEcritures() {
710
 
711
        JPanel panelSelectEcritures = new JPanel();
712
 
713
        GridBagConstraints cPanel = new GridBagConstraints();
714
        cPanel.anchor = GridBagConstraints.NORTHWEST;
715
        cPanel.fill = GridBagConstraints.HORIZONTAL;
716
        cPanel.gridheight = 1;
717
        cPanel.gridwidth = 1;
718
        cPanel.gridx = 0;
719
        cPanel.gridy = 0;
720
        cPanel.weightx = 0;
721
        cPanel.weighty = 0;
722
 
723
        panelSelectEcritures.setLayout(new GridBagLayout());
724
 
725
        final JRadioButton buttonBoth = new JRadioButton("Toutes");
726
        panelSelectEcritures.add(buttonBoth, cPanel);
727
        cPanel.gridx++;
728
        final JRadioButton buttonNonLettre = new JRadioButton("Non lettrées");
729
        panelSelectEcritures.add(buttonNonLettre, cPanel);
730
        cPanel.gridx++;
731
        final JRadioButton buttonLettre = new JRadioButton("Lettrées");
732
        panelSelectEcritures.add(buttonLettre, cPanel);
733
 
734
        ButtonGroup group = new ButtonGroup();
735
        group.add(buttonBoth);
736
        group.add(buttonNonLettre);
737
        group.add(buttonLettre);
738
        buttonBoth.setSelected(true);
739
 
740
        buttonLettre.addActionListener(new ActionListener() {
741
            public void actionPerformed(ActionEvent e) {
742
                if (buttonLettre.isSelected()) {
743
                    LettragePanel.this.modeSelect = ecritureLettree;
744
                    changeListRequest();
745
                }
746
            }
747
        });
748
 
749
        buttonNonLettre.addActionListener(new ActionListener() {
750
            public void actionPerformed(ActionEvent e) {
751
                if (buttonNonLettre.isSelected()) {
752
                    LettragePanel.this.modeSelect = ecritureNonLettree;
753
                    changeListRequest();
754
                }
755
            }
756
        });
757
 
758
        buttonBoth.addActionListener(new ActionListener() {
759
            public void actionPerformed(ActionEvent e) {
760
                if (buttonBoth.isSelected()) {
761
                    LettragePanel.this.modeSelect = allEcriture;
762
                    changeListRequest();
763
                }
764
            }
765
        });
766
 
767
        return panelSelectEcritures;
768
    }
769
 
770
    /*
771
     * Creation du panel de la legende
772
     */
773
    private JPanel createPanelLegende() {
774
        JPanel panelLegende = new JPanel();
775
 
776
        GridBagConstraints c = new GridBagConstraints();
777
        c.anchor = GridBagConstraints.NORTHWEST;
778
        c.fill = GridBagConstraints.HORIZONTAL;
779
        c.gridheight = 1;
780
        c.gridwidth = 1;
781
        c.gridx = 0;
782
        c.gridy = GridBagConstraints.RELATIVE;
783
        c.weightx = 0;
784
        c.weighty = 0;
785
        c.insets = new Insets(2, 0, 0, 0);
786
 
787
        GridBagConstraints cPanel = new GridBagConstraints();
788
        cPanel.anchor = GridBagConstraints.NORTHWEST;
789
        cPanel.fill = GridBagConstraints.HORIZONTAL;
790
        cPanel.gridheight = 1;
791
        cPanel.gridwidth = 1;
792
        cPanel.gridx = 0;
793
        cPanel.gridy = GridBagConstraints.RELATIVE;
794
        cPanel.weightx = 0;
795
        cPanel.weighty = 0;
796
        cPanel.insets = new Insets(0, 0, 0, 0);
797
 
798
        panelLegende.setLayout(new GridBagLayout());
799
        panelLegende.setBorder(BorderFactory.createTitledBorder("Légendes"));
800
 
801
        JPanel ecritureValidPanel = new JPanel();
802
        ecritureValidPanel.setLayout(new GridBagLayout());
803
        ecritureValidPanel.setBackground(Color.WHITE);
804
        ecritureValidPanel.add(new JLabel("Ecritures validées"), cPanel);
805
        panelLegende.add(ecritureValidPanel, c);
806
 
807
        JPanel ecritureNonValidPanel = new JPanel();
808
        ecritureNonValidPanel.setLayout(new GridBagLayout());
19 ilm 809
        ecritureNonValidPanel.setBackground(PointageRenderer.getCouleurEcritureNonValide());
18 ilm 810
        ecritureNonValidPanel.add(new JLabel("Ecritures non validées"), cPanel);
811
        panelLegende.add(ecritureNonValidPanel, c);
812
 
813
        JPanel ecritureNonValidTodayPanel = new JPanel();
814
        ecritureNonValidTodayPanel.setLayout(new GridBagLayout());
815
        ecritureNonValidTodayPanel.setBackground(PointageRenderer.getCouleurEcritureToDay());
816
        ecritureNonValidTodayPanel.add(new JLabel("Ecritures non validées du jour"), cPanel);
817
        panelLegende.add(ecritureNonValidTodayPanel, c);
818
 
819
        JPanel ecriturePointePanel = new JPanel();
820
        ecriturePointePanel.setLayout(new GridBagLayout());
821
        ecriturePointePanel.setBackground(PointageRenderer.getCouleurEcriturePointee());
822
        ecriturePointePanel.add(new JLabel("Ecritures lettrées"), cPanel);
823
        panelLegende.add(ecriturePointePanel, c);
824
 
825
        return panelLegende;
826
    }
827
}