OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | 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
 
180 ilm 144
                // Contrat
145
                c.fill = GridBagConstraints.BOTH;
146
                JPanel panelContrat = new JPanel();
147
                panelContrat.setOpaque(false);
148
                panelContrat.setBorder(BorderFactory.createTitledBorder("Contrat de travail"));
149
                panelContrat.setLayout(new GridBagLayout());
150
                GridBagConstraints c2 = new DefaultGridBagConstraints();
151
                c2.fill = GridBagConstraints.HORIZONTAL;
152
                c2.weighty = 1;
153
                c2.weightx = 1;
154
                c2.anchor = GridBagConstraints.NORTH;
155
                this.addView("ID_CONTRAT_SALARIE", REQ + ";" + DEC + ";" + SEP);
156
                ElementSQLObject eltContrat = (ElementSQLObject) this.getView("ID_CONTRAT_SALARIE");
157
                panelContrat.add(eltContrat, c2);
158
 
159
                c.gridx = 0;
160
                c.gridy++;
161
                c.gridheight = 1;
162
                c.gridwidth = GridBagConstraints.REMAINDER;
163
                c.weightx = 1;
164
                this.add(panelContrat, c);
165
                c.gridwidth = 1;
166
                c.gridheight = 1;
167
 
18 ilm 168
                // Classement conventionnel
169
                c.fill = GridBagConstraints.BOTH;
170
                JPanel panelClassement = new JPanel();
171
                panelClassement.setOpaque(false);
172
                panelClassement.setBorder(BorderFactory.createTitledBorder("Classement conventionnel"));
173
                panelClassement.setLayout(new GridBagLayout());
174
                this.addView("ID_CLASSEMENT_CONVENTIONNEL", REQ + ";" + DEC + ";" + SEP);
175
                ElementSQLObject eltClassement = (ElementSQLObject) this.getView("ID_CLASSEMENT_CONVENTIONNEL");
176
                c.gridx = 0;
177
                c.gridy = 0;
178
                c.weightx = 1;
179
                panelClassement.add(eltClassement, c);
180
 
180 ilm 181
                c.gridy = 2;
18 ilm 182
                c.gridx = 0;
183
                c.gridwidth = 2;
180 ilm 184
                c.weightx = 1;
18 ilm 185
                this.add(panelClassement, c);
186
 
132 ilm 187
                // Classement conventionnel
188
                final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
189
                if (base.getTable("COEFF_PRIME") != null) {
190
                    c.fill = GridBagConstraints.BOTH;
191
                    JPanel panelCoeff = new JPanel();
192
                    panelCoeff.setOpaque(false);
193
                    panelCoeff.setBorder(BorderFactory.createTitledBorder("Coefficient prime"));
194
                    panelCoeff.setLayout(new GridBagLayout());
195
                    this.addView("ID_COEFF_PRIME", REQ + ";" + DEC + ";" + SEP);
196
                    ElementSQLObject eltCoeff = (ElementSQLObject) this.getView("ID_COEFF_PRIME");
197
                    c.gridx = 0;
198
                    c.gridy = 0;
199
                    c.weightx = 1;
200
                    panelCoeff.add(eltCoeff, c);
180 ilm 201
                    c.gridy = 3;
132 ilm 202
                    c.gridx = 0;
203
                    c.gridwidth = 2;
204
                    c.weightx = 0;
205
                    this.add(panelCoeff, c);
206
                    c.gridwidth = 1;
207
                }
18 ilm 208
 
209
                /***********************************************************************************
210
                 * DATE ENTREE / SORTIE
211
                 **********************************************************************************/
212
                JPanel panelEntreeSortie = new JPanel();
213
                panelEntreeSortie.setOpaque(false);
214
                panelEntreeSortie.setBorder(BorderFactory.createTitledBorder("Entrée/Sortie"));
215
                panelEntreeSortie.setLayout(new GridBagLayout());
216
 
217
                // Date d'arrivée dans la société
218
                JLabel labelDateArrive = new JLabel(getLabelFor("DATE_ARRIVE"));
219
                labelDateArrive.setHorizontalAlignment(SwingConstants.RIGHT);
220
                JDate dateArrive = new JDate(true);
221
                c.gridy = 0;
222
                c.gridx = 0;
223
                c.weightx = 0;
224
                c.fill = GridBagConstraints.HORIZONTAL;
225
                panelEntreeSortie.add(labelDateArrive, c);
226
                c.gridx++;
227
                panelEntreeSortie.add(dateArrive, c);
228
 
229
                // Date de sortie
230
                JLabel labelDateSortie = new JLabel(getLabelFor("DATE_SORTIE"));
231
                labelDateSortie.setHorizontalAlignment(SwingConstants.RIGHT);
232
                JDate dateSortie = new JDate();
233
 
234
                c.gridy++;
235
                c.gridx = 0;
236
                c.fill = GridBagConstraints.HORIZONTAL;
237
                panelEntreeSortie.add(labelDateSortie, c);
238
                c.gridx++;
239
                panelEntreeSortie.add(dateSortie, c);
240
 
241
                /*
242
                 * // Ancienneté JLabel labelAnc = new
243
                 * JLabel(Configuration.getInstance().getTranslator
244
                 * ().getLabelFor(InfosSalariePayeSQLElement
245
                 * .this.getTable().getField("DATE_SORTIE")));
246
                 * labelDateSortie.setHorizontalAlignment(SwingConstants.RIGHT); JTextField textAnc
247
                 * = new JTextField(5, false);
248
                 *
249
                 * c.gridy++; c.gridx = 0; c.fill = GridBagConstraints.HORIZONTAL;
250
                 * panelEntreeSortie.add(labelAnc, c); c.gridx++; panelEntreeSortie.add(textAnc, c);
251
                 */
180 ilm 252
                c.gridx = 2;
253
                c.gridy = 2;
18 ilm 254
                c.gridwidth = 2;
255
                this.add(panelEntreeSortie, c);
256
                c.gridwidth = 1;
257
 
142 ilm 258
                JPanel panelPeni = new JPanel();
259
                panelPeni.setOpaque(false);
260
                panelPeni.setBorder(BorderFactory.createTitledBorder("Pénibilité (S21.G00.34)"));
261
                panelPeni.setLayout(new GridBagLayout());
262
                GridBagConstraints cPeni = new DefaultGridBagConstraints();
263
                cPeni.weightx = 1;
264
                cPeni.weighty = 1;
265
                cPeni.fill = GridBagConstraints.BOTH;
266
 
267
                panelPeni.add(tablePeni, cPeni);
268
                c.gridy++;
269
                c.weighty = 1;
270
                c.fill = GridBagConstraints.BOTH;
271
                this.add(panelPeni, c);
272
                c.fill = GridBagConstraints.HORIZONTAL;
273
 
18 ilm 274
                /***********************************************************************************
275
                 * Valeurs de bases
276
                 **********************************************************************************/
277
                JPanel panelBase = new JPanel();
278
                panelBase.setOpaque(false);
279
                panelBase.setBorder(BorderFactory.createTitledBorder("Valeurs de base"));
280
                panelBase.setLayout(new GridBagLayout());
281
 
282
                // Durée mensuelle
283
                JLabel labelDureeMois = new JLabel(getLabelFor("DUREE_MOIS"));
284
                labelDureeMois.setHorizontalAlignment(SwingConstants.RIGHT);
285
                this.dureeMois = new JTextField();
286
                c.gridy = 0;
287
                c.gridx = 0;
288
                c.gridheight = 1;
289
                c.fill = GridBagConstraints.HORIZONTAL;
290
                panelBase.add(labelDureeMois, c);
291
                c.gridx++;
292
                c.weightx = 1;
293
                panelBase.add(this.dureeMois, c);
294
 
295
                // Durée hebdomadaire
296
                JLabel labelDureeHebdo = new JLabel(getLabelFor("DUREE_HEBDO"));
297
                labelDureeHebdo.setHorizontalAlignment(SwingConstants.RIGHT);
298
                this.dureeHebdo = new JTextField();
299
                c.gridx++;
300
                c.weightx = 0;
301
                panelBase.add(labelDureeHebdo, c);
302
                c.gridx++;
303
                c.weightx = 1;
304
                panelBase.add(this.dureeHebdo, c);
305
 
306
                // Salaire de base
307
                JLabel labelSalaireBase = new JLabel(getLabelFor("SALAIRE_MOIS"));
308
                labelSalaireBase.setHorizontalAlignment(SwingConstants.RIGHT);
309
                JTextField salaireBase = new JTextField();
310
                c.gridx++;
180 ilm 311
 
18 ilm 312
                c.weightx = 0;
313
                panelBase.add(labelSalaireBase, c);
314
                c.gridx++;
315
                c.weightx = 1;
316
                panelBase.add(salaireBase, c);
317
 
91 ilm 318
                if (getTable().contains("PRIME_TRANSPORT")) {
319
 
320
                    // PRIME_TRANSPORT
321
                    JLabel labelTransport = new JLabel(getLabelFor("PRIME_TRANSPORT"));
322
                    labelTransport.setHorizontalAlignment(SwingConstants.RIGHT);
323
 
324
                    c.gridy++;
325
                    c.gridx = 0;
326
                    c.gridheight = 1;
327
                    c.fill = GridBagConstraints.HORIZONTAL;
328
                    panelBase.add(labelTransport, c);
329
                    c.gridx++;
330
                    c.weightx = 1;
331
                    JTextField fieldTransp = new JTextField();
332
                    panelBase.add(fieldTransp, c);
333
                    addView(fieldTransp, "PRIME_TRANSPORT");
334
 
335
                    // Durée hebdomadaire
336
                    JLabel labelPanier = new JLabel(getLabelFor("PRIME_PANIER"));
337
                    labelPanier.setHorizontalAlignment(SwingConstants.RIGHT);
338
                    JTextField fieldPanier = new JTextField();
339
                    c.gridx++;
340
                    c.weightx = 0;
341
                    panelBase.add(labelPanier, c);
342
                    c.gridx++;
343
                    c.weightx = 1;
344
                    panelBase.add(fieldPanier, c);
345
                    addView(fieldPanier, "PRIME_PANIER");
346
 
347
                    // Salaire de base
348
                    JLabel labelLogement = new JLabel(getLabelFor("PRIME_LOGEMENT"));
349
                    labelLogement.setHorizontalAlignment(SwingConstants.RIGHT);
350
                    JTextField fieldLogement = new JTextField();
351
                    c.gridx++;
352
                    c.weightx = 0;
353
                    panelBase.add(labelLogement, c);
354
                    c.gridx++;
355
                    c.weightx = 1;
356
                    panelBase.add(fieldLogement, c);
357
                    addView(fieldLogement, "PRIME_LOGEMENT");
358
 
359
                    // PRIME_TRANSPORT
360
                    JLabel labelCnam = new JLabel(getLabelFor("NUMERO_CNAM"));
361
                    labelCnam.setHorizontalAlignment(SwingConstants.RIGHT);
362
                    c.gridy++;
363
                    c.gridx = 0;
364
                    c.gridheight = 1;
365
                    c.fill = GridBagConstraints.HORIZONTAL;
366
                    panelBase.add(labelCnam, c);
367
                    c.gridx++;
368
                    c.weightx = 1;
369
                    JTextField fieldCnam = new JTextField();
370
                    panelBase.add(fieldCnam, c);
371
                    addView(fieldCnam, "NUMERO_CNAM");
372
 
373
                    // Durée hebdomadaire
374
                    JLabel labelCNSS = new JLabel(getLabelFor("NUMERO_CNSS"));
375
                    labelCNSS.setHorizontalAlignment(SwingConstants.RIGHT);
376
                    JTextField fieldCnss = new JTextField();
377
                    c.gridx++;
378
                    c.weightx = 0;
379
                    panelBase.add(labelCNSS, c);
380
                    c.gridx++;
381
                    c.weightx = 1;
382
                    panelBase.add(fieldCnss, c);
383
                    addView(fieldCnss, "NUMERO_CNSS");
384
 
385
                }
18 ilm 386
                // Taux AT
387
                JLabel labelTauxAT = new JLabel(getLabelFor("TAUX_AT"));
388
                labelTauxAT.setHorizontalAlignment(SwingConstants.RIGHT);
389
                JTextField tauxAT = new JTextField();
390
                c.gridy++;
391
                c.gridx = 0;
392
                c.weightx = 0;
393
                panelBase.add(labelTauxAT, c);
394
                c.gridx++;
395
                c.weightx = 1;
396
                panelBase.add(tauxAT, c);
397
 
398
                // Congés payés
399
                JLabel labelConges = new JLabel(getLabelFor("CONGES_PAYES"));
400
                labelConges.setHorizontalAlignment(SwingConstants.RIGHT);
401
                JTextField conges = new JTextField();
402
                c.gridx++;
403
                c.weightx = 0;
404
                panelBase.add(labelConges, c);
405
                c.gridx++;
406
                c.weightx = 1;
407
                panelBase.add(conges, c);
408
 
132 ilm 409
                if (getTable().contains("BASE_FILLON_ANNUELLE")) {
410
                    JLabel labelFillon = new JLabel(getLabelFor("BASE_FILLON_ANNUELLE"));
411
                    labelFillon.setHorizontalAlignment(SwingConstants.RIGHT);
412
                    JTextField fillon = new JTextField();
413
                    c.gridx++;
414
                    c.weightx = 0;
415
                    panelBase.add(labelFillon, c);
416
                    c.gridx++;
417
                    c.weightx = 1;
418
                    panelBase.add(fillon, c);
419
                    addView(fillon, "BASE_FILLON_ANNUELLE");
420
                }
421
 
41 ilm 422
                // Code AT
423
                JLabel labelCodeAT = new JLabel(getLabelFor("CODE_AT"));
424
                labelCodeAT.setHorizontalAlignment(SwingConstants.RIGHT);
425
                JTextField CodeAT = new JTextField();
426
                c.gridy++;
427
                c.gridx = 0;
428
                c.weightx = 0;
429
                panelBase.add(labelCodeAT, c);
430
                c.gridx++;
431
                c.weightx = 1;
432
                panelBase.add(CodeAT, c);
151 ilm 433
                addView(CodeAT, "CODE_AT", REQ);
41 ilm 434
 
435
                // Code section AT
436
                JLabel labelSectionAT = new JLabel(getLabelFor("CODE_SECTION_AT"));
437
                labelSectionAT.setHorizontalAlignment(SwingConstants.RIGHT);
438
                JTextField sectionAT = new JTextField();
439
                c.gridx++;
440
                c.weightx = 0;
441
                panelBase.add(labelSectionAT, c);
442
                c.gridx++;
443
                c.weightx = 1;
444
                panelBase.add(sectionAT, c);
445
                addView(sectionAT, "CODE_SECTION_AT");
446
 
174 ilm 447
                if (getTable().contains("DUREE_FORFAIT")) {
448
                    JLabel labelForfait = new JLabel(getLabelFor("DUREE_FORFAIT"));
449
                    labelForfait.setHorizontalAlignment(SwingConstants.RIGHT);
450
                    JTextField forfait = new JTextField();
451
                    c.gridx++;
452
                    c.weightx = 0;
453
                    panelBase.add(labelForfait, c);
454
                    c.gridx++;
455
                    c.weightx = 1;
456
                    panelBase.add(forfait, c);
457
                    addView(forfait, "DUREE_FORFAIT");
458
                }
459
 
142 ilm 460
                c.gridy = 5;
18 ilm 461
                c.gridx = 0;
462
                c.gridwidth = GridBagConstraints.REMAINDER;
463
                c.weighty = 1;
464
                c.weightx = 1;
465
                c.anchor = GridBagConstraints.NORTHWEST;
466
                this.add(panelBase, c);
467
 
468
                this.addRequiredSQLObject(comboConvention, "ID_IDCC");
469
                this.addRequiredSQLObject(dateArrive, "DATE_ARRIVE");
470
                this.addSQLObject(dateSortie, "DATE_SORTIE");
471
                this.addRequiredSQLObject(this.dureeHebdo, "DUREE_HEBDO");
472
                this.addRequiredSQLObject(this.dureeMois, "DUREE_MOIS");
473
                this.addRequiredSQLObject(tauxAT, "TAUX_AT");
474
                this.addRequiredSQLObject(conges, "CONGES_PAYES");
475
                this.addRequiredSQLObject(salaireBase, "SALAIRE_MOIS");
476
                // this.addRequiredSQLObject(textAnc, "ANCIENNETE");
477
 
478
                // Listener
479
                this.dureeMois.getDocument().addDocumentListener(this.listenerMois);
480
                this.dureeHebdo.getDocument().addDocumentListener(this.listenerHebdo);
481
            }
482
 
483
            private void updateHebdo() {
484
 
485
                if (this.dureeMois.getText().trim().length() == 0) {
486
                    return;
487
                } else {
488
 
489
                    this.dureeHebdo.getDocument().removeDocumentListener(this.listenerHebdo);
490
 
491
                    this.dureeHebdo.setText(String.valueOf(new PrixHT(Float.parseFloat(this.dureeMois.getText()) / (52.0 / 12.0)).getValue()));
492
 
493
                    this.dureeHebdo.getDocument().addDocumentListener(this.listenerHebdo);
494
                }
495
            }
496
 
497
            private void updateMois() {
498
 
499
                if (this.dureeHebdo.getText().trim().length() == 0) {
500
                    return;
501
                } else {
502
 
503
                    this.dureeMois.getDocument().removeDocumentListener(this.listenerMois);
504
 
505
                    this.dureeMois.setText(String.valueOf(new PrixHT(Float.parseFloat(this.dureeHebdo.getText()) * (52.0 / 12.0)).getValue()));
506
 
507
                    this.dureeMois.getDocument().addDocumentListener(this.listenerMois);
508
                }
509
            }
510
 
511
            @Override
512
            public void select(SQLRowAccessor r) {
513
                this.dureeMois.getDocument().removeDocumentListener(this.listenerMois);
514
                this.dureeHebdo.getDocument().removeDocumentListener(this.listenerHebdo);
515
 
516
                super.select(r);
517
 
142 ilm 518
                if (r != null) {
519
                    tablePeni.insertFrom("ID_INFOS_SALARIE_PAYE", r.getID());
520
                }
521
 
18 ilm 522
                this.dureeMois.getDocument().addDocumentListener(this.listenerMois);
523
                this.dureeHebdo.getDocument().addDocumentListener(this.listenerHebdo);
524
            }
525
        };
526
    }
57 ilm 527
 
528
    @Override
529
    protected String createCode() {
156 ilm 530
        return createCodeOfPackage() + ".info";
57 ilm 531
    }
18 ilm 532
}