OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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