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.config.ComptaPropsConfiguration;
|
156 |
ilm |
17 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
18 |
ilm |
18 |
import org.openconcerto.erp.core.common.ui.SQLJavaEditor;
|
|
|
19 |
import org.openconcerto.erp.core.humanresources.payroll.component.FormuleTreeNode;
|
|
|
20 |
import org.openconcerto.erp.core.humanresources.payroll.component.VariableRowTreeNode;
|
|
|
21 |
import org.openconcerto.erp.core.humanresources.payroll.component.VariableTree;
|
|
|
22 |
import org.openconcerto.sql.Configuration;
|
|
|
23 |
import org.openconcerto.sql.element.BaseSQLComponent;
|
|
|
24 |
import org.openconcerto.sql.element.SQLComponent;
|
132 |
ilm |
25 |
import org.openconcerto.sql.element.TreesOfSQLRows;
|
156 |
ilm |
26 |
import org.openconcerto.sql.model.DBRoot;
|
18 |
ilm |
27 |
import org.openconcerto.sql.model.SQLBase;
|
|
|
28 |
import org.openconcerto.sql.model.SQLField;
|
|
|
29 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
30 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
31 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
32 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
33 |
import org.openconcerto.sql.model.Where;
|
|
|
34 |
import org.openconcerto.sql.sqlobject.ElementComboBox;
|
|
|
35 |
import org.openconcerto.sql.view.EditFrame;
|
|
|
36 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
37 |
import org.openconcerto.ui.component.ITextArea;
|
|
|
38 |
import org.openconcerto.ui.warning.JLabelWarning;
|
|
|
39 |
import org.openconcerto.utils.ExceptionHandler;
|
21 |
ilm |
40 |
import org.openconcerto.utils.checks.ValidState;
|
|
|
41 |
import org.openconcerto.utils.text.SimpleDocumentListener;
|
18 |
ilm |
42 |
|
|
|
43 |
import java.awt.Component;
|
|
|
44 |
import java.awt.Dimension;
|
|
|
45 |
import java.awt.GridBagConstraints;
|
|
|
46 |
import java.awt.GridBagLayout;
|
|
|
47 |
import java.awt.event.ActionEvent;
|
|
|
48 |
import java.awt.event.ActionListener;
|
|
|
49 |
import java.awt.event.MouseAdapter;
|
|
|
50 |
import java.awt.event.MouseEvent;
|
|
|
51 |
import java.beans.PropertyChangeEvent;
|
|
|
52 |
import java.beans.PropertyChangeListener;
|
|
|
53 |
import java.sql.SQLException;
|
|
|
54 |
import java.util.ArrayList;
|
156 |
ilm |
55 |
import java.util.Arrays;
|
18 |
ilm |
56 |
import java.util.HashMap;
|
|
|
57 |
import java.util.HashSet;
|
|
|
58 |
import java.util.List;
|
|
|
59 |
import java.util.Map;
|
|
|
60 |
import java.util.Set;
|
|
|
61 |
|
|
|
62 |
import javax.swing.AbstractAction;
|
|
|
63 |
import javax.swing.ButtonGroup;
|
|
|
64 |
import javax.swing.JLabel;
|
156 |
ilm |
65 |
import javax.swing.JOptionPane;
|
18 |
ilm |
66 |
import javax.swing.JPanel;
|
|
|
67 |
import javax.swing.JPopupMenu;
|
|
|
68 |
import javax.swing.JRadioButton;
|
|
|
69 |
import javax.swing.JScrollPane;
|
|
|
70 |
import javax.swing.JSplitPane;
|
|
|
71 |
import javax.swing.JTextField;
|
|
|
72 |
import javax.swing.event.DocumentEvent;
|
|
|
73 |
import javax.swing.tree.TreePath;
|
|
|
74 |
|
|
|
75 |
import org.apache.commons.dbutils.handlers.ArrayListHandler;
|
|
|
76 |
import org.jedit.CTokenMarker;
|
|
|
77 |
|
|
|
78 |
// FIXME retirer le scrolling de l'edit frame pour scroller uniquement sur l'arbre des variables
|
156 |
ilm |
79 |
public class VariablePayeSQLElement extends ComptaSQLConfElement {
|
18 |
ilm |
80 |
|
21 |
ilm |
81 |
private final static ValidState VAR_ALREADY_EXIST = ValidState.createInvalid("Cette variable existe déjà !");
|
|
|
82 |
private final static ValidState VAR_NAME_NOT_CORRECT = ValidState.createInvalid("Nom de variable incorrect !");
|
|
|
83 |
private final static ValidState VAR_NO_NAME = ValidState.createInvalid("Aucun nom attribué !");
|
|
|
84 |
|
18 |
ilm |
85 |
private static SQLTable tableVarSal = null;
|
|
|
86 |
|
|
|
87 |
private static SQLTable getTableVarSal() {
|
|
|
88 |
if (tableVarSal == null)
|
|
|
89 |
tableVarSal = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete().getTable("VARIABLE_SALARIE");
|
|
|
90 |
return tableVarSal;
|
|
|
91 |
}
|
|
|
92 |
|
156 |
ilm |
93 |
public VariablePayeSQLElement(final DBRoot root) {
|
|
|
94 |
super(root.getTable("VARIABLE_PAYE"), "une variable de paye", "variables de paye");
|
18 |
ilm |
95 |
}
|
|
|
96 |
|
|
|
97 |
protected List<String> getListFields() {
|
|
|
98 |
final List<String> l = new ArrayList<String>();
|
|
|
99 |
l.add("NOM");
|
|
|
100 |
l.add("CATEGORIE");
|
|
|
101 |
l.add("VALEUR");
|
|
|
102 |
l.add("FORMULE");
|
|
|
103 |
return l;
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
@Override
|
|
|
107 |
public Set<String> getInsertOnlyFields() {
|
|
|
108 |
Set<String> s = new HashSet<String>();
|
|
|
109 |
s.add("NOM");
|
|
|
110 |
return s;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
protected List<String> getComboFields() {
|
|
|
114 |
final List<String> l = new ArrayList<String>();
|
|
|
115 |
l.add("NOM");
|
|
|
116 |
return l;
|
|
|
117 |
}
|
|
|
118 |
|
57 |
ilm |
119 |
public static final boolean isForbidden(final String code) {
|
21 |
ilm |
120 |
final List<String> l = getForbiddenVarName();
|
|
|
121 |
for (int i = 0; i < l.size(); i++) {
|
|
|
122 |
if (l.get(i).trim().equalsIgnoreCase(code)) {
|
|
|
123 |
return true;
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
return false;
|
|
|
127 |
}
|
|
|
128 |
|
18 |
ilm |
129 |
// Liste des variables deja definit
|
|
|
130 |
// L'utilisateur ne peut pas utiliser ces noms
|
|
|
131 |
public static final List<String> getForbiddenVarName() {
|
|
|
132 |
|
|
|
133 |
List<String> l = new ArrayList<String>();
|
|
|
134 |
|
|
|
135 |
for (SQLField field : getTableVarSal().getContentFields()) {
|
|
|
136 |
|
|
|
137 |
// String field = i.next().toString().trim();
|
|
|
138 |
// field = field.substring(field.indexOf('.') + 1, field.length() - 1);
|
|
|
139 |
l.add(field.getName());
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
l.add("PAT");
|
|
|
143 |
l.add("SAL");
|
|
|
144 |
l.add("BASE");
|
|
|
145 |
l.add("MONTANT");
|
|
|
146 |
l.add("TAUX");
|
|
|
147 |
|
|
|
148 |
l.add("ACOMPTE");
|
|
|
149 |
l.add("DUREE_HEBDO");
|
|
|
150 |
l.add("DUREE_MOIS");
|
|
|
151 |
l.add("SALAIRE_MOIS");
|
|
|
152 |
l.add("TAUX_AT");
|
|
|
153 |
l.add("CONGES_PAYES");
|
|
|
154 |
l.add("NB_ENFANTS");
|
|
|
155 |
l.add("NB_PERS_A_CHARGE");
|
|
|
156 |
l.add("PAT");
|
|
|
157 |
l.add("SAL");
|
|
|
158 |
l.add("MONTANT");
|
|
|
159 |
|
|
|
160 |
l.add("SAL_BRUT");
|
|
|
161 |
l.add("COT_PAT");
|
|
|
162 |
l.add("COT_SAL");
|
|
|
163 |
l.add("NET_IMP");
|
|
|
164 |
l.add("NET_A_PAYER");
|
|
|
165 |
l.add("CSG");
|
|
|
166 |
|
|
|
167 |
l.add("CONGES_ACQUIS");
|
|
|
168 |
l.add("CSG_C");
|
|
|
169 |
l.add("CONGES_PRIS");
|
|
|
170 |
l.add("RESTANT");
|
|
|
171 |
l.add("COT_PAT_C");
|
|
|
172 |
l.add("COT_SAL_C");
|
|
|
173 |
l.add("HEURE_ABS");
|
|
|
174 |
l.add("HEURE_TRAV");
|
|
|
175 |
l.add("HEURE_110");
|
|
|
176 |
l.add("HEURE_125");
|
|
|
177 |
l.add("HEURE_150");
|
|
|
178 |
l.add("HEURE_200");
|
|
|
179 |
l.add("SAL_BRUT_C");
|
144 |
ilm |
180 |
l.add("HEURE_TRAV_C");
|
18 |
ilm |
181 |
l.add("NET_A_PAYER_C");
|
|
|
182 |
l.add("NET_IMP_C");
|
132 |
ilm |
183 |
|
144 |
ilm |
184 |
l.add("ANCIENNETE_JOUR");
|
|
|
185 |
|
132 |
ilm |
186 |
l.add("COEFF");
|
|
|
187 |
l.add("ECHELON");
|
|
|
188 |
l.add("NIVEAU");
|
|
|
189 |
l.add("POSITION");
|
|
|
190 |
l.add("INDICE");
|
|
|
191 |
|
18 |
ilm |
192 |
return l;
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
// Map qui contient la structure de l'arbre
|
|
|
196 |
public static final Map<String, List<?>> getMapTree() {
|
|
|
197 |
|
|
|
198 |
SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
|
|
|
199 |
SQLBase baseCommon = Configuration.getInstance().getBase();
|
|
|
200 |
SQLTable tableVar = baseCommon.getTable("VARIABLE_PAYE");
|
|
|
201 |
SQLTable tableCumulsConges = base.getTable("CUMULS_CONGES");
|
|
|
202 |
SQLTable tableCumulsPaye = base.getTable("CUMULS_PAYE");
|
156 |
ilm |
203 |
SQLTable tablePAS = base.getTable("PAS");
|
18 |
ilm |
204 |
|
|
|
205 |
Map<String, List<?>> mapTree = new HashMap<String, List<?>>();
|
|
|
206 |
|
|
|
207 |
// Variables propre au salarié
|
|
|
208 |
List<SQLField> varSal = new ArrayList<SQLField>();
|
|
|
209 |
|
|
|
210 |
for (SQLField field : getTableVarSal().getContentFields()) {
|
|
|
211 |
|
|
|
212 |
varSal.add(field);
|
|
|
213 |
}
|
|
|
214 |
for (SQLField field : tableCumulsConges.getContentFields()) {
|
|
|
215 |
|
|
|
216 |
varSal.add(field);
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
for (SQLField field : tableCumulsPaye.getContentFields()) {
|
|
|
220 |
|
|
|
221 |
varSal.add(field);
|
|
|
222 |
}
|
|
|
223 |
|
156 |
ilm |
224 |
for (SQLField field : tablePAS.getContentFields()) {
|
|
|
225 |
|
|
|
226 |
varSal.add(field);
|
|
|
227 |
}
|
|
|
228 |
|
18 |
ilm |
229 |
mapTree.put("Infos période", varSal);
|
|
|
230 |
|
|
|
231 |
List<SQLField> l = new ArrayList<SQLField>();
|
|
|
232 |
SQLTable tableInfos = base.getTable("INFOS_SALARIE_PAYE");
|
|
|
233 |
l.add(tableInfos.getField("DUREE_HEBDO"));
|
|
|
234 |
l.add(tableInfos.getField("DUREE_MOIS"));
|
|
|
235 |
l.add(tableInfos.getField("SALAIRE_MOIS"));
|
|
|
236 |
l.add(tableInfos.getField("TAUX_AT"));
|
|
|
237 |
l.add(tableInfos.getField("CONGES_PAYES"));
|
132 |
ilm |
238 |
if (tableInfos.contains("BASE_FILLON_ANNUELLE")) {
|
|
|
239 |
l.add(tableInfos.getField("BASE_FILLON_ANNUELLE"));
|
|
|
240 |
}
|
|
|
241 |
|
91 |
ilm |
242 |
if (tableInfos.contains("PRIME_TRANSPORT")) {
|
|
|
243 |
l.add(tableInfos.getField("PRIME_LOGEMENT"));
|
|
|
244 |
l.add(tableInfos.getField("PRIME_PANIER"));
|
|
|
245 |
l.add(tableInfos.getField("PRIME_TRANSPORT"));
|
|
|
246 |
}
|
18 |
ilm |
247 |
mapTree.put("Contrat salarié", l);
|
|
|
248 |
|
|
|
249 |
List<SQLField> l2 = new ArrayList<SQLField>();
|
|
|
250 |
SQLTable tableFichePaye = base.getTable("FICHE_PAYE");
|
|
|
251 |
l2.add(tableFichePaye.getField("CONGES_ACQUIS"));
|
|
|
252 |
l2.add(tableFichePaye.getField("ACOMPTE"));
|
|
|
253 |
l2.add(tableFichePaye.getField("SAL_BRUT"));
|
144 |
ilm |
254 |
l2.add(tableFichePaye.getField("SAL_BRUT_TAXABLE"));
|
|
|
255 |
l2.add(tableFichePaye.getField("SAL_BASE_BRUT"));
|
|
|
256 |
l2.add(tableFichePaye.getField("TAXE_CM_SAL"));
|
|
|
257 |
l2.add(tableFichePaye.getField("TAXE_CM_PAT"));
|
|
|
258 |
l2.add(tableFichePaye.getField("SAL_BRUT_COTISABLE"));
|
18 |
ilm |
259 |
l2.add(tableFichePaye.getField("COT_PAT"));
|
|
|
260 |
l2.add(tableFichePaye.getField("COT_SAL"));
|
|
|
261 |
l2.add(tableFichePaye.getField("NET_IMP"));
|
|
|
262 |
l2.add(tableFichePaye.getField("NET_A_PAYER"));
|
|
|
263 |
l2.add(tableFichePaye.getField("CSG"));
|
132 |
ilm |
264 |
|
18 |
ilm |
265 |
mapTree.put("Contenu paye", l2);
|
|
|
266 |
|
132 |
ilm |
267 |
List<SQLField> l3 = new ArrayList<SQLField>();
|
|
|
268 |
SQLTable tableClassement = base.getTable("CLASSEMENT_CONVENTIONNEL");
|
|
|
269 |
l3.add(tableClassement.getField("COEFF"));
|
|
|
270 |
l3.add(tableClassement.getField("ECHELON"));
|
|
|
271 |
l3.add(tableClassement.getField("NIVEAU"));
|
|
|
272 |
l3.add(tableClassement.getField("POSITION"));
|
|
|
273 |
l3.add(tableClassement.getField("INDICE"));
|
|
|
274 |
mapTree.put("Classement conventionnel", l3);
|
|
|
275 |
|
|
|
276 |
List<SQLField> l4 = new ArrayList<SQLField>();
|
|
|
277 |
SQLTable tableCoeff = base.getTable("COEFF_PRIME");
|
|
|
278 |
if (tableCoeff != null) {
|
|
|
279 |
l4.add(tableCoeff.getField("PRIME_PERSO"));
|
|
|
280 |
l4.add(tableCoeff.getField("PRIME_RECONSTRUCTION"));
|
|
|
281 |
l4.add(tableCoeff.getField("PRIME_ANCIENNETE"));
|
|
|
282 |
l4.add(tableCoeff.getField("PRIME_DEROULEMENT"));
|
|
|
283 |
mapTree.put("Coefficient de prime", l4);
|
|
|
284 |
}
|
18 |
ilm |
285 |
/*
|
|
|
286 |
* List lEtat = new ArrayList(); SQLTable tableEtat =
|
|
|
287 |
* Configuration.getInstance().getBase().getTable("ETAT_CIVIL");
|
|
|
288 |
* lEtat.add(tableEtat.getField("NB_ENFANTS"));
|
|
|
289 |
* lEtat.add(tableEtat.getField("NB_PERS_A_CHARGE")); mapTree.put("Salarie.etat_civil",
|
|
|
290 |
* lEtat);
|
|
|
291 |
*/
|
|
|
292 |
|
|
|
293 |
SQLSelect selAllVarID = new SQLSelect(tableVar.getBase());
|
|
|
294 |
|
|
|
295 |
selAllVarID.addSelect(tableVar.getField("ID"));
|
|
|
296 |
selAllVarID.addRawOrder("LENGTH(\"VARIABLE_PAYE\".\"NOM\") DESC");
|
|
|
297 |
|
|
|
298 |
String reqAllVarID = selAllVarID.asString();
|
|
|
299 |
Object[] objKeysRowVar = ((List) tableVar.getBase().getDataSource().execute(reqAllVarID, new ArrayListHandler())).toArray();
|
|
|
300 |
|
|
|
301 |
List<SQLRow> lVar = new ArrayList<SQLRow>();
|
|
|
302 |
for (int i = 0; i < objKeysRowVar.length; i++) {
|
|
|
303 |
Object[] tmp = (Object[]) objKeysRowVar[i];
|
|
|
304 |
lVar.add(tableVar.getRow(Integer.parseInt(tmp[0].toString())));
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
if (lVar.size() > 0) {
|
|
|
308 |
mapTree.put("Variables", lVar);
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
List<Map<String, String>> fonction = new ArrayList<Map<String, String>>();
|
|
|
312 |
Map<String, String> listFonction = new HashMap<String, String>();
|
|
|
313 |
listFonction.put("Minimum", "Math.min()");
|
|
|
314 |
listFonction.put("Maximum", "Math.max()");
|
|
|
315 |
listFonction.put("Valeur absolue", "Math.abs()");
|
|
|
316 |
listFonction.put("Arrondi", "Math.round()");
|
|
|
317 |
|
|
|
318 |
fonction.add(listFonction);
|
|
|
319 |
|
|
|
320 |
mapTree.put("Fonctions", fonction);
|
|
|
321 |
// Chargement des variables dans l'éditeur
|
|
|
322 |
// System.out.println(mapTree);
|
|
|
323 |
|
|
|
324 |
return mapTree;
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
/*
|
|
|
328 |
* (non-Javadoc)
|
|
|
329 |
*
|
|
|
330 |
* @see org.openconcerto.devis.SQLElement#getComponent()
|
|
|
331 |
*/
|
|
|
332 |
public SQLComponent createComponent() {
|
|
|
333 |
|
|
|
334 |
return new BaseSQLComponent(this) {
|
|
|
335 |
|
21 |
ilm |
336 |
private ValidState validVarName;
|
18 |
ilm |
337 |
private JRadioButton radioVal = new JRadioButton("Valeur");
|
|
|
338 |
private JRadioButton radioFormule = new JRadioButton("Formule");
|
|
|
339 |
|
|
|
340 |
private final JTextField textValeur = new JTextField();
|
|
|
341 |
// private final ITextArea textFormule = new ITextArea();
|
|
|
342 |
private final VariableTree treeVariable = new VariableTree();
|
|
|
343 |
private final JTextField textNom = new JTextField();
|
21 |
ilm |
344 |
private final JLabel labelWarningBadVar = new JLabelWarning();
|
18 |
ilm |
345 |
private ElementComboBox comboSelSal;
|
|
|
346 |
private EditFrame edit = null;
|
|
|
347 |
private final SQLJavaEditor textFormule = new SQLJavaEditor(getMapTree());
|
|
|
348 |
|
|
|
349 |
public void addViews() {
|
|
|
350 |
this.setLayout(new GridBagLayout());
|
|
|
351 |
final GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
352 |
|
21 |
ilm |
353 |
this.validVarName = null;
|
18 |
ilm |
354 |
this.textFormule.setEditable(false);
|
|
|
355 |
|
|
|
356 |
// Arbre des variables
|
|
|
357 |
JScrollPane sc = new JScrollPane(this.treeVariable);
|
|
|
358 |
sc.setPreferredSize(new Dimension(150, sc.getPreferredSize().height));
|
|
|
359 |
|
|
|
360 |
this.treeVariable.addMouseListener(new MouseAdapter() {
|
|
|
361 |
public void mousePressed(final MouseEvent mE) {
|
|
|
362 |
if (mE.getButton() == MouseEvent.BUTTON3) {
|
|
|
363 |
JPopupMenu menuDroit = new JPopupMenu();
|
|
|
364 |
|
|
|
365 |
TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y);
|
|
|
366 |
|
|
|
367 |
final Object obj = path.getLastPathComponent();
|
|
|
368 |
|
|
|
369 |
if ((obj == null) || !(obj instanceof VariableRowTreeNode)) {
|
|
|
370 |
return;
|
|
|
371 |
}
|
|
|
372 |
|
|
|
373 |
menuDroit.add(new AbstractAction("Editer") {
|
|
|
374 |
public void actionPerformed(ActionEvent e) {
|
|
|
375 |
if (edit == null) {
|
80 |
ilm |
376 |
edit = new EditFrame(getElement(), EditFrame.MODIFICATION);
|
18 |
ilm |
377 |
}
|
|
|
378 |
|
|
|
379 |
System.err.println("Action performed");
|
|
|
380 |
|
|
|
381 |
if (obj != null) {
|
|
|
382 |
System.err.println("Object not null --> " + obj.toString());
|
|
|
383 |
if (obj instanceof VariableRowTreeNode) {
|
|
|
384 |
System.err.println("Object VariableRowTreeNode");
|
|
|
385 |
VariableRowTreeNode varNode = (VariableRowTreeNode) obj;
|
|
|
386 |
|
|
|
387 |
edit.selectionId(varNode.getID(), 1);
|
|
|
388 |
edit.setVisible(true);
|
|
|
389 |
}
|
|
|
390 |
}
|
|
|
391 |
}
|
|
|
392 |
});
|
|
|
393 |
menuDroit.show((Component) mE.getSource(), mE.getPoint().x, mE.getPoint().y);
|
|
|
394 |
} else {
|
|
|
395 |
if (mE.getClickCount() == 2) {
|
|
|
396 |
TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y);
|
|
|
397 |
Object obj = path.getLastPathComponent();
|
|
|
398 |
|
|
|
399 |
if (obj != null) {
|
|
|
400 |
if (obj instanceof FormuleTreeNode) {
|
|
|
401 |
final FormuleTreeNode n = (FormuleTreeNode) obj;
|
|
|
402 |
|
|
|
403 |
int start = textFormule.getSelectionStart();
|
|
|
404 |
String tmp = textFormule.getText();
|
|
|
405 |
textFormule.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
|
|
|
406 |
}
|
|
|
407 |
}
|
|
|
408 |
}
|
|
|
409 |
}
|
|
|
410 |
}
|
|
|
411 |
});
|
|
|
412 |
|
|
|
413 |
JPanel panelDroite = new JPanel();
|
|
|
414 |
panelDroite.setLayout(new GridBagLayout());
|
|
|
415 |
|
|
|
416 |
// Categorie
|
|
|
417 |
JTextField textCategorie = new JTextField();
|
|
|
418 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
419 |
c.gridheight = 1;
|
|
|
420 |
c.gridx = 1;
|
|
|
421 |
c.gridy = 0;
|
|
|
422 |
JLabel labelCategorie = new JLabel("Catégorie");
|
|
|
423 |
panelDroite.add(labelCategorie, c);
|
|
|
424 |
c.gridx++;
|
21 |
ilm |
425 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
18 |
ilm |
426 |
panelDroite.add(textCategorie, c);
|
21 |
ilm |
427 |
c.gridwidth = 1;
|
18 |
ilm |
428 |
|
|
|
429 |
// Nom
|
|
|
430 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
431 |
c.gridheight = 1;
|
|
|
432 |
c.gridx = 1;
|
|
|
433 |
c.gridy++;
|
|
|
434 |
JLabel labelNom = new JLabel("Nom");
|
|
|
435 |
panelDroite.add(labelNom, c);
|
|
|
436 |
|
|
|
437 |
c.gridx++;
|
21 |
ilm |
438 |
c.weightx = 1;
|
18 |
ilm |
439 |
panelDroite.add(this.textNom, c);
|
|
|
440 |
|
21 |
ilm |
441 |
this.textNom.getDocument().addDocumentListener(new SimpleDocumentListener() {
|
|
|
442 |
@Override
|
|
|
443 |
public void update(DocumentEvent e) {
|
|
|
444 |
updateValidVarName();
|
18 |
ilm |
445 |
}
|
|
|
446 |
});
|
|
|
447 |
|
|
|
448 |
c.gridx++;
|
21 |
ilm |
449 |
c.weightx = 0;
|
18 |
ilm |
450 |
panelDroite.add(this.labelWarningBadVar, c);
|
|
|
451 |
|
|
|
452 |
// Description
|
|
|
453 |
JLabel labelInfos = new JLabel(getLabelFor("INFOS"));
|
|
|
454 |
ITextArea textInfos = new ITextArea();
|
|
|
455 |
c.gridy++;
|
|
|
456 |
c.gridx = 1;
|
|
|
457 |
c.gridwidth = 1;
|
21 |
ilm |
458 |
c.weightx = 0;
|
18 |
ilm |
459 |
panelDroite.add(labelInfos, c);
|
|
|
460 |
c.gridx++;
|
|
|
461 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
21 |
ilm |
462 |
c.weightx = 1;
|
18 |
ilm |
463 |
c.weighty = 0;
|
|
|
464 |
panelDroite.add(textInfos, c);
|
|
|
465 |
|
|
|
466 |
// Valeur
|
|
|
467 |
c.gridx = 1;
|
|
|
468 |
c.gridy++;
|
|
|
469 |
c.gridwidth = 1;
|
21 |
ilm |
470 |
c.weightx = 0;
|
18 |
ilm |
471 |
panelDroite.add(this.radioVal, c);
|
|
|
472 |
|
|
|
473 |
c.gridx++;
|
21 |
ilm |
474 |
c.weightx = 1;
|
18 |
ilm |
475 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
476 |
panelDroite.add(this.textValeur, c);
|
|
|
477 |
|
|
|
478 |
c.gridwidth = 1;
|
|
|
479 |
c.gridx = 1;
|
|
|
480 |
c.gridy++;
|
|
|
481 |
panelDroite.add(this.radioFormule, c);
|
|
|
482 |
|
|
|
483 |
c.gridx++;
|
|
|
484 |
c.weightx = 1;
|
|
|
485 |
c.weighty = 1;
|
|
|
486 |
c.fill = GridBagConstraints.BOTH;
|
|
|
487 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
488 |
panelDroite.add(this.textFormule, c);
|
|
|
489 |
c.gridwidth = 1;
|
|
|
490 |
|
|
|
491 |
ButtonGroup group = new ButtonGroup();
|
|
|
492 |
group.add(this.radioVal);
|
|
|
493 |
group.add(this.radioFormule);
|
|
|
494 |
|
|
|
495 |
this.radioVal.setSelected(true);
|
|
|
496 |
setFormuleEnabled(false);
|
|
|
497 |
|
|
|
498 |
this.radioVal.addActionListener(new ActionListener() {
|
|
|
499 |
public void actionPerformed(ActionEvent e) {
|
|
|
500 |
|
|
|
501 |
setFormuleEnabled(false);
|
|
|
502 |
}
|
|
|
503 |
});
|
|
|
504 |
this.radioFormule.addActionListener(new ActionListener() {
|
|
|
505 |
public void actionPerformed(ActionEvent e) {
|
|
|
506 |
|
|
|
507 |
setFormuleEnabled(true);
|
|
|
508 |
}
|
|
|
509 |
});
|
|
|
510 |
|
|
|
511 |
c.gridy++;
|
|
|
512 |
c.gridx = 1;
|
|
|
513 |
c.weighty = 0;
|
|
|
514 |
c.weightx = 0;
|
|
|
515 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
516 |
|
|
|
517 |
this.comboSelSal = new ElementComboBox(false);
|
80 |
ilm |
518 |
this.comboSelSal.init(getDirectory().getElement(SalarieSQLElement.class));
|
18 |
ilm |
519 |
|
|
|
520 |
c.gridx++;
|
21 |
ilm |
521 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
522 |
c.weightx = 0;
|
18 |
ilm |
523 |
panelDroite.add(this.comboSelSal, c);
|
21 |
ilm |
524 |
c.gridwidth = 1;
|
18 |
ilm |
525 |
|
|
|
526 |
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sc, panelDroite);
|
|
|
527 |
|
|
|
528 |
c.fill = GridBagConstraints.BOTH;
|
|
|
529 |
c.gridx = 0;
|
|
|
530 |
c.gridy = 0;
|
|
|
531 |
c.weightx = 1;
|
|
|
532 |
c.weighty = 1;
|
|
|
533 |
this.add(split, c);
|
|
|
534 |
|
|
|
535 |
this.addRequiredSQLObject(this.textNom, "NOM");
|
|
|
536 |
this.addSQLObject(this.textValeur, "VALEUR");
|
|
|
537 |
this.addSQLObject(this.textFormule, "FORMULE");
|
|
|
538 |
this.addSQLObject(textCategorie, "CATEGORIE");
|
|
|
539 |
this.addSQLObject(textInfos, "INFOS");
|
|
|
540 |
|
|
|
541 |
this.comboSelSal.addValueListener(new PropertyChangeListener() {
|
|
|
542 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
543 |
// TODO Auto-generated method stub
|
|
|
544 |
textFormule.setSalarieID(comboSelSal.getSelectedId());
|
|
|
545 |
}
|
|
|
546 |
});
|
|
|
547 |
}
|
|
|
548 |
|
21 |
ilm |
549 |
@Override
|
|
|
550 |
public synchronized ValidState getValidState() {
|
|
|
551 |
return super.getValidState().and(this.validVarName);
|
18 |
ilm |
552 |
}
|
|
|
553 |
|
|
|
554 |
private void setFormuleEnabled(boolean b) {
|
|
|
555 |
|
|
|
556 |
if (b) {
|
|
|
557 |
this.textValeur.setText("");
|
|
|
558 |
} else {
|
|
|
559 |
this.textFormule.setText("");
|
|
|
560 |
}
|
|
|
561 |
|
|
|
562 |
this.textValeur.setEditable(!b);
|
|
|
563 |
this.textValeur.setEnabled(!b);
|
|
|
564 |
this.textFormule.setEditable(b);
|
|
|
565 |
this.textFormule.setEnabled(b);
|
|
|
566 |
this.treeVariable.setEnabled(b);
|
|
|
567 |
this.treeVariable.setEditable(b);
|
|
|
568 |
}
|
|
|
569 |
|
21 |
ilm |
570 |
private void setValidVarName(ValidState s) {
|
|
|
571 |
if (!s.equals(this.validVarName)) {
|
|
|
572 |
this.validVarName = s;
|
|
|
573 |
final boolean warningVisible = !s.isValid();
|
|
|
574 |
if (warningVisible)
|
|
|
575 |
this.labelWarningBadVar.setText(s.getValidationText());
|
|
|
576 |
this.labelWarningBadVar.setVisible(warningVisible);
|
|
|
577 |
this.fireValidChange();
|
|
|
578 |
}
|
|
|
579 |
}
|
18 |
ilm |
580 |
|
21 |
ilm |
581 |
private void updateValidVarName() {
|
|
|
582 |
this.setValidVarName(this.computeValidVarName());
|
|
|
583 |
}
|
|
|
584 |
|
|
|
585 |
private ValidState computeValidVarName() {
|
18 |
ilm |
586 |
// on vérifie si la syntaxe de la variable est correct (chiffre lettre et _)
|
21 |
ilm |
587 |
final String varName = this.textNom.getText().trim();
|
18 |
ilm |
588 |
|
|
|
589 |
System.err.println("Verification de la validité du nom de la variable.");
|
|
|
590 |
|
|
|
591 |
if (varName.length() == 0) {
|
21 |
ilm |
592 |
return VAR_NO_NAME;
|
18 |
ilm |
593 |
}
|
|
|
594 |
|
|
|
595 |
// ne contient que des chiffre lettre et _ et ne commence pas par un chiffre
|
|
|
596 |
if (!isJavaVar(varName)) {
|
21 |
ilm |
597 |
return VAR_NAME_NOT_CORRECT;
|
18 |
ilm |
598 |
}
|
|
|
599 |
|
|
|
600 |
// on vérifie que la variable n'existe pas déja
|
|
|
601 |
SQLSelect selAllVarName = new SQLSelect(getTable().getBase());
|
|
|
602 |
|
|
|
603 |
selAllVarName.addSelect(VariablePayeSQLElement.this.getTable().getField("ID"));
|
21 |
ilm |
604 |
Where w = new Where(VariablePayeSQLElement.this.getTable().getField("NOM"), "=", varName);
|
18 |
ilm |
605 |
w = w.and(new Where(VariablePayeSQLElement.this.getTable().getKey(), "!=", getSelectedID()));
|
|
|
606 |
selAllVarName.setWhere(w);
|
|
|
607 |
|
|
|
608 |
String reqAllVarName = selAllVarName.asString();// + " AND '" + varName.trim() + "'
|
|
|
609 |
// REGEXP VARIABLE_PAYE.NOM";
|
|
|
610 |
Object[] objKeysRowName = ((List) getTable().getBase().getDataSource().execute(reqAllVarName, new ArrayListHandler())).toArray();
|
|
|
611 |
|
|
|
612 |
if (objKeysRowName.length > 0) {
|
21 |
ilm |
613 |
return VAR_ALREADY_EXIST;
|
18 |
ilm |
614 |
} else {
|
|
|
615 |
|
|
|
616 |
// Impossible de créer une variable du meme nom qu'un champ du salarie
|
21 |
ilm |
617 |
if (isForbidden(varName))
|
|
|
618 |
return VAR_ALREADY_EXIST;
|
18 |
ilm |
619 |
|
21 |
ilm |
620 |
this.textFormule.setVarAssign(varName);
|
|
|
621 |
return ValidState.getTrueInstance();
|
18 |
ilm |
622 |
}
|
|
|
623 |
}
|
|
|
624 |
|
|
|
625 |
private boolean isJavaVar(String s) {
|
|
|
626 |
if ((s.charAt(0) >= '0') && ((s.charAt(0) <= '9'))) {
|
|
|
627 |
System.err.println("Erreur la variable commence par un chiffre!!");
|
|
|
628 |
return false;
|
|
|
629 |
} else {
|
|
|
630 |
for (int i = 0; i < s.length(); i++) {
|
|
|
631 |
|
|
|
632 |
if (!(((s.charAt(i) >= '0') && (s.charAt(i) <= '9')) || (s.charAt(i) >= 'a') && (s.charAt(i) <= 'z') || (s.charAt(i) >= 'A') && (s.charAt(i) <= 'Z') || (s.charAt(i) == '_'))) {
|
|
|
633 |
System.err.println("Erreur la variable contient un caractere incorrect!!");
|
|
|
634 |
return false;
|
|
|
635 |
}
|
|
|
636 |
}
|
|
|
637 |
|
|
|
638 |
return (!CTokenMarker.getKeywords().isExisting(s));
|
|
|
639 |
}
|
|
|
640 |
}
|
|
|
641 |
|
|
|
642 |
@Override
|
|
|
643 |
public void select(SQLRowAccessor r) {
|
|
|
644 |
|
|
|
645 |
super.select(r);
|
|
|
646 |
// System.err.println("Select RowAccess -------> " + r.getID() + " For Object " +
|
|
|
647 |
// this.hashCode());
|
|
|
648 |
if (r != null) {
|
|
|
649 |
if (r.getString("FORMULE").trim().length() == 0) {
|
|
|
650 |
this.radioVal.setSelected(true);
|
|
|
651 |
setFormuleEnabled(false);
|
|
|
652 |
} else {
|
|
|
653 |
this.radioFormule.setSelected(true);
|
|
|
654 |
setFormuleEnabled(true);
|
|
|
655 |
}
|
|
|
656 |
|
|
|
657 |
this.textFormule.setVarAssign(r.getString("NOM"));
|
|
|
658 |
}
|
|
|
659 |
|
21 |
ilm |
660 |
this.updateValidVarName();
|
18 |
ilm |
661 |
}
|
|
|
662 |
};
|
|
|
663 |
}
|
|
|
664 |
|
|
|
665 |
@Override
|
132 |
ilm |
666 |
protected void archive(TreesOfSQLRows trees, boolean cutLinks) throws SQLException {
|
|
|
667 |
for (SQLRow row : trees.getRows()) {
|
|
|
668 |
secureArchiveVariable(row, cutLinks);
|
|
|
669 |
}
|
18 |
ilm |
670 |
}
|
|
|
671 |
|
|
|
672 |
// Archive la variable si elle n'est pas utilisé dans une formule
|
132 |
ilm |
673 |
private void secureArchiveVariable(SQLRow row, boolean cutLinks) throws SQLException {
|
18 |
ilm |
674 |
|
|
|
675 |
if (row != null) {
|
156 |
ilm |
676 |
// Test si la variable n'est pas utilisée dans une autre variable
|
|
|
677 |
SQLSelect selCheckVar = new SQLSelect();
|
|
|
678 |
selCheckVar.addSelect(getTable().getField("ID"));
|
|
|
679 |
final String patternMatching = "%" + row.getString("NOM") + "%";
|
|
|
680 |
selCheckVar.setWhere(new Where(getTable().getField("FORMULE"), "LIKE", patternMatching));
|
|
|
681 |
selCheckVar.andWhere(new Where(getTable().getField("ID"), "!=", row.getID()));
|
|
|
682 |
String reqCheckVar = selCheckVar.asString();
|
|
|
683 |
List<Object> l = getTable().getBase().getDataSource().executeA(reqCheckVar);
|
|
|
684 |
if (l.isEmpty()) {
|
|
|
685 |
l = checkVariableInRubrique(patternMatching, "RUBRIQUE_BRUT", Arrays.asList("BASE", "TAUX", "MONTANT"));
|
|
|
686 |
if (l.isEmpty()) {
|
|
|
687 |
l = checkVariableInRubrique(patternMatching, "RUBRIQUE_COTISATION", Arrays.asList("BASE", "TX_SAL", "TX_PAT"));
|
|
|
688 |
if (l.isEmpty()) {
|
|
|
689 |
l = checkVariableInRubrique(patternMatching, "RUBRIQUE_NET", Arrays.asList("BASE", "TAUX", "MONTANT"));
|
|
|
690 |
if (l.isEmpty()) {
|
|
|
691 |
super.archive(new TreesOfSQLRows(this, row), true);
|
|
|
692 |
} else {
|
|
|
693 |
JOptionPane.showMessageDialog(null, "Suppression impossible, cette variable est référencée dans une rubrique de net!");
|
|
|
694 |
}
|
18 |
ilm |
695 |
|
156 |
ilm |
696 |
} else {
|
|
|
697 |
JOptionPane.showMessageDialog(null, "Suppression impossible, cette variable est référencée dans une rubrique de cotisation!");
|
|
|
698 |
}
|
|
|
699 |
|
|
|
700 |
} else {
|
|
|
701 |
JOptionPane.showMessageDialog(null, "Suppression impossible, cette variable est référencée dans une rubrique de brut!");
|
|
|
702 |
}
|
18 |
ilm |
703 |
} else {
|
156 |
ilm |
704 |
JOptionPane.showMessageDialog(null, "Suppression impossible, cette variable est référencée par une autre.");
|
18 |
ilm |
705 |
}
|
|
|
706 |
|
|
|
707 |
} else {
|
132 |
ilm |
708 |
super.archive(new TreesOfSQLRows(this, row), true);
|
18 |
ilm |
709 |
}
|
|
|
710 |
}
|
57 |
ilm |
711 |
|
156 |
ilm |
712 |
private List checkVariableInRubrique(final String patternMatching, final String tableRub, List<String> fieldsToCheck) {
|
|
|
713 |
|
|
|
714 |
SQLSelect selBrut = new SQLSelect();
|
|
|
715 |
final SQLTable tableRubBrut = getTable().getDBRoot().findTable(tableRub);
|
|
|
716 |
selBrut.addSelect(tableRubBrut.getField("ID"));
|
|
|
717 |
for (String fieldToCheck : fieldsToCheck) {
|
|
|
718 |
selBrut.setWhere(new Where(tableRubBrut.getField(fieldToCheck), "LIKE", patternMatching));
|
|
|
719 |
}
|
|
|
720 |
|
|
|
721 |
String reqCheckBrut = selBrut.asString();
|
|
|
722 |
return getTable().getBase().getDataSource().executeA(reqCheckBrut);
|
|
|
723 |
|
|
|
724 |
}
|
|
|
725 |
|
57 |
ilm |
726 |
@Override
|
|
|
727 |
protected String createCode() {
|
|
|
728 |
return "humanresources.payroll.payment.variable";
|
|
|
729 |
}
|
18 |
ilm |
730 |
}
|