OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | 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;
144 ilm 21
import org.openconcerto.erp.core.humanresources.payroll.report.LignePayeSimplifieeComboBox;
22
import org.openconcerto.erp.core.humanresources.payroll.report.LignePayeSimplifieeRowItemView;
23
import org.openconcerto.erp.core.humanresources.payroll.report.LigneSimplifieeCellRenderer;
18 ilm 24
import org.openconcerto.sql.element.ElementSQLObject;
25
import org.openconcerto.sql.element.SQLComponent;
26
import org.openconcerto.sql.element.SQLElement;
156 ilm 27
import org.openconcerto.sql.model.DBRoot;
18 ilm 28
import org.openconcerto.sql.sqlobject.ElementComboBox;
156 ilm 29
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
144 ilm 30
import org.openconcerto.sql.view.list.SQLTableModelSource;
18 ilm 31
import org.openconcerto.ui.DefaultGridBagConstraints;
132 ilm 32
import org.openconcerto.utils.ListMap;
94 ilm 33
import org.openconcerto.utils.NoneSelectedButtonGroup;
18 ilm 34
 
35
import java.awt.GridBagConstraints;
36
import java.awt.GridBagLayout;
37
import java.awt.Insets;
38
import java.awt.event.MouseAdapter;
39
import java.awt.event.MouseEvent;
40
import java.beans.PropertyChangeEvent;
41
import java.beans.PropertyChangeListener;
42
import java.util.ArrayList;
43
import java.util.List;
44
import java.util.Map;
45
 
46
import javax.swing.BorderFactory;
47
import javax.swing.ButtonGroup;
48
import javax.swing.JCheckBox;
49
import javax.swing.JLabel;
50
import javax.swing.JPanel;
51
import javax.swing.JRadioButton;
52
import javax.swing.JScrollPane;
53
import javax.swing.JSplitPane;
54
import javax.swing.JTabbedPane;
55
import javax.swing.SwingConstants;
56
import javax.swing.tree.TreePath;
57
 
58
// FIXME bug Layout
59
 
156 ilm 60
public class RubriqueCotisationSQLElement extends ComptaSQLConfElement {
18 ilm 61
 
156 ilm 62
    public RubriqueCotisationSQLElement(final DBRoot root) {
63
        super(root.getTable("RUBRIQUE_COTISATION"), "une rubrique de cotisation", "rubriques de cotisation");
18 ilm 64
    }
65
 
144 ilm 66
    @Override
67
    protected synchronized void _initTableSource(SQLTableModelSource res) {
68
        res.init();
69
        res.getColumn(getTable().getField("LIGNE_PAYE_SIMPLIFIEE")).setRenderer(new LigneSimplifieeCellRenderer());
70
        super._initTableSource(res);
71
    }
72
 
18 ilm 73
    protected List<String> getListFields() {
74
        final List<String> l = new ArrayList<String>();
75
        l.add("CODE");
76
        l.add("NOM");
144 ilm 77
        l.add("LIGNE_PAYE_SIMPLIFIEE");
18 ilm 78
        l.add("ID_CAISSE_COTISATION");
79
        l.add("BASE");
80
        l.add("TX_PAT");
81
        l.add("TX_SAL");
82
        l.add("BRUT");
132 ilm 83
        l.add("ID_CODE_CAISSE_TYPE_RUBRIQUE");
84
        l.add("ID_CODE_BASE_ASSUJETTIE");
142 ilm 85
        l.add("ID_TYPE_COMPOSANT_BASE_ASSUJETTIE");
86
        l.add("ID_CODE_COTISATION_INDIVIDUELLE");
18 ilm 87
        l.add("PART_CSG");
94 ilm 88
        l.add("PART_CSG_SANS_ABATTEMENT");
18 ilm 89
        l.add("IMPOSABLE");
94 ilm 90
        l.add("PART_PAT_IMPOSABLE");
18 ilm 91
        return l;
92
    }
93
 
94
    protected List<String> getComboFields() {
95
        final List<String> l = new ArrayList<String>();
96
        l.add("CODE");
97
        l.add("NOM");
98
        return l;
99
    }
100
 
132 ilm 101
    @Override
102
    public ListMap<String, String> getShowAs() {
103
        return ListMap.singleton(null, "NOM");
18 ilm 104
    }
105
 
106
    /*
107
     * (non-Javadoc)
108
     *
109
     * @see org.openconcerto.devis.SQLElement#getComponent()
110
     */
111
    public SQLComponent createComponent() {
21 ilm 112
        return new RubriqueSQLComponent(this) {
18 ilm 113
 
114
            private ElementComboBox selCaisseCot = new ElementComboBox();
115
            private SQLJavaEditor formuleBase, formuleTxSal, formuleTxPat;
116
 
21 ilm 117
            @Override
118
            protected void addViews(GridBagConstraints c) {
18 ilm 119
                // Caisse de cotisation
120
                c.gridx = 0;
121
                JLabel labelSelCaisse = new JLabel(getLabelFor("ID_CAISSE_COTISATION"));
122
                labelSelCaisse.setHorizontalAlignment(SwingConstants.RIGHT);
123
                this.add(labelSelCaisse, c);
124
 
125
                c.gridx++;
126
                c.gridwidth = GridBagConstraints.REMAINDER;
127
                this.add(this.selCaisseCot, c);
128
                c.gridwidth = 1;
129
 
130
                /***********************************************************************************
131
                 * PANEL CALCUL
132
                 **********************************************************************************/
133
                JPanel panelCalcul = new JPanel();
134
                panelCalcul.setLayout(new GridBagLayout());
135
                final GridBagConstraints cPanel = new DefaultGridBagConstraints();
136
 
137
                final VariableTree tree = new VariableTree();
138
                JScrollPane paneTree = new JScrollPane(tree);
139
 
140
                cPanel.gridheight = GridBagConstraints.REMAINDER;
141
                cPanel.weighty = 1;
142
                cPanel.weightx = 1;
143
                cPanel.fill = GridBagConstraints.BOTH;
144
                // panelCalcul.add(paneTree, cPanel);
145
                cPanel.fill = GridBagConstraints.HORIZONTAL;
146
                cPanel.weighty = 0;
147
                cPanel.weightx = 0;
148
                cPanel.gridheight = 1;
149
 
150
                // Formule base
151
                cPanel.gridx++;
152
                final Map<String, List<?>> mapTree = VariablePayeSQLElement.getMapTree();
153
                this.formuleBase = new SQLJavaEditor(mapTree);
154
                this.formuleBase.setVarAssign("BASE");
155
 
156
                final JRadioButton radioBase = new JRadioButton(getLabelFor("BASE"));
157
                panelCalcul.add(radioBase, cPanel);
158
                cPanel.gridx++;
159
                panelCalcul.add(this.formuleBase, cPanel);
160
 
161
                // Formule Tx Sal
162
                cPanel.gridy++;
163
                cPanel.gridx = 1;
164
 
165
                this.formuleTxSal = new SQLJavaEditor(mapTree);
166
                this.formuleTxSal.setVarAssign("SAL");
167
                final JRadioButton radioTxSal = new JRadioButton(getLabelFor("TX_SAL"));
168
                panelCalcul.add(radioTxSal, cPanel);
169
                cPanel.gridx++;
170
                panelCalcul.add(this.formuleTxSal, cPanel);
171
 
172
                // Formule Tx Pat
173
                cPanel.gridy++;
174
                cPanel.gridx = 1;
175
                this.formuleTxPat = new SQLJavaEditor(mapTree);
176
                this.formuleTxPat.setVarAssign("PAT");
177
                final JRadioButton radioTxPat = new JRadioButton(getLabelFor("TX_PAT"));
178
                panelCalcul.add(radioTxPat, cPanel);
179
                cPanel.gridx++;
180
                panelCalcul.add(this.formuleTxPat, cPanel);
181
 
182
                ButtonGroup group1 = new ButtonGroup();
183
                group1.add(radioBase);
184
                group1.add(radioTxPat);
185
                group1.add(radioTxSal);
186
                radioBase.setSelected(true);
187
 
188
                // Salarie
189
                cPanel.gridy++;
190
                cPanel.gridx = 1;
191
                JLabel labelSelSal = new JLabel("Salarié");
192
                labelSelSal.setHorizontalAlignment(SwingConstants.RIGHT);
193
                panelCalcul.add(labelSelSal, cPanel);
194
 
80 ilm 195
                final SQLElement eltSal = getDirectory().getElement(SalarieSQLElement.class);
18 ilm 196
                final ElementComboBox selSalarie = new ElementComboBox(false);
197
 
198
                cPanel.gridx++;
199
                selSalarie.init(eltSal);
200
                panelCalcul.add(selSalarie, cPanel);
201
 
202
                /***********************************************************************************
203
                 * PANEL PROPRIETE
204
                 **********************************************************************************/
205
                JPanel panelProp = new JPanel();
206
                panelProp.setLayout(new GridBagLayout());
207
                cPanel.gridx = 0;
208
                cPanel.gridy = 0;
209
                cPanel.weightx = 0;
210
                cPanel.weighty = 0;
211
                cPanel.gridwidth = 1;
212
                cPanel.gridheight = 1;
213
                cPanel.fill = GridBagConstraints.HORIZONTAL;
214
                cPanel.anchor = GridBagConstraints.NORTHWEST;
215
                cPanel.insets = new Insets(2, 2, 1, 2);
216
 
217
                // Periode d'application
218
                this.addView("ID_PERIODE_VALIDITE", REQ + ";" + DEC + ";" + SEP);
219
                ElementSQLObject eltInfosPaye = (ElementSQLObject) this.getView("ID_PERIODE_VALIDITE");
220
                cPanel.gridy = 0;
221
                cPanel.gridx = 0;
222
                cPanel.gridheight = GridBagConstraints.REMAINDER;
223
                JPanel panelPeriodeVal = new JPanel();
224
                panelPeriodeVal.setBorder(BorderFactory.createTitledBorder("Période de validité"));
225
                panelPeriodeVal.add(eltInfosPaye);
226
                cPanel.fill = GridBagConstraints.NONE;
227
                cPanel.weightx = 0;
228
                cPanel.weighty = 1;
229
                panelProp.add(panelPeriodeVal, cPanel);
230
                cPanel.weightx = 0;
231
                cPanel.weighty = 0;
232
                cPanel.gridheight = 1;
233
                cPanel.fill = GridBagConstraints.HORIZONTAL;
234
 
235
                // Impression
236
                JLabel labelSelTypeImpression = new JLabel("Impression");
237
                cPanel.gridy++;
238
                cPanel.gridx = 1;
239
                cPanel.weightx = 0;
240
                panelProp.add(labelSelTypeImpression, cPanel);
241
 
156 ilm 242
                SQLRequestComboBox comboSelTypeImpression = new SQLRequestComboBox(false);
18 ilm 243
                cPanel.gridx++;
244
                cPanel.weightx = 1;
245
                panelProp.add(comboSelTypeImpression, cPanel);
246
 
144 ilm 247
                // Ligne simplifiée
248
                final JLabel labelEtat = new JLabel(getLabelFor("LIGNE_PAYE_SIMPLIFIEE"), SwingConstants.RIGHT);
249
                cPanel.gridy++;
250
                cPanel.gridx = 1;
251
                cPanel.weightx = 0;
252
                cPanel.fill = GridBagConstraints.HORIZONTAL;
253
                panelProp.add(labelEtat, cPanel);
254
                final LignePayeSimplifieeComboBox comboEtat = new LignePayeSimplifieeComboBox();
255
                cPanel.gridx++;
256
                cPanel.fill = GridBagConstraints.NONE;
257
                cPanel.weightx = 1;
258
                panelProp.add(comboEtat, cPanel);
259
                addView(new LignePayeSimplifieeRowItemView(comboEtat), "LIGNE_PAYE_SIMPLIFIEE", REQ);
260
 
18 ilm 261
                // Imposable
262
                cPanel.gridx = 1;
263
                cPanel.weightx = 0;
264
                cPanel.gridy++;
265
                JCheckBox checkImpo = new JCheckBox(getLabelFor("IMPOSABLE"));
266
                panelProp.add(checkImpo, cPanel);
267
 
144 ilm 268
                // Imposable
269
                cPanel.gridx = 1;
270
                cPanel.weightx = 0;
271
                cPanel.gridy++;
272
                JCheckBox checkalle = new JCheckBox(getLabelFor("ALLEGEMENT_COTISATION"));
273
                panelProp.add(checkalle, cPanel);
274
                addView(checkalle, "ALLEGEMENT_COTISATION", REQ);
275
 
142 ilm 276
                JLabel labelSelTypePersonnel = new JLabel("Code Type Personnel URSSAF (S21.G00.23)");
132 ilm 277
                cPanel.gridy++;
278
                cPanel.gridx = 1;
279
                cPanel.weightx = 0;
280
                panelProp.add(labelSelTypePersonnel, cPanel);
281
 
282
                ElementComboBox comboSelTypePersonnel = new ElementComboBox(false);
283
                cPanel.gridx++;
284
                cPanel.weightx = 1;
285
                panelProp.add(comboSelTypePersonnel, cPanel);
286
                this.addView(comboSelTypePersonnel, "ID_CODE_CAISSE_TYPE_RUBRIQUE");
287
 
142 ilm 288
                JLabel labelSelTypeBase = new JLabel("Code Base assujettie (S21.G00.78)");
132 ilm 289
                cPanel.gridy++;
290
                cPanel.gridx = 1;
291
                cPanel.weightx = 0;
292
                panelProp.add(labelSelTypeBase, cPanel);
293
 
294
                ElementComboBox comboSelTypeBase = new ElementComboBox(false);
295
                cPanel.gridx++;
296
                cPanel.weightx = 1;
297
                panelProp.add(comboSelTypeBase, cPanel);
298
                this.addView(comboSelTypeBase, "ID_CODE_BASE_ASSUJETTIE");
299
 
142 ilm 300
                JLabel labelSelTypeComposant = new JLabel("Type Composant base assujettie (S21.G00.79)");
301
                cPanel.gridy++;
302
                cPanel.gridx = 1;
303
                cPanel.weightx = 0;
304
                panelProp.add(labelSelTypeComposant, cPanel);
305
 
306
                ElementComboBox comboSelTypeComposant = new ElementComboBox(false);
307
                cPanel.gridx++;
308
                cPanel.weightx = 1;
309
                panelProp.add(comboSelTypeComposant, cPanel);
310
                this.addView(comboSelTypeComposant, "ID_TYPE_COMPOSANT_BASE_ASSUJETTIE");
311
 
312
                JLabel labelSelCodeInd = new JLabel("Code cotisation individuelle (S21.G00.81)");
313
                cPanel.gridy++;
314
                cPanel.gridx = 1;
315
                cPanel.weightx = 0;
316
                panelProp.add(labelSelCodeInd, cPanel);
317
 
318
                ElementComboBox comboSelCodeInd = new ElementComboBox(false);
319
                cPanel.gridx++;
320
                cPanel.weightx = 1;
321
                panelProp.add(comboSelCodeInd, cPanel);
322
                this.addView(comboSelCodeInd, "ID_CODE_COTISATION_INDIVIDUELLE");
144 ilm 323
 
142 ilm 324
                JLabel labelSelCodeEta = new JLabel("Code cotisation établissement (S21.G00.82.002)");
325
                cPanel.gridy++;
326
                cPanel.gridx = 1;
327
                cPanel.weightx = 0;
328
                panelProp.add(labelSelCodeEta, cPanel);
329
 
330
                ElementComboBox comboSelCodeEta = new ElementComboBox(false);
331
                cPanel.gridx++;
332
                cPanel.weightx = 1;
333
                panelProp.add(comboSelCodeEta, cPanel);
334
                this.addView(comboSelCodeEta, "ID_CODE_COTISATION_ETABLISSEMENT");
335
 
94 ilm 336
                // Patronale imposable
337
                cPanel.gridy++;
132 ilm 338
                c.gridx--;
94 ilm 339
                JCheckBox checkPartPatrImposable = new JCheckBox(getLabelFor("PART_PAT_IMPOSABLE"));
340
                panelProp.add(checkPartPatrImposable, cPanel);
341
 
18 ilm 342
                // Part csg
343
                cPanel.gridy++;
344
                JCheckBox checkPartPatr = new JCheckBox(getLabelFor("PART_CSG"));
345
                panelProp.add(checkPartPatr, cPanel);
346
 
94 ilm 347
                // Part csg
348
                cPanel.gridy++;
349
                JCheckBox checkPartPatrSansAbattement = new JCheckBox(getLabelFor("PART_CSG_SANS_ABATTEMENT"));
350
                panelProp.add(checkPartPatrSansAbattement, cPanel);
351
 
352
                NoneSelectedButtonGroup group = new NoneSelectedButtonGroup();
353
                group.add(checkPartPatrSansAbattement);
354
                group.add(checkPartPatr);
355
 
18 ilm 356
                // Brut
357
                cPanel.gridy++;
358
                JCheckBox checkBrut = new JCheckBox(getLabelFor("BRUT"));
359
                panelProp.add(checkBrut, cPanel);
360
 
361
                // Tabbed Pane
362
                JTabbedPane tab = new JTabbedPane();
363
                tab.add("Calcul", new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, paneTree, panelCalcul));
364
                tab.add("Propriétés", panelProp);
365
 
366
                c.gridwidth = GridBagConstraints.REMAINDER;
367
                c.gridy++;
368
                c.gridx = 0;
369
                c.fill = GridBagConstraints.BOTH;
370
                c.weightx = 1;
371
                c.weighty = 1;
372
                this.add(tab, c);
373
 
374
                tree.addMouseListener(new MouseAdapter() {
375
 
376
                    public void mousePressed(MouseEvent e) {
377
 
378
                        if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
379
                            TreePath path = tree.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
380
 
381
                            final Object obj = path.getLastPathComponent();
382
 
383
                            if (obj == null) {
384
                                return;
385
                            } else {
386
                                if (obj instanceof FormuleTreeNode) {
387
                                    FormuleTreeNode n = (FormuleTreeNode) obj;
388
 
389
                                    if (radioBase.isSelected()) {
390
                                        int start = formuleBase.getSelectionStart();
391
                                        String tmp = formuleBase.getText();
392
 
393
                                        formuleBase.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
394
                                    } else {
395
 
396
                                        if (radioTxPat.isSelected()) {
397
                                            int start = formuleTxPat.getSelectionStart();
398
                                            String tmp = formuleTxPat.getText();
399
 
400
                                            formuleTxPat.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
401
                                        } else {
402
                                            int start = formuleTxSal.getSelectionStart();
403
                                            String tmp = formuleTxSal.getText();
404
 
405
                                            formuleTxSal.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
406
                                        }
407
                                    }
408
                                }
409
 
410
                            }
411
                        }
412
                    }
413
                });
414
 
415
                this.addRequiredSQLObject(this.selCaisseCot, "ID_CAISSE_COTISATION");
416
                this.addSQLObject(this.formuleBase, "BASE");
417
                this.addSQLObject(this.formuleTxPat, "TX_PAT");
418
                this.addSQLObject(this.formuleTxSal, "TX_SAL");
419
                this.addSQLObject(checkBrut, "BRUT");
420
                this.addSQLObject(checkPartPatr, "PART_CSG");
94 ilm 421
                this.addSQLObject(checkPartPatrSansAbattement, "PART_CSG_SANS_ABATTEMENT");
18 ilm 422
                this.addSQLObject(checkImpo, "IMPOSABLE");
94 ilm 423
                this.addSQLObject(checkPartPatrImposable, "PART_PAT_IMPOSABLE");
18 ilm 424
                this.addRequiredSQLObject(comboSelTypeImpression, "ID_IMPRESSION_RUBRIQUE");
425
 
426
                selSalarie.addValueListener(new PropertyChangeListener() {
427
                    public void propertyChange(PropertyChangeEvent evt) {
428
 
429
                        formuleBase.setSalarieID(selSalarie.getSelectedId());
430
                        formuleTxPat.setSalarieID(selSalarie.getSelectedId());
431
                        formuleTxSal.setSalarieID(selSalarie.getSelectedId());
432
                    }
433
                });
434
            }
435
        };
436
    }
57 ilm 437
 
438
    @Override
439
    protected String createCode() {
440
        return "humanresources.payroll.category.subscription";
441
    }
18 ilm 442
}