OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 182 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 182 Rev 185
Line 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.config;
14
 package org.openconcerto.erp.config;
15
 
15
 
16
import org.openconcerto.erp.config.update.Updater_1_5;
16
import org.openconcerto.erp.config.update.Updater_1_5;
-
 
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.humanresources.payroll.report.LignePayeSimplifiee;
18
import org.openconcerto.erp.core.humanresources.payroll.report.LignePayeSimplifiee;
18
import org.openconcerto.erp.core.sales.order.ui.EtatCommandeClient;
19
import org.openconcerto.erp.core.sales.order.ui.EtatCommandeClient;
19
import org.openconcerto.erp.core.sales.quote.element.EtatDevisSQLElement;
20
import org.openconcerto.erp.core.sales.quote.element.EtatDevisSQLElement;
20
import org.openconcerto.erp.modules.ModuleManager;
21
import org.openconcerto.erp.modules.ModuleManager;
21
import org.openconcerto.erp.modules.ModuleReference;
22
import org.openconcerto.erp.modules.ModuleReference;
Line 98... Line 99...
98
import javax.swing.SwingUtilities;
99
import javax.swing.SwingUtilities;
99
 
100
 
100
public class InstallationPanel extends JPanel {
101
public class InstallationPanel extends JPanel {
101
    private static final boolean DEBUG_FK = false;
102
    private static final boolean DEBUG_FK = false;
102
 
103
 
-
 
104
    public static final String METADATA_VERSION = "OpenConcerto_Version";
-
 
105
 
103
    public static void insertUndef(final SQLCreateTable ct) throws SQLException {
106
    public static void insertUndef(final SQLCreateTable ct) throws SQLException {
104
        // check that we can use insertReturnFirstField()
107
        // check that we can use insertReturnFirstField()
105
        if (ct.getPrimaryKey().size() != 1)
108
        if (ct.getPrimaryKey().size() != 1)
106
            throw new IllegalStateException("Not one and only one field in the PK : " + ct.getPrimaryKey());
109
            throw new IllegalStateException("Not one and only one field in the PK : " + ct.getPrimaryKey());
107
        final Insertion<?> insertion = new Inserter(ct).insertReturnFirstField("(" + SQLBase.quoteIdentifier(SQLSyntax.ORDER_NAME) + ") VALUES(" + ReOrder.MIN_ORDER + ")", false);
110
        final Insertion<?> insertion = new Inserter(ct).insertReturnFirstField("(" + SQLBase.quoteIdentifier(SQLSyntax.ORDER_NAME) + ") VALUES(" + ReOrder.MIN_ORDER + ")", false);
Line 862... Line 865...
862
 
865
 
863
            if (!alter.isEmpty())
866
            if (!alter.isEmpty())
864
                alters.add(alter);
867
                alters.add(alter);
865
 
868
 
866
        }
869
        }
-
 
870
 
-
 
871
        {
-
 
872
            List<String> tables = Arrays.asList("FACTURE_FOURNISSEUR_ELEMENT", "DEVIS_ELEMENT", "COMMANDE_ELEMENT", "BON_RECEPTION_ELEMENT", "COMMANDE_CLIENT_ELEMENT", "BON_DE_LIVRAISON_ELEMENT",
-
 
873
                    "SAISIE_VENTE_FACTURE_ELEMENT", "AVOIR_CLIENT_ELEMENT", "DEMANDE_PRIX_ELEMENT"
-
 
874
 
-
 
875
            );
-
 
876
            for (String string : tables) {
-
 
877
 
-
 
878
                final String fName = "T_POIDS_COLIS_NET";
-
 
879
                if (root.getTable(string).contains(fName)) {
-
 
880
                    SQLField fieldRepFacture = root.getTable(string).getField(fName);
-
 
881
                    if (fieldRepFacture.getType().getSize() > 500) {
-
 
882
                        final AlterTable alter = new AlterTable(root.getTable(string));
-
 
883
                        alter.alterColumn(fName, EnumSet.allOf(Properties.class), "numeric(16,8)", "1", false);
-
 
884
                        alter.alterColumn("POIDS_COLIS_NET", EnumSet.allOf(Properties.class), "numeric(16,8)", "1", false);
-
 
885
                        alters.add(alter);
-
 
886
                    }
-
 
887
                }
-
 
888
            }
-
 
889
        }
867
        if (alters.size() > 0) {
890
        if (alters.size() > 0) {
868
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
891
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
869
 
892
 
870
            for (UpdateBuilder updateBuilder : builds) {
893
            for (UpdateBuilder updateBuilder : builds) {
871
                ds.execute(updateBuilder.asString());
894
                ds.execute(updateBuilder.asString());
Line 3867... Line 3890...
3867
            rowValsUserRight.put("ID_RIGHT", row.getID());
3890
            rowValsUserRight.put("ID_RIGHT", row.getID());
3868
            rowValsUserRight.put("HAVE_RIGHT", Boolean.TRUE);
3891
            rowValsUserRight.put("HAVE_RIGHT", Boolean.TRUE);
3869
            rowValsUserRight.commit();
3892
            rowValsUserRight.commit();
3870
        }
3893
        }
3871
 
3894
 
-
 
3895
        if (!codes.contains(ComptaSQLConfElement.NON_RESTREINT_PAR_COMMERCIAL_RIGHT)) {
-
 
3896
            SQLRowValues rowVals = new SQLRowValues(table);
-
 
3897
            rowVals.put("CODE", ComptaSQLConfElement.NON_RESTREINT_PAR_COMMERCIAL_RIGHT);
-
 
3898
            rowVals.put("NOM", "Non restreint aux éléments liés au commercial de l'utilisateur");
-
 
3899
            String desc = "Liste non restreinte aux éléments liés au commercial de l'utilisateur";
-
 
3900
            rowVals.put("DESCRIPTION", desc);
-
 
3901
            SQLRow row = rowVals.commit();
-
 
3902
            SQLRowValues rowValsUserRight = new SQLRowValues(table.getTable("USER_RIGHT"));
-
 
3903
            rowValsUserRight.put("ID_RIGHT", row.getID());
-
 
3904
            rowValsUserRight.put("HAVE_RIGHT", Boolean.TRUE);
-
 
3905
            rowValsUserRight.commit();
-
 
3906
        }
-
 
3907
 
3872
    }
3908
    }
3873
 
3909
 
3874
    private void findBadForeignKey(DBRoot root) {
3910
    private void findBadForeignKey(DBRoot root) {
3875
        Set<SQLTable> tables = root.getTables();
3911
        Set<SQLTable> tables = root.getTables();
3876
        for (SQLTable table : tables) {
3912
        for (SQLTable table : tables) {
Line 4109... Line 4145...
4109
            rowVals.put("NOM", "PortVenteNonSoumisTVA");
4145
            rowVals.put("NOM", "PortVenteNonSoumisTVA");
4110
            rowVals.put("NUMERO_DEFAULT", "708520");
4146
            rowVals.put("NUMERO_DEFAULT", "708520");
4111
            rowVals.commit();
4147
            rowVals.commit();
4112
        }
4148
        }
4113
 
4149
 
-
 
4150
        if (!prefs.contains("PortAchatSoumisTVA")) {
-
 
4151
            SQLRowValues rowVals = new SQLRowValues(table);
-
 
4152
            rowVals.put("NOM", "PortAchatSoumisTVA");
-
 
4153
            rowVals.put("NUMERO_DEFAULT", "608510");
-
 
4154
            rowVals.commit();
-
 
4155
        }
-
 
4156
 
-
 
4157
        if (!prefs.contains("PortAchatNonSoumisTVA")) {
-
 
4158
            SQLRowValues rowVals = new SQLRowValues(table);
-
 
4159
            rowVals.put("NOM", "PortAchatNonSoumisTVA");
-
 
4160
            rowVals.put("NUMERO_DEFAULT", "608520");
-
 
4161
            rowVals.commit();
-
 
4162
        }
-
 
4163
 
4114
        if (!prefs.contains("AvanceClients")) {
4164
        if (!prefs.contains("AvanceClients")) {
4115
            SQLRowValues rowVals = new SQLRowValues(table);
4165
            SQLRowValues rowVals = new SQLRowValues(table);
4116
            rowVals.put("NOM", "AvanceClients");
4166
            rowVals.put("NOM", "AvanceClients");
4117
            rowVals.put("NUMERO_DEFAULT", "4191");
4167
            rowVals.put("NUMERO_DEFAULT", "4191");
4118
            rowVals.commit();
4168
            rowVals.commit();
Line 4185... Line 4235...
4185
 
4235
 
4186
            String req = "UPDATE " + tableAdresse.getSQLName().quote() + " SET \"VILLE\"= trim (both ' ' from substring(\"VILLE\" from 0 for (position('(' in \"VILLE\")))) ";
4236
            String req = "UPDATE " + tableAdresse.getSQLName().quote() + " SET \"VILLE\"= trim (both ' ' from substring(\"VILLE\" from 0 for (position('(' in \"VILLE\")))) ";
4187
            req += ", \"CODE_POSTAL\"=substring(\"VILLE\" from (position('(' in \"VILLE\")+1) for length(\"VILLE\")-position('(' in \"VILLE\")-1) WHERE \"VILLE\" LIKE '% (%)'";
4237
            req += ", \"CODE_POSTAL\"=substring(\"VILLE\" from (position('(' in \"VILLE\")+1) for length(\"VILLE\")-position('(' in \"VILLE\")-1) WHERE \"VILLE\" LIKE '% (%)'";
4188
            tableAdresse.getDBRoot().getDBSystemRoot().getDataSource().execute(req);
4238
            tableAdresse.getDBRoot().getDBSystemRoot().getDataSource().execute(req);
4189
        }
4239
        }
-
 
4240
 
4190
    }
4241
    }
4191
 
4242
 
4192
    private void updateVariablePaye(SQLTable table, String var, double value) throws SQLException {
4243
    private void updateVariablePaye(SQLTable table, String var, double value) throws SQLException {
4193
        if (table == null) {
4244
        if (table == null) {
4194
            throw new IllegalArgumentException("null table");
4245
            throw new IllegalArgumentException("null table");
Line 4344... Line 4395...
4344
                        pos++;
4395
                        pos++;
4345
                    }
4396
                    }
4346
                }
4397
                }
4347
 
4398
 
4348
                final SQLTable tableRB = conf.getRoot().getTable("RUBRIQUE_BRUT");
4399
                final SQLTable tableRB = conf.getRoot().getTable("RUBRIQUE_BRUT");
-
 
4400
                if (!tableRB.contains("PART_CSG_SANS_ABATTEMENT")) {
-
 
4401
                    final AlterTable alter = new AlterTable(tableRB);
-
 
4402
                    alter.addBooleanColumn("PART_CSG_SANS_ABATTEMENT", Boolean.FALSE, false);
-
 
4403
                    final String req = alter.asString();
-
 
4404
                    conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
-
 
4405
                    conf.getRoot().refetchTable(tableRB.getName());
-
 
4406
                    conf.getRoot().getSchema().updateVersion();
-
 
4407
                }
-
 
4408
 
4349
                if (!tableRB.contains("AVANTAGE_NATURE")) {
4409
                if (!tableRB.contains("AVANTAGE_NATURE")) {
4350
                    final AlterTable alter = new AlterTable(tableRB);
4410
                    final AlterTable alter = new AlterTable(tableRB);
4351
                    alter.addBooleanColumn("AVANTAGE_NATURE", Boolean.FALSE, false);
4411
                    alter.addBooleanColumn("AVANTAGE_NATURE", Boolean.FALSE, false);
4352
                    final String req = alter.asString();
4412
                    final String req = alter.asString();
4353
                    conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
4413
                    conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
Line 4589... Line 4649...
4589
 
4649
 
4590
                    mergeIDCC.change(table);
4650
                    mergeIDCC.change(table);
4591
                }
4651
                }
4592
            }
4652
            }
4593
            // final Set<String> childrenNames = conf.getSystemRoot().getChildrenNames();
4653
            // final Set<String> childrenNames = conf.getSystemRoot().getChildrenNames();
4594
 
-
 
-
 
4654
            conf.getRoot().setMetadata(METADATA_VERSION, ProductInfo.getInstance().getVersion());
4595
            SwingUtilities.invokeLater(new Runnable() {
4655
            SwingUtilities.invokeLater(new Runnable() {
4596
 
4656
 
4597
                @Override
4657
                @Override
4598
                public void run() {
4658
                public void run() {
4599
                    bar.setIndeterminate(false);
4659
                    bar.setIndeterminate(false);
Line 4718... Line 4778...
4718
 
4778
 
4719
                            }
4779
                            }
4720
 
4780
 
4721
                            // at the end to let Updater_1_5 change field types from varchar to text
4781
                            // at the end to let Updater_1_5 change field types from varchar to text
4722
                            fixUnboundedVarchar(root);
4782
                            fixUnboundedVarchar(root);
-
 
4783
                            root.setMetadata(METADATA_VERSION, ProductInfo.getInstance().getVersion());
4723
                            return null;
4784
                            return null;
4724
                        }
4785
                        }
4725
 
4786
 
4726
                    });
4787
                    });
4727
                }
4788
                }