OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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