OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.humanresources.payroll.element;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18
import org.openconcerto.erp.core.common.ui.JNiceButton;
151 ilm 19
import org.openconcerto.erp.core.common.ui.PanelFrame;
18 ilm 20
import org.openconcerto.erp.core.humanresources.payroll.component.VariableRowTreeNode;
151 ilm 21
import org.openconcerto.erp.core.humanresources.payroll.report.FichePayeSheetXML;
18 ilm 22
import org.openconcerto.erp.core.humanresources.payroll.ui.FichePayeRenderer;
151 ilm 23
import org.openconcerto.erp.core.humanresources.payroll.ui.PanelCumulsPaye;
18 ilm 24
import org.openconcerto.erp.generationEcritures.GenerationMvtFichePaye;
25
import org.openconcerto.erp.model.FichePayeModel;
151 ilm 26
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
18 ilm 27
import org.openconcerto.erp.model.RubriquePayeTree;
28
import org.openconcerto.sql.Configuration;
29
import org.openconcerto.sql.element.BaseSQLComponent;
30
import org.openconcerto.sql.element.SQLComponent;
73 ilm 31
import org.openconcerto.sql.element.SQLElementDirectory;
144 ilm 32
import org.openconcerto.sql.element.SQLElementLink.LinkType;
142 ilm 33
import org.openconcerto.sql.element.SQLElementLinksSetup;
18 ilm 34
import org.openconcerto.sql.element.TreesOfSQLRows;
35
import org.openconcerto.sql.model.SQLBase;
73 ilm 36
import org.openconcerto.sql.model.SQLField;
18 ilm 37
import org.openconcerto.sql.model.SQLRow;
38
import org.openconcerto.sql.model.SQLRowAccessor;
73 ilm 39
import org.openconcerto.sql.model.SQLRowListRSH;
18 ilm 40
import org.openconcerto.sql.model.SQLRowValues;
41
import org.openconcerto.sql.model.SQLSelect;
28 ilm 42
import org.openconcerto.sql.model.SQLSystem;
18 ilm 43
import org.openconcerto.sql.model.SQLTable;
44
import org.openconcerto.sql.sqlobject.ElementComboBox;
45
import org.openconcerto.sql.view.EditFrame;
46
import org.openconcerto.sql.view.IListFrame;
151 ilm 47
import org.openconcerto.sql.view.list.IListe;
48
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
49
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
18 ilm 50
import org.openconcerto.ui.DefaultGridBagConstraints;
51
import org.openconcerto.ui.JDate;
144 ilm 52
import org.openconcerto.ui.component.ITextArea;
93 ilm 53
import org.openconcerto.ui.component.InteractionMode;
73 ilm 54
import org.openconcerto.utils.ExceptionHandler;
18 ilm 55
 
144 ilm 56
import java.awt.GridBagConstraints;
57
import java.awt.GridBagLayout;
58
import java.awt.event.ActionEvent;
59
import java.awt.event.ActionListener;
60
import java.awt.event.MouseAdapter;
61
import java.awt.event.MouseEvent;
62
import java.beans.PropertyChangeEvent;
63
import java.beans.PropertyChangeListener;
64
import java.sql.SQLException;
65
import java.util.ArrayList;
66
import java.util.Arrays;
67
import java.util.Calendar;
68
import java.util.Date;
69
import java.util.List;
70
 
71
import javax.swing.AbstractAction;
72
import javax.swing.BorderFactory;
73
import javax.swing.JButton;
74
import javax.swing.JLabel;
75
import javax.swing.JOptionPane;
76
import javax.swing.JPanel;
77
import javax.swing.JPopupMenu;
78
import javax.swing.JScrollPane;
79
import javax.swing.JSplitPane;
80
import javax.swing.JTable;
81
import javax.swing.JTextField;
82
import javax.swing.SwingUtilities;
83
import javax.swing.tree.TreePath;
84
 
18 ilm 85
public class FichePayeSQLElement extends ComptaSQLConfElement {
86
 
87
    public FichePayeSQLElement() {
88
        super("FICHE_PAYE", "une fiche de paye", "fiches de paye");
151 ilm 89
 
90
        MouseSheetXmlListeListener l = new MouseSheetXmlListeListener(FichePayeSheetXML.class);
91
        getRowActions().addAll(l.getRowActions());
92
 
93
        PredicateRowAction actionCumuls = new PredicateRowAction(new AbstractAction("Détails cumuls et variables") {
94
 
95
            @Override
96
            public void actionPerformed(ActionEvent e) {
97
                final PanelCumulsPaye pCumuls = new PanelCumulsPaye();
98
                final PanelFrame p = new PanelFrame(pCumuls, "Détails cumuls et variables");
99
                pCumuls.selectFiche(IListe.get(e).getSelectedRow().asRow());
100
                p.setVisible(true);
101
            }
102
        }, true);
103
        actionCumuls.setPredicate(IListeEvent.getSingleSelectionPredicate());
104
        getRowActions().add(actionCumuls);
105
 
18 ilm 106
    }
107
 
108
    protected List<String> getListFields() {
109
        final List<String> l = new ArrayList<String>();
110
        l.add("ID_SALARIE");
111
        l.add("ID_MOIS");
112
        l.add("ANNEE");
113
        l.add("NET_A_PAYER");
114
        return l;
115
    }
116
 
117
    protected List<String> getComboFields() {
118
        final List<String> l = new ArrayList<String>();
119
        l.add("ID_SALARIE");
120
        l.add("ID_MOIS");
121
        l.add("ANNEE");
122
        return l;
123
    }
124
 
132 ilm 125
    @Override
126
    public boolean isPrivate() {
127
        return true;
128
    }
129
 
142 ilm 130
    @Override
131
    protected void setupLinks(SQLElementLinksSetup links) {
132
        super.setupLinks(links);
133
        if (getTable().contains("ID_INFOS_SALARIE_PAYE")) {
134
            links.get("ID_INFOS_SALARIE_PAYE").setType(LinkType.ASSOCIATION);
135
        }
136
    }
137
 
18 ilm 138
    /*
139
     * (non-Javadoc)
140
     *
141
     * @see org.openconcerto.devis.SQLElement#getComponent()
142
     */
143
    // FIXME Place des rubriques importantes --> [Brut -- cotisations -- cotisations with CSG --
144
    // Net]
145
    // FIXME Date periode must be correct
146
    public SQLComponent createComponent() {
147
        return new BaseSQLComponent(this) {
148
 
149
            private FichePayeModel model;
150
            private ElementComboBox comboSelProfil, selSalCombo;
151
            private EditFrame edit = null;
152
            private ElementComboBox selMois;
153
            private int dernMois, dernAnnee;
154
            private JTextField textAnnee;
155
            JDate dateDu, dateAu;
156
            private JScrollPane paneTreeLeft;
157
            private JPanel pDate;
158
            private JButton buttonValider, buttonGenCompta;
159
 
160
            public void addViews() {
161
 
162
                this.dernMois = 0;
163
                this.dernAnnee = 0;
164
 
165
                this.setLayout(new GridBagLayout());
166
 
167
                final RubriquePayeTree tree = new RubriquePayeTree();
168
                tree.expandRow(0);
156 ilm 169
                JPanel panelLeft = new JPanel(new GridBagLayout());
170
                GridBagConstraints cLeft = new DefaultGridBagConstraints();
171
                cLeft.fill = GridBagConstraints.BOTH;
172
                cLeft.weightx = 1;
173
                cLeft.weighty = 1;
174
                cLeft.gridheight = GridBagConstraints.REMAINDER;
175
                panelLeft.add(tree, cLeft);
18 ilm 176
                this.paneTreeLeft = new JScrollPane(tree);
177
                // this.add(this.paneTreeLeft, c);
178
 
179
                // Panel Fiche paye on the right
180
                // Salarie
156 ilm 181
                JPanel panelRight = new JPanel(new GridBagLayout());
182
                final GridBagConstraints c = new DefaultGridBagConstraints();
183
                // Tree elt Fiche de Paye On the left
18 ilm 184
                c.fill = GridBagConstraints.HORIZONTAL;
185
                c.weightx = 1;
186
                c.weighty = 0;
187
                c.gridheight = 1;
188
                c.gridwidth = 2;
189
                this.selSalCombo = new ElementComboBox();
190
                // c.gridx++;
191
                panelRight.add(this.selSalCombo, c);
192
 
193
                // Mois
156 ilm 194
 
18 ilm 195
                JLabel labelMois = new JLabel("Fiche de paye du mois de");
196
                this.selMois = new ElementComboBox(true, 20);
197
                JLabel labelDu = new JLabel("Du");
198
                JLabel labelAu = new JLabel("Au");
199
                this.dateDu = new JDate();
200
                this.dateAu = new JDate();
201
 
202
                // JTextField textMois = new JTextField();
203
                JLabel labelAnnee = new JLabel("Année");
204
                this.textAnnee = new JTextField();
205
                {
156 ilm 206
                    this.pDate = new JPanel(new GridBagLayout());
207
                    GridBagConstraints cDate = new DefaultGridBagConstraints();
208
                    cDate.weightx = 0;
209
                    cDate.gridx = GridBagConstraints.RELATIVE;
18 ilm 210
                    this.pDate.setOpaque(false);
156 ilm 211
                    this.pDate.add(labelMois, cDate);
212
                    cDate.weightx = 1;
213
                    this.pDate.add(this.selMois, cDate);
214
                    cDate.weightx = 0;
215
                    this.pDate.add(labelAnnee, cDate);
216
                    cDate.weightx = 1;
217
                    this.pDate.add(this.textAnnee, cDate);
218
                    cDate.weightx = 0;
219
                    this.pDate.add(labelDu, cDate);
220
                    cDate.weightx = 0;
221
                    this.pDate.add(this.dateDu, cDate);
222
                    cDate.weightx = 0;
223
                    this.pDate.add(labelAu, cDate);
224
                    cDate.weightx = 0;
225
                    this.pDate.add(this.dateAu, cDate);
226
 
227
                    c.gridy++;
228
                    // c.gridx++;
229
                    c.fill = GridBagConstraints.HORIZONTAL;
230
                    c.weightx = 1;
231
                    c.weighty = 0;
232
                    c.gridheight = 1;
233
                    c.gridwidth = 2;
18 ilm 234
                    panelRight.add(this.pDate, c);
235
                }
156 ilm 236
                // c.gridx += 2;
237
                // c.weightx = 1;
238
                // c.gridwidth = 1;
239
                // c.fill = GridBagConstraints.HORIZONTAL;
240
                // panelRight.add(new JPanel(), c);
18 ilm 241
 
242
                // Action Button
243
 
156 ilm 244
                JPanel pButtons = new JPanel(new GridBagLayout());
18 ilm 245
                pButtons.setOpaque(false);
246
                JButton buttonUp = new JNiceButton(IListFrame.class.getResource("fleche_haut.png"));
247
                JButton buttonDown = new JNiceButton(IListFrame.class.getResource("fleche_bas.png"));
248
                JButton buttonRemove = new JNiceButton(SQLComponent.class.getResource("delete.png"));
249
                {
156 ilm 250
                    GridBagConstraints cButtons = new DefaultGridBagConstraints();
251
                    cButtons.weightx = 0;
252
                    cButtons.fill = GridBagConstraints.NONE;
253
                    cButtons.gridx = GridBagConstraints.RELATIVE;
254
                    pButtons.add(buttonUp, cButtons);
255
                    pButtons.add(buttonDown, cButtons);
256
                    pButtons.add(buttonRemove, cButtons);
18 ilm 257
                }
156 ilm 258
                c.gridx += 2;
259
                c.fill = GridBagConstraints.NONE;
260
                c.weightx = 0;
261
                c.weighty = 0;
262
                c.gridwidth = 1;
18 ilm 263
                panelRight.add(pButtons, c);
264
 
265
                // Table
266
                c.fill = GridBagConstraints.BOTH;
267
                c.weightx = 1;
268
                c.weighty = 1;
156 ilm 269
                c.gridx = 0;
18 ilm 270
                c.gridy++;
271
                c.gridwidth = GridBagConstraints.REMAINDER;
272
                this.model = new FichePayeModel(1);
273
                final JTable table = new JTable(this.model);
274
                panelRight.add(new JScrollPane(table), c);
275
                FichePayeRenderer rend = new FichePayeRenderer();
276
                table.setDefaultRenderer(String.class, rend);
277
                table.setDefaultRenderer(Float.class, rend);
278
 
279
                // Import profil
156 ilm 280
                c.gridx = 0;
18 ilm 281
                c.gridy++;
282
                c.weightx = 0;
283
                c.weighty = 0;
284
                c.gridwidth = 1;
285
                c.fill = GridBagConstraints.HORIZONTAL;
156 ilm 286
                JLabel labelProfil = new JLabel("Lié à un profil prédéfini");
18 ilm 287
                panelRight.add(labelProfil, c);
288
                c.gridwidth = 1;
289
                this.comboSelProfil = new ElementComboBox();
290
                // this.comboSelProfil = new ElementComboBox();
291
                this.comboSelProfil.setListIconVisible(false);
292
                c.gridx++;
293
                c.gridwidth = 1;
156 ilm 294
                c.weightx = 1;
18 ilm 295
 
296
                // this.comboSelProfil.init(eltProfil.getTable().getField("NOM"), null);
297
                panelRight.add(this.comboSelProfil, c);
298
 
299
                JButton buttonImportProfil = new JButton("Importer");
300
                c.gridx++;
156 ilm 301
                c.weightx = 0;
18 ilm 302
                panelRight.add(buttonImportProfil, c);
303
 
304
                // Total Periode
156 ilm 305
                JPanel panelTotal = new JPanel(new GridBagLayout());
18 ilm 306
                panelTotal.setBorder(BorderFactory.createTitledBorder("Total période"));
156 ilm 307
 
18 ilm 308
                GridBagConstraints cPanel = new DefaultGridBagConstraints();
309
 
144 ilm 310
                JLabel labelInfosConges = new JLabel(getLabelFor("DETAILS_CONGES"));
311
                panelTotal.add(labelInfosConges, cPanel);
312
                ITextArea textConges = new ITextArea();
313
                cPanel.gridx++;
314
                cPanel.weightx = 1;
315
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
316
                panelTotal.add(textConges, cPanel);
317
                addView(textConges, "DETAILS_CONGES");
318
 
18 ilm 319
                // Salaire brut
144 ilm 320
                cPanel.weightx = 0;
321
                cPanel.gridwidth = 1;
322
                cPanel.gridy++;
151 ilm 323
                cPanel.gridx = 0;
18 ilm 324
                JLabel labelBrut = new JLabel(getLabelFor("SAL_BRUT"));
325
                panelTotal.add(labelBrut, cPanel);
326
                JTextField textSalBrut = new JTextField(10);
327
                cPanel.gridx++;
328
                cPanel.weightx = 0;
329
                panelTotal.add(textSalBrut, cPanel);
330
                textSalBrut.setEditable(false);
331
                textSalBrut.setEnabled(false);
332
 
333
                // acompte
334
                cPanel.gridx++;
335
                JLabel labelAcompte = new JLabel(getLabelFor("ACOMPTE"));
336
                panelTotal.add(labelAcompte, cPanel);
337
                JTextField textAcompte = new JTextField(10);
338
                cPanel.gridx++;
339
                panelTotal.add(textAcompte, cPanel);
340
                // textAcompte.setEditable(false);
341
                // textAcompte.setEnabled(false);
342
 
343
                // Conges Acquis
344
                cPanel.gridx++;
345
                JLabel labelCongesAcquis = new JLabel(getLabelFor("CONGES_ACQUIS"));
346
                panelTotal.add(labelCongesAcquis, cPanel);
347
                JTextField textCongesAcquis = new JTextField(10);
348
                cPanel.gridx++;
349
                panelTotal.add(textCongesAcquis, cPanel);
350
 
351
                // cotisation salariale
352
                cPanel.gridx = 0;
353
                cPanel.gridy++;
354
                JLabel labelCotSal = new JLabel(getLabelFor("COT_SAL"));
355
                panelTotal.add(labelCotSal, cPanel);
356
                JTextField textCotSal = new JTextField(10);
357
                cPanel.gridx++;
358
                panelTotal.add(textCotSal, cPanel);
359
                textCotSal.setEditable(false);
360
                textCotSal.setEnabled(false);
361
 
362
                // cotisation patronale
363
                cPanel.gridx++;
364
                JLabel labelCotPat = new JLabel(getLabelFor("COT_PAT"));
365
                panelTotal.add(labelCotPat, cPanel);
366
                JTextField textCotPat = new JTextField(10);
367
                cPanel.gridx++;
368
                panelTotal.add(textCotPat, cPanel);
369
                textCotPat.setEditable(false);
370
                textCotPat.setEnabled(false);
371
 
372
                JLabel labelCSG = new JLabel(getLabelFor("CSG"));
373
                cPanel.gridx++;
374
                panelTotal.add(labelCSG, cPanel);
375
                JTextField textCSG = new JTextField(10);
376
                cPanel.gridx++;
377
                panelTotal.add(textCSG, cPanel);
378
                textCSG.setEditable(false);
379
                textCSG.setEnabled(false);
380
 
381
                // net imposable
382
                cPanel.gridx = 0;
383
                cPanel.gridy++;
384
                JLabel labelNetImp = new JLabel(getLabelFor("NET_IMP"));
385
                panelTotal.add(labelNetImp, cPanel);
386
                JTextField textNetImp = new JTextField(10);
387
                cPanel.gridx++;
388
                panelTotal.add(textNetImp, cPanel);
389
                textNetImp.setEditable(false);
390
                textNetImp.setEnabled(false);
391
 
392
                cPanel.gridx++;
393
                JLabel labelNetAPayer = new JLabel(getLabelFor("NET_A_PAYER"));
394
                panelTotal.add(labelNetAPayer, cPanel);
395
                JTextField textNetAPayer = new JTextField(10);
396
                cPanel.gridx++;
397
                panelTotal.add(textNetAPayer, cPanel);
398
                textNetAPayer.setEditable(false);
399
                textNetAPayer.setEnabled(false);
400
 
144 ilm 401
                cPanel.gridx++;
402
                JLabel labelCice = new JLabel(getLabelFor("CICE"));
403
                panelTotal.add(labelCice, cPanel);
404
                JTextField textCice = new JTextField(10);
405
                cPanel.gridx++;
406
                panelTotal.add(textCice, cPanel);
407
                textCice.setEditable(false);
408
                textCice.setEnabled(false);
409
                this.addSQLObject(textCice, "CICE");
410
 
156 ilm 411
                c.gridx = 0;
18 ilm 412
                c.gridy++;
156 ilm 413
                c.fill = GridBagConstraints.HORIZONTAL;
414
                c.weightx = 1;
415
                c.weighty = 0;
18 ilm 416
                c.gridwidth = GridBagConstraints.REMAINDER;
417
                panelRight.add(panelTotal, c);
418
 
419
                // Cumuls
420
 
421
                c.gridx = 1;
422
                c.gridy++;
423
                c.gridwidth = 1;
424
                c.fill = GridBagConstraints.NONE;
425
                this.buttonValider = new JButton("Valider");
426
                // panelRight.add(buttonValider, c);
427
 
428
                c.gridx++;
429
                c.gridwidth = 1;
430
                this.buttonGenCompta = new JButton("Generer la comptabilité");
431
                // panelRight.add(buttonGenCompta, c);
432
 
156 ilm 433
                GridBagConstraints cGlobal = new DefaultGridBagConstraints();
434
                cGlobal.gridx = 0;
435
                cGlobal.gridy = 0;
436
                cGlobal.gridwidth = 1;
437
                cGlobal.gridheight = 1;
438
                cGlobal.fill = GridBagConstraints.BOTH;
439
                cGlobal.weightx = 1;
440
                cGlobal.weighty = 1;
441
                this.add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, this.paneTreeLeft, panelRight), cGlobal);
18 ilm 442
 
443
                // Listeners
444
                this.buttonGenCompta.addActionListener(new ActionListener() {
445
                    public void actionPerformed(ActionEvent e) {
73 ilm 446
                        try {
447
                            int[] i = new int[1];
448
                            i[0] = getSelectedID();
18 ilm 449
 
73 ilm 450
                            SQLRow rowMois = getTable().getBase().getTable("MOIS").getRow(selMois.getSelectedId());
18 ilm 451
 
73 ilm 452
                            new GenerationMvtFichePaye(i, rowMois.getString("NOM"), textAnnee.getText());
453
                        } catch (Exception ex) {
454
                            ExceptionHandler.handle("Erreur de génération des mouvements", ex);
455
                        }
18 ilm 456
                    }
457
                });
458
 
459
                this.buttonValider.addActionListener(new ActionListener() {
460
                    public void actionPerformed(ActionEvent e) {
73 ilm 461
                        try {
462
                            validationFiche();
463
                        } catch (SQLException e1) {
464
                            ExceptionHandler.handle("Error while updating pay slip", e1);
465
                        }
18 ilm 466
                    }
467
                });
468
 
469
                buttonUp.addActionListener(new ActionListener() {
470
 
471
                    public void actionPerformed(ActionEvent e) {
472
                        int newRowSelected = model.upRow(table.getSelectedRow());
473
                        if (newRowSelected >= 0) {
474
                            table.setRowSelectionInterval(newRowSelected, newRowSelected);
475
                        }
476
                    }
477
                });
478
 
479
                buttonDown.addActionListener(new ActionListener() {
480
 
481
                    public void actionPerformed(ActionEvent e) {
482
                        int newRowSelected = model.downRow(table.getSelectedRow());
483
                        if (newRowSelected >= 0) {
484
                            table.setRowSelectionInterval(newRowSelected, newRowSelected);
485
                        }
486
                    }
487
                });
488
 
489
                buttonRemove.addActionListener(new ActionListener() {
490
 
491
                    public void actionPerformed(ActionEvent e) {
492
                        model.removeRow(table.getSelectedRow());
493
                    }
494
                });
495
 
496
                tree.addMouseListener(new MouseAdapter() {
497
 
498
                    public void mousePressed(MouseEvent mE) {
499
 
500
                        TreePath path = tree.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y);
501
 
502
                        final Object obj = path.getLastPathComponent();
503
 
504
                        if (obj == null) {
505
                            return;
506
                        }
507
 
508
                        if (mE.getClickCount() == 2 && mE.getButton() == MouseEvent.BUTTON1) {
509
 
510
                            if (obj instanceof VariableRowTreeNode) {
511
                                model.addRowAt(((VariableRowTreeNode) obj).getRow(), table.getSelectedRow());
512
                            }
513
                        } else {
514
 
515
                            if (mE.getButton() == 3) {
516
 
517
                                if (obj instanceof VariableRowTreeNode) {
518
 
519
                                    final SQLRow row = ((VariableRowTreeNode) obj).getRow();
520
 
521
                                    JPopupMenu menuDroit = new JPopupMenu();
522
 
523
                                    menuDroit.add(new AbstractAction("Editer") {
524
                                        public void actionPerformed(ActionEvent e) {
525
 
526
                                            if (edit != null) {
527
                                                edit.dispose();
528
                                            }
529
                                            edit = new EditFrame(Configuration.getInstance().getDirectory().getElement(row.getTable()), EditFrame.MODIFICATION);
530
                                            edit.selectionId(row.getID(), 0);
531
                                            edit.pack();
532
                                            edit.setVisible(true);
533
                                        }
534
                                    });
535
 
536
                                    menuDroit.add(new AbstractAction("Nouvelle rubrique") {
537
                                        public void actionPerformed(ActionEvent e) {
538
 
539
                                            if (edit != null) {
540
                                                edit.dispose();
541
                                            }
542
                                            edit = new EditFrame(Configuration.getInstance().getDirectory().getElement(row.getTable()));
543
                                            edit.pack();
544
                                            edit.setVisible(true);
545
                                        }
546
                                    });
547
 
548
                                    menuDroit.show(mE.getComponent(), mE.getPoint().x, mE.getPoint().y);
549
 
550
                                }
551
                            }
552
                        }
553
                    }
554
                });
555
 
556
                this.dateDu.addValueListener(new PropertyChangeListener() {
557
                    public void propertyChange(PropertyChangeEvent evt) {
558
                        if (!dateDu.isEmpty()) {
559
                            Date d = dateDu.getValue();
560
 
561
                            if (d != null) {
562
                                Calendar cal = Calendar.getInstance();
563
                                cal.setTime(d);
564
                                if (selMois.getSelectedId() > 1 && cal.get(Calendar.MONTH) + 2 != selMois.getSelectedId()) {
565
 
566
                                    cal.set(Calendar.DAY_OF_MONTH, 1);
567
                                    cal.set(Calendar.MONTH, selMois.getSelectedId() - 2);
568
                                    System.err.println("Du " + cal.getTime());
569
                                    dateDu.setValue(cal.getTime());
570
                                }
132 ilm 571
                                fireValidChange();
18 ilm 572
                            }
573
                        }
574
                    }
575
                });
576
 
577
                this.dateAu.addValueListener(new PropertyChangeListener() {
578
                    public void propertyChange(PropertyChangeEvent evt) {
579
                        if (!dateAu.isEmpty()) {
580
                            Date d = dateAu.getValue();
581
                            if (d != null) {
582
                                Calendar cal = Calendar.getInstance();
583
                                cal.setTime(d);
584
                                if (selMois.getSelectedId() > 1 && cal.get(Calendar.MONTH) + 2 != selMois.getSelectedId()) {
585
 
586
                                    // TODO checker l'annee
587
                                    // TODO ajouter dans le isValidated du au compris dans le mois
588
                                    // selectionne
589
 
590
                                    // Calendar.getInstance().set(Calendar.DAY_OF_MONTH, maxDay);
591
                                    cal.set(Calendar.DAY_OF_MONTH, 1);
592
                                    cal.set(Calendar.MONTH, selMois.getSelectedId() - 2);
593
                                    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
594
                                    System.err.println("Au " + cal.getTime());
595
                                    dateAu.setValue(cal.getTime());
596
                                }
132 ilm 597
                                fireValidChange();
18 ilm 598
                            }
599
                        }
600
                    }
601
                });
602
 
603
                this.addRequiredSQLObject(this.textAnnee, "ANNEE");
604
                this.addRequiredSQLObject(this.selMois, "ID_MOIS");
605
                this.addSQLObject(this.comboSelProfil, "ID_PROFIL_PAYE");
606
 
607
                this.addSQLObject(textCongesAcquis, "CONGES_ACQUIS");
608
                this.addSQLObject(textCotPat, "COT_PAT");
609
                this.addSQLObject(textCotSal, "COT_SAL");
610
                this.addSQLObject(textCSG, "CSG");
611
                this.addSQLObject(textNetAPayer, "NET_A_PAYER");
612
                this.addSQLObject(textNetImp, "NET_IMP");
613
                this.addSQLObject(textSalBrut, "SAL_BRUT");
614
                this.addSQLObject(textAcompte, "ACOMPTE");
615
                this.addSQLObject(this.selSalCombo, "ID_SALARIE");
616
 
617
                this.addRequiredSQLObject(this.dateDu, "DU");
618
                this.addRequiredSQLObject(this.dateAu, "AU");
619
 
93 ilm 620
                this.selSalCombo.setInteractionMode(InteractionMode.DISABLED);
18 ilm 621
                this.selSalCombo.setEnabled(false);
622
                this.selSalCombo.setButtonsVisible(false);
623
                // this.selSalCombo.setVisible(false);
624
 
625
                buttonImportProfil.addActionListener(new ActionListener() {
626
                    public void actionPerformed(ActionEvent e) {
627
 
628
                        model.loadFromProfil(comboSelProfil.getSelectedId());
629
                    }
630
                });
631
            }
632
 
144 ilm 633
            // private boolean isDateValid() {
634
            //
635
            // String yearS = this.textAnnee.getText().trim();
636
            // int annee = (yearS.length() == 0) ? 0 : Integer.parseInt(yearS);
637
            //
638
            // int mois = this.selMois.getSelectedId();
639
            // // System.err.println("année " + annee + " dernAnnee " + this.dernAnnee + " mois " +
640
            // // mois + " dernMois " + this.dernMois);
641
            //
642
            // return ((this.dernAnnee == 0) ? true : annee > this.dernAnnee) || ((this.dernMois ==
643
            // 0 || this.dernMois == 13) ? true : mois > this.dernMois);
644
            // }
645
            //
646
            // @Override
647
            // public synchronized ValidState getValidState() {
648
            // // FIXME add fireValidChange()
649
            // return super.getValidState().and(ValidState.createCached(isDateValid(), "Date
650
            // invalide"));
651
            // }
18 ilm 652
 
653
            public int insert(SQLRow order) {
654
 
655
                int id = super.insert(order);
656
                this.model.updateFields(id);
657
                return id;
658
            }
659
 
660
            @Override
661
            public void update() {
662
                super.update();
663
                this.model.updateFields(this.getSelectedID());
664
            }
665
 
666
            @Override
667
            public void select(SQLRowAccessor r) {
668
 
669
                // System.err.println("SELECT FICHE ID -> " + r.getID());
670
                super.select(r);
671
 
672
                if (r != null && r.getID() > 1) {
673
                    this.model.setFicheID(r.getID());
674
 
675
                    SQLTable tableSal = getTable().getBase().getTable("SALARIE");
676
                    SQLRow rowSal = tableSal.getRow(r.getInt("ID_SALARIE"));
677
 
678
                    this.dernMois = rowSal.getInt("DERNIER_MOIS");
679
                    this.dernAnnee = rowSal.getInt("DERNIERE_ANNEE");
680
 
681
                    this.selSalCombo.setVisible(((Boolean) r.getObject("VALIDE")).booleanValue());
682
                    this.paneTreeLeft.setVisible(!((Boolean) r.getObject("VALIDE")).booleanValue());
683
                    this.buttonValider.setVisible(!((Boolean) r.getObject("VALIDE")).booleanValue());
684
                    setpDateEnabled(!((Boolean) r.getObject("VALIDE")).booleanValue());
685
                }
93 ilm 686
                this.selSalCombo.setInteractionMode(InteractionMode.DISABLED);
18 ilm 687
                this.selSalCombo.setEnabled(false);
688
                this.selMois.setButtonsVisible(false);
689
                this.selSalCombo.setButtonsVisible(false);
690
            }
691
 
692
            private void setpDateEnabled(boolean b) {
693
 
694
                // System.err.println("Set date enable --> " + b);
132 ilm 695
 
93 ilm 696
                this.selMois.setInteractionMode((b) ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
18 ilm 697
                // this.selMois.setEnabled(b);
698
 
699
                this.textAnnee.setEditable(b);
700
                this.textAnnee.setEnabled(b);
701
 
132 ilm 702
                this.dateDu.setInteractionMode((b) ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
703
                this.dateAu.setInteractionMode((b) ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
18 ilm 704
            }
705
 
73 ilm 706
            private void validationFiche() throws SQLException {
18 ilm 707
 
708
                this.update();
709
                FichePayeSQLElement.validationFiche(this.getSelectedID());
710
            }
711
 
712
            protected SQLRowValues createDefaults() {
713
 
714
                System.err.println("**********Set Defaults on FichePaye.date");
715
                SQLRowValues rowVals = new SQLRowValues(getTable());
716
                Calendar cal = Calendar.getInstance();
717
                rowVals.put("ID_MOIS", cal.get(Calendar.MONTH) + 2);
718
                rowVals.put("ANNEE", cal.get(Calendar.YEAR));
719
 
720
                cal.set(Calendar.DAY_OF_MONTH, 1);
721
                rowVals.put("DU", new java.sql.Date(cal.getTime().getTime()));
722
 
723
                cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
724
                rowVals.put("AU", new java.sql.Date(cal.getTime().getTime()));
725
                return rowVals;
726
            }
727
 
728
        };
729
    }
730
 
144 ilm 731
    private static List<String> cumulFields = Arrays.asList("SAL_BRUT", "CSG", "COT_SAL", "COT_PAT", "NET_IMP", "HEURE_TRAV", "CICE", "AVANTAGE_NATURE", "ALLEGEMENT_COTISATION", "SAL_BASE_BRUT",
732
            "TAXE_CM_SAL", "TAXE_CM_PAT", "SAL_BRUT_COTISABLE", "SAL_BRUT_TAXABLE");
733
 
18 ilm 734
    @Override
735
    protected void archive(TreesOfSQLRows trees, boolean cutLinks) throws SQLException {
736
        super.archive(trees, cutLinks);
737
        for (SQLRow row : trees.getRows()) {
738
            if (row != null && row.getID() > 1) {
93 ilm 739
                if (JOptionPane.showConfirmDialog(null, "Soustraire les cumuls de cette fiche à celle en cours?", "Suppression d'une fiche de paye",
740
                        JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
18 ilm 741
                    // on effectue le cumul
742
                    // System.err.println("Calcul des cumuls");
743
 
744
                    SQLRow rowSal = row.getForeignRow("ID_SALARIE");
745
 
746
                    SQLRow rowCumuls = rowSal.getForeignRow("ID_CUMULS_PAYE");
747
 
144 ilm 748
                    SQLRowValues rowValsCumul = rowCumuls.createEmptyUpdateRow();
749
                    for (String string : cumulFields) {
750
                        float cumul = rowCumuls.getFloat(string + "_C") - row.getFloat(string);
751
                        rowValsCumul.put(string + "_C", new Float(cumul));
752
                    }
142 ilm 753
                    // TODO stocker les heures travaillées du mois pour faire déduction
754
                    // float heure = rowCumuls.getFloat("HEURE_TRAV_C") -
755
                    // row.getFloat("HEURE_TRAV");
18 ilm 756
                    float netAPayer = rowCumuls.getFloat("NET_A_PAYER_C") - row.getFloat("NET_A_PAYER") - row.getFloat("ACOMPTE");
757
                    rowValsCumul.put("NET_A_PAYER_C", new Float(netAPayer));
142 ilm 758
                    // rowValsCumul.put("HEURE_TRAV_C", new Float(heure));
18 ilm 759
 
760
                    try {
761
                        rowValsCumul.update();
762
                    } catch (SQLException e) {
763
                        e.printStackTrace();
764
                    }
765
 
766
                    // Calcul des congés
767
                    SQLRow rowCumulConge = rowSal.getForeignRow("ID_CUMULS_CONGES");
156 ilm 768
                    SQLRow rowVarSalFiche = row.getForeignRow("ID_VARIABLE_SALARIE");
769
                    SQLRow rowVarSal = rowSal.getForeignRow("ID_VARIABLE_SALARIE");
18 ilm 770
                    float congeCumule = rowCumulConge.getFloat("ACQUIS");
771
                    float congeRestant = rowCumulConge.getFloat("RESTANT");
772
 
156 ilm 773
                    float prisPeriode = rowVarSalFiche.getFloat("CONGES_PRIS");
18 ilm 774
 
775
                    congeRestant += prisPeriode;
776
                    congeCumule -= row.getFloat("CONGES_ACQUIS");
777
 
778
                    SQLRowValues rowValsCumulsConges = new SQLRowValues(rowCumulConge.getTable());
779
                    rowValsCumulsConges.put("ACQUIS", new Float(congeCumule));
780
                    rowValsCumulsConges.put("RESTANT", new Float(congeRestant));
781
 
782
                    try {
783
                        rowValsCumulsConges.update(rowCumulConge.getID());
784
                    } catch (SQLException e) {
785
                        e.printStackTrace();
786
                    }
787
 
156 ilm 788
                    // Annulation du cumul des variables
789
                    final SQLRowValues rowVals = rowVarSal.asRowValues();
790
                    for (final SQLField field : rowVarSalFiche.getTable().getContentFields()) {
791
                        if (!field.getName().endsWith("_DEFAULT_VAL") && !field.getName().endsWith("_CUMUL_VAL")) {
792
                            if (rowVarSalFiche.getTable().contains(field.getName() + "_CUMUL_VAL")) {
793
                                final float valPeriode = rowVarSalFiche.getObject(field.getName()) == null ? 0.0F : rowVarSalFiche.getFloat(field.getName());
794
                                final float valCumul = rowVarSal.getObject(field.getName() + "_CUMUL_VAL") == null ? 0.0F : rowVarSal.getFloat(field.getName() + "_CUMUL_VAL");
795
                                rowVals.put(field.getName() + "_CUMUL_VAL", valCumul - valPeriode);
796
                            }
797
 
798
                        }
799
                    }
800
                    try {
801
                        rowVals.update();
802
                    } catch (SQLException e) {
803
                        e.printStackTrace();
804
                    }
18 ilm 805
                }
806
            }
807
        }
808
    }
809
 
810
    /**
811
     * Validation de la fiche de paye en cours pour un salarié
812
     *
813
     * @param id id de la fiche à valider
73 ilm 814
     * @throws SQLException
18 ilm 815
     */
73 ilm 816
    public static synchronized void validationFiche(int id) throws SQLException {
18 ilm 817
        final int oldID = id;
818
 
819
        SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
820
        SQLTable tableSal = base.getTable("SALARIE");
821
        SQLTable tableCumulConge = base.getTable("CUMULS_CONGES");
822
        SQLTable tableVariableSal = base.getTable("VARIABLE_SALARIE");
823
        SQLTable tableFiche = base.getTable("FICHE_PAYE");
824
        SQLTable tableFicheElt = base.getTable("FICHE_PAYE_ELEMENT");
825
        SQLTable tableCumuls = base.getTable("CUMULS_PAYE");
826
 
827
        final SQLRowValues rowValsSal = new SQLRowValues(tableSal);
828
 
829
        final SQLRow rowFiche = tableFiche.getRow(oldID);
830
        final SQLRow rowSal = tableSal.getRow(rowFiche.getInt("ID_SALARIE"));
831
 
832
        // On teste que la fiche est entrée dans une période non cloturée
833
        if (!checkDateValid(id)) {
834
            String msg = "Impossible de créer la fiche de paye de " + rowSal.getString("NOM") + " " + rowSal.getString("PRENOM") + ".\n La période est cloturée.";
835
            JOptionPane.showMessageDialog(null, msg, "Création paye impossible", JOptionPane.INFORMATION_MESSAGE);
836
            return;
837
        }
838
 
839
        // valider les elements de la fiche
840
        validElements(id);
841
 
842
        // Sauvegarde des valeurs de la fiche (cumuls, conges, ...)
843
        stockValidValues(oldID);
844
 
845
        // creer et associer une nouvelle fiche au salarie
846
        final SQLRowValues rowValsNewFiche = new SQLRowValues(tableFiche);
847
 
848
        try {
849
            SQLRow r = rowValsNewFiche.insert();
850
            rowValsNewFiche.put("ID", r.getID());
851
            // System.err.println("rowValsNewFiche -----> " + r.getID());
852
        } catch (SQLException e) {
853
            e.printStackTrace();
854
        }
855
 
856
        // mis a jour de la periode
857
        int mois = rowFiche.getInt("ID_MOIS");
858
        int annee = rowFiche.getInt("ANNEE");
859
        rowValsNewFiche.put("ID_MOIS", mois);
860
        rowValsNewFiche.put("ANNEE", annee);
144 ilm 861
        final Calendar calDu = rowFiche.getDate("DU");
862
        calDu.add(Calendar.MONTH, 1);
863
        calDu.set(Calendar.DAY_OF_MONTH, 1);
864
        rowValsNewFiche.put("DU", calDu.getTime());
865
        calDu.set(Calendar.DAY_OF_MONTH, calDu.getActualMaximum(Calendar.DAY_OF_MONTH));
866
        rowValsNewFiche.put("AU", calDu.getTime());
18 ilm 867
        rowValsNewFiche.put("ID_PROFIL_PAYE", rowFiche.getInt("ID_PROFIL_PAYE"));
868
 
869
        /*
870
         * int ancMois = rowFiche.getInt("ID_MOIS"); int ancAnnee = rowFiche.getInt("ANNEE");
871
         *
872
         * rowValsSal.put("DERNIER_MOIS", ancMois); rowValsSal.put("DERNIERE_ANNEE", ancAnnee);
873
         *
874
         * try { rowValsSal.update(rowFiche.getInt("ID_SALARIE")); } catch (SQLException e1) {
875
         * e1.printStackTrace(); }
876
         *
877
         * int mois = ancMois - 2; mois = (mois + 1) % 12; mois += 2; int annee = ancAnnee; if (mois
878
         * == 2) { annee++; } rowValsNewFiche.put("ID_MOIS", mois); rowValsNewFiche.put("ANNEE",
879
         * annee); rowValsNewFiche.put("ID_PROFIL_PAYE", rowFiche.getInt("ID_PROFIL_PAYE"));
880
         *
881
         * try { rowValsNewFiche.update(); } catch (SQLException e) { e.printStackTrace(); }
882
         */
883
 
884
        rowValsNewFiche.put("ID_SALARIE", rowSal.getID());
885
        rowValsSal.put("ID_FICHE_PAYE", rowValsNewFiche.getID());
886
 
887
        SwingUtilities.invokeLater(new Runnable() {
888
            public void run() {
889
                try {
73 ilm 890
                    // FIXME: Ouch: sql in swing!
18 ilm 891
                    rowValsSal.update(rowSal.getID());
892
 
893
                    rowValsNewFiche.update();
894
                } catch (SQLException e1) {
895
                    e1.printStackTrace();
896
                }
897
            }
898
        });
899
        // On recupere la liste des elements de la fiche de paye
73 ilm 900
        SQLSelect selAllElt = new SQLSelect();
901
        selAllElt.addSelect(tableFicheElt.getKey());
18 ilm 902
        selAllElt.addSelect(tableFicheElt.getField("POSITION"));
73 ilm 903
        selAllElt.addSelect(tableFicheElt.getField("SOURCE"));
904
        selAllElt.addSelect(tableFicheElt.getField("IDSOURCE"));
65 ilm 905
        selAllElt.setWhere(tableFicheElt.getField("ID_FICHE_PAYE"), "=", oldID);
18 ilm 906
        selAllElt.setDistinct(true);
73 ilm 907
        selAllElt.addFieldOrder(tableFicheElt.getField("POSITION"));
18 ilm 908
 
73 ilm 909
        for (final SQLRow rowTmpElt : SQLRowListRSH.execute(selAllElt)) {
18 ilm 910
            String source = rowTmpElt.getString("SOURCE");
911
            int idSource = rowTmpElt.getInt("IDSOURCE");
912
            int pos = rowTmpElt.getInt("POSITION");
913
            SQLRowValues rowValsTmp = new SQLRowValues(tableFicheElt);
914
            rowValsTmp.put("SOURCE", source);
915
            rowValsTmp.put("IDSOURCE", idSource);
916
            rowValsTmp.put("POSITION", pos);
917
            rowValsTmp.put("ID_FICHE_PAYE", rowValsNewFiche.getID());
73 ilm 918
            rowValsTmp.commit();
18 ilm 919
        }
920
 
921
        // on effectue le cumul
922
        // System.err.println("Calcul des cumuls");
132 ilm 923
        final SQLRow rowVarSal = tableVariableSal.getRow(rowSal.getInt("ID_VARIABLE_SALARIE"));
18 ilm 924
        int idCumuls = rowSal.getInt("ID_CUMULS_PAYE");
925
        SQLRow rowCumuls = tableCumuls.getRow(idCumuls);
926
 
144 ilm 927
        SQLRowValues rowValsCumul = new SQLRowValues(tableCumuls);
928
        for (String string : cumulFields) {
929
            float cumul = rowCumuls.getFloat(string + "_C") + rowFiche.getFloat(string);
930
            rowValsCumul.put(string + "_C", new Float(cumul));
931
        }
18 ilm 932
        float netAPayer = rowCumuls.getFloat("NET_A_PAYER_C") + rowFiche.getFloat("NET_A_PAYER") + rowFiche.getFloat("ACOMPTE");
933
        rowValsCumul.put("NET_A_PAYER_C", new Float(netAPayer));
934
 
73 ilm 935
        SQLRow r = rowValsCumul.insert();
936
        rowValsCumul.put("ID", r.getID());
18 ilm 937
 
938
        // System.err.println("Mis a jour de la fiche de paye");
939
        rowValsSal.put("ID_CUMULS_PAYE", rowValsCumul.getID());
940
 
941
        SwingUtilities.invokeLater(new Runnable() {
942
            public void run() {
73 ilm 943
                // FIXME: Ouch: sql in swing!
18 ilm 944
                try {
945
                    rowValsSal.update(rowFiche.getInt("ID_SALARIE"));
946
                } catch (SQLException e1) {
947
                    e1.printStackTrace();
948
                }
949
            }
950
        });
951
        // Calcul des congés
952
        final SQLRow rowCumulConge = tableCumulConge.getRow(rowSal.getInt("ID_CUMULS_CONGES"));
132 ilm 953
 
18 ilm 954
        float congeCumule = rowCumulConge.getFloat("ACQUIS");
955
        float congeRestant = rowCumulConge.getFloat("RESTANT");
956
 
957
        float prisPeriode = rowVarSal.getFloat("CONGES_PRIS");
958
        congeRestant -= prisPeriode;
959
 
960
        SQLTable tableInfosSalPaye = base.getTable("INFOS_SALARIE_PAYE");
961
        final SQLRow rowSalInfosPaye = tableInfosSalPaye.getRow(rowSal.getInt("ID_INFOS_SALARIE_PAYE"));
962
 
963
        congeCumule += rowFiche.getFloat("CONGES_ACQUIS");
964
 
965
        final SQLRowValues rowValsCumulsConges = new SQLRowValues(tableCumulConge);
966
 
967
        // Si on passe le 1 juin
968
        // FIXME est ce que les conges nonpris sont à indemniser
969
        /*
970
         * if (mois == 7) { congeRestant = congeCumule; congeCumule = 0; }
971
         */
972
 
973
        rowValsCumulsConges.put("ACQUIS", new Float(congeCumule));
974
        rowValsCumulsConges.put("RESTANT", new Float(congeRestant));
975
 
976
        SwingUtilities.invokeLater(new Runnable() {
73 ilm 977
            public void run() { // FIXME: Ouch: sql in swing!
18 ilm 978
                try {
979
                    rowValsCumulsConges.update(rowCumulConge.getID());
980
                    rowValsNewFiche.put("CONGES_ACQUIS", new Float(rowSalInfosPaye.getFloat("CONGES_PAYES")));
981
                    rowValsNewFiche.update();
982
                } catch (SQLException e) {
983
                    e.printStackTrace();
984
                }
985
            }
986
        });
987
        final SQLRowValues rowValsOldFiche = new SQLRowValues(tableFiche);
988
        rowValsOldFiche.put("VALIDE", Boolean.TRUE);
989
 
990
        SwingUtilities.invokeLater(new Runnable() {
73 ilm 991
            public void run() { // FIXME: Ouch: sql in swing!
18 ilm 992
                try {
993
                    rowValsOldFiche.update(rowFiche.getID());
994
                } catch (SQLException e) {
995
                    e.printStackTrace();
996
                }
997
            }
998
        });
999
        // Remise à 0 des variables sal
1000
        final SQLRowValues rowVals = new SQLRowValues(tableVariableSal);
73 ilm 1001
        for (final SQLField field : tableVariableSal.getContentFields()) {
156 ilm 1002
            if (!field.getName().endsWith("_DEFAULT_VAL") && !field.getName().endsWith("_CUMUL_VAL")) {
1003
                if (tableVariableSal.contains(field.getName() + "_CUMUL_VAL")) {
1004
                    final float valPeriode = rowVarSal.getObject(field.getName()) == null ? 0.0F : rowVarSal.getFloat(field.getName());
1005
                    final float valCumul = rowVarSal.getObject(field.getName() + "_CUMUL_VAL") == null ? 0.0F : rowVarSal.getFloat(field.getName() + "_CUMUL_VAL");
1006
                    rowVals.put(field.getName() + "_CUMUL_VAL", valCumul + valPeriode);
1007
                }
144 ilm 1008
                if (tableVariableSal.contains(field.getName() + "_DEFAULT_VAL")) {
1009
                    rowVals.put(field.getName(), rowVarSal.getObject(field.getName() + "_DEFAULT_VAL"));
1010
                } else {
1011
                    if (field.getType().getJavaType() == Integer.class) {
1012
                        rowVals.put(field.getName(), 0);
1013
                    } else {
1014
                        rowVals.put(field.getName(), Float.valueOf(0));
1015
                    }
1016
                }
156 ilm 1017
 
142 ilm 1018
            }
18 ilm 1019
        }
132 ilm 1020
        rowVals.put("HEURE_TRAV", rowSalInfosPaye.getObject("DUREE_MOIS"));
91 ilm 1021
 
1022
        if (tableVariableSal.contains("NB_JOUR_MOIS")) {
1023
            rowVals.put("NB_JOUR_MOIS", Float.valueOf(31));
1024
            rowVals.put("NB_JOUR_TRAV", Float.valueOf(31));
1025
        }
18 ilm 1026
        SwingUtilities.invokeLater(new Runnable() {
73 ilm 1027
            public void run() { // FIXME: Ouch: sql in swing!
18 ilm 1028
                try {
1029
                    rowVals.update(rowVarSal.getID());
1030
                } catch (SQLException e) {
1031
                    e.printStackTrace();
1032
                }
1033
            }
1034
        });
1035
    }
1036
 
1037
    public static void clotureMensuelle(int idMois, int annee, int idSal) {
1038
 
1039
        SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
1040
        SQLRowValues rowValsSal = new SQLRowValues(base.getTable("SALARIE"));
1041
        SQLRow rowSal = base.getTable("SALARIE").getRow(idSal);
1042
        int ancMois = rowSal.getInt("DERNIER_MOIS");
1043
        int ancAnnee = rowSal.getInt("DERNIERE_ANNEE");
1044
 
1045
        // on verifie que le mois et l'année sont > aux anciennes valeurs
1046
        if (ancAnnee < annee && ancMois < idMois) {
1047
 
1048
            rowValsSal.put("DERNIER_MOIS", idMois);
1049
            rowValsSal.put("DERNIERE_ANNEE", annee);
1050
 
1051
            try {
1052
                rowValsSal.update(idSal);
1053
            } catch (SQLException e1) {
1054
                e1.printStackTrace();
1055
            }
1056
        }
1057
        /*
1058
         * int mois = ancMois - 2; mois = (mois + 1) % 12; mois += 2; int annee = ancAnnee; if (mois
1059
         * == 2) { annee++; } rowValsNewFiche.put("ID_MOIS", mois); rowValsNewFiche.put("ANNEE",
1060
         * annee); rowValsNewFiche.put("ID_PROFIL_PAYE", rowFiche.getInt("ID_PROFIL_PAYE"));
1061
         *
1062
         * try { rowValsNewFiche.update(); } catch (SQLException e) { e.printStackTrace(); }
1063
         */
1064
    }
1065
 
1066
    // stocke les éléments validés (cumuls congés, paye, ...)
73 ilm 1067
    private static void stockValidValues(final int id) throws SQLException {
1068
        final ComptaPropsConfiguration conf = ComptaPropsConfiguration.getInstanceCompta();
1069
        final SQLElementDirectory dir = conf.getDirectory();
1070
        final SQLTable tableFiche = conf.getRootSociete().getTable("FICHE_PAYE");
1071
        final SQLRow rowFiche = tableFiche.getRow(id);
1072
        final SQLRow rowSal = rowFiche.getForeignRow("ID_SALARIE");
18 ilm 1073
 
73 ilm 1074
        final SQLRowValues rowValsFiche = new SQLRowValues(tableFiche);
156 ilm 1075
        for (final String fk : Arrays.asList("ID_PAS", "ID_VARIABLE_SALARIE", "ID_CUMULS_CONGES", "ID_CUMULS_PAYE", "ID_REGLEMENT_PAYE")) {
73 ilm 1076
            final SQLRow fRow = rowSal.getForeignRow(fk);
1077
            final SQLRowValues copy = dir.getElement(fRow.getTable()).createCopy(fRow, null);
1078
            // make sure the copy will be inserted by the update()
1079
            assert copy.getIDNumber() == null;
1080
            rowValsFiche.put(fk, copy);
1081
        }
18 ilm 1082
 
73 ilm 1083
        final SQLRow rInfosSalPaye = rowSal.getForeignRow("ID_INFOS_SALARIE_PAYE");
1084
        final SQLRow rContrat = rInfosSalPaye.getForeignRow("ID_CONTRAT_SALARIE");
1085
        rowValsFiche.put("NATURE_EMPLOI", rContrat.getString("NATURE"));
1086
        rowValsFiche.put("ID_IDCC", rInfosSalPaye.getInt("ID_IDCC"));
142 ilm 1087
        rowValsFiche.put("ID_INFOS_SALARIE_PAYE", rInfosSalPaye.getID());
1088
 
73 ilm 1089
        rowValsFiche.update(id);
18 ilm 1090
 
1091
    }
1092
 
1093
    // FIXME retirer les rubriques non imprime ou pas dans de la periode de la fiche validee ??
1094
    private static void validElements(int id) {
1095
 
1096
        SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
1097
        System.err.println("Validation des éléments de la fiche.");
1098
        String trueString = "1";
28 ilm 1099
        if (Configuration.getInstance().getBase().getServer().getSQLSystem() == SQLSystem.POSTGRESQL) {
18 ilm 1100
            trueString = "true";
1101
        }
1102
        String req = "UPDATE \"FICHE_PAYE_ELEMENT\" SET \"VALIDE\" = " + trueString + " WHERE \"FICHE_PAYE_ELEMENT\".\"ID_FICHE_PAYE\" = " + id;
1103
 
1104
        base.getDataSource().execute(req);
1105
 
1106
        System.err.println("Validation terminée.");
1107
    }
1108
 
1109
    private static boolean checkDateValid(int idFiche) {
1110
 
1111
        SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
1112
 
1113
        SQLRow rowFiche = base.getTable("FICHE_PAYE").getRow(idFiche);
1114
        SQLRow rowSal = base.getTable("SALARIE").getRow(rowFiche.getInt("ID_SALARIE"));
1115
        int moisClot = rowSal.getInt("DERNIER_MOIS");
1116
        int anneeClot = rowSal.getInt("DERNIERE_ANNEE");
1117
 
1118
        int mois = rowFiche.getInt("ID_MOIS");
1119
        int annee = rowFiche.getInt("ANNEE");
1120
        return ((anneeClot == 0) ? true : annee > anneeClot) || ((moisClot == 0 || moisClot == 13) ? true : mois > moisClot);
1121
    }
57 ilm 1122
 
1123
    @Override
1124
    protected String createCode() {
156 ilm 1125
        return createCodeOfPackage() + ".payslip";
57 ilm 1126
    }
18 ilm 1127
}