OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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