OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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