OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Rev 151 | Go to most recent revision | 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.ui.DeviseNiceTableCellRenderer;
18
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
19
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
20
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
21
import org.openconcerto.erp.core.finance.accounting.model.PointageModel;
22
import org.openconcerto.erp.model.ISQLCompteSelector;
23
import org.openconcerto.erp.rights.ComptaUserRight;
24
import org.openconcerto.sql.Configuration;
149 ilm 25
import org.openconcerto.sql.element.SQLElement;
26
import org.openconcerto.sql.element.SQLElementDirectory;
18 ilm 27
import org.openconcerto.sql.model.SQLBase;
28
import org.openconcerto.sql.model.SQLRow;
29
import org.openconcerto.sql.model.SQLRowValues;
149 ilm 30
import org.openconcerto.sql.model.SQLSystem;
18 ilm 31
import org.openconcerto.sql.model.SQLTable;
32
import org.openconcerto.sql.model.Where;
149 ilm 33
import org.openconcerto.sql.request.ComboSQLRequest;
144 ilm 34
import org.openconcerto.sql.users.rights.UserRightsManager;
19 ilm 35
import org.openconcerto.sql.view.list.IListe;
18 ilm 36
import org.openconcerto.ui.DefaultGridBagConstraints;
37
import org.openconcerto.ui.JDate;
38
import org.openconcerto.ui.TitledSeparator;
39
import org.openconcerto.ui.warning.JLabelWarning;
40
 
41
import java.awt.Color;
42
import java.awt.Dimension;
43
import java.awt.GridBagConstraints;
44
import java.awt.GridBagLayout;
45
import java.awt.Insets;
46
import java.awt.Window;
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionListener;
49
import java.awt.event.KeyAdapter;
50
import java.awt.event.KeyEvent;
51
import java.awt.event.MouseAdapter;
52
import java.awt.event.MouseEvent;
53
import java.beans.PropertyChangeEvent;
54
import java.beans.PropertyChangeListener;
55
import java.sql.SQLException;
56
import java.util.Date;
57
import java.util.concurrent.ExecutionException;
58
 
59
import javax.swing.AbstractAction;
60
import javax.swing.BorderFactory;
61
import javax.swing.ButtonGroup;
62
import javax.swing.JButton;
63
import javax.swing.JCheckBox;
64
import javax.swing.JLabel;
65
import javax.swing.JPanel;
66
import javax.swing.JPopupMenu;
67
import javax.swing.JRadioButton;
68
import javax.swing.JScrollPane;
69
import javax.swing.JTable;
70
import javax.swing.JTextField;
71
import javax.swing.SwingConstants;
72
import javax.swing.SwingUtilities;
73
import javax.swing.SwingWorker;
74
import javax.swing.event.DocumentEvent;
75
import javax.swing.event.DocumentListener;
76
 
77
public class PointagePanel extends JPanel {
78
 
79
    private ListPanelEcritures ecriturePanel;
80
    private JTextField codePointage;
81
    private ISQLCompteSelector selCompte;
82
    private final JDate datePointee;
83
    private JCheckBox boxValidEcriture;
84
    private JPanel warningPanel;
85
 
86
    private final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
87
    private final SQLTable tableEcr = this.base.getTable("ECRITURE");
88
    private final SQLTable tableCpt = this.base.getTable("COMPTE_PCE");
89
 
90
    private final static int allEcriture = 0;
91
    private final static int ecriturePointee = 1;
92
    private final static int ecritureNotPointee = 2;
93
 
94
    private int modeSelect;
95
    private PointageModel model;
96
    private JButton buttonPointer;
97
    private JDate dateFin, dateDeb;
98
 
99
    public PointagePanel() {
100
        this.setLayout(new GridBagLayout());
101
        final GridBagConstraints c = new DefaultGridBagConstraints();
149 ilm 102
        final SQLElementDirectory directory = Configuration.getInstance().getDirectory();
18 ilm 103
        this.modeSelect = allEcriture;
104
 
105
        // Selection du compte à pointer
106
        // TODO Ajouter selection d'un Journal
107
 
108
        JLabel labelPointageCompte = new JLabel("Pointage du compte");
109
        labelPointageCompte.setHorizontalAlignment(SwingConstants.RIGHT);
110
        this.add(labelPointageCompte, c);
111
 
112
        this.selCompte = new ISQLCompteSelector();
149 ilm 113
        SQLElement eltCpt = directory.getElement("COMPTE_PCE");
114
        final ComboSQLRequest createComboRequest = eltCpt.createComboRequest();
115
        String function = "REGEXP";
116
        if (Configuration.getInstance().getBase().getServer().getSQLSystem() == SQLSystem.POSTGRESQL) {
117
            function = "~";
118
        }
119
        createComboRequest.setWhere(new Where(eltCpt.getTable().getField("NUMERO"), function, "^5.*$"));
120
        this.selCompte.init(eltCpt, createComboRequest);
18 ilm 121
        new SwingWorker<Integer, Object>() {
122
 
123
            @Override
124
            protected Integer doInBackground() throws Exception {
125
 
126
                return ComptePCESQLElement.getId("5");
127
            }
128
 
129
            @Override
130
            protected void done() {
131
                try {
132
                    PointagePanel.this.selCompte.setValue(get());
133
                } catch (InterruptedException e) {
134
                    // TODO Auto-generated catch block
135
                    e.printStackTrace();
136
                } catch (ExecutionException e) {
137
                    // TODO Auto-generated catch block
138
                    e.printStackTrace();
139
                }
140
            }
141
        }.execute();
142
 
143
        // c.fill = GridBagConstraints.NONE;
144
        c.weightx = 1;
145
        c.gridx++;
146
        c.gridwidth = GridBagConstraints.REMAINDER;
147
        this.add(this.selCompte, c);
148
 
149
        // Gestion du pointage
150
        c.insets = new Insets(2, 2, 1, 2);
151
        TitledSeparator sepGestionPointage = new TitledSeparator("Gestion du pointage");
152
        c.fill = GridBagConstraints.HORIZONTAL;
153
        c.gridy++;
154
        c.gridx = 0;
155
        this.add(sepGestionPointage, c);
156
 
157
        // Panel Selection du mode d'affichage des ecritures
158
 
159
        c.gridy++;
160
        c.gridx = 0;
161
        c.gridwidth = 1;
162
        c.gridheight = 1;
163
        c.weightx = 0;
164
 
165
        // Numero de releve
166
        // c.anchor = GridBagConstraints.EAST;
167
        JLabel labelReleve = new JLabel("N° de relevé");
168
        labelReleve.setHorizontalAlignment(SwingConstants.RIGHT);
169
        this.add(labelReleve, c);
170
 
171
        this.codePointage = new JTextField(10);
172
        c.gridx++;
173
        c.weightx = 0;
174
        c.fill = GridBagConstraints.NONE;
175
        c.anchor = GridBagConstraints.WEST;
176
        this.add(this.codePointage, c);
177
 
178
        // Warning si aucun code rentré
179
        c.gridx++;
180
        c.fill = GridBagConstraints.HORIZONTAL;
181
        createPanelWarning();
182
        c.gridwidth = 1;
183
        c.weightx = 1;
184
        this.add(this.warningPanel, c);
185
 
186
        // Date de pointage
187
        // MAYBE si date invalide grisée le bouton pointer
188
        JLabel labelDate = new JLabel("Date de pointage");
189
        labelDate.setHorizontalAlignment(SwingConstants.RIGHT);
190
        c.gridx = 0;
191
        c.gridy++;
192
        c.gridwidth = 1;
193
        c.weightx = 0;
194
        this.add(labelDate, c);
195
 
196
        this.datePointee = new JDate(true);
197
        c.fill = GridBagConstraints.NONE;
198
        c.weightx = 1;
199
        c.gridx++;
200
        c.gridwidth = 1;
201
        this.add(this.datePointee, c);
202
 
203
        TitledSeparator sepPeriode = new TitledSeparator("Filtre ");
204
        c.gridy++;
205
        c.gridx = 0;
206
        c.anchor = GridBagConstraints.WEST;
207
        c.gridwidth = GridBagConstraints.REMAINDER;
208
        c.fill = GridBagConstraints.HORIZONTAL;
209
        this.add(sepPeriode, c);
210
 
211
        JPanel panelSelectEcritures = createPanelSelectionEcritures();
212
        c.gridy++;
213
        c.weightx = 0;
214
        c.gridwidth = 1;
215
        c.gridx = 0;
216
        final JLabel labelEcr = new JLabel("Ecritures");
217
        labelEcr.setHorizontalAlignment(SwingConstants.RIGHT);
218
        this.add(labelEcr, c);
219
        c.gridx++;
220
        c.fill = GridBagConstraints.NONE;
221
        c.gridwidth = GridBagConstraints.REMAINDER;
222
        c.weightx = 1;
223
        this.add(panelSelectEcritures, c);
224
        c.fill = GridBagConstraints.HORIZONTAL;
225
 
226
        c.gridy++;
227
        c.gridx = 0;
228
        c.weightx = 0;
229
        JPanel panelPeriode = new JPanel();
230
        // Date de début
231
        this.dateDeb = new JDate();
232
        final JLabel periodLabel = new JLabel("Période du ");
233
        periodLabel.setHorizontalAlignment(SwingConstants.RIGHT);
234
        c.gridwidth = 1;
235
        this.add(periodLabel, c);
236
 
237
        c.gridx++;
238
 
239
        panelPeriode.add(this.dateDeb);
240
        this.dateDeb.addValueListener(new PropertyChangeListener() {
241
            public void propertyChange(PropertyChangeEvent evt) {
242
                changeListRequest();
243
            }
244
        });
245
 
246
        // Date de fin
247
        this.dateFin = new JDate(true);
248
        panelPeriode.add(new JLabel("au"));
249
        this.dateFin.addValueListener(new PropertyChangeListener() {
250
            public void propertyChange(PropertyChangeEvent evt) {
251
                changeListRequest();
252
            }
253
        });
254
 
255
        panelPeriode.add(this.dateFin);
256
 
257
        c.weightx = 1;
258
        c.fill = GridBagConstraints.NONE;
259
        c.gridwidth = GridBagConstraints.REMAINDER;
260
        this.add(panelPeriode, c);
261
 
262
        TitledSeparator sepEcriture = new TitledSeparator("Ecritures ");
263
        c.gridy++;
264
        c.gridx = 0;
265
        c.gridwidth = GridBagConstraints.REMAINDER;
266
        c.fill = GridBagConstraints.HORIZONTAL;
267
        this.add(sepEcriture, c);
268
 
269
        // Liste des ecritures
149 ilm 270
        final EcritureSQLElement ecritureElem = directory.getElement(EcritureSQLElement.class);
19 ilm 271
        this.ecriturePanel = new ListPanelEcritures(ecritureElem, new IListe(ecritureElem.createPointageTableSource()));
94 ilm 272
        this.ecriturePanel.setShowReadOnlyFrameOnDoubleClick(false);
18 ilm 273
        c.gridx = 0;
274
        c.gridy++;
275
        c.weighty = 1;
276
        c.weightx = 1;
277
        c.fill = GridBagConstraints.BOTH;
278
        c.gridwidth = GridBagConstraints.REMAINDER;
279
        this.ecriturePanel.getListe().setPreferredSize(new Dimension(this.ecriturePanel.getListe().getPreferredSize().width, 200));
280
        this.add(this.ecriturePanel, c);
281
 
282
        // JTable Totaux
283
        c.gridy++;
284
        c.gridx = 0;
285
        c.weighty = 0;
286
        c.weightx = 1;
287
        c.fill = GridBagConstraints.BOTH;
288
        c.gridwidth = 4;
289
        c.gridheight = 3;
290
        this.model = new PointageModel(this.selCompte.getSelectedId());
291
        JTable table = new JTable(this.model);
292
 
293
        // AlternateTableCellRenderer.setAllColumns(table);
294
        final DeviseNiceTableCellRenderer cellRenderer = new DeviseNiceTableCellRenderer();
295
        for (int i = 0; i < table.getColumnCount(); i++) {
296
            // if (table.getColumnClass(i) == Long.class || table.getColumnClass(i) ==
297
            // BigInteger.class) {
298
 
299
            table.getColumnModel().getColumn(i).setCellRenderer(cellRenderer);
300
            // }else{
301
            //
302
            // }
303
        }
304
        JScrollPane sPane = new JScrollPane(table);
305
 
306
        // TODO Gerer la taille des colonnes
307
        Dimension d = new Dimension(table.getPreferredSize().width, table.getPreferredSize().height + table.getTableHeader().getPreferredSize().height + 4);
308
        sPane.setPreferredSize(d);
309
        this.add(sPane, c);
310
 
311
        // Legende
312
        c.gridx += 4;
313
        c.gridwidth = 1;
314
        c.anchor = GridBagConstraints.WEST;
315
        c.fill = GridBagConstraints.NONE;
316
        c.weightx = 0;
317
        this.add(createPanelLegende(), c);
318
 
319
        // Validation des ecritures pointées
320
        this.boxValidEcriture = new JCheckBox("Valider les écritures pointées");
321
        c.gridx++;
322
        c.gridheight = 1;
323
        c.gridwidth = GridBagConstraints.REMAINDER;
324
        this.add(this.boxValidEcriture, c);
325
 
326
        // Bouton Pointer
327
        c.anchor = GridBagConstraints.SOUTHEAST;
328
        this.buttonPointer = new JButton("Pointer");
329
        c.gridwidth = 1;
330
        c.gridheight = 1;
331
        c.weightx = 0;
332
        c.gridx = 5;
333
        c.gridy++;
334
        c.fill = GridBagConstraints.NONE;
335
 
336
        this.add(this.buttonPointer, c);
337
 
338
        // Bouton Depointer
339
        JButton buttonDepointer = new JButton("Dépointer");
340
        c.gridx++;
341
        c.weightx = 0;
342
        this.add(buttonDepointer, c);
343
 
344
        c.gridwidth = GridBagConstraints.REMAINDER;
345
        c.gridheight = 1;
346
        c.weightx = 0;
347
        c.gridx = 5;
348
        c.gridy++;
349
        c.fill = GridBagConstraints.NONE;
350
        c.anchor = GridBagConstraints.EAST;
351
        JButton buttonClose = new JButton("Fermer");
352
        buttonClose.addActionListener(new ActionListener() {
353
 
354
            @Override
355
            public void actionPerformed(ActionEvent e) {
356
                ((Window) SwingUtilities.getRoot(PointagePanel.this)).dispose();
357
            }
358
        });
359
        this.add(buttonClose, c);
360
        this.buttonPointer.addActionListener(new ActionListener() {
361
            public void actionPerformed(ActionEvent e) {
362
 
363
                int[] rowIndex = PointagePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
364
 
365
                for (int i = 0; i < rowIndex.length; i++) {
366
                    System.err.println("Action pointage sur " + i);
367
                    actionPointage(rowIndex[i]);
368
                }
369
            }
370
        });
371
 
372
        buttonDepointer.addActionListener(new ActionListener() {
373
            public void actionPerformed(ActionEvent e) {
374
 
375
                int[] rowIndex = PointagePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
376
 
377
                for (int i = 0; i < rowIndex.length; i++) {
378
                    System.err.println("Action depointage sur " + i);
379
                    actionDepointage(rowIndex[i]);
380
                }
381
            }
382
        });
383
 
384
        // Changement de compte
385
        this.selCompte.addValueListener(new PropertyChangeListener() {
386
            public void propertyChange(PropertyChangeEvent evt) {
387
 
388
                changeListRequest();
389
            };
390
        });
391
 
392
        // Action Souris sur la IListe
393
        this.ecriturePanel.getListe().getJTable().addMouseListener(new MouseAdapter() {
394
 
132 ilm 395
            @Override
396
            public void mouseReleased(MouseEvent e) {
397
                // ATTN never modify an IListe on mousePressed otherwise the selection is incoherent
398
                // (see IListe.iterateSelectedRows())
399
                if ((e.getClickCount() == 2) && (e.getButton() == MouseEvent.BUTTON1)) {
18 ilm 400
 
401
                    int rowIndex = PointagePanel.this.ecriturePanel.getListe().getJTable().rowAtPoint(e.getPoint());
402
                    int id = PointagePanel.this.ecriturePanel.getListe().idFromIndex(rowIndex);
403
 
404
                    SQLRow row = PointagePanel.this.tableEcr.getRow(id);
405
                    if (row.getString("POINTEE").trim().length() == 0) {
406
                        actionPointage(rowIndex);
407
                    } else {
408
                        actionDepointage(rowIndex);
409
                    }
410
                }
411
 
132 ilm 412
                if (e.getButton() == MouseEvent.BUTTON3) {
18 ilm 413
                    actionMenuDroit(e);
414
                }
415
 
416
                int[] selectedRows = PointagePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
417
                int[] idRows = new int[selectedRows.length];
418
                for (int i = 0; i < idRows.length; i++) {
419
                    idRows[i] = PointagePanel.this.ecriturePanel.getListe().idFromIndex(selectedRows[i]);
420
                }
421
 
422
                PointagePanel.this.model.updateSelection(idRows);
423
            }
424
        });
425
 
426
        // action sur la IListe
427
        this.ecriturePanel.getListe().getJTable().addKeyListener(new KeyAdapter() {
132 ilm 428
            @Override
18 ilm 429
            public void keyReleased(KeyEvent e) {
430
                int[] selectedRows = PointagePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
431
                int[] idRows = new int[selectedRows.length];
432
                for (int i = 0; i < idRows.length; i++) {
433
                    idRows[i] = PointagePanel.this.ecriturePanel.getListe().idFromIndex(selectedRows[i]);
434
                }
435
 
436
                PointagePanel.this.model.updateSelection(idRows);
437
            }
438
        });
439
 
440
        // Gestion du code de releve
441
        this.codePointage.getDocument().addDocumentListener(new DocumentListener() {
442
            public void changedUpdate(DocumentEvent e) {
443
 
444
                PointagePanel.this.warningPanel.setVisible((PointagePanel.this.codePointage.getText().trim().length() == 0));
445
                PointagePanel.this.buttonPointer.setEnabled((PointagePanel.this.codePointage.getText().trim().length() != 0));
446
            }
447
 
448
            public void removeUpdate(DocumentEvent e) {
449
 
450
                PointagePanel.this.warningPanel.setVisible((PointagePanel.this.codePointage.getText().trim().length() == 0));
451
                PointagePanel.this.buttonPointer.setEnabled((PointagePanel.this.codePointage.getText().trim().length() != 0));
452
            }
453
 
454
            public void insertUpdate(DocumentEvent e) {
455
 
456
                PointagePanel.this.warningPanel.setVisible((PointagePanel.this.codePointage.getText().trim().length() == 0));
457
                PointagePanel.this.buttonPointer.setEnabled((PointagePanel.this.codePointage.getText().trim().length() != 0));
458
            }
459
        });
460
 
461
        changeListRequest();
462
        this.warningPanel.setVisible((this.codePointage.getText().trim().length() == 0));
463
        this.buttonPointer.setEnabled((this.codePointage.getText().trim().length() != 0));
464
    }
465
 
466
    /* Menu clic Droit */
467
    private void actionMenuDroit(final MouseEvent mE) {
468
        JPopupMenu menu = new JPopupMenu();
469
 
470
        menu.add(new AbstractAction("Voir la source") {
471
            public void actionPerformed(ActionEvent e) {
472
 
473
                int rowIndex = PointagePanel.this.ecriturePanel.getListe().getJTable().rowAtPoint(mE.getPoint());
474
                int id = PointagePanel.this.ecriturePanel.getListe().idFromIndex(rowIndex);
475
 
476
                SQLTable ecriture = PointagePanel.this.base.getTable("ECRITURE");
477
                SQLRow rowEcr = ecriture.getRow(id);
478
 
479
                MouvementSQLElement.showSource(rowEcr.getInt("ID_MOUVEMENT"));
480
            }
481
        });
482
 
483
        if (this.codePointage.getText().trim().length() != 0) {
484
            menu.add(new AbstractAction("Pointer") {
485
                public void actionPerformed(ActionEvent e) {
486
 
487
                    int rowIndex = PointagePanel.this.ecriturePanel.getListe().getJTable().rowAtPoint(mE.getPoint());
488
                    actionPointage(rowIndex);
489
                }
490
            });
491
        }
492
 
493
        menu.add(new AbstractAction("Dépointer") {
494
            public void actionPerformed(ActionEvent e) {
495
 
496
                int rowIndex = PointagePanel.this.ecriturePanel.getListe().getJTable().rowAtPoint(mE.getPoint());
497
                actionDepointage(rowIndex);
498
            }
499
        });
500
 
501
        menu.show(mE.getComponent(), mE.getPoint().x, mE.getPoint().y);
502
    }
503
 
504
    /* Panel Warning no numero releve */
505
    private void createPanelWarning() {
506
 
507
        this.warningPanel = new JPanel();
508
        this.warningPanel.setLayout(new GridBagLayout());
509
        // this.warningPanel.setBorder(BorderFactory.createTitledBorder("Warning"));
510
 
511
        GridBagConstraints c = new GridBagConstraints();
512
        c.anchor = GridBagConstraints.WEST;
513
        c.fill = GridBagConstraints.NONE;
514
        c.gridheight = 1;
515
        c.gridwidth = 1;
516
        c.gridx = 0;
517
        c.gridy = 0;
518
        c.weightx = 0;
519
        c.weighty = 0;
520
 
521
        final JLabel warningNoCodeImg = new JLabelWarning();
522
        // warningNoCodeImg.setHorizontalAlignment(SwingConstants.RIGHT);
523
        this.warningPanel.add(warningNoCodeImg, c);
524
        final JLabel warningNoCodeText = new JLabel("Impossible de pointer tant que le numéro de relevé n'est pas saisi!");
525
        c.gridx++;
526
        this.warningPanel.add(warningNoCodeText, c);
527
    }
528
 
529
    // Pointe la ligne passée en parametre
530
    private void actionPointage(int rowIndex) {
531
        String codePoint = this.codePointage.getText().trim();
532
 
533
        int id = this.ecriturePanel.getListe().idFromIndex(rowIndex);
534
 
535
        SQLRow row = this.tableEcr.getRow(id);
536
        SQLRowValues rowVals = new SQLRowValues(this.tableEcr);
537
 
538
        // Pointage
539
        // On pointe ou repointe la ligne avec la date et le numero de releve saisis
540
        if ((!this.datePointee.isEmpty()) && (codePoint.length() > 0)) {
541
 
542
            // Si la ligne est en brouillard on valide le mouvement associé
543
            if (this.boxValidEcriture.isSelected() && (!row.getBoolean("VALIDE"))) {
544
                EcritureSQLElement.validationEcritures(row.getInt("ID_MOUVEMENT"));
545
            }
546
 
547
            rowVals.put("POINTEE", codePoint);
548
            rowVals.put("DATE_POINTEE", new java.sql.Date(this.datePointee.getDate().getTime()));
549
 
550
            try {
551
                rowVals.update(id);
552
            } catch (SQLException e1) {
553
 
554
                e1.printStackTrace();
555
            }
556
        }
557
        this.model.updateTotauxCompte();
558
    }
559
 
560
    // Pointe la ligne passée en parametre
561
    private void actionDepointage(int rowIndex) {
562
 
563
        int id = this.ecriturePanel.getListe().idFromIndex(rowIndex);
564
 
565
        SQLRow row = this.tableEcr.getRow(id);
566
        SQLRowValues rowVals = new SQLRowValues(this.tableEcr);
567
 
568
        // Dépointage
569
        if (row.getString("POINTEE").trim().length() != 0) {
570
 
571
            rowVals.put("POINTEE", "");
572
            rowVals.put("DATE_POINTEE", null);
573
 
574
            try {
575
                rowVals.update(id);
576
            } catch (SQLException e1) {
577
                e1.printStackTrace();
578
            }
579
        }
580
        this.model.updateTotauxCompte();
581
    }
582
 
583
    /*
584
     * MaJ de la requete pour remplir la IListe en fonction du compte sélectionner et du mode de
585
     * sélection
586
     */
587
    private void changeListRequest() {
588
        Object idCpt = this.selCompte.getSelectedId();
589
 
590
        // filtre de selection
591
 
592
        Where w = new Where(this.tableEcr.getField("ID_COMPTE_PCE"), "=", idCpt);
593
 
144 ilm 594
        if (!UserRightsManager.getCurrentUserRights().haveRight(ComptaUserRight.ACCES_NOT_RESCTRICTED_TO_411)) {
18 ilm 595
            // TODO Show Restricted acces in UI
596
            w = w.and(new Where(this.tableEcr.getField("COMPTE_NUMERO"), "LIKE", "411%"));
597
        }
598
 
599
        Date d1 = this.dateDeb.getValue();
600
        Date d2 = this.dateFin.getValue();
601
 
602
        if (d1 == null && d2 != null) {
603
            w = w.and(new Where(this.tableEcr.getField("DATE"), "<=", d2));
604
        } else {
605
            if (d1 != null && d2 == null) {
606
                w = w.and(new Where(this.tableEcr.getField("DATE"), ">=", d1));
607
            } else {
608
                if (d1 != null && d2 != null) {
609
                    w = w.and(new Where(this.tableEcr.getField("DATE"), d1, d2));
610
                }
611
            }
612
        }
613
 
614
        if (this.modeSelect == ecriturePointee) {
615
            w = w.and(new Where(this.tableEcr.getField("POINTEE"), "!=", ""));
616
        } else {
617
            if (this.modeSelect == ecritureNotPointee) {
618
                w = w.and(new Where(this.tableEcr.getField("POINTEE"), "=", ""));
619
            }
620
        }
621
 
19 ilm 622
        this.ecriturePanel.getListe().getRequest().setWhere(w);
18 ilm 623
        this.ecriturePanel.getListe().setSQLEditable(false);
624
 
625
        this.model.setIdCompte(Integer.parseInt(idCpt.toString()));
626
    }
627
 
628
    /*
629
     * Panel de sélection du mode d'affichage des ecritures
630
     */
631
    private JPanel createPanelSelectionEcritures() {
632
 
633
        JPanel panelSelectEcritures = new JPanel();
634
 
635
        GridBagConstraints cPanel = new GridBagConstraints();
636
        cPanel.anchor = GridBagConstraints.NORTHWEST;
637
        cPanel.fill = GridBagConstraints.HORIZONTAL;
638
        cPanel.gridheight = 1;
639
        cPanel.gridwidth = 1;
640
        cPanel.gridx = 0;
641
        cPanel.gridy = 0;
642
        cPanel.weightx = 0;
643
        cPanel.weighty = 0;
644
 
645
        panelSelectEcritures.setLayout(new GridBagLayout());
646
 
647
        final JRadioButton buttonBoth = new JRadioButton("Toutes");
648
        panelSelectEcritures.add(buttonBoth, cPanel);
649
        cPanel.gridx++;
650
        final JRadioButton buttonNotPointe = new JRadioButton("Non pointées");
651
        panelSelectEcritures.add(buttonNotPointe, cPanel);
652
        cPanel.gridx++;
653
        final JRadioButton buttonPointe = new JRadioButton("Pointées");
654
        panelSelectEcritures.add(buttonPointe, cPanel);
655
 
656
        ButtonGroup group = new ButtonGroup();
657
        group.add(buttonBoth);
658
        group.add(buttonNotPointe);
659
        group.add(buttonPointe);
660
        buttonBoth.setSelected(true);
661
 
662
        buttonPointe.addActionListener(new ActionListener() {
663
            public void actionPerformed(ActionEvent e) {
664
                if (buttonPointe.isSelected()) {
665
                    PointagePanel.this.modeSelect = ecriturePointee;
666
                    changeListRequest();
667
                }
668
            }
669
        });
670
 
671
        buttonNotPointe.addActionListener(new ActionListener() {
672
            public void actionPerformed(ActionEvent e) {
673
                if (buttonNotPointe.isSelected()) {
674
                    PointagePanel.this.modeSelect = ecritureNotPointee;
675
                    changeListRequest();
676
                }
677
            }
678
        });
679
 
680
        buttonBoth.addActionListener(new ActionListener() {
681
            public void actionPerformed(ActionEvent e) {
682
                if (buttonBoth.isSelected()) {
683
                    PointagePanel.this.modeSelect = allEcriture;
684
                    changeListRequest();
685
                }
686
            }
687
        });
688
 
689
        return panelSelectEcritures;
690
    }
691
 
692
    /*
693
     * Creation du panel de la legende
694
     */
695
    private JPanel createPanelLegende() {
696
        JPanel panelLegende = new JPanel();
697
 
698
        GridBagConstraints c = new GridBagConstraints();
699
        c.anchor = GridBagConstraints.NORTHWEST;
700
        c.fill = GridBagConstraints.HORIZONTAL;
701
        c.gridheight = 1;
702
        c.gridwidth = 1;
703
        c.gridx = 0;
704
        c.gridy = GridBagConstraints.RELATIVE;
705
        c.weightx = 0;
706
        c.weighty = 0;
707
        c.insets = new Insets(2, 0, 0, 0);
708
 
709
        GridBagConstraints cPanel = new GridBagConstraints();
710
        cPanel.anchor = GridBagConstraints.NORTHWEST;
711
        cPanel.fill = GridBagConstraints.HORIZONTAL;
712
        cPanel.gridheight = 1;
713
        cPanel.gridwidth = 1;
714
        cPanel.gridx = 0;
715
        cPanel.gridy = GridBagConstraints.RELATIVE;
716
        cPanel.weightx = 0;
717
        cPanel.weighty = 0;
718
        cPanel.insets = new Insets(0, 0, 0, 0);
719
 
720
        panelLegende.setLayout(new GridBagLayout());
721
        panelLegende.setBorder(BorderFactory.createTitledBorder("Légendes"));
722
 
723
        JPanel ecritureValidPanel = new JPanel();
724
        ecritureValidPanel.setLayout(new GridBagLayout());
725
        ecritureValidPanel.setBackground(Color.WHITE);
726
        ecritureValidPanel.add(new JLabel("Ecritures validées"), cPanel);
727
        panelLegende.add(ecritureValidPanel, c);
728
 
729
        JPanel ecritureNonValidPanel = new JPanel();
730
        ecritureNonValidPanel.setLayout(new GridBagLayout());
19 ilm 731
        ecritureNonValidPanel.setBackground(PointageRenderer.getCouleurEcritureNonValide());
18 ilm 732
        ecritureNonValidPanel.add(new JLabel("Ecritures non validées"), cPanel);
733
        panelLegende.add(ecritureNonValidPanel, c);
734
 
735
        JPanel ecritureNonValidTodayPanel = new JPanel();
736
        ecritureNonValidTodayPanel.setLayout(new GridBagLayout());
737
        ecritureNonValidTodayPanel.setBackground(PointageRenderer.getCouleurEcritureToDay());
738
        ecritureNonValidTodayPanel.add(new JLabel("Ecritures non validées du jour"), cPanel);
739
        panelLegende.add(ecritureNonValidTodayPanel, c);
740
 
741
        JPanel ecriturePointePanel = new JPanel();
742
        ecriturePointePanel.setLayout(new GridBagLayout());
743
        ecriturePointePanel.setBackground(PointageRenderer.getCouleurEcriturePointee());
744
        ecriturePointePanel.add(new JLabel("Ecritures pointées"), cPanel);
745
        panelLegende.add(ecriturePointePanel, c);
746
 
747
        return panelLegende;
748
    }
749
}