OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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