OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Rev 180 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
132 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.config;
15
 
156 ilm 16
import org.openconcerto.erp.config.DsnBrutCode.DsnTypeCodeBrut;
132 ilm 17
import org.openconcerto.sql.model.DBRoot;
18
import org.openconcerto.sql.model.SQLBase;
142 ilm 19
import org.openconcerto.sql.model.SQLName;
132 ilm 20
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.sql.model.SQLRowListRSH;
22
import org.openconcerto.sql.model.SQLRowValues;
23
import org.openconcerto.sql.model.SQLSelect;
24
import org.openconcerto.sql.model.SQLSyntax;
25
import org.openconcerto.sql.model.SQLTable;
26
import org.openconcerto.sql.model.Where;
27
import org.openconcerto.sql.request.Inserter;
28
import org.openconcerto.sql.request.Inserter.Insertion;
142 ilm 29
import org.openconcerto.sql.request.UpdateBuilder;
132 ilm 30
import org.openconcerto.sql.utils.AlterTable;
31
import org.openconcerto.sql.utils.ReOrder;
32
import org.openconcerto.sql.utils.SQLCreateTable;
33
import org.openconcerto.utils.Tuple2;
156 ilm 34
import org.openconcerto.utils.Tuple3;
132 ilm 35
 
36
import java.sql.SQLException;
37
import java.util.ArrayList;
38
import java.util.Arrays;
142 ilm 39
import java.util.HashMap;
132 ilm 40
import java.util.List;
142 ilm 41
import java.util.Map;
132 ilm 42
 
43
public class DSNInstallationUtils {
44
 
45
    private void insertUndef(final SQLCreateTable ct) throws SQLException {
46
        // check that we can use insertReturnFirstField()
47
        if (ct.getPrimaryKey().size() != 1)
48
            throw new IllegalStateException("Not one and only one field in the PK : " + ct.getPrimaryKey());
49
        final Insertion<?> insertion = new Inserter(ct).insertReturnFirstField("(" + SQLBase.quoteIdentifier(SQLSyntax.ORDER_NAME) + ") VALUES(" + ReOrder.MIN_ORDER + ")", false);
50
        assert insertion.getCount() == 1;
51
        if (insertion.getRows().size() != 1)
52
            throw new IllegalStateException("Missing ID " + insertion.getRows());
53
        SQLTable.setUndefID(ct.getRoot().getSchema(), ct.getName(), ((Number) insertion.getRows().get(0)).intValue());
54
    }
55
 
56
    private void insertValues(List<Tuple2<String, String>> values, SQLTable table) throws SQLException {
142 ilm 57
        SQLSelect sel = new SQLSelect();
58
        sel.addSelect(table.getField("CODE"));
59
        List<String> codes = (List<String>) table.getDBSystemRoot().getDataSource().executeA(sel.asString());
132 ilm 60
        for (Tuple2<String, String> tuple2 : values) {
142 ilm 61
            if (!codes.contains(tuple2.get0())) {
62
                SQLRowValues rowVals = new SQLRowValues(table);
63
                rowVals.put("CODE", tuple2.get0());
64
                rowVals.put("NOM", tuple2.get1());
65
                rowVals.commit();
66
            }
132 ilm 67
        }
68
    }
69
 
70
    public void updateDSNCommonTable(final DBRoot root) throws SQLException {
71
 
72
        SQLTable societeCommonT = root.getTable("SOCIETE_COMMON");
73
        if (!societeCommonT.contains("IBAN")) {
74
            AlterTable t = new AlterTable(societeCommonT);
75
            t.addVarCharColumn("IBAN", 256);
76
            t.addVarCharColumn("BIC", 256);
77
            root.getBase().getDataSource().execute(t.asString());
78
            root.refetchTable("SOCIETE_COMMON");
79
            root.getSchema().updateVersion();
80
        }
81
        if (!societeCommonT.contains("ORG_PROTECTION_SOCIAL_ID")) {
82
            AlterTable t = new AlterTable(societeCommonT);
83
            t.addVarCharColumn("ORG_PROTECTION_SOCIAL_ID", 256);
84
            root.getBase().getDataSource().execute(t.asString());
85
            root.refetchTable("SOCIETE_COMMON");
86
            root.getSchema().updateVersion();
87
        }
88
 
89
        SQLTable tableRubCot = root.getTable("RUBRIQUE_COTISATION");
90
        if (!tableRubCot.contains("ASSIETTE_PLAFONNEE")) {
91
            AlterTable tableRub = new AlterTable(tableRubCot);
92
            tableRub.addBooleanColumn("ASSIETTE_PLAFONNEE", false, false);
93
            root.getBase().getDataSource().execute(tableRub.asString());
94
            root.refetchTable("RUBRIQUE_COTISATION");
95
            root.getSchema().updateVersion();
96
        }
97
 
144 ilm 98
        if (!tableRubCot.contains("TAXABLE_CM")) {
99
            AlterTable tableRub = new AlterTable(tableRubCot);
100
            tableRub.addBooleanColumn("TAXABLE_CM", Boolean.FALSE, false);
101
            root.getBase().getDataSource().execute(tableRub.asString());
102
            root.refetchTable("RUBRIQUE_COTISATION");
103
            root.getSchema().updateVersion();
104
        }
105
 
132 ilm 106
        if (!root.contains("CODE_CAISSE_TYPE_RUBRIQUE")) {
107
            final SQLCreateTable createTableCode = new SQLCreateTable(root, "CODE_CAISSE_TYPE_RUBRIQUE");
108
            createTableCode.addVarCharColumn("CODE", 25);
109
            createTableCode.addVarCharColumn("NOM", 512);
110
            createTableCode.addVarCharColumn("CAISSE_COTISATION", 512);
111
 
112
            try {
113
                root.getBase().getDataSource().execute(createTableCode.asString());
114
                insertUndef(createTableCode);
115
                root.refetchTable("CODE_CAISSE_TYPE_RUBRIQUE");
116
 
117
                final SQLTable table = root.getTable("CODE_CAISSE_TYPE_RUBRIQUE");
118
 
119
                DsnUrssafCode codeUrssaf = new DsnUrssafCode();
120
                codeUrssaf.insertCode(table);
121
 
122
                List<String> tableRubName = Arrays.asList("RUBRIQUE_BRUT", "RUBRIQUE_COTISATION", "RUBRIQUE_NET");
123
                for (String t : tableRubName) {
124
                    AlterTable tableRub = new AlterTable(root.getTable(t));
125
                    tableRub.addForeignColumn("ID_CODE_CAISSE_TYPE_RUBRIQUE", table);
126
                    root.getBase().getDataSource().execute(tableRub.asString());
127
                    root.refetchTable(t);
128
                }
129
                root.getSchema().updateVersion();
130
 
131
            } catch (SQLException ex) {
132
                throw new IllegalStateException("Erreur lors de la création de la table " + "CODE_CAISSE_TYPE_RUBRIQUE", ex);
133
            }
134
        }
135
 
136
        if (!root.contains("MOTIF_ARRET_TRAVAIL")) {
137
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "MOTIF_ARRET_TRAVAIL");
138
            createTableMotif.addVarCharColumn("CODE", 25);
139
            createTableMotif.addVarCharColumn("NOM", 512);
140
 
141
            try {
142
                root.getBase().getDataSource().execute(createTableMotif.asString());
143
                insertUndef(createTableMotif);
144
                root.refetchTable("MOTIF_ARRET_TRAVAIL");
145
                root.getSchema().updateVersion();
146
 
147
                final SQLTable table = root.getTable("MOTIF_ARRET_TRAVAIL");
148
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
149
                v.add(Tuple2.create("01", "maladie"));
150
                v.add(Tuple2.create("02", "maternité /adoption"));
151
                v.add(Tuple2.create("03", "paternité / accueil de l’enfant"));
152
                v.add(Tuple2.create("04", "congé suite à un accident de trajet"));
153
                v.add(Tuple2.create("05", "congé suite à maladie professionnelle"));
154
                v.add(Tuple2.create("06", "congé suite à accident de travail ou de service"));
155
                v.add(Tuple2.create("07", "femme enceinte dispensée de travail"));
156
                v.add(Tuple2.create("99", "annulation"));
157
 
158
                insertValues(v, table);
159
            } catch (SQLException ex) {
160
                throw new IllegalStateException("Erreur lors de la création de la table " + "MOTIF_ARRET_TRAVAIL", ex);
161
            }
162
        }
163
 
142 ilm 164
        if (!root.contains("TYPE_PREAVIS")) {
165
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "TYPE_PREAVIS");
166
            createTableMotif.addVarCharColumn("CODE", 25);
167
            createTableMotif.addVarCharColumn("NOM", 512);
168
 
169
            try {
170
                root.getBase().getDataSource().execute(createTableMotif.asString());
171
                insertUndef(createTableMotif);
172
                root.refetchTable("TYPE_PREAVIS");
173
                root.getSchema().updateVersion();
174
 
175
                final SQLTable table = root.getTable("TYPE_PREAVIS");
176
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
177
                v.add(Tuple2.create("01", "préavis effectué et payé"));
178
                v.add(Tuple2.create("02", "préavis non effectué et payé"));
179
                v.add(Tuple2.create("03", "préavis non effectué et non payé"));
180
                v.add(Tuple2.create("10", "préavis non effectué non payé dans le cadre d’un contrat de sécurisation professionnelle (CSP)"));
181
                v.add(Tuple2.create("50", "préavis non effectué et payé dans le cadre d’un congé de reclassement"));
182
                v.add(Tuple2.create("51", "préavis non effectué et payé dans le cadre d’un congé de mobilité"));
183
                v.add(Tuple2.create("60", "Délai de prévenance"));
184
                v.add(Tuple2.create("90", "pas de clause de préavis applicable"));
185
 
186
                insertValues(v, table);
187
            } catch (SQLException ex) {
188
                throw new IllegalStateException("Erreur lors de la création de la table " + "TYPE_PREAVIS", ex);
189
            }
190
        }
191
 
132 ilm 192
        if (!root.contains("CODE_BASE_ASSUJETTIE")) {
193
            final SQLCreateTable createTableCodeBase = new SQLCreateTable(root, "CODE_BASE_ASSUJETTIE");
194
            createTableCodeBase.addVarCharColumn("CODE", 25);
195
            createTableCodeBase.addVarCharColumn("NOM", 512);
196
 
197
            try {
198
                root.getBase().getDataSource().execute(createTableCodeBase.asString());
199
                insertUndef(createTableCodeBase);
200
                root.refetchTable("CODE_BASE_ASSUJETTIE");
201
                root.getSchema().updateVersion();
202
 
203
                final SQLTable table = root.getTable("CODE_BASE_ASSUJETTIE");
204
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
205
 
206
                v.add(Tuple2.create("02", "Assiette brute plafonnée"));
207
                v.add(Tuple2.create("03", "Assiette brute déplafonnée"));
208
                v.add(Tuple2.create("04", "Assiette de la contribution sociale généralisée"));
209
                v.add(Tuple2.create("07", "Assiette des contributions d'Assurance Chômage"));
210
                v.add(Tuple2.create("08", "Assiette retraite CPRP SNCF"));
211
                v.add(Tuple2.create("09", "Assiette de compensation bilatérale maladie CPRP SNCF"));
212
                v.add(Tuple2.create("10", "Base brute fiscale"));
213
                v.add(Tuple2.create("11", "Base forfaitaire soumise aux cotisations de Sécurité Sociale"));
214
                v.add(Tuple2.create("12", "Assiette du crédit d'impôt compétitivité-emploi"));
215
                v.add(Tuple2.create("13", "Assiette du forfait social à 8%"));
216
                v.add(Tuple2.create("14", "Assiette du forfait social à 20%"));
217
 
218
                insertValues(v, table);
219
            } catch (SQLException ex) {
220
                throw new IllegalStateException("Erreur lors de la création de la table " + "CODE_BASE_ASSUJETTIE", ex);
221
            }
222
        }
223
        if (!tableRubCot.contains("ID_CODE_BASE_ASSUJETTIE")) {
224
            AlterTable alterTableCot = new AlterTable(tableRubCot);
225
            alterTableCot.addForeignColumn("ID_CODE_BASE_ASSUJETTIE", root.getTable("CODE_BASE_ASSUJETTIE"));
226
            root.getBase().getDataSource().execute(alterTableCot.asString());
227
            root.refetchTable("RUBRIQUE_COTISATION");
228
            root.getSchema().updateVersion();
229
        }
230
 
231
        if (!root.contains("CODE_TYPE_RUBRIQUE_BRUT")) {
232
            final SQLCreateTable createTableCodeBase = new SQLCreateTable(root, "CODE_TYPE_RUBRIQUE_BRUT");
233
            createTableCodeBase.addVarCharColumn("CODE", 25);
234
            createTableCodeBase.addVarCharColumn("NOM", 512);
235
            createTableCodeBase.addVarCharColumn("TYPE", 512);
236
 
237
            try {
238
                root.getBase().getDataSource().execute(createTableCodeBase.asString());
239
                insertUndef(createTableCodeBase);
240
                root.refetchTable("CODE_TYPE_RUBRIQUE_BRUT");
241
                root.getSchema().updateVersion();
242
 
243
                DsnBrutCode brutCode = new DsnBrutCode();
244
                brutCode.insertCode(root.getTable("CODE_TYPE_RUBRIQUE_BRUT"));
245
            } catch (SQLException ex) {
246
                throw new IllegalStateException("Erreur lors de la création de la table " + "CODE_BASE_ASSUJETTIE", ex);
247
            }
248
        }
249
 
250
        SQLTable tableRubBrut = root.getTable("RUBRIQUE_BRUT");
251
        if (!tableRubBrut.contains("ID_CODE_TYPE_RUBRIQUE_BRUT")) {
252
            AlterTable alterTableBrut = new AlterTable(tableRubBrut);
253
            alterTableBrut.addForeignColumn("ID_CODE_TYPE_RUBRIQUE_BRUT", root.getTable("CODE_TYPE_RUBRIQUE_BRUT"));
254
            root.getBase().getDataSource().execute(alterTableBrut.asString());
255
            root.refetchTable("RUBRIQUE_BRUT");
256
            root.getSchema().updateVersion();
257
        }
258
 
144 ilm 259
        if (!tableRubBrut.contains("COTISABLE")) {
260
            AlterTable alterTableBrut = new AlterTable(tableRubBrut);
261
            alterTableBrut.addBooleanColumn("COTISABLE", Boolean.TRUE, false);
262
            root.getBase().getDataSource().execute(alterTableBrut.asString());
263
            root.refetchTable("RUBRIQUE_BRUT");
264
            root.getSchema().updateVersion();
265
        }
266
 
267
        if (!tableRubBrut.contains("TAXABLE_CM")) {
268
            AlterTable alterTableBrut = new AlterTable(tableRubBrut);
269
            alterTableBrut.addBooleanColumn("TAXABLE_CM", Boolean.TRUE, false);
270
            root.getBase().getDataSource().execute(alterTableBrut.asString());
271
            root.refetchTable("RUBRIQUE_BRUT");
272
            root.getSchema().updateVersion();
273
        }
274
 
177 ilm 275
        if (!tableRubBrut.contains("CSG_NORMAL")) {
276
            AlterTable alterTableBrut = new AlterTable(tableRubBrut);
277
            alterTableBrut.addBooleanColumn("CSG_NORMAL", Boolean.TRUE, false);
278
            root.getBase().getDataSource().execute(alterTableBrut.asString());
279
            root.refetchTable("RUBRIQUE_BRUT");
280
            root.getSchema().updateVersion();
281
        }
282
        if (!tableRubBrut.contains("CSG_REDUIT")) {
283
            AlterTable alterTableBrut = new AlterTable(tableRubBrut);
284
            alterTableBrut.addBooleanColumn("CSG_REDUIT", Boolean.FALSE, false);
285
            root.getBase().getDataSource().execute(alterTableBrut.asString());
286
            root.refetchTable("RUBRIQUE_BRUT");
287
            root.getSchema().updateVersion();
288
        }
289
 
142 ilm 290
        SQLTable tableRubNet = root.getTable("RUBRIQUE_NET");
291
        if (!tableRubNet.contains("ID_CODE_TYPE_RUBRIQUE_BRUT")) {
292
 
293
            AlterTable alterTableNet = new AlterTable(tableRubNet);
294
            alterTableNet.addForeignColumn("ID_CODE_TYPE_RUBRIQUE_BRUT", root.getTable("CODE_TYPE_RUBRIQUE_BRUT"));
295
            root.getBase().getDataSource().execute(alterTableNet.asString());
296
            root.refetchTable("RUBRIQUE_NET");
297
            root.getSchema().updateVersion();
298
        }
299
 
132 ilm 300
        if (!root.contains("DSN_REGIME_LOCAL")) {
301
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "DSN_REGIME_LOCAL");
302
            createTableMotif.addVarCharColumn("CODE", 25);
303
            createTableMotif.addVarCharColumn("NOM", 512);
304
 
305
            try {
306
                root.getBase().getDataSource().execute(createTableMotif.asString());
307
                insertUndef(createTableMotif);
308
                root.refetchTable("DSN_REGIME_LOCAL");
309
                root.getSchema().updateVersion();
310
 
311
                final SQLTable table = root.getTable("DSN_REGIME_LOCAL");
312
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
313
                v.add(Tuple2.create("99", "non applicable"));
314
                v.add(Tuple2.create("01", "régime local Alsace Moselle"));
315
                insertValues(v, table);
316
            } catch (SQLException ex) {
317
                throw new IllegalStateException("Erreur lors de la création de la table " + "DSN_REGIME_LOCAL", ex);
318
            }
319
        }
320
 
321
        if (!root.contains("CONTRAT_MODALITE_TEMPS")) {
322
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CONTRAT_MODALITE_TEMPS");
323
            createTableMotif.addVarCharColumn("CODE", 25);
324
            createTableMotif.addVarCharColumn("NOM", 512);
325
 
326
            try {
327
                root.getBase().getDataSource().execute(createTableMotif.asString());
328
                insertUndef(createTableMotif);
329
                root.refetchTable("CONTRAT_MODALITE_TEMPS");
330
                root.getSchema().updateVersion();
331
 
332
                final SQLTable table = root.getTable("CONTRAT_MODALITE_TEMPS");
333
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
334
                v.add(Tuple2.create("10", "temps plein"));
335
                v.add(Tuple2.create("20", "temps partiel"));
336
                v.add(Tuple2.create("21", "temps partiel thérapeutique"));
337
                v.add(Tuple2.create("99", "salarié non concerné"));
338
                insertValues(v, table);
339
            } catch (SQLException ex) {
340
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_MODALITE_TEMPS", ex);
341
            }
342
        }
343
 
344
        if (!root.contains("CONTRAT_REGIME_MALADIE")) {
345
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CONTRAT_REGIME_MALADIE");
346
            createTableMotif.addVarCharColumn("CODE", 25);
347
            createTableMotif.addVarCharColumn("NOM", 512);
348
 
349
            try {
350
                root.getBase().getDataSource().execute(createTableMotif.asString());
351
                insertUndef(createTableMotif);
352
                root.refetchTable("CONTRAT_REGIME_MALADIE");
353
                root.getSchema().updateVersion();
354
 
355
                final SQLTable table = root.getTable("CONTRAT_REGIME_MALADIE");
356
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
357
                v.add(Tuple2.create("134", "régime spécial de la SNCF"));
358
                v.add(Tuple2.create("135", "régime spécial de la RATP"));
359
                v.add(Tuple2.create("136", "établissement des invalides de la marine (ENIM)"));
360
                v.add(Tuple2.create("137", "mineurs ou assimilés (CANMSS)"));
361
                v.add(Tuple2.create("138", "militaires de carrière (CNMSS)"));
362
                v.add(Tuple2.create("140", "clercs et employés de notaires (CRPCEN)"));
363
                v.add(Tuple2.create("141", "chambre de commerce et d'industrie de Paris"));
364
                v.add(Tuple2.create("144", "Assemblée Nationale"));
365
                v.add(Tuple2.create("145", "Sénat"));
366
                v.add(Tuple2.create("146", "port autonome de Bordeaux"));
367
                v.add(Tuple2.create("147", "industries électriques et gazières (CAMIEG)"));
368
                v.add(Tuple2.create("149", "régimes des cultes (CAVIMAC)"));
369
                v.add(Tuple2.create("200", "régime général (CNAM)"));
370
                v.add(Tuple2.create("300", "régime agricole (MSA)"));
371
                v.add(Tuple2.create("400", "régime spécial Banque de France"));
372
                v.add(Tuple2.create("900", "autre régime (réservé Polynésie Française, Nouvelle Calédonie)"));
373
                v.add(Tuple2.create("999", "autre"));
374
 
375
                insertValues(v, table);
376
            } catch (SQLException ex) {
377
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_REGIME_MALADIE", ex);
378
            }
379
        }
380
 
381
        if (!root.contains("CONTRAT_REGIME_VIEILLESSE")) {
382
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CONTRAT_REGIME_VIEILLESSE");
383
            createTableMotif.addVarCharColumn("CODE", 25);
384
            createTableMotif.addVarCharColumn("NOM", 512);
385
 
386
            try {
387
                root.getBase().getDataSource().execute(createTableMotif.asString());
388
                insertUndef(createTableMotif);
389
                root.refetchTable("CONTRAT_REGIME_VIEILLESSE");
390
                root.getSchema().updateVersion();
391
 
392
                final SQLTable table = root.getTable("CONTRAT_REGIME_VIEILLESSE");
393
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
394
                v.add(Tuple2.create("120", "retraite des agents des collectivités locales (CNRACL)"));
395
                v.add(Tuple2.create("121", "pensions des ouvriers des établissements industriels de l'Etat (FSPOEIE)"));
396
                v.add(Tuple2.create("122", "pensions civiles et militaires de retraite de l'Etat (SRE)"));
397
                v.add(Tuple2.create("134", "régime spécial de la SNCF"));
398
                v.add(Tuple2.create("135", "régime spécial de la RATP"));
399
                v.add(Tuple2.create("136", "établissement des invalides de la marine (ENIM)"));
400
                v.add(Tuple2.create("137", "mineurs ou assimilés (fonds Caisse des Dépôts)"));
401
                v.add(Tuple2.create("139", "Banque de France"));
402
                v.add(Tuple2.create("140", "clercs et employés de notaires (CRPCEN)"));
403
                v.add(Tuple2.create("141", "chambre de commerce et d'industrie de Paris"));
404
                v.add(Tuple2.create("144", "Assemblée Nationale"));
405
                v.add(Tuple2.create("145", "Sénat"));
406
                v.add(Tuple2.create("147", "industries électriques et gazières (CNIEG)"));
407
                v.add(Tuple2.create("149", "régime des cultes (CAVIMAC)"));
408
                v.add(Tuple2.create("157", "régime de retraite des avocats (CNBF)"));
409
                v.add(Tuple2.create("158", "SEITA"));
410
                v.add(Tuple2.create("159", "Comédie Française"));
411
                v.add(Tuple2.create("160", "Opéra de Paris"));
412
                v.add(Tuple2.create("200", "régime général (CNAV)"));
413
                v.add(Tuple2.create("300", "régime agricole (MSA)"));
414
                v.add(Tuple2.create("900", "autre régime (réservé Polynésie Française, Nouvelle Calédonie, Principauté de Monaco)"));
415
                v.add(Tuple2.create("903", "salariés étrangers exemptés d'affiliation pour le risque vieillesse"));
416
                v.add(Tuple2.create("999", "cas particuliers d'affiliation"));
417
 
418
                insertValues(v, table);
419
            } catch (SQLException ex) {
420
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_REGIME_VIEILLESSE", ex);
421
            }
422
        }
423
 
424
        if (!root.contains("CONTRAT_MOTIF_RECOURS")) {
425
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CONTRAT_MOTIF_RECOURS");
426
            createTableMotif.addVarCharColumn("CODE", 25);
427
            createTableMotif.addVarCharColumn("NOM", 512);
428
 
429
            try {
430
                root.getBase().getDataSource().execute(createTableMotif.asString());
431
                insertUndef(createTableMotif);
432
                root.refetchTable("CONTRAT_MOTIF_RECOURS");
433
                root.getSchema().updateVersion();
434
 
435
                final SQLTable table = root.getTable("CONTRAT_MOTIF_RECOURS");
436
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
437
                v.add(Tuple2.create("01", "Remplacement d'un salarié"));
438
                v.add(Tuple2.create("02", "Accroissement temporaire de l'activité de l'entreprise"));
439
                v.add(Tuple2.create("03", "Emplois à caractère saisonnier"));
440
                v.add(Tuple2.create("04", "Contrat vendanges"));
441
                v.add(Tuple2.create("05", "Contrat à durée déterminée d’usage"));
442
                v.add(Tuple2.create("06", "Contrat à durée déterminée à objet défini"));
443
                v.add(Tuple2.create("07", "Remplacement d'un chef d'entreprise"));
444
                v.add(Tuple2.create("08", "Remplacement du chef d'une exploitation agricole"));
445
                v.add(Tuple2.create("09", "Recrutement de personnes sans emploi rencontrant des difficultés sociales et professionnelles particulières"));
446
                v.add(Tuple2.create("10", "Complément de formation professionnelle au salarié"));
447
                v.add(Tuple2.create("11",
448
                        "Formation professionnelle au salarié par la voie de l'apprentissage, en vue de l'obtention d'une qualification professionnelle sanctionnée par un diplôme ou un titre à finalité professionnelle enregistré au répertoire national des certifications professionnelles"));
449
                v.add(Tuple2.create("12", "Remplacement d’un salarié passé provisoirement à temps partiel"));
450
                v.add(Tuple2.create("13", "Attente de la suppression définitive du poste du salarié ayant quitté définitivement l’entreprise"));
451
                insertValues(v, table);
452
            } catch (SQLException ex) {
453
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_MOTIF_RECOURS", ex);
454
            }
455
        }
456
 
457
        if (!root.contains("CONTRAT_DETACHE_EXPATRIE")) {
458
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CONTRAT_DETACHE_EXPATRIE");
459
            createTableMotif.addVarCharColumn("CODE", 25);
460
            createTableMotif.addVarCharColumn("NOM", 512);
461
 
462
            try {
463
                root.getBase().getDataSource().execute(createTableMotif.asString());
464
                insertUndef(createTableMotif);
465
                root.refetchTable("CONTRAT_DETACHE_EXPATRIE");
466
                root.getSchema().updateVersion();
467
 
468
                final SQLTable table = root.getTable("CONTRAT_DETACHE_EXPATRIE");
469
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
470
                v.add(Tuple2.create("01", "Détaché"));
471
                v.add(Tuple2.create("02", "Expatrié"));
472
                v.add(Tuple2.create("03", "Frontalier"));
473
                v.add(Tuple2.create("99", "Salarié non concerné"));
474
                insertValues(v, table);
475
            } catch (SQLException ex) {
476
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_DETACHE_EXPATRIE", ex);
477
            }
478
        }
479
 
480
        if (!root.contains("DSN_NATURE")) {
481
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "DSN_NATURE");
482
            createTableMotif.addVarCharColumn("CODE", 25);
483
            createTableMotif.addVarCharColumn("NOM", 512);
484
 
485
            try {
486
                root.getBase().getDataSource().execute(createTableMotif.asString());
487
                insertUndef(createTableMotif);
488
                root.refetchTable("DSN_NATURE");
489
                root.getSchema().updateVersion();
490
 
491
                final SQLTable table = root.getTable("DSN_NATURE");
492
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
493
                v.add(Tuple2.create("01", "DSN Mensuelle"));
494
                v.add(Tuple2.create("02", "Signalement Fin du contrat de travail"));
495
                v.add(Tuple2.create("04", "Signalement Arrêt de travail"));
496
                v.add(Tuple2.create("05", "Signalement Reprise suite à arrêt de travail"));
497
                v.add(Tuple2.create("06", "DSN reprise d'historique"));
498
                insertValues(v, table);
499
            } catch (SQLException ex) {
500
                throw new IllegalStateException("Erreur lors de la création de la table " + "DSN_NATURE", ex);
501
            }
502
        }
503
 
504
        if (!root.contains("DSN_TYPE")) {
505
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "DSN_TYPE");
506
            createTableMotif.addVarCharColumn("CODE", 25);
507
            createTableMotif.addVarCharColumn("NOM", 512);
508
 
509
            try {
510
                root.getBase().getDataSource().execute(createTableMotif.asString());
511
                insertUndef(createTableMotif);
512
                root.refetchTable("DSN_TYPE");
513
                root.getSchema().updateVersion();
514
 
515
                final SQLTable table = root.getTable("DSN_TYPE");
516
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
517
                v.add(Tuple2.create("01", "déclaration normale"));
518
                v.add(Tuple2.create("02", "déclaration normale néant"));
519
                v.add(Tuple2.create("03", "déclaration annule et remplace intégral"));
520
                v.add(Tuple2.create("04", "déclaration annule"));
521
                v.add(Tuple2.create("05", "annule et remplace néant"));
522
                insertValues(v, table);
523
            } catch (SQLException ex) {
524
                throw new IllegalStateException("Erreur lors de la création de la table " + "DSN_TYPE", ex);
525
            }
526
        }
527
 
528
        if (!root.contains("CONTRAT_DISPOSITIF_POLITIQUE")) {
529
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CONTRAT_DISPOSITIF_POLITIQUE");
530
            createTableMotif.addVarCharColumn("CODE", 25);
531
            createTableMotif.addVarCharColumn("NOM", 512);
532
 
533
            try {
534
                root.getBase().getDataSource().execute(createTableMotif.asString());
535
                insertUndef(createTableMotif);
536
                root.refetchTable("CONTRAT_DISPOSITIF_POLITIQUE");
537
                root.getSchema().updateVersion();
538
 
539
                final SQLTable table = root.getTable("CONTRAT_DISPOSITIF_POLITIQUE");
540
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
541
                v.add(Tuple2.create("21", "CUI - Contrat Initiative Emploi"));
542
                v.add(Tuple2.create("41", "CUI - Contrat d'Accompagnement dans l'Emploi"));
543
                v.add(Tuple2.create("42", "CUI - Contrat d'accès à l'emploi - DOM"));
544
                v.add(Tuple2.create("50", "Emploi d'avenir secteur marchand"));
545
                v.add(Tuple2.create("51", "Emploi d'avenir secteur non marchand"));
546
                v.add(Tuple2.create("61", "Contrat de Professionnalisation"));
547
                v.add(Tuple2.create("64", "Contrat d'apprentissage entreprises artisanales ou de moins de 11 salariés (loi du 3 janvier 1979)"));
548
                v.add(Tuple2.create("65", "Contrat d’apprentissage entreprises non inscrites au répertoire des métiers d’au moins 11 salariés (loi de 1987)"));
549
                v.add(Tuple2.create("70", "Contrat à durée déterminée pour les séniors"));
550
                v.add(Tuple2.create("71", "Contrat à durée déterminée d’insertion"));
551
                v.add(Tuple2.create("80", "Contrat de génération"));
552
                v.add(Tuple2.create("81", "Contrat d'apprentissage secteur public (Loi de 1992)"));
553
                v.add(Tuple2.create("82", "Contrat à durée indéterminée intérimaire"));
554
                v.add(Tuple2.create("99", "Non concerné"));
555
                insertValues(v, table);
556
            } catch (SQLException ex) {
557
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_DISPOSITIF_POLITIQUE", ex);
558
            }
559
        }
560
 
177 ilm 561
        if (!root.contains("CODE_AMENAGEMENT_PARTIEL")) {
562
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CODE_AMENAGEMENT_PARTIEL");
563
            createTableMotif.addVarCharColumn("CODE", 25);
564
            createTableMotif.addVarCharColumn("NOM", 512);
565
 
566
            try {
567
                root.getBase().getDataSource().execute(createTableMotif.asString());
568
                insertUndef(createTableMotif);
569
                root.refetchTable("CODE_AMENAGEMENT_PARTIEL");
570
                root.getSchema().updateVersion();
571
 
572
                final SQLTable table = root.getTable("CODE_AMENAGEMENT_PARTIEL");
573
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
574
 
575
                v.add(Tuple2.create("01", "Forfait hebdomadaire"));
576
                v.add(Tuple2.create("02", "Autre temps de travail hebdomadaire"));
577
                v.add(Tuple2.create("03", "Equivalent à 35h - 39h (Mayotte)"));
578
                v.add(Tuple2.create("04", "Forfait mensuel"));
579
                v.add(Tuple2.create("05", "Forfait annuel en jour"));
580
                v.add(Tuple2.create("06", "Forfait annuel en heures"));
581
                v.add(Tuple2.create("07", "Cycle"));
582
                v.add(Tuple2.create("08", "Modulation"));
583
                v.add(Tuple2.create("09", "Aménagement du temps de travail (Loi du 20 août 2008)"));
584
                v.add(Tuple2.create("10", "Personnel navigant ou autres"));
585
 
586
                insertValues(v, table);
587
            } catch (SQLException ex) {
588
                throw new IllegalStateException("Erreur lors de la création de la table " + "CODE_AMENAGEMENT_PARTIEL", ex);
589
            }
590
        }
591
 
592
        if (!root.contains("CODE_SUSPENSION")) {
593
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CODE_SUSPENSION");
594
            createTableMotif.addVarCharColumn("CODE", 25);
595
            createTableMotif.addVarCharColumn("NOM", 512);
596
 
597
            try {
598
                root.getBase().getDataSource().execute(createTableMotif.asString());
599
                insertUndef(createTableMotif);
600
                root.refetchTable("CODE_SUSPENSION");
601
                root.getSchema().updateVersion();
602
 
603
                final SQLTable table = root.getTable("CODE_SUSPENSION");
604
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
605
 
606
                v.add(Tuple2.create("112", "Invalidité catégorie 1"));
607
                v.add(Tuple2.create("114", "Invalidité catégorie 2"));
608
                v.add(Tuple2.create("116", "Invalidité catégorie 3"));
609
                v.add(Tuple2.create("200", "COP (Congés payés)"));
610
                v.add(Tuple2.create("301", "Congé de Formation Professionnelle"));
611
                v.add(Tuple2.create("501", "Congé divers non rémunéré"));
612
                v.add(Tuple2.create("507", "Chômage intempéries"));
613
                v.add(Tuple2.create("601", "Mobilité volontaire sécurisée"));
614
                v.add(Tuple2.create("602", "Chômage sans rupture de contrat"));
615
                v.add(Tuple2.create("603", "Détention provisoire"));
616
                v.add(Tuple2.create("604", "Journée de perception de l'allocation journalière de présence parentale"));
617
                v.add(Tuple2.create("605", "Congé statutaire"));
618
                v.add(Tuple2.create("606", "Détachement d'un salarié IEG en France"));
619
                v.add(Tuple2.create("607", "Congé de présence parentale"));
620
                v.add(Tuple2.create("608", "CASA"));
621
                v.add(Tuple2.create("609", "CIF (Congé Individuel de Formation)"));
622
                v.add(Tuple2.create("611", "Congé de bilan de compétences"));
623
                v.add(Tuple2.create("612", "Congé de candidat parlementaire ou élu à un mandat local"));
624
                v.add(Tuple2.create("615", "Congé de formation de cadres et d'animateurs pour la jeunesse"));
625
                v.add(Tuple2.create("617", "Congé de formation pour les salariés de moins de 25 ans"));
626
                v.add(Tuple2.create("618", "Congé de formation économique, sociale et syndicale"));
627
                v.add(Tuple2.create("620", "Congé de mobilité"));
628
                v.add(Tuple2.create("621", "Congé de participation aux instances d'emploi ou de formation professionnelle"));
629
                v.add(Tuple2.create("625", "Congé de reclassement"));
630
                v.add(Tuple2.create("626", "Congé de représentation"));
631
                v.add(Tuple2.create("627", "Congé de solidarité familiale"));
632
                v.add(Tuple2.create("628", "Congé de solidarité internationale"));
633
                v.add(Tuple2.create("630", "Congé d'enseignement ou de recherche"));
634
                v.add(Tuple2.create("631", "Congé mutualiste de formation"));
635
                v.add(Tuple2.create("632", "Congé parental d'éducation"));
636
                v.add(Tuple2.create("633", "Congé pour acquisition de la nationalité"));
637
                v.add(Tuple2.create("634", "Congé pour catastrophe naturelle"));
638
                v.add(Tuple2.create("635", "Congé pour création ou reprise d'entreprise"));
639
                v.add(Tuple2.create("636", "Congé pour enfant malade"));
640
                v.add(Tuple2.create("637", "Congé pour évènement familial"));
641
                v.add(Tuple2.create("638", "Congé pour validation des acquis de l'expérience"));
642
                v.add(Tuple2.create("639", "Congé sabbatique"));
643
                v.add(Tuple2.create("642", "Convention FNE d'aide au passage à temps partiel"));
644
                v.add(Tuple2.create("643", "Congé de conversion avec prise en charge par l'Etat"));
645
                v.add(Tuple2.create("644", "Congé de conversion sans prise en charge par l'Etat"));
646
                v.add(Tuple2.create("645", "Préretraite progressive"));
647
                v.add(Tuple2.create("646", "Préretraite d'entreprise sans rupture de contrat de travail"));
648
                v.add(Tuple2.create("647", "Réduction temps d'emploi"));
649
                v.add(Tuple2.create("648", "Conventions d'Allocations Spéciales du FNE (ASFNE)"));
650
                v.add(Tuple2.create("650", "Congé de proche aidant"));
651
                v.add(Tuple2.create("651", "Congé pour mandat parlementaire"));
652
                v.add(Tuple2.create("652", "Inaptitude temporaire liée à la grossesse"));
653
                v.add(Tuple2.create("653", "Maintien de salaire – personnel navigant de l’aéronautique civile"));
654
                v.add(Tuple2.create("654", "Inactivité temps alterné – personnel navigant de l’aéronautique civile"));
655
                v.add(Tuple2.create("655", "[FP] Détachement conduisant à pension (ECP)"));
656
                v.add(Tuple2.create("656", "[FP] Congé pour cessation anticipée d’activité du fait d’une maladie professionnelle provoquée par l’amiante"));
657
                v.add(Tuple2.create("657", "[FP] Absence concertée de travail"));
658
                v.add(Tuple2.create("658", "[FP] Congé spécial"));
659
                v.add(Tuple2.create("659", "[FP] Période d'instruction militaire ou réserve opérationnelle"));
660
                v.add(Tuple2.create("660", "[FP] Congé avec traitement période d'instruction militaire obligatoire"));
661
                v.add(Tuple2.create("661", "[FP] Congé organisations de jeunesse"));
662
                v.add(Tuple2.create("662", "[FP] Congé pour siéger auprès d’une association, d’une mutuelle, d’une instance de l’Etat ou d’une collectivité territoriale"));
663
                v.add(Tuple2.create("663", "[FP] Congé non rémunéré de 18 jours pour mandats municipaux ou départementaux ou régionaux"));
664
                v.add(Tuple2.create("664", "[FP] Congé avec traitement pour période d'activité dans la réserve de sécurité civile"));
665
                v.add(Tuple2.create("665", "[FP] Congé pour période d'activité dans la réserve sanitaire"));
666
                v.add(Tuple2.create("666", "[FP] Congé pour recherches ou conversions thématiques"));
667
                v.add(Tuple2.create("667", "[FP] Congé pour raisons opérationnelles et activités privées des sapeurs"));
668
                v.add(Tuple2.create("668", "[FP] Congé pour raisons opérationnelles cotisé des sapeurs"));
669
                v.add(Tuple2.create("669", "[FP] Congé pour difficultés opérationnelles des sapeurs"));
670
                v.add(Tuple2.create("670", "[FP] Congé pour période d'activité dans la réserve civile de la police"));
671
                v.add(Tuple2.create("671", "[FP] Exclusion temporaire de fonctions"));
672
                v.add(Tuple2.create("672", "[FP] Suspension"));
673
                v.add(Tuple2.create("673", "[FP] Absences irrégulières (service non fait)"));
674
                v.add(Tuple2.create("674", "[FP] Détachement ne conduisant pas à pension (ENCP)"));
675
                v.add(Tuple2.create("675", "[FP] Disponibilité"));
676
                v.add(Tuple2.create("676", "[FP] Disponibilité pour maladie"));
677
                v.add(Tuple2.create("677", "[FP] Disponibilité pour élever un enfant âgé de moins de 8 ans"));
678
                v.add(Tuple2.create("678", "[FP] Position hors cadres"));
679
                v.add(Tuple2.create("680", "Congé sans solde cotisés"));
680
                v.add(Tuple2.create("681", "Détachement hors IEG"));
681
                v.add(Tuple2.create("998", "Annulation"));
682
 
683
                insertValues(v, table);
684
            } catch (SQLException ex) {
685
                throw new IllegalStateException("Erreur lors de la création de la table " + "CODE_SUSPENSION", ex);
686
            }
687
        }
688
 
132 ilm 689
        if (!root.contains("MOTIF_REPRISE_ARRET_TRAVAIL")) {
690
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "MOTIF_REPRISE_ARRET_TRAVAIL");
691
            createTableMotif.addVarCharColumn("CODE", 25);
692
            createTableMotif.addVarCharColumn("NOM", 512);
693
 
694
            try {
695
                root.getBase().getDataSource().execute(createTableMotif.asString());
696
                insertUndef(createTableMotif);
697
                root.refetchTable("MOTIF_REPRISE_ARRET_TRAVAIL");
698
                root.getSchema().updateVersion();
699
 
700
                final SQLTable table = root.getTable("MOTIF_REPRISE_ARRET_TRAVAIL");
701
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
702
                v.add(Tuple2.create("01", "reprise normale"));
703
                v.add(Tuple2.create("02", "reprise temps partiel thérapeutique"));
704
                v.add(Tuple2.create("03", "reprise temps partiel raison personnelle"));
705
                insertValues(v, table);
706
            } catch (SQLException ex) {
707
                throw new IllegalStateException("Erreur lors de la création de la table " + "MOTIF_REPRISE_ARRET_TRAVAIL", ex);
708
            }
709
        }
710
 
711
        if (!root.contains("MOTIF_FIN_CONTRAT")) {
712
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "MOTIF_FIN_CONTRAT");
713
            createTableMotif.addVarCharColumn("CODE", 25);
714
            createTableMotif.addVarCharColumn("NOM", 512);
715
 
716
            try {
717
                root.getBase().getDataSource().execute(createTableMotif.asString());
718
                insertUndef(createTableMotif);
719
                root.refetchTable("MOTIF_FIN_CONTRAT");
720
                root.getSchema().updateVersion();
721
 
722
                final SQLTable table = root.getTable("MOTIF_FIN_CONTRAT");
723
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
724
                v.add(Tuple2.create("011", "licenciement suite à liquidation judiciaire ou à redressement judiciaire"));
725
                v.add(Tuple2.create("012", "licenciement suite à fermeture définitive de l'établissement"));
726
                v.add(Tuple2.create("014", "licenciement pour motif économique"));
727
                v.add(Tuple2.create("015", "licenciement pour fin de chantier"));
728
                v.add(Tuple2.create("020", "licenciement pour autre motif"));
729
                v.add(Tuple2.create("025", "autre fin de contrat pour motif économique"));
730
                v.add(Tuple2.create("026", "rupture pour motif économique dans le cadre d’un contrat de sécurisation professionnelle CSP"));
731
                v.add(Tuple2.create("031", "fin de contrat à durée déterminée ou fin d'accueil occasionnel"));
732
                v.add(Tuple2.create("032", "fin de mission d'intérim"));
733
                v.add(Tuple2.create("033", "rupture anticipée d’un CDD ou d’un contrat de mission en cas d’inaptitude physique constatée par le médecin du travail"));
734
                v.add(Tuple2.create("034", "fin de période d'essai à l'initiative de l'employeur"));
735
                v.add(Tuple2.create("035", "fin de période d'essai à l'initiative du salarié"));
736
                v.add(Tuple2.create("036", " rupture anticipée d'un CDD, d'un contrat d'apprentissage ou d’un contrat de mission à l'initiative de l'employeur"));
737
                v.add(Tuple2.create("037", "rupture anticipée d'un CDD, d'un contrat d'apprentissage ou d’un contrat de mission à l'initiative du salarié"));
738
                v.add(Tuple2.create("038", "mise à la retraite par l'employeur"));
739
                v.add(Tuple2.create("039", "départ à la retraite à l'initiative du salarié"));
740
                v.add(Tuple2.create("043", "rupture conventionnelle"));
741
                v.add(Tuple2.create("058", "prise d'acte de la rupture de contrat de travail"));
742
                v.add(Tuple2.create("059", "démission"));
743
                v.add(Tuple2.create("065", "décès de l'employeur ou internement / conduit à un licenciement autre motif"));
744
                v.add(Tuple2.create("066", "décès du salarié / rupture force majeure"));
745
                v.add(Tuple2.create("081", "fin de contrat d'apprentissage"));
746
                v.add(Tuple2.create("082", "résiliation judiciaire du contrat de travail"));
747
                v.add(Tuple2.create("083", "rupture de contrat de travail ou d’un contrat de mission pour force majeure"));
748
                v.add(Tuple2.create("084", "rupture d'un commun accord du CDD, du contrat d'apprentissage ou d’un contrat de mission"));
749
                v.add(Tuple2.create("085", "fin de mandat"));
750
                v.add(Tuple2.create("086", "licenciement convention CATS"));
751
                v.add(Tuple2.create("087", "licenciement pour faute grave"));
752
                v.add(Tuple2.create("088", "licenciement pour faute lourde"));
753
                v.add(Tuple2.create("089", "licenciement pour force majeure"));
754
                v.add(Tuple2.create("091", "licenciement pour inaptitude physique d'origine non professionnelle"));
755
                v.add(Tuple2.create("092", "licenciement pour inaptitude physique d'origine professionnelle"));
756
                v.add(Tuple2.create("093", "licenciement suite à décision d'une autorité administrative"));
757
                v.add(Tuple2.create("094", "rupture anticipée du contrat de travail pour arrêt de tournage"));
758
                v.add(Tuple2.create("095", "rupture anticipée du contrat de travail ou d’un contrat de mission pour faute grave"));
759
                v.add(Tuple2.create("096", "rupture anticipée du contrat de travail ou d’un contrat de mission pour faute lourde"));
760
                v.add(Tuple2.create("097", "rupture anticipée d’un contrat de travail ou d’un contrat de mission suite à fermeture de l'établissement"));
761
                v.add(Tuple2.create("098", "retrait d'enfant"));
762
                v.add(Tuple2.create("998", "transfert du contrat de travail sans rupture du contrat vers un autre établissement n'effectuant pas encore de DSN"));
763
                v.add(Tuple2.create("999", "fin de relation avec l’employeur (autres que contrat de travail) pour les cas ne portant aucun impact sur l’Assurance chômage"));
764
                insertValues(v, table);
765
            } catch (SQLException ex) {
766
                throw new IllegalStateException("Erreur lors de la création de la table " + "MOTIF_FIN_CONTRAT", ex);
767
            }
768
        }
769
 
770
        DSNUpdateRubrique dsnUpdateRubrique = new DSNUpdateRubrique(root);
771
        dsnUpdateRubrique.updateRubriqueCotisation();
142 ilm 772
 
773
        // PHASE 3
156 ilm 774
        final SQLTable caisseCot = root.getTable("CAISSE_COTISATION");
142 ilm 775
        {
776
            SQLTable tableCaisseCotisation = root.findTable("CAISSE_COTISATION");
777
            if (!tableCaisseCotisation.contains("ORG_PROTECTION_SOCIALE")) {
778
                final AlterTable alterCaisse = new AlterTable(tableCaisseCotisation);
779
                alterCaisse.addBooleanColumn("ORG_PROTECTION_SOCIALE", Boolean.FALSE, false);
780
                alterCaisse.addBooleanColumn("URSSAF", Boolean.FALSE, false);
781
 
782
                root.getBase().getDataSource().execute(alterCaisse.asString());
783
                root.refetchTable("CAISSE_COTISATION");
784
                root.getSchema().updateVersion();
785
 
786
                {
787
                    UpdateBuilder upCaisse = new UpdateBuilder(tableCaisseCotisation);
788
                    upCaisse.setObject("ORG_PROTECTION_SOCIALE", Boolean.TRUE);
789
                    upCaisse.setWhere(new Where(tableCaisseCotisation.getField("NOM"), Arrays.asList("URSSAF", "AGIRC", "ARRCO")));
790
                    root.getBase().getDataSource().execute(upCaisse.asString());
791
                }
792
                {
793
                    UpdateBuilder upCaisse = new UpdateBuilder(tableCaisseCotisation);
794
                    upCaisse.setObject("URSSAF", Boolean.TRUE);
795
                    upCaisse.setWhere(new Where(tableCaisseCotisation.getField("NOM"), Arrays.asList("URSSAF")));
796
                    root.getBase().getDataSource().execute(upCaisse.asString());
797
                }
798
            }
799
            if (!root.contains("CAISSE_MODE_PAIEMENT")) {
800
                final SQLCreateTable createCaisseMode = new SQLCreateTable(root, "CAISSE_MODE_PAIEMENT");
801
                createCaisseMode.addVarCharColumn("CODE", 25);
802
                createCaisseMode.addVarCharColumn("NOM", 512);
803
 
804
                try {
805
                    root.getBase().getDataSource().execute(createCaisseMode.asString());
806
                    insertUndef(createCaisseMode);
807
                    root.refetchTable("CAISSE_MODE_PAIEMENT");
808
                    root.getSchema().updateVersion();
809
 
810
                    final SQLTable table = root.getTable("CAISSE_MODE_PAIEMENT");
811
                    List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
812
                    v.add(Tuple2.create("01", "chèque"));
813
                    v.add(Tuple2.create("02", "virement"));
814
                    v.add(Tuple2.create("03", "prélèvement"));
815
                    v.add(Tuple2.create("04", "titre inter-bancaire de paiement"));
816
                    v.add(Tuple2.create("05", "prélèvement SEPA"));
817
                    v.add(Tuple2.create("06", "versement réalisé par un autre établissement"));
818
 
819
                    insertValues(v, table);
820
                } catch (SQLException ex) {
821
                    throw new IllegalStateException("Erreur lors de la création de la table " + "CAISSE_MODE_PAIEMENT", ex);
822
                }
823
 
824
                final SQLCreateTable createCaisseREnseignement = new SQLCreateTable(root, "CAISSE_COTISATION_RENSEIGNEMENT");
825
                createCaisseREnseignement.addVarCharColumn("IDENTIFIANT", 256);
826
                createCaisseREnseignement.addVarCharColumn("SIRET", 256);
827
                createCaisseREnseignement.addVarCharColumn("BIC", 256);
828
                createCaisseREnseignement.addVarCharColumn("IBAN", 256);
829
                createCaisseREnseignement.addVarCharColumn("ENTITE_AFFECTATION", 256);
830
                createCaisseREnseignement.addBooleanColumn("ORGANISME_COMPLEMENTAIRE", Boolean.FALSE, false);
831
                createCaisseREnseignement.addBooleanColumn("PAIEMENT_TRIMESTRIEL", Boolean.FALSE, false);
832
                createCaisseREnseignement.addVarCharColumn("CODE_DELEGATAIRE", 256);
833
                createCaisseREnseignement.addForeignColumn("ID_CAISSE_MODE_PAIEMENT", root.getTable("CAISSE_MODE_PAIEMENT"));
156 ilm 834
                createCaisseREnseignement.addForeignColumn("ID_CAISSE_COTISATION", caisseCot);
142 ilm 835
                createCaisseREnseignement.addForeignColumn("ID_SOCIETE_COMMON", root.getTable("SOCIETE_COMMON"));
836
                root.getBase().getDataSource().execute(createCaisseREnseignement.asString());
837
                insertUndef(createCaisseREnseignement);
838
                root.refetchTable("CAISSE_COTISATION_RENSEIGNEMENT");
839
                root.getSchema().updateVersion();
840
            }
841
            SQLTable tableCR = root.getTable("CAISSE_COTISATION_RENSEIGNEMENT");
842
            if (!tableCR.contains("PAIEMENT_TRIMESTRIEL")) {
843
                AlterTable alter = new AlterTable(tableCR);
844
                alter.addBooleanColumn("PAIEMENT_TRIMESTRIEL", Boolean.FALSE, false);
845
                root.getBase().getDataSource().execute(alter.asString());
846
                root.refetchTable("CAISSE_COTISATION_RENSEIGNEMENT");
847
                root.getSchema().updateVersion();
848
            }
144 ilm 849
 
850
            if (!tableCR.contains("JOUR_PAIEMENT")) {
851
                AlterTable alter = new AlterTable(tableCR);
852
                alter.addIntegerColumn("JOUR_PAIEMENT", 0);
853
                root.getBase().getDataSource().execute(alter.asString());
854
                root.refetchTable("CAISSE_COTISATION_RENSEIGNEMENT");
855
                root.getSchema().updateVersion();
856
            }
142 ilm 857
        }
858
 
859
        if (!root.contains("TYPE_COMPOSANT_BASE_ASSUJETTIE")) {
860
            final SQLCreateTable createTableTypeComposant = new SQLCreateTable(root, "TYPE_COMPOSANT_BASE_ASSUJETTIE");
861
            createTableTypeComposant.addVarCharColumn("CODE", 25);
862
            createTableTypeComposant.addVarCharColumn("NOM", 512);
863
 
864
            try {
865
                root.getBase().getDataSource().execute(createTableTypeComposant.asString());
866
                insertUndef(createTableTypeComposant);
867
                root.refetchTable("TYPE_COMPOSANT_BASE_ASSUJETTIE");
868
                root.getSchema().updateVersion();
869
 
870
                final SQLTable table = root.getTable("TYPE_COMPOSANT_BASE_ASSUJETTIE");
871
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
872
 
873
                v.add(Tuple2.create("01", "Montant du SMIC retenu pour le calcul de la Réduction générale des cotisations patronales de sécurité sociale"));
874
                v.add(Tuple2.create("02", "Montant du SMIC retenu pour le calcul du crédit d'impôt compétitivité-emploi"));
875
                v.add(Tuple2.create("03", "Contributions patronales à des régimes complémentaires de retraite"));
876
                v.add(Tuple2.create("04", "Contributions patronales destinées au financement des prestations de prévoyance complémentaire"));
877
                v.add(Tuple2.create("05", "Contributions patronales destinées au financement des prestations de retraite supplémentaire"));
878
                v.add(Tuple2.create("06", "Plafond calculé pour salarié poly-employeurs"));
879
                v.add(Tuple2.create("10", "Salaire brut Prévoyance"));
880
                v.add(Tuple2.create("11", "Tranche A Prévoyance"));
881
                v.add(Tuple2.create("12", "Tranche 2 Prévoyance"));
882
                v.add(Tuple2.create("13", "Tranche B Prévoyance"));
883
                v.add(Tuple2.create("14", "Tranche C Prévoyance"));
884
                v.add(Tuple2.create("15", "Tranche D Prévoyance"));
885
                v.add(Tuple2.create("16", "Tranche D1 Prévoyance"));
886
                v.add(Tuple2.create("17", "Base spécifique Prévoyance"));
887
                v.add(Tuple2.create("18", "Base forfaitaire Prévoyance"));
888
                v.add(Tuple2.create("19", "Base fictive Prévoyance reconstituée"));
889
                v.add(Tuple2.create("20", "Montant forfaitaire Prévoyance"));
890
                v.add(Tuple2.create("21", "Montant Prévoyance libre ou exceptionnel"));
891
                v.add(Tuple2.create("22", "Montant des indemnités journalières CRPCEN"));
892
                v.add(Tuple2.create("90", "Retenue sur salaire"));
893
                v.add(Tuple2.create("91", "Base de taxe sur les salaires au taux normal"));
894
 
895
                insertValues(v, table);
896
 
897
                AlterTable tableRubCotis = new AlterTable(tableRubCot);
898
                tableRubCotis.addForeignColumn("ID_TYPE_COMPOSANT_BASE_ASSUJETTIE", root.getTable("TYPE_COMPOSANT_BASE_ASSUJETTIE"));
899
                root.getBase().getDataSource().execute(tableRubCotis.asString());
900
                root.refetchTable(tableRubCot.getName());
901
                root.getSchema().updateVersion();
902
            } catch (SQLException ex) {
903
                throw new IllegalStateException("Erreur lors de la création de la table " + "TYPE_COMPOSANT_BASE_ASSUJETTIE", ex);
904
            }
905
        }
906
        if (!root.contains("CODE_COTISATION_INDIVIDUELLE")) {
907
            final SQLCreateTable createTableTypeComposant = new SQLCreateTable(root, "CODE_COTISATION_INDIVIDUELLE");
908
            createTableTypeComposant.addVarCharColumn("CODE", 25);
909
            createTableTypeComposant.addVarCharColumn("NOM", 512);
910
 
911
            try {
912
                root.getBase().getDataSource().execute(createTableTypeComposant.asString());
913
                insertUndef(createTableTypeComposant);
914
                root.refetchTable("CODE_COTISATION_INDIVIDUELLE");
915
                root.getSchema().updateVersion();
916
 
917
                final SQLTable table = root.getTable("CODE_COTISATION_INDIVIDUELLE");
918
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
919
 
920
                v.add(Tuple2.create("001", "Exonération de cotisations au titre de l'emploi d'un apprenti (loi de 1979)"));
921
                v.add(Tuple2.create("002", "Exonération de cotisations au titre de l'emploi d'un apprenti (loi de 1987)"));
922
                v.add(Tuple2.create("003", "Exonération de cotisations au titre de l'emploi d'un apprenti (loi de 1992)"));
923
                v.add(Tuple2.create("004", "Exonération de cotisations au titre de l'emploi d'un salarié en contrat d'accès à l'emploi"));
924
                v.add(Tuple2.create("006", "Exonération de cotisations au titre de l'emploi d'un salarié en contrat d'accompagnement dans l'emploi"));
925
                v.add(Tuple2.create("008", "Exonération de cotisations au titre de l'emploi d'un salarié en contrat de professionnalisation"));
926
                v.add(Tuple2.create("009", "Exonération de cotisations applicable aux associations intermédiaires"));
927
                v.add(Tuple2.create("010", "Exonération de cotisations applicable aux entreprises des bassins d'emploi à redynamiser"));
928
                v.add(Tuple2.create("011", "Exonération de cotisations applicable au créateur ou repreneur d'entreprise"));
929
                v.add(Tuple2.create("012", "Exonération de cotisations applicable dans les DOM"));
930
                v.add(Tuple2.create("013", "Exonération de cotisations applicable aux entreprises et associations d'aide à domicile"));
931
                v.add(Tuple2.create("014", "Exonérations de cotisations applicable aux entreprises innovantes ou universitaires"));
932
                v.add(Tuple2.create("015", "Exonération de cotisations applicable aux entreprises en zones franches urbaines"));
933
                v.add(Tuple2.create("016", "Exonération de cotisations applicable aux organismes d'intérêt général en zones de revitalisation rurale"));
934
                v.add(Tuple2.create("017", "Exonération de cotisations applicable aux structures agréées de l'aide sociale"));
935
                v.add(Tuple2.create("018", "Réduction générale des cotisations patronales de sécurité sociale"));
936
                v.add(Tuple2.create("019", "Réduction de cotisations applicable aux entreprises des zones de restructuration de la défense"));
937
                v.add(Tuple2.create("020", "Réduction de cotisations au titre de l'embauche du 1er au 50ème salarié en zones de revitalisation rurale"));
938
                v.add(Tuple2.create("021", "Déduction patronale au titre des heures supplémentaires"));
939
                v.add(Tuple2.create("022", "Exonération de cotisations applicable à une gratification de stage"));
940
                v.add(Tuple2.create("023", "Exonération de cotisation des sommes provenant d'un CET et réaffectées à un PERCO ou à un régime de retraite supplémentaire"));
941
                v.add(Tuple2.create("025", "Exonération de cotisations au titre de l’emploi d’un salarié en chantier et atelier d'insertion"));
942
                v.add(Tuple2.create("027", "Exonération Personnel technique CUMA, hors ateliers"));
943
                v.add(Tuple2.create("028", "Réduction Travailleur Occasionnel"));
944
                v.add(Tuple2.create("029", "CNIEG Réduction employeurs petit pool"));
945
                v.add(Tuple2.create("030", "Camieg Cotisation employeurs Régime spécial Complémentaire"));
946
                v.add(Tuple2.create("031", "Camieg Cotisation salariés Régime spécial Complémentaire"));
947
                v.add(Tuple2.create("032", "Camieg Cotisation salariés Régime spécial Solidarité"));
948
                v.add(Tuple2.create("033", "CNIEG Cotisation employeurs complément d'invalidité"));
949
                v.add(Tuple2.create("034", "CNIEG Cotisation employeurs régime de droit commun (population adossée)"));
950
                v.add(Tuple2.create("035", "CNIEG Cotisation employeurs Régime spécial (population adossée)"));
951
                v.add(Tuple2.create("036", "CNIEG Cotisation employeurs régime spécial (population non adossée)"));
952
                v.add(Tuple2.create("037", "CNIEG Cotisation salariés régime de droit commun (population adossée)"));
953
                v.add(Tuple2.create("038", "CNIEG Cotisation salariés régime spécial (population non adossée)"));
954
                v.add(Tuple2.create("039", "CNIEG Cotisations employeurs petit pool"));
955
                v.add(Tuple2.create("040", "Cotisation AC : assurance chômage sur rémunérations brutes après déduction, limitées à 4 fois le plafond de la SS"));
956
                v.add(Tuple2.create("041", "Cotisation AC majorée 1 : application d’une majoration AC + 0,5% sur les contrats d’usage inférieurs ou égaux à 3 mois"));
957
                v.add(Tuple2.create("042", "Cotisation AC majorée 2 : application d’une majoration AC + 3% sur les contrats d’accroissement temporaire d’activité inférieurs ou égaux à 1 mois"));
958
                v.add(Tuple2.create("043",
959
                        "Cotisation AC majorée 3 : application d’une majoration AC + 1,5% sur les contrats d’accroissement temporaire d’activité supérieurs à 1 mois mais inférieurs ou égaux à 3 mois"));
960
                v.add(Tuple2.create("044", "Exonération de cotisation chômage pour les moins de 26 ans"));
961
                v.add(Tuple2.create("045", "Cotisation Accident du travail"));
962
                v.add(Tuple2.create("046", "Cotisation AEF Bourse de l'emploi"));
963
                v.add(Tuple2.create("047", "Cotisation AEF CESA"));
964
                v.add(Tuple2.create("048", "Cotisation AGS : assurance garantie des salaires sur rémunérations brutes après déduction, limitées à 4 fois le plafond de la sécurité sociale"));
965
                v.add(Tuple2.create("049", "Cotisation Allocation de logement (FNAL)"));
966
                v.add(Tuple2.create("051", "Cotisation Formation professionnelle ADEFA"));
967
                v.add(Tuple2.create("052", "Cotisation AFNCA, ANEFA, PROVEA, ASCPA"));
968
                v.add(Tuple2.create("053", "Cotisation Formation professionnelle additionnelle FAFSEA"));
969
                v.add(Tuple2.create("054", "Cotisation Formation professionnelle AREFA"));
970
                v.add(Tuple2.create("055", "Cotisation Formation professionnelle CEREFAR"));
971
                v.add(Tuple2.create("056", "Cotisation Formation professionnelle FAFSEA"));
972
                v.add(Tuple2.create("057", "Cotisation Formation professionnelle FAFSEA CDD"));
973
                v.add(Tuple2.create("058", "Cotisation Formation professionnelle FAFSEA des communes forestières"));
974
                v.add(Tuple2.create("059", "Cotisation individuelle Prévoyance-Assurance-Mutuelle pour la période et l'affiliation concernées"));
975
                v.add(Tuple2.create("060", "Cotisation IRCANTEC Tranche A"));
976
                v.add(Tuple2.create("061", "Cotisation IRCANTEC Tranche B"));
977
                v.add(Tuple2.create("063", "RETA Montant de cotisation Arrco"));
978
                v.add(Tuple2.create("064", "RETC Montant de cotisation Agirc"));
979
                v.add(Tuple2.create("065", "Cotisation CRPCEN"));
980
                v.add(Tuple2.create("066", "Cotisation caisse de congés spectacles"));
981
                v.add(Tuple2.create("068", "Contribution solidarité autonomie"));
982
                v.add(Tuple2.create("069", "Contribution sur avantage de pré-retraite entreprise à dater du 11/10/2007 (CAPE)"));
983
                v.add(Tuple2.create("070", "Contribution sur avantage de pré-retraite entreprise aux taux normal (CAPE)"));
984
                v.add(Tuple2.create("071", "Contribution forfait social"));
985
                v.add(Tuple2.create("072", "Contribution sociale généralisée/salaires partiellement déductibles"));
986
                v.add(Tuple2.create("073", "CSG/CRDS sur participation intéressement épargne salariale"));
987
                v.add(Tuple2.create("074", "Cotisation Allocation familiale taux normal  "));
988
                v.add(Tuple2.create("075", "Cotisation Assurance Maladie"));
989
                v.add(Tuple2.create("076", "Cotisation Assurance Vieillesse"));
990
                v.add(Tuple2.create("077", "Montant de la retenue à la source effectuée sur les salaires versés aux personnes domiciliées hors de France"));
991
                v.add(Tuple2.create("078", "Pénalité de 1% emploi sénior"));
992
                v.add(Tuple2.create("079", "Remboursement de la dette sociale"));
993
                v.add(Tuple2.create("081", "Versement transport"));
994
                v.add(Tuple2.create("082", "Versement transport additionnel"));
995
                v.add(Tuple2.create("086", "Cotisation pénibilité mono exposition"));
996
                v.add(Tuple2.create("087", "Cotisation pénibilité multi exposition"));
997
                v.add(Tuple2.create("088", "Exonération versement transport"));
998
                v.add(Tuple2.create("089", "Exonération Contrat Initiative Emploi"));
999
                v.add(Tuple2.create("090", "Exonération accueillants familiaux"));
1000
                v.add(Tuple2.create("091", "Cotisation Service de santé au travail"));
1001
                v.add(Tuple2.create("092", "Cotisation Association pour l'emploi des cadres ingénieurs et techniciens de l'agriculture (APECITA)"));
1002
                v.add(Tuple2.create("093", "Contribution sur indemnités de mise à la retraite"));
1003
                v.add(Tuple2.create("094", "Exonération cotisations Allocations familiales (SICAE)"));
1004
                v.add(Tuple2.create("096", "Cotisation CRPNPAC au fonds de retraite"));
1005
                v.add(Tuple2.create("097", "Cotisation CRPNPAC au fonds d'assurance"));
1006
                v.add(Tuple2.create("098", "Cotisation CRPNPAC au fonds de majoration"));
1007
                v.add(Tuple2.create("099", "Contribution stock options"));
1008
                v.add(Tuple2.create("100", "Contribution pour le financement des organisations syndicales de salariés et organisations professionnelles d'employeurs"));
1009
                v.add(Tuple2.create("101", "Association Mutualisation du Coût Inaptitude"));
1010
                v.add(Tuple2.create("102", "Cotisation Allocation Familiale - taux réduit"));
1011
                v.add(Tuple2.create("103", "Contribution actions gratuites"));
1012
                v.add(Tuple2.create("226", "Assiette du Versement Transport"));
1013
                v.add(Tuple2.create("901", "Cotisation épargne retraite"));
1014
 
1015
                insertValues(v, table);
1016
 
1017
                List<Tuple2<String, String>> vCodeBase = new ArrayList<Tuple2<String, String>>();
1018
                vCodeBase.add(Tuple2.create("15", "CNIEG-Assiette brute du régime spécial"));
1019
                vCodeBase.add(Tuple2.create("16", "CNIEG-Assiette brute du complément invalidité"));
1020
                vCodeBase.add(Tuple2.create("17", "CNIEG - Assiette brute du petit pool"));
1021
                vCodeBase.add(Tuple2.create("18", "Camieg - assiette brute plafonnée"));
1022
                vCodeBase.add(Tuple2.create("19", "Assiette CRPCEN"));
1023
                vCodeBase.add(Tuple2.create("20", "CIBTP - Base brute de cotisations congés payés"));
1024
                vCodeBase.add(Tuple2.create("21", "CIBTP - Base brute de cotisations OPPBTP permanents"));
1025
                vCodeBase.add(Tuple2.create("22", "Base brute spécifique"));
1026
                vCodeBase.add(Tuple2.create("23", "Base exceptionnelle (Agirc Arrco)"));
1027
                vCodeBase.add(Tuple2.create("24", "Base plafonnée spécifique"));
1028
                vCodeBase.add(Tuple2.create("25", "Assiette de contribution libératoire"));
1029
                vCodeBase.add(Tuple2.create("27", "Assiette Caisse de congés spectacles"));
1030
                vCodeBase.add(Tuple2.create("28", "Base IRCANTEC cotisée"));
1031
                vCodeBase.add(Tuple2.create("29", "Base IRCANTEC non cotisée (arrêt de travail)"));
1032
                vCodeBase.add(Tuple2.create("31", "Eléments de cotisation Prévoyance, Santé, retraite supplémentaire"));
1033
                vCodeBase.add(Tuple2.create("33", "Assiette Contribution sur les avantages de préretraite entreprise"));
1034
                vCodeBase.add(Tuple2.create("34", "CIBTP -Base plafonnée de cotisations intempéries gros oeuvre travaux publics"));
1035
                vCodeBase.add(Tuple2.create("35", "CIBTP -Base plafonnée de cotisations intempéries second oeuvre"));
1036
                vCodeBase.add(Tuple2.create("36", "CIBTP -Base \"A\" de cotisations organisme professionnel BTP"));
1037
                vCodeBase.add(Tuple2.create("37", "Assiette de pénibilité"));
1038
                vCodeBase.add(Tuple2.create("38", "Rémunération pour le calcul de la réduction Travailleur Occasionnel"));
1039
                vCodeBase.add(Tuple2.create("39", "CIBTP -Base \"B\" de cotisations organisme professionnel BTP"));
1040
                vCodeBase.add(Tuple2.create("40", "CIBTP -Base \"C\" de cotisations organisme professionnel BTP"));
1041
                vCodeBase.add(Tuple2.create("41", "CRPNPAC-Assiette soumise au taux normal (non-plafonnée)"));
1042
                vCodeBase.add(Tuple2.create("42", "CRPNPAC-Assiette soumise au taux majoré (non-plafonnée)"));
1043
                vCodeBase.add(Tuple2.create("43", "Base plafonnée exceptionnelle Agirc Arrco"));
1044
                vCodeBase.add(Tuple2.create("44", "Assiette du forfait social à 16%"));
1045
                vCodeBase.add(Tuple2.create("45", "Base plafonnée ICP Agirc-Arrco"));
1046
                vCodeBase.add(Tuple2.create("90", "Autre revenu net imposable"));
1047
                insertValues(vCodeBase, root.getTable("CODE_BASE_ASSUJETTIE"));
1048
 
1049
                AlterTable tableRubCotis = new AlterTable(tableRubCot);
1050
                tableRubCotis.addForeignColumn("ID_CODE_COTISATION_INDIVIDUELLE", root.getTable("CODE_COTISATION_INDIVIDUELLE"));
1051
                root.getBase().getDataSource().execute(tableRubCotis.asString());
1052
                root.refetchTable(tableRubCot.getName());
1053
                root.getSchema().updateVersion();
1054
            } catch (SQLException ex) {
1055
                throw new IllegalStateException("Erreur lors de la création de la table " + "CODE_COTISATION_INDIVIDUELLE", ex);
1056
            }
1057
            {
1058
                final SQLTable tableCodeBase = root.getTable("CODE_BASE_ASSUJETTIE");
1059
                SQLSelect selCodeBase = new SQLSelect();
1060
                selCodeBase.addSelectStar(tableCodeBase);
1061
                List<SQLRow> rowsCodeBase = SQLRowListRSH.execute(selCodeBase);
1062
                Map<String, SQLRow> mapCodeBase = new HashMap<String, SQLRow>();
1063
                for (SQLRow sqlRow : rowsCodeBase) {
1064
 
1065
                    final String string = sqlRow.getString("CODE");
1066
                    mapCodeBase.put(string, sqlRow);
1067
                }
1068
                final SQLTable tableCodeTypeComp = root.getTable("TYPE_COMPOSANT_BASE_ASSUJETTIE");
1069
                SQLSelect selCodeTypeComp = new SQLSelect();
1070
                selCodeTypeComp.addSelectStar(tableCodeTypeComp);
1071
                List<SQLRow> rowsTypeComp = SQLRowListRSH.execute(selCodeTypeComp);
1072
                Map<String, SQLRow> mapTypeComp = new HashMap<String, SQLRow>();
1073
                for (SQLRow sqlRow : rowsTypeComp) {
1074
                    final String string = sqlRow.getString("CODE");
1075
                    mapTypeComp.put(string, sqlRow);
1076
                }
1077
                final SQLTable tableCodeCotInd = root.getTable("CODE_COTISATION_INDIVIDUELLE");
1078
                SQLSelect selCodeCodeInd = new SQLSelect();
1079
                selCodeCodeInd.addSelectStar(tableCodeCotInd);
1080
                List<SQLRow> rowsCodeInd = SQLRowListRSH.execute(selCodeCodeInd);
1081
                Map<String, SQLRow> mapCodeInd = new HashMap<String, SQLRow>();
1082
                for (SQLRow sqlRow : rowsCodeInd) {
1083
                    final String string = sqlRow.getString("CODE");
1084
                    mapCodeInd.put(string, sqlRow);
1085
                }
156 ilm 1086
                final SQLTable tableCaisse = caisseCot;
142 ilm 1087
                SQLSelect selCodeCodeCaisse = new SQLSelect();
1088
                selCodeCodeCaisse.addSelectStar(tableCaisse);
1089
                List<SQLRow> rowsCodeCaisse = SQLRowListRSH.execute(selCodeCodeCaisse);
1090
                Map<String, SQLRow> mapCodeCaisse = new HashMap<String, SQLRow>();
1091
                for (SQLRow sqlRow : rowsCodeCaisse) {
1092
                    final String string = sqlRow.getString("NOM");
1093
                    mapCodeCaisse.put(string, sqlRow);
1094
                }
1095
                if (mapCodeCaisse.containsKey("ARRCO")) {
1096
                    UpdateBuilder updaterRubCot = new UpdateBuilder(tableRubCot);
1097
                    updaterRubCot.setObject("ID_CODE_BASE_ASSUJETTIE", mapCodeBase.get("02").getID());
1098
                    updaterRubCot.setObject("ID_CODE_COTISATION_INDIVIDUELLE", mapCodeInd.get("063").getID());
1099
                    // updaterRubCot.setObject("ID_TYPE_COMPOSANT_BASE_ASSUJETTIE",
1100
                    // mapTypeComp.get("03").getID());
1101
                    updaterRubCot.setWhere(new Where(tableRubCot.getField("ID_CAISSE_COTISATION"), "=", mapCodeCaisse.get("ARRCO").getID()));
1102
                    root.getBase().getDataSource().execute(updaterRubCot.asString());
1103
                }
1104
                if (mapCodeCaisse.containsKey("AGIRC")) {
1105
                    UpdateBuilder updaterRubCot = new UpdateBuilder(tableRubCot);
1106
                    updaterRubCot.setObject("ID_CODE_BASE_ASSUJETTIE", mapCodeBase.get("03").getID());
1107
                    updaterRubCot.setObject("ID_CODE_COTISATION_INDIVIDUELLE", mapCodeInd.get("064").getID());
1108
                    // updaterRubCot.setObject("ID_TYPE_COMPOSANT_BASE_ASSUJETTIE",
1109
                    // mapTypeComp.get("03").getID());
1110
                    updaterRubCot.setWhere(new Where(tableRubCot.getField("ID_CAISSE_COTISATION"), "=", mapCodeCaisse.get("AGIRC").getID()));
1111
                    root.getBase().getDataSource().execute(updaterRubCot.asString());
1112
                }
1113
            }
1114
        }
1115
 
1116
        if (!tableRubNet.contains("ID_CODE_COTISATION_INDIVIDUELLE")) {
1117
            AlterTable alterRubNet = new AlterTable(tableRubNet);
1118
            alterRubNet.addForeignColumn("ID_CODE_COTISATION_INDIVIDUELLE", root.getTable("CODE_COTISATION_INDIVIDUELLE"));
1119
            root.getBase().getDataSource().execute(alterRubNet.asString());
1120
            root.refetchTable(tableRubNet.getName());
1121
            root.getSchema().updateVersion();
1122
        }
1123
        if (!tableRubNet.contains("ID_TYPE_COMPOSANT_BASE_ASSUJETTIE")) {
1124
            AlterTable alterRubNet = new AlterTable(tableRubNet);
1125
            alterRubNet.addForeignColumn("ID_TYPE_COMPOSANT_BASE_ASSUJETTIE", root.getTable("TYPE_COMPOSANT_BASE_ASSUJETTIE"));
1126
            root.getBase().getDataSource().execute(alterRubNet.asString());
1127
            root.refetchTable(tableRubNet.getName());
1128
            root.getSchema().updateVersion();
1129
        }
1130
        if (!tableRubNet.contains("ID_CODE_BASE_ASSUJETTIE")) {
1131
            AlterTable alterRubNet = new AlterTable(tableRubNet);
1132
            alterRubNet.addForeignColumn("ID_CODE_BASE_ASSUJETTIE", root.getTable("CODE_BASE_ASSUJETTIE"));
1133
            root.getBase().getDataSource().execute(alterRubNet.asString());
1134
            root.refetchTable(tableRubNet.getName());
1135
            root.getSchema().updateVersion();
1136
        }
1137
 
1138
        if (!tableRubNet.contains("ID_CAISSE_COTISATION")) {
1139
            AlterTable alterRubNet = new AlterTable(tableRubNet);
156 ilm 1140
            alterRubNet.addForeignColumn("ID_CAISSE_COTISATION", caisseCot);
142 ilm 1141
            root.getBase().getDataSource().execute(alterRubNet.asString());
1142
            root.refetchTable(tableRubNet.getName());
1143
            root.getSchema().updateVersion();
1144
        }
1145
 
1146
        if (!root.contains("CODE_COTISATION_ETABLISSEMENT")) {
1147
            final SQLCreateTable createTableTypeComposant = new SQLCreateTable(root, "CODE_COTISATION_ETABLISSEMENT");
1148
            createTableTypeComposant.addVarCharColumn("CODE", 25);
1149
            createTableTypeComposant.addVarCharColumn("NOM", 512);
1150
 
1151
            try {
1152
                root.getBase().getDataSource().execute(createTableTypeComposant.asString());
1153
                insertUndef(createTableTypeComposant);
1154
                root.refetchTable("CODE_COTISATION_ETABLISSEMENT");
1155
                root.getSchema().updateVersion();
1156
 
1157
                final SQLTable table = root.getTable("CODE_COTISATION_ETABLISSEMENT");
1158
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
1159
 
1160
                v.add(Tuple2.create("001", "Cotisation ADPFA (Association pour le Développement du Paritarisme des Fleuristes et Animaliers)"));
1161
                v.add(Tuple2.create("002", "Cotisation APNAB (Association Paritaire Nationale pour le développement de la négociation collective dans l'Artisanat du Bâtiment)"));
1162
                v.add(Tuple2.create("003 ", "Cotisation sur assiette avec congés payés CCCA-BTP (Comité de Concertation et de Coordination de l'apprentissage du Bâtiment et des Travaux Publics)"));
1163
                v.add(Tuple2.create("004 ", "Cotisation CPPNTT (Commission Paritaire Professionnelle Nationale du Travail Temporaire)"));
1164
                v.add(Tuple2.create("005 ", "Cotisation Développement du paritarisme"));
1165
                v.add(Tuple2.create("006 ", "Cotisation Dialogue social"));
1166
                v.add(Tuple2.create("007 ", "Cotisation FAF (Fonds d'Assurance formation)"));
1167
                v.add(Tuple2.create("009 ", "Cotisation FAPS (Fonds d'action professionnelle et sociale)"));
1168
                v.add(Tuple2.create("010 ", "Cotisation FASTT (Fonds d'Action Sociale du Travail Temporaire)"));
1169
                v.add(Tuple2.create("011 ", "Cotisation Fonds de péréquation"));
1170
                v.add(Tuple2.create("012 ", "Cotisation IFC (Indemnités de fin de carrière)"));
1171
                v.add(Tuple2.create("017 ", "Cotisation ORGA (Organisations Syndicales  du Travail Temporaire)"));
1172
                v.add(Tuple2.create("018 ", "Cotisation Promotion et recrutement"));
1173
                v.add(Tuple2.create("019 ", "Cotisations attachées à une population de non salariés ayants"));
1174
                v.add(Tuple2.create("020 ", "Cotisations attachées à une population de non salariés retraités"));
1175
                v.add(Tuple2.create("021 ", "Cotisations FMSE (Fond national agricole de mutualisation des risques sanitaires et environnementaux)"));
1176
                v.add(Tuple2.create("022 ", "Cotisations VAL'HOR (association française pour la valorisation des produits et métiers de l'horticulture et du paysage)"));
1177
                v.add(Tuple2.create("023 ", "Chiffre d'affaire"));
1178
                v.add(Tuple2.create("024 ", "Nombre d'heures d'intérim"));
1179
                v.add(Tuple2.create("025 ", "Contribution aux régimes supplémentaires de retraite à prestations définies - Rente"));
1180
                v.add(Tuple2.create("026 ", "Contribution aux régimes supplémentaires de retraite à prestations définies - Prime"));
1181
                v.add(Tuple2.create("027 ", "Contribution aux régimes supplémentaires de retraite à prestations définies - Dotations"));
1182
                v.add(Tuple2.create("028 ", "Contribution additionnelle sur les rentes liquidées"));
1183
                v.add(Tuple2.create("029 ", "Contribution aux régimes supplémentaires de retraite à prestations définies. Rente à taux 7%"));
1184
                v.add(Tuple2.create("030 ", "Contribution aux régimes supplémentaires de retraite à prestations définies. Rente à taux 14%"));
1185
                v.add(Tuple2.create("031 ", "Contribution additionnelle de solidarité pour l'autonomie"));
1186
                v.add(Tuple2.create("032 ", "Contribution Sociale généralisée au taux de 3,80% + RDS sur revenu de remplacement "));
1187
                v.add(Tuple2.create("033 ", "Contribution Sociale généralisée au taux de 6,20% + RDS sur revenu de remplacement "));
1188
                v.add(Tuple2.create("034 ", "Contribution Sociale généralisée au taux de 6,60% + RDS sur revenu de remplacement "));
1189
                v.add(Tuple2.create("035 ", "Contribution Sociale généralisée au taux de 7,50% + RDS sur revenu de remplacement "));
1190
                v.add(Tuple2.create("036 ", "Cotisation TTC sur assiette CDD avec congés payés pour le secteur du BTP (Constructys Organisme Paritaire Collecteur Agréé pour le BTP)"));
1191
                v.add(Tuple2.create("037 ", "Cotisation TTC sur assiette avec congés payés pour le secteur du BTP (Constructys Organisme Paritaire Collecteur Agréé pour le BTP)"));
1192
                v.add(Tuple2.create("038 ", "Cotisation TTC  sur assiette sans  congés payés (Constructys Organisme Paritaire Collecteur Agréé pour le BTP)"));
1193
                v.add(Tuple2.create("039 ",
1194
                        "Cotisation TTC  sur assiette avec congés payés pour les salariés non soumis à la cotisation CCCA-BTP (Constructys Organisme Paritaire Collecteur Agréé pour le BTP)"));
1195
                v.add(Tuple2.create("040 ",
1196
                        "Cotisation TTC  sur assiette hors congés payés pour les salariés non soumis à la cotisation CCCA-BTP (Constructys Organisme Paritaire Collecteur Agréé pour le BTP)"));
1197
                v.add(Tuple2.create("041 ", "Cotisation maladie sur les avantages de préretraite"));
1198
                v.add(Tuple2.create("042 ", "Cotisation maladie sur les avantages de retraite"));
1199
                v.add(Tuple2.create("043 ", "Cotisation maladie Alsace-Moselle sur les avantages de retraite"));
1200
                v.add(Tuple2.create("044 ", "Cotisation forfait social à 8%"));
1201
                v.add(Tuple2.create("045 ", "Cotisation forfait social à 20%"));
1202
                v.add(Tuple2.create("090 ", "Cotisation spécifique Prévoyance"));
1203
 
1204
                insertValues(v, table);
1205
 
1206
                AlterTable tableRubCotis = new AlterTable(tableRubCot);
1207
                tableRubCotis.addForeignColumn("ID_CODE_COTISATION_ETABLISSEMENT", root.getTable("CODE_COTISATION_ETABLISSEMENT"));
1208
                root.getBase().getDataSource().execute(tableRubCotis.asString());
1209
                root.refetchTable(tableRubCot.getName());
1210
                root.getSchema().updateVersion();
1211
            } catch (SQLException ex) {
1212
                throw new IllegalStateException("Erreur lors de la création de la table " + "CODE_COTISATION_ETABLISSEMENT", ex);
1213
            }
1214
        }
1215
 
1216
        if (!root.contains("CODE_PENIBILITE")) {
1217
            final SQLCreateTable createTableTypeComposant = new SQLCreateTable(root, "CODE_PENIBILITE");
1218
            createTableTypeComposant.addVarCharColumn("CODE", 25);
1219
            createTableTypeComposant.addVarCharColumn("NOM", 512);
1220
 
1221
            try {
1222
                root.getBase().getDataSource().execute(createTableTypeComposant.asString());
1223
                insertUndef(createTableTypeComposant);
1224
                root.refetchTable("CODE_PENIBILITE");
1225
                root.getSchema().updateVersion();
1226
 
1227
                final SQLTable table = root.getTable("CODE_PENIBILITE");
1228
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
1229
 
1230
                v.add(Tuple2.create("01", "les manutentions manuelles de charges"));
1231
                v.add(Tuple2.create("02", "les postures pénibles (positions forcées des articulations)"));
1232
                v.add(Tuple2.create("03", "les vibrations mécaniques"));
1233
                v.add(Tuple2.create("04", "les agents chimiques dangereux"));
1234
                v.add(Tuple2.create("05", "les activités exercées en milieu hyperbare"));
1235
                v.add(Tuple2.create("06", "les températures extrêmes"));
1236
                v.add(Tuple2.create("07", "le bruit"));
1237
                v.add(Tuple2.create("08", "le travail de nuit"));
1238
                v.add(Tuple2.create("09", "le travail en équipes successives alternantes"));
1239
                v.add(Tuple2.create("10", "le travail répétitif (répétition d'un même geste, à une cadence contrainte avec un temps de cycle défini)"));
1240
                v.add(Tuple2.create("99", "annulation"));
1241
 
1242
                insertValues(v, table);
1243
 
1244
            } catch (SQLException ex) {
1245
                throw new IllegalStateException("Erreur lors de la création de la table " + "CODE_PENIBILITE", ex);
1246
            }
1247
        }
1248
 
1249
        if (!root.contains("AYANT_DROIT_TYPE")) {
1250
            final SQLCreateTable createTableTypeAyantDroit = new SQLCreateTable(root, "AYANT_DROIT_TYPE");
1251
            createTableTypeAyantDroit.addVarCharColumn("CODE", 25);
1252
            createTableTypeAyantDroit.addVarCharColumn("NOM", 512);
1253
 
1254
            try {
1255
                root.getBase().getDataSource().execute(createTableTypeAyantDroit.asString());
1256
                insertUndef(createTableTypeAyantDroit);
1257
                root.refetchTable("AYANT_DROIT_TYPE");
1258
                root.getSchema().updateVersion();
1259
 
1260
                final SQLTable table = root.getTable("AYANT_DROIT_TYPE");
1261
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
1262
 
1263
                v.add(Tuple2.create("01", "Adultes (conjoint, concubin, pacs)"));
1264
                v.add(Tuple2.create("02", "Enfant"));
1265
                v.add(Tuple2.create("03", "Autre (ascendant, collatéraux, ...)"));
1266
 
1267
                insertValues(v, table);
1268
 
1269
            } catch (SQLException ex) {
1270
                throw new IllegalStateException("Erreur lors de la création de la table " + "AYANT_DROIT_TYPE", ex);
1271
            }
1272
        }
1273
 
156 ilm 1274
        if (!root.contains("TYPE_TAUX_PAS")) {
1275
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "TYPE_TAUX_PAS");
1276
            createTableMotif.addVarCharColumn("CODE", 25);
1277
            createTableMotif.addVarCharColumn("NOM", 512);
1278
 
1279
            try {
1280
                root.getBase().getDataSource().execute(createTableMotif.asString());
1281
                insertUndef(createTableMotif);
1282
                root.refetchTable("TYPE_TAUX_PAS");
1283
                root.getSchema().updateVersion();
1284
 
1285
                final SQLTable table = root.getTable("TYPE_TAUX_PAS");
1286
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
1287
                v.add(Tuple2.create("01", " Taux transmis par la DGFIP"));
1288
                v.add(Tuple2.create("10", " Barème horaire métropole"));
1289
                v.add(Tuple2.create("11", " Barème quotidien métropole"));
1290
                v.add(Tuple2.create("12", " Barème hebdomadaire métropole"));
1291
                v.add(Tuple2.create("13", " Barème mensuel métropole"));
1292
                v.add(Tuple2.create("14", " Barème trimestriel métropole"));
1293
                v.add(Tuple2.create("15", " Barème semestriel métropole"));
1294
                v.add(Tuple2.create("16", " Barème annuel métropole"));
1295
                v.add(Tuple2.create("17", " Barème mathématique sur base mensuelle métropole"));
1296
                v.add(Tuple2.create("18", " Barème mathématique sur base annuelle métropole"));
1297
                v.add(Tuple2.create("20", " Barème horaire Guadeloupe, Réunion et Martinique"));
1298
                v.add(Tuple2.create("21", " Barème quotidien Guadeloupe, Réunion et Martinique"));
1299
                v.add(Tuple2.create("22", " Barème hebdomadaire Guadeloupe, Réunion et Martinique"));
1300
                v.add(Tuple2.create("23", " Barème mensuel Guadeloupe, Réunion et Martinique"));
1301
                v.add(Tuple2.create("24", " Barème trimestriel Guadeloupe, Réunion et Martinique"));
1302
                v.add(Tuple2.create("25", " Barème semestriel Guadeloupe, Réunion et Martinique"));
1303
                v.add(Tuple2.create("26", " Barème annuel Guadeloupe, Réunion et Martinique"));
1304
                v.add(Tuple2.create("27", " Barème mathématique sur base mensuelle Guadeloupe, Réunion et Martinique"));
1305
                v.add(Tuple2.create("28", " Barème mathématique sur base annuelle Guadeloupe, Réunion et Martinique"));
1306
                v.add(Tuple2.create("30", " Barème horaire Guyane et Mayotte"));
1307
                v.add(Tuple2.create("31", " Barème quotidien Guyane et Mayotte"));
1308
                v.add(Tuple2.create("32", " Barème hebdomadaire Guyane et Mayotte"));
1309
                v.add(Tuple2.create("33", " Barème mensuel Guyane et Mayotte"));
1310
                v.add(Tuple2.create("34", " Barème trimestriel Guyane et Mayotte"));
1311
                v.add(Tuple2.create("35", " Barème semestriel Guyane et Mayotte"));
1312
                v.add(Tuple2.create("36", " Barème annuel Guyane et Mayotte"));
1313
                v.add(Tuple2.create("37", " Barème mathématique sur base mensuelle Guyane et Mayotte"));
1314
                v.add(Tuple2.create("38", " Barème mathématique sur base annuelle Guyane et Mayotte"));
1315
                v.add(Tuple2.create("99", " Indu relatif à un exercice antérieur – pas de taux de PAS"));
1316
 
1317
                insertValues(v, table);
1318
            } catch (SQLException ex) {
1319
                throw new IllegalStateException("Erreur lors de la création de la table " + "TYPE_TAUX_PAS", ex);
1320
            }
1321
        }
1322
 
1323
        // P19V01.2
1324
        final SQLTable tableCotInd = root.getTable("CODE_COTISATION_INDIVIDUELLE");
1325
        List<Tuple2<String, String>> vCodeIndiv = new ArrayList<>();
1326
        vCodeIndiv.add(Tuple2.create("104", "Pénibilité Cotisation de base"));
1327
        vCodeIndiv.add(Tuple2.create("105", "Montant de cotisation Régime Unifié Agirc-Arrco y compris Apec"));
1328
        vCodeIndiv.add(Tuple2.create("106", "Réduction générale des cotisations patronales Agirc-Arrco"));
1329
        insertValues(vCodeIndiv, tableCotInd);
1330
 
1331
        final SQLTable tableCTP = root.getTable("CODE_CAISSE_TYPE_RUBRIQUE");
1332
        List<Tuple2<String, String>> vCTP = new ArrayList<>();
1333
        vCTP.add(Tuple2.create("003", "Réduction cotisations salariale heures supplémentaires"));
1334
        vCTP.add(Tuple2.create("510", "Prime exceptionnelle de pouvoir d’achat"));
177 ilm 1335
        vCTP.add(Tuple2.create("060", "RR Chômage CSG-CRDS taux plein"));
156 ilm 1336
        insertValues(vCTP, tableCTP);
1337
 
1338
        final SQLTable tableTypeBrut = root.getTable("CODE_TYPE_RUBRIQUE_BRUT");
1339
        List<Tuple3<String, String, String>> vbrutType = new ArrayList<>();
1340
        vbrutType.add(Tuple3.create("016", "[FP] Heures affectées à un travail d’aide à domicile", DsnTypeCodeBrut.REMUNERATION.getName()));
1341
        vbrutType.add(Tuple3.create("017", "Heures supplémentaires ou complémentaires aléatoires", DsnTypeCodeBrut.REMUNERATION.getName()));
1342
        vbrutType.add(Tuple3.create("018", "Heures supplémentaires structurelles", DsnTypeCodeBrut.REMUNERATION.getName()));
177 ilm 1343
        vbrutType.add(Tuple3.create("019", "Heures d'activité partielle", DsnTypeCodeBrut.REMUNERATION.getName()));
1344
        vbrutType.add(Tuple3.create("020", "Heures affectées à un travail d’aide à domicile de publics fragiles", DsnTypeCodeBrut.REMUNERATION.getName()));
156 ilm 1345
        DsnBrutCode dsnBurCode = new DsnBrutCode();
1346
        dsnBurCode.updateTable(vbrutType, tableTypeBrut);
1347
 
132 ilm 1348
    }
1349
 
1350
    public void updateDSN(final DBRoot root) throws SQLException {
1351
        final SQLTable tableCodeStatutCat = root.getTable("CODE_STATUT_CATEGORIEL");
1352
        SQLRow rowNonCadre = tableCodeStatutCat.getRow(4);
1353
        if (rowNonCadre != null) {
1354
            rowNonCadre.createEmptyUpdateRow().put("CODE", "04").commit();
1355
        }
1356
        SQLRow rowSansStatut = tableCodeStatutCat.getRow(4);
1357
        if (rowSansStatut != null) {
1358
            rowSansStatut.createEmptyUpdateRow().put("CODE", "99").commit();
1359
        }
142 ilm 1360
        // 04 non cadre
1361
        UpdateBuilder up04 = new UpdateBuilder(tableCodeStatutCat);
1362
        up04.setObject("NOM", "Non cadre");
1363
        up04.setWhere(new Where(tableCodeStatutCat.getField("CODE"), "=", "04"));
1364
        root.getBase().getDataSource().execute(up04.asString());
132 ilm 1365
 
142 ilm 1366
        // 99 - pas de retraite complémentaire
1367
        UpdateBuilder up99 = new UpdateBuilder(tableCodeStatutCat);
1368
        up99.setObject("NOM", "Pas de retraite complémentaire");
1369
        up99.setWhere(new Where(tableCodeStatutCat.getField("CODE"), "=", "99"));
1370
        root.getBase().getDataSource().execute(up99.asString());
1371
 
132 ilm 1372
        if (!root.contains("ARRET_TRAVAIL")) {
1373
 
1374
            final SQLCreateTable createTable = new SQLCreateTable(root, "ARRET_TRAVAIL");
1375
            createTable.addForeignColumn("SALARIE");
1376
            createTable.addDateAndTimeColumn("DATE_DERNIER_JOUR_TRAV");
1377
            createTable.addDateAndTimeColumn("DATE_FIN_PREV");
1378
            createTable.addBooleanColumn("SUBROGATION", Boolean.FALSE, false);
1379
            createTable.addDateAndTimeColumn("DATE_DEBUT_SUBROGATION");
1380
            createTable.addDateAndTimeColumn("DATE_FIN_SUBROGATION");
1381
            createTable.addForeignColumn("ID_MOTIF_ARRET_TRAVAIL", root.findTable("MOTIF_ARRET_TRAVAIL"));
1382
            createTable.addForeignColumn("ID_MOTIF_REPRISE_ARRET_TRAVAIL", root.findTable("MOTIF_REPRISE_ARRET_TRAVAIL"));
1383
            createTable.addDateAndTimeColumn("DATE_REPRISE");
1384
            createTable.addDateAndTimeColumn("DATE_ACCIDENT");
1385
 
1386
            try {
1387
                root.getBase().getDataSource().execute(createTable.asString());
1388
                insertUndef(createTable);
1389
                root.refetchTable("ARRET_TRAVAIL");
1390
                root.getSchema().updateVersion();
1391
            } catch (SQLException ex) {
1392
                throw new IllegalStateException("Erreur lors de la création de la table " + "ARRET_TRAVAIL", ex);
1393
            }
1394
        }
1395
 
142 ilm 1396
        if (!root.contains("FIN_CONTRAT")) {
1397
 
1398
            final SQLCreateTable createTable = new SQLCreateTable(root, "FIN_CONTRAT");
1399
            createTable.addForeignColumn("FICHE_PAYE");
1400
            createTable.addForeignColumn("ID_MOTIF_FIN_CONTRAT", root.findTable("MOTIF_FIN_CONTRAT"));
1401
            createTable.addDateAndTimeColumn("DATE_FIN");
1402
            createTable.addDateAndTimeColumn("DATE_NOTIFICATION");
1403
            createTable.addDateAndTimeColumn("DATE_SIGNATURE_CONVENTION");
1404
            createTable.addDateAndTimeColumn("DATE_ENGAGEMENT_PROCEDURE");
1405
            createTable.addDateAndTimeColumn("DERNIER_JOUR_TRAV_PAYE");
1406
            createTable.addBooleanColumn("TRANSACTION_EN_COURS", Boolean.FALSE, false);
1407
            createTable.addBooleanColumn("PORTABILITE_PREVOYANCE", Boolean.FALSE, false);
1408
            createTable.addIntegerColumn("NB_DIF_RESTANT", null, true);
1409
            createTable.addIntegerColumn("NB_MOIS_CSP", null, true);
1410
            createTable.addDecimalColumn("SALAIRE_NET_HORAIRE", 16, 8, null, true);
1411
            createTable.addDecimalColumn("INDEMNITE_VERSE", 16, 8, null, true);
1412
            createTable.addForeignColumn("ID_TYPE_PREAVIS", root.findTable("TYPE_PREAVIS"));
1413
            createTable.addDateAndTimeColumn("DATE_DEBUT_PREAVIS");
1414
            createTable.addDateAndTimeColumn("DATE_FIN_PREAVIS");
1415
            createTable.addVarCharColumn("INFOS", 2048);
1416
 
1417
            try {
1418
                root.getBase().getDataSource().execute(createTable.asString());
1419
                insertUndef(createTable);
1420
                root.refetchTable("FIN_CONTRAT");
1421
                root.getSchema().updateVersion();
1422
            } catch (SQLException ex) {
1423
                throw new IllegalStateException("Erreur lors de la création de la table " + "FIN_CONTRAT", ex);
1424
            }
1425
        }
1426
 
132 ilm 1427
        if (!root.contains("REPRISE_TRAVAIL")) {
1428
 
1429
            final SQLCreateTable createTable = new SQLCreateTable(root, "REPRISE_TRAVAIL");
1430
            createTable.addForeignColumn("SALARIE");
1431
            createTable.addDateAndTimeColumn("DATE_DERNIER_JOUR_TRAV");
1432
            createTable.addDateAndTimeColumn("DATE_FIN_PREV");
1433
            createTable.addBooleanColumn("SUBROGATION", Boolean.FALSE, false);
1434
            createTable.addDateAndTimeColumn("DATE_DEBUT_SUBROGATION");
1435
            createTable.addDateAndTimeColumn("DATE_FIN_SUBROGATION");
1436
            createTable.addForeignColumn("ID_MOTIF_ARRET_TRAVAIL", root.findTable("MOTIF_ARRET_TRAVAIL"));
1437
            createTable.addForeignColumn("ID_MOTIF_REPRISE_ARRET_TRAVAIL", root.findTable("MOTIF_REPRISE_ARRET_TRAVAIL"));
1438
            createTable.addDateAndTimeColumn("DATE_REPRISE");
1439
            createTable.addDateAndTimeColumn("DATE_ACCIDENT");
1440
            createTable.addDateAndTimeColumn("DATE");
1441
            createTable.addVarCharColumn("COMMENTAIRES", 2048);
1442
 
1443
            try {
1444
                root.getBase().getDataSource().execute(createTable.asString());
1445
                insertUndef(createTable);
1446
                root.refetchTable("REPRISE_TRAVAIL");
1447
                root.getSchema().updateVersion();
1448
            } catch (SQLException ex) {
1449
                throw new IllegalStateException("Erreur lors de la création de la table " + "REPRISE_TRAVAIL", ex);
1450
            }
1451
        }
1452
 
1453
        if (!root.contains("DECLARATION_DSN")) {
1454
 
1455
            final SQLCreateTable createTable = new SQLCreateTable(root, "DECLARATION_DSN");
1456
            createTable.addForeignColumn("ID_DSN_NATURE", root.findTable("DSN_NATURE"));
1457
 
1458
            createTable.addDateAndTimeColumn("DATE");
1459
            createTable.addDateAndTimeColumn("DATE_ENVOI");
1460
            createTable.addBooleanColumn("TEST", Boolean.FALSE, false);
1461
            createTable.addBooleanColumn("ENVOYE", Boolean.FALSE, false);
1462
            createTable.addVarCharColumn("COMMENTAIRE", 1024);
1463
            createTable.addVarCharColumn("DSN_FILE", 75000);
1464
            createTable.addIntegerColumn("NUMERO", 1);
1465
            createTable.addIntegerColumn("ANNEE", 2016);
1466
            createTable.addForeignColumn("MOIS");
1467
 
1468
            try {
1469
                root.getBase().getDataSource().execute(createTable.asString());
1470
                insertUndef(createTable);
1471
                root.refetchTable("DECLARATION_DSN");
1472
                root.getSchema().updateVersion();
1473
            } catch (SQLException ex) {
1474
                throw new IllegalStateException("Erreur lors de la création de la table " + "DECLARATION_DSN", ex);
1475
            }
1476
        }
1477
 
1478
        SQLTable tableArret = root.getTable("ARRET_TRAVAIL");
1479
        if (!tableArret.contains("DATE")) {
1480
            AlterTable alter = new AlterTable(tableArret);
1481
            alter.addDateAndTimeColumn("DATE");
1482
            alter.addVarCharColumn("COMMENTAIRES", 2048);
1483
            root.getBase().getDataSource().execute(alter.asString());
1484
            root.refetchTable("ARRET_TRAVAIL");
1485
            root.getSchema().updateVersion();
1486
        }
1487
 
1488
        SQLTable tableDsn = root.getTable("DECLARATION_DSN");
1489
        if (!tableDsn.contains("ID_ARRET_TRAVAIL")) {
1490
            AlterTable alter = new AlterTable(tableDsn);
1491
            alter.addForeignColumn("ID_ARRET_TRAVAIL", root.findTable("ARRET_TRAVAIL"));
1492
            root.getBase().getDataSource().execute(alter.asString());
1493
            root.getSchema().updateVersion();
1494
        }
142 ilm 1495
        if (!tableDsn.contains("ID_FIN_CONTRAT")) {
1496
            AlterTable alter = new AlterTable(tableDsn);
1497
            alter.addForeignColumn("ID_FIN_CONTRAT", root.findTable("FIN_CONTRAT"));
1498
            root.getBase().getDataSource().execute(alter.asString());
1499
            root.getSchema().updateVersion();
1500
        }
1501
 
132 ilm 1502
        if (!tableDsn.contains("ID_REPRISE_TRAVAIL")) {
1503
            AlterTable alter = new AlterTable(tableDsn);
1504
            alter.addForeignColumn("ID_REPRISE_TRAVAIL", root.findTable("REPRISE_TRAVAIL"));
1505
            root.getBase().getDataSource().execute(alter.asString());
1506
            root.getSchema().updateVersion();
1507
        }
1508
        if (!tableDsn.contains("ID_MOIS_REGUL")) {
1509
            AlterTable alter = new AlterTable(tableDsn);
1510
            alter.addForeignColumn("ID_MOIS_REGUL", root.findTable("MOIS"));
1511
            root.getBase().getDataSource().execute(alter.asString());
1512
            root.getSchema().updateVersion();
1513
        }
1514
 
1515
        if (!tableDsn.contains("ANNULE_REMPLACE")) {
1516
            AlterTable alter = new AlterTable(tableDsn);
1517
            alter.addBooleanColumn("ANNULE_REMPLACE", Boolean.FALSE, false);
1518
            root.getBase().getDataSource().execute(alter.asString());
1519
            root.getSchema().updateVersion();
1520
        }
142 ilm 1521
        if (!tableDsn.contains("NUMERO_REFERENCE")) {
1522
            AlterTable alter = new AlterTable(tableDsn);
1523
            alter.addVarCharColumn("NUMERO_REFERENCE", 256);
1524
            root.getBase().getDataSource().execute(alter.asString());
1525
            root.getSchema().updateVersion();
1526
        }
1527
        if (!tableDsn.contains("ID_DECLARATION_DSN_ANNULATION")) {
1528
            AlterTable alter = new AlterTable(tableDsn);
1529
            alter.addForeignColumn("ID_DECLARATION_DSN_ANNULATION", tableDsn);
1530
            root.getBase().getDataSource().execute(alter.asString());
1531
            root.getSchema().updateVersion();
1532
        }
1533
        if (!tableDsn.contains("EFFECTIF_CVAE")) {
1534
            AlterTable alter = new AlterTable(tableDsn);
1535
            alter.addIntegerColumn("EFFECTIF_CVAE", null, true);
1536
            alter.addVarCharColumn("CODE_INSEE_CVAE", 32);
1537
            root.getBase().getDataSource().execute(alter.asString());
1538
            root.getSchema().updateVersion();
1539
            root.refetchTable(tableDsn.getName());
1540
        }
132 ilm 1541
 
142 ilm 1542
        if (!tableDsn.contains("PERIODE_CVAE_DEBUT")) {
1543
            AlterTable alter = new AlterTable(tableDsn);
1544
            alter.addColumn("PERIODE_CVAE_DEBUT", "date");
1545
            alter.addColumn("PERIODE_CVAE_FIN", "date");
1546
            root.getBase().getDataSource().execute(alter.asString());
1547
            root.getSchema().updateVersion();
1548
        }
1549
 
132 ilm 1550
        // if (!root.contains("FIN_CONTRAT")) {
1551
        //
1552
        // final SQLCreateTable createTable = new SQLCreateTable(root, "FIN_CONTRAT");
1553
        // createTable.addForeignColumn("SALARIE");
1554
        // createTable.addDateAndTimeColumn("DATE_FIN");
1555
        // createTable.addDateAndTimeColumn("DATE_FIN_PREV");
1556
        // createTable.addBooleanColumn("SUBROGATION", Boolean.FALSE, false);
1557
        // createTable.addDateAndTimeColumn("DATE_DEBUT_SUBROGATION");
1558
        // createTable.addDateAndTimeColumn("DATE_FIN_SUBROGATION");
1559
        // createTable.addForeignColumn("ID_MOTIF_ARRET_TRAVAIL",
1560
        // root.findTable("MOTIF_ARRET_TRAVAIL"));
1561
        // createTable.addForeignColumn("ID_MOTIF_REPRISE_ARRET_TRAVAIL",
1562
        // root.findTable("MOTIF_REPRISE_ARRET_TRAVAIL"));
1563
        // createTable.addDateAndTimeColumn("DATE_REPRISE");
1564
        // createTable.addDateAndTimeColumn("DATE_ACCIDENT");
1565
        //
1566
        // try {
1567
        // root.getBase().getDataSource().execute(createTable.asString());
1568
        // insertUndef(createTable);
1569
        // root.refetchTable("FIN_CONTRAT");
1570
        // root.getSchema().updateVersion();
1571
        // } catch (SQLException ex) {
1572
        // throw new IllegalStateException("Erreur lors de la création de la table " +
1573
        // "FIN_CONTRAT", ex);
1574
        // }
1575
        // }
1576
 
1577
        SQLTable tableContrat = root.getTable("CONTRAT_SALARIE");
1578
        if (!tableContrat.contains("NUMERO")) {
1579
            AlterTable alter = new AlterTable(tableContrat);
1580
            alter.addColumn("NUMERO", "varchar(" + 128 + ") default '00000' NOT NULL");
1581
            root.getBase().getDataSource().execute(alter.asString());
1582
            root.getSchema().updateVersion();
1583
        }
1584
 
1585
        if (!tableContrat.contains("CODE_REGIME_RETRAITE_DSN")) {
1586
            AlterTable alter = new AlterTable(tableContrat);
1587
            alter.addColumn("CODE_REGIME_RETRAITE_DSN", "varchar(" + 128 + ") default '00000' NOT NULL");
1588
            root.getBase().getDataSource().execute(alter.asString());
1589
            root.getSchema().updateVersion();
1590
        }
1591
 
1592
        if (!tableContrat.contains("DATE_PREV_FIN")) {
1593
            AlterTable alter = new AlterTable(tableContrat);
1594
            alter.addDateAndTimeColumn("DATE_PREV_FIN");
1595
            root.getBase().getDataSource().execute(alter.asString());
1596
            root.getSchema().updateVersion();
1597
        }
1598
 
1599
        boolean updateContrat = false;
1600
        if (!tableContrat.contains("ID_CONTRAT_MODALITE_TEMPS")) {
1601
            updateContrat = true;
1602
            AlterTable alter = new AlterTable(tableContrat);
1603
            alter.addForeignColumn("ID_CONTRAT_MODALITE_TEMPS", root.findTable("CONTRAT_MODALITE_TEMPS"));
1604
            root.getBase().getDataSource().execute(alter.asString());
1605
            root.getSchema().updateVersion();
1606
        }
1607
        if (!tableContrat.contains("ID_CONTRAT_REGIME_MALADIE")) {
1608
            AlterTable alter = new AlterTable(tableContrat);
1609
            alter.addForeignColumn("ID_CONTRAT_REGIME_MALADIE", root.findTable("CONTRAT_REGIME_MALADIE"));
1610
            root.getBase().getDataSource().execute(alter.asString());
1611
            root.getSchema().updateVersion();
1612
        }
1613
        if (!tableContrat.contains("ID_CONTRAT_REGIME_VIEILLESSE")) {
1614
            AlterTable alter = new AlterTable(tableContrat);
1615
            alter.addForeignColumn("ID_CONTRAT_REGIME_VIEILLESSE", root.findTable("CONTRAT_REGIME_VIEILLESSE"));
1616
            root.getBase().getDataSource().execute(alter.asString());
1617
            root.getSchema().updateVersion();
1618
        }
1619
        if (!tableContrat.contains("ID_CONTRAT_MOTIF_RECOURS")) {
1620
            AlterTable alter = new AlterTable(tableContrat);
1621
            alter.addForeignColumn("ID_CONTRAT_MOTIF_RECOURS", root.findTable("CONTRAT_MOTIF_RECOURS"));
1622
            root.getBase().getDataSource().execute(alter.asString());
1623
            root.getSchema().updateVersion();
1624
        }
1625
        if (!tableContrat.contains("ID_CONTRAT_DETACHE_EXPATRIE")) {
1626
            AlterTable alter = new AlterTable(tableContrat);
1627
            alter.addForeignColumn("ID_CONTRAT_DETACHE_EXPATRIE", root.findTable("CONTRAT_DETACHE_EXPATRIE"));
1628
            root.getBase().getDataSource().execute(alter.asString());
1629
            root.getSchema().updateVersion();
1630
        }
1631
        if (!tableContrat.contains("ID_CONTRAT_DISPOSITIF_POLITIQUE")) {
1632
            AlterTable alter = new AlterTable(tableContrat);
1633
            alter.addForeignColumn("ID_CONTRAT_DISPOSITIF_POLITIQUE", root.findTable("CONTRAT_DISPOSITIF_POLITIQUE"));
1634
            root.getBase().getDataSource().execute(alter.asString());
1635
            root.getSchema().updateVersion();
1636
        }
177 ilm 1637
        if (!tableContrat.contains("ID_CODE_AMENAGEMENT_PARTIEL")) {
1638
            updateContrat = true;
1639
            AlterTable alter = new AlterTable(tableContrat);
1640
            alter.addForeignColumn("ID_CODE_AMENAGEMENT_PARTIEL", root.findTable("CODE_AMENAGEMENT_PARTIEL"));
1641
            alter.addColumn("DATE_DEBUT_SUSPENSION", "date");
1642
            alter.addColumn("DATE_FIN_SUSPENSION", "date");
1643
            root.getBase().getDataSource().execute(alter.asString());
1644
            root.getSchema().updateVersion();
1645
        }
132 ilm 1646
 
177 ilm 1647
        if (!tableContrat.contains("ID_CODE_SUSPENSION")) {
1648
            updateContrat = true;
1649
            AlterTable alter = new AlterTable(tableContrat);
1650
            alter.addForeignColumn("ID_CODE_SUSPENSION", root.findTable("CODE_SUSPENSION"));
1651
            root.getBase().getDataSource().execute(alter.asString());
1652
            root.getSchema().updateVersion();
1653
        }
1654
 
132 ilm 1655
        if (updateContrat) {
1656
            root.refetchTable("CONTRAT_SALARIE");
1657
            tableContrat = root.findTable("CONTRAT_SALARIE");
1658
            SQLSelect sel = new SQLSelect();
1659
            sel.addSelectStar(tableContrat);
1660
            List<SQLRow> contrats = SQLRowListRSH.execute(sel);
1661
 
1662
            SQLSelect selModal = new SQLSelect();
1663
            final SQLTable tableModaliteTemps = root.findTable("CONTRAT_MODALITE_TEMPS");
1664
            selModal.addSelectStar(tableModaliteTemps);
1665
            selModal.setWhere(new Where(tableModaliteTemps.getField("CODE"), "=", "10"));
1666
            SQLRow contratModalite = SQLRowListRSH.execute(selModal).get(0);
1667
 
1668
            SQLSelect selMaladie = new SQLSelect();
1669
            final SQLTable tableMaladie = root.findTable("CONTRAT_REGIME_MALADIE");
1670
            selMaladie.addSelectStar(tableMaladie);
1671
            selMaladie.setWhere(new Where(tableMaladie.getField("CODE"), "=", "200"));
1672
            SQLRow contratMaladie = SQLRowListRSH.execute(selMaladie).get(0);
1673
 
1674
            SQLSelect selViel = new SQLSelect();
1675
            final SQLTable tableViel = root.findTable("CONTRAT_REGIME_VIEILLESSE");
1676
            selViel.addSelectStar(tableViel);
1677
            selViel.setWhere(new Where(tableViel.getField("CODE"), "=", "200"));
1678
            SQLRow contratViel = SQLRowListRSH.execute(selViel).get(0);
1679
 
1680
            SQLSelect selDetacheExp = new SQLSelect();
1681
            final SQLTable tableDetacheExp = root.findTable("CONTRAT_DETACHE_EXPATRIE");
1682
            selDetacheExp.addSelectStar(tableDetacheExp);
1683
            selDetacheExp.setWhere(new Where(tableDetacheExp.getField("CODE"), "=", "99"));
1684
            SQLRow contratDetacheExp = SQLRowListRSH.execute(selDetacheExp).get(0);
1685
 
1686
            SQLSelect selDispoPolitique = new SQLSelect();
1687
            final SQLTable tableDispoPol = root.findTable("CONTRAT_DISPOSITIF_POLITIQUE");
1688
            selDispoPolitique.addSelectStar(tableDispoPol);
1689
            selDispoPolitique.setWhere(new Where(tableDispoPol.getField("CODE"), "=", "99"));
1690
            SQLRow contratDispoPol = SQLRowListRSH.execute(selDispoPolitique).get(0);
1691
 
1692
            for (SQLRow contrat : contrats) {
1693
 
1694
                final SQLRowValues createEmptyUpdateRow = contrat.createEmptyUpdateRow();
1695
                createEmptyUpdateRow.put("ID_CONTRAT_MODALITE_TEMPS", contratModalite.getID());
1696
                createEmptyUpdateRow.put("ID_CONTRAT_REGIME_MALADIE", contratMaladie.getID());
1697
                createEmptyUpdateRow.put("ID_CONTRAT_REGIME_VIEILLESSE", contratViel.getID());
1698
                createEmptyUpdateRow.put("ID_CONTRAT_DETACHE_EXPATRIE", contratDetacheExp.getID());
1699
                createEmptyUpdateRow.put("ID_CONTRAT_DISPOSITIF_POLITIQUE", contratDispoPol.getID());
1700
                createEmptyUpdateRow.commit();
1701
            }
1702
        }
142 ilm 1703
        if (!root.contains("CONTRAT_PREVOYANCE")) {
132 ilm 1704
 
142 ilm 1705
            final SQLCreateTable createTable = new SQLCreateTable(root, "CONTRAT_PREVOYANCE");
1706
            createTable.addVarCharColumn("REFERENCE", 256);
1707
            createTable.addDateAndTimeColumn("DATE_DEBUT");
1708
            createTable.addDateAndTimeColumn("DATE_FIN");
1709
            createTable.addVarCharColumn("CODE_ORGANISME", 256);
1710
            createTable.addVarCharColumn("CODE_DELEGATAIRE", 256);
1711
            createTable.addVarCharColumn("CODE_UNIQUE", 256);
1712
            createTable.addVarCharColumn("NOM", 256);
1713
            try {
1714
                root.getBase().getDataSource().execute(createTable.asString());
1715
                insertUndef(createTable);
1716
                root.refetchTable("CONTRAT_PREVOYANCE");
1717
                root.getSchema().updateVersion();
1718
            } catch (SQLException ex) {
1719
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_PREVOYANCE", ex);
1720
            }
1721
        }
1722
        if (!root.getTable("CONTRAT_PREVOYANCE").contains("COTISATION_ETABLISSEMENT")) {
1723
            AlterTable tableContratP = new AlterTable(root.getTable("CONTRAT_PREVOYANCE"));
1724
            tableContratP.addBooleanColumn("COTISATION_ETABLISSEMENT", Boolean.FALSE, false);
1725
            root.getBase().getDataSource().execute(tableContratP.asString());
1726
            root.refetchTable("CONTRAT_PREVOYANCE");
1727
            root.getSchema().updateVersion();
1728
        }
1729
 
1730
        if (!root.contains("CONTRAT_PREVOYANCE_CONTRAT_SALARIE")) {
1731
 
1732
            final SQLCreateTable createTableSal = new SQLCreateTable(root, "CONTRAT_PREVOYANCE_CONTRAT_SALARIE");
1733
            final SQLTable tableInfosSalarie = root.getTable("INFOS_SALARIE_PAYE");
1734
            createTableSal.addForeignColumn("ID_INFOS_SALARIE_PAYE", tableInfosSalarie);
1735
            createTableSal.addForeignColumn("ID_CONTRAT_PREVOYANCE", root.getTable("CONTRAT_PREVOYANCE"));
1736
            createTableSal.addVarCharColumn("CODE_OPTION", 256);
1737
            createTableSal.addVarCharColumn("CODE_POPULATION", 256);
1738
            createTableSal.addIntegerColumn("NB_ENFANT_CHARGE", null, true);
1739
            createTableSal.addIntegerColumn("NB_ADULTE_AYANT_DROIT", null, true);
1740
            createTableSal.addIntegerColumn("NB_AYANT_DROIT", null, true);
1741
            createTableSal.addIntegerColumn("NB_AYANT_DROIT_AUTRE", null, true);
1742
            createTableSal.addIntegerColumn("NB_ENFANT_AYANT_DROIT", null, true);
1743
 
1744
            try {
1745
                root.getBase().getDataSource().execute(createTableSal.asString());
1746
                insertUndef(createTableSal);
1747
                root.refetchTable("CONTRAT_PREVOYANCE_CONTRAT_SALARIE");
1748
                root.getSchema().updateVersion();
1749
 
1750
                String up = "UPDATE " + new SQLName(root.getName(), tableInfosSalarie.getName()).quote() + " i SET \"ID_SALARIE\" = (SELECT s.\"ID\" FROM "
1751
                        + new SQLName(root.getName(), tableInfosSalarie.getForeignTable("ID_SALARIE").getName()).quote() + " s WHERE s.\"ID_INFOS_SALARIE_PAYE\"=i.\"ID\" and s.\"ARCHIVE\"=0)"
1752
                        + " WHERE i.\"ID\" IN (SELECT i2.\"ID_INFOS_SALARIE_PAYE\" FROM " + new SQLName(root.getName(), tableInfosSalarie.getForeignTable("ID_SALARIE").getName()).quote();
1753
                up += " i2 WHERE i2.\"ARCHIVE\"=0)";
1754
 
1755
                root.getBase().getDataSource().execute(up);
1756
 
1757
            } catch (SQLException ex) {
1758
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_PREVOYANCE_SALARIE", ex);
1759
            }
1760
        }
1761
        if (!root.contains("CONTRAT_PREVOYANCE_RUBRIQUE"))
1762
 
1763
        {
1764
 
1765
            final SQLCreateTable createTableRub = new SQLCreateTable(root, "CONTRAT_PREVOYANCE_RUBRIQUE");
1766
            createTableRub.addForeignColumn("ID_RUBRIQUE_COTISATION", root.findTable("RUBRIQUE_COTISATION"));
1767
            createTableRub.addForeignColumn("ID_CONTRAT_PREVOYANCE", root.getTable("CONTRAT_PREVOYANCE"));
1768
 
1769
            try {
1770
                root.getBase().getDataSource().execute(createTableRub.asString());
1771
                insertUndef(createTableRub);
1772
                root.refetchTable("CONTRAT_PREVOYANCE_RUBRIQUE");
1773
                root.getSchema().updateVersion();
1774
            } catch (SQLException ex) {
1775
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_PREVOYANCE_RUBRIQUE", ex);
1776
            }
1777
        }
1778
 
1779
        if (!root.contains("CONTRAT_PREVOYANCE_RUBRIQUE_NET"))
1780
 
1781
        {
1782
 
1783
            final SQLCreateTable createTableRub = new SQLCreateTable(root, "CONTRAT_PREVOYANCE_RUBRIQUE_NET");
1784
            createTableRub.addForeignColumn("ID_RUBRIQUE_NET", root.findTable("RUBRIQUE_NET"));
1785
            createTableRub.addForeignColumn("ID_CONTRAT_PREVOYANCE", root.getTable("CONTRAT_PREVOYANCE"));
1786
 
1787
            try {
1788
                root.getBase().getDataSource().execute(createTableRub.asString());
1789
                insertUndef(createTableRub);
1790
                root.refetchTable("CONTRAT_PREVOYANCE_RUBRIQUE_NET");
1791
                root.getSchema().updateVersion();
1792
            } catch (SQLException ex) {
1793
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_PREVOYANCE_RUBRIQUE_NET", ex);
1794
            }
1795
        }
1796
        if (!root.contains("AYANT_DROIT")) {
1797
 
1798
            final SQLCreateTable createTableAyantDroit = new SQLCreateTable(root, "AYANT_DROIT");
1799
            createTableAyantDroit.addVarCharColumn("NOM", 256);
1800
            createTableAyantDroit.addForeignColumn("ID_SALARIE", root.findTable("SALARIE"));
1801
            createTableAyantDroit.addForeignColumn("ID_AYANT_DROIT_TYPE", root.findTable("AYANT_DROIT_TYPE"));
1802
            createTableAyantDroit.addBooleanColumn("REGIME_ALSACE", Boolean.FALSE, false);
1803
            createTableAyantDroit.addVarCharColumn("NIR", 256);
1804
            createTableAyantDroit.addVarCharColumn("PRENOMS", 256);
1805
            createTableAyantDroit.addVarCharColumn("CODE_ORGANISME_AFFILIATION", 256);
1806
            createTableAyantDroit.addVarCharColumn("CODE_OPTION", 256);
1807
            createTableAyantDroit.addVarCharColumn("NIR_OUVRANT_DROIT", 256);
1808
            createTableAyantDroit.addDateAndTimeColumn("DATE_DEBUT_RATTACHEMENT");
1809
            createTableAyantDroit.addDateAndTimeColumn("DATE_FIN_RATTACHEMENT");
1810
            createTableAyantDroit.addDateAndTimeColumn("DATE_NAISSANCE");
1811
            try {
1812
                root.getBase().getDataSource().execute(createTableAyantDroit.asString());
1813
                insertUndef(createTableAyantDroit);
1814
                root.refetchTable("AYANT_DROIT");
1815
                root.getSchema().updateVersion();
1816
            } catch (SQLException ex) {
1817
                throw new IllegalStateException("Erreur lors de la création de la table " + "AYANT_DROIT", ex);
1818
            }
1819
 
1820
            final SQLCreateTable createTablePrevAyant = new SQLCreateTable(root, "CONTRAT_PREVOYANCE_AYANT_DROIT");
1821
            createTablePrevAyant.addForeignColumn("ID_AYANT_DROIT", root.getTable("AYANT_DROIT"));
1822
            createTablePrevAyant.addForeignColumn("ID_CONTRAT_PREVOYANCE", root.getTable("CONTRAT_PREVOYANCE"));
1823
 
1824
            try {
1825
                root.getBase().getDataSource().execute(createTablePrevAyant.asString());
1826
                insertUndef(createTablePrevAyant);
1827
                root.refetchTable("CONTRAT_PREVOYANCE_AYANT_DROIT");
1828
                root.getSchema().updateVersion();
1829
            } catch (SQLException ex) {
1830
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_PREVOYANCE_AYANT_DROIT", ex);
1831
            }
1832
        }
1833
        if (!root.contains("CODE_PENIBILITE_CONTRAT_SALARIE")) {
1834
 
1835
            final SQLCreateTable createTableSal = new SQLCreateTable(root, "CODE_PENIBILITE_CONTRAT_SALARIE");
1836
            final SQLTable tableInfosSalarie = root.getTable("INFOS_SALARIE_PAYE");
1837
            createTableSal.addForeignColumn("ID_INFOS_SALARIE_PAYE", tableInfosSalarie);
1838
            createTableSal.addForeignColumn("ID_CODE_PENIBILITE", root.findTable("CODE_PENIBILITE"));
1839
 
1840
            try {
1841
                root.getBase().getDataSource().execute(createTableSal.asString());
1842
                insertUndef(createTableSal);
1843
                root.refetchTable("CODE_PENIBILITE_CONTRAT_SALARIE");
1844
                root.getSchema().updateVersion();
1845
 
1846
            } catch (SQLException ex) {
1847
                throw new IllegalStateException("Erreur lors de la création de la table " + "CODE_PENIBILITE_CONTRAT_SALARIE", ex);
1848
            }
1849
        }
132 ilm 1850
    }
1851
 
1852
}