OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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