OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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