OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
25 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.employe.report;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.element.SQLElement;
19
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRowListRSH;
21
import org.openconcerto.sql.model.SQLSelect;
22
import org.openconcerto.sql.model.Where;
80 ilm 23
import org.openconcerto.utils.StringUtils;
25 ilm 24
 
25
import java.io.IOException;
26
import java.text.DateFormat;
41 ilm 27
import java.text.DecimalFormat;
28
import java.text.DecimalFormatSymbols;
25 ilm 29
import java.text.Normalizer;
30
import java.text.Normalizer.Form;
31
import java.text.SimpleDateFormat;
73 ilm 32
import java.util.Calendar;
25 ilm 33
import java.util.Date;
34
import java.util.List;
35
 
36
import javax.swing.JFrame;
37
import javax.swing.JOptionPane;
41 ilm 38
import javax.swing.SwingUtilities;
25 ilm 39
 
40
public class N4DSSalarie {
41
 
142 ilm 42
    private DateFormat format = new SimpleDateFormat("ddMMyyyy");
25 ilm 43
    private ComptaPropsConfiguration conf = ((ComptaPropsConfiguration) Configuration.getInstance());
44
    private N4DS n4ds;
45
 
156 ilm 46
    Date d = new Date(117, 0, 1);
47
    Date d2 = new Date(117, 11, 31);
73 ilm 48
 
41 ilm 49
    DecimalFormat decimalFormat = new DecimalFormat("0.00");
50
 
25 ilm 51
    // FIXME Salarie renvoye
52
 
53
    public N4DSSalarie(N4DS n4ds) {
54
        this.n4ds = n4ds;
41 ilm 55
        DecimalFormatSymbols symbol = new DecimalFormatSymbols();
56
        symbol.setDecimalSeparator('.');
57
        decimalFormat.setDecimalFormatSymbols(symbol);
25 ilm 58
    }
59
 
60
    public void write(SQLRow row, SQLRow rowSociete) throws IOException {
61
        writeS30(row);
62
        writeS41(row, rowSociete);
63
        writeS44(row);
73 ilm 64
        writeS45(row);
41 ilm 65
        writeS48(row);
156 ilm 66
        //writeS65(row);
25 ilm 67
    }
68
 
73 ilm 69
    private void writeS45(final SQLRow rowSalarie) throws IOException {
41 ilm 70
        // // FIXME
71
        // n4ds.write("S44.G01.00.001", "07");
72
        // n4ds.write("S44.G01.00.002", "1100");
73
 
73 ilm 74
        // FIXME Régimes complémentaires
41 ilm 75
 
76
        SQLRow rowInfos = rowSalarie.getForeignRow("ID_INFOS_SALARIE_PAYE");
73 ilm 77
        SQLRow rowEtatCivil = rowSalarie.getForeignRow("ID_ETAT_CIVIL");
78
        SQLRow siutationFam = rowEtatCivil.getForeign("ID_SITUATION_FAMILIALE");
79
 
80
        // Date arrivée dans l'entreprise
81
        final Calendar dateArrivee = rowInfos.getDate("DATE_ARRIVE");
82
        n4ds.write("S45.G01.00.001.001", dateFormat.format(dateArrivee.getTime()));
83
 
84
        // Code situation familiale
142 ilm 85
        n4ds.write("S45.G01.00.002", "0" + (siutationFam.getID() - 1));
73 ilm 86
 
87
        // Nombre d'enfant à charge
88
        n4ds.write("S45.G01.00.006", rowEtatCivil.getString("NB_ENFANTS"));
89
 
90
        // Ancienneté dans l'entreprise
91
        n4ds.write("S45.G01.05.001.001", "01");
92
        // Code unité mensuelle
93
        n4ds.write("S45.G01.05.001.002", "02");
94
        // Ancienneté
95
        int monthArrive = dateArrivee.get(Calendar.MONTH);
96
        int yearArrive = dateArrivee.get(Calendar.YEAR);
97
        int month = this.d2.getMonth();
98
        int year = this.d2.getYear() + 1900;
99
        int diff;
100
        if (month > monthArrive) {
101
            diff = (year - yearArrive) * 12 + month - monthArrive;
102
        } else {
103
            diff = (year - yearArrive - 1) * 12 + (month) + (12 - monthArrive);
104
        }
105
        n4ds.write("S45.G01.05.002", String.valueOf(diff));
106
 
41 ilm 107
        SQLRow rowContrat = rowInfos.getForeignRow("ID_CONTRAT_SALARIE");
108
        if (rowContrat.getString("CODE_IRC_RETRAITE") != null && rowContrat.getString("CODE_IRC_RETRAITE").trim().length() > 0) {
109
            // Mederic "G022"
73 ilm 110
            n4ds.write("S45.G05.00.001", rowContrat.getString("NUMERO_RATTACHEMENT_RETRAITE"));
41 ilm 111
            // 200339139001002
73 ilm 112
            n4ds.write("S45.G05.00.005", rowContrat.getString("CODE_IRC_RETRAITE"));
41 ilm 113
        }
114
 
73 ilm 115
        // Période
116
        n4ds.write("S45.G05.10.001", dateFormat.format(d));
117
        // Code unité mensuelle
118
        n4ds.write("S45.G05.10.002", dateFormat.format(d2));
119
 
120
        // Base brute
121
        final double baseBrute = getBaseBrute(rowSalarie);
122
        n4ds.write("S45.G05.15.001.001", decimalFormat.format(baseBrute));
123
        n4ds.write("S45.G05.15.002.001", decimalFormat.format(baseBrute));
124
        // FIXME Tranche
125
        n4ds.write("S45.G05.15.003.001", "0.00");
126
        n4ds.write("S45.G05.15.004.001", "0.00");
127
        n4ds.write("S45.G05.15.005.001", "0.00");
128
        n4ds.write("S45.G05.15.006.001", "0.00");
129
        n4ds.write("S45.G05.15.007.001", "0.00");
130
        n4ds.write("S45.G05.15.008.001", "0.00");
131
        n4ds.write("S45.G05.15.009.001", decimalFormat.format(baseBrute * 0.016));
132
 
133
    }
134
 
135
    private void writeS44(final SQLRow rowSalarie) throws IOException {
136
        // // FIXME
137
        // n4ds.write("S44.G01.00.001", "07");
138
        // n4ds.write("S44.G01.00.002", "1100");
139
 
140
        n4ds.write("S44.G03.00.001", "90");
141
 
142
        // FIXME Régimes complémentaires
143
        SQLRow rowInfos = rowSalarie.getForeignRow("ID_INFOS_SALARIE_PAYE");
144
        SQLRow rowContrat = rowInfos.getForeignRow("ID_CONTRAT_SALARIE");
145
 
41 ilm 146
        // UGRR
147
        if (rowContrat.getString("CODE_IRC_UGRR") != null && rowContrat.getString("CODE_IRC_UGRR").trim().length() > 0 && rowContrat.getString("NUMERO_RATTACHEMENT_UGRR") != null
148
                && rowContrat.getString("NUMERO_RATTACHEMENT_UGRR").trim().length() > 0) {
149
            // "A700"
150
            n4ds.write("S44.G03.05.001", rowContrat.getString("CODE_IRC_UGRR"));
151
            // 800943487
152
            n4ds.write("S44.G03.05.002", rowContrat.getString("NUMERO_RATTACHEMENT_UGRR"));
153
        } else {
154
            SwingUtilities.invokeLater(new Runnable() {
155
 
156
                @Override
157
                public void run() {
158
                    JOptionPane.showMessageDialog(null, "Attention les informations de rattachement à l'UGRR ne sont pas définies pour le salarié " + rowSalarie.getString("NOM"));
159
                }
160
            });
161
        }
162
 
163
        // UGRC
164
        if (rowContrat.getString("CODE_IRC_UGRC") != null && rowContrat.getString("CODE_IRC_UGRC").trim().length() > 0 && rowContrat.getString("NUMERO_RATTACHEMENT_UGRC") != null
165
                && rowContrat.getString("NUMERO_RATTACHEMENT_UGRC").trim().length() > 0) {
166
            // "C039"
167
            n4ds.write("S44.G03.05.001", rowContrat.getString("CODE_IRC_UGRC"));
168
            // "00095913"
169
            n4ds.write("S44.G03.05.002", rowContrat.getString("NUMERO_RATTACHEMENT_UGRC"));
170
        } else {
171
            SwingUtilities.invokeLater(new Runnable() {
172
 
173
                @Override
174
                public void run() {
175
                    JOptionPane.showMessageDialog(null, "Attention les informations de rattachement à l'UGRC ne sont pas définies pour le salarié " + rowSalarie.getString("NOM"));
176
                }
177
            });
178
        }
179
 
180
    }
181
 
182
    private void writeS48(SQLRow rowSalarie) throws IOException {
183
        // Assurance chômage
142 ilm 184
 
41 ilm 185
        n4ds.write("S48.G10.00.015", "01");
186
        n4ds.write("S48.G10.00.016", "90");
187
        n4ds.write("S48.G10.00.017", "01");
188
        final double baseBrute = getBaseBrute(rowSalarie);
189
        n4ds.write("S48.G10.00.018", decimalFormat.format(baseBrute));
73 ilm 190
        // Remove since N4DS v01x07
191
        // n4ds.write("S48.G10.00.019", decimalFormat.format(baseBrute));
41 ilm 192
 
193
    }
194
 
195
    private void writeS65(SQLRow rowSalarie) throws IOException {
196
 
197
        // Section prudhomme
198
        n4ds.write("S65.G40.05.009", "01");
25 ilm 199
        // FIXME
41 ilm 200
        n4ds.write("S65.G40.05.010", "05");
25 ilm 201
 
41 ilm 202
        // FIXME durée annuelle = 1200heures
142 ilm 203
        // n4ds.write("S65.G40.10.023.001", "01");
204
        // n4ds.write("S65.G40.10.023.002", "98");
205
        // n4ds.write("S65.G40.10.023.003", "98");
206
        // if (rowSalarie.getString("PRENOM").equalsIgnoreCase("Vincent")) {
207
        // n4ds.write("S65.G40.10.023.004", "12");
208
        // } else {
209
        // n4ds.write("S65.G40.10.023.004", "03");
210
        // }
211
        // n4ds.write("S65.G40.10.023.005", "98");
41 ilm 212
 
25 ilm 213
    }
214
 
73 ilm 215
    DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy");
216
 
25 ilm 217
    private void writeS41(SQLRow rowSalarie, SQLRow rowSociete) throws IOException {
218
 
219
        // FIXME Debut periode
73 ilm 220
        n4ds.write("S40.G01.00.001", dateFormat.format(d));
25 ilm 221
        // FIXME embauche, etc...
222
        n4ds.write("S40.G01.00.002.001", "097");
223
 
224
        // FIXME Fin periode
73 ilm 225
        n4ds.write("S40.G01.00.003", dateFormat.format(d2));
25 ilm 226
        // FIXME licenciement, etc...
227
        n4ds.write("S40.G01.00.004.001", "098");
228
 
229
        // Nic de l'établissment du d'affectation du salarié
90 ilm 230
        final String siret = rowSociete.getString("NUM_SIRET").replaceAll(" ", "");
231
        String siren = StringUtils.limitLength(siret, 9);
232
        String nic = siret.substring(siren.length(), siret.length());
25 ilm 233
        n4ds.write("S40.G01.00.005", nic);
234
 
235
        /**
236
         * Situation administrative générale du salarié ou de l'agent. S40.G10.00
237
         */
238
 
239
        // TODO: ajouter les codes emplois pour le public, etc...
240
        n4ds.write("S40.G10.00.005", "10");
241
 
242
        // TODO Code Employeur multiple
243
        // Ici forcé en employeur unique
244
        n4ds.write("S40.G10.00.008.001", "01");
245
 
246
        // TODO Code Emploi multiple
247
        // Ici forcé en emploi unique
248
        n4ds.write("S40.G10.00.008.002", "01");
249
 
250
        // TODO Code decalage paie
251
        // Ici, sans décalage de paie
252
        n4ds.write("S40.G10.00.009.001", "01");
253
        // Ici, paiement au mois
41 ilm 254
        n4ds.write("S40.G10.00.009.002", "16");
25 ilm 255
 
256
        SQLRow rowInfos = rowSalarie.getForeignRow("ID_INFOS_SALARIE_PAYE");
257
        SQLRow rowContrat = rowInfos.getForeignRow("ID_CONTRAT_SALARIE");
258
 
259
        // Nature de l'emploi
142 ilm 260
        n4ds.write("S40.G10.00.010", normalizeString2(rowContrat.getString("NATURE")));
25 ilm 261
 
262
        // Catégorie socio
263
        SQLRow rowCodeEmploi = rowContrat.getForeignRow("ID_CODE_EMPLOI");
264
        n4ds.write("S40.G10.05.011.001", rowCodeEmploi.getString("CODE"));
265
 
266
        // code contrat
267
        SQLRow rowCodeContrat = rowContrat.getForeignRow("ID_CODE_CONTRAT_TRAVAIL");
268
        n4ds.write("S40.G10.05.012.001", rowCodeContrat.getString("CODE"));
269
 
270
        // code droit contrat
156 ilm 271
        // SQLRow rowCodeDroitContrat = rowContrat.getForeignRow("ID_CODE_DROIT_CONTRAT");
272
        // n4ds.write("S40.G10.05.012.002", rowCodeDroitContrat.getString("CODE"));
25 ilm 273
 
41 ilm 274
        // Code intitulé du contrat de travail
275
        n4ds.write("S40.G10.05.012.003", "90");
25 ilm 276
 
41 ilm 277
        // FIXME code modalité d'activité
73 ilm 278
        n4ds.write("S40.G10.05.013.004", "90");
25 ilm 279
 
280
        // FIXME code statut cat convention
41 ilm 281
        // SQLRow rowStatutCat = rowContrat.getForeignRow("ID_CODE_STATUT_CATEGORIEL");
282
        SQLRow rowCodeStatutConv = rowContrat.getForeignRow("ID_CODE_STATUT_CAT_CONV");
283
        n4ds.write("S40.G10.05.015.001", rowCodeStatutConv.getString("CODE"));
25 ilm 284
 
285
        // Code statut cat agirc arrco
73 ilm 286
        SQLRow rowStatutCat = rowContrat.getForeignRow("ID_CODE_STATUT_CATEGORIEL");
25 ilm 287
        n4ds.write("S40.G10.05.015.002", rowStatutCat.getString("CODE"));
288
 
289
        // Convention collective IDCC
290
        SQLRow rowIDCC = rowInfos.getForeignRow("ID_IDCC");
142 ilm 291
        String idcc = rowIDCC.getString("CODE").trim();
292
        if (idcc.length() <= 3) {
293
            for (int c = 0; c < 4 - idcc.length(); c++) {
294
                idcc = "0" + idcc;
295
            }
296
        }
297
        n4ds.write("S40.G10.05.016", idcc);
25 ilm 298
        // FIXME Classement conventionnel
299
        n4ds.write("S40.G10.05.017", "sans classement conventionnel");
300
 
301
        /**
302
         * Caisse spécifique de congés payés. S40.G10.06
303
         */
304
 
305
        //
306
 
307
        /**
308
         * Complément salarié sous contrat de droit privé dans le secteur public. S40.G10.08
309
         */
310
        // TODO secteur public
311
 
312
        /**
313
         * Situation administrative spécifique de l'agent sous statut d'emploi de droit public.
314
         * S40.G10.10
315
         */
316
        // TODO secteur public
317
 
318
        /**
319
         * Emploi supérieur antérieur de l'agent sous statut personnel de droit public. S40.G10.15
142 ilm 320
         */
25 ilm 321
        // TODO secteur public
322
 
323
        /**
324
         * Départ ou retour de détachement de l'agent sous statut personnel de droit public.
325
         * S40.G10.24
326
         */
327
        // TODO secteur public
328
 
329
        // FIXME Code regime de base obligatoire
330
        // n4ds.write("S41.G01.00.018.001", "200");
331
 
332
        // TODO rubrique conditionnelle
333
 
334
        // if (prenom.equalsIgnoreCase("guillaume")) {
335
        // // FIXME Durée anuelle du travail
336
        // n4ds.write( "S41.G01.00.023.001", "99");
337
        //
338
        // // FIXME Durée trimestrielle du travail
339
        // n4ds.write( "S41.G01.00.023.002", "12");
340
        //
341
        // // FIXME Durée mensuelle du travail
342
        // n4ds.write( "S41.G01.00.023.003", "98");
343
        // } else {
344
 
345
        // FIXME Code unité d'expression du temps de travail
346
        n4ds.write("S40.G15.00.001", "10");
347
 
41 ilm 348
        // FIXME Temps de travail
349
        double tempsTravail = 1820.00;
142 ilm 350
 
41 ilm 351
        n4ds.write("S40.G15.00.003", decimalFormat.format(tempsTravail));
352
        n4ds.write("S40.G15.00.022.001", decimalFormat.format(tempsTravail));
353
        n4ds.write("S40.G15.00.022.002", decimalFormat.format(tempsTravail));
354
 
355
        n4ds.write("S40.G15.05.013.001", "10");
356
        n4ds.write("S40.G15.05.025.001", "10");
357
        n4ds.write("S40.G15.05.025.002", decimalFormat.format(tempsTravail));
358
        n4ds.write("S40.G15.05.025.003", decimalFormat.format(tempsTravail));
359
 
360
        // Code régime obligatoire maladie
361
        n4ds.write("S40.G20.00.018.002", "200");
362
        // Code régime obligatoire AT
363
        n4ds.write("S40.G20.00.018.003", "200");
364
        // Code régime obligatoire vieillesse
365
        n4ds.write("S40.G20.00.018.004", "200");
366
 
73 ilm 367
        // Code section accident travail
368
        n4ds.write("S40.G25.00.025", rowInfos.getString("CODE_SECTION_AT"));
25 ilm 369
 
73 ilm 370
        // Code risque accident travail
371
        n4ds.write("S40.G25.00.026", rowInfos.getString("CODE_AT"));
25 ilm 372
 
373
        // TODO Code bureau
374
        // n4ds.write( "S41.G01.00.027", "B");
375
 
376
        // Taux accident travail
377
        float f = rowInfos.getFloat("TAUX_AT");
378
 
41 ilm 379
        n4ds.write("S40.G25.00.028", decimalFormat.format(f));
380
        n4ds.write("S40.G25.00.029", decimalFormat.format(tempsTravail));
381
 
25 ilm 382
        // Base brute
41 ilm 383
        final double baseBrute = getBaseBrute(rowSalarie);
384
        n4ds.write("S40.G28.05.029.001", decimalFormat.format(baseBrute));
25 ilm 385
        n4ds.addMasseSalarialeBrute(baseBrute);
386
 
387
        // Code nature cotisations
41 ilm 388
        n4ds.write("S40.G28.05.029.003", "01");
389
        n4ds.write("S40.G28.05.029.004", "0");
25 ilm 390
 
391
        // FIXME Base brute limité plafond
41 ilm 392
        n4ds.write("S40.G28.05.030.001", decimalFormat.format(baseBrute));
25 ilm 393
 
394
        // CSG
41 ilm 395
        n4ds.write("S40.G30.04.001", decimalFormat.format(getCSG(rowSalarie)));
25 ilm 396
 
41 ilm 397
        // FIXME CRDS ...
398
        n4ds.write("S40.G30.04.002", decimalFormat.format(getCSG(rowSalarie)));
25 ilm 399
 
80 ilm 400
        // final double baseBrute = getBaseBrute(rowSalarie);
142 ilm 401
        final double smicMensuel = 9.61;
90 ilm 402
        if ((baseBrute) < (2.5 * smicMensuel * 12 * 151.6667)) {
80 ilm 403
 
142 ilm 404
            n4ds.write("S40.G30.40.001", String.valueOf("17490.00"));
80 ilm 405
            n4ds.write("S40.G30.40.002", decimalFormat.format(baseBrute));
406
        }
142 ilm 407
 
90 ilm 408
        if ((baseBrute / 12.0 / 151.6667) < (1.6 * smicMensuel)) {
142 ilm 409
            double COEFF_FILLON = (0.2795 / 0.6) * ((1.6 * 17490.0 / (rowSalarie.getForeign("ID_INFOS_SALARIE_PAYE").getFloat("SALAIRE_MOIS") * 12.0)) - 1.0);
80 ilm 410
            n4ds.write("S40.G30.40.003", decimalFormat.format(baseBrute * COEFF_FILLON));
411
        } else {
412
            n4ds.write("S40.G30.40.003", String.valueOf("0.00"));
413
        }
414
 
142 ilm 415
        // n4ds.write("S40.G30.40.004", String.valueOf("0.00"));
416
        if ((baseBrute) < (2.5 * 17490.0)) {
417
            n4ds.write("S40.G30.40.005", String.valueOf("17490.00"));
90 ilm 418
            n4ds.write("S40.G30.40.006", decimalFormat.format(baseBrute));
142 ilm 419
        } else {
420
            n4ds.write("S40.G30.40.005", String.valueOf("0.00"));
421
            n4ds.write("S40.G30.40.006", String.valueOf("0.00"));
90 ilm 422
        }
80 ilm 423
 
25 ilm 424
        // FIXME base brute fiscale
41 ilm 425
        n4ds.write("S40.G40.00.035.001", decimalFormat.format(baseBrute));
25 ilm 426
 
41 ilm 427
        // revenu d'activite net
428
        n4ds.write("S40.G40.00.063.001", decimalFormat.format(getNetImp(rowSalarie)));
25 ilm 429
 
41 ilm 430
        // Fillon
431
        // if (rowSalarie.getString("PRENOM").equalsIgnoreCase("ludovic") ||
432
        // rowSalarie.getString("PRENOM").equalsIgnoreCase("guillaume")) {
433
        // // S41.G01.06.001 Code type exonération O X ..6
434
        // n4ds.write("S41.G01.06.001", "33");
435
        // // X S41.G01.06.002.001 Base brute soumise à exonération O N ..10
436
        // n4ds.write("S41.G01.06.002.001", String.valueOf(baseBrute));
437
        // }
438
 
439
        double fraisPro = getFraisProfessionels(rowSalarie);
440
 
25 ilm 441
        if (fraisPro > 0) {
442
            // remboursement frais pro
41 ilm 443
            n4ds.write("S40.G40.10.043", "02");
25 ilm 444
 
41 ilm 445
            // Montant des frais professionnels
446
            n4ds.write("S40.G40.10.044.001", decimalFormat.format(fraisPro));
25 ilm 447
 
448
        }
449
 
450
    }
451
 
41 ilm 452
    private double getFraisProfessionels(SQLRow rowSalarie) {
25 ilm 453
 
454
        SQLElement eltFichePaye = this.conf.getDirectory().getElement("FICHE_PAYE");
455
        SQLElement eltFichePayeElement = this.conf.getDirectory().getElement("FICHE_PAYE_ELEMENT");
456
        SQLElement eltRubriqueNet = this.conf.getDirectory().getElement("RUBRIQUE_NET");
457
        SQLSelect sel = new SQLSelect(rowSalarie.getTable().getBase());
458
        sel.addSelect(eltFichePayeElement.getTable().getKey());
459
        Where w = new Where(eltFichePaye.getTable().getField("DU"), d, d2);
460
        w = w.and(new Where(eltFichePaye.getTable().getField("VALIDE"), "=", Boolean.TRUE));
461
        w = w.and(new Where(eltFichePaye.getTable().getField("ID_SALARIE"), "=", rowSalarie.getID()));
462
        w = w.and(new Where(eltFichePayeElement.getTable().getField("ID_FICHE_PAYE"), "=", eltFichePaye.getTable().getKey()));
463
        w = w.and(new Where(eltFichePayeElement.getTable().getField("SOURCE"), "=", "RUBRIQUE_NET"));
464
 
465
        sel.setWhere(w);
466
        System.err.println(sel.asString());
467
        List<SQLRow> l = (List<SQLRow>) this.conf.getBase().getDataSource().execute(sel.asString(), new SQLRowListRSH(eltFichePayeElement.getTable()));
468
 
41 ilm 469
        double fraisPro = 0;
25 ilm 470
        for (SQLRow row : l) {
471
            int id = row.getInt("IDSOURCE");
472
            if (id > 1) {
473
                SQLRow rowRubrique = eltRubriqueNet.getTable().getRow(id);
474
                if (rowRubrique.getBoolean("FRAIS_PERS")) {
475
                    fraisPro += row.getFloat("MONTANT_SAL_AJ");
476
                }
477
            }
478
        }
479
 
41 ilm 480
        return fraisPro;
25 ilm 481
    }
482
 
41 ilm 483
    private double getBaseBrute(SQLRow rowSalarie) {
25 ilm 484
 
485
        SQLElement eltFichePaye = this.conf.getDirectory().getElement("FICHE_PAYE");
73 ilm 486
        SQLSelect sel = new SQLSelect();
25 ilm 487
        sel.addSelect(eltFichePaye.getTable().getKey());
488
        Where w = new Where(eltFichePaye.getTable().getField("DU"), d, d2);
489
        w = w.and(new Where(eltFichePaye.getTable().getField("VALIDE"), "=", Boolean.TRUE));
490
        w = w.and(new Where(eltFichePaye.getTable().getField("ID_SALARIE"), "=", rowSalarie.getID()));
491
 
492
        sel.setWhere(w);
493
        System.err.println(sel.asString());
494
        List<SQLRow> l = (List<SQLRow>) this.conf.getBase().getDataSource().execute(sel.asString(), new SQLRowListRSH(eltFichePaye.getTable()));
495
 
41 ilm 496
        double brut = 0;
25 ilm 497
        for (SQLRow row : l) {
498
            brut += row.getFloat("SAL_BRUT");
499
        }
500
 
41 ilm 501
        return brut;
25 ilm 502
    }
503
 
41 ilm 504
    private double getNetImp(SQLRow rowSalarie) {
25 ilm 505
 
506
        SQLElement eltFichePaye = this.conf.getDirectory().getElement("FICHE_PAYE");
73 ilm 507
        SQLSelect sel = new SQLSelect();
25 ilm 508
        sel.addSelect(eltFichePaye.getTable().getKey());
73 ilm 509
 
25 ilm 510
        Where w = new Where(eltFichePaye.getTable().getField("DU"), d, d2);
511
        w = w.and(new Where(eltFichePaye.getTable().getField("VALIDE"), "=", Boolean.TRUE));
512
        w = w.and(new Where(eltFichePaye.getTable().getField("ID_SALARIE"), "=", rowSalarie.getID()));
513
 
514
        sel.setWhere(w);
515
        List<SQLRow> l = (List<SQLRow>) this.conf.getBase().getDataSource().execute(sel.asString(), new SQLRowListRSH(eltFichePaye.getTable()));
516
 
41 ilm 517
        double brut = 0;
25 ilm 518
        for (SQLRow row : l) {
519
            brut += row.getFloat("NET_IMP");
520
        }
521
 
41 ilm 522
        return brut;
25 ilm 523
    }
524
 
41 ilm 525
    private double getCSG(SQLRow rowSalarie) {
25 ilm 526
 
527
        SQLElement eltFichePaye = this.conf.getDirectory().getElement("FICHE_PAYE");
73 ilm 528
        SQLSelect sel = new SQLSelect();
25 ilm 529
        sel.addSelect(eltFichePaye.getTable().getKey());
73 ilm 530
 
25 ilm 531
        Where w = new Where(eltFichePaye.getTable().getField("DU"), d, d2);
532
        w = w.and(new Where(eltFichePaye.getTable().getField("VALIDE"), "=", Boolean.TRUE));
533
        w = w.and(new Where(eltFichePaye.getTable().getField("ID_SALARIE"), "=", rowSalarie.getID()));
534
 
535
        sel.setWhere(w);
536
        List<SQLRow> l = (List<SQLRow>) this.conf.getBase().getDataSource().execute(sel.asString(), new SQLRowListRSH(eltFichePaye.getTable()));
537
 
41 ilm 538
        double brut = 0;
25 ilm 539
        for (SQLRow row : l) {
540
            brut += row.getFloat("CSG");
541
        }
542
 
41 ilm 543
        return brut;
25 ilm 544
    }
545
 
546
    private void writeS30(SQLRow rowSalarie) throws IOException {
547
 
548
        SQLRow rowEtatCivil = rowSalarie.getForeignRow("ID_ETAT_CIVIL");
549
 
550
        // Numero inscription
551
        String nir = rowEtatCivil.getString("NUMERO_SS").replaceAll(" ", "");
552
 
553
        if (nir.length() >= 13) {
554
            nir = nir.substring(0, 13);
555
        } else {
556
            JOptionPane.showMessageDialog(new JFrame(), "Numéro d'inscription pour le salarié " + rowSalarie.getString("PRENOM") + " " + rowSalarie.getString("NOM") + " incorrect");
557
 
558
        }
559
        n4ds.write("S30.G01.00.001", nir);
560
 
561
        // Nom
142 ilm 562
        n4ds.write("S30.G01.00.002", normalizeString2(rowSalarie.getString("NOM")));
25 ilm 563
 
564
        // Prenoms
565
        // FIXME: regarder pour les prénoms pas seulement le 1er
142 ilm 566
        n4ds.write("S30.G01.00.003", normalizeString2(rowSalarie.getString("PRENOM")));
25 ilm 567
 
568
        // Code civilite
569
        final SQLRow rowTitre = rowSalarie.getForeignRow("ID_TITRE_PERSONNEL");
570
        final String civilite = rowTitre.getString("NOM").toLowerCase();
571
        if (civilite.contains("monsieur")) {
572
            n4ds.write("S30.G01.00.007", "01");
573
        } else if (civilite.contains("madame")) {
574
            n4ds.write("S30.G01.00.007", "02");
575
        } else if (civilite.contains("mademoiselle") || civilite.contains("mlle")) {
576
            n4ds.write("S30.G01.00.007", "03");
577
        } else {
578
            JOptionPane.showMessageDialog(new JFrame(), "Civilité incorrecte pour " + rowSalarie.getString("PRENOM") + " " + rowSalarie.getString("NOM") + " (" + civilite + ")");
579
        }
580
        SQLRow rowAdr = rowEtatCivil.getForeignRow("ID_ADRESSE");
581
        String voie = rowAdr.getString("RUE");
582
 
583
        // Complement adresse
584
        if (voie.contains("\n")) {
585
            String[] sVoies = voie.split("\n");
586
            if (sVoies.length > 0) {
587
                voie = sVoies[0].trim();
588
                String complement = "";
589
                for (int i = 1; i < sVoies.length; i++) {
590
                    complement += sVoies[i].trim() + " ";
591
                }
592
                if (complement.length() > 0) {
593
                    complement = complement.substring(0, complement.length() - 1);
594
                }
595
 
142 ilm 596
                n4ds.write("S30.G01.00.008.001", normalizeString2(complement));
25 ilm 597
            }
598
        }
599
 
600
        // Numéro, extension, nature et libellé de la voie
142 ilm 601
        n4ds.write("S30.G01.00.008.006", normalizeString2(voie));
25 ilm 602
 
603
        // Code postal
73 ilm 604
        n4ds.write("S30.G01.00.008.010", rowAdr.getString("CODE_POSTAL"));
25 ilm 605
 
606
        // Commune
73 ilm 607
        String villeFormat = normalizeString2(rowAdr.getString("VILLE"));
25 ilm 608
        n4ds.write("S30.G01.00.008.012", villeFormat);
609
 
610
        // Date de naissance
611
        Date d = rowEtatCivil.getDate("DATE_NAISSANCE").getTime();
612
        n4ds.write("S30.G01.00.009", format.format(d));
613
 
614
        // Commune de naissance
615
        String villeFormat2 = normalizeString2(rowEtatCivil.getString("COMMUNE_NAISSANCE"));
616
        n4ds.write("S30.G01.00.010", villeFormat2);
617
 
618
        SQLRow rowDept = rowEtatCivil.getForeignRow("ID_DEPARTEMENT_NAISSANCE");
619
 
620
        // Code departement de naissance
621
        n4ds.write("S30.G01.00.011", rowDept.getString("NUMERO"));
622
 
623
        SQLRow rowPays = rowEtatCivil.getForeignRow("ID_PAYS_NAISSANCE");
624
 
625
        // Pays naissance
626
        String pays = rowPays.getString("NOM").toUpperCase();
627
        n4ds.write("S30.G01.00.012", pays);
628
 
629
        // Pays
630
        n4ds.write("S30.G01.00.013", pays);
631
 
632
        // Matricule Salarie
41 ilm 633
        n4ds.write("S30.G01.00.019", rowSalarie.getString("CODE"));
25 ilm 634
    }
635
 
636
    public static String normalizeString2(String s) {
637
        s = s.toUpperCase();
638
        String temp = Normalizer.normalize(s, Form.NFC);
639
        temp = temp.replaceAll("-", " ");
142 ilm 640
        temp = temp.replaceAll("é", "e");
641
        temp = temp.replaceAll("è", "e");
642
        temp = temp.replaceAll("ê", "e");
643
        temp = temp.replaceAll(",", "");
25 ilm 644
        return temp.replaceAll("[^\\p{ASCII}]", "");
645
    }
646
 
647
    private String getNumeroVoie(String voie) {
648
        String numero = "";
649
        voie = voie.trim();
650
        for (int i = 0; i < voie.trim().length(); i++) {
651
            char c = voie.charAt(i);
652
            if (c >= '0' && c <= '9') {
653
                numero += c;
654
            } else {
655
                break;
656
            }
657
        }
658
        return numero;
659
    }
660
 
661
    private String getVoieWithoutNumber(String voie) {
662
        voie = voie.trim();
663
        String resultVoie = new String(voie);
664
 
665
        for (int i = 0; i < voie.trim().length(); i++) {
666
            char c = voie.charAt(i);
667
            if (c >= '0' && c <= '9') {
668
                resultVoie = resultVoie.substring(1);
669
            } else {
670
                break;
671
            }
672
        }
673
        return resultVoie.trim();
674
    }
675
 
676
}