OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
185 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
18 ilm 5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.humanresources.payroll.element;
15
 
156 ilm 16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18 ilm 17
import org.openconcerto.erp.core.common.ui.SQLJavaEditor;
18
import org.openconcerto.erp.core.humanresources.payroll.component.FormuleTreeNode;
57 ilm 19
import org.openconcerto.erp.core.humanresources.payroll.component.RubriqueSQLComponent;
18 ilm 20
import org.openconcerto.erp.core.humanresources.payroll.component.VariableTree;
21
import org.openconcerto.sql.element.ElementSQLObject;
22
import org.openconcerto.sql.element.SQLComponent;
23
import org.openconcerto.sql.element.SQLElement;
156 ilm 24
import org.openconcerto.sql.model.DBRoot;
25
import org.openconcerto.sql.model.SQLRowValues;
18 ilm 26
import org.openconcerto.sql.sqlobject.ElementComboBox;
156 ilm 27
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
18 ilm 28
import org.openconcerto.ui.DefaultGridBagConstraints;
132 ilm 29
import org.openconcerto.utils.ListMap;
177 ilm 30
import org.openconcerto.utils.NoneSelectedButtonGroup;
18 ilm 31
 
32
import java.awt.GridBagConstraints;
33
import java.awt.GridBagLayout;
34
import java.awt.Insets;
35
import java.awt.event.MouseAdapter;
36
import java.awt.event.MouseEvent;
37
import java.beans.PropertyChangeEvent;
38
import java.beans.PropertyChangeListener;
39
import java.util.ArrayList;
40
import java.util.List;
41
import java.util.Map;
42
 
43
import javax.swing.BorderFactory;
44
import javax.swing.ButtonGroup;
45
import javax.swing.JCheckBox;
46
import javax.swing.JLabel;
47
import javax.swing.JPanel;
48
import javax.swing.JRadioButton;
49
import javax.swing.JScrollPane;
50
import javax.swing.JSeparator;
51
import javax.swing.JSplitPane;
52
import javax.swing.JTabbedPane;
53
import javax.swing.SwingConstants;
54
import javax.swing.tree.TreePath;
55
 
156 ilm 56
public class RubriqueBrutSQLElement extends ComptaSQLConfElement {
18 ilm 57
 
156 ilm 58
    public RubriqueBrutSQLElement(final DBRoot root) {
59
        super(root.getTable("RUBRIQUE_BRUT"), "une rubrique de brut", "rubriques de brut");
18 ilm 60
    }
61
 
62
    protected List<String> getListFields() {
63
        final List<String> l = new ArrayList<String>();
64
        l.add("CODE");
65
        l.add("NOM");
66
 
67
        l.add("BASE");
68
        l.add("TAUX");
69
        l.add("MONTANT");
156 ilm 70
        l.add("COTISABLE");
18 ilm 71
        l.add("PART_CP");
156 ilm 72
        l.add("TAXABLE_CM");
177 ilm 73
        l.add("CSG_NORMAL");
74
        l.add("CSG_REDUIT");
18 ilm 75
        return l;
76
    }
77
 
78
    protected List<String> getComboFields() {
79
        final List<String> l = new ArrayList<String>();
80
        l.add("CODE");
81
        l.add("NOM");
82
        return l;
83
    }
84
 
132 ilm 85
    @Override
86
    public ListMap<String, String> getShowAs() {
87
        return ListMap.singleton(null, "NOM");
18 ilm 88
    }
89
 
90
    /*
91
     * (non-Javadoc)
92
     *
93
     * @see org.openconcerto.devis.SQLElement#getComponent()
94
     */
95
    public SQLComponent createComponent() {
21 ilm 96
        return new RubriqueSQLComponent(this) {
18 ilm 97
 
98
            private SQLJavaEditor formuleBase, formuleTaux, formuleMontant;
99
 
21 ilm 100
            @Override
101
            protected void addViews(GridBagConstraints c) {
18 ilm 102
                c.weightx = 0;
103
                c.gridwidth = 1;
104
 
105
                /***********************************************************************************
106
                 * PANEL CALCUL
107
                 **********************************************************************************/
108
                JPanel panelCalcul = new JPanel();
109
                panelCalcul.setLayout(new GridBagLayout());
110
                final GridBagConstraints cPanel = new DefaultGridBagConstraints();
111
 
112
                final VariableTree tree = new VariableTree();
113
                JScrollPane paneTree = new JScrollPane(tree);
114
 
115
                cPanel.gridheight = GridBagConstraints.REMAINDER;
116
                cPanel.weighty = 1;
117
                cPanel.weightx = 1;
118
                cPanel.fill = GridBagConstraints.BOTH;
119
                // panelCalcul.add(paneTree, cPanel);
120
 
121
                cPanel.fill = GridBagConstraints.HORIZONTAL;
122
                cPanel.weighty = 0;
123
                cPanel.weightx = 0;
124
                cPanel.gridheight = 1;
125
 
126
                // Formule base
127
                cPanel.gridx++;
128
                final Map<String, List<?>> mapTree = VariablePayeSQLElement.getMapTree();
129
                this.formuleBase = new SQLJavaEditor(mapTree);
130
                this.formuleBase.setVarAssign("BASE");
131
 
132
                final JRadioButton radioBase = new JRadioButton(getLabelFor("BASE"));
133
                panelCalcul.add(radioBase, cPanel);
134
                cPanel.gridx++;
135
                panelCalcul.add(this.formuleBase, cPanel);
136
 
137
                JSeparator sep1 = new JSeparator();
138
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
139
                cPanel.gridy++;
140
                cPanel.gridx = 1;
141
                cPanel.weightx = 1;
142
                panelCalcul.add(sep1, cPanel);
143
                cPanel.gridwidth = 1;
144
                cPanel.weightx = 0;
145
 
146
                // Formule Taux
147
                cPanel.gridy++;
148
                cPanel.gridx = 1;
149
 
150
                this.formuleTaux = new SQLJavaEditor(mapTree);
151
                this.formuleTaux.setVarAssign("TAUX");
152
                final JRadioButton radioTaux = new JRadioButton(getLabelFor("TAUX"));
153
                panelCalcul.add(radioTaux, cPanel);
154
                cPanel.gridx++;
155
                panelCalcul.add(this.formuleTaux, cPanel);
156
 
157
                JSeparator sep2 = new JSeparator();
158
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
159
                cPanel.gridy++;
160
                cPanel.gridx = 1;
161
                cPanel.weightx = 1;
162
                panelCalcul.add(sep2, cPanel);
163
                cPanel.gridwidth = 1;
164
                cPanel.weightx = 0;
165
 
166
                // Formule Montant
167
                cPanel.gridy++;
168
                cPanel.gridx = 1;
169
                this.formuleMontant = new SQLJavaEditor(mapTree);
170
                this.formuleMontant.setVarAssign("MONTANT");
171
                final JRadioButton radioMontant = new JRadioButton(getLabelFor("MONTANT"));
172
                panelCalcul.add(radioMontant, cPanel);
173
                cPanel.gridx++;
174
                panelCalcul.add(this.formuleMontant, cPanel);
175
 
176
                JSeparator sep3 = new JSeparator();
177
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
178
                cPanel.gridy++;
179
                cPanel.gridx = 1;
180
                cPanel.weightx = 1;
181
                panelCalcul.add(sep3, cPanel);
182
                cPanel.gridwidth = 1;
183
                cPanel.weightx = 0;
184
 
185
                // Salarie
186
                cPanel.gridy++;
187
                cPanel.gridx = 1;
188
                JLabel labelSelSal = new JLabel("Salarié");
189
                labelSelSal.setHorizontalAlignment(SwingConstants.RIGHT);
190
                panelCalcul.add(labelSelSal, cPanel);
191
 
80 ilm 192
                SQLElement eltSal = getDirectory().getElement(SalarieSQLElement.class);
18 ilm 193
                final ElementComboBox selSalarie = new ElementComboBox(false);
194
 
195
                cPanel.gridx++;
196
                selSalarie.init(eltSal);
197
                panelCalcul.add(selSalarie, cPanel);
198
 
199
                ButtonGroup groupRadio = new ButtonGroup();
200
                groupRadio.add(radioBase);
201
                groupRadio.add(radioMontant);
202
                groupRadio.add(radioTaux);
203
                radioBase.setSelected(true);
204
 
205
                tree.addMouseListener(new MouseAdapter() {
206
 
207
                    public void mousePressed(MouseEvent e) {
208
 
209
                        if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
210
                            TreePath path = tree.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
211
 
212
                            final Object obj = path.getLastPathComponent();
213
 
214
                            if (obj == null) {
215
                                return;
216
                            } else {
217
                                if (obj instanceof FormuleTreeNode) {
218
                                    FormuleTreeNode n = (FormuleTreeNode) obj;
219
 
220
                                    if (radioBase.isSelected()) {
221
                                        int start = formuleBase.getSelectionStart();
222
                                        String tmp = formuleBase.getText();
223
 
224
                                        formuleBase.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
225
                                    } else {
226
 
227
                                        if (radioMontant.isSelected()) {
228
                                            int start = formuleMontant.getSelectionStart();
229
                                            String tmp = formuleMontant.getText();
230
 
231
                                            formuleMontant.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
232
                                        } else {
233
                                            int start = formuleTaux.getSelectionStart();
234
                                            String tmp = formuleTaux.getText();
235
 
236
                                            formuleTaux.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
237
                                        }
238
                                    }
239
                                }
240
 
241
                            }
242
                        }
243
                    }
244
                });
245
 
246
                /***********************************************************************************
247
                 * PANEL PROPRIETE
248
                 **********************************************************************************/
249
                JPanel panelProp = new JPanel();
250
                panelProp.setLayout(new GridBagLayout());
251
                cPanel.gridx = 0;
252
                cPanel.gridy = 0;
253
                cPanel.weightx = 0;
254
                cPanel.weighty = 0;
255
                cPanel.gridwidth = 1;
256
                cPanel.gridheight = 1;
257
                cPanel.fill = GridBagConstraints.HORIZONTAL;
258
                cPanel.anchor = GridBagConstraints.NORTHWEST;
259
                cPanel.insets = new Insets(2, 2, 1, 2);
260
 
261
                // Periode d'application
262
                this.addView("ID_PERIODE_VALIDITE", REQ + ";" + DEC + ";" + SEP);
263
                ElementSQLObject eltInfosPaye = (ElementSQLObject) this.getView("ID_PERIODE_VALIDITE");
264
                cPanel.gridy = 0;
265
                cPanel.gridx = 0;
266
                cPanel.gridheight = GridBagConstraints.REMAINDER;
267
                cPanel.weighty = 1;
268
                cPanel.fill = GridBagConstraints.NONE;
269
                JPanel panelPeriodeVal = new JPanel();
270
                panelPeriodeVal.setBorder(BorderFactory.createTitledBorder("Période de validité"));
271
                panelPeriodeVal.add(eltInfosPaye);
272
                panelProp.add(panelPeriodeVal, cPanel);
273
 
274
                cPanel.weightx = 0;
275
                cPanel.weighty = 0;
276
                cPanel.gridheight = 1;
277
                cPanel.fill = GridBagConstraints.HORIZONTAL;
278
 
279
                // Type
280
                JLabel labelSelTypeRubrique = new JLabel("Type");
281
                labelSelTypeRubrique.setHorizontalAlignment(SwingConstants.RIGHT);
282
                cPanel.gridx++;
283
                cPanel.gridheight = 1;
284
 
285
                cPanel.weightx = 0;
286
                cPanel.anchor = GridBagConstraints.WEST;
287
                panelProp.add(labelSelTypeRubrique, cPanel);
288
 
289
                // SQLElement eltType =
290
                // Configuration.getInstance().getDirectory().getElement("TYPE_RUBRIQUE_BRUT");
156 ilm 291
                SQLRequestComboBox comboSelTypeRubrique = new SQLRequestComboBox(false);
18 ilm 292
                cPanel.gridx++;
293
                cPanel.weightx = 1;
294
                panelProp.add(comboSelTypeRubrique, cPanel);
295
 
296
                // Impression
297
                JLabel labelSelTypeRubriqueImpression = new JLabel("Impression");
298
                cPanel.gridy++;
299
                cPanel.gridx = 1;
300
                cPanel.weightx = 0;
301
                panelProp.add(labelSelTypeRubriqueImpression, cPanel);
302
 
156 ilm 303
                SQLRequestComboBox comboSelTypeImpression = new SQLRequestComboBox(false);
18 ilm 304
                cPanel.gridx++;
305
                cPanel.weightx = 1;
306
                panelProp.add(comboSelTypeImpression, cPanel);
307
 
308
                // Imposable
309
                cPanel.gridx = 1;
310
                cPanel.weightx = 1;
311
                cPanel.gridy++;
312
                c.fill = GridBagConstraints.HORIZONTAL;
313
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
156 ilm 314
                JCheckBox checkImpo = new JCheckBox(getLabelFor("TAXABLE_CM"));
18 ilm 315
                panelProp.add(checkImpo, cPanel);
316
 
156 ilm 317
                // Participation à la base cotisable
318
                cPanel.gridx = 1;
319
                cPanel.weightx = 1;
320
                cPanel.gridy++;
321
                c.fill = GridBagConstraints.HORIZONTAL;
322
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
323
                JCheckBox checkCotis = new JCheckBox(getLabelFor("COTISABLE"));
324
                panelProp.add(checkCotis, cPanel);
325
 
18 ilm 326
                // Participation à la base brute
327
                cPanel.gridx = 1;
328
                cPanel.weightx = 1;
329
                cPanel.gridy++;
330
                c.fill = GridBagConstraints.HORIZONTAL;
331
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
332
                JCheckBox checkBrut = new JCheckBox(getLabelFor("PART_BRUT"));
333
                panelProp.add(checkBrut, cPanel);
334
 
335
                // Participation aux congés payés
336
                cPanel.gridx = 1;
337
                cPanel.weightx = 1;
338
                cPanel.gridy++;
339
                c.fill = GridBagConstraints.HORIZONTAL;
340
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
341
                JCheckBox checkCP = new JCheckBox(getLabelFor("PART_CP"));
342
                panelProp.add(checkCP, cPanel);
343
 
177 ilm 344
                // CSG Normal
345
                cPanel.gridx = 1;
346
                cPanel.weightx = 1;
347
                cPanel.gridy++;
348
                c.fill = GridBagConstraints.HORIZONTAL;
349
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
350
                JCheckBox checkCSGN = new JCheckBox(getLabelFor("CSG_NORMAL"));
351
                panelProp.add(checkCSGN, cPanel);
352
 
353
                // CSG Réduite
354
                cPanel.gridx = 1;
355
                cPanel.weightx = 1;
356
                cPanel.gridy++;
357
                c.fill = GridBagConstraints.HORIZONTAL;
358
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
359
                JCheckBox checkCSGR = new JCheckBox(getLabelFor("CSG_REDUIT"));
360
                panelProp.add(checkCSGR, cPanel);
361
 
185 ilm 362
                cPanel.gridx = 1;
363
                cPanel.weightx = 1;
364
                cPanel.gridy++;
365
                c.fill = GridBagConstraints.HORIZONTAL;
366
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
367
                JCheckBox checkCSGSansAbattement = new JCheckBox(getLabelFor("PART_CSG_SANS_ABATTEMENT"));
368
                panelProp.add(checkCSGSansAbattement, cPanel);
369
 
177 ilm 370
                NoneSelectedButtonGroup groupCSG = new NoneSelectedButtonGroup();
371
                groupCSG.add(checkCSGN);
372
                groupCSG.add(checkCSGR);
185 ilm 373
                groupCSG.add(checkCSGSansAbattement);
177 ilm 374
 
132 ilm 375
                // Type
142 ilm 376
                JLabel labelSelCodeRubrique = new JLabel("Code DSN (S21.G00.51.011)");
132 ilm 377
                labelSelCodeRubrique.setHorizontalAlignment(SwingConstants.RIGHT);
378
                cPanel.gridy++;
379
                cPanel.gridx = 1;
380
                cPanel.gridheight = 1;
381
                cPanel.gridwidth = 1;
382
                cPanel.weightx = 0;
383
                cPanel.anchor = GridBagConstraints.WEST;
384
                panelProp.add(labelSelCodeRubrique, cPanel);
385
 
386
                ElementComboBox comboSelCodeRubrique = new ElementComboBox(false);
387
                cPanel.gridx++;
388
                cPanel.weightx = 1;
389
                panelProp.add(comboSelCodeRubrique, cPanel);
390
                this.addView(comboSelCodeRubrique, "ID_CODE_TYPE_RUBRIQUE_BRUT");
391
 
18 ilm 392
                // Tabbed Pane
393
                JTabbedPane tab = new JTabbedPane();
394
                tab.add("Calcul", new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, paneTree, panelCalcul));
395
                tab.add("Propriétés", panelProp);
396
 
397
                c.gridwidth = GridBagConstraints.REMAINDER;
398
                c.gridx = 0;
399
                c.fill = GridBagConstraints.BOTH;
400
                c.weightx = 1;
401
                c.weighty = 1;
402
                this.add(tab, c);
403
 
404
                this.addSQLObject(this.formuleBase, "BASE");
405
                this.addSQLObject(this.formuleTaux, "TAUX");
406
                this.addSQLObject(this.formuleMontant, "MONTANT");
407
                this.addRequiredSQLObject(comboSelTypeRubrique, "ID_TYPE_RUBRIQUE_BRUT");
408
                this.addRequiredSQLObject(comboSelTypeImpression, "ID_IMPRESSION_RUBRIQUE");
409
                this.addSQLObject(checkBrut, "PART_BRUT");
156 ilm 410
                this.addSQLObject(checkCotis, "COTISABLE");
18 ilm 411
                this.addSQLObject(checkCP, "PART_CP");
156 ilm 412
                this.addSQLObject(checkImpo, "TAXABLE_CM");
177 ilm 413
                this.addSQLObject(checkCSGN, "CSG_NORMAL");
414
                this.addSQLObject(checkCSGR, "CSG_REDUIT");
185 ilm 415
                this.addSQLObject(checkCSGSansAbattement, "PART_CSG_SANS_ABATTEMENT");
18 ilm 416
 
417
                selSalarie.addValueListener(new PropertyChangeListener() {
418
 
419
                    public void propertyChange(PropertyChangeEvent evt) {
420
                        formuleBase.setSalarieID(selSalarie.getSelectedId());
421
                        formuleTaux.setSalarieID(selSalarie.getSelectedId());
422
                        formuleMontant.setSalarieID(selSalarie.getSelectedId());
423
                    }
424
                });
425
            }
156 ilm 426
 
427
            @Override
428
            protected SQLRowValues createDefaults() {
429
                SQLRowValues rowVals = new SQLRowValues(getTable());
430
                rowVals.put("TAXABLE_CM", Boolean.TRUE);
431
                rowVals.put("COTISABLE", Boolean.TRUE);
432
                rowVals.put("PART_BRUT", Boolean.TRUE);
177 ilm 433
                rowVals.put("CSG_NORMAL", Boolean.TRUE);
156 ilm 434
                return rowVals;
435
            }
18 ilm 436
        };
437
    }
57 ilm 438
 
439
    @Override
440
    protected String createCode() {
441
        return "humanresources.payroll.category.raw";
442
    }
18 ilm 443
}