OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 18 | Rev 94 | 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.model;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.ui.SQLJavaEditor;
18
import org.openconcerto.erp.core.humanresources.payroll.element.PeriodeValiditeSQLElement;
19
import org.openconcerto.erp.core.humanresources.payroll.element.VariablePayeSQLElement;
73 ilm 20
import org.openconcerto.erp.preferences.PayeGlobalPreferencePanel;
18 ilm 21
import org.openconcerto.sql.Configuration;
22
import org.openconcerto.sql.model.SQLBase;
23
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.sql.model.SQLRowValues;
25
import org.openconcerto.sql.model.SQLSelect;
26
import org.openconcerto.sql.model.SQLTable;
27
import org.openconcerto.sql.model.Where;
73 ilm 28
import org.openconcerto.sql.preferences.SQLPreferences;
18 ilm 29
 
30
import java.sql.SQLException;
31
import java.util.Date;
32
import java.util.HashMap;
33
import java.util.List;
34
import java.util.Map;
35
import java.util.Vector;
36
 
37
import javax.swing.table.AbstractTableModel;
38
 
39
import org.apache.commons.dbutils.handlers.ArrayListHandler;
40
 
41
// TODO gestion de la place des rubriques dans l'ordre brut - cot - net et comm everywhere
42
// FIXME Thread pour le calcul
43
public class FichePayeModel extends AbstractTableModel {
44
 
45
    // Rubrique
46
    private Vector<SQLRowValues> vectRubrique;
47
    private Vector<SQLRowValues> vectRowValsToDelete;
48
 
49
    // table des rubriques
50
    private final Map<String, SQLTable> mapTableSource = new HashMap<String, SQLTable>();
51
 
52
    // Id de la fiche de paye concernee
53
    private int idFiche;
54
 
55
    private String[] title;
56
 
57
    private final static SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
58
    private final static SQLTable tableProfilElt = Configuration.getInstance().getBase().getTable("PROFIL_PAYE_ELEMENT");
59
    private final static SQLTable tableFichePayeElt = base.getTable("FICHE_PAYE_ELEMENT");
60
    private final static SQLTable tableFichePaye = base.getTable("FICHE_PAYE");
61
    private final static SQLTable tableValidite = Configuration.getInstance().getBase().getTable("PERIODE_VALIDITE");
62
 
63
    private SQLJavaEditor javaEdit = new SQLJavaEditor(VariablePayeSQLElement.getMapTree());
64
 
65
    // liste des variable de paye à calculer
66
    private float salBrut, cotPat, cotSal, netImp, netAPayer, csg;
67
    private Map<Integer, String> mapField;
68
 
73 ilm 69
    private final double tauxCSG;
70
 
18 ilm 71
    public FichePayeModel(int idFiche) {
72
 
73
        System.err.println("NEW FICHE PAYE MODEL");
74
 
75
        this.idFiche = idFiche;
76
        this.vectRubrique = new Vector<SQLRowValues>();
77
        this.vectRowValsToDelete = new Vector<SQLRowValues>();
78
 
79
        // Titres des colonnes
80
        this.title = new String[9];
81
        this.title[0] = "Libellé";
82
        this.title[1] = "Base";
83
        this.title[2] = "Taux sal.";
84
        this.title[3] = "Montant sal. à ajouter";
85
        this.title[4] = "Montant sal. à déduire";
86
        this.title[5] = "Taux pat.";
87
        this.title[6] = "Montant pat.";
88
        this.title[7] = "Impression";
89
        this.title[8] = "Dans la Période";
90
 
91
        SQLTable tableNet = Configuration.getInstance().getBase().getTable("RUBRIQUE_NET");
92
        SQLTable tableBrut = Configuration.getInstance().getBase().getTable("RUBRIQUE_BRUT");
93
        SQLTable tableCotis = Configuration.getInstance().getBase().getTable("RUBRIQUE_COTISATION");
94
        SQLTable tableComm = Configuration.getInstance().getBase().getTable("RUBRIQUE_COMM");
95
        this.mapTableSource.put(tableNet.getName(), tableNet);
96
        this.mapTableSource.put(tableBrut.getName(), tableBrut);
97
        this.mapTableSource.put(tableCotis.getName(), tableCotis);
98
        this.mapTableSource.put(tableComm.getName(), tableComm);
99
 
100
        this.mapField = new HashMap<Integer, String>();
101
        this.mapField.put(new Integer(0), "NOM");
102
        this.mapField.put(new Integer(1), "NB_BASE");
103
        this.mapField.put(new Integer(2), "TAUX_SAL");
104
        this.mapField.put(new Integer(3), "MONTANT_SAL_AJ");
105
        this.mapField.put(new Integer(4), "MONTANT_SAL_DED");
106
        this.mapField.put(new Integer(5), "TAUX_PAT");
107
        this.mapField.put(new Integer(6), "MONTANT_PAT");
108
        this.mapField.put(new Integer(7), "IMPRESSION");
109
        this.mapField.put(new Integer(8), "IN_PERIODE");
110
 
73 ilm 111
        SQLPreferences prefs = new SQLPreferences(tableFichePaye.getTable().getDBRoot());
112
        this.tauxCSG = prefs.getDouble(PayeGlobalPreferencePanel.ASSIETTE_CSG, 0.9825D);
113
 
18 ilm 114
        // loadElement();
115
        // methodeTmp();
116
    }
117
 
118
    private void resetValueFiche() {
119
 
120
        /*
121
         * if (this.threadUpdate != null && this.threadUpdate.isAlive()) { this.threadUpdate.stop();
122
         * }
123
         */
124
 
125
        this.salBrut = 0.0F;
126
        this.cotPat = 0.0F;
127
        this.cotSal = 0.0F;
128
        this.netAPayer = 0.0F;
129
        this.netImp = 0.0F;
130
        this.csg = 0.0F;
131
 
132
    }
133
 
134
    public void loadAllElements() {
135
 
136
        System.err.println("Start At " + new Date());
137
        if (this.idFiche <= 1) {
138
            System.err.println("Aucune fiche associée");
139
            return;
140
        }
141
 
142
        // RAZ
143
        resetValueFiche();
144
 
145
        /*
146
         * this.threadUpdate = new Thread("Update Fiche Paye") { public void run() {
147
         */
148
        this.vectRubrique = new Vector<SQLRowValues>();
149
 
150
        SQLRow rowFiche = tableFichePaye.getRow(this.idFiche);
151
 
152
        this.javaEdit.setSalarieID(rowFiche.getInt("ID_SALARIE"));
153
 
154
        // éléments de la fiche de paye
73 ilm 155
        SQLSelect selAllIDFicheElt = new SQLSelect();
18 ilm 156
 
157
        selAllIDFicheElt.addSelect(tableFichePayeElt.getField("ID"));
158
        selAllIDFicheElt.addSelect(tableFichePayeElt.getField("POSITION"));
159
        selAllIDFicheElt.setWhere(new Where(tableFichePayeElt.getField("ID_FICHE_PAYE"), "=", this.idFiche));
160
 
161
        selAllIDFicheElt.setDistinct(true);
162
 
163
        selAllIDFicheElt.addRawOrder("\"FICHE_PAYE_ELEMENT\".\"POSITION\"");
164
        String reqAllIDFichelElt = selAllIDFicheElt.asString();
165
 
166
        System.err.println("Request " + reqAllIDFichelElt);
167
 
168
        Object[] objIDFicheElt = ((List) base.getDataSource().execute(reqAllIDFichelElt, new ArrayListHandler())).toArray();
169
 
170
        System.err.println(objIDFicheElt.length + " elements to load");
171
 
172
        for (int i = 0; i < objIDFicheElt.length; i++) {
173
            SQLRow row = tableFichePayeElt.getRow(Integer.parseInt(((Object[]) objIDFicheElt[i])[0].toString()));
174
 
175
            String source = row.getString("SOURCE");
176
            int idSource = row.getInt("IDSOURCE");
177
 
178
            if (source.trim().length() != 0) {
179
 
180
                // System.err.println("Source != null");
181
 
182
                if (this.mapTableSource.get(source) != null) {
183
                    SQLRow rowSource = this.mapTableSource.get(source).getRow(idSource);
184
 
185
                    if (rowSource.getTable().getName().equalsIgnoreCase("RUBRIQUE_BRUT")) {
186
                        loadElementBrut(rowSource, row);
187
                    }
188
 
189
                    if (rowSource.getTable().getName().equalsIgnoreCase("RUBRIQUE_COTISATION")) {
190
                        loadElementCotisation(rowSource, row);
191
                    }
192
 
193
                    if (rowSource.getTable().getName().equalsIgnoreCase("RUBRIQUE_NET")) {
194
                        loadElementNet(rowSource, row);
195
                    }
196
 
197
                    if (rowSource.getTable().getName().equalsIgnoreCase("RUBRIQUE_COMM")) {
198
                        loadElementComm(rowSource, row);
199
                    }
200
 
201
                } else {
202
                    System.err.println("Table " + source + " non référencée");
203
                }
204
            }
205
        }
206
        System.err.println(this.vectRubrique.size() + " elements ADDed ");
207
 
208
        fireTableDataChanged();
209
        /*
210
         * } }; this.threadUpdate.start();
211
         */
212
 
213
        System.err.println("End At " + new Date());
214
    }
215
 
216
    public String getColumnName(int column) {
217
 
218
        return this.title[column];
219
    }
220
 
221
    public int getRowCount() {
222
 
223
        return this.vectRubrique.size();
224
    }
225
 
226
    public int getColumnCount() {
227
 
228
        return this.title.length;
229
    }
230
 
231
    public Object getValueAt(int rowIndex, int columnIndex) {
232
 
233
        SQLRowValues row = this.vectRubrique.get(rowIndex);
234
        Object o = null;
235
 
236
        if (row != null) {
237
            o = row.getObject(this.mapField.get(new Integer(columnIndex)).toString());
238
        }
239
 
240
        return o;
241
    }
242
 
243
    public Class<?> getColumnClass(int columnIndex) {
244
        Class<?> cl = tableFichePayeElt.getField(this.mapField.get(new Integer(columnIndex))).getType().getJavaType();
245
        return cl;
246
    }
247
 
248
    /*
249
     * public boolean isCellEditable(int rowIndex, int columnIndex) {
250
     *
251
     * if (columnIndex == 0) { return true; }
252
     *
253
     * SQLRowValues rowVals = (SQLRowValues) this.vectRubrique.get(rowIndex);
254
     *
255
     * Object ob = rowVals.getObject("SOURCE"); String source = (ob == null) ? "" : ob.toString();
256
     *
257
     * if ((source.trim().length() != 0) && (!source.equalsIgnoreCase("RUBRIQUE_COTISATION"))) {
258
     *
259
     * if (!source.equalsIgnoreCase("RUBRIQUE_COMM")) { if (columnIndex > 5) { return false; } else
260
     * {
261
     *
262
     * if (columnIndex == 1 || columnIndex == 2) { return true; }
263
     *
264
     * if (source.equalsIgnoreCase("RUBRIQUE_COT") && (columnIndex == 5)) {
265
     *
266
     * return true; } } } } return false; }
267
     *
268
     * public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
269
     *
270
     * System.err.println("_______***$$$$ " + this.mapField.get(new
271
     * Integer(columnIndex)).toString()); SQLRowValues rowVals = (SQLRowValues)
272
     * this.vectRubrique.get(rowIndex); rowVals.put(this.mapField.get(new
273
     * Integer(columnIndex)).toString(), aValue); rowVals.put("VALIDE", Boolean.TRUE);
274
     *
275
     * try { rowVals.update(); } catch (SQLException e) { e.printStackTrace(); }
276
     *
277
     * calculValue(); }
278
     */
279
    public boolean containValueAt(int rowIndex, int columnIndex) {
280
 
281
        if (columnIndex == 0) {
282
            return true;
283
        }
284
 
285
        SQLRowValues rowVals = this.vectRubrique.get(rowIndex);
286
 
287
        Object ob = rowVals.getObject("SOURCE");
288
        String source = (ob == null) ? "" : ob.toString();
289
 
290
        Object obId = rowVals.getObject("IDSOURCE");
291
        int idSource = (obId == null) ? 1 : rowVals.getInt("IDSOURCE");
292
 
293
        if ((source.trim().length() != 0) && (!source.equalsIgnoreCase("RUBRIQUE_COTISATION"))) {
294
            /*
295
             * if (source.equalsIgnoreCase("RUBRIQUE_COMM")) { return true; } else {
296
             */
297
 
298
            if (columnIndex > 4) {
299
                return false;
300
            } else {
301
                SQLRow row = this.mapTableSource.get(source).getRow(idSource);
302
                if (source.equalsIgnoreCase("RUBRIQUE_BRUT")) {
303
                    if ((row.getInt("ID_TYPE_RUBRIQUE_BRUT") == 2) && (columnIndex == 4)) {
304
                        return false;
305
                    }
306
                    if ((row.getInt("ID_TYPE_RUBRIQUE_BRUT") == 3) && (columnIndex == 3)) {
307
                        return false;
308
                    }
309
                } else {
310
                    if (source.equalsIgnoreCase("RUBRIQUE_NET")) {
311
                        if ((row.getInt("ID_TYPE_RUBRIQUE_NET") == 2) && (columnIndex == 4)) {
312
                            return false;
313
                        }
314
                        if ((row.getInt("ID_TYPE_RUBRIQUE_NET") == 3) && (columnIndex == 3)) {
315
                            return false;
316
                        }
317
                    } else {
318
                        return false;
319
                    }
320
                }
321
                // }
322
            }
323
        } else {
324
            if (columnIndex == 3) {
325
                return false;
326
            }
327
        }
328
 
329
        return true;
330
    }
331
 
332
    public void loadFromProfil(final int idProfil) {
333
 
334
        System.err.println("Load from profil");
335
 
336
        resetValueFiche();
337
 
338
        /*
339
         * this.threadUpdate = new Thread("Update Fiche Paye") { public void run() {
340
         */
341
        // On supprime les anciennes lignes de la fiche
342
        while (this.vectRubrique.size() > 0) {
343
 
344
            this.vectRowValsToDelete.add(this.vectRubrique.remove(0));
345
        }
346
 
347
        // this.vectRubrique = new Vector();
348
 
349
        // Listes des rubriques du profil
73 ilm 350
        SQLSelect selAllIDProfilElt = new SQLSelect();
18 ilm 351
 
352
        selAllIDProfilElt.addSelect(tableProfilElt.getField("ID"));
353
        selAllIDProfilElt.addSelect(tableProfilElt.getField("POSITION"));
354
        selAllIDProfilElt.setWhere(new Where(tableProfilElt.getField("ID_PROFIL_PAYE"), "=", idProfil));
355
        selAllIDProfilElt.addRawOrder("\"PROFIL_PAYE_ELEMENT\".\"POSITION\"");
356
 
357
        String reqAllIDProfilElt = selAllIDProfilElt.asString();
358
 
359
        Object[] objIDProfilElt = ((List) Configuration.getInstance().getBase().getDataSource().execute(reqAllIDProfilElt, new ArrayListHandler())).toArray();
360
 
361
        for (int i = 0; i < objIDProfilElt.length; i++) {
362
            SQLRow rowTmp = tableProfilElt.getRow(Integer.parseInt(((Object[]) objIDProfilElt[i])[0].toString()));
363
 
364
            String source = rowTmp.getString("SOURCE");
365
            int idSource = rowTmp.getInt("IDSOURCE");
366
 
367
            if (this.mapTableSource.get(source) != null) {
368
                SQLRow row = this.mapTableSource.get(source).getRow(idSource);
369
 
370
                if (row.getTable().getName().equalsIgnoreCase("RUBRIQUE_BRUT")) {
371
                    loadElementBrut(row, null);
372
                }
373
                if (row.getTable().getName().equalsIgnoreCase("RUBRIQUE_COTISATION")) {
374
                    loadElementCotisation(row, null);
375
                }
376
                if (row.getTable().getName().equalsIgnoreCase("RUBRIQUE_NET")) {
377
                    loadElementNet(row, null);
378
                }
379
                if (row.getTable().getName().equalsIgnoreCase("RUBRIQUE_COMM")) {
380
                    loadElementComm(row, null);
381
                }
382
 
383
            } else {
384
                System.err.println("FichePayeModel.java --> Table non référencée dans la Map. Table name : " + source);
385
            }
386
        }
387
 
388
        // this.vectRubrique = new Vector();
389
 
390
        // updateFields(this.idFiche);
391
        fireTableDataChanged();
392
 
393
        /*
394
         * } }; this.threadUpdate.start();
395
         */
396
    }
397
 
398
    public String getSourceAt(int rowIndex) {
399
        return this.vectRubrique.get(rowIndex).getString("SOURCE");
400
    }
401
 
402
    public int upRow(int rowIndex) {
403
        // On vérifie qu'il est possible de remonter la ligne
404
        if ((this.vectRubrique.size() > 1) && (rowIndex > 0)) {
405
            System.err.println("UP");
406
            SQLRowValues tmp = this.vectRubrique.get(rowIndex);
407
            this.vectRubrique.set(rowIndex, this.vectRubrique.get(rowIndex - 1));
408
            this.vectRubrique.set(rowIndex - 1, tmp);
409
            this.fireTableDataChanged();
410
            return rowIndex - 1;
411
        }
412
        System.err.println("can't up!!");
413
        return rowIndex;
414
    }
415
 
416
    public int downRow(int rowIndex) {
417
        // On vérifie qu'il est possible de descendre la ligne
418
        if ((rowIndex >= 0) && (this.vectRubrique.size() > 1) && (rowIndex + 1 < this.vectRubrique.size())) {
419
 
420
            System.err.println("DOWN");
421
            SQLRowValues tmp = this.vectRubrique.get(rowIndex);
422
            this.vectRubrique.set(rowIndex, this.vectRubrique.get(rowIndex + 1));
423
            this.vectRubrique.set(rowIndex + 1, tmp);
424
            this.fireTableDataChanged();
425
            return rowIndex + 1;
426
        }
427
 
428
        System.err.println("can't down!!!");
429
        return rowIndex;
430
    }
431
 
432
    public void setLastRowAT(int rowIndex) {
433
 
434
        // On vérifie qu'il est possible de descendre la ligne
435
        if ((rowIndex > 0) && (rowIndex < this.vectRubrique.size())) {
436
            this.vectRubrique.add(rowIndex, this.vectRubrique.remove(this.vectRubrique.size() - 1));
437
        }
438
        this.fireTableDataChanged();
439
    }
440
 
441
    public void setFicheID(int id) {
442
        this.idFiche = id;
443
 
444
        // this.javaEdit.setSalarieID(this.tableFichePaye.getRow(this.idFiche).getInt("ID_SALARIE"));
445
        this.loadAllElements();
446
    }
447
 
448
    /***********************************************************************************************
449
     * Ajouter une ligne
450
     *
451
     * @param row SQLRow RUBRIQUE_BRUT, RUBRIQUE_COTISATION, RUBRIQUE_NET, RUBRIQUE_COMM
452
     * @param index index ou doit etre insere la row
453
     */
454
    public void addRowAt(SQLRow row, int index) {
455
 
456
        int size = this.vectRubrique.size();
457
        if (row.getTable().getName().equalsIgnoreCase("RUBRIQUE_BRUT")) {
458
            this.loadElementBrut(row, null);
459
        } else {
460
            if (row.getTable().getName().equalsIgnoreCase("RUBRIQUE_COTISATION")) {
461
                this.loadElementCotisation(row, null);
462
            } else {
463
                if (row.getTable().getName().equalsIgnoreCase("RUBRIQUE_NET")) {
464
                    this.loadElementNet(row, null);
465
                } else {
466
                    if (row.getTable().getName().equalsIgnoreCase("RUBRIQUE_COMM")) {
467
                        this.loadElementComm(row, null);
468
                    }
469
                }
470
            }
471
        }
472
 
473
        if (size != this.vectRubrique.size()) {
474
            setLastRowAT(index);
475
        }
476
        if (!row.getTable().getName().equalsIgnoreCase("RUBRIQUE_COMM")) {
477
            calculValue();
478
        }
479
        this.fireTableDataChanged();
480
    }
481
 
482
    public void removeRow(int rowIndex) {
483
        // System.err.println("_________________________________REMOVE");
484
        if (rowIndex >= 0) {
485
 
486
            SQLRowValues rowVals = this.vectRubrique.remove(rowIndex);
487
            this.vectRowValsToDelete.add(rowVals);
488
 
489
            if (!rowVals.getString("SOURCE").equalsIgnoreCase("RUBRIQUE_COMM")) {
490
                calculValue();
491
            }
492
            this.fireTableDataChanged();
493
        }
494
    }
495
 
496
    public void updateFields(int idFiche) {
497
 
498
        // System.err.println("UPDATE FIELDS");
499
 
500
        for (int i = 0; i < this.vectRowValsToDelete.size(); i++) {
501
            SQLRowValues rowVals = this.vectRowValsToDelete.get(i);
502
 
503
            if (rowVals.getID() != SQLRow.NONEXISTANT_ID) {
504
 
505
                rowVals.put("ARCHIVE", 1);
506
                try {
507
                    rowVals.update();
508
                } catch (SQLException e) {
509
 
510
                    e.printStackTrace();
511
                }
512
            }
513
        }
514
 
515
        this.vectRowValsToDelete = new Vector<SQLRowValues>();
516
 
517
        for (int i = 0; i < this.vectRubrique.size(); i++) {
518
            SQLRowValues rowVals = this.vectRubrique.get(i);
519
            rowVals.put("ID_FICHE_PAYE", idFiche);
520
            rowVals.put("POSITION", i);
521
 
522
            try {
523
                rowVals.commit();
524
            } catch (SQLException e) {
525
 
526
                e.printStackTrace();
527
            }
528
        }
529
    }
530
 
531
    public void showData() {
532
 
533
        if (this.vectRubrique.size() == 0) {
534
            System.err.println("Vecteur contains no value.");
535
        }
536
        for (int i = 0; i < this.vectRubrique.size(); i++) {
537
            System.err.println(this.vectRubrique.get(i));
538
        }
539
    }
540
 
541
    public Object getVectorObjectAt(int index) {
542
        return this.vectRubrique.get(index);
543
    }
544
 
545
    private boolean isEltInPeriod(SQLRow rowSource) {
546
        SQLRow rowFiche = tableFichePaye.getRow(this.idFiche);
547
        int mois = rowFiche.getInt("ID_MOIS") - 1;
548
 
549
        Object ob = PeriodeValiditeSQLElement.mapTranslate().get(Integer.valueOf(mois));
550
 
551
        if (ob == null) {
552
            return false;
553
        }
554
        String moisName = ob.toString();
555
 
556
        SQLRow rowPeriodeValid = tableValidite.getRow(rowSource.getInt("ID_PERIODE_VALIDITE"));
557
 
558
        return (rowPeriodeValid.getBoolean(moisName));
559
    }
560
 
561
    private boolean isEltImprimable(SQLRow rowSource, SQLRowValues row) {
562
 
563
        int impression = rowSource.getInt("ID_IMPRESSION_RUBRIQUE");
564
 
565
        if (impression == 3) {
566
            return true;
567
        } else {
568
            if (impression == 4) {
569
                return false;
570
            } else {
571
                if (impression == 2) {
572
 
573
                    Object montantSalAjOb = row.getObject("MONTANT_SAL_AJ");
574
                    float montantSalAj = (montantSalAjOb == null) ? 0.0F : Float.valueOf(montantSalAjOb.toString()).floatValue();
575
 
576
                    Object montantSalDedOb = row.getObject("MONTANT_SAL_DED");
577
                    float montantSalDed = (montantSalDedOb == null) ? 0.0F : Float.valueOf(montantSalDedOb.toString()).floatValue();
578
 
579
                    Object montantPatOb = row.getObject("MONTANT_PAT");
580
                    float montantPat = (montantPatOb == null) ? 0.0F : Float.valueOf(montantPatOb.toString()).floatValue();
581
 
582
                    if (montantSalAj == 0 && montantSalDed == 0 && montantPat == 0) {
583
                        return false;
584
                    }
585
                    return true;
586
 
587
                }
588
            }
589
        }
590
        return true;
591
    }
592
 
593
    /**
594
     * charge un élément de la fiche dans rowVals, dont la rubrique source est rowSource et
595
     * l'élément row si l'élément existe déja
596
     *
597
     * @param rowVals
598
     * @param rowSource
599
     * @param row
600
     * @return true si on doit calculer les valeurs
601
     */
602
    private boolean loadElement(SQLRowValues rowVals, SQLRow rowSource, SQLRow row) {
603
 
604
        if (row != null) {
605
            rowVals.loadAbsolutelyAll(row);
606
        }
607
 
608
        // on vérifie que la rubrique s'applique pour le mois concerné
609
        // if (!isEltInPeriod(rowSource)) {
610
        // System.err.println("Not In periode");
611
        rowVals.put("IN_PERIODE", Boolean.valueOf(isEltInPeriod(rowSource)));
612
        // }
613
 
614
        rowVals.put("SOURCE", rowSource.getTable().getName());
615
        rowVals.put("IDSOURCE", rowSource.getID());
616
 
617
        Object ob = rowVals.getObject("VALIDE");
618
        boolean b = (ob == null) ? false : new Boolean(ob.toString()).booleanValue();
619
 
620
        return b;
621
    }
622
 
623
    private void updateValueFiche() {
624
 
625
        SQLRowValues rowValsFiche = new SQLRowValues(tableFichePaye);
626
        rowValsFiche.put("SAL_BRUT", Float.valueOf(this.salBrut));
627
        rowValsFiche.put("NET_IMP", Float.valueOf(this.netImp + this.salBrut));
628
        rowValsFiche.put("NET_A_PAYER", Float.valueOf(this.netAPayer + this.salBrut));
629
        rowValsFiche.put("COT_SAL", Float.valueOf(this.cotSal));
630
        rowValsFiche.put("COT_PAT", Float.valueOf(this.cotPat));
73 ilm 631
        rowValsFiche.put("CSG", Float.valueOf((this.salBrut + this.csg) * (float) this.tauxCSG));
18 ilm 632
 
633
        try {
634
            rowValsFiche.update(this.idFiche);
635
        } catch (SQLException e) {
636
            e.printStackTrace();
637
        }
638
    }
639
 
640
    /***********************************************************************************************
641
     * Charge un élément d'une rubrique de brut
642
     *
643
     * @param rowSource row de la rubrique source
644
     * @param row row de l'élément de la fiche
645
     **********************************************************************************************/
646
    private void loadElementBrut(SQLRow rowSource, SQLRow row) {
647
 
648
        // System.err.println("________________________LOAD ELT BRUT");
649
        SQLRowValues rowVals = new SQLRowValues(tableFichePayeElt);
650
 
651
        if (!loadElement(rowVals, rowSource, row)) {
652
 
653
            // System.err.println("________________________Recalcul des ELT BRUT ");
654
            Object baseOb = this.javaEdit.checkFormule(rowSource.getString("BASE"), "BASE");
655
            Object tauxSalOb = this.javaEdit.checkFormule(rowSource.getString("TAUX"), "TAUX");
656
            rowVals.put("NOM", rowSource.getString("NOM"));
657
 
658
            rowVals.put("NB_BASE", (baseOb == null) ? null : Float.valueOf(Math.round(Float.valueOf(baseOb.toString()).floatValue() * 100.0F) / 100.0F));
659
            rowVals.put("TAUX_SAL", (tauxSalOb == null) ? null : Float.valueOf(Float.valueOf(tauxSalOb.toString()).floatValue()));
660
        }
661
 
662
        calculBrut(rowSource, rowVals);
663
 
664
        boolean b = isEltImprimable(rowSource, rowVals);
665
        // System.err.println("Impression --- > " + b);
666
        rowVals.put("IMPRESSION", Boolean.valueOf(b));
667
 
668
        this.vectRubrique.add(rowVals);
669
    }
670
 
671
    /**
672
     * Calcul le montant d'une rubrique de brut et met à jour les variables du salarié
673
     *
674
     * @param rowSource
675
     * @param rowVals
676
     */
677
    private void calculBrut(SQLRow rowSource, SQLRowValues rowVals) {
678
 
679
        if (((Boolean) rowVals.getObject("IN_PERIODE")).booleanValue()) {
680
 
681
            Object baseOb = rowVals.getObject("NB_BASE");
682
            Object tauxSalOb = rowVals.getObject("TAUX_SAL");
683
 
684
            float base = 0.0F;
685
            if ((baseOb != null) && (baseOb.toString().trim().length() != 0)) {
686
                base = Float.valueOf(baseOb.toString()).floatValue();
687
            }
688
 
689
            float tauxSal = 0.0F;
690
            if ((tauxSalOb != null) && (tauxSalOb.toString().trim().length() != 0)) {
691
                tauxSal = Float.valueOf(tauxSalOb.toString()).floatValue();
692
            }
693
 
694
            // Calcul du montant
695
            String formuleMontant = rowSource.getString("MONTANT");
696
 
697
            float montant = 0.0F;
698
            if (formuleMontant.trim().length() == 0) {
699
                montant = Math.round(base * tauxSal * 100.0F) / 100.0F;
700
            } else {
701
                Object montantNet = this.javaEdit.checkFormule(rowSource.getString("MONTANT"), "MONTANT");
702
                String montantNetS = (montantNet == null) ? "0.0" : montantNet.toString();
703
                montant = Math.round(Float.valueOf(montantNetS).floatValue() * 100.0F) / 100.0F;
704
            }
705
 
706
            // Retenue
707
            if (rowSource.getInt("ID_TYPE_RUBRIQUE_BRUT") == 3) {
708
 
709
                rowVals.put("MONTANT_SAL_DED", Float.valueOf(montant));
710
                this.salBrut -= montant;
711
            }// Gain
712
            else {
713
 
714
                rowVals.put("MONTANT_SAL_AJ", Float.valueOf(montant));
715
                this.salBrut += montant;
716
            }
717
 
718
            // Mis a jour du salaire brut
719
            updateValueFiche();
720
        }
721
    }
722
 
723
    private void calculNet(SQLRow rowSource, SQLRowValues rowVals) {
724
 
725
        if (((Boolean) rowVals.getObject("IN_PERIODE")).booleanValue()) {
726
 
727
            Object baseOb = rowVals.getObject("NB_BASE");
728
            Object tauxSalOb = rowVals.getObject("TAUX_SAL");
729
 
730
            float base = 0.0F;
731
            if ((baseOb != null) && (baseOb.toString().trim().length() != 0)) {
732
                base = ((Float) baseOb).floatValue();
733
            }
734
 
735
            float tauxSal = 0.0F;
736
            if ((tauxSalOb != null) && (tauxSalOb.toString().trim().length() != 0)) {
737
                tauxSal = ((Float) tauxSalOb).floatValue();
738
            }
739
 
740
            // Calcul du montant
741
            String formuleMontant = rowSource.getString("MONTANT");
742
 
743
            float montant = 0.0F;
744
            if (formuleMontant.trim().length() == 0) {
745
                montant = Math.round(base * tauxSal * 100.0F) / 100.0F;
746
            } else {
747
                Object montantNet = this.javaEdit.checkFormule(rowSource.getString("MONTANT"), "MONTANT");
748
                if (montantNet != null) {
749
                    montant = Math.round(Float.valueOf(montantNet.toString()).floatValue() * 100.0F) / 100.0F;
750
                }
751
            }
752
 
753
            // Retenue
754
            if (rowSource.getInt("ID_TYPE_RUBRIQUE_NET") == 3) {
755
 
756
                rowVals.put("MONTANT_SAL_DED", Float.valueOf(montant));
757
 
758
                if (rowSource.getBoolean("IMPOSABLE")) {
759
                    this.netAPayer -= montant;
760
                } else {
761
                    this.netAPayer -= montant;
762
                    this.netImp -= montant;
763
                }
764
 
765
            }// Gain
766
            else {
767
 
768
                rowVals.put("MONTANT_SAL_AJ", Float.valueOf(montant));
769
 
770
                if (rowSource.getBoolean("IMPOSABLE")) {
771
                    this.netAPayer += montant;
772
 
773
                } else {
774
                    this.netAPayer += montant;
775
                    this.netImp += montant;
776
                }
777
            }
778
 
779
            // Mis a jour du salaire net
780
            updateValueFiche();
781
        }
782
    }
783
 
784
    private void loadElementNet(SQLRow rowSource, SQLRow row) {
785
        SQLRowValues rowVals = new SQLRowValues(tableFichePayeElt);
786
        // System.err.println("________________________LOAD ELT NET");
787
 
788
        if (!loadElement(rowVals, rowSource, row)) {
789
 
790
            Object baseOb = this.javaEdit.checkFormule(rowSource.getString("BASE"), "BASE");
791
            Object tauxSalOb = this.javaEdit.checkFormule(rowSource.getString("TAUX"), "TAUX");
792
            rowVals.put("NOM", rowSource.getString("NOM"));
793
            rowVals.put("NB_BASE", (baseOb == null) ? null : Float.valueOf(Math.round(Float.valueOf(baseOb.toString()).floatValue() * 100.0F) / 100.0F));
794
            rowVals.put("TAUX_SAL", (tauxSalOb == null) ? null : Float.valueOf(Float.valueOf(tauxSalOb.toString()).floatValue()));
795
        }
796
 
797
        calculNet(rowSource, rowVals);
798
 
799
        boolean b = isEltImprimable(rowSource, rowVals);
800
        // System.err.println("Impression --- > " + b);
801
        rowVals.put("IMPRESSION", Boolean.valueOf(b));
802
 
803
        this.vectRubrique.add(rowVals);
804
    }
805
 
806
    private void calculCotisation(SQLRow rowSource, SQLRowValues rowVals) {
807
 
808
        if (((Boolean) rowVals.getObject("IN_PERIODE")).booleanValue()) {
809
 
810
            Object baseOb = rowVals.getObject("NB_BASE");
811
            Object tauxSalOb = rowVals.getObject("TAUX_SAL");
812
            Object tauxPatOb = rowVals.getObject("TAUX_PAT");
813
 
814
            float base = 0.0F;
815
            if ((baseOb != null) && (baseOb.toString().trim().length() != 0)) {
816
                base = ((Number) baseOb).floatValue();
817
            }
818
 
819
            float tauxSal = 0.0F;
820
            if ((tauxSalOb != null) && (tauxSalOb.toString().trim().length() != 0)) {
821
                tauxSal = ((Number) tauxSalOb).floatValue() / 100.0F;
822
            }
823
 
824
            float tauxPat = 0.0F;
825
            if ((tauxPatOb != null) && (tauxPatOb.toString().trim().length() != 0)) {
826
                tauxPat = ((Number) tauxPatOb).floatValue() / 100.0F;
827
            }
828
 
829
            // Calcul du montant
830
            float montantSal = 0.0F;
831
            montantSal = Math.round(base * tauxSal * 100.0F) / 100.0F;
832
            float montantPat = 0.0F;
833
            montantPat = Math.round(base * tauxPat * 100.0F) / 100.0F;
834
 
835
            rowVals.put("MONTANT_SAL_DED", new Float(montantSal));
836
            rowVals.put("MONTANT_PAT", new Float(montantPat));
837
 
838
            if (rowSource.getBoolean("IMPOSABLE")) {
839
                this.netAPayer -= montantSal;
840
 
841
            } else {
842
                this.netAPayer -= montantSal;
843
                this.netImp -= montantSal;
844
            }
845
 
846
            if (rowSource.getBoolean("PART_CSG")) {
847
                this.csg += montantPat;
848
            }
849
 
850
            this.cotSal += montantSal;
851
            this.cotPat += montantPat;
852
 
853
            // Mis a jour des cotisations
854
            updateValueFiche();
855
        }
856
    }
857
 
858
    private void loadElementCotisation(SQLRow rowSource, SQLRow row) {
859
        SQLRowValues rowVals = new SQLRowValues(tableFichePayeElt);
860
        // System.err.println("________________________LOAD ELT COTISATION");
861
 
862
        if (!loadElement(rowVals, rowSource, row)) {
863
 
864
            // On calcule les valeurs
865
            Object baseOb = this.javaEdit.checkFormule(rowSource.getString("BASE"), "BASE");
866
            Object tauxSalOb = this.javaEdit.checkFormule(rowSource.getString("TX_SAL"), "TX_SAL");
867
            Object tauxPatOb = this.javaEdit.checkFormule(rowSource.getString("TX_PAT"), "TX_PAT");
868
            rowVals.put("NOM", rowSource.getString("NOM"));
869
            rowVals.put("NB_BASE", (baseOb == null) ? null : Float.valueOf(Math.round(Float.valueOf(baseOb.toString()).floatValue() * 100.0F) / 100.0F));
870
            rowVals.put("TAUX_SAL", (tauxSalOb == null) ? null : Float.valueOf(Float.valueOf(tauxSalOb.toString()).floatValue()));
871
            rowVals.put("TAUX_PAT", (tauxPatOb == null) ? null : Float.valueOf(Float.valueOf(tauxPatOb.toString()).floatValue()));
872
        }
873
 
874
        calculCotisation(rowSource, rowVals);
875
 
876
        boolean b = isEltImprimable(rowSource, rowVals);
877
        // System.err.println("Impression --- > " + b);
878
        rowVals.put("IMPRESSION", Boolean.valueOf(b));
879
 
880
        this.vectRubrique.add(rowVals);
881
    }
882
 
883
    public void loadElementComm(SQLRow rowSource, SQLRow row) {
884
        SQLRowValues rowVals = new SQLRowValues(tableFichePayeElt);
885
        // System.err.println("________________________LOAD ELT COMM");
886
 
887
        if (loadElement(rowVals, rowSource, row)) {
888
            this.vectRubrique.add(rowVals);
889
            return;
890
        }
891
 
892
        Object baseOb = this.javaEdit.checkFormule(rowSource.getString("NB_BASE"), "BASE");
893
        Object tauxSalOb = this.javaEdit.checkFormule(rowSource.getString("TAUX_SAL"), "SAL");
894
        Object tauxPatOb = this.javaEdit.checkFormule(rowSource.getString("TAUX_PAT"), "PAT");
895
        Object montantPatOb = this.javaEdit.checkFormule(rowSource.getString("MONTANT_PAT"), "MONTANT");
896
        Object montantAdOb = this.javaEdit.checkFormule(rowSource.getString("MONTANT_SAL_AJ"), "MONTANT");
897
        Object montantDedOb = this.javaEdit.checkFormule(rowSource.getString("MONTANT_SAL_DED"), "MONTANT");
898
        rowVals.put("NOM", rowSource.getBoolean("NOM_VISIBLE") ? rowSource.getString("NOM") : "");
899
        rowVals.put("NB_BASE", baseOb);
900
        rowVals.put("TAUX_SAL", tauxSalOb);
901
        rowVals.put("TAUX_PAT", tauxPatOb);
902
        rowVals.put("MONTANT_PAT", montantPatOb);
903
        rowVals.put("MONTANT_SAL_AJ", montantAdOb);
904
        rowVals.put("MONTANT_SAL_DED", montantDedOb);
905
 
906
        boolean b = isEltImprimable(rowSource, rowVals);
907
        // System.err.println("Impression --- > " + b);
908
        rowVals.put("IMPRESSION", Boolean.valueOf(b));
909
 
910
        this.vectRubrique.add(rowVals);
911
    }
912
 
913
    private void calculValue() {
914
 
915
        System.err.println("Start calculValue At " + new Date());
916
 
917
        resetValueFiche();
918
 
919
        /*
920
         * this.threadUpdate = new Thread("Update Fiche Paye") { public void run() {
921
         */
922
        Vector<SQLRowValues> vectTmp = new Vector<SQLRowValues>(this.vectRubrique);
923
 
924
        this.vectRubrique = new Vector<SQLRowValues>();
925
        for (int i = 0; i < vectTmp.size(); i++) {
926
 
927
            SQLRowValues rowVals = vectTmp.get(i);
928
            String source = rowVals.getString("SOURCE");
929
            int idSource = rowVals.getInt("IDSOURCE");
930
            SQLRow row = tableFichePayeElt.getRow(rowVals.getID());
931
 
932
            if (source.trim().length() != 0) {
933
 
934
                // System.err.println("Source != null");
935
 
936
                if (this.mapTableSource.get(source) != null) {
937
                    SQLRow rowSource = this.mapTableSource.get(source).getRow(idSource);
938
 
939
                    if (rowSource.getTable().getName().equalsIgnoreCase("RUBRIQUE_BRUT")) {
940
                        loadElementBrut(rowSource, row);
941
                    }
942
                    if (rowSource.getTable().getName().equalsIgnoreCase("RUBRIQUE_COTISATION")) {
943
                        loadElementCotisation(rowSource, row);
944
                    }
945
                    if (rowSource.getTable().getName().equalsIgnoreCase("RUBRIQUE_NET")) {
946
                        loadElementNet(rowSource, row);
947
                    }
948
                    if (rowSource.getTable().getName().equalsIgnoreCase("RUBRIQUE_COMM")) {
949
                        loadElementComm(rowSource, row);
950
                    }
951
                } else {
952
                    System.err.println("Table " + source + " non référencée");
953
                }
954
            }
955
        }
956
        System.err.println(this.vectRubrique.size() + " elements ADDed ");
957
 
958
        fireTableDataChanged();
959
        /*
960
         * } }; this.threadUpdate.start();
961
         */
962
 
963
        System.err.println("End calculValue At " + new Date());
964
    }
965
 
966
    public void validElt() {
967
 
968
        System.err.println("Validation des éléments de la fiche.");
969
        for (int i = 0; i < this.vectRubrique.size(); i++) {
970
            SQLRowValues rowVals = this.vectRubrique.get(i);
971
            rowVals.put("VALIDE", Boolean.valueOf(true));
972
 
973
            try {
974
                rowVals.commit();
975
            } catch (SQLException e) {
976
                e.printStackTrace();
977
            }
978
        }
979
        System.err.println("Validation terminée.");
980
    }
981
}