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
 
132 ilm 16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
18 ilm 17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
142 ilm 18
import org.openconcerto.erp.core.humanresources.payroll.ui.ContratPenibiliteTable;
18 ilm 19
import org.openconcerto.erp.model.PrixHT;
132 ilm 20
import org.openconcerto.sql.Configuration;
18 ilm 21
import org.openconcerto.sql.element.BaseSQLComponent;
22
import org.openconcerto.sql.element.ElementSQLObject;
23
import org.openconcerto.sql.element.SQLComponent;
132 ilm 24
import org.openconcerto.sql.model.SQLBase;
142 ilm 25
import org.openconcerto.sql.model.SQLRow;
18 ilm 26
import org.openconcerto.sql.model.SQLRowAccessor;
27
import org.openconcerto.sql.sqlobject.ElementComboBox;
28
import org.openconcerto.ui.DefaultGridBagConstraints;
29
import org.openconcerto.ui.JDate;
30
 
31
import java.awt.GridBagConstraints;
32
import java.awt.GridBagLayout;
33
import java.util.ArrayList;
34
import java.util.List;
35
 
36
import javax.swing.BorderFactory;
37
import javax.swing.JLabel;
38
import javax.swing.JPanel;
39
import javax.swing.JTextField;
40
import javax.swing.SwingConstants;
41
import javax.swing.event.DocumentEvent;
42
import javax.swing.event.DocumentListener;
43
 
44
public class InfosSalariePayeSQLElement extends ComptaSQLConfElement {
45
 
46
    public InfosSalariePayeSQLElement() {
156 ilm 47
        super("INFOS_SALARIE_PAYE", "une fiche d'informations salarié-paye", "fiches d'informations salariés-payes");
18 ilm 48
    }
49
 
132 ilm 50
    @Override
51
    public boolean isPrivate() {
52
        return true;
53
    }
54
 
18 ilm 55
    protected List<String> getListFields() {
56
        final List<String> l = new ArrayList<String>();
57
        l.add("ID_IDCC");
142 ilm 58
        l.add("ID_SALARIE");
18 ilm 59
        return l;
60
    }
61
 
62
    protected List<String> getComboFields() {
63
        final List<String> l = new ArrayList<String>();
142 ilm 64
        l.add("ID_SALARIE");
65
        l.add("ID_CONTRAT_SALARIE");
18 ilm 66
        return l;
67
    }
68
 
69
    /*
70
     * (non-Javadoc)
71
     *
72
     * @see org.openconcerto.devis.SQLElement#getComponent()
73
     */
74
    public SQLComponent createComponent() {
75
        return new BaseSQLComponent(this) {
76
 
77
            private JTextField dureeMois;
78
            private JTextField dureeHebdo;
79
 
80
            private DocumentListener listenerMois = new DocumentListener() {
81
 
82
                public void insertUpdate(DocumentEvent e) {
83
                    updateHebdo();
84
                }
85
 
86
                public void removeUpdate(DocumentEvent e) {
87
                    updateHebdo();
88
                }
89
 
90
                public void changedUpdate(DocumentEvent e) {
91
                    updateHebdo();
92
                }
93
            };
94
 
95
            private DocumentListener listenerHebdo = new DocumentListener() {
96
 
97
                public void insertUpdate(DocumentEvent e) {
98
                    updateMois();
99
                }
100
 
101
                public void removeUpdate(DocumentEvent e) {
102
                    updateMois();
103
                }
104
 
105
                public void changedUpdate(DocumentEvent e) {
106
                    updateMois();
107
                }
108
            };
109
 
142 ilm 110
            ContratPenibiliteTable tablePeni = new ContratPenibiliteTable();
111
 
112
            @Override
113
            public int insert(SQLRow order) {
114
                // TODO Auto-generated method stub
115
                int id = super.insert(order);
116
                tablePeni.updateField("ID_INFOS_SALARIE_PAYE", id);
117
                return id;
118
            }
119
 
120
            @Override
121
            public void update() {
122
                // TODO Auto-generated method stub
123
                int id = getSelectedID();
124
                super.update();
125
                tablePeni.updateField("ID_INFOS_SALARIE_PAYE", id);
126
            }
127
 
18 ilm 128
            public void addViews() {
129
                this.setLayout(new GridBagLayout());
130
                GridBagConstraints c = new DefaultGridBagConstraints();
131
 
132
                // Convention collective
133
                JLabel labelConvention = new JLabel(getLabelFor("ID_IDCC"));
134
                labelConvention.setHorizontalAlignment(SwingConstants.RIGHT);
135
                final ElementComboBox comboConvention = new ElementComboBox();
136
 
137
                this.add(labelConvention, c);
138
                c.gridx++;
139
                c.gridwidth = GridBagConstraints.REMAINDER;
140
                c.weightx = 1;
141
                this.add(comboConvention, c);
142
                c.gridwidth = 1;
143
 
144
                // Classement conventionnel
145
                c.fill = GridBagConstraints.BOTH;
146
                JPanel panelClassement = new JPanel();
147
                panelClassement.setOpaque(false);
148
                panelClassement.setBorder(BorderFactory.createTitledBorder("Classement conventionnel"));
149
                panelClassement.setLayout(new GridBagLayout());
150
                this.addView("ID_CLASSEMENT_CONVENTIONNEL", REQ + ";" + DEC + ";" + SEP);
151
                ElementSQLObject eltClassement = (ElementSQLObject) this.getView("ID_CLASSEMENT_CONVENTIONNEL");
152
                c.gridx = 0;
153
                c.gridy = 0;
154
                c.weightx = 1;
155
                panelClassement.add(eltClassement, c);
156
 
157
                c.gridy = 1;
158
                c.gridx = 0;
159
                c.gridwidth = 2;
160
                c.weightx = 0;
161
                this.add(panelClassement, c);
162
 
132 ilm 163
                // Classement conventionnel
164
                final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
165
                if (base.getTable("COEFF_PRIME") != null) {
166
                    c.fill = GridBagConstraints.BOTH;
167
                    JPanel panelCoeff = new JPanel();
168
                    panelCoeff.setOpaque(false);
169
                    panelCoeff.setBorder(BorderFactory.createTitledBorder("Coefficient prime"));
170
                    panelCoeff.setLayout(new GridBagLayout());
171
                    this.addView("ID_COEFF_PRIME", REQ + ";" + DEC + ";" + SEP);
172
                    ElementSQLObject eltCoeff = (ElementSQLObject) this.getView("ID_COEFF_PRIME");
173
                    c.gridx = 0;
174
                    c.gridy = 0;
175
                    c.weightx = 1;
176
                    panelCoeff.add(eltCoeff, c);
177
                    c.gridy = 2;
178
                    c.gridx = 0;
179
                    c.gridwidth = 2;
180
                    c.weightx = 0;
181
                    this.add(panelCoeff, c);
182
                    c.gridwidth = 1;
183
                }
18 ilm 184
                // Contrat
185
                c.fill = GridBagConstraints.BOTH;
186
                JPanel panelContrat = new JPanel();
187
                panelContrat.setOpaque(false);
188
                panelContrat.setBorder(BorderFactory.createTitledBorder("Contrat de travail"));
189
                panelContrat.setLayout(new GridBagLayout());
190
                GridBagConstraints c2 = new DefaultGridBagConstraints();
191
                c2.fill = GridBagConstraints.HORIZONTAL;
192
                c2.weighty = 1;
193
                c2.weightx = 1;
194
                c2.anchor = GridBagConstraints.NORTH;
195
                this.addView("ID_CONTRAT_SALARIE", REQ + ";" + DEC + ";" + SEP);
196
                ElementSQLObject eltContrat = (ElementSQLObject) this.getView("ID_CONTRAT_SALARIE");
197
                panelContrat.add(eltContrat, c2);
198
 
199
                c.gridx = 2;
200
                c.gridy = 1;
142 ilm 201
                c.gridheight = 4;
18 ilm 202
                c.gridwidth = GridBagConstraints.REMAINDER;
203
                c.weightx = 1;
204
                this.add(panelContrat, c);
205
                c.gridwidth = 1;
206
                c.gridheight = 1;
207
 
208
                /***********************************************************************************
209
                 * DATE ENTREE / SORTIE
210
                 **********************************************************************************/
211
                JPanel panelEntreeSortie = new JPanel();
212
                panelEntreeSortie.setOpaque(false);
213
                panelEntreeSortie.setBorder(BorderFactory.createTitledBorder("Entrée/Sortie"));
214
                panelEntreeSortie.setLayout(new GridBagLayout());
215
 
216
                // Date d'arrivée dans la société
217
                JLabel labelDateArrive = new JLabel(getLabelFor("DATE_ARRIVE"));
218
                labelDateArrive.setHorizontalAlignment(SwingConstants.RIGHT);
219
                JDate dateArrive = new JDate(true);
220
                c.gridy = 0;
221
                c.gridx = 0;
222
                c.weightx = 0;
223
                c.fill = GridBagConstraints.HORIZONTAL;
224
                panelEntreeSortie.add(labelDateArrive, c);
225
                c.gridx++;
226
                panelEntreeSortie.add(dateArrive, c);
227
 
228
                // Date de sortie
229
                JLabel labelDateSortie = new JLabel(getLabelFor("DATE_SORTIE"));
230
                labelDateSortie.setHorizontalAlignment(SwingConstants.RIGHT);
231
                JDate dateSortie = new JDate();
232
 
233
                c.gridy++;
234
                c.gridx = 0;
235
                c.fill = GridBagConstraints.HORIZONTAL;
236
                panelEntreeSortie.add(labelDateSortie, c);
237
                c.gridx++;
238
                panelEntreeSortie.add(dateSortie, c);
239
 
240
                /*
241
                 * // Ancienneté JLabel labelAnc = new
242
                 * JLabel(Configuration.getInstance().getTranslator
243
                 * ().getLabelFor(InfosSalariePayeSQLElement
244
                 * .this.getTable().getField("DATE_SORTIE")));
245
                 * labelDateSortie.setHorizontalAlignment(SwingConstants.RIGHT); JTextField textAnc
246
                 * = new JTextField(5, false);
247
                 *
248
                 * c.gridy++; c.gridx = 0; c.fill = GridBagConstraints.HORIZONTAL;
249
                 * panelEntreeSortie.add(labelAnc, c); c.gridx++; panelEntreeSortie.add(textAnc, c);
250
                 */
251
                c.gridx = 0;
132 ilm 252
                c.gridy = 3;
18 ilm 253
                c.gridwidth = 2;
254
                this.add(panelEntreeSortie, c);
255
                c.gridwidth = 1;
256
 
142 ilm 257
                JPanel panelPeni = new JPanel();
258
                panelPeni.setOpaque(false);
259
                panelPeni.setBorder(BorderFactory.createTitledBorder("Pénibilité (S21.G00.34)"));
260
                panelPeni.setLayout(new GridBagLayout());
261
                GridBagConstraints cPeni = new DefaultGridBagConstraints();
262
                cPeni.weightx = 1;
263
                cPeni.weighty = 1;
264
                cPeni.fill = GridBagConstraints.BOTH;
265
 
266
                panelPeni.add(tablePeni, cPeni);
267
                c.gridy++;
268
                c.weighty = 1;
269
                c.fill = GridBagConstraints.BOTH;
270
                this.add(panelPeni, c);
271
                c.fill = GridBagConstraints.HORIZONTAL;
272
 
18 ilm 273
                /***********************************************************************************
274
                 * Valeurs de bases
275
                 **********************************************************************************/
276
                JPanel panelBase = new JPanel();
277
                panelBase.setOpaque(false);
278
                panelBase.setBorder(BorderFactory.createTitledBorder("Valeurs de base"));
279
                panelBase.setLayout(new GridBagLayout());
280
 
281
                // Durée mensuelle
282
                JLabel labelDureeMois = new JLabel(getLabelFor("DUREE_MOIS"));
283
                labelDureeMois.setHorizontalAlignment(SwingConstants.RIGHT);
284
                this.dureeMois = new JTextField();
285
                c.gridy = 0;
286
                c.gridx = 0;
287
                c.gridheight = 1;
288
                c.fill = GridBagConstraints.HORIZONTAL;
289
                panelBase.add(labelDureeMois, c);
290
                c.gridx++;
291
                c.weightx = 1;
292
                panelBase.add(this.dureeMois, c);
293
 
294
                // Durée hebdomadaire
295
                JLabel labelDureeHebdo = new JLabel(getLabelFor("DUREE_HEBDO"));
296
                labelDureeHebdo.setHorizontalAlignment(SwingConstants.RIGHT);
297
                this.dureeHebdo = new JTextField();
298
                c.gridx++;
299
                c.weightx = 0;
300
                panelBase.add(labelDureeHebdo, c);
301
                c.gridx++;
302
                c.weightx = 1;
303
                panelBase.add(this.dureeHebdo, c);
304
 
305
                // Salaire de base
306
                JLabel labelSalaireBase = new JLabel(getLabelFor("SALAIRE_MOIS"));
307
                labelSalaireBase.setHorizontalAlignment(SwingConstants.RIGHT);
308
                JTextField salaireBase = new JTextField();
309
                c.gridx++;
310
                c.weightx = 0;
311
                panelBase.add(labelSalaireBase, c);
312
                c.gridx++;
313
                c.weightx = 1;
314
                panelBase.add(salaireBase, c);
315
 
91 ilm 316
                if (getTable().contains("PRIME_TRANSPORT")) {
317
 
318
                    // PRIME_TRANSPORT
319
                    JLabel labelTransport = new JLabel(getLabelFor("PRIME_TRANSPORT"));
320
                    labelTransport.setHorizontalAlignment(SwingConstants.RIGHT);
321
 
322
                    c.gridy++;
323
                    c.gridx = 0;
324
                    c.gridheight = 1;
325
                    c.fill = GridBagConstraints.HORIZONTAL;
326
                    panelBase.add(labelTransport, c);
327
                    c.gridx++;
328
                    c.weightx = 1;
329
                    JTextField fieldTransp = new JTextField();
330
                    panelBase.add(fieldTransp, c);
331
                    addView(fieldTransp, "PRIME_TRANSPORT");
332
 
333
                    // Durée hebdomadaire
334
                    JLabel labelPanier = new JLabel(getLabelFor("PRIME_PANIER"));
335
                    labelPanier.setHorizontalAlignment(SwingConstants.RIGHT);
336
                    JTextField fieldPanier = new JTextField();
337
                    c.gridx++;
338
                    c.weightx = 0;
339
                    panelBase.add(labelPanier, c);
340
                    c.gridx++;
341
                    c.weightx = 1;
342
                    panelBase.add(fieldPanier, c);
343
                    addView(fieldPanier, "PRIME_PANIER");
344
 
345
                    // Salaire de base
346
                    JLabel labelLogement = new JLabel(getLabelFor("PRIME_LOGEMENT"));
347
                    labelLogement.setHorizontalAlignment(SwingConstants.RIGHT);
348
                    JTextField fieldLogement = new JTextField();
349
                    c.gridx++;
350
                    c.weightx = 0;
351
                    panelBase.add(labelLogement, c);
352
                    c.gridx++;
353
                    c.weightx = 1;
354
                    panelBase.add(fieldLogement, c);
355
                    addView(fieldLogement, "PRIME_LOGEMENT");
356
 
357
                    // PRIME_TRANSPORT
358
                    JLabel labelCnam = new JLabel(getLabelFor("NUMERO_CNAM"));
359
                    labelCnam.setHorizontalAlignment(SwingConstants.RIGHT);
360
                    c.gridy++;
361
                    c.gridx = 0;
362
                    c.gridheight = 1;
363
                    c.fill = GridBagConstraints.HORIZONTAL;
364
                    panelBase.add(labelCnam, c);
365
                    c.gridx++;
366
                    c.weightx = 1;
367
                    JTextField fieldCnam = new JTextField();
368
                    panelBase.add(fieldCnam, c);
369
                    addView(fieldCnam, "NUMERO_CNAM");
370
 
371
                    // Durée hebdomadaire
372
                    JLabel labelCNSS = new JLabel(getLabelFor("NUMERO_CNSS"));
373
                    labelCNSS.setHorizontalAlignment(SwingConstants.RIGHT);
374
                    JTextField fieldCnss = new JTextField();
375
                    c.gridx++;
376
                    c.weightx = 0;
377
                    panelBase.add(labelCNSS, c);
378
                    c.gridx++;
379
                    c.weightx = 1;
380
                    panelBase.add(fieldCnss, c);
381
                    addView(fieldCnss, "NUMERO_CNSS");
382
 
383
                }
18 ilm 384
                // Taux AT
385
                JLabel labelTauxAT = new JLabel(getLabelFor("TAUX_AT"));
386
                labelTauxAT.setHorizontalAlignment(SwingConstants.RIGHT);
387
                JTextField tauxAT = new JTextField();
388
                c.gridy++;
389
                c.gridx = 0;
390
                c.weightx = 0;
391
                panelBase.add(labelTauxAT, c);
392
                c.gridx++;
393
                c.weightx = 1;
394
                panelBase.add(tauxAT, c);
395
 
396
                // Congés payés
397
                JLabel labelConges = new JLabel(getLabelFor("CONGES_PAYES"));
398
                labelConges.setHorizontalAlignment(SwingConstants.RIGHT);
399
                JTextField conges = new JTextField();
400
                c.gridx++;
401
                c.weightx = 0;
402
                panelBase.add(labelConges, c);
403
                c.gridx++;
404
                c.weightx = 1;
405
                panelBase.add(conges, c);
406
 
132 ilm 407
                if (getTable().contains("BASE_FILLON_ANNUELLE")) {
408
                    JLabel labelFillon = new JLabel(getLabelFor("BASE_FILLON_ANNUELLE"));
409
                    labelFillon.setHorizontalAlignment(SwingConstants.RIGHT);
410
                    JTextField fillon = new JTextField();
411
                    c.gridx++;
412
                    c.weightx = 0;
413
                    panelBase.add(labelFillon, c);
414
                    c.gridx++;
415
                    c.weightx = 1;
416
                    panelBase.add(fillon, c);
417
                    addView(fillon, "BASE_FILLON_ANNUELLE");
418
                }
419
 
41 ilm 420
                // Code AT
421
                JLabel labelCodeAT = new JLabel(getLabelFor("CODE_AT"));
422
                labelCodeAT.setHorizontalAlignment(SwingConstants.RIGHT);
423
                JTextField CodeAT = new JTextField();
424
                c.gridy++;
425
                c.gridx = 0;
426
                c.weightx = 0;
427
                panelBase.add(labelCodeAT, c);
428
                c.gridx++;
429
                c.weightx = 1;
430
                panelBase.add(CodeAT, c);
151 ilm 431
                addView(CodeAT, "CODE_AT", REQ);
41 ilm 432
 
433
                // Code section AT
434
                JLabel labelSectionAT = new JLabel(getLabelFor("CODE_SECTION_AT"));
435
                labelSectionAT.setHorizontalAlignment(SwingConstants.RIGHT);
436
                JTextField sectionAT = new JTextField();
437
                c.gridx++;
438
                c.weightx = 0;
439
                panelBase.add(labelSectionAT, c);
440
                c.gridx++;
441
                c.weightx = 1;
442
                panelBase.add(sectionAT, c);
443
                addView(sectionAT, "CODE_SECTION_AT");
444
 
174 ilm 445
                if (getTable().contains("DUREE_FORFAIT")) {
446
                    JLabel labelForfait = new JLabel(getLabelFor("DUREE_FORFAIT"));
447
                    labelForfait.setHorizontalAlignment(SwingConstants.RIGHT);
448
                    JTextField forfait = new JTextField();
449
                    c.gridx++;
450
                    c.weightx = 0;
451
                    panelBase.add(labelForfait, c);
452
                    c.gridx++;
453
                    c.weightx = 1;
454
                    panelBase.add(forfait, c);
455
                    addView(forfait, "DUREE_FORFAIT");
456
                }
457
 
142 ilm 458
                c.gridy = 5;
18 ilm 459
                c.gridx = 0;
460
                c.gridwidth = GridBagConstraints.REMAINDER;
461
                c.weighty = 1;
462
                c.weightx = 1;
463
                c.anchor = GridBagConstraints.NORTHWEST;
464
                this.add(panelBase, c);
465
 
466
                this.addRequiredSQLObject(comboConvention, "ID_IDCC");
467
                this.addRequiredSQLObject(dateArrive, "DATE_ARRIVE");
468
                this.addSQLObject(dateSortie, "DATE_SORTIE");
469
                this.addRequiredSQLObject(this.dureeHebdo, "DUREE_HEBDO");
470
                this.addRequiredSQLObject(this.dureeMois, "DUREE_MOIS");
471
                this.addRequiredSQLObject(tauxAT, "TAUX_AT");
472
                this.addRequiredSQLObject(conges, "CONGES_PAYES");
473
                this.addRequiredSQLObject(salaireBase, "SALAIRE_MOIS");
474
                // this.addRequiredSQLObject(textAnc, "ANCIENNETE");
475
 
476
                // Listener
477
                this.dureeMois.getDocument().addDocumentListener(this.listenerMois);
478
                this.dureeHebdo.getDocument().addDocumentListener(this.listenerHebdo);
479
            }
480
 
481
            private void updateHebdo() {
482
 
483
                if (this.dureeMois.getText().trim().length() == 0) {
484
                    return;
485
                } else {
486
 
487
                    this.dureeHebdo.getDocument().removeDocumentListener(this.listenerHebdo);
488
 
489
                    this.dureeHebdo.setText(String.valueOf(new PrixHT(Float.parseFloat(this.dureeMois.getText()) / (52.0 / 12.0)).getValue()));
490
 
491
                    this.dureeHebdo.getDocument().addDocumentListener(this.listenerHebdo);
492
                }
493
            }
494
 
495
            private void updateMois() {
496
 
497
                if (this.dureeHebdo.getText().trim().length() == 0) {
498
                    return;
499
                } else {
500
 
501
                    this.dureeMois.getDocument().removeDocumentListener(this.listenerMois);
502
 
503
                    this.dureeMois.setText(String.valueOf(new PrixHT(Float.parseFloat(this.dureeHebdo.getText()) * (52.0 / 12.0)).getValue()));
504
 
505
                    this.dureeMois.getDocument().addDocumentListener(this.listenerMois);
506
                }
507
            }
508
 
509
            @Override
510
            public void select(SQLRowAccessor r) {
511
                this.dureeMois.getDocument().removeDocumentListener(this.listenerMois);
512
                this.dureeHebdo.getDocument().removeDocumentListener(this.listenerHebdo);
513
 
514
                super.select(r);
515
 
142 ilm 516
                if (r != null) {
517
                    tablePeni.insertFrom("ID_INFOS_SALARIE_PAYE", r.getID());
518
                }
519
 
18 ilm 520
                this.dureeMois.getDocument().addDocumentListener(this.listenerMois);
521
                this.dureeHebdo.getDocument().addDocumentListener(this.listenerHebdo);
522
            }
523
        };
524
    }
57 ilm 525
 
526
    @Override
527
    protected String createCode() {
156 ilm 528
        return createCodeOfPackage() + ".info";
57 ilm 529
    }
18 ilm 530
}