OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 177 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 177 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
Line 17... Line 17...
17
import org.openconcerto.erp.core.humanresources.payroll.report.LignePayeSimplifiee;
17
import org.openconcerto.erp.core.humanresources.payroll.report.LignePayeSimplifiee;
18
import org.openconcerto.erp.core.sales.order.ui.EtatCommandeClient;
18
import org.openconcerto.erp.core.sales.order.ui.EtatCommandeClient;
19
import org.openconcerto.erp.core.sales.quote.element.EtatDevisSQLElement;
19
import org.openconcerto.erp.core.sales.quote.element.EtatDevisSQLElement;
20
import org.openconcerto.erp.modules.ModuleManager;
20
import org.openconcerto.erp.modules.ModuleManager;
21
import org.openconcerto.erp.modules.ModuleReference;
21
import org.openconcerto.erp.modules.ModuleReference;
22
import org.openconcerto.sql.Configuration;
22
import org.openconcerto.erp.rights.DepotStockViewRightEditor;
23
import org.openconcerto.sql.changer.convert.AddFK;
23
import org.openconcerto.sql.changer.convert.AddFK;
-
 
24
import org.openconcerto.sql.changer.convert.AddMDFields;
24
import org.openconcerto.sql.changer.convert.ChangeIDToInt;
25
import org.openconcerto.sql.changer.convert.ChangeIDToInt;
-
 
26
import org.openconcerto.sql.changer.convert.MergeTable;
25
import org.openconcerto.sql.changer.correct.CorrectOrder;
27
import org.openconcerto.sql.changer.correct.CorrectOrder;
26
import org.openconcerto.sql.changer.correct.FixSerial;
28
import org.openconcerto.sql.changer.correct.FixSerial;
27
import org.openconcerto.sql.element.GroupSQLComponent;
29
import org.openconcerto.sql.element.GroupSQLComponent;
28
import org.openconcerto.sql.model.AliasedTable;
30
import org.openconcerto.sql.model.AliasedTable;
29
import org.openconcerto.sql.model.DBRoot;
31
import org.openconcerto.sql.model.DBRoot;
Line 139... Line 141...
139
                    @Override
141
                    @Override
140
                    public void run() {
142
                    public void run() {
141
                        System.setProperty(SQLSchema.NOAUTO_CREATE_METADATA, "false");
143
                        System.setProperty(SQLSchema.NOAUTO_CREATE_METADATA, "false");
142
                        final ComptaPropsConfiguration conf = ComptaPropsConfiguration.create(true);
144
                        final ComptaPropsConfiguration conf = ComptaPropsConfiguration.create(true);
143
 
145
 
144
                        final DBSystemRoot systemRoot = conf.getSystemRoot();
-
 
145
                        if (systemRoot.getChild(conf.getRootNameValue().getValue()) == null) {
-
 
146
                            conf.destroy();
-
 
147
                            SwingUtilities.invokeLater(new Runnable() {
-
 
148
                                @Override
-
 
149
                                public void run() {
-
 
150
                                    up.setEnabled(true);
-
 
151
                                    bar.setValue(bar.getMaximum());
-
 
152
                                    JOptionPane.showMessageDialog(InstallationPanel.this, "Votre base de données n'est pas initialisée");
-
 
153
                                }
-
 
154
                            });
-
 
155
                            return;
-
 
156
                        }
-
 
157
 
-
 
158
                        updateDatabase(conf);
146
                        updateDatabase(conf);
159
 
147
 
160
                        conf.destroy();
148
                        conf.destroy();
161
                        SwingUtilities.invokeLater(new Runnable() {
149
                        SwingUtilities.invokeLater(new Runnable() {
162
 
150
 
Line 3566... Line 3554...
3566
            }
3554
            }
3567
        }
3555
        }
3568
        patchFieldElt1Dot3(table, root);
3556
        patchFieldElt1Dot3(table, root);
3569
    }
3557
    }
3570
 
3558
 
3571
    private void updateSocieteSchema(final Configuration conf, final DBRoot root) throws IOException, Exception {
3559
    private void updateSocieteSchema(final DBRoot root) throws IOException, Exception {
3572
        final DBSystemRoot sysRoot = root.getDBSystemRoot();
3560
        final DBSystemRoot sysRoot = root.getDBSystemRoot();
3573
        final SQLDataSource ds = sysRoot.getDataSource();
3561
        final SQLDataSource ds = sysRoot.getDataSource();
3574
        System.out.println("InstallationPanel.InstallationPanel() UPDATE COMMERCIAL " + root);
3562
        System.out.println("InstallationPanel.InstallationPanel() UPDATE COMMERCIAL " + root);
3575
        // Fix commercial Ordre
3563
        // Fix commercial Ordre
3576
 
3564
 
Line 3670... Line 3658...
3670
            // Suppression des champs 1.0
3658
            // Suppression des champs 1.0
3671
            System.out.println("InstallationPanel.InstallationPanel() UPDATE FROM 1.0 " + root);
3659
            System.out.println("InstallationPanel.InstallationPanel() UPDATE FROM 1.0 " + root);
3672
            final List<ChangeTable<?>> changes = new ArrayList<ChangeTable<?>>();
3660
            final List<ChangeTable<?>> changes = new ArrayList<ChangeTable<?>>();
3673
 
3661
 
3674
            final ModuleManager instance = new ModuleManager();
3662
            final ModuleManager instance = new ModuleManager();
3675
            instance.setup(root, conf);
3663
            instance.setRoot(root);
3676
            final Collection<ModuleReference> refs = instance.getModulesInstalledRemotely();
3664
            final Collection<ModuleReference> refs = instance.getModulesInstalledRemotely();
3677
            final Set<String> allUsedTable = new HashSet<String>();
3665
            final Set<String> allUsedTable = new HashSet<String>();
3678
            for (ModuleReference ref : refs) {
3666
            for (ModuleReference ref : refs) {
3679
                Set<String> tableNames = instance.getCreatedItems(ref.getID()).get0();
3667
                Set<String> tableNames = instance.getCreatedItems(ref.getID()).get0();
3680
                allUsedTable.addAll(tableNames);
3668
                allUsedTable.addAll(tableNames);
3681
            }
3669
            }
3682
            System.out.println("Tables created by modules:" + allUsedTable);
3670
            System.out.println("Tables created by modules:" + allUsedTable);
3683
 
3671
 
3684
            final Set<String> notMigrated = instance.migrateOldTransientDirs();
-
 
3685
            if (!notMigrated.isEmpty())
-
 
3686
                System.out.println("Couldn't migrate old backed up/failed modules: " + notMigrated);
-
 
3687
 
-
 
3688
            final List<String> alterRequests = ChangeTable.cat(changes, root.getName());
3672
            final List<String> alterRequests = ChangeTable.cat(changes, root.getName());
3689
            try {
3673
            try {
3690
                for (final String req : alterRequests) {
3674
                for (final String req : alterRequests) {
3691
                    ds.execute(req);
3675
                    ds.execute(req);
3692
                }
3676
                }
Line 3756... Line 3740...
3756
            rowValsUserRight.put("ID_RIGHT", row.getID());
3740
            rowValsUserRight.put("ID_RIGHT", row.getID());
3757
            rowValsUserRight.put("HAVE_RIGHT", Boolean.TRUE);
3741
            rowValsUserRight.put("HAVE_RIGHT", Boolean.TRUE);
3758
            rowValsUserRight.commit();
3742
            rowValsUserRight.commit();
3759
        }
3743
        }
3760
 
3744
 
-
 
3745
        if (!codes.contains(DepotStockViewRightEditor.ID_RIGHT)) {
-
 
3746
            SQLRowValues rowVals = new SQLRowValues(table);
-
 
3747
            rowVals.put("CODE", DepotStockViewRightEditor.ID_RIGHT);
-
 
3748
            rowVals.put("NOM", "Voir le stock d'un dépôt");
-
 
3749
            String desc = "Autorise un utilisateur à visualiser le stock d'un dépôt.";
-
 
3750
            rowVals.put("DESCRIPTION", desc);
-
 
3751
            SQLRow row = rowVals.commit();
-
 
3752
            SQLRowValues rowValsUserRight = new SQLRowValues(table.getTable("USER_RIGHT"));
-
 
3753
            rowValsUserRight.put("ID_RIGHT", row.getID());
-
 
3754
            rowValsUserRight.put("HAVE_RIGHT", Boolean.TRUE);
-
 
3755
            rowValsUserRight.commit();
-
 
3756
        }
-
 
3757
 
3761
        if (!codes.contains("MENU_ACCESS")) {
3758
        if (!codes.contains("MENU_ACCESS")) {
3762
            SQLRowValues rowVals = new SQLRowValues(table);
3759
            SQLRowValues rowVals = new SQLRowValues(table);
3763
            rowVals.put("CODE", "MENU_ACCESS");
3760
            rowVals.put("CODE", "MENU_ACCESS");
3764
            rowVals.put("NOM", "Autoriser l'accés à un menu");
3761
            rowVals.put("NOM", "Autoriser l'accés à un menu");
3765
            String desc = "Autorise un utilisateur à visualiser le menu spécifié en objet.";
3762
            String desc = "Autorise un utilisateur à visualiser le menu spécifié en objet.";
Line 3816... Line 3813...
3816
            SQLRowValues rowValsUserRight = new SQLRowValues(table.getTable("USER_RIGHT"));
3813
            SQLRowValues rowValsUserRight = new SQLRowValues(table.getTable("USER_RIGHT"));
3817
            rowValsUserRight.put("ID_RIGHT", row.getID());
3814
            rowValsUserRight.put("ID_RIGHT", row.getID());
3818
            rowValsUserRight.put("HAVE_RIGHT", Boolean.TRUE);
3815
            rowValsUserRight.put("HAVE_RIGHT", Boolean.TRUE);
3819
            rowValsUserRight.commit();
3816
            rowValsUserRight.commit();
3820
        }
3817
        }
-
 
3818
 
3821
        // if (!codes.contains("MODIF_PRODUCT_KIT")) {
3819
        // if (!codes.contains("MODIF_PRODUCT_KIT")) {
3822
        // SQLRowValues rowVals = new SQLRowValues(table);
3820
        // SQLRowValues rowVals = new SQLRowValues(table);
3823
        // rowVals.put("CODE", "MODIF_PRODUCT_KIT");
3821
        // rowVals.put("CODE", "MODIF_PRODUCT_KIT");
3824
        // rowVals.put("NOM", "Autoriser à modifier les kits créer par autres utilisateurs.");
3822
        // rowVals.put("NOM", "Autoriser à modifier les kits créer par autres utilisateurs.");
3825
        // String desc =
3823
        // String desc =
Line 4208... Line 4206...
4208
    }
4206
    }
4209
 
4207
 
4210
    public void updateDatabase(final ComptaPropsConfiguration conf) {
4208
    public void updateDatabase(final ComptaPropsConfiguration conf) {
4211
 
4209
 
4212
        try {
4210
        try {
4213
            final DBSystemRoot systemRoot = conf.getSystemRoot();
4211
            final SQLDataSource ds = conf.getSystemRoot().getDataSource();
4214
            System.err.println("SystemRoot:" + systemRoot);
4212
            System.err.println("SystemRoot:" + conf.getSystemRoot());
4215
            final DBRoot rootCommon = conf.getRoot();
-
 
4216
            System.err.println("Root:" + rootCommon);
4213
            System.err.println("Root:" + conf.getRoot());
4217
 
4214
 
4218
            final SQLDataSource ds = systemRoot.getDataSource();
-
 
4219
            // FixUnbounded varchar
4215
            // FixUnbounded varchar
4220
            fixUnboundedVarchar(rootCommon);
4216
            fixUnboundedVarchar(conf.getRoot());
4221
 
4217
 
4222
            // FIXME DROP CONSTRAINT UNIQUE ORDRE ON
4218
            // FIXME DROP CONSTRAINT UNIQUE ORDRE ON
4223
            // CONTACT_FOURNISSEUR
4219
            // CONTACT_FOURNISSEUR
4224
 
4220
 
4225
            checkCompteDefault(rootCommon);
4221
            checkCompteDefault(conf.getRoot());
4226
 
4222
 
4227
            updateSocieteTable(rootCommon);
4223
            updateSocieteTable(conf.getRoot());
4228
            updateVille(rootCommon.getTable("ADRESSE"));
4224
            updateVille(conf.getRoot().getTable("ADRESSE"));
4229
 
4225
 
4230
            // Champ user 1.4.1
4226
            // Champ user 1.4.1
4231
            final SQLTable tableUser = rootCommon.getTable("USER_COMMON");
4227
            final SQLTable tableUser = conf.getRoot().getTable("USER_COMMON");
4232
            if (tableUser != null) {
4228
            if (tableUser != null) {
4233
                final AlterTable alter = new AlterTable(tableUser);
4229
                final AlterTable alter = new AlterTable(tableUser);
4234
                boolean alterUser = false;
4230
                boolean alterUser = false;
4235
                if (!tableUser.contains("DISABLED")) {
4231
                if (!tableUser.contains("DISABLED")) {
4236
                    alter.addBooleanColumn("DISABLED", Boolean.FALSE, false);
4232
                    alter.addBooleanColumn("DISABLED", Boolean.FALSE, false);
Line 4241... Line 4237...
4241
                    alterUser = true;
4237
                    alterUser = true;
4242
                }
4238
                }
4243
 
4239
 
4244
                if (alterUser) {
4240
                if (alterUser) {
4245
                    final String req = alter.asString();
4241
                    final String req = alter.asString();
4246
                    rootCommon.getDBSystemRoot().getDataSource().execute(req);
4242
                    conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
4247
                    rootCommon.refetchTable(tableUser.getName());
4243
                    conf.getRoot().refetchTable(tableUser.getName());
4248
                    rootCommon.getSchema().updateVersion();
4244
                    conf.getRoot().getSchema().updateVersion();
4249
                }
4245
                }
4250
            }
4246
            }
4251
 
4247
 
4252
            // Champ Paye
4248
            // Champ Paye
4253
            final SQLTable tableCaisse = rootCommon.getTable("CAISSE_COTISATION");
4249
            final SQLTable tableCaisse = conf.getRoot().getTable("CAISSE_COTISATION");
4254
            if (!tableCaisse.contains("NUMERO_COMPTE_PCE")) {
4250
            if (!tableCaisse.contains("NUMERO_COMPTE_PCE")) {
4255
                final AlterTable alter = new AlterTable(tableCaisse);
4251
                final AlterTable alter = new AlterTable(tableCaisse);
4256
                alter.addVarCharColumn("NUMERO_COMPTE_PCE", 128);
4252
                alter.addVarCharColumn("NUMERO_COMPTE_PCE", 128);
4257
                alter.addVarCharColumn("NUMERO_COMPTE_PCE_CHARGES", 128);
4253
                alter.addVarCharColumn("NUMERO_COMPTE_PCE_CHARGES", 128);
4258
                final String req = alter.asString();
4254
                final String req = alter.asString();
4259
                rootCommon.getDBSystemRoot().getDataSource().execute(req);
4255
                conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
4260
                rootCommon.refetchTable(tableCaisse.getName());
4256
                conf.getRoot().refetchTable(tableCaisse.getName());
4261
                rootCommon.getSchema().updateVersion();
4257
                conf.getRoot().getSchema().updateVersion();
4262
            }
4258
            }
4263
 
4259
 
4264
            final SQLTable tableRC = rootCommon.getTable("RUBRIQUE_COTISATION");
4260
            final SQLTable tableRC = conf.getRoot().getTable("RUBRIQUE_COTISATION");
4265
            if (!tableRC.contains("PART_CSG_SANS_ABATTEMENT")) {
4261
            if (!tableRC.contains("PART_CSG_SANS_ABATTEMENT")) {
4266
                final AlterTable alter = new AlterTable(tableRC);
4262
                final AlterTable alter = new AlterTable(tableRC);
4267
                alter.addBooleanColumn("PART_CSG_SANS_ABATTEMENT", Boolean.FALSE, false);
4263
                alter.addBooleanColumn("PART_CSG_SANS_ABATTEMENT", Boolean.FALSE, false);
4268
                final String req = alter.asString();
4264
                final String req = alter.asString();
4269
                rootCommon.getDBSystemRoot().getDataSource().execute(req);
4265
                conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
4270
                rootCommon.refetchTable(tableRC.getName());
4266
                conf.getRoot().refetchTable(tableRC.getName());
4271
                rootCommon.getSchema().updateVersion();
4267
                conf.getRoot().getSchema().updateVersion();
4272
            }
4268
            }
4273
 
4269
 
-
 
4270
            // if (!tableRC.contains("DATE_DEBUT_REGUL")) {
-
 
4271
            // final AlterTable alter = new AlterTable(tableRC);
-
 
4272
            // alter.addColumn("DATE_DEBUT_REGUL", "date");
-
 
4273
            // alter.addColumn("DATE_FIN_REGUL", "date");
-
 
4274
            // final String req = alter.asString();
-
 
4275
            // conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
-
 
4276
            // conf.getRoot().refetchTable(tableRC.getName());
-
 
4277
            // conf.getRoot().getSchema().updateVersion();
-
 
4278
            // }
-
 
4279
 
4274
            // Paye simplifiee
4280
            // Paye simplifiee
4275
            List<SQLRow> rowRubriqueReduGvt = new ArrayList<>();
4281
            List<SQLRow> rowRubriqueReduGvt = new ArrayList<>();
4276
            {
4282
            {
4277
 
4283
 
4278
                final SQLTable tableRCom = rootCommon.getTable("RUBRIQUE_COMM");
4284
                final SQLTable tableRCom = conf.getRoot().getTable("RUBRIQUE_COMM");
4279
                if (!tableRCom.contains("REDUCTION_GVT_COM")) {
4285
                if (!tableRCom.contains("REDUCTION_GVT_COM")) {
4280
                    final AlterTable alter = new AlterTable(tableRCom);
4286
                    final AlterTable alter = new AlterTable(tableRCom);
4281
                    alter.addBooleanColumn("REDUCTION_GVT_COM", Boolean.FALSE, false);
4287
                    alter.addBooleanColumn("REDUCTION_GVT_COM", Boolean.FALSE, false);
4282
                    final String req = alter.asString();
4288
                    final String req = alter.asString();
4283
                    rootCommon.getDBSystemRoot().getDataSource().execute(req);
4289
                    conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
4284
                    rootCommon.refetchTable(tableRCom.getName());
4290
                    conf.getRoot().refetchTable(tableRCom.getName());
4285
                    rootCommon.getSchema().updateVersion();
4291
                    conf.getRoot().getSchema().updateVersion();
4286
 
4292
 
4287
                    SQLRowValues rowValsCommChom = new SQLRowValues(tableRCom);
4293
                    SQLRowValues rowValsCommChom = new SQLRowValues(tableRCom);
4288
                    rowValsCommChom.put("TAUX_SAL", "1.45;");
4294
                    rowValsCommChom.put("TAUX_SAL", "1.45;");
4289
                    rowValsCommChom.put("NB_BASE", "SAL_BRUT;");
4295
                    rowValsCommChom.put("NB_BASE", "SAL_BRUT;");
4290
                    rowValsCommChom.put("NOM", "Assurance chômage reduction 2018");
4296
                    rowValsCommChom.put("NOM", "Assurance chômage reduction 2018");
Line 4319... Line 4325...
4319
                    rowValsCommCSG.put("REDUCTION_GVT_COM", Boolean.TRUE);
4325
                    rowValsCommCSG.put("REDUCTION_GVT_COM", Boolean.TRUE);
4320
                    rowValsCommCSG.putRowValues("ID_PERIODE_VALIDITE").put("JANVIER", Boolean.TRUE);
4326
                    rowValsCommCSG.putRowValues("ID_PERIODE_VALIDITE").put("JANVIER", Boolean.TRUE);
4321
                    rowRubriqueReduGvt.add(rowValsCommCSG.commit());
4327
                    rowRubriqueReduGvt.add(rowValsCommCSG.commit());
4322
 
4328
 
4323
                    SQLSelect sel = new SQLSelect();
4329
                    SQLSelect sel = new SQLSelect();
4324
                    sel.addSelect(rootCommon.getTable("PROFIL_PAYE").getKey());
4330
                    sel.addSelect(conf.getRoot().getTable("PROFIL_PAYE").getKey());
4325
                    List<SQLRow> rowsProfil = SQLRowListRSH.execute(sel);
4331
                    List<SQLRow> rowsProfil = SQLRowListRSH.execute(sel);
4326
                    int pos = 70;
4332
                    int pos = 70;
4327
                    for (SQLRow rowRub : rowRubriqueReduGvt) {
4333
                    for (SQLRow rowRub : rowRubriqueReduGvt) {
4328
                        for (SQLRow rowProfil : rowsProfil) {
4334
                        for (SQLRow rowProfil : rowsProfil) {
4329
 
4335
 
4330
                            SQLRowValues rowValsRubGvt = new SQLRowValues(rootCommon.getTable("PROFIL_PAYE_ELEMENT"));
4336
                            SQLRowValues rowValsRubGvt = new SQLRowValues(conf.getRoot().getTable("PROFIL_PAYE_ELEMENT"));
4331
                            rowValsRubGvt.put("ID_PROFIL_PAYE", rowProfil.getID());
4337
                            rowValsRubGvt.put("ID_PROFIL_PAYE", rowProfil.getID());
4332
                            rowValsRubGvt.put("POSITION", pos);
4338
                            rowValsRubGvt.put("POSITION", pos);
4333
                            rowValsRubGvt.put("IDSOURCE", rowRub.getID());
4339
                            rowValsRubGvt.put("IDSOURCE", rowRub.getID());
4334
                            rowValsRubGvt.put("SOURCE", rowRub.getTable().getName());
4340
                            rowValsRubGvt.put("SOURCE", rowRub.getTable().getName());
4335
                            rowValsRubGvt.put("NOM", rowRub.getString("NOM"));
4341
                            rowValsRubGvt.put("NOM", rowRub.getString("NOM"));
Line 4337... Line 4343...
4337
                        }
4343
                        }
4338
                        pos++;
4344
                        pos++;
4339
                    }
4345
                    }
4340
                }
4346
                }
4341
 
4347
 
4342
                final SQLTable tableRB = rootCommon.getTable("RUBRIQUE_BRUT");
4348
                final SQLTable tableRB = conf.getRoot().getTable("RUBRIQUE_BRUT");
4343
                if (!tableRB.contains("AVANTAGE_NATURE")) {
4349
                if (!tableRB.contains("AVANTAGE_NATURE")) {
4344
                    final AlterTable alter = new AlterTable(tableRB);
4350
                    final AlterTable alter = new AlterTable(tableRB);
4345
                    alter.addBooleanColumn("AVANTAGE_NATURE", Boolean.FALSE, false);
4351
                    alter.addBooleanColumn("AVANTAGE_NATURE", Boolean.FALSE, false);
4346
                    final String req = alter.asString();
4352
                    final String req = alter.asString();
4347
                    rootCommon.getDBSystemRoot().getDataSource().execute(req);
4353
                    conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
4348
                    rootCommon.refetchTable(tableRB.getName());
4354
                    conf.getRoot().refetchTable(tableRB.getName());
4349
                    rootCommon.getSchema().updateVersion();
4355
                    conf.getRoot().getSchema().updateVersion();
4350
                }
4356
                }
4351
 
4357
 
4352
                if (!tableRC.contains("LIGNE_PAYE_SIMPLIFIEE")) {
4358
                if (!tableRC.contains("LIGNE_PAYE_SIMPLIFIEE")) {
4353
                    final AlterTable alter = new AlterTable(tableRC);
4359
                    final AlterTable alter = new AlterTable(tableRC);
4354
 
4360
 
4355
                    alter.addBooleanColumn("ALLEGEMENT_COTISATION", Boolean.FALSE, false);
4361
                    alter.addBooleanColumn("ALLEGEMENT_COTISATION", Boolean.FALSE, false);
4356
                    alter.addVarCharColumn("LIGNE_PAYE_SIMPLIFIEE", 256);
4362
                    alter.addVarCharColumn("LIGNE_PAYE_SIMPLIFIEE", 256);
4357
                    final String req = alter.asString();
4363
                    final String req = alter.asString();
4358
                    rootCommon.getDBSystemRoot().getDataSource().execute(req);
4364
                    conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
4359
                    rootCommon.refetchTable(tableRC.getName());
4365
                    conf.getRoot().refetchTable(tableRC.getName());
4360
                    rootCommon.getSchema().updateVersion();
4366
                    conf.getRoot().getSchema().updateVersion();
4361
                    Map<String, String> liaison = new HashMap<String, String>();
4367
                    Map<String, String> liaison = new HashMap<String, String>();
4362
                    liaison.put("COTCSA", LignePayeSimplifiee.SANTE_SECURITE.getId());
4368
                    liaison.put("COTCSA", LignePayeSimplifiee.SANTE_SECURITE.getId());
4363
                    liaison.put("COTMALADIE", LignePayeSimplifiee.SANTE_SECURITE.getId());
4369
                    liaison.put("COTMALADIE", LignePayeSimplifiee.SANTE_SECURITE.getId());
4364
                    liaison.put("COTAF", LignePayeSimplifiee.FAMILLE_ALLOCATIONS.getId());
4370
                    liaison.put("COTAF", LignePayeSimplifiee.FAMILLE_ALLOCATIONS.getId());
4365
                    liaison.put("COTVEUV", LignePayeSimplifiee.SANTE_SECURITE.getId());
4371
                    liaison.put("COTVEUV", LignePayeSimplifiee.SANTE_SECURITE.getId());
Line 4404... Line 4410...
4404
                    liaison.put("COTPREV", LignePayeSimplifiee.RETRAITE_SUPPLEMENTAIRE.getId());
4410
                    liaison.put("COTPREV", LignePayeSimplifiee.RETRAITE_SUPPLEMENTAIRE.getId());
4405
                    liaison.put("COT_MUTUELLE", LignePayeSimplifiee.SANTE_COMPLEMENAIRE_SANTE.getId());
4411
                    liaison.put("COT_MUTUELLE", LignePayeSimplifiee.SANTE_COMPLEMENAIRE_SANTE.getId());
4406
                    liaison.put("COT_PENIBLE", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
4412
                    liaison.put("COT_PENIBLE", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
4407
 
4413
 
4408
                    SQLSelect sel = new SQLSelect();
4414
                    SQLSelect sel = new SQLSelect();
4409
                    sel.addSelect(rootCommon.findTable("RUBRIQUE_COTISATION").getField("CODE"));
4415
                    sel.addSelect(conf.getRoot().findTable("RUBRIQUE_COTISATION").getField("CODE"));
4410
                    sel.addSelect(rootCommon.findTable("RUBRIQUE_COTISATION").getField("NOM"));
4416
                    sel.addSelect(conf.getRoot().findTable("RUBRIQUE_COTISATION").getField("NOM"));
4411
                    sel.addSelect(rootCommon.findTable("RUBRIQUE_COTISATION").getKey());
4417
                    sel.addSelect(conf.getRoot().findTable("RUBRIQUE_COTISATION").getKey());
4412
                    List<SQLRow> rubCotis = SQLRowListRSH.execute(sel);
4418
                    List<SQLRow> rubCotis = SQLRowListRSH.execute(sel);
4413
 
4419
 
4414
                    for (SQLRow sqlRow : rubCotis) {
4420
                    for (SQLRow sqlRow : rubCotis) {
4415
                        final String code = sqlRow.getString("CODE");
4421
                        final String code = sqlRow.getString("CODE");
4416
                        if (liaison.containsKey(code)) {
4422
                        if (liaison.containsKey(code)) {
Line 4421... Line 4427...
4421
                        }
4427
                        }
4422
                    }
4428
                    }
4423
                }
4429
                }
4424
            }
4430
            }
4425
 
4431
 
4426
            final SQLTable tableRnet = rootCommon.getTable("RUBRIQUE_NET");
4432
            final SQLTable tableRnet = conf.getRoot().getTable("RUBRIQUE_NET");
4427
 
4433
 
4428
            if (!tableRnet.contains("NUMERO_COMPTE_PCE_CHARGES")) {
4434
            if (!tableRnet.contains("NUMERO_COMPTE_PCE_CHARGES")) {
4429
                final AlterTable alter = new AlterTable(tableRnet);
4435
                final AlterTable alter = new AlterTable(tableRnet);
4430
                alter.addVarCharColumn("NUMERO_COMPTE_PCE_CHARGES", 128);
4436
                alter.addVarCharColumn("NUMERO_COMPTE_PCE_CHARGES", 128);
4431
                final String req = alter.asString();
4437
                final String req = alter.asString();
4432
                rootCommon.getDBSystemRoot().getDataSource().execute(req);
4438
                conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
4433
                rootCommon.refetchTable(tableRnet.getName());
4439
                conf.getRoot().refetchTable(tableRnet.getName());
4434
                rootCommon.getSchema().updateVersion();
4440
                conf.getRoot().getSchema().updateVersion();
4435
            }
4441
            }
4436
 
4442
 
4437
            if (!tableRC.contains("PART_PAT_IMPOSABLE")) {
4443
            if (!tableRC.contains("PART_PAT_IMPOSABLE")) {
4438
                final AlterTable alter = new AlterTable(tableRC);
4444
                final AlterTable alter = new AlterTable(tableRC);
4439
                alter.addBooleanColumn("PART_PAT_IMPOSABLE", Boolean.FALSE, false);
4445
                alter.addBooleanColumn("PART_PAT_IMPOSABLE", Boolean.FALSE, false);
4440
                final String req = alter.asString();
4446
                final String req = alter.asString();
4441
                rootCommon.getDBSystemRoot().getDataSource().execute(req);
4447
                conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
4442
                rootCommon.refetchTable(tableRC.getName());
4448
                conf.getRoot().refetchTable(tableRC.getName());
4443
                rootCommon.getSchema().updateVersion();
4449
                conf.getRoot().getSchema().updateVersion();
4444
            }
4450
            }
4445
 
4451
 
4446
            if (!tableRC.contains("REDUCTION_FILLON")) {
4452
            if (!tableRC.contains("REDUCTION_FILLON")) {
4447
                final AlterTable alter = new AlterTable(tableRC);
4453
                final AlterTable alter = new AlterTable(tableRC);
4448
                alter.addBooleanColumn("REDUCTION_FILLON", Boolean.FALSE, false);
4454
                alter.addBooleanColumn("REDUCTION_FILLON", Boolean.FALSE, false);
4449
                final String req = alter.asString();
4455
                final String req = alter.asString();
4450
                rootCommon.getDBSystemRoot().getDataSource().execute(req);
4456
                conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
4451
                rootCommon.refetchTable(tableRC.getName());
4457
                conf.getRoot().refetchTable(tableRC.getName());
4452
                rootCommon.getSchema().updateVersion();
4458
                conf.getRoot().getSchema().updateVersion();
4453
            }
4459
            }
4454
 
4460
 
4455
            // Vérification des droits existants
4461
            // Vérification des droits existants
4456
            checkRights(rootCommon);
4462
            checkRights(conf.getRoot());
4457
 
4463
 
4458
            if (!rootCommon.contains("DEVISE")) {
4464
            if (!conf.getRoot().contains("DEVISE")) {
4459
                System.out.println("InstallationPanel.InstallationPanel() ADD DEVISE");
4465
                System.out.println("InstallationPanel.InstallationPanel() ADD DEVISE");
4460
                try {
4466
                try {
4461
                    SQLUtils.executeAtomic(ds, new SQLUtils.SQLFactory<Object>() {
4467
                    SQLUtils.executeAtomic(ds, new SQLUtils.SQLFactory<Object>() {
4462
                        @Override
4468
                        @Override
4463
                        public Object create() throws SQLException {
4469
                        public Object create() throws SQLException {
4464
                            final SQLCreateTable createDevise = new SQLCreateTable(rootCommon, "DEVISE");
4470
                            final SQLCreateTable createDevise = new SQLCreateTable(conf.getRoot(), "DEVISE");
4465
                            createDevise.addVarCharColumn("CODE", 128);
4471
                            createDevise.addVarCharColumn("CODE", 128);
4466
                            createDevise.addVarCharColumn("NOM", 128);
4472
                            createDevise.addVarCharColumn("NOM", 128);
4467
                            createDevise.addVarCharColumn("LIBELLE", 128);
4473
                            createDevise.addVarCharColumn("LIBELLE", 128);
4468
                            createDevise.addVarCharColumn("LIBELLE_CENT", 128);
4474
                            createDevise.addVarCharColumn("LIBELLE_CENT", 128);
4469
                            createDevise.addDecimalColumn("TAUX", 16, 8, BigDecimal.ONE, false);
4475
                            createDevise.addDecimalColumn("TAUX", 16, 8, BigDecimal.ONE, false);
4470
                            createDevise.addDecimalColumn("TAUX_COMMERCIAL", 16, 8, BigDecimal.ONE, false);
4476
                            createDevise.addDecimalColumn("TAUX_COMMERCIAL", 16, 8, BigDecimal.ONE, false);
4471
                            ds.execute(createDevise.asString());
4477
                            ds.execute(createDevise.asString());
4472
                            insertUndef(createDevise);
4478
                            insertUndef(createDevise);
4473
                            rootCommon.getSchema().updateVersion();
4479
                            conf.getRoot().getSchema().updateVersion();
4474
                            return null;
4480
                            return null;
4475
                        }
4481
                        }
4476
                    });
4482
                    });
4477
                } catch (Exception ex) {
4483
                } catch (Exception ex) {
4478
                    throw new IllegalStateException("Erreur lors de la création de la table DEVISE", ex);
4484
                    throw new IllegalStateException("Erreur lors de la création de la table DEVISE", ex);
4479
                }
4485
                }
4480
            } else if (!rootCommon.getTable("DEVISE").contains("TAUX_COMMERCIAL")) {
4486
            } else if (!conf.getRoot().getTable("DEVISE").contains("TAUX_COMMERCIAL")) {
4481
                final SQLTable tDevise = rootCommon.getTable("DEVISE");
4487
                final SQLTable tDevise = conf.getRoot().getTable("DEVISE");
4482
                final AlterTable alterDevise = new AlterTable(tDevise);
4488
                final AlterTable alterDevise = new AlterTable(tDevise);
4483
                alterDevise.addDecimalColumn("TAUX_COMMERCIAL", 16, 8, BigDecimal.ONE, false);
4489
                alterDevise.addDecimalColumn("TAUX_COMMERCIAL", 16, 8, BigDecimal.ONE, false);
4484
                ds.execute(alterDevise.asString());
4490
                ds.execute(alterDevise.asString());
4485
                tDevise.getSchema().updateVersion();
4491
                tDevise.getSchema().updateVersion();
4486
            }
4492
            }
4487
 
4493
 
4488
            if (!rootCommon.contains("TYPE_MODELE")) {
4494
            if (!conf.getRoot().contains("TYPE_MODELE")) {
4489
                System.out.println("InstallationPanel.InstallationPanel() ADD TYPE_MODELE");
4495
                System.out.println("InstallationPanel.InstallationPanel() ADD TYPE_MODELE");
4490
                try {
4496
                try {
4491
                    SQLUtils.executeAtomic(ds, new SQLUtils.SQLFactory<Object>() {
4497
                    SQLUtils.executeAtomic(ds, new SQLUtils.SQLFactory<Object>() {
4492
 
4498
 
4493
                        @Override
4499
                        @Override
4494
                        public Object create() throws SQLException {
4500
                        public Object create() throws SQLException {
4495
                            final SQLCreateTable createTypeModele = new SQLCreateTable(rootCommon, "TYPE_MODELE");
4501
                            final SQLCreateTable createTypeModele = new SQLCreateTable(conf.getRoot(), "TYPE_MODELE");
4496
                            createTypeModele.addVarCharColumn("NOM", 128);
4502
                            createTypeModele.addVarCharColumn("NOM", 128);
4497
                            createTypeModele.addVarCharColumn("TABLE", 128);
4503
                            createTypeModele.addVarCharColumn("TABLE", 128);
4498
                            createTypeModele.addVarCharColumn("DEFAULT_MODELE", 128);
4504
                            createTypeModele.addVarCharColumn("DEFAULT_MODELE", 128);
4499
                            ds.execute(createTypeModele.asString());
4505
                            ds.execute(createTypeModele.asString());
4500
 
4506
 
4501
                            insertUndef(createTypeModele);
4507
                            insertUndef(createTypeModele);
4502
 
4508
 
4503
                            rootCommon.getSchema().updateVersion();
4509
                            conf.getRoot().getSchema().updateVersion();
4504
 
4510
 
4505
                            rootCommon.refetch();
4511
                            conf.getRoot().refetch();
4506
 
4512
 
4507
                            return null;
4513
                            return null;
4508
                        }
4514
                        }
4509
                    });
4515
                    });
4510
                    final String[] type = new String[] { "Avoir client", "AVOIR_CLIENT", "Avoir", "Bon de livraison", "BON_DE_LIVRAISON", "BonLivraison", "Commande Client", "COMMANDE_CLIENT",
4516
                    final String[] type = new String[] { "Avoir client", "AVOIR_CLIENT", "Avoir", "Bon de livraison", "BON_DE_LIVRAISON", "BonLivraison", "Commande Client", "COMMANDE_CLIENT",
4511
                            "CommandeClient", "Devis", "DEVIS", "Devis", "Facture", "SAISIE_VENTE_FACTURE", "VenteFacture" };
4517
                            "CommandeClient", "Devis", "DEVIS", "Devis", "Facture", "SAISIE_VENTE_FACTURE", "VenteFacture" };
4512
                    // ('FR', 'Français', 1.000), ('EN',
4518
                    // ('FR', 'Français', 1.000), ('EN',
4513
                    // 'Anglais', 2.000)
4519
                    // 'Anglais', 2.000)
4514
                    final List<String> values = new ArrayList<String>();
4520
                    final List<String> values = new ArrayList<String>();
4515
                    final SQLBase base = rootCommon.getBase();
4521
                    final SQLBase base = conf.getRoot().getBase();
4516
 
4522
 
4517
                    for (int i = 0; i < type.length; i += 3) {
4523
                    for (int i = 0; i < type.length; i += 3) {
4518
                        final int order = values.size() + 1;
4524
                        final int order = values.size() + 1;
4519
                        values.add("(" + base.quoteString(type[i]) + ", " + base.quoteString(type[i + 1]) + ", " + base.quoteString(type[i + 2]) + ", " + order + ")");
4525
                        values.add("(" + base.quoteString(type[i]) + ", " + base.quoteString(type[i + 1]) + ", " + base.quoteString(type[i + 2]) + ", " + order + ")");
4520
                    }
4526
                    }
4521
                    final String valuesStr = CollectionUtils.join(values, ", ");
4527
                    final String valuesStr = CollectionUtils.join(values, ", ");
4522
                    final String insertVals = "INSERT INTO " + rootCommon.getTable("TYPE_MODELE").getSQLName().quote() + "(" + SQLBase.quoteIdentifier("NOM") + ", " + SQLBase.quoteIdentifier("TABLE")
4528
                    final String insertVals = "INSERT INTO " + conf.getRoot().getTable("TYPE_MODELE").getSQLName().quote() + "(" + SQLBase.quoteIdentifier("NOM") + ", "
4523
                            + ", " + SQLBase.quoteIdentifier("DEFAULT_MODELE") + ", " + SQLBase.quoteIdentifier(SQLSyntax.ORDER_NAME) + ") VALUES" + valuesStr;
4529
                            + SQLBase.quoteIdentifier("TABLE") + ", " + SQLBase.quoteIdentifier("DEFAULT_MODELE") + ", " + SQLBase.quoteIdentifier(SQLSyntax.ORDER_NAME) + ") VALUES" + valuesStr;
4524
 
4530
 
4525
                    ds.execute(insertVals);
4531
                    ds.execute(insertVals);
4526
                } catch (Exception ex) {
4532
                } catch (Exception ex) {
4527
                    throw new IllegalStateException("Erreur lors de la création de la table TYPE_MODELE", ex);
4533
                    throw new IllegalStateException("Erreur lors de la création de la table TYPE_MODELE", ex);
4528
                }
4534
                }
4529
            }
4535
            }
4530
 
4536
 
4531
            SQLTable.setUndefID(rootCommon.getSchema(), "DEVISE", 1);
4537
            SQLTable.setUndefID(conf.getRoot().getSchema(), "DEVISE", 1);
4532
            SQLTable.setUndefID(rootCommon.getSchema(), "TYPE_MODELE", 1);
4538
            SQLTable.setUndefID(conf.getRoot().getSchema(), "TYPE_MODELE", 1);
4533
 
4539
 
4534
            // DSN
4540
            // DSN
4535
            final DSNInstallationUtils dsnUtils = new DSNInstallationUtils();
4541
            final DSNInstallationUtils dsnUtils = new DSNInstallationUtils();
4536
            dsnUtils.updateDSNCommonTable(rootCommon);
4542
            dsnUtils.updateDSNCommonTable(conf.getRoot());
4537
            SQLRow rowRubNetPAS = createPasCommon(rootCommon);
4543
            SQLRow rowRubNetPAS = createPasCommon(conf.getRoot());
4538
            // ECo contribution
4544
            // ECo contribution
4539
            final EcoContributionInstallationUtils ecoUtils = new EcoContributionInstallationUtils();
4545
            final EcoContributionInstallationUtils ecoUtils = new EcoContributionInstallationUtils();
4540
            ecoUtils.updateEcoCommonTable(rootCommon);
4546
            ecoUtils.updateEcoCommonTable(conf.getRoot());
4541
 
4547
 
4542
 
4548
 
4543
            // we need to upgrade all roots
4549
            // we need to upgrade all roots
4544
            // ///////////////////////////
4550
            // ///////////////////////////
4545
            systemRoot.mapAllRoots();
4551
            conf.getSystemRoot().mapAllRoots();
4546
            systemRoot.refetch();
4552
            conf.getSystemRoot().refetch();
-
 
4553
 
-
 
4554
            // Merge IDCC
-
 
4555
            final SQLTable societeCommon = conf.getRoot().getTable("SOCIETE_COMMON");
-
 
4556
            if (!societeCommon.contains("ID_IDCC")) {
-
 
4557
                SQLCreateTable createIDCCCommon = new SQLCreateTable(conf.getRoot(), "IDCC");
-
 
4558
                createIDCCCommon.addVarCharColumn("CODE", 45, false, "''", true);
-
 
4559
                createIDCCCommon.addVarCharColumn("NOM", 2048, false, "''", true);
-
 
4560
                AddMDFields.addFields(createIDCCCommon, conf.getRoot().getTable("USER_COMMON"));
-
 
4561
 
-
 
4562
                societeCommon.getDBRoot().createTable(createIDCCCommon);
-
 
4563
                societeCommon.getDBRoot().refetchTable("IDCC");
-
 
4564
 
-
 
4565
                AlterTable alter = new AlterTable(societeCommon);
-
 
4566
                alter.addForeignColumn("ID_IDCC", conf.getRoot().getTable("IDCC"));
-
 
4567
                societeCommon.getDBRoot().getDBSystemRoot().getDataSource().execute(alter.asString());
-
 
4568
                societeCommon.getDBRoot().refetchTable("SOCIETE_COMMON");
-
 
4569
 
-
 
4570
            }
-
 
4571
            final Set<String> childrenNames = conf.getSystemRoot().getChildrenNames();
-
 
4572
            MergeTable mergeIDCC = new MergeTable(conf.getRoot().getDBSystemRoot());
-
 
4573
            mergeIDCC.setDestTable(conf.getRoot().getTable("IDCC"));
-
 
4574
 
-
 
4575
            final List<String> mdFields = Arrays.asList("ID_USER_COMMON_CREATE", "ID_USER_COMMON_MODIFY", "CREATION_DATE", "MODIFICATION_DATE");
-
 
4576
            for (final String childName : childrenNames) {
-
 
4577
                final DBRoot root = conf.getSystemRoot().getRoot(childName);
-
 
4578
                if (!root.getName().contains("Common") && root.contains("IDCC")) {
-
 
4579
                    final SQLTable table = root.getTable("IDCC");
-
 
4580
                    AlterTable alter = new AlterTable(table);
-
 
4581
                    alter.alterColumnNullable("ARCHIVE", false);
-
 
4582
                    // Drop MD Fields to be sure having same column properties
-
 
4583
                    for (String field : mdFields) {
-
 
4584
                        alter.dropColumn(field);
-
 
4585
                    }
-
 
4586
                    root.getDBSystemRoot().getDataSource().execute(alter.asString());
-
 
4587
                    root.refetchTable("IDCC");
-
 
4588
                    new AddMDFields(root.getDBSystemRoot()).change(table);
4547
 
4589
 
-
 
4590
                    mergeIDCC.change(table);
-
 
4591
                }
-
 
4592
            }
4548
            final Set<String> childrenNames = systemRoot.getChildrenNames();
4593
            // final Set<String> childrenNames = conf.getSystemRoot().getChildrenNames();
4549
 
4594
 
4550
            SwingUtilities.invokeLater(new Runnable() {
4595
            SwingUtilities.invokeLater(new Runnable() {
4551
 
4596
 
4552
                @Override
4597
                @Override
4553
                public void run() {
4598
                public void run() {
Line 4566... Line 4611...
4566
                    public void run() {
4611
                    public void run() {
4567
                        bar.setValue(barValue);
4612
                        bar.setValue(barValue);
4568
                    }
4613
                    }
4569
                });
4614
                });
4570
                i++;
4615
                i++;
4571
                final DBRoot root = systemRoot.getRoot(childName);
4616
                final DBRoot root = conf.getSystemRoot().getRoot(childName);
4572
                try {
4617
                try {
4573
                    systemRoot.getDataSource().execute("CREATE LANGUAGE plpgsql;");
4618
                    conf.getSystemRoot().getDataSource().execute("CREATE LANGUAGE plpgsql;");
4574
                } catch (Exception e) {
4619
                } catch (Exception e) {
4575
                    System.err.println("Warning: cannot add language plpgsql" + e.getMessage());
4620
                    System.err.println("Warning: cannot add language plpgsql" + e.getMessage());
4576
                }
4621
                }
4577
                final SQLTable tableUndef = root.getTable(SQLTable.undefTable);
4622
                final SQLTable tableUndef = root.getTable(SQLTable.undefTable);
4578
                if (tableUndef != null && tableUndef.getField("UNDEFINED_ID").isNullable() == Boolean.FALSE) {
4623
                if (tableUndef != null && tableUndef.getField("UNDEFINED_ID").isNullable() == Boolean.FALSE) {
Line 4599... Line 4644...
4599
                        @Override
4644
                        @Override
4600
                        public Object create() throws SQLException {
4645
                        public Object create() throws SQLException {
4601
                            fixUnboundedNumeric(root);
4646
                            fixUnboundedNumeric(root);
4602
                            fixCompletion(root);
4647
                            fixCompletion(root);
4603
                            try {
4648
                            try {
4604
                                updateSocieteSchema(conf, root);
4649
                                updateSocieteSchema(root);
4605
                            } catch (Exception e) {
4650
                            } catch (Exception e) {
4606
                                throw new SQLException(e);
4651
                                throw new SQLException(e);
4607
                            }
4652
                            }
4608
                            updateToV1Dot2(root);
4653
                            updateToV1Dot2(root);
4609
                            updateToV1Dot3(root);
4654
                            updateToV1Dot3(root);