OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Rev 177 | 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
 
142 ilm 275
        SQLTable tableRubNet = root.getTable("RUBRIQUE_NET");
276
        if (!tableRubNet.contains("ID_CODE_TYPE_RUBRIQUE_BRUT")) {
277
 
278
            AlterTable alterTableNet = new AlterTable(tableRubNet);
279
            alterTableNet.addForeignColumn("ID_CODE_TYPE_RUBRIQUE_BRUT", root.getTable("CODE_TYPE_RUBRIQUE_BRUT"));
280
            root.getBase().getDataSource().execute(alterTableNet.asString());
281
            root.refetchTable("RUBRIQUE_NET");
282
            root.getSchema().updateVersion();
283
        }
284
 
132 ilm 285
        if (!root.contains("DSN_REGIME_LOCAL")) {
286
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "DSN_REGIME_LOCAL");
287
            createTableMotif.addVarCharColumn("CODE", 25);
288
            createTableMotif.addVarCharColumn("NOM", 512);
289
 
290
            try {
291
                root.getBase().getDataSource().execute(createTableMotif.asString());
292
                insertUndef(createTableMotif);
293
                root.refetchTable("DSN_REGIME_LOCAL");
294
                root.getSchema().updateVersion();
295
 
296
                final SQLTable table = root.getTable("DSN_REGIME_LOCAL");
297
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
298
                v.add(Tuple2.create("99", "non applicable"));
299
                v.add(Tuple2.create("01", "régime local Alsace Moselle"));
300
                insertValues(v, table);
301
            } catch (SQLException ex) {
302
                throw new IllegalStateException("Erreur lors de la création de la table " + "DSN_REGIME_LOCAL", ex);
303
            }
304
        }
305
 
306
        if (!root.contains("CONTRAT_MODALITE_TEMPS")) {
307
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CONTRAT_MODALITE_TEMPS");
308
            createTableMotif.addVarCharColumn("CODE", 25);
309
            createTableMotif.addVarCharColumn("NOM", 512);
310
 
311
            try {
312
                root.getBase().getDataSource().execute(createTableMotif.asString());
313
                insertUndef(createTableMotif);
314
                root.refetchTable("CONTRAT_MODALITE_TEMPS");
315
                root.getSchema().updateVersion();
316
 
317
                final SQLTable table = root.getTable("CONTRAT_MODALITE_TEMPS");
318
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
319
                v.add(Tuple2.create("10", "temps plein"));
320
                v.add(Tuple2.create("20", "temps partiel"));
321
                v.add(Tuple2.create("21", "temps partiel thérapeutique"));
322
                v.add(Tuple2.create("99", "salarié non concerné"));
323
                insertValues(v, table);
324
            } catch (SQLException ex) {
325
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_MODALITE_TEMPS", ex);
326
            }
327
        }
328
 
329
        if (!root.contains("CONTRAT_REGIME_MALADIE")) {
330
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CONTRAT_REGIME_MALADIE");
331
            createTableMotif.addVarCharColumn("CODE", 25);
332
            createTableMotif.addVarCharColumn("NOM", 512);
333
 
334
            try {
335
                root.getBase().getDataSource().execute(createTableMotif.asString());
336
                insertUndef(createTableMotif);
337
                root.refetchTable("CONTRAT_REGIME_MALADIE");
338
                root.getSchema().updateVersion();
339
 
340
                final SQLTable table = root.getTable("CONTRAT_REGIME_MALADIE");
341
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
342
                v.add(Tuple2.create("134", "régime spécial de la SNCF"));
343
                v.add(Tuple2.create("135", "régime spécial de la RATP"));
344
                v.add(Tuple2.create("136", "établissement des invalides de la marine (ENIM)"));
345
                v.add(Tuple2.create("137", "mineurs ou assimilés (CANMSS)"));
346
                v.add(Tuple2.create("138", "militaires de carrière (CNMSS)"));
347
                v.add(Tuple2.create("140", "clercs et employés de notaires (CRPCEN)"));
348
                v.add(Tuple2.create("141", "chambre de commerce et d'industrie de Paris"));
349
                v.add(Tuple2.create("144", "Assemblée Nationale"));
350
                v.add(Tuple2.create("145", "Sénat"));
351
                v.add(Tuple2.create("146", "port autonome de Bordeaux"));
352
                v.add(Tuple2.create("147", "industries électriques et gazières (CAMIEG)"));
353
                v.add(Tuple2.create("149", "régimes des cultes (CAVIMAC)"));
354
                v.add(Tuple2.create("200", "régime général (CNAM)"));
355
                v.add(Tuple2.create("300", "régime agricole (MSA)"));
356
                v.add(Tuple2.create("400", "régime spécial Banque de France"));
357
                v.add(Tuple2.create("900", "autre régime (réservé Polynésie Française, Nouvelle Calédonie)"));
358
                v.add(Tuple2.create("999", "autre"));
359
 
360
                insertValues(v, table);
361
            } catch (SQLException ex) {
362
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_REGIME_MALADIE", ex);
363
            }
364
        }
365
 
366
        if (!root.contains("CONTRAT_REGIME_VIEILLESSE")) {
367
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CONTRAT_REGIME_VIEILLESSE");
368
            createTableMotif.addVarCharColumn("CODE", 25);
369
            createTableMotif.addVarCharColumn("NOM", 512);
370
 
371
            try {
372
                root.getBase().getDataSource().execute(createTableMotif.asString());
373
                insertUndef(createTableMotif);
374
                root.refetchTable("CONTRAT_REGIME_VIEILLESSE");
375
                root.getSchema().updateVersion();
376
 
377
                final SQLTable table = root.getTable("CONTRAT_REGIME_VIEILLESSE");
378
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
379
                v.add(Tuple2.create("120", "retraite des agents des collectivités locales (CNRACL)"));
380
                v.add(Tuple2.create("121", "pensions des ouvriers des établissements industriels de l'Etat (FSPOEIE)"));
381
                v.add(Tuple2.create("122", "pensions civiles et militaires de retraite de l'Etat (SRE)"));
382
                v.add(Tuple2.create("134", "régime spécial de la SNCF"));
383
                v.add(Tuple2.create("135", "régime spécial de la RATP"));
384
                v.add(Tuple2.create("136", "établissement des invalides de la marine (ENIM)"));
385
                v.add(Tuple2.create("137", "mineurs ou assimilés (fonds Caisse des Dépôts)"));
386
                v.add(Tuple2.create("139", "Banque de France"));
387
                v.add(Tuple2.create("140", "clercs et employés de notaires (CRPCEN)"));
388
                v.add(Tuple2.create("141", "chambre de commerce et d'industrie de Paris"));
389
                v.add(Tuple2.create("144", "Assemblée Nationale"));
390
                v.add(Tuple2.create("145", "Sénat"));
391
                v.add(Tuple2.create("147", "industries électriques et gazières (CNIEG)"));
392
                v.add(Tuple2.create("149", "régime des cultes (CAVIMAC)"));
393
                v.add(Tuple2.create("157", "régime de retraite des avocats (CNBF)"));
394
                v.add(Tuple2.create("158", "SEITA"));
395
                v.add(Tuple2.create("159", "Comédie Française"));
396
                v.add(Tuple2.create("160", "Opéra de Paris"));
397
                v.add(Tuple2.create("200", "régime général (CNAV)"));
398
                v.add(Tuple2.create("300", "régime agricole (MSA)"));
399
                v.add(Tuple2.create("900", "autre régime (réservé Polynésie Française, Nouvelle Calédonie, Principauté de Monaco)"));
400
                v.add(Tuple2.create("903", "salariés étrangers exemptés d'affiliation pour le risque vieillesse"));
401
                v.add(Tuple2.create("999", "cas particuliers d'affiliation"));
402
 
403
                insertValues(v, table);
404
            } catch (SQLException ex) {
405
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_REGIME_VIEILLESSE", ex);
406
            }
407
        }
408
 
409
        if (!root.contains("CONTRAT_MOTIF_RECOURS")) {
410
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CONTRAT_MOTIF_RECOURS");
411
            createTableMotif.addVarCharColumn("CODE", 25);
412
            createTableMotif.addVarCharColumn("NOM", 512);
413
 
414
            try {
415
                root.getBase().getDataSource().execute(createTableMotif.asString());
416
                insertUndef(createTableMotif);
417
                root.refetchTable("CONTRAT_MOTIF_RECOURS");
418
                root.getSchema().updateVersion();
419
 
420
                final SQLTable table = root.getTable("CONTRAT_MOTIF_RECOURS");
421
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
422
                v.add(Tuple2.create("01", "Remplacement d'un salarié"));
423
                v.add(Tuple2.create("02", "Accroissement temporaire de l'activité de l'entreprise"));
424
                v.add(Tuple2.create("03", "Emplois à caractère saisonnier"));
425
                v.add(Tuple2.create("04", "Contrat vendanges"));
426
                v.add(Tuple2.create("05", "Contrat à durée déterminée d’usage"));
427
                v.add(Tuple2.create("06", "Contrat à durée déterminée à objet défini"));
428
                v.add(Tuple2.create("07", "Remplacement d'un chef d'entreprise"));
429
                v.add(Tuple2.create("08", "Remplacement du chef d'une exploitation agricole"));
430
                v.add(Tuple2.create("09", "Recrutement de personnes sans emploi rencontrant des difficultés sociales et professionnelles particulières"));
431
                v.add(Tuple2.create("10", "Complément de formation professionnelle au salarié"));
432
                v.add(Tuple2.create("11",
433
                        "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"));
434
                v.add(Tuple2.create("12", "Remplacement d’un salarié passé provisoirement à temps partiel"));
435
                v.add(Tuple2.create("13", "Attente de la suppression définitive du poste du salarié ayant quitté définitivement l’entreprise"));
436
                insertValues(v, table);
437
            } catch (SQLException ex) {
438
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_MOTIF_RECOURS", ex);
439
            }
440
        }
441
 
442
        if (!root.contains("CONTRAT_DETACHE_EXPATRIE")) {
443
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CONTRAT_DETACHE_EXPATRIE");
444
            createTableMotif.addVarCharColumn("CODE", 25);
445
            createTableMotif.addVarCharColumn("NOM", 512);
446
 
447
            try {
448
                root.getBase().getDataSource().execute(createTableMotif.asString());
449
                insertUndef(createTableMotif);
450
                root.refetchTable("CONTRAT_DETACHE_EXPATRIE");
451
                root.getSchema().updateVersion();
452
 
453
                final SQLTable table = root.getTable("CONTRAT_DETACHE_EXPATRIE");
454
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
455
                v.add(Tuple2.create("01", "Détaché"));
456
                v.add(Tuple2.create("02", "Expatrié"));
457
                v.add(Tuple2.create("03", "Frontalier"));
458
                v.add(Tuple2.create("99", "Salarié non concerné"));
459
                insertValues(v, table);
460
            } catch (SQLException ex) {
461
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_DETACHE_EXPATRIE", ex);
462
            }
463
        }
464
 
465
        if (!root.contains("DSN_NATURE")) {
466
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "DSN_NATURE");
467
            createTableMotif.addVarCharColumn("CODE", 25);
468
            createTableMotif.addVarCharColumn("NOM", 512);
469
 
470
            try {
471
                root.getBase().getDataSource().execute(createTableMotif.asString());
472
                insertUndef(createTableMotif);
473
                root.refetchTable("DSN_NATURE");
474
                root.getSchema().updateVersion();
475
 
476
                final SQLTable table = root.getTable("DSN_NATURE");
477
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
478
                v.add(Tuple2.create("01", "DSN Mensuelle"));
479
                v.add(Tuple2.create("02", "Signalement Fin du contrat de travail"));
480
                v.add(Tuple2.create("04", "Signalement Arrêt de travail"));
481
                v.add(Tuple2.create("05", "Signalement Reprise suite à arrêt de travail"));
482
                v.add(Tuple2.create("06", "DSN reprise d'historique"));
483
                insertValues(v, table);
484
            } catch (SQLException ex) {
485
                throw new IllegalStateException("Erreur lors de la création de la table " + "DSN_NATURE", ex);
486
            }
487
        }
488
 
489
        if (!root.contains("DSN_TYPE")) {
490
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "DSN_TYPE");
491
            createTableMotif.addVarCharColumn("CODE", 25);
492
            createTableMotif.addVarCharColumn("NOM", 512);
493
 
494
            try {
495
                root.getBase().getDataSource().execute(createTableMotif.asString());
496
                insertUndef(createTableMotif);
497
                root.refetchTable("DSN_TYPE");
498
                root.getSchema().updateVersion();
499
 
500
                final SQLTable table = root.getTable("DSN_TYPE");
501
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
502
                v.add(Tuple2.create("01", "déclaration normale"));
503
                v.add(Tuple2.create("02", "déclaration normale néant"));
504
                v.add(Tuple2.create("03", "déclaration annule et remplace intégral"));
505
                v.add(Tuple2.create("04", "déclaration annule"));
506
                v.add(Tuple2.create("05", "annule et remplace néant"));
507
                insertValues(v, table);
508
            } catch (SQLException ex) {
509
                throw new IllegalStateException("Erreur lors de la création de la table " + "DSN_TYPE", ex);
510
            }
511
        }
512
 
513
        if (!root.contains("CONTRAT_DISPOSITIF_POLITIQUE")) {
514
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "CONTRAT_DISPOSITIF_POLITIQUE");
515
            createTableMotif.addVarCharColumn("CODE", 25);
516
            createTableMotif.addVarCharColumn("NOM", 512);
517
 
518
            try {
519
                root.getBase().getDataSource().execute(createTableMotif.asString());
520
                insertUndef(createTableMotif);
521
                root.refetchTable("CONTRAT_DISPOSITIF_POLITIQUE");
522
                root.getSchema().updateVersion();
523
 
524
                final SQLTable table = root.getTable("CONTRAT_DISPOSITIF_POLITIQUE");
525
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
526
                v.add(Tuple2.create("21", "CUI - Contrat Initiative Emploi"));
527
                v.add(Tuple2.create("41", "CUI - Contrat d'Accompagnement dans l'Emploi"));
528
                v.add(Tuple2.create("42", "CUI - Contrat d'accès à l'emploi - DOM"));
529
                v.add(Tuple2.create("50", "Emploi d'avenir secteur marchand"));
530
                v.add(Tuple2.create("51", "Emploi d'avenir secteur non marchand"));
531
                v.add(Tuple2.create("61", "Contrat de Professionnalisation"));
532
                v.add(Tuple2.create("64", "Contrat d'apprentissage entreprises artisanales ou de moins de 11 salariés (loi du 3 janvier 1979)"));
533
                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)"));
534
                v.add(Tuple2.create("70", "Contrat à durée déterminée pour les séniors"));
535
                v.add(Tuple2.create("71", "Contrat à durée déterminée d’insertion"));
536
                v.add(Tuple2.create("80", "Contrat de génération"));
537
                v.add(Tuple2.create("81", "Contrat d'apprentissage secteur public (Loi de 1992)"));
538
                v.add(Tuple2.create("82", "Contrat à durée indéterminée intérimaire"));
539
                v.add(Tuple2.create("99", "Non concerné"));
540
                insertValues(v, table);
541
            } catch (SQLException ex) {
542
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_DISPOSITIF_POLITIQUE", ex);
543
            }
544
        }
545
 
546
        if (!root.contains("MOTIF_REPRISE_ARRET_TRAVAIL")) {
547
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "MOTIF_REPRISE_ARRET_TRAVAIL");
548
            createTableMotif.addVarCharColumn("CODE", 25);
549
            createTableMotif.addVarCharColumn("NOM", 512);
550
 
551
            try {
552
                root.getBase().getDataSource().execute(createTableMotif.asString());
553
                insertUndef(createTableMotif);
554
                root.refetchTable("MOTIF_REPRISE_ARRET_TRAVAIL");
555
                root.getSchema().updateVersion();
556
 
557
                final SQLTable table = root.getTable("MOTIF_REPRISE_ARRET_TRAVAIL");
558
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
559
                v.add(Tuple2.create("01", "reprise normale"));
560
                v.add(Tuple2.create("02", "reprise temps partiel thérapeutique"));
561
                v.add(Tuple2.create("03", "reprise temps partiel raison personnelle"));
562
                insertValues(v, table);
563
            } catch (SQLException ex) {
564
                throw new IllegalStateException("Erreur lors de la création de la table " + "MOTIF_REPRISE_ARRET_TRAVAIL", ex);
565
            }
566
        }
567
 
568
        if (!root.contains("MOTIF_FIN_CONTRAT")) {
569
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "MOTIF_FIN_CONTRAT");
570
            createTableMotif.addVarCharColumn("CODE", 25);
571
            createTableMotif.addVarCharColumn("NOM", 512);
572
 
573
            try {
574
                root.getBase().getDataSource().execute(createTableMotif.asString());
575
                insertUndef(createTableMotif);
576
                root.refetchTable("MOTIF_FIN_CONTRAT");
577
                root.getSchema().updateVersion();
578
 
579
                final SQLTable table = root.getTable("MOTIF_FIN_CONTRAT");
580
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
581
                v.add(Tuple2.create("011", "licenciement suite à liquidation judiciaire ou à redressement judiciaire"));
582
                v.add(Tuple2.create("012", "licenciement suite à fermeture définitive de l'établissement"));
583
                v.add(Tuple2.create("014", "licenciement pour motif économique"));
584
                v.add(Tuple2.create("015", "licenciement pour fin de chantier"));
585
                v.add(Tuple2.create("020", "licenciement pour autre motif"));
586
                v.add(Tuple2.create("025", "autre fin de contrat pour motif économique"));
587
                v.add(Tuple2.create("026", "rupture pour motif économique dans le cadre d’un contrat de sécurisation professionnelle CSP"));
588
                v.add(Tuple2.create("031", "fin de contrat à durée déterminée ou fin d'accueil occasionnel"));
589
                v.add(Tuple2.create("032", "fin de mission d'intérim"));
590
                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"));
591
                v.add(Tuple2.create("034", "fin de période d'essai à l'initiative de l'employeur"));
592
                v.add(Tuple2.create("035", "fin de période d'essai à l'initiative du salarié"));
593
                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"));
594
                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é"));
595
                v.add(Tuple2.create("038", "mise à la retraite par l'employeur"));
596
                v.add(Tuple2.create("039", "départ à la retraite à l'initiative du salarié"));
597
                v.add(Tuple2.create("043", "rupture conventionnelle"));
598
                v.add(Tuple2.create("058", "prise d'acte de la rupture de contrat de travail"));
599
                v.add(Tuple2.create("059", "démission"));
600
                v.add(Tuple2.create("065", "décès de l'employeur ou internement / conduit à un licenciement autre motif"));
601
                v.add(Tuple2.create("066", "décès du salarié / rupture force majeure"));
602
                v.add(Tuple2.create("081", "fin de contrat d'apprentissage"));
603
                v.add(Tuple2.create("082", "résiliation judiciaire du contrat de travail"));
604
                v.add(Tuple2.create("083", "rupture de contrat de travail ou d’un contrat de mission pour force majeure"));
605
                v.add(Tuple2.create("084", "rupture d'un commun accord du CDD, du contrat d'apprentissage ou d’un contrat de mission"));
606
                v.add(Tuple2.create("085", "fin de mandat"));
607
                v.add(Tuple2.create("086", "licenciement convention CATS"));
608
                v.add(Tuple2.create("087", "licenciement pour faute grave"));
609
                v.add(Tuple2.create("088", "licenciement pour faute lourde"));
610
                v.add(Tuple2.create("089", "licenciement pour force majeure"));
611
                v.add(Tuple2.create("091", "licenciement pour inaptitude physique d'origine non professionnelle"));
612
                v.add(Tuple2.create("092", "licenciement pour inaptitude physique d'origine professionnelle"));
613
                v.add(Tuple2.create("093", "licenciement suite à décision d'une autorité administrative"));
614
                v.add(Tuple2.create("094", "rupture anticipée du contrat de travail pour arrêt de tournage"));
615
                v.add(Tuple2.create("095", "rupture anticipée du contrat de travail ou d’un contrat de mission pour faute grave"));
616
                v.add(Tuple2.create("096", "rupture anticipée du contrat de travail ou d’un contrat de mission pour faute lourde"));
617
                v.add(Tuple2.create("097", "rupture anticipée d’un contrat de travail ou d’un contrat de mission suite à fermeture de l'établissement"));
618
                v.add(Tuple2.create("098", "retrait d'enfant"));
619
                v.add(Tuple2.create("998", "transfert du contrat de travail sans rupture du contrat vers un autre établissement n'effectuant pas encore de DSN"));
620
                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"));
621
                insertValues(v, table);
622
            } catch (SQLException ex) {
623
                throw new IllegalStateException("Erreur lors de la création de la table " + "MOTIF_FIN_CONTRAT", ex);
624
            }
625
        }
626
 
627
        DSNUpdateRubrique dsnUpdateRubrique = new DSNUpdateRubrique(root);
628
        dsnUpdateRubrique.updateRubriqueCotisation();
142 ilm 629
 
630
        // PHASE 3
156 ilm 631
        final SQLTable caisseCot = root.getTable("CAISSE_COTISATION");
142 ilm 632
        {
633
            SQLTable tableCaisseCotisation = root.findTable("CAISSE_COTISATION");
634
            if (!tableCaisseCotisation.contains("ORG_PROTECTION_SOCIALE")) {
635
                final AlterTable alterCaisse = new AlterTable(tableCaisseCotisation);
636
                alterCaisse.addBooleanColumn("ORG_PROTECTION_SOCIALE", Boolean.FALSE, false);
637
                alterCaisse.addBooleanColumn("URSSAF", Boolean.FALSE, false);
638
 
639
                root.getBase().getDataSource().execute(alterCaisse.asString());
640
                root.refetchTable("CAISSE_COTISATION");
641
                root.getSchema().updateVersion();
642
 
643
                {
644
                    UpdateBuilder upCaisse = new UpdateBuilder(tableCaisseCotisation);
645
                    upCaisse.setObject("ORG_PROTECTION_SOCIALE", Boolean.TRUE);
646
                    upCaisse.setWhere(new Where(tableCaisseCotisation.getField("NOM"), Arrays.asList("URSSAF", "AGIRC", "ARRCO")));
647
                    root.getBase().getDataSource().execute(upCaisse.asString());
648
                }
649
                {
650
                    UpdateBuilder upCaisse = new UpdateBuilder(tableCaisseCotisation);
651
                    upCaisse.setObject("URSSAF", Boolean.TRUE);
652
                    upCaisse.setWhere(new Where(tableCaisseCotisation.getField("NOM"), Arrays.asList("URSSAF")));
653
                    root.getBase().getDataSource().execute(upCaisse.asString());
654
                }
655
            }
656
            if (!root.contains("CAISSE_MODE_PAIEMENT")) {
657
                final SQLCreateTable createCaisseMode = new SQLCreateTable(root, "CAISSE_MODE_PAIEMENT");
658
                createCaisseMode.addVarCharColumn("CODE", 25);
659
                createCaisseMode.addVarCharColumn("NOM", 512);
660
 
661
                try {
662
                    root.getBase().getDataSource().execute(createCaisseMode.asString());
663
                    insertUndef(createCaisseMode);
664
                    root.refetchTable("CAISSE_MODE_PAIEMENT");
665
                    root.getSchema().updateVersion();
666
 
667
                    final SQLTable table = root.getTable("CAISSE_MODE_PAIEMENT");
668
                    List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
669
                    v.add(Tuple2.create("01", "chèque"));
670
                    v.add(Tuple2.create("02", "virement"));
671
                    v.add(Tuple2.create("03", "prélèvement"));
672
                    v.add(Tuple2.create("04", "titre inter-bancaire de paiement"));
673
                    v.add(Tuple2.create("05", "prélèvement SEPA"));
674
                    v.add(Tuple2.create("06", "versement réalisé par un autre établissement"));
675
 
676
                    insertValues(v, table);
677
                } catch (SQLException ex) {
678
                    throw new IllegalStateException("Erreur lors de la création de la table " + "CAISSE_MODE_PAIEMENT", ex);
679
                }
680
 
681
                final SQLCreateTable createCaisseREnseignement = new SQLCreateTable(root, "CAISSE_COTISATION_RENSEIGNEMENT");
682
                createCaisseREnseignement.addVarCharColumn("IDENTIFIANT", 256);
683
                createCaisseREnseignement.addVarCharColumn("SIRET", 256);
684
                createCaisseREnseignement.addVarCharColumn("BIC", 256);
685
                createCaisseREnseignement.addVarCharColumn("IBAN", 256);
686
                createCaisseREnseignement.addVarCharColumn("ENTITE_AFFECTATION", 256);
687
                createCaisseREnseignement.addBooleanColumn("ORGANISME_COMPLEMENTAIRE", Boolean.FALSE, false);
688
                createCaisseREnseignement.addBooleanColumn("PAIEMENT_TRIMESTRIEL", Boolean.FALSE, false);
689
                createCaisseREnseignement.addVarCharColumn("CODE_DELEGATAIRE", 256);
690
                createCaisseREnseignement.addForeignColumn("ID_CAISSE_MODE_PAIEMENT", root.getTable("CAISSE_MODE_PAIEMENT"));
156 ilm 691
                createCaisseREnseignement.addForeignColumn("ID_CAISSE_COTISATION", caisseCot);
142 ilm 692
                createCaisseREnseignement.addForeignColumn("ID_SOCIETE_COMMON", root.getTable("SOCIETE_COMMON"));
693
                root.getBase().getDataSource().execute(createCaisseREnseignement.asString());
694
                insertUndef(createCaisseREnseignement);
695
                root.refetchTable("CAISSE_COTISATION_RENSEIGNEMENT");
696
                root.getSchema().updateVersion();
697
            }
698
            SQLTable tableCR = root.getTable("CAISSE_COTISATION_RENSEIGNEMENT");
699
            if (!tableCR.contains("PAIEMENT_TRIMESTRIEL")) {
700
                AlterTable alter = new AlterTable(tableCR);
701
                alter.addBooleanColumn("PAIEMENT_TRIMESTRIEL", Boolean.FALSE, false);
702
                root.getBase().getDataSource().execute(alter.asString());
703
                root.refetchTable("CAISSE_COTISATION_RENSEIGNEMENT");
704
                root.getSchema().updateVersion();
705
            }
144 ilm 706
 
707
            if (!tableCR.contains("JOUR_PAIEMENT")) {
708
                AlterTable alter = new AlterTable(tableCR);
709
                alter.addIntegerColumn("JOUR_PAIEMENT", 0);
710
                root.getBase().getDataSource().execute(alter.asString());
711
                root.refetchTable("CAISSE_COTISATION_RENSEIGNEMENT");
712
                root.getSchema().updateVersion();
713
            }
142 ilm 714
        }
715
 
716
        if (!root.contains("TYPE_COMPOSANT_BASE_ASSUJETTIE")) {
717
            final SQLCreateTable createTableTypeComposant = new SQLCreateTable(root, "TYPE_COMPOSANT_BASE_ASSUJETTIE");
718
            createTableTypeComposant.addVarCharColumn("CODE", 25);
719
            createTableTypeComposant.addVarCharColumn("NOM", 512);
720
 
721
            try {
722
                root.getBase().getDataSource().execute(createTableTypeComposant.asString());
723
                insertUndef(createTableTypeComposant);
724
                root.refetchTable("TYPE_COMPOSANT_BASE_ASSUJETTIE");
725
                root.getSchema().updateVersion();
726
 
727
                final SQLTable table = root.getTable("TYPE_COMPOSANT_BASE_ASSUJETTIE");
728
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
729
 
730
                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"));
731
                v.add(Tuple2.create("02", "Montant du SMIC retenu pour le calcul du crédit d'impôt compétitivité-emploi"));
732
                v.add(Tuple2.create("03", "Contributions patronales à des régimes complémentaires de retraite"));
733
                v.add(Tuple2.create("04", "Contributions patronales destinées au financement des prestations de prévoyance complémentaire"));
734
                v.add(Tuple2.create("05", "Contributions patronales destinées au financement des prestations de retraite supplémentaire"));
735
                v.add(Tuple2.create("06", "Plafond calculé pour salarié poly-employeurs"));
736
                v.add(Tuple2.create("10", "Salaire brut Prévoyance"));
737
                v.add(Tuple2.create("11", "Tranche A Prévoyance"));
738
                v.add(Tuple2.create("12", "Tranche 2 Prévoyance"));
739
                v.add(Tuple2.create("13", "Tranche B Prévoyance"));
740
                v.add(Tuple2.create("14", "Tranche C Prévoyance"));
741
                v.add(Tuple2.create("15", "Tranche D Prévoyance"));
742
                v.add(Tuple2.create("16", "Tranche D1 Prévoyance"));
743
                v.add(Tuple2.create("17", "Base spécifique Prévoyance"));
744
                v.add(Tuple2.create("18", "Base forfaitaire Prévoyance"));
745
                v.add(Tuple2.create("19", "Base fictive Prévoyance reconstituée"));
746
                v.add(Tuple2.create("20", "Montant forfaitaire Prévoyance"));
747
                v.add(Tuple2.create("21", "Montant Prévoyance libre ou exceptionnel"));
748
                v.add(Tuple2.create("22", "Montant des indemnités journalières CRPCEN"));
749
                v.add(Tuple2.create("90", "Retenue sur salaire"));
750
                v.add(Tuple2.create("91", "Base de taxe sur les salaires au taux normal"));
751
 
752
                insertValues(v, table);
753
 
754
                AlterTable tableRubCotis = new AlterTable(tableRubCot);
755
                tableRubCotis.addForeignColumn("ID_TYPE_COMPOSANT_BASE_ASSUJETTIE", root.getTable("TYPE_COMPOSANT_BASE_ASSUJETTIE"));
756
                root.getBase().getDataSource().execute(tableRubCotis.asString());
757
                root.refetchTable(tableRubCot.getName());
758
                root.getSchema().updateVersion();
759
            } catch (SQLException ex) {
760
                throw new IllegalStateException("Erreur lors de la création de la table " + "TYPE_COMPOSANT_BASE_ASSUJETTIE", ex);
761
            }
762
        }
763
        if (!root.contains("CODE_COTISATION_INDIVIDUELLE")) {
764
            final SQLCreateTable createTableTypeComposant = new SQLCreateTable(root, "CODE_COTISATION_INDIVIDUELLE");
765
            createTableTypeComposant.addVarCharColumn("CODE", 25);
766
            createTableTypeComposant.addVarCharColumn("NOM", 512);
767
 
768
            try {
769
                root.getBase().getDataSource().execute(createTableTypeComposant.asString());
770
                insertUndef(createTableTypeComposant);
771
                root.refetchTable("CODE_COTISATION_INDIVIDUELLE");
772
                root.getSchema().updateVersion();
773
 
774
                final SQLTable table = root.getTable("CODE_COTISATION_INDIVIDUELLE");
775
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
776
 
777
                v.add(Tuple2.create("001", "Exonération de cotisations au titre de l'emploi d'un apprenti (loi de 1979)"));
778
                v.add(Tuple2.create("002", "Exonération de cotisations au titre de l'emploi d'un apprenti (loi de 1987)"));
779
                v.add(Tuple2.create("003", "Exonération de cotisations au titre de l'emploi d'un apprenti (loi de 1992)"));
780
                v.add(Tuple2.create("004", "Exonération de cotisations au titre de l'emploi d'un salarié en contrat d'accès à l'emploi"));
781
                v.add(Tuple2.create("006", "Exonération de cotisations au titre de l'emploi d'un salarié en contrat d'accompagnement dans l'emploi"));
782
                v.add(Tuple2.create("008", "Exonération de cotisations au titre de l'emploi d'un salarié en contrat de professionnalisation"));
783
                v.add(Tuple2.create("009", "Exonération de cotisations applicable aux associations intermédiaires"));
784
                v.add(Tuple2.create("010", "Exonération de cotisations applicable aux entreprises des bassins d'emploi à redynamiser"));
785
                v.add(Tuple2.create("011", "Exonération de cotisations applicable au créateur ou repreneur d'entreprise"));
786
                v.add(Tuple2.create("012", "Exonération de cotisations applicable dans les DOM"));
787
                v.add(Tuple2.create("013", "Exonération de cotisations applicable aux entreprises et associations d'aide à domicile"));
788
                v.add(Tuple2.create("014", "Exonérations de cotisations applicable aux entreprises innovantes ou universitaires"));
789
                v.add(Tuple2.create("015", "Exonération de cotisations applicable aux entreprises en zones franches urbaines"));
790
                v.add(Tuple2.create("016", "Exonération de cotisations applicable aux organismes d'intérêt général en zones de revitalisation rurale"));
791
                v.add(Tuple2.create("017", "Exonération de cotisations applicable aux structures agréées de l'aide sociale"));
792
                v.add(Tuple2.create("018", "Réduction générale des cotisations patronales de sécurité sociale"));
793
                v.add(Tuple2.create("019", "Réduction de cotisations applicable aux entreprises des zones de restructuration de la défense"));
794
                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"));
795
                v.add(Tuple2.create("021", "Déduction patronale au titre des heures supplémentaires"));
796
                v.add(Tuple2.create("022", "Exonération de cotisations applicable à une gratification de stage"));
797
                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"));
798
                v.add(Tuple2.create("025", "Exonération de cotisations au titre de l’emploi d’un salarié en chantier et atelier d'insertion"));
799
                v.add(Tuple2.create("027", "Exonération Personnel technique CUMA, hors ateliers"));
800
                v.add(Tuple2.create("028", "Réduction Travailleur Occasionnel"));
801
                v.add(Tuple2.create("029", "CNIEG Réduction employeurs petit pool"));
802
                v.add(Tuple2.create("030", "Camieg Cotisation employeurs Régime spécial Complémentaire"));
803
                v.add(Tuple2.create("031", "Camieg Cotisation salariés Régime spécial Complémentaire"));
804
                v.add(Tuple2.create("032", "Camieg Cotisation salariés Régime spécial Solidarité"));
805
                v.add(Tuple2.create("033", "CNIEG Cotisation employeurs complément d'invalidité"));
806
                v.add(Tuple2.create("034", "CNIEG Cotisation employeurs régime de droit commun (population adossée)"));
807
                v.add(Tuple2.create("035", "CNIEG Cotisation employeurs Régime spécial (population adossée)"));
808
                v.add(Tuple2.create("036", "CNIEG Cotisation employeurs régime spécial (population non adossée)"));
809
                v.add(Tuple2.create("037", "CNIEG Cotisation salariés régime de droit commun (population adossée)"));
810
                v.add(Tuple2.create("038", "CNIEG Cotisation salariés régime spécial (population non adossée)"));
811
                v.add(Tuple2.create("039", "CNIEG Cotisations employeurs petit pool"));
812
                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"));
813
                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"));
814
                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"));
815
                v.add(Tuple2.create("043",
816
                        "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"));
817
                v.add(Tuple2.create("044", "Exonération de cotisation chômage pour les moins de 26 ans"));
818
                v.add(Tuple2.create("045", "Cotisation Accident du travail"));
819
                v.add(Tuple2.create("046", "Cotisation AEF Bourse de l'emploi"));
820
                v.add(Tuple2.create("047", "Cotisation AEF CESA"));
821
                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"));
822
                v.add(Tuple2.create("049", "Cotisation Allocation de logement (FNAL)"));
823
                v.add(Tuple2.create("051", "Cotisation Formation professionnelle ADEFA"));
824
                v.add(Tuple2.create("052", "Cotisation AFNCA, ANEFA, PROVEA, ASCPA"));
825
                v.add(Tuple2.create("053", "Cotisation Formation professionnelle additionnelle FAFSEA"));
826
                v.add(Tuple2.create("054", "Cotisation Formation professionnelle AREFA"));
827
                v.add(Tuple2.create("055", "Cotisation Formation professionnelle CEREFAR"));
828
                v.add(Tuple2.create("056", "Cotisation Formation professionnelle FAFSEA"));
829
                v.add(Tuple2.create("057", "Cotisation Formation professionnelle FAFSEA CDD"));
830
                v.add(Tuple2.create("058", "Cotisation Formation professionnelle FAFSEA des communes forestières"));
831
                v.add(Tuple2.create("059", "Cotisation individuelle Prévoyance-Assurance-Mutuelle pour la période et l'affiliation concernées"));
832
                v.add(Tuple2.create("060", "Cotisation IRCANTEC Tranche A"));
833
                v.add(Tuple2.create("061", "Cotisation IRCANTEC Tranche B"));
834
                v.add(Tuple2.create("063", "RETA Montant de cotisation Arrco"));
835
                v.add(Tuple2.create("064", "RETC Montant de cotisation Agirc"));
836
                v.add(Tuple2.create("065", "Cotisation CRPCEN"));
837
                v.add(Tuple2.create("066", "Cotisation caisse de congés spectacles"));
838
                v.add(Tuple2.create("068", "Contribution solidarité autonomie"));
839
                v.add(Tuple2.create("069", "Contribution sur avantage de pré-retraite entreprise à dater du 11/10/2007 (CAPE)"));
840
                v.add(Tuple2.create("070", "Contribution sur avantage de pré-retraite entreprise aux taux normal (CAPE)"));
841
                v.add(Tuple2.create("071", "Contribution forfait social"));
842
                v.add(Tuple2.create("072", "Contribution sociale généralisée/salaires partiellement déductibles"));
843
                v.add(Tuple2.create("073", "CSG/CRDS sur participation intéressement épargne salariale"));
844
                v.add(Tuple2.create("074", "Cotisation Allocation familiale taux normal  "));
845
                v.add(Tuple2.create("075", "Cotisation Assurance Maladie"));
846
                v.add(Tuple2.create("076", "Cotisation Assurance Vieillesse"));
847
                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"));
848
                v.add(Tuple2.create("078", "Pénalité de 1% emploi sénior"));
849
                v.add(Tuple2.create("079", "Remboursement de la dette sociale"));
850
                v.add(Tuple2.create("081", "Versement transport"));
851
                v.add(Tuple2.create("082", "Versement transport additionnel"));
852
                v.add(Tuple2.create("086", "Cotisation pénibilité mono exposition"));
853
                v.add(Tuple2.create("087", "Cotisation pénibilité multi exposition"));
854
                v.add(Tuple2.create("088", "Exonération versement transport"));
855
                v.add(Tuple2.create("089", "Exonération Contrat Initiative Emploi"));
856
                v.add(Tuple2.create("090", "Exonération accueillants familiaux"));
857
                v.add(Tuple2.create("091", "Cotisation Service de santé au travail"));
858
                v.add(Tuple2.create("092", "Cotisation Association pour l'emploi des cadres ingénieurs et techniciens de l'agriculture (APECITA)"));
859
                v.add(Tuple2.create("093", "Contribution sur indemnités de mise à la retraite"));
860
                v.add(Tuple2.create("094", "Exonération cotisations Allocations familiales (SICAE)"));
861
                v.add(Tuple2.create("096", "Cotisation CRPNPAC au fonds de retraite"));
862
                v.add(Tuple2.create("097", "Cotisation CRPNPAC au fonds d'assurance"));
863
                v.add(Tuple2.create("098", "Cotisation CRPNPAC au fonds de majoration"));
864
                v.add(Tuple2.create("099", "Contribution stock options"));
865
                v.add(Tuple2.create("100", "Contribution pour le financement des organisations syndicales de salariés et organisations professionnelles d'employeurs"));
866
                v.add(Tuple2.create("101", "Association Mutualisation du Coût Inaptitude"));
867
                v.add(Tuple2.create("102", "Cotisation Allocation Familiale - taux réduit"));
868
                v.add(Tuple2.create("103", "Contribution actions gratuites"));
869
                v.add(Tuple2.create("226", "Assiette du Versement Transport"));
870
                v.add(Tuple2.create("901", "Cotisation épargne retraite"));
871
 
872
                insertValues(v, table);
873
 
874
                List<Tuple2<String, String>> vCodeBase = new ArrayList<Tuple2<String, String>>();
875
                vCodeBase.add(Tuple2.create("15", "CNIEG-Assiette brute du régime spécial"));
876
                vCodeBase.add(Tuple2.create("16", "CNIEG-Assiette brute du complément invalidité"));
877
                vCodeBase.add(Tuple2.create("17", "CNIEG - Assiette brute du petit pool"));
878
                vCodeBase.add(Tuple2.create("18", "Camieg - assiette brute plafonnée"));
879
                vCodeBase.add(Tuple2.create("19", "Assiette CRPCEN"));
880
                vCodeBase.add(Tuple2.create("20", "CIBTP - Base brute de cotisations congés payés"));
881
                vCodeBase.add(Tuple2.create("21", "CIBTP - Base brute de cotisations OPPBTP permanents"));
882
                vCodeBase.add(Tuple2.create("22", "Base brute spécifique"));
883
                vCodeBase.add(Tuple2.create("23", "Base exceptionnelle (Agirc Arrco)"));
884
                vCodeBase.add(Tuple2.create("24", "Base plafonnée spécifique"));
885
                vCodeBase.add(Tuple2.create("25", "Assiette de contribution libératoire"));
886
                vCodeBase.add(Tuple2.create("27", "Assiette Caisse de congés spectacles"));
887
                vCodeBase.add(Tuple2.create("28", "Base IRCANTEC cotisée"));
888
                vCodeBase.add(Tuple2.create("29", "Base IRCANTEC non cotisée (arrêt de travail)"));
889
                vCodeBase.add(Tuple2.create("31", "Eléments de cotisation Prévoyance, Santé, retraite supplémentaire"));
890
                vCodeBase.add(Tuple2.create("33", "Assiette Contribution sur les avantages de préretraite entreprise"));
891
                vCodeBase.add(Tuple2.create("34", "CIBTP -Base plafonnée de cotisations intempéries gros oeuvre travaux publics"));
892
                vCodeBase.add(Tuple2.create("35", "CIBTP -Base plafonnée de cotisations intempéries second oeuvre"));
893
                vCodeBase.add(Tuple2.create("36", "CIBTP -Base \"A\" de cotisations organisme professionnel BTP"));
894
                vCodeBase.add(Tuple2.create("37", "Assiette de pénibilité"));
895
                vCodeBase.add(Tuple2.create("38", "Rémunération pour le calcul de la réduction Travailleur Occasionnel"));
896
                vCodeBase.add(Tuple2.create("39", "CIBTP -Base \"B\" de cotisations organisme professionnel BTP"));
897
                vCodeBase.add(Tuple2.create("40", "CIBTP -Base \"C\" de cotisations organisme professionnel BTP"));
898
                vCodeBase.add(Tuple2.create("41", "CRPNPAC-Assiette soumise au taux normal (non-plafonnée)"));
899
                vCodeBase.add(Tuple2.create("42", "CRPNPAC-Assiette soumise au taux majoré (non-plafonnée)"));
900
                vCodeBase.add(Tuple2.create("43", "Base plafonnée exceptionnelle Agirc Arrco"));
901
                vCodeBase.add(Tuple2.create("44", "Assiette du forfait social à 16%"));
902
                vCodeBase.add(Tuple2.create("45", "Base plafonnée ICP Agirc-Arrco"));
903
                vCodeBase.add(Tuple2.create("90", "Autre revenu net imposable"));
904
                insertValues(vCodeBase, root.getTable("CODE_BASE_ASSUJETTIE"));
905
 
906
                AlterTable tableRubCotis = new AlterTable(tableRubCot);
907
                tableRubCotis.addForeignColumn("ID_CODE_COTISATION_INDIVIDUELLE", root.getTable("CODE_COTISATION_INDIVIDUELLE"));
908
                root.getBase().getDataSource().execute(tableRubCotis.asString());
909
                root.refetchTable(tableRubCot.getName());
910
                root.getSchema().updateVersion();
911
            } catch (SQLException ex) {
912
                throw new IllegalStateException("Erreur lors de la création de la table " + "CODE_COTISATION_INDIVIDUELLE", ex);
913
            }
914
            {
915
                final SQLTable tableCodeBase = root.getTable("CODE_BASE_ASSUJETTIE");
916
                SQLSelect selCodeBase = new SQLSelect();
917
                selCodeBase.addSelectStar(tableCodeBase);
918
                List<SQLRow> rowsCodeBase = SQLRowListRSH.execute(selCodeBase);
919
                Map<String, SQLRow> mapCodeBase = new HashMap<String, SQLRow>();
920
                for (SQLRow sqlRow : rowsCodeBase) {
921
 
922
                    final String string = sqlRow.getString("CODE");
923
                    mapCodeBase.put(string, sqlRow);
924
                }
925
                final SQLTable tableCodeTypeComp = root.getTable("TYPE_COMPOSANT_BASE_ASSUJETTIE");
926
                SQLSelect selCodeTypeComp = new SQLSelect();
927
                selCodeTypeComp.addSelectStar(tableCodeTypeComp);
928
                List<SQLRow> rowsTypeComp = SQLRowListRSH.execute(selCodeTypeComp);
929
                Map<String, SQLRow> mapTypeComp = new HashMap<String, SQLRow>();
930
                for (SQLRow sqlRow : rowsTypeComp) {
931
                    final String string = sqlRow.getString("CODE");
932
                    mapTypeComp.put(string, sqlRow);
933
                }
934
                final SQLTable tableCodeCotInd = root.getTable("CODE_COTISATION_INDIVIDUELLE");
935
                SQLSelect selCodeCodeInd = new SQLSelect();
936
                selCodeCodeInd.addSelectStar(tableCodeCotInd);
937
                List<SQLRow> rowsCodeInd = SQLRowListRSH.execute(selCodeCodeInd);
938
                Map<String, SQLRow> mapCodeInd = new HashMap<String, SQLRow>();
939
                for (SQLRow sqlRow : rowsCodeInd) {
940
                    final String string = sqlRow.getString("CODE");
941
                    mapCodeInd.put(string, sqlRow);
942
                }
156 ilm 943
                final SQLTable tableCaisse = caisseCot;
142 ilm 944
                SQLSelect selCodeCodeCaisse = new SQLSelect();
945
                selCodeCodeCaisse.addSelectStar(tableCaisse);
946
                List<SQLRow> rowsCodeCaisse = SQLRowListRSH.execute(selCodeCodeCaisse);
947
                Map<String, SQLRow> mapCodeCaisse = new HashMap<String, SQLRow>();
948
                for (SQLRow sqlRow : rowsCodeCaisse) {
949
                    final String string = sqlRow.getString("NOM");
950
                    mapCodeCaisse.put(string, sqlRow);
951
                }
952
                if (mapCodeCaisse.containsKey("ARRCO")) {
953
                    UpdateBuilder updaterRubCot = new UpdateBuilder(tableRubCot);
954
                    updaterRubCot.setObject("ID_CODE_BASE_ASSUJETTIE", mapCodeBase.get("02").getID());
955
                    updaterRubCot.setObject("ID_CODE_COTISATION_INDIVIDUELLE", mapCodeInd.get("063").getID());
956
                    // updaterRubCot.setObject("ID_TYPE_COMPOSANT_BASE_ASSUJETTIE",
957
                    // mapTypeComp.get("03").getID());
958
                    updaterRubCot.setWhere(new Where(tableRubCot.getField("ID_CAISSE_COTISATION"), "=", mapCodeCaisse.get("ARRCO").getID()));
959
                    root.getBase().getDataSource().execute(updaterRubCot.asString());
960
                }
961
                if (mapCodeCaisse.containsKey("AGIRC")) {
962
                    UpdateBuilder updaterRubCot = new UpdateBuilder(tableRubCot);
963
                    updaterRubCot.setObject("ID_CODE_BASE_ASSUJETTIE", mapCodeBase.get("03").getID());
964
                    updaterRubCot.setObject("ID_CODE_COTISATION_INDIVIDUELLE", mapCodeInd.get("064").getID());
965
                    // updaterRubCot.setObject("ID_TYPE_COMPOSANT_BASE_ASSUJETTIE",
966
                    // mapTypeComp.get("03").getID());
967
                    updaterRubCot.setWhere(new Where(tableRubCot.getField("ID_CAISSE_COTISATION"), "=", mapCodeCaisse.get("AGIRC").getID()));
968
                    root.getBase().getDataSource().execute(updaterRubCot.asString());
969
                }
970
            }
971
        }
972
 
973
        if (!tableRubNet.contains("ID_CODE_COTISATION_INDIVIDUELLE")) {
974
            AlterTable alterRubNet = new AlterTable(tableRubNet);
975
            alterRubNet.addForeignColumn("ID_CODE_COTISATION_INDIVIDUELLE", root.getTable("CODE_COTISATION_INDIVIDUELLE"));
976
            root.getBase().getDataSource().execute(alterRubNet.asString());
977
            root.refetchTable(tableRubNet.getName());
978
            root.getSchema().updateVersion();
979
        }
980
        if (!tableRubNet.contains("ID_TYPE_COMPOSANT_BASE_ASSUJETTIE")) {
981
            AlterTable alterRubNet = new AlterTable(tableRubNet);
982
            alterRubNet.addForeignColumn("ID_TYPE_COMPOSANT_BASE_ASSUJETTIE", root.getTable("TYPE_COMPOSANT_BASE_ASSUJETTIE"));
983
            root.getBase().getDataSource().execute(alterRubNet.asString());
984
            root.refetchTable(tableRubNet.getName());
985
            root.getSchema().updateVersion();
986
        }
987
        if (!tableRubNet.contains("ID_CODE_BASE_ASSUJETTIE")) {
988
            AlterTable alterRubNet = new AlterTable(tableRubNet);
989
            alterRubNet.addForeignColumn("ID_CODE_BASE_ASSUJETTIE", root.getTable("CODE_BASE_ASSUJETTIE"));
990
            root.getBase().getDataSource().execute(alterRubNet.asString());
991
            root.refetchTable(tableRubNet.getName());
992
            root.getSchema().updateVersion();
993
        }
994
 
995
        if (!tableRubNet.contains("ID_CAISSE_COTISATION")) {
996
            AlterTable alterRubNet = new AlterTable(tableRubNet);
156 ilm 997
            alterRubNet.addForeignColumn("ID_CAISSE_COTISATION", caisseCot);
142 ilm 998
            root.getBase().getDataSource().execute(alterRubNet.asString());
999
            root.refetchTable(tableRubNet.getName());
1000
            root.getSchema().updateVersion();
1001
        }
1002
 
1003
        if (!root.contains("CODE_COTISATION_ETABLISSEMENT")) {
1004
            final SQLCreateTable createTableTypeComposant = new SQLCreateTable(root, "CODE_COTISATION_ETABLISSEMENT");
1005
            createTableTypeComposant.addVarCharColumn("CODE", 25);
1006
            createTableTypeComposant.addVarCharColumn("NOM", 512);
1007
 
1008
            try {
1009
                root.getBase().getDataSource().execute(createTableTypeComposant.asString());
1010
                insertUndef(createTableTypeComposant);
1011
                root.refetchTable("CODE_COTISATION_ETABLISSEMENT");
1012
                root.getSchema().updateVersion();
1013
 
1014
                final SQLTable table = root.getTable("CODE_COTISATION_ETABLISSEMENT");
1015
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
1016
 
1017
                v.add(Tuple2.create("001", "Cotisation ADPFA (Association pour le Développement du Paritarisme des Fleuristes et Animaliers)"));
1018
                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)"));
1019
                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)"));
1020
                v.add(Tuple2.create("004 ", "Cotisation CPPNTT (Commission Paritaire Professionnelle Nationale du Travail Temporaire)"));
1021
                v.add(Tuple2.create("005 ", "Cotisation Développement du paritarisme"));
1022
                v.add(Tuple2.create("006 ", "Cotisation Dialogue social"));
1023
                v.add(Tuple2.create("007 ", "Cotisation FAF (Fonds d'Assurance formation)"));
1024
                v.add(Tuple2.create("009 ", "Cotisation FAPS (Fonds d'action professionnelle et sociale)"));
1025
                v.add(Tuple2.create("010 ", "Cotisation FASTT (Fonds d'Action Sociale du Travail Temporaire)"));
1026
                v.add(Tuple2.create("011 ", "Cotisation Fonds de péréquation"));
1027
                v.add(Tuple2.create("012 ", "Cotisation IFC (Indemnités de fin de carrière)"));
1028
                v.add(Tuple2.create("017 ", "Cotisation ORGA (Organisations Syndicales  du Travail Temporaire)"));
1029
                v.add(Tuple2.create("018 ", "Cotisation Promotion et recrutement"));
1030
                v.add(Tuple2.create("019 ", "Cotisations attachées à une population de non salariés ayants"));
1031
                v.add(Tuple2.create("020 ", "Cotisations attachées à une population de non salariés retraités"));
1032
                v.add(Tuple2.create("021 ", "Cotisations FMSE (Fond national agricole de mutualisation des risques sanitaires et environnementaux)"));
1033
                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)"));
1034
                v.add(Tuple2.create("023 ", "Chiffre d'affaire"));
1035
                v.add(Tuple2.create("024 ", "Nombre d'heures d'intérim"));
1036
                v.add(Tuple2.create("025 ", "Contribution aux régimes supplémentaires de retraite à prestations définies - Rente"));
1037
                v.add(Tuple2.create("026 ", "Contribution aux régimes supplémentaires de retraite à prestations définies - Prime"));
1038
                v.add(Tuple2.create("027 ", "Contribution aux régimes supplémentaires de retraite à prestations définies - Dotations"));
1039
                v.add(Tuple2.create("028 ", "Contribution additionnelle sur les rentes liquidées"));
1040
                v.add(Tuple2.create("029 ", "Contribution aux régimes supplémentaires de retraite à prestations définies. Rente à taux 7%"));
1041
                v.add(Tuple2.create("030 ", "Contribution aux régimes supplémentaires de retraite à prestations définies. Rente à taux 14%"));
1042
                v.add(Tuple2.create("031 ", "Contribution additionnelle de solidarité pour l'autonomie"));
1043
                v.add(Tuple2.create("032 ", "Contribution Sociale généralisée au taux de 3,80% + RDS sur revenu de remplacement "));
1044
                v.add(Tuple2.create("033 ", "Contribution Sociale généralisée au taux de 6,20% + RDS sur revenu de remplacement "));
1045
                v.add(Tuple2.create("034 ", "Contribution Sociale généralisée au taux de 6,60% + RDS sur revenu de remplacement "));
1046
                v.add(Tuple2.create("035 ", "Contribution Sociale généralisée au taux de 7,50% + RDS sur revenu de remplacement "));
1047
                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)"));
1048
                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)"));
1049
                v.add(Tuple2.create("038 ", "Cotisation TTC  sur assiette sans  congés payés (Constructys Organisme Paritaire Collecteur Agréé pour le BTP)"));
1050
                v.add(Tuple2.create("039 ",
1051
                        "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)"));
1052
                v.add(Tuple2.create("040 ",
1053
                        "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)"));
1054
                v.add(Tuple2.create("041 ", "Cotisation maladie sur les avantages de préretraite"));
1055
                v.add(Tuple2.create("042 ", "Cotisation maladie sur les avantages de retraite"));
1056
                v.add(Tuple2.create("043 ", "Cotisation maladie Alsace-Moselle sur les avantages de retraite"));
1057
                v.add(Tuple2.create("044 ", "Cotisation forfait social à 8%"));
1058
                v.add(Tuple2.create("045 ", "Cotisation forfait social à 20%"));
1059
                v.add(Tuple2.create("090 ", "Cotisation spécifique Prévoyance"));
1060
 
1061
                insertValues(v, table);
1062
 
1063
                AlterTable tableRubCotis = new AlterTable(tableRubCot);
1064
                tableRubCotis.addForeignColumn("ID_CODE_COTISATION_ETABLISSEMENT", root.getTable("CODE_COTISATION_ETABLISSEMENT"));
1065
                root.getBase().getDataSource().execute(tableRubCotis.asString());
1066
                root.refetchTable(tableRubCot.getName());
1067
                root.getSchema().updateVersion();
1068
            } catch (SQLException ex) {
1069
                throw new IllegalStateException("Erreur lors de la création de la table " + "CODE_COTISATION_ETABLISSEMENT", ex);
1070
            }
1071
        }
1072
 
1073
        if (!root.contains("CODE_PENIBILITE")) {
1074
            final SQLCreateTable createTableTypeComposant = new SQLCreateTable(root, "CODE_PENIBILITE");
1075
            createTableTypeComposant.addVarCharColumn("CODE", 25);
1076
            createTableTypeComposant.addVarCharColumn("NOM", 512);
1077
 
1078
            try {
1079
                root.getBase().getDataSource().execute(createTableTypeComposant.asString());
1080
                insertUndef(createTableTypeComposant);
1081
                root.refetchTable("CODE_PENIBILITE");
1082
                root.getSchema().updateVersion();
1083
 
1084
                final SQLTable table = root.getTable("CODE_PENIBILITE");
1085
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
1086
 
1087
                v.add(Tuple2.create("01", "les manutentions manuelles de charges"));
1088
                v.add(Tuple2.create("02", "les postures pénibles (positions forcées des articulations)"));
1089
                v.add(Tuple2.create("03", "les vibrations mécaniques"));
1090
                v.add(Tuple2.create("04", "les agents chimiques dangereux"));
1091
                v.add(Tuple2.create("05", "les activités exercées en milieu hyperbare"));
1092
                v.add(Tuple2.create("06", "les températures extrêmes"));
1093
                v.add(Tuple2.create("07", "le bruit"));
1094
                v.add(Tuple2.create("08", "le travail de nuit"));
1095
                v.add(Tuple2.create("09", "le travail en équipes successives alternantes"));
1096
                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)"));
1097
                v.add(Tuple2.create("99", "annulation"));
1098
 
1099
                insertValues(v, table);
1100
 
1101
            } catch (SQLException ex) {
1102
                throw new IllegalStateException("Erreur lors de la création de la table " + "CODE_PENIBILITE", ex);
1103
            }
1104
        }
1105
 
1106
        if (!root.contains("AYANT_DROIT_TYPE")) {
1107
            final SQLCreateTable createTableTypeAyantDroit = new SQLCreateTable(root, "AYANT_DROIT_TYPE");
1108
            createTableTypeAyantDroit.addVarCharColumn("CODE", 25);
1109
            createTableTypeAyantDroit.addVarCharColumn("NOM", 512);
1110
 
1111
            try {
1112
                root.getBase().getDataSource().execute(createTableTypeAyantDroit.asString());
1113
                insertUndef(createTableTypeAyantDroit);
1114
                root.refetchTable("AYANT_DROIT_TYPE");
1115
                root.getSchema().updateVersion();
1116
 
1117
                final SQLTable table = root.getTable("AYANT_DROIT_TYPE");
1118
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
1119
 
1120
                v.add(Tuple2.create("01", "Adultes (conjoint, concubin, pacs)"));
1121
                v.add(Tuple2.create("02", "Enfant"));
1122
                v.add(Tuple2.create("03", "Autre (ascendant, collatéraux, ...)"));
1123
 
1124
                insertValues(v, table);
1125
 
1126
            } catch (SQLException ex) {
1127
                throw new IllegalStateException("Erreur lors de la création de la table " + "AYANT_DROIT_TYPE", ex);
1128
            }
1129
        }
1130
 
156 ilm 1131
        if (!root.contains("TYPE_TAUX_PAS")) {
1132
            final SQLCreateTable createTableMotif = new SQLCreateTable(root, "TYPE_TAUX_PAS");
1133
            createTableMotif.addVarCharColumn("CODE", 25);
1134
            createTableMotif.addVarCharColumn("NOM", 512);
1135
 
1136
            try {
1137
                root.getBase().getDataSource().execute(createTableMotif.asString());
1138
                insertUndef(createTableMotif);
1139
                root.refetchTable("TYPE_TAUX_PAS");
1140
                root.getSchema().updateVersion();
1141
 
1142
                final SQLTable table = root.getTable("TYPE_TAUX_PAS");
1143
                List<Tuple2<String, String>> v = new ArrayList<Tuple2<String, String>>();
1144
                v.add(Tuple2.create("01", " Taux transmis par la DGFIP"));
1145
                v.add(Tuple2.create("10", " Barème horaire métropole"));
1146
                v.add(Tuple2.create("11", " Barème quotidien métropole"));
1147
                v.add(Tuple2.create("12", " Barème hebdomadaire métropole"));
1148
                v.add(Tuple2.create("13", " Barème mensuel métropole"));
1149
                v.add(Tuple2.create("14", " Barème trimestriel métropole"));
1150
                v.add(Tuple2.create("15", " Barème semestriel métropole"));
1151
                v.add(Tuple2.create("16", " Barème annuel métropole"));
1152
                v.add(Tuple2.create("17", " Barème mathématique sur base mensuelle métropole"));
1153
                v.add(Tuple2.create("18", " Barème mathématique sur base annuelle métropole"));
1154
                v.add(Tuple2.create("20", " Barème horaire Guadeloupe, Réunion et Martinique"));
1155
                v.add(Tuple2.create("21", " Barème quotidien Guadeloupe, Réunion et Martinique"));
1156
                v.add(Tuple2.create("22", " Barème hebdomadaire Guadeloupe, Réunion et Martinique"));
1157
                v.add(Tuple2.create("23", " Barème mensuel Guadeloupe, Réunion et Martinique"));
1158
                v.add(Tuple2.create("24", " Barème trimestriel Guadeloupe, Réunion et Martinique"));
1159
                v.add(Tuple2.create("25", " Barème semestriel Guadeloupe, Réunion et Martinique"));
1160
                v.add(Tuple2.create("26", " Barème annuel Guadeloupe, Réunion et Martinique"));
1161
                v.add(Tuple2.create("27", " Barème mathématique sur base mensuelle Guadeloupe, Réunion et Martinique"));
1162
                v.add(Tuple2.create("28", " Barème mathématique sur base annuelle Guadeloupe, Réunion et Martinique"));
1163
                v.add(Tuple2.create("30", " Barème horaire Guyane et Mayotte"));
1164
                v.add(Tuple2.create("31", " Barème quotidien Guyane et Mayotte"));
1165
                v.add(Tuple2.create("32", " Barème hebdomadaire Guyane et Mayotte"));
1166
                v.add(Tuple2.create("33", " Barème mensuel Guyane et Mayotte"));
1167
                v.add(Tuple2.create("34", " Barème trimestriel Guyane et Mayotte"));
1168
                v.add(Tuple2.create("35", " Barème semestriel Guyane et Mayotte"));
1169
                v.add(Tuple2.create("36", " Barème annuel Guyane et Mayotte"));
1170
                v.add(Tuple2.create("37", " Barème mathématique sur base mensuelle Guyane et Mayotte"));
1171
                v.add(Tuple2.create("38", " Barème mathématique sur base annuelle Guyane et Mayotte"));
1172
                v.add(Tuple2.create("99", " Indu relatif à un exercice antérieur – pas de taux de PAS"));
1173
 
1174
                insertValues(v, table);
1175
            } catch (SQLException ex) {
1176
                throw new IllegalStateException("Erreur lors de la création de la table " + "TYPE_TAUX_PAS", ex);
1177
            }
1178
        }
1179
 
1180
        // P19V01.2
1181
        final SQLTable tableCotInd = root.getTable("CODE_COTISATION_INDIVIDUELLE");
1182
        List<Tuple2<String, String>> vCodeIndiv = new ArrayList<>();
1183
        vCodeIndiv.add(Tuple2.create("104", "Pénibilité Cotisation de base"));
1184
        vCodeIndiv.add(Tuple2.create("105", "Montant de cotisation Régime Unifié Agirc-Arrco y compris Apec"));
1185
        vCodeIndiv.add(Tuple2.create("106", "Réduction générale des cotisations patronales Agirc-Arrco"));
1186
        insertValues(vCodeIndiv, tableCotInd);
1187
 
1188
        final SQLTable tableCTP = root.getTable("CODE_CAISSE_TYPE_RUBRIQUE");
1189
        List<Tuple2<String, String>> vCTP = new ArrayList<>();
1190
        vCTP.add(Tuple2.create("003", "Réduction cotisations salariale heures supplémentaires"));
1191
        vCTP.add(Tuple2.create("510", "Prime exceptionnelle de pouvoir d’achat"));
1192
        insertValues(vCTP, tableCTP);
1193
 
1194
        final SQLTable tableTypeBrut = root.getTable("CODE_TYPE_RUBRIQUE_BRUT");
1195
        List<Tuple3<String, String, String>> vbrutType = new ArrayList<>();
1196
        vbrutType.add(Tuple3.create("016", "[FP] Heures affectées à un travail d’aide à domicile", DsnTypeCodeBrut.REMUNERATION.getName()));
1197
        vbrutType.add(Tuple3.create("017", "Heures supplémentaires ou complémentaires aléatoires", DsnTypeCodeBrut.REMUNERATION.getName()));
1198
        vbrutType.add(Tuple3.create("018", "Heures supplémentaires structurelles", DsnTypeCodeBrut.REMUNERATION.getName()));
1199
        DsnBrutCode dsnBurCode = new DsnBrutCode();
1200
        dsnBurCode.updateTable(vbrutType, tableTypeBrut);
1201
 
132 ilm 1202
    }
1203
 
1204
    public void updateDSN(final DBRoot root) throws SQLException {
1205
        final SQLTable tableCodeStatutCat = root.getTable("CODE_STATUT_CATEGORIEL");
1206
        SQLRow rowNonCadre = tableCodeStatutCat.getRow(4);
1207
        if (rowNonCadre != null) {
1208
            rowNonCadre.createEmptyUpdateRow().put("CODE", "04").commit();
1209
        }
1210
        SQLRow rowSansStatut = tableCodeStatutCat.getRow(4);
1211
        if (rowSansStatut != null) {
1212
            rowSansStatut.createEmptyUpdateRow().put("CODE", "99").commit();
1213
        }
142 ilm 1214
        // 04 non cadre
1215
        UpdateBuilder up04 = new UpdateBuilder(tableCodeStatutCat);
1216
        up04.setObject("NOM", "Non cadre");
1217
        up04.setWhere(new Where(tableCodeStatutCat.getField("CODE"), "=", "04"));
1218
        root.getBase().getDataSource().execute(up04.asString());
132 ilm 1219
 
142 ilm 1220
        // 99 - pas de retraite complémentaire
1221
        UpdateBuilder up99 = new UpdateBuilder(tableCodeStatutCat);
1222
        up99.setObject("NOM", "Pas de retraite complémentaire");
1223
        up99.setWhere(new Where(tableCodeStatutCat.getField("CODE"), "=", "99"));
1224
        root.getBase().getDataSource().execute(up99.asString());
1225
 
132 ilm 1226
        if (!root.contains("ARRET_TRAVAIL")) {
1227
 
1228
            final SQLCreateTable createTable = new SQLCreateTable(root, "ARRET_TRAVAIL");
1229
            createTable.addForeignColumn("SALARIE");
1230
            createTable.addDateAndTimeColumn("DATE_DERNIER_JOUR_TRAV");
1231
            createTable.addDateAndTimeColumn("DATE_FIN_PREV");
1232
            createTable.addBooleanColumn("SUBROGATION", Boolean.FALSE, false);
1233
            createTable.addDateAndTimeColumn("DATE_DEBUT_SUBROGATION");
1234
            createTable.addDateAndTimeColumn("DATE_FIN_SUBROGATION");
1235
            createTable.addForeignColumn("ID_MOTIF_ARRET_TRAVAIL", root.findTable("MOTIF_ARRET_TRAVAIL"));
1236
            createTable.addForeignColumn("ID_MOTIF_REPRISE_ARRET_TRAVAIL", root.findTable("MOTIF_REPRISE_ARRET_TRAVAIL"));
1237
            createTable.addDateAndTimeColumn("DATE_REPRISE");
1238
            createTable.addDateAndTimeColumn("DATE_ACCIDENT");
1239
 
1240
            try {
1241
                root.getBase().getDataSource().execute(createTable.asString());
1242
                insertUndef(createTable);
1243
                root.refetchTable("ARRET_TRAVAIL");
1244
                root.getSchema().updateVersion();
1245
            } catch (SQLException ex) {
1246
                throw new IllegalStateException("Erreur lors de la création de la table " + "ARRET_TRAVAIL", ex);
1247
            }
1248
        }
1249
 
142 ilm 1250
        if (!root.contains("FIN_CONTRAT")) {
1251
 
1252
            final SQLCreateTable createTable = new SQLCreateTable(root, "FIN_CONTRAT");
1253
            createTable.addForeignColumn("FICHE_PAYE");
1254
            createTable.addForeignColumn("ID_MOTIF_FIN_CONTRAT", root.findTable("MOTIF_FIN_CONTRAT"));
1255
            createTable.addDateAndTimeColumn("DATE_FIN");
1256
            createTable.addDateAndTimeColumn("DATE_NOTIFICATION");
1257
            createTable.addDateAndTimeColumn("DATE_SIGNATURE_CONVENTION");
1258
            createTable.addDateAndTimeColumn("DATE_ENGAGEMENT_PROCEDURE");
1259
            createTable.addDateAndTimeColumn("DERNIER_JOUR_TRAV_PAYE");
1260
            createTable.addBooleanColumn("TRANSACTION_EN_COURS", Boolean.FALSE, false);
1261
            createTable.addBooleanColumn("PORTABILITE_PREVOYANCE", Boolean.FALSE, false);
1262
            createTable.addIntegerColumn("NB_DIF_RESTANT", null, true);
1263
            createTable.addIntegerColumn("NB_MOIS_CSP", null, true);
1264
            createTable.addDecimalColumn("SALAIRE_NET_HORAIRE", 16, 8, null, true);
1265
            createTable.addDecimalColumn("INDEMNITE_VERSE", 16, 8, null, true);
1266
            createTable.addForeignColumn("ID_TYPE_PREAVIS", root.findTable("TYPE_PREAVIS"));
1267
            createTable.addDateAndTimeColumn("DATE_DEBUT_PREAVIS");
1268
            createTable.addDateAndTimeColumn("DATE_FIN_PREAVIS");
1269
            createTable.addVarCharColumn("INFOS", 2048);
1270
 
1271
            try {
1272
                root.getBase().getDataSource().execute(createTable.asString());
1273
                insertUndef(createTable);
1274
                root.refetchTable("FIN_CONTRAT");
1275
                root.getSchema().updateVersion();
1276
            } catch (SQLException ex) {
1277
                throw new IllegalStateException("Erreur lors de la création de la table " + "FIN_CONTRAT", ex);
1278
            }
1279
        }
1280
 
132 ilm 1281
        if (!root.contains("REPRISE_TRAVAIL")) {
1282
 
1283
            final SQLCreateTable createTable = new SQLCreateTable(root, "REPRISE_TRAVAIL");
1284
            createTable.addForeignColumn("SALARIE");
1285
            createTable.addDateAndTimeColumn("DATE_DERNIER_JOUR_TRAV");
1286
            createTable.addDateAndTimeColumn("DATE_FIN_PREV");
1287
            createTable.addBooleanColumn("SUBROGATION", Boolean.FALSE, false);
1288
            createTable.addDateAndTimeColumn("DATE_DEBUT_SUBROGATION");
1289
            createTable.addDateAndTimeColumn("DATE_FIN_SUBROGATION");
1290
            createTable.addForeignColumn("ID_MOTIF_ARRET_TRAVAIL", root.findTable("MOTIF_ARRET_TRAVAIL"));
1291
            createTable.addForeignColumn("ID_MOTIF_REPRISE_ARRET_TRAVAIL", root.findTable("MOTIF_REPRISE_ARRET_TRAVAIL"));
1292
            createTable.addDateAndTimeColumn("DATE_REPRISE");
1293
            createTable.addDateAndTimeColumn("DATE_ACCIDENT");
1294
            createTable.addDateAndTimeColumn("DATE");
1295
            createTable.addVarCharColumn("COMMENTAIRES", 2048);
1296
 
1297
            try {
1298
                root.getBase().getDataSource().execute(createTable.asString());
1299
                insertUndef(createTable);
1300
                root.refetchTable("REPRISE_TRAVAIL");
1301
                root.getSchema().updateVersion();
1302
            } catch (SQLException ex) {
1303
                throw new IllegalStateException("Erreur lors de la création de la table " + "REPRISE_TRAVAIL", ex);
1304
            }
1305
        }
1306
 
1307
        if (!root.contains("DECLARATION_DSN")) {
1308
 
1309
            final SQLCreateTable createTable = new SQLCreateTable(root, "DECLARATION_DSN");
1310
            createTable.addForeignColumn("ID_DSN_NATURE", root.findTable("DSN_NATURE"));
1311
 
1312
            createTable.addDateAndTimeColumn("DATE");
1313
            createTable.addDateAndTimeColumn("DATE_ENVOI");
1314
            createTable.addBooleanColumn("TEST", Boolean.FALSE, false);
1315
            createTable.addBooleanColumn("ENVOYE", Boolean.FALSE, false);
1316
            createTable.addVarCharColumn("COMMENTAIRE", 1024);
1317
            createTable.addVarCharColumn("DSN_FILE", 75000);
1318
            createTable.addIntegerColumn("NUMERO", 1);
1319
            createTable.addIntegerColumn("ANNEE", 2016);
1320
            createTable.addForeignColumn("MOIS");
1321
 
1322
            try {
1323
                root.getBase().getDataSource().execute(createTable.asString());
1324
                insertUndef(createTable);
1325
                root.refetchTable("DECLARATION_DSN");
1326
                root.getSchema().updateVersion();
1327
            } catch (SQLException ex) {
1328
                throw new IllegalStateException("Erreur lors de la création de la table " + "DECLARATION_DSN", ex);
1329
            }
1330
        }
1331
 
1332
        SQLTable tableArret = root.getTable("ARRET_TRAVAIL");
1333
        if (!tableArret.contains("DATE")) {
1334
            AlterTable alter = new AlterTable(tableArret);
1335
            alter.addDateAndTimeColumn("DATE");
1336
            alter.addVarCharColumn("COMMENTAIRES", 2048);
1337
            root.getBase().getDataSource().execute(alter.asString());
1338
            root.refetchTable("ARRET_TRAVAIL");
1339
            root.getSchema().updateVersion();
1340
        }
1341
 
1342
        SQLTable tableDsn = root.getTable("DECLARATION_DSN");
1343
        if (!tableDsn.contains("ID_ARRET_TRAVAIL")) {
1344
            AlterTable alter = new AlterTable(tableDsn);
1345
            alter.addForeignColumn("ID_ARRET_TRAVAIL", root.findTable("ARRET_TRAVAIL"));
1346
            root.getBase().getDataSource().execute(alter.asString());
1347
            root.getSchema().updateVersion();
1348
        }
142 ilm 1349
        if (!tableDsn.contains("ID_FIN_CONTRAT")) {
1350
            AlterTable alter = new AlterTable(tableDsn);
1351
            alter.addForeignColumn("ID_FIN_CONTRAT", root.findTable("FIN_CONTRAT"));
1352
            root.getBase().getDataSource().execute(alter.asString());
1353
            root.getSchema().updateVersion();
1354
        }
1355
 
132 ilm 1356
        if (!tableDsn.contains("ID_REPRISE_TRAVAIL")) {
1357
            AlterTable alter = new AlterTable(tableDsn);
1358
            alter.addForeignColumn("ID_REPRISE_TRAVAIL", root.findTable("REPRISE_TRAVAIL"));
1359
            root.getBase().getDataSource().execute(alter.asString());
1360
            root.getSchema().updateVersion();
1361
        }
1362
        if (!tableDsn.contains("ID_MOIS_REGUL")) {
1363
            AlterTable alter = new AlterTable(tableDsn);
1364
            alter.addForeignColumn("ID_MOIS_REGUL", root.findTable("MOIS"));
1365
            root.getBase().getDataSource().execute(alter.asString());
1366
            root.getSchema().updateVersion();
1367
        }
1368
 
1369
        if (!tableDsn.contains("ANNULE_REMPLACE")) {
1370
            AlterTable alter = new AlterTable(tableDsn);
1371
            alter.addBooleanColumn("ANNULE_REMPLACE", Boolean.FALSE, false);
1372
            root.getBase().getDataSource().execute(alter.asString());
1373
            root.getSchema().updateVersion();
1374
        }
142 ilm 1375
        if (!tableDsn.contains("NUMERO_REFERENCE")) {
1376
            AlterTable alter = new AlterTable(tableDsn);
1377
            alter.addVarCharColumn("NUMERO_REFERENCE", 256);
1378
            root.getBase().getDataSource().execute(alter.asString());
1379
            root.getSchema().updateVersion();
1380
        }
1381
        if (!tableDsn.contains("ID_DECLARATION_DSN_ANNULATION")) {
1382
            AlterTable alter = new AlterTable(tableDsn);
1383
            alter.addForeignColumn("ID_DECLARATION_DSN_ANNULATION", tableDsn);
1384
            root.getBase().getDataSource().execute(alter.asString());
1385
            root.getSchema().updateVersion();
1386
        }
1387
        if (!tableDsn.contains("EFFECTIF_CVAE")) {
1388
            AlterTable alter = new AlterTable(tableDsn);
1389
            alter.addIntegerColumn("EFFECTIF_CVAE", null, true);
1390
            alter.addVarCharColumn("CODE_INSEE_CVAE", 32);
1391
            root.getBase().getDataSource().execute(alter.asString());
1392
            root.getSchema().updateVersion();
1393
            root.refetchTable(tableDsn.getName());
1394
        }
132 ilm 1395
 
142 ilm 1396
        if (!tableDsn.contains("PERIODE_CVAE_DEBUT")) {
1397
            AlterTable alter = new AlterTable(tableDsn);
1398
            alter.addColumn("PERIODE_CVAE_DEBUT", "date");
1399
            alter.addColumn("PERIODE_CVAE_FIN", "date");
1400
            root.getBase().getDataSource().execute(alter.asString());
1401
            root.getSchema().updateVersion();
1402
        }
1403
 
132 ilm 1404
        // if (!root.contains("FIN_CONTRAT")) {
1405
        //
1406
        // final SQLCreateTable createTable = new SQLCreateTable(root, "FIN_CONTRAT");
1407
        // createTable.addForeignColumn("SALARIE");
1408
        // createTable.addDateAndTimeColumn("DATE_FIN");
1409
        // createTable.addDateAndTimeColumn("DATE_FIN_PREV");
1410
        // createTable.addBooleanColumn("SUBROGATION", Boolean.FALSE, false);
1411
        // createTable.addDateAndTimeColumn("DATE_DEBUT_SUBROGATION");
1412
        // createTable.addDateAndTimeColumn("DATE_FIN_SUBROGATION");
1413
        // createTable.addForeignColumn("ID_MOTIF_ARRET_TRAVAIL",
1414
        // root.findTable("MOTIF_ARRET_TRAVAIL"));
1415
        // createTable.addForeignColumn("ID_MOTIF_REPRISE_ARRET_TRAVAIL",
1416
        // root.findTable("MOTIF_REPRISE_ARRET_TRAVAIL"));
1417
        // createTable.addDateAndTimeColumn("DATE_REPRISE");
1418
        // createTable.addDateAndTimeColumn("DATE_ACCIDENT");
1419
        //
1420
        // try {
1421
        // root.getBase().getDataSource().execute(createTable.asString());
1422
        // insertUndef(createTable);
1423
        // root.refetchTable("FIN_CONTRAT");
1424
        // root.getSchema().updateVersion();
1425
        // } catch (SQLException ex) {
1426
        // throw new IllegalStateException("Erreur lors de la création de la table " +
1427
        // "FIN_CONTRAT", ex);
1428
        // }
1429
        // }
1430
 
1431
        SQLTable tableContrat = root.getTable("CONTRAT_SALARIE");
1432
        if (!tableContrat.contains("NUMERO")) {
1433
            AlterTable alter = new AlterTable(tableContrat);
1434
            alter.addColumn("NUMERO", "varchar(" + 128 + ") default '00000' NOT NULL");
1435
            root.getBase().getDataSource().execute(alter.asString());
1436
            root.getSchema().updateVersion();
1437
        }
1438
 
1439
        if (!tableContrat.contains("CODE_REGIME_RETRAITE_DSN")) {
1440
            AlterTable alter = new AlterTable(tableContrat);
1441
            alter.addColumn("CODE_REGIME_RETRAITE_DSN", "varchar(" + 128 + ") default '00000' NOT NULL");
1442
            root.getBase().getDataSource().execute(alter.asString());
1443
            root.getSchema().updateVersion();
1444
        }
1445
 
1446
        if (!tableContrat.contains("DATE_PREV_FIN")) {
1447
            AlterTable alter = new AlterTable(tableContrat);
1448
            alter.addDateAndTimeColumn("DATE_PREV_FIN");
1449
            root.getBase().getDataSource().execute(alter.asString());
1450
            root.getSchema().updateVersion();
1451
        }
1452
 
1453
        boolean updateContrat = false;
1454
        if (!tableContrat.contains("ID_CONTRAT_MODALITE_TEMPS")) {
1455
            updateContrat = true;
1456
            AlterTable alter = new AlterTable(tableContrat);
1457
            alter.addForeignColumn("ID_CONTRAT_MODALITE_TEMPS", root.findTable("CONTRAT_MODALITE_TEMPS"));
1458
            root.getBase().getDataSource().execute(alter.asString());
1459
            root.getSchema().updateVersion();
1460
        }
1461
        if (!tableContrat.contains("ID_CONTRAT_REGIME_MALADIE")) {
1462
            AlterTable alter = new AlterTable(tableContrat);
1463
            alter.addForeignColumn("ID_CONTRAT_REGIME_MALADIE", root.findTable("CONTRAT_REGIME_MALADIE"));
1464
            root.getBase().getDataSource().execute(alter.asString());
1465
            root.getSchema().updateVersion();
1466
        }
1467
        if (!tableContrat.contains("ID_CONTRAT_REGIME_VIEILLESSE")) {
1468
            AlterTable alter = new AlterTable(tableContrat);
1469
            alter.addForeignColumn("ID_CONTRAT_REGIME_VIEILLESSE", root.findTable("CONTRAT_REGIME_VIEILLESSE"));
1470
            root.getBase().getDataSource().execute(alter.asString());
1471
            root.getSchema().updateVersion();
1472
        }
1473
        if (!tableContrat.contains("ID_CONTRAT_MOTIF_RECOURS")) {
1474
            AlterTable alter = new AlterTable(tableContrat);
1475
            alter.addForeignColumn("ID_CONTRAT_MOTIF_RECOURS", root.findTable("CONTRAT_MOTIF_RECOURS"));
1476
            root.getBase().getDataSource().execute(alter.asString());
1477
            root.getSchema().updateVersion();
1478
        }
1479
        if (!tableContrat.contains("ID_CONTRAT_DETACHE_EXPATRIE")) {
1480
            AlterTable alter = new AlterTable(tableContrat);
1481
            alter.addForeignColumn("ID_CONTRAT_DETACHE_EXPATRIE", root.findTable("CONTRAT_DETACHE_EXPATRIE"));
1482
            root.getBase().getDataSource().execute(alter.asString());
1483
            root.getSchema().updateVersion();
1484
        }
1485
        if (!tableContrat.contains("ID_CONTRAT_DISPOSITIF_POLITIQUE")) {
1486
            AlterTable alter = new AlterTable(tableContrat);
1487
            alter.addForeignColumn("ID_CONTRAT_DISPOSITIF_POLITIQUE", root.findTable("CONTRAT_DISPOSITIF_POLITIQUE"));
1488
            root.getBase().getDataSource().execute(alter.asString());
1489
            root.getSchema().updateVersion();
1490
        }
1491
 
1492
        if (updateContrat) {
1493
            root.refetchTable("CONTRAT_SALARIE");
1494
            tableContrat = root.findTable("CONTRAT_SALARIE");
1495
            SQLSelect sel = new SQLSelect();
1496
            sel.addSelectStar(tableContrat);
1497
            List<SQLRow> contrats = SQLRowListRSH.execute(sel);
1498
 
1499
            SQLSelect selModal = new SQLSelect();
1500
            final SQLTable tableModaliteTemps = root.findTable("CONTRAT_MODALITE_TEMPS");
1501
            selModal.addSelectStar(tableModaliteTemps);
1502
            selModal.setWhere(new Where(tableModaliteTemps.getField("CODE"), "=", "10"));
1503
            SQLRow contratModalite = SQLRowListRSH.execute(selModal).get(0);
1504
 
1505
            SQLSelect selMaladie = new SQLSelect();
1506
            final SQLTable tableMaladie = root.findTable("CONTRAT_REGIME_MALADIE");
1507
            selMaladie.addSelectStar(tableMaladie);
1508
            selMaladie.setWhere(new Where(tableMaladie.getField("CODE"), "=", "200"));
1509
            SQLRow contratMaladie = SQLRowListRSH.execute(selMaladie).get(0);
1510
 
1511
            SQLSelect selViel = new SQLSelect();
1512
            final SQLTable tableViel = root.findTable("CONTRAT_REGIME_VIEILLESSE");
1513
            selViel.addSelectStar(tableViel);
1514
            selViel.setWhere(new Where(tableViel.getField("CODE"), "=", "200"));
1515
            SQLRow contratViel = SQLRowListRSH.execute(selViel).get(0);
1516
 
1517
            SQLSelect selDetacheExp = new SQLSelect();
1518
            final SQLTable tableDetacheExp = root.findTable("CONTRAT_DETACHE_EXPATRIE");
1519
            selDetacheExp.addSelectStar(tableDetacheExp);
1520
            selDetacheExp.setWhere(new Where(tableDetacheExp.getField("CODE"), "=", "99"));
1521
            SQLRow contratDetacheExp = SQLRowListRSH.execute(selDetacheExp).get(0);
1522
 
1523
            SQLSelect selDispoPolitique = new SQLSelect();
1524
            final SQLTable tableDispoPol = root.findTable("CONTRAT_DISPOSITIF_POLITIQUE");
1525
            selDispoPolitique.addSelectStar(tableDispoPol);
1526
            selDispoPolitique.setWhere(new Where(tableDispoPol.getField("CODE"), "=", "99"));
1527
            SQLRow contratDispoPol = SQLRowListRSH.execute(selDispoPolitique).get(0);
1528
 
1529
            for (SQLRow contrat : contrats) {
1530
 
1531
                final SQLRowValues createEmptyUpdateRow = contrat.createEmptyUpdateRow();
1532
                createEmptyUpdateRow.put("ID_CONTRAT_MODALITE_TEMPS", contratModalite.getID());
1533
                createEmptyUpdateRow.put("ID_CONTRAT_REGIME_MALADIE", contratMaladie.getID());
1534
                createEmptyUpdateRow.put("ID_CONTRAT_REGIME_VIEILLESSE", contratViel.getID());
1535
                createEmptyUpdateRow.put("ID_CONTRAT_DETACHE_EXPATRIE", contratDetacheExp.getID());
1536
                createEmptyUpdateRow.put("ID_CONTRAT_DISPOSITIF_POLITIQUE", contratDispoPol.getID());
1537
                createEmptyUpdateRow.commit();
1538
            }
1539
        }
142 ilm 1540
        if (!root.contains("CONTRAT_PREVOYANCE")) {
132 ilm 1541
 
142 ilm 1542
            final SQLCreateTable createTable = new SQLCreateTable(root, "CONTRAT_PREVOYANCE");
1543
            createTable.addVarCharColumn("REFERENCE", 256);
1544
            createTable.addDateAndTimeColumn("DATE_DEBUT");
1545
            createTable.addDateAndTimeColumn("DATE_FIN");
1546
            createTable.addVarCharColumn("CODE_ORGANISME", 256);
1547
            createTable.addVarCharColumn("CODE_DELEGATAIRE", 256);
1548
            createTable.addVarCharColumn("CODE_UNIQUE", 256);
1549
            createTable.addVarCharColumn("NOM", 256);
1550
            try {
1551
                root.getBase().getDataSource().execute(createTable.asString());
1552
                insertUndef(createTable);
1553
                root.refetchTable("CONTRAT_PREVOYANCE");
1554
                root.getSchema().updateVersion();
1555
            } catch (SQLException ex) {
1556
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_PREVOYANCE", ex);
1557
            }
1558
        }
1559
        if (!root.getTable("CONTRAT_PREVOYANCE").contains("COTISATION_ETABLISSEMENT")) {
1560
            AlterTable tableContratP = new AlterTable(root.getTable("CONTRAT_PREVOYANCE"));
1561
            tableContratP.addBooleanColumn("COTISATION_ETABLISSEMENT", Boolean.FALSE, false);
1562
            root.getBase().getDataSource().execute(tableContratP.asString());
1563
            root.refetchTable("CONTRAT_PREVOYANCE");
1564
            root.getSchema().updateVersion();
1565
        }
1566
 
1567
        if (!root.contains("CONTRAT_PREVOYANCE_CONTRAT_SALARIE")) {
1568
 
1569
            final SQLCreateTable createTableSal = new SQLCreateTable(root, "CONTRAT_PREVOYANCE_CONTRAT_SALARIE");
1570
            final SQLTable tableInfosSalarie = root.getTable("INFOS_SALARIE_PAYE");
1571
            createTableSal.addForeignColumn("ID_INFOS_SALARIE_PAYE", tableInfosSalarie);
1572
            createTableSal.addForeignColumn("ID_CONTRAT_PREVOYANCE", root.getTable("CONTRAT_PREVOYANCE"));
1573
            createTableSal.addVarCharColumn("CODE_OPTION", 256);
1574
            createTableSal.addVarCharColumn("CODE_POPULATION", 256);
1575
            createTableSal.addIntegerColumn("NB_ENFANT_CHARGE", null, true);
1576
            createTableSal.addIntegerColumn("NB_ADULTE_AYANT_DROIT", null, true);
1577
            createTableSal.addIntegerColumn("NB_AYANT_DROIT", null, true);
1578
            createTableSal.addIntegerColumn("NB_AYANT_DROIT_AUTRE", null, true);
1579
            createTableSal.addIntegerColumn("NB_ENFANT_AYANT_DROIT", null, true);
1580
 
1581
            try {
1582
                root.getBase().getDataSource().execute(createTableSal.asString());
1583
                insertUndef(createTableSal);
1584
                root.refetchTable("CONTRAT_PREVOYANCE_CONTRAT_SALARIE");
1585
                root.getSchema().updateVersion();
1586
 
1587
                String up = "UPDATE " + new SQLName(root.getName(), tableInfosSalarie.getName()).quote() + " i SET \"ID_SALARIE\" = (SELECT s.\"ID\" FROM "
1588
                        + new SQLName(root.getName(), tableInfosSalarie.getForeignTable("ID_SALARIE").getName()).quote() + " s WHERE s.\"ID_INFOS_SALARIE_PAYE\"=i.\"ID\" and s.\"ARCHIVE\"=0)"
1589
                        + " WHERE i.\"ID\" IN (SELECT i2.\"ID_INFOS_SALARIE_PAYE\" FROM " + new SQLName(root.getName(), tableInfosSalarie.getForeignTable("ID_SALARIE").getName()).quote();
1590
                up += " i2 WHERE i2.\"ARCHIVE\"=0)";
1591
 
1592
                root.getBase().getDataSource().execute(up);
1593
 
1594
            } catch (SQLException ex) {
1595
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_PREVOYANCE_SALARIE", ex);
1596
            }
1597
        }
1598
        if (!root.contains("CONTRAT_PREVOYANCE_RUBRIQUE"))
1599
 
1600
        {
1601
 
1602
            final SQLCreateTable createTableRub = new SQLCreateTable(root, "CONTRAT_PREVOYANCE_RUBRIQUE");
1603
            createTableRub.addForeignColumn("ID_RUBRIQUE_COTISATION", root.findTable("RUBRIQUE_COTISATION"));
1604
            createTableRub.addForeignColumn("ID_CONTRAT_PREVOYANCE", root.getTable("CONTRAT_PREVOYANCE"));
1605
 
1606
            try {
1607
                root.getBase().getDataSource().execute(createTableRub.asString());
1608
                insertUndef(createTableRub);
1609
                root.refetchTable("CONTRAT_PREVOYANCE_RUBRIQUE");
1610
                root.getSchema().updateVersion();
1611
            } catch (SQLException ex) {
1612
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_PREVOYANCE_RUBRIQUE", ex);
1613
            }
1614
        }
1615
 
1616
        if (!root.contains("CONTRAT_PREVOYANCE_RUBRIQUE_NET"))
1617
 
1618
        {
1619
 
1620
            final SQLCreateTable createTableRub = new SQLCreateTable(root, "CONTRAT_PREVOYANCE_RUBRIQUE_NET");
1621
            createTableRub.addForeignColumn("ID_RUBRIQUE_NET", root.findTable("RUBRIQUE_NET"));
1622
            createTableRub.addForeignColumn("ID_CONTRAT_PREVOYANCE", root.getTable("CONTRAT_PREVOYANCE"));
1623
 
1624
            try {
1625
                root.getBase().getDataSource().execute(createTableRub.asString());
1626
                insertUndef(createTableRub);
1627
                root.refetchTable("CONTRAT_PREVOYANCE_RUBRIQUE_NET");
1628
                root.getSchema().updateVersion();
1629
            } catch (SQLException ex) {
1630
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_PREVOYANCE_RUBRIQUE_NET", ex);
1631
            }
1632
        }
1633
        if (!root.contains("AYANT_DROIT")) {
1634
 
1635
            final SQLCreateTable createTableAyantDroit = new SQLCreateTable(root, "AYANT_DROIT");
1636
            createTableAyantDroit.addVarCharColumn("NOM", 256);
1637
            createTableAyantDroit.addForeignColumn("ID_SALARIE", root.findTable("SALARIE"));
1638
            createTableAyantDroit.addForeignColumn("ID_AYANT_DROIT_TYPE", root.findTable("AYANT_DROIT_TYPE"));
1639
            createTableAyantDroit.addBooleanColumn("REGIME_ALSACE", Boolean.FALSE, false);
1640
            createTableAyantDroit.addVarCharColumn("NIR", 256);
1641
            createTableAyantDroit.addVarCharColumn("PRENOMS", 256);
1642
            createTableAyantDroit.addVarCharColumn("CODE_ORGANISME_AFFILIATION", 256);
1643
            createTableAyantDroit.addVarCharColumn("CODE_OPTION", 256);
1644
            createTableAyantDroit.addVarCharColumn("NIR_OUVRANT_DROIT", 256);
1645
            createTableAyantDroit.addDateAndTimeColumn("DATE_DEBUT_RATTACHEMENT");
1646
            createTableAyantDroit.addDateAndTimeColumn("DATE_FIN_RATTACHEMENT");
1647
            createTableAyantDroit.addDateAndTimeColumn("DATE_NAISSANCE");
1648
            try {
1649
                root.getBase().getDataSource().execute(createTableAyantDroit.asString());
1650
                insertUndef(createTableAyantDroit);
1651
                root.refetchTable("AYANT_DROIT");
1652
                root.getSchema().updateVersion();
1653
            } catch (SQLException ex) {
1654
                throw new IllegalStateException("Erreur lors de la création de la table " + "AYANT_DROIT", ex);
1655
            }
1656
 
1657
            final SQLCreateTable createTablePrevAyant = new SQLCreateTable(root, "CONTRAT_PREVOYANCE_AYANT_DROIT");
1658
            createTablePrevAyant.addForeignColumn("ID_AYANT_DROIT", root.getTable("AYANT_DROIT"));
1659
            createTablePrevAyant.addForeignColumn("ID_CONTRAT_PREVOYANCE", root.getTable("CONTRAT_PREVOYANCE"));
1660
 
1661
            try {
1662
                root.getBase().getDataSource().execute(createTablePrevAyant.asString());
1663
                insertUndef(createTablePrevAyant);
1664
                root.refetchTable("CONTRAT_PREVOYANCE_AYANT_DROIT");
1665
                root.getSchema().updateVersion();
1666
            } catch (SQLException ex) {
1667
                throw new IllegalStateException("Erreur lors de la création de la table " + "CONTRAT_PREVOYANCE_AYANT_DROIT", ex);
1668
            }
1669
        }
1670
        if (!root.contains("CODE_PENIBILITE_CONTRAT_SALARIE")) {
1671
 
1672
            final SQLCreateTable createTableSal = new SQLCreateTable(root, "CODE_PENIBILITE_CONTRAT_SALARIE");
1673
            final SQLTable tableInfosSalarie = root.getTable("INFOS_SALARIE_PAYE");
1674
            createTableSal.addForeignColumn("ID_INFOS_SALARIE_PAYE", tableInfosSalarie);
1675
            createTableSal.addForeignColumn("ID_CODE_PENIBILITE", root.findTable("CODE_PENIBILITE"));
1676
 
1677
            try {
1678
                root.getBase().getDataSource().execute(createTableSal.asString());
1679
                insertUndef(createTableSal);
1680
                root.refetchTable("CODE_PENIBILITE_CONTRAT_SALARIE");
1681
                root.getSchema().updateVersion();
1682
 
1683
            } catch (SQLException ex) {
1684
                throw new IllegalStateException("Erreur lors de la création de la table " + "CODE_PENIBILITE_CONTRAT_SALARIE", ex);
1685
            }
1686
        }
132 ilm 1687
    }
1688
 
1689
}