OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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