OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Rev 177 | Go to most recent revision | 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
 
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;
18 ilm 30
 
31
import java.awt.GridBagConstraints;
32
import java.awt.GridBagLayout;
33
import java.awt.Insets;
34
import java.awt.event.MouseAdapter;
35
import java.awt.event.MouseEvent;
36
import java.beans.PropertyChangeEvent;
37
import java.beans.PropertyChangeListener;
38
import java.util.ArrayList;
39
import java.util.List;
40
import java.util.Map;
41
 
42
import javax.swing.BorderFactory;
43
import javax.swing.ButtonGroup;
44
import javax.swing.JCheckBox;
45
import javax.swing.JLabel;
46
import javax.swing.JPanel;
47
import javax.swing.JRadioButton;
48
import javax.swing.JScrollPane;
49
import javax.swing.JSeparator;
50
import javax.swing.JSplitPane;
51
import javax.swing.JTabbedPane;
52
import javax.swing.SwingConstants;
53
import javax.swing.tree.TreePath;
54
 
156 ilm 55
public class RubriqueBrutSQLElement extends ComptaSQLConfElement {
18 ilm 56
 
156 ilm 57
    public RubriqueBrutSQLElement(final DBRoot root) {
58
        super(root.getTable("RUBRIQUE_BRUT"), "une rubrique de brut", "rubriques de brut");
18 ilm 59
    }
60
 
61
    protected List<String> getListFields() {
62
        final List<String> l = new ArrayList<String>();
63
        l.add("CODE");
64
        l.add("NOM");
65
 
66
        l.add("BASE");
67
        l.add("TAUX");
68
        l.add("MONTANT");
156 ilm 69
        l.add("COTISABLE");
18 ilm 70
        l.add("PART_CP");
156 ilm 71
        l.add("TAXABLE_CM");
18 ilm 72
 
73
        return l;
74
    }
75
 
76
    protected List<String> getComboFields() {
77
        final List<String> l = new ArrayList<String>();
78
        l.add("CODE");
79
        l.add("NOM");
80
        return l;
81
    }
82
 
132 ilm 83
    @Override
84
    public ListMap<String, String> getShowAs() {
85
        return ListMap.singleton(null, "NOM");
18 ilm 86
    }
87
 
88
    /*
89
     * (non-Javadoc)
90
     *
91
     * @see org.openconcerto.devis.SQLElement#getComponent()
92
     */
93
    public SQLComponent createComponent() {
21 ilm 94
        return new RubriqueSQLComponent(this) {
18 ilm 95
 
96
            private SQLJavaEditor formuleBase, formuleTaux, formuleMontant;
97
 
21 ilm 98
            @Override
99
            protected void addViews(GridBagConstraints c) {
18 ilm 100
                c.weightx = 0;
101
                c.gridwidth = 1;
102
 
103
                /***********************************************************************************
104
                 * PANEL CALCUL
105
                 **********************************************************************************/
106
                JPanel panelCalcul = new JPanel();
107
                panelCalcul.setLayout(new GridBagLayout());
108
                final GridBagConstraints cPanel = new DefaultGridBagConstraints();
109
 
110
                final VariableTree tree = new VariableTree();
111
                JScrollPane paneTree = new JScrollPane(tree);
112
 
113
                cPanel.gridheight = GridBagConstraints.REMAINDER;
114
                cPanel.weighty = 1;
115
                cPanel.weightx = 1;
116
                cPanel.fill = GridBagConstraints.BOTH;
117
                // panelCalcul.add(paneTree, cPanel);
118
 
119
                cPanel.fill = GridBagConstraints.HORIZONTAL;
120
                cPanel.weighty = 0;
121
                cPanel.weightx = 0;
122
                cPanel.gridheight = 1;
123
 
124
                // Formule base
125
                cPanel.gridx++;
126
                final Map<String, List<?>> mapTree = VariablePayeSQLElement.getMapTree();
127
                this.formuleBase = new SQLJavaEditor(mapTree);
128
                this.formuleBase.setVarAssign("BASE");
129
 
130
                final JRadioButton radioBase = new JRadioButton(getLabelFor("BASE"));
131
                panelCalcul.add(radioBase, cPanel);
132
                cPanel.gridx++;
133
                panelCalcul.add(this.formuleBase, cPanel);
134
 
135
                JSeparator sep1 = new JSeparator();
136
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
137
                cPanel.gridy++;
138
                cPanel.gridx = 1;
139
                cPanel.weightx = 1;
140
                panelCalcul.add(sep1, cPanel);
141
                cPanel.gridwidth = 1;
142
                cPanel.weightx = 0;
143
 
144
                // Formule Taux
145
                cPanel.gridy++;
146
                cPanel.gridx = 1;
147
 
148
                this.formuleTaux = new SQLJavaEditor(mapTree);
149
                this.formuleTaux.setVarAssign("TAUX");
150
                final JRadioButton radioTaux = new JRadioButton(getLabelFor("TAUX"));
151
                panelCalcul.add(radioTaux, cPanel);
152
                cPanel.gridx++;
153
                panelCalcul.add(this.formuleTaux, cPanel);
154
 
155
                JSeparator sep2 = new JSeparator();
156
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
157
                cPanel.gridy++;
158
                cPanel.gridx = 1;
159
                cPanel.weightx = 1;
160
                panelCalcul.add(sep2, cPanel);
161
                cPanel.gridwidth = 1;
162
                cPanel.weightx = 0;
163
 
164
                // Formule Montant
165
                cPanel.gridy++;
166
                cPanel.gridx = 1;
167
                this.formuleMontant = new SQLJavaEditor(mapTree);
168
                this.formuleMontant.setVarAssign("MONTANT");
169
                final JRadioButton radioMontant = new JRadioButton(getLabelFor("MONTANT"));
170
                panelCalcul.add(radioMontant, cPanel);
171
                cPanel.gridx++;
172
                panelCalcul.add(this.formuleMontant, cPanel);
173
 
174
                JSeparator sep3 = new JSeparator();
175
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
176
                cPanel.gridy++;
177
                cPanel.gridx = 1;
178
                cPanel.weightx = 1;
179
                panelCalcul.add(sep3, cPanel);
180
                cPanel.gridwidth = 1;
181
                cPanel.weightx = 0;
182
 
183
                // Salarie
184
                cPanel.gridy++;
185
                cPanel.gridx = 1;
186
                JLabel labelSelSal = new JLabel("Salarié");
187
                labelSelSal.setHorizontalAlignment(SwingConstants.RIGHT);
188
                panelCalcul.add(labelSelSal, cPanel);
189
 
80 ilm 190
                SQLElement eltSal = getDirectory().getElement(SalarieSQLElement.class);
18 ilm 191
                final ElementComboBox selSalarie = new ElementComboBox(false);
192
 
193
                cPanel.gridx++;
194
                selSalarie.init(eltSal);
195
                panelCalcul.add(selSalarie, cPanel);
196
 
197
                ButtonGroup groupRadio = new ButtonGroup();
198
                groupRadio.add(radioBase);
199
                groupRadio.add(radioMontant);
200
                groupRadio.add(radioTaux);
201
                radioBase.setSelected(true);
202
 
203
                tree.addMouseListener(new MouseAdapter() {
204
 
205
                    public void mousePressed(MouseEvent e) {
206
 
207
                        if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
208
                            TreePath path = tree.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
209
 
210
                            final Object obj = path.getLastPathComponent();
211
 
212
                            if (obj == null) {
213
                                return;
214
                            } else {
215
                                if (obj instanceof FormuleTreeNode) {
216
                                    FormuleTreeNode n = (FormuleTreeNode) obj;
217
 
218
                                    if (radioBase.isSelected()) {
219
                                        int start = formuleBase.getSelectionStart();
220
                                        String tmp = formuleBase.getText();
221
 
222
                                        formuleBase.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
223
                                    } else {
224
 
225
                                        if (radioMontant.isSelected()) {
226
                                            int start = formuleMontant.getSelectionStart();
227
                                            String tmp = formuleMontant.getText();
228
 
229
                                            formuleMontant.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
230
                                        } else {
231
                                            int start = formuleTaux.getSelectionStart();
232
                                            String tmp = formuleTaux.getText();
233
 
234
                                            formuleTaux.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
235
                                        }
236
                                    }
237
                                }
238
 
239
                            }
240
                        }
241
                    }
242
                });
243
 
244
                /***********************************************************************************
245
                 * PANEL PROPRIETE
246
                 **********************************************************************************/
247
                JPanel panelProp = new JPanel();
248
                panelProp.setLayout(new GridBagLayout());
249
                cPanel.gridx = 0;
250
                cPanel.gridy = 0;
251
                cPanel.weightx = 0;
252
                cPanel.weighty = 0;
253
                cPanel.gridwidth = 1;
254
                cPanel.gridheight = 1;
255
                cPanel.fill = GridBagConstraints.HORIZONTAL;
256
                cPanel.anchor = GridBagConstraints.NORTHWEST;
257
                cPanel.insets = new Insets(2, 2, 1, 2);
258
 
259
                // Periode d'application
260
                this.addView("ID_PERIODE_VALIDITE", REQ + ";" + DEC + ";" + SEP);
261
                ElementSQLObject eltInfosPaye = (ElementSQLObject) this.getView("ID_PERIODE_VALIDITE");
262
                cPanel.gridy = 0;
263
                cPanel.gridx = 0;
264
                cPanel.gridheight = GridBagConstraints.REMAINDER;
265
                cPanel.weighty = 1;
266
                cPanel.fill = GridBagConstraints.NONE;
267
                JPanel panelPeriodeVal = new JPanel();
268
                panelPeriodeVal.setBorder(BorderFactory.createTitledBorder("Période de validité"));
269
                panelPeriodeVal.add(eltInfosPaye);
270
                panelProp.add(panelPeriodeVal, cPanel);
271
 
272
                cPanel.weightx = 0;
273
                cPanel.weighty = 0;
274
                cPanel.gridheight = 1;
275
                cPanel.fill = GridBagConstraints.HORIZONTAL;
276
 
277
                // Type
278
                JLabel labelSelTypeRubrique = new JLabel("Type");
279
                labelSelTypeRubrique.setHorizontalAlignment(SwingConstants.RIGHT);
280
                cPanel.gridx++;
281
                cPanel.gridheight = 1;
282
 
283
                cPanel.weightx = 0;
284
                cPanel.anchor = GridBagConstraints.WEST;
285
                panelProp.add(labelSelTypeRubrique, cPanel);
286
 
287
                // SQLElement eltType =
288
                // Configuration.getInstance().getDirectory().getElement("TYPE_RUBRIQUE_BRUT");
156 ilm 289
                SQLRequestComboBox comboSelTypeRubrique = new SQLRequestComboBox(false);
18 ilm 290
                cPanel.gridx++;
291
                cPanel.weightx = 1;
292
                panelProp.add(comboSelTypeRubrique, cPanel);
293
 
294
                // Impression
295
                JLabel labelSelTypeRubriqueImpression = new JLabel("Impression");
296
                cPanel.gridy++;
297
                cPanel.gridx = 1;
298
                cPanel.weightx = 0;
299
                panelProp.add(labelSelTypeRubriqueImpression, cPanel);
300
 
156 ilm 301
                SQLRequestComboBox comboSelTypeImpression = new SQLRequestComboBox(false);
18 ilm 302
                cPanel.gridx++;
303
                cPanel.weightx = 1;
304
                panelProp.add(comboSelTypeImpression, cPanel);
305
 
306
                // Imposable
307
                cPanel.gridx = 1;
308
                cPanel.weightx = 1;
309
                cPanel.gridy++;
310
                c.fill = GridBagConstraints.HORIZONTAL;
311
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
156 ilm 312
                JCheckBox checkImpo = new JCheckBox(getLabelFor("TAXABLE_CM"));
18 ilm 313
                panelProp.add(checkImpo, cPanel);
314
 
156 ilm 315
                // Participation à la base cotisable
316
                cPanel.gridx = 1;
317
                cPanel.weightx = 1;
318
                cPanel.gridy++;
319
                c.fill = GridBagConstraints.HORIZONTAL;
320
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
321
                JCheckBox checkCotis = new JCheckBox(getLabelFor("COTISABLE"));
322
                panelProp.add(checkCotis, cPanel);
323
 
18 ilm 324
                // Participation à la base brute
325
                cPanel.gridx = 1;
326
                cPanel.weightx = 1;
327
                cPanel.gridy++;
328
                c.fill = GridBagConstraints.HORIZONTAL;
329
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
330
                JCheckBox checkBrut = new JCheckBox(getLabelFor("PART_BRUT"));
331
                panelProp.add(checkBrut, cPanel);
332
 
333
                // Participation aux congés payés
334
                cPanel.gridx = 1;
335
                cPanel.weightx = 1;
336
                cPanel.gridy++;
337
                c.fill = GridBagConstraints.HORIZONTAL;
338
                cPanel.gridwidth = GridBagConstraints.REMAINDER;
339
                JCheckBox checkCP = new JCheckBox(getLabelFor("PART_CP"));
340
                panelProp.add(checkCP, cPanel);
341
 
132 ilm 342
                // Type
142 ilm 343
                JLabel labelSelCodeRubrique = new JLabel("Code DSN (S21.G00.51.011)");
132 ilm 344
                labelSelCodeRubrique.setHorizontalAlignment(SwingConstants.RIGHT);
345
                cPanel.gridy++;
346
                cPanel.gridx = 1;
347
                cPanel.gridheight = 1;
348
                cPanel.gridwidth = 1;
349
                cPanel.weightx = 0;
350
                cPanel.anchor = GridBagConstraints.WEST;
351
                panelProp.add(labelSelCodeRubrique, cPanel);
352
 
353
                ElementComboBox comboSelCodeRubrique = new ElementComboBox(false);
354
                cPanel.gridx++;
355
                cPanel.weightx = 1;
356
                panelProp.add(comboSelCodeRubrique, cPanel);
357
                this.addView(comboSelCodeRubrique, "ID_CODE_TYPE_RUBRIQUE_BRUT");
358
 
18 ilm 359
                // Tabbed Pane
360
                JTabbedPane tab = new JTabbedPane();
361
                tab.add("Calcul", new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, paneTree, panelCalcul));
362
                tab.add("Propriétés", panelProp);
363
 
364
                c.gridwidth = GridBagConstraints.REMAINDER;
365
                c.gridx = 0;
366
                c.fill = GridBagConstraints.BOTH;
367
                c.weightx = 1;
368
                c.weighty = 1;
369
                this.add(tab, c);
370
 
371
                this.addSQLObject(this.formuleBase, "BASE");
372
                this.addSQLObject(this.formuleTaux, "TAUX");
373
                this.addSQLObject(this.formuleMontant, "MONTANT");
374
                this.addRequiredSQLObject(comboSelTypeRubrique, "ID_TYPE_RUBRIQUE_BRUT");
375
                this.addRequiredSQLObject(comboSelTypeImpression, "ID_IMPRESSION_RUBRIQUE");
376
                this.addSQLObject(checkBrut, "PART_BRUT");
156 ilm 377
                this.addSQLObject(checkCotis, "COTISABLE");
18 ilm 378
                this.addSQLObject(checkCP, "PART_CP");
156 ilm 379
                this.addSQLObject(checkImpo, "TAXABLE_CM");
18 ilm 380
 
381
                selSalarie.addValueListener(new PropertyChangeListener() {
382
 
383
                    public void propertyChange(PropertyChangeEvent evt) {
384
                        formuleBase.setSalarieID(selSalarie.getSelectedId());
385
                        formuleTaux.setSalarieID(selSalarie.getSelectedId());
386
                        formuleMontant.setSalarieID(selSalarie.getSelectedId());
387
                    }
388
                });
389
            }
156 ilm 390
 
391
            @Override
392
            protected SQLRowValues createDefaults() {
393
                SQLRowValues rowVals = new SQLRowValues(getTable());
394
                rowVals.put("TAXABLE_CM", Boolean.TRUE);
395
                rowVals.put("COTISABLE", Boolean.TRUE);
396
                rowVals.put("PART_BRUT", Boolean.TRUE);
397
 
398
                return rowVals;
399
            }
18 ilm 400
        };
401
    }
57 ilm 402
 
403
    @Override
404
    protected String createCode() {
405
        return "humanresources.payroll.category.raw";
406
    }
18 ilm 407
}