OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 174 Rev 177
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 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.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
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.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.sql.Configuration;
23
import org.openconcerto.sql.changer.convert.AddFK;
23
import org.openconcerto.sql.changer.convert.AddFK;
24
import org.openconcerto.sql.changer.convert.ChangeIDToInt;
24
import org.openconcerto.sql.changer.convert.ChangeIDToInt;
25
import org.openconcerto.sql.changer.correct.CorrectOrder;
25
import org.openconcerto.sql.changer.correct.CorrectOrder;
26
import org.openconcerto.sql.changer.correct.FixSerial;
26
import org.openconcerto.sql.changer.correct.FixSerial;
27
import org.openconcerto.sql.element.GroupSQLComponent;
27
import org.openconcerto.sql.element.GroupSQLComponent;
28
import org.openconcerto.sql.model.AliasedTable;
28
import org.openconcerto.sql.model.AliasedTable;
29
import org.openconcerto.sql.model.DBRoot;
29
import org.openconcerto.sql.model.DBRoot;
30
import org.openconcerto.sql.model.DBSystemRoot;
30
import org.openconcerto.sql.model.DBSystemRoot;
31
import org.openconcerto.sql.model.SQLBase;
31
import org.openconcerto.sql.model.SQLBase;
32
import org.openconcerto.sql.model.SQLDataSource;
32
import org.openconcerto.sql.model.SQLDataSource;
33
import org.openconcerto.sql.model.SQLField;
33
import org.openconcerto.sql.model.SQLField;
34
import org.openconcerto.sql.model.SQLField.Properties;
34
import org.openconcerto.sql.model.SQLField.Properties;
35
import org.openconcerto.sql.model.SQLInjector;
35
import org.openconcerto.sql.model.SQLInjector;
36
import org.openconcerto.sql.model.SQLName;
36
import org.openconcerto.sql.model.SQLName;
37
import org.openconcerto.sql.model.SQLRow;
37
import org.openconcerto.sql.model.SQLRow;
38
import org.openconcerto.sql.model.SQLRowListRSH;
38
import org.openconcerto.sql.model.SQLRowListRSH;
39
import org.openconcerto.sql.model.SQLRowValues;
39
import org.openconcerto.sql.model.SQLRowValues;
40
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
40
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
41
import org.openconcerto.sql.model.SQLSchema;
41
import org.openconcerto.sql.model.SQLSchema;
42
import org.openconcerto.sql.model.SQLSelect;
42
import org.openconcerto.sql.model.SQLSelect;
43
import org.openconcerto.sql.model.SQLSyntax;
43
import org.openconcerto.sql.model.SQLSyntax;
44
import org.openconcerto.sql.model.SQLSystem;
44
import org.openconcerto.sql.model.SQLSystem;
45
import org.openconcerto.sql.model.SQLTable;
45
import org.openconcerto.sql.model.SQLTable;
46
import org.openconcerto.sql.model.Where;
46
import org.openconcerto.sql.model.Where;
47
import org.openconcerto.sql.model.graph.SQLKey;
47
import org.openconcerto.sql.model.graph.SQLKey;
48
import org.openconcerto.sql.request.Inserter;
48
import org.openconcerto.sql.request.Inserter;
49
import org.openconcerto.sql.request.Inserter.Insertion;
49
import org.openconcerto.sql.request.Inserter.Insertion;
50
import org.openconcerto.sql.request.UpdateBuilder;
50
import org.openconcerto.sql.request.UpdateBuilder;
51
import org.openconcerto.sql.sqlobject.SQLTextCombo;
51
import org.openconcerto.sql.sqlobject.SQLTextCombo;
52
import org.openconcerto.sql.users.rights.TableAllRights;
52
import org.openconcerto.sql.users.rights.TableAllRights;
53
import org.openconcerto.sql.utils.AlterTable;
53
import org.openconcerto.sql.utils.AlterTable;
54
import org.openconcerto.sql.utils.ChangeTable;
54
import org.openconcerto.sql.utils.ChangeTable;
55
import org.openconcerto.sql.utils.ChangeTable.ClauseType;
55
import org.openconcerto.sql.utils.ChangeTable.ClauseType;
56
import org.openconcerto.sql.utils.ChangeTable.DeferredClause;
56
import org.openconcerto.sql.utils.ChangeTable.DeferredClause;
57
import org.openconcerto.sql.utils.ReOrder;
57
import org.openconcerto.sql.utils.ReOrder;
58
import org.openconcerto.sql.utils.SQLCreateMoveableTable;
58
import org.openconcerto.sql.utils.SQLCreateMoveableTable;
59
import org.openconcerto.sql.utils.SQLCreateTable;
59
import org.openconcerto.sql.utils.SQLCreateTable;
60
import org.openconcerto.sql.utils.SQLUtils;
60
import org.openconcerto.sql.utils.SQLUtils;
61
import org.openconcerto.sql.utils.SQLUtils.SQLFactory;
61
import org.openconcerto.sql.utils.SQLUtils.SQLFactory;
62
import org.openconcerto.ui.DefaultGridBagConstraints;
62
import org.openconcerto.ui.DefaultGridBagConstraints;
63
import org.openconcerto.ui.JLabelBold;
63
import org.openconcerto.ui.JLabelBold;
64
import org.openconcerto.utils.CollectionUtils;
64
import org.openconcerto.utils.CollectionUtils;
65
import org.openconcerto.utils.ExceptionHandler;
65
import org.openconcerto.utils.ExceptionHandler;
66
import org.openconcerto.utils.ProductInfo;
66
import org.openconcerto.utils.ProductInfo;
67
import org.openconcerto.utils.StringUtils;
67
import org.openconcerto.utils.StringUtils;
68
import org.openconcerto.utils.cc.ITransformer;
68
import org.openconcerto.utils.cc.ITransformer;
69
 
69
 
70
import java.awt.GridBagConstraints;
70
import java.awt.GridBagConstraints;
71
import java.awt.GridBagLayout;
71
import java.awt.GridBagLayout;
72
import java.awt.Insets;
72
import java.awt.Insets;
73
import java.awt.event.ActionEvent;
73
import java.awt.event.ActionEvent;
74
import java.awt.event.ActionListener;
74
import java.awt.event.ActionListener;
75
import java.io.IOException;
75
import java.io.IOException;
76
import java.math.BigDecimal;
76
import java.math.BigDecimal;
77
import java.sql.SQLException;
77
import java.sql.SQLException;
78
import java.sql.Types;
78
import java.sql.Types;
79
import java.util.ArrayList;
79
import java.util.ArrayList;
80
import java.util.Arrays;
80
import java.util.Arrays;
81
import java.util.Collection;
81
import java.util.Collection;
82
import java.util.Collections;
82
import java.util.Collections;
83
import java.util.EnumSet;
83
import java.util.EnumSet;
84
import java.util.HashMap;
84
import java.util.HashMap;
85
import java.util.HashSet;
85
import java.util.HashSet;
86
import java.util.List;
86
import java.util.List;
87
import java.util.Map;
87
import java.util.Map;
88
import java.util.Set;
88
import java.util.Set;
89
 
89
 
90
import javax.swing.JButton;
90
import javax.swing.JButton;
91
import javax.swing.JLabel;
91
import javax.swing.JLabel;
92
import javax.swing.JOptionPane;
92
import javax.swing.JOptionPane;
93
import javax.swing.JPanel;
93
import javax.swing.JPanel;
94
import javax.swing.JProgressBar;
94
import javax.swing.JProgressBar;
95
import javax.swing.JTextField;
95
import javax.swing.JTextField;
96
import javax.swing.SwingUtilities;
96
import javax.swing.SwingUtilities;
97
 
97
 
98
public class InstallationPanel extends JPanel {
98
public class InstallationPanel extends JPanel {
99
    private static final boolean DEBUG_FK = false;
99
    private static final boolean DEBUG_FK = false;
100
 
100
 
101
    public static void insertUndef(final SQLCreateTable ct) throws SQLException {
101
    public static void insertUndef(final SQLCreateTable ct) throws SQLException {
102
        // check that we can use insertReturnFirstField()
102
        // check that we can use insertReturnFirstField()
103
        if (ct.getPrimaryKey().size() != 1)
103
        if (ct.getPrimaryKey().size() != 1)
104
            throw new IllegalStateException("Not one and only one field in the PK : " + ct.getPrimaryKey());
104
            throw new IllegalStateException("Not one and only one field in the PK : " + ct.getPrimaryKey());
105
        final Insertion<?> insertion = new Inserter(ct).insertReturnFirstField("(" + SQLBase.quoteIdentifier(SQLSyntax.ORDER_NAME) + ") VALUES(" + ReOrder.MIN_ORDER + ")", false);
105
        final Insertion<?> insertion = new Inserter(ct).insertReturnFirstField("(" + SQLBase.quoteIdentifier(SQLSyntax.ORDER_NAME) + ") VALUES(" + ReOrder.MIN_ORDER + ")", false);
106
        assert insertion.getCount() == 1;
106
        assert insertion.getCount() == 1;
107
        if (insertion.getRows().size() != 1)
107
        if (insertion.getRows().size() != 1)
108
            throw new IllegalStateException("Missing ID " + insertion.getRows());
108
            throw new IllegalStateException("Missing ID " + insertion.getRows());
109
        SQLTable.setUndefID(ct.getRoot().getSchema(), ct.getName(), ((Number) insertion.getRows().get(0)).intValue());
109
        SQLTable.setUndefID(ct.getRoot().getSchema(), ct.getName(), ((Number) insertion.getRows().get(0)).intValue());
110
    }
110
    }
111
 
111
 
112
    private static SQLName getTableName(final SQLCreateTable ct) {
112
    private static SQLName getTableName(final SQLCreateTable ct) {
113
        return new SQLName(ct.getRoot().getName(), ct.getName());
113
        return new SQLName(ct.getRoot().getName(), ct.getName());
114
    }
114
    }
115
 
115
 
116
    JProgressBar bar = new JProgressBar();
116
    JProgressBar bar = new JProgressBar();
117
    boolean error;
117
    boolean error;
118
 
118
 
119
    public InstallationPanel(final ServerFinderPanel finderPanel) {
119
    public InstallationPanel(final ServerFinderPanel finderPanel) {
120
        super(new GridBagLayout());
120
        super(new GridBagLayout());
121
        setOpaque(false);
121
        setOpaque(false);
122
        GridBagConstraints c = new DefaultGridBagConstraints();
122
        GridBagConstraints c = new DefaultGridBagConstraints();
123
        JButton user = new JButton("Créer l'utilisateur");
123
        JButton user = new JButton("Créer l'utilisateur");
124
        user.setOpaque(false);
124
        user.setOpaque(false);
125
        // JButton bd = new JButton("Créer la base de données");
125
        // JButton bd = new JButton("Créer la base de données");
126
        final JButton up = new JButton("Mise à niveau de la base");
126
        final JButton up = new JButton("Mise à niveau de la base");
127
        up.setOpaque(false);
127
        up.setOpaque(false);
128
        up.addActionListener(new ActionListener() {
128
        up.addActionListener(new ActionListener() {
129
 
129
 
130
            @Override
130
            @Override
131
            public void actionPerformed(ActionEvent e) {
131
            public void actionPerformed(ActionEvent e) {
132
                if (finderPanel != null) {
132
                if (finderPanel != null) {
133
                    finderPanel.saveConfigFile();
133
                    finderPanel.saveConfigFile();
134
                }
134
                }
135
                bar.setIndeterminate(true);
135
                bar.setIndeterminate(true);
136
                up.setEnabled(false);
136
                up.setEnabled(false);
137
                new Thread(new Runnable() {
137
                new Thread(new Runnable() {
138
 
138
 
139
                    @Override
139
                    @Override
140
                    public void run() {
140
                    public void run() {
141
                        System.setProperty(SQLSchema.NOAUTO_CREATE_METADATA, "false");
141
                        System.setProperty(SQLSchema.NOAUTO_CREATE_METADATA, "false");
142
                        final ComptaPropsConfiguration conf = ComptaPropsConfiguration.create(true);
142
                        final ComptaPropsConfiguration conf = ComptaPropsConfiguration.create(true);
143
 
143
 
144
                        final DBSystemRoot systemRoot = conf.getSystemRoot();
144
                        final DBSystemRoot systemRoot = conf.getSystemRoot();
145
                        if (systemRoot.getChild(conf.getRootNameValue().getValue()) == null) {
145
                        if (systemRoot.getChild(conf.getRootNameValue().getValue()) == null) {
146
                            conf.destroy();
146
                            conf.destroy();
147
                            SwingUtilities.invokeLater(new Runnable() {
147
                            SwingUtilities.invokeLater(new Runnable() {
148
                                @Override
148
                                @Override
149
                                public void run() {
149
                                public void run() {
150
                                    up.setEnabled(true);
150
                                    up.setEnabled(true);
151
                                    bar.setValue(bar.getMaximum());
151
                                    bar.setValue(bar.getMaximum());
152
                                    JOptionPane.showMessageDialog(InstallationPanel.this, "Votre base de données n'est pas initialisée");
152
                                    JOptionPane.showMessageDialog(InstallationPanel.this, "Votre base de données n'est pas initialisée");
153
                                }
153
                                }
154
                            });
154
                            });
155
                            return;
155
                            return;
156
                        }
156
                        }
157
 
157
 
158
                        updateDatabase(conf);
158
                        updateDatabase(conf);
159
 
159
 
160
                        conf.destroy();
160
                        conf.destroy();
161
                        SwingUtilities.invokeLater(new Runnable() {
161
                        SwingUtilities.invokeLater(new Runnable() {
162
 
162
 
163
                            @Override
163
                            @Override
164
                            public void run() {
164
                            public void run() {
165
                                up.setEnabled(true);
165
                                up.setEnabled(true);
166
                                bar.setValue(bar.getMaximum());
166
                                bar.setValue(bar.getMaximum());
167
                                if (!error) {
167
                                if (!error) {
168
                                    JOptionPane.showMessageDialog(InstallationPanel.this, "Mise à niveau réussie");
168
                                    JOptionPane.showMessageDialog(InstallationPanel.this, "Mise à niveau réussie");
169
                                }
169
                                }
170
                            }
170
                            }
171
                        });
171
                        });
172
                        System.setProperty(SQLSchema.NOAUTO_CREATE_METADATA, "true");
172
                        System.setProperty(SQLSchema.NOAUTO_CREATE_METADATA, "true");
173
                    }
173
                    }
174
                }, "Database structure updater").start();
174
                }, "Database structure updater").start();
175
 
175
 
176
            }
176
            }
177
 
177
 
178
        });
178
        });
179
        if (finderPanel != null && finderPanel.getToken() == null) {
179
        if (finderPanel != null && finderPanel.getToken() == null) {
180
            c.weightx = 1;
180
            c.weightx = 1;
181
            c.gridwidth = GridBagConstraints.REMAINDER;
181
            c.gridwidth = GridBagConstraints.REMAINDER;
182
            this.add(new JLabelBold("Création de l'utilisateur openconcerto dans la base"), c);
182
            this.add(new JLabelBold("Création de l'utilisateur openconcerto dans la base"), c);
183
            c.gridy++;
183
            c.gridy++;
184
            c.weightx = 1;
184
            c.weightx = 1;
185
            this.add(new JLabel("Identifiant de connexion de votre base "), c);
185
            this.add(new JLabel("Identifiant de connexion de votre base "), c);
186
            c.gridy++;
186
            c.gridy++;
187
            c.gridwidth = 1;
187
            c.gridwidth = 1;
188
            c.weightx = 0;
188
            c.weightx = 0;
189
            this.add(new JLabel("Login"), c);
189
            this.add(new JLabel("Login"), c);
190
            c.gridx++;
190
            c.gridx++;
191
 
191
 
192
            final JTextField login = new JTextField();
192
            final JTextField login = new JTextField();
193
            c.weightx = 1;
193
            c.weightx = 1;
194
            this.add(login, c);
194
            this.add(login, c);
195
 
195
 
196
            c.gridx++;
196
            c.gridx++;
197
            c.weightx = 0;
197
            c.weightx = 0;
198
            this.add(new JLabel("Mot de passe"), c);
198
            this.add(new JLabel("Mot de passe"), c);
199
            c.gridx++;
199
            c.gridx++;
200
            final JTextField mdp = new JTextField();
200
            final JTextField mdp = new JTextField();
201
            c.weightx = 1;
201
            c.weightx = 1;
202
            this.add(mdp, c);
202
            this.add(mdp, c);
203
 
203
 
204
            c.gridx = 0;
204
            c.gridx = 0;
205
            c.gridy++;
205
            c.gridy++;
206
            c.weightx = 0;
206
            c.weightx = 0;
207
            c.anchor = GridBagConstraints.EAST;
207
            c.anchor = GridBagConstraints.EAST;
208
            c.gridwidth = GridBagConstraints.REMAINDER;
208
            c.gridwidth = GridBagConstraints.REMAINDER;
209
            c.fill = GridBagConstraints.NONE;
209
            c.fill = GridBagConstraints.NONE;
210
            this.add(user, c);
210
            this.add(user, c);
211
            c.anchor = GridBagConstraints.WEST;
211
            c.anchor = GridBagConstraints.WEST;
212
            c.fill = GridBagConstraints.HORIZONTAL;
212
            c.fill = GridBagConstraints.HORIZONTAL;
213
            c.gridwidth = 1;
213
            c.gridwidth = 1;
214
            user.addActionListener(new ActionListener() {
214
            user.addActionListener(new ActionListener() {
215
 
215
 
216
                @Override
216
                @Override
217
                public void actionPerformed(ActionEvent e) {
217
                public void actionPerformed(ActionEvent e) {
218
                    try {
218
                    try {
219
                        if (finderPanel.getServerConfig().createUserIfNeeded(login.getText(), mdp.getText())) {
219
                        if (finderPanel.getServerConfig().createUserIfNeeded(login.getText(), mdp.getText())) {
220
                            JOptionPane.showMessageDialog(InstallationPanel.this, "L'utilisateur openconcerto a été correctement ajouté.");
220
                            JOptionPane.showMessageDialog(InstallationPanel.this, "L'utilisateur openconcerto a été correctement ajouté.");
221
                        } else {
221
                        } else {
222
                            JOptionPane.showMessageDialog(InstallationPanel.this, "L'utilisateur openconcerto existe déjà dans la base.");
222
                            JOptionPane.showMessageDialog(InstallationPanel.this, "L'utilisateur openconcerto existe déjà dans la base.");
223
                        }
223
                        }
224
                    } catch (Exception e1) {
224
                    } catch (Exception e1) {
225
                        e1.printStackTrace();
225
                        e1.printStackTrace();
226
                        JOptionPane.showMessageDialog(InstallationPanel.this, "Une erreur est survenue pendant la connexion au serveur, vérifiez vos paramètres de connexion.");
226
                        JOptionPane.showMessageDialog(InstallationPanel.this, "Une erreur est survenue pendant la connexion au serveur, vérifiez vos paramètres de connexion.");
227
                    }
227
                    }
228
                }
228
                }
229
            });
229
            });
230
 
230
 
231
            c.gridy++;
231
            c.gridy++;
232
            c.weightx = 1;
232
            c.weightx = 1;
233
            c.gridwidth = GridBagConstraints.REMAINDER;
233
            c.gridwidth = GridBagConstraints.REMAINDER;
234
            c.insets = new Insets(10, 3, 2, 2);
234
            c.insets = new Insets(10, 3, 2, 2);
235
            this.add(new JLabelBold("Paramètrages de la base de données"), c);
235
            this.add(new JLabelBold("Paramètrages de la base de données"), c);
236
            c.gridy++;
236
            c.gridy++;
237
            c.insets = DefaultGridBagConstraints.getDefaultInsets();
237
            c.insets = DefaultGridBagConstraints.getDefaultInsets();
238
            this.add(new JLabel("Création des fonctions SQL nécessaires (plpgsql)."), c);
238
            this.add(new JLabel("Création des fonctions SQL nécessaires (plpgsql)."), c);
239
            c.gridy++;
239
            c.gridy++;
240
            c.weightx = 0;
240
            c.weightx = 0;
241
            c.anchor = GridBagConstraints.EAST;
241
            c.anchor = GridBagConstraints.EAST;
242
            c.gridwidth = GridBagConstraints.REMAINDER;
242
            c.gridwidth = GridBagConstraints.REMAINDER;
243
            c.fill = GridBagConstraints.NONE;
243
            c.fill = GridBagConstraints.NONE;
244
 
244
 
245
            JButton buttonPL = new JButton("Lancer");
245
            JButton buttonPL = new JButton("Lancer");
246
            buttonPL.setOpaque(false);
246
            buttonPL.setOpaque(false);
247
            buttonPL.addActionListener(new ActionListener() {
247
            buttonPL.addActionListener(new ActionListener() {
248
 
248
 
249
                @Override
249
                @Override
250
                public void actionPerformed(ActionEvent e) {
250
                public void actionPerformed(ActionEvent e) {
251
                    if (!finderPanel.getServerConfig().getType().equals(ServerFinderConfig.POSTGRESQL)) {
251
                    if (!finderPanel.getServerConfig().getType().equals(ServerFinderConfig.POSTGRESQL)) {
252
 
252
 
253
                    } else {
253
                    } else {
254
                        final ComptaPropsConfiguration conf = ComptaPropsConfiguration.create(true);
254
                        final ComptaPropsConfiguration conf = ComptaPropsConfiguration.create(true);
255
                        try {
255
                        try {
256
                            final SQLDataSource ds = conf.getSystemRoot().getDataSource();
256
                            final SQLDataSource ds = conf.getSystemRoot().getDataSource();
257
                            // ds.execute("CREATE FUNCTION plpgsql_call_handler() RETURNS
257
                            // ds.execute("CREATE FUNCTION plpgsql_call_handler() RETURNS
258
                            // language_handler AS '$libdir/plpgsql' LANGUAGE C;"
258
                            // language_handler AS '$libdir/plpgsql' LANGUAGE C;"
259
                            // + "\n"
259
                            // + "\n"
260
                            // +
260
                            // +
261
                            // "CREATE FUNCTION plpgsql_validator(oid) RETURNS void AS
261
                            // "CREATE FUNCTION plpgsql_validator(oid) RETURNS void AS
262
                            // '$libdir/plpgsql' LANGUAGE C;"
262
                            // '$libdir/plpgsql' LANGUAGE C;"
263
                            // + "\n"
263
                            // + "\n"
264
                            // +
264
                            // +
265
                            // "CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql HANDLER
265
                            // "CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql HANDLER
266
                            // plpgsql_call_handler VALIDATOR plpgsql_validator;");
266
                            // plpgsql_call_handler VALIDATOR plpgsql_validator;");
267
                            ds.execute("CREATE LANGUAGE plpgsql;");
267
                            ds.execute("CREATE LANGUAGE plpgsql;");
268
 
268
 
269
                        } catch (Exception ex) {
269
                        } catch (Exception ex) {
270
                            System.err.println("Impossible d'ajouter le langage PLPGSQL. Peut etre est il déjà installé.");
270
                            System.err.println("Impossible d'ajouter le langage PLPGSQL. Peut etre est il déjà installé.");
271
                        }
271
                        }
272
                    }
272
                    }
273
                    JOptionPane.showMessageDialog(null, "Paramètrage terminé.");
273
                    JOptionPane.showMessageDialog(null, "Paramètrage terminé.");
274
                }
274
                }
275
            });
275
            });
276
            this.add(buttonPL, c);
276
            this.add(buttonPL, c);
277
        }
277
        }
278
        c.gridy++;
278
        c.gridy++;
279
        c.gridx = 0;
279
        c.gridx = 0;
280
        c.weightx = 1;
280
        c.weightx = 1;
281
        c.fill = GridBagConstraints.HORIZONTAL;
281
        c.fill = GridBagConstraints.HORIZONTAL;
282
        c.anchor = GridBagConstraints.WEST;
282
        c.anchor = GridBagConstraints.WEST;
283
        c.gridwidth = GridBagConstraints.REMAINDER;
283
        c.gridwidth = GridBagConstraints.REMAINDER;
284
        c.insets = new Insets(10, 3, 2, 2);
284
        c.insets = new Insets(10, 3, 2, 2);
285
        this.add(new JLabelBold("Mise à niveau de la base OpenConcerto"), c);
285
        this.add(new JLabelBold("Mise à niveau de la base OpenConcerto"), c);
286
        c.gridy++;
286
        c.gridy++;
287
        c.insets = DefaultGridBagConstraints.getDefaultInsets();
287
        c.insets = DefaultGridBagConstraints.getDefaultInsets();
288
        this.add(new JLabel("Cette opération est nécessaire à chaque mise à jour du logiciel."), c);
288
        this.add(new JLabel("Cette opération est nécessaire à chaque mise à jour du logiciel."), c);
289
        c.gridy++;
289
        c.gridy++;
290
        this.add(new JLabel("La mise à niveau peut prendre plusieurs minutes."), c);
290
        this.add(new JLabel("La mise à niveau peut prendre plusieurs minutes."), c);
291
        c.gridy++;
291
        c.gridy++;
292
        this.add(this.bar, c);
292
        this.add(this.bar, c);
293
        c.gridy++;
293
        c.gridy++;
294
        c.weightx = 0;
294
        c.weightx = 0;
295
        c.anchor = GridBagConstraints.EAST;
295
        c.anchor = GridBagConstraints.EAST;
296
        c.gridwidth = GridBagConstraints.REMAINDER;
296
        c.gridwidth = GridBagConstraints.REMAINDER;
297
        c.fill = GridBagConstraints.NONE;
297
        c.fill = GridBagConstraints.NONE;
298
 
298
 
299
        this.add(up, c);
299
        this.add(up, c);
300
 
300
 
301
        c.anchor = GridBagConstraints.WEST;
301
        c.anchor = GridBagConstraints.WEST;
302
        c.fill = GridBagConstraints.HORIZONTAL;
302
        c.fill = GridBagConstraints.HORIZONTAL;
303
 
303
 
304
        c.weightx = 1;
304
        c.weightx = 1;
305
        c.gridwidth = GridBagConstraints.REMAINDER;
305
        c.gridwidth = GridBagConstraints.REMAINDER;
306
        c.weighty = 1;
306
        c.weighty = 1;
307
        c.gridy++;
307
        c.gridy++;
308
        final JPanel comp = new JPanel();
308
        final JPanel comp = new JPanel();
309
        comp.setOpaque(false);
309
        comp.setOpaque(false);
310
        this.add(comp, c);
310
        this.add(comp, c);
311
    }
311
    }
312
 
312
 
313
 
313
 
314
    private void addArticleFournisseur(DBRoot root) {
314
    private void addArticleFournisseur(DBRoot root) {
315
        if (!root.contains("ARTICLE_FOURNISSEUR")) {
315
        if (!root.contains("ARTICLE_FOURNISSEUR")) {
316
 
316
 
317
            SQLCreateTable createBaseFamille = new SQLCreateTable(root, "FAMILLE_ARTICLE_FOURNISSEUR");
317
            SQLCreateTable createBaseFamille = new SQLCreateTable(root, "FAMILLE_ARTICLE_FOURNISSEUR");
318
            createBaseFamille.addVarCharColumn("CODE", 45);
318
            createBaseFamille.addVarCharColumn("CODE", 45);
319
            createBaseFamille.addVarCharColumn("NOM", 2048);
319
            createBaseFamille.addVarCharColumn("NOM", 2048);
320
            createBaseFamille.addForeignColumn("ID_FAMILLE_ARTICLE_FOURNISSEUR_PERE", createBaseFamille);
320
            createBaseFamille.addForeignColumn("ID_FAMILLE_ARTICLE_FOURNISSEUR_PERE", createBaseFamille);
321
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
321
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
322
 
322
 
323
            try {
323
            try {
324
                ds.execute(createBaseFamille.asString());
324
                ds.execute(createBaseFamille.asString());
325
 
325
 
326
                insertUndef(createBaseFamille);
326
                insertUndef(createBaseFamille);
327
                root.refetchTable("FAMILLE_ARTICLE_FOURNISSEUR");
327
                root.refetchTable("FAMILLE_ARTICLE_FOURNISSEUR");
328
                root.getSchema().updateVersion();
328
                root.getSchema().updateVersion();
329
            } catch (SQLException ex) {
329
            } catch (SQLException ex) {
330
                throw new IllegalStateException("Erreur lors de la création de la table FAMILLE_ARTICLE_FOURNISSEUR", ex);
330
                throw new IllegalStateException("Erreur lors de la création de la table FAMILLE_ARTICLE_FOURNISSEUR", ex);
331
            }
331
            }
332
 
332
 
333
            SQLCreateTable createBase = new SQLCreateTable(root, "ARTICLE_FOURNISSEUR");
333
            SQLCreateTable createBase = new SQLCreateTable(root, "ARTICLE_FOURNISSEUR");
334
            createBase.addVarCharColumn("CODE", 45);
334
            createBase.addVarCharColumn("CODE", 45);
335
            createBase.addVarCharColumn("CODE_BARRE", 45);
335
            createBase.addVarCharColumn("CODE_BARRE", 45);
336
            createBase.addVarCharColumn("CODE_DOUANIER", 45);
336
            createBase.addVarCharColumn("CODE_DOUANIER", 45);
337
            createBase.addVarCharColumn("NOM", 2048);
337
            createBase.addVarCharColumn("NOM", 2048);
338
            createBase.addVarCharColumn("DESCRIPTIF", 2048);
338
            createBase.addVarCharColumn("DESCRIPTIF", 2048);
339
            createBase.addVarCharColumn("INFOS", 2048);
339
            createBase.addVarCharColumn("INFOS", 2048);
340
 
340
 
341
            createBase.addColumn("PRIX_METRIQUE_HA_1", "numeric (16,6) DEFAULT 0");
341
            createBase.addColumn("PRIX_METRIQUE_HA_1", "numeric (16,6) DEFAULT 0");
342
            createBase.addColumn("PRIX_METRIQUE_HA_2", "numeric (16,8) DEFAULT 0");
342
            createBase.addColumn("PRIX_METRIQUE_HA_2", "numeric (16,8) DEFAULT 0");
343
            createBase.addColumn("PRIX_METRIQUE_HA_3", "numeric (16,8) DEFAULT 0");
343
            createBase.addColumn("PRIX_METRIQUE_HA_3", "numeric (16,8) DEFAULT 0");
344
 
344
 
345
            createBase.addColumn("PRIX_METRIQUE_VT_1", "numeric (16,8) DEFAULT 0");
345
            createBase.addColumn("PRIX_METRIQUE_VT_1", "numeric (16,8) DEFAULT 0");
346
            createBase.addColumn("PRIX_METRIQUE_VT_2", "numeric (16,8) DEFAULT 0");
346
            createBase.addColumn("PRIX_METRIQUE_VT_2", "numeric (16,8) DEFAULT 0");
347
            createBase.addColumn("PRIX_METRIQUE_VT_3", "numeric (16,8) DEFAULT 0");
347
            createBase.addColumn("PRIX_METRIQUE_VT_3", "numeric (16,8) DEFAULT 0");
348
 
348
 
349
            createBase.addForeignColumn("ID_METRIQUE_1", root.findTable("METRIQUE", true));
349
            createBase.addForeignColumn("ID_METRIQUE_1", root.findTable("METRIQUE", true));
350
            createBase.addForeignColumn("ID_METRIQUE_2", root.findTable("METRIQUE", true));
350
            createBase.addForeignColumn("ID_METRIQUE_2", root.findTable("METRIQUE", true));
351
            createBase.addForeignColumn("ID_METRIQUE_3", root.findTable("METRIQUE", true));
351
            createBase.addForeignColumn("ID_METRIQUE_3", root.findTable("METRIQUE", true));
352
 
352
 
353
            createBase.addColumn("PA_DEVISE", "numeric (16,8) DEFAULT 0");
353
            createBase.addColumn("PA_DEVISE", "numeric (16,8) DEFAULT 0");
354
            createBase.addColumn("PV_U_DEVISE", "numeric (16,8) DEFAULT 0");
354
            createBase.addColumn("PV_U_DEVISE", "numeric (16,8) DEFAULT 0");
355
            createBase.addColumn("PA_HT", "numeric (16,8) DEFAULT 0");
355
            createBase.addColumn("PA_HT", "numeric (16,8) DEFAULT 0");
356
            createBase.addColumn("PV_HT", "numeric (16,8) DEFAULT 0");
356
            createBase.addColumn("PV_HT", "numeric (16,8) DEFAULT 0");
357
            createBase.addColumn("PV_TTC", "numeric (16,2) DEFAULT 0");
357
            createBase.addColumn("PV_TTC", "numeric (16,2) DEFAULT 0");
358
 
358
 
359
            createBase.addForeignColumn("ID_TAXE", root.findTable("TAXE", true));
359
            createBase.addForeignColumn("ID_TAXE", root.findTable("TAXE", true));
360
            createBase.addForeignColumn("ID_FAMILLE_ARTICLE_FOURNISSEUR", root.findTable("FAMILLE_ARTICLE_FOURNISSEUR", true));
360
            createBase.addForeignColumn("ID_FAMILLE_ARTICLE_FOURNISSEUR", root.findTable("FAMILLE_ARTICLE_FOURNISSEUR", true));
361
            createBase.addForeignColumn("ID_MODE_VENTE_ARTICLE", root.findTable("MODE_VENTE_ARTICLE", true));
361
            createBase.addForeignColumn("ID_MODE_VENTE_ARTICLE", root.findTable("MODE_VENTE_ARTICLE", true));
362
            createBase.addForeignColumn("ID_FOURNISSEUR", root.findTable("FOURNISSEUR", true));
362
            createBase.addForeignColumn("ID_FOURNISSEUR", root.findTable("FOURNISSEUR", true));
363
            createBase.addForeignColumn("ID_PAYS", root.findTable("PAYS", true));
363
            createBase.addForeignColumn("ID_PAYS", root.findTable("PAYS", true));
364
            createBase.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
364
            createBase.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
365
            createBase.addForeignColumn("ID_DEVISE_HA", root.findTable("DEVISE", true));
365
            createBase.addForeignColumn("ID_DEVISE_HA", root.findTable("DEVISE", true));
366
            createBase.addForeignColumn("ID_UNITE_VENTE", root.findTable("UNITE_VENTE", true));
366
            createBase.addForeignColumn("ID_UNITE_VENTE", root.findTable("UNITE_VENTE", true));
367
            createBase.addForeignColumn("ID_COMPTE_PCE", root.findTable("COMPTE_PCE", true));
367
            createBase.addForeignColumn("ID_COMPTE_PCE", root.findTable("COMPTE_PCE", true));
368
            createBase.addForeignColumn("ID_COMPTE_PCE_ACHAT", root.findTable("COMPTE_PCE", true));
368
            createBase.addForeignColumn("ID_COMPTE_PCE_ACHAT", root.findTable("COMPTE_PCE", true));
369
            createBase.addForeignColumn("ID_ARTICLE", root.findTable("ARTICLE", true));
369
            createBase.addForeignColumn("ID_ARTICLE", root.findTable("ARTICLE", true));
370
 
370
 
371
            createBase.addColumn("POIDS", "real DEFAULT 0");
371
            createBase.addColumn("POIDS", "real DEFAULT 0");
372
            createBase.addColumn("VALEUR_METRIQUE_1", "real DEFAULT 0");
372
            createBase.addColumn("VALEUR_METRIQUE_1", "real DEFAULT 0");
373
            createBase.addColumn("VALEUR_METRIQUE_2", "real DEFAULT 0");
373
            createBase.addColumn("VALEUR_METRIQUE_2", "real DEFAULT 0");
374
            createBase.addColumn("VALEUR_METRIQUE_3", "real DEFAULT 0");
374
            createBase.addColumn("VALEUR_METRIQUE_3", "real DEFAULT 0");
375
            createBase.addBooleanColumn("SERVICE", Boolean.FALSE, false);
375
            createBase.addBooleanColumn("SERVICE", Boolean.FALSE, false);
376
            createBase.addBooleanColumn("OBSOLETE", Boolean.FALSE, false);
376
            createBase.addBooleanColumn("OBSOLETE", Boolean.FALSE, false);
377
            createBase.addBooleanColumn("GESTION_STOCK", Boolean.FALSE, false);
377
            createBase.addBooleanColumn("GESTION_STOCK", Boolean.FALSE, false);
378
            createBase.addIntegerColumn("QTE_ACHAT", 1);
378
            createBase.addIntegerColumn("QTE_ACHAT", 1);
379
            createBase.addIntegerColumn("QTE_MIN", 1);
379
            createBase.addIntegerColumn("QTE_MIN", 1);
380
 
380
 
381
            try {
381
            try {
382
                ds.execute(createBase.asString());
382
                ds.execute(createBase.asString());
383
 
383
 
384
                insertUndef(createBase);
384
                insertUndef(createBase);
385
                root.refetchTable("ARTICLE_FOURNISSEUR");
385
                root.refetchTable("ARTICLE_FOURNISSEUR");
386
                root.getSchema().updateVersion();
386
                root.getSchema().updateVersion();
387
            } catch (SQLException ex) {
387
            } catch (SQLException ex) {
388
                throw new IllegalStateException("Erreur lors de la création de la table ARTICLE_FOURNISSEUR", ex);
388
                throw new IllegalStateException("Erreur lors de la création de la table ARTICLE_FOURNISSEUR", ex);
389
            }
389
            }
390
        }
390
        }
391
    }
391
    }
392
 
392
 
393
    private void addContact(DBRoot root) throws SQLException {
393
    private void addContact(DBRoot root) throws SQLException {
394
 
394
 
395
        List<String> tables = Arrays.asList("AVOIR_CLIENT", "DEVIS", "BON_DE_LIVRAISON", "COMMANDE_CLIENT", "SAISIE_VENTE_FACTURE");
395
        List<String> tables = Arrays.asList("AVOIR_CLIENT", "DEVIS", "BON_DE_LIVRAISON", "COMMANDE_CLIENT", "SAISIE_VENTE_FACTURE");
396
        final SQLTable tableContact = root.findTable("CONTACT");
396
        final SQLTable tableContact = root.findTable("CONTACT");
397
        final SQLTable tableDpt = root.findTable("CLIENT_DEPARTEMENT");
397
        final SQLTable tableDpt = root.findTable("CLIENT_DEPARTEMENT");
398
        final SQLDataSource dataSource = root.getDBSystemRoot().getDataSource();
398
        final SQLDataSource dataSource = root.getDBSystemRoot().getDataSource();
399
        for (String tableName : tables) {
399
        for (String tableName : tables) {
400
            boolean update = false;
400
            boolean update = false;
401
            final SQLTable table = root.getTable(tableName);
401
            final SQLTable table = root.getTable(tableName);
402
            final AlterTable alterEcheance = new AlterTable(table);
402
            final AlterTable alterEcheance = new AlterTable(table);
403
 
403
 
404
            if (!table.contains("ID_CONTACT")) {
404
            if (!table.contains("ID_CONTACT")) {
405
                alterEcheance.addForeignColumn("ID_CONTACT", tableContact);
405
                alterEcheance.addForeignColumn("ID_CONTACT", tableContact);
406
                update = true;
406
                update = true;
407
            }
407
            }
408
 
408
 
409
            if (!table.contains("ID_CLIENT_DEPARTEMENT")) {
409
            if (!table.contains("ID_CLIENT_DEPARTEMENT")) {
410
                alterEcheance.addForeignColumn("ID_CLIENT_DEPARTEMENT", tableDpt);
410
                alterEcheance.addForeignColumn("ID_CLIENT_DEPARTEMENT", tableDpt);
411
                update = true;
411
                update = true;
412
            }
412
            }
413
            if (update) {
413
            if (update) {
414
                dataSource.execute(alterEcheance.asString());
414
                dataSource.execute(alterEcheance.asString());
415
                table.getSchema().updateVersion();
415
                table.getSchema().updateVersion();
416
            }
416
            }
417
 
417
 
418
        }
418
        }
419
    }
419
    }
420
 
420
 
421
    private void addForeignKeyFactureOnEcheance(DBRoot root) {
421
    private void addForeignKeyFactureOnEcheance(DBRoot root) {
422
 
422
 
423
        final SQLTable tableEch = root.getTable("ECHEANCE_CLIENT");
423
        final SQLTable tableEch = root.getTable("ECHEANCE_CLIENT");
424
        if (!tableEch.contains("ID_SAISIE_VENTE_FACTURE")) {
424
        if (!tableEch.contains("ID_SAISIE_VENTE_FACTURE")) {
425
            final SQLTable tableFacture = root.getTable("SAISIE_VENTE_FACTURE");
425
            final SQLTable tableFacture = root.getTable("SAISIE_VENTE_FACTURE");
426
            final SQLTable tableMvt = root.getTable("MOUVEMENT");
426
            final SQLTable tableMvt = root.getTable("MOUVEMENT");
427
            String query = "no query";
427
            String query = "no query";
428
            try {
428
            try {
429
                final SQLDataSource dataSource = root.getDBSystemRoot().getDataSource();
429
                final SQLDataSource dataSource = root.getDBSystemRoot().getDataSource();
430
                final AlterTable alterEcheance = new AlterTable(tableEch);
430
                final AlterTable alterEcheance = new AlterTable(tableEch);
431
                alterEcheance.addForeignColumn("ID_SAISIE_VENTE_FACTURE", tableFacture);
431
                alterEcheance.addForeignColumn("ID_SAISIE_VENTE_FACTURE", tableFacture);
432
                dataSource.execute(alterEcheance.asString());
432
                dataSource.execute(alterEcheance.asString());
433
                tableEch.getSchema().updateVersion();
433
                tableEch.getSchema().updateVersion();
434
                tableEch.fetchFields();
434
                tableEch.fetchFields();
435
 
435
 
436
                // select MOUVEMENT whose parent has a source FACTURE
436
                // select MOUVEMENT whose parent has a source FACTURE
437
                final SQLSelect selMvt = new SQLSelect();
437
                final SQLSelect selMvt = new SQLSelect();
438
                final AliasedTable refChild = new AliasedTable(tableMvt, "m1");
438
                final AliasedTable refChild = new AliasedTable(tableMvt, "m1");
439
                final AliasedTable refParent = new AliasedTable(tableMvt, "m2");
439
                final AliasedTable refParent = new AliasedTable(tableMvt, "m2");
440
                selMvt.addSelect(refParent.getField("IDSOURCE"));
440
                selMvt.addSelect(refParent.getField("IDSOURCE"));
441
                selMvt.addBackwardJoin("INNER", refChild.getField("ID_MOUVEMENT_PERE"), refParent.getAlias());
441
                selMvt.addBackwardJoin("INNER", refChild.getField("ID_MOUVEMENT_PERE"), refParent.getAlias());
442
                selMvt.addSelect(refChild.getKey());
442
                selMvt.addSelect(refChild.getKey());
443
                selMvt.setWhere(new Where(refParent.getField("SOURCE"), "=", tableFacture.getName()));
443
                selMvt.setWhere(new Where(refParent.getField("SOURCE"), "=", tableFacture.getName()));
444
 
444
 
445
                final UpdateBuilder build = new UpdateBuilder(tableEch);
445
                final UpdateBuilder build = new UpdateBuilder(tableEch);
446
                build.addVirtualJoin("( " + selMvt.asString() + " )", "mvt", false, tableMvt.getKey().getName(), "ID_MOUVEMENT");
446
                build.addVirtualJoin("( " + selMvt.asString() + " )", "mvt", false, tableMvt.getKey().getName(), "ID_MOUVEMENT");
447
                build.setFromVirtualJoinField("ID_SAISIE_VENTE_FACTURE", "mvt", "IDSOURCE");
447
                build.setFromVirtualJoinField("ID_SAISIE_VENTE_FACTURE", "mvt", "IDSOURCE");
448
                query = build.asString();
448
                query = build.asString();
449
                dataSource.execute(query);
449
                dataSource.execute(query);
450
            } catch (SQLException ex) {
450
            } catch (SQLException ex) {
451
                Log.get().severe("Error on query :" + query);
451
                Log.get().severe("Error on query :" + query);
452
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table ECHEANCE_CLIENT", ex);
452
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table ECHEANCE_CLIENT", ex);
453
            }
453
            }
454
        }
454
        }
455
    }
455
    }
456
 
456
 
457
    private void addFieldForPartialInvoice(DBRoot root) throws SQLException {
457
    private void addFieldForPartialInvoice(DBRoot root) throws SQLException {
458
        final SQLTable tableVF = root.getTable("SAISIE_VENTE_FACTURE");
458
        final SQLTable tableVF = root.getTable("SAISIE_VENTE_FACTURE");
459
        AlterTable alter = new AlterTable(tableVF);
459
        AlterTable alter = new AlterTable(tableVF);
460
        boolean doAlter = false;
460
        boolean doAlter = false;
461
        if (!tableVF.contains("POURCENT_FACTURABLE")) {
461
        if (!tableVF.contains("POURCENT_FACTURABLE")) {
462
            alter.addColumn("POURCENT_FACTURABLE", "numeric (16,8)");
462
            alter.addColumn("POURCENT_FACTURABLE", "numeric (16,8)");
463
            doAlter = true;
463
            doAlter = true;
464
        }
464
        }
465
        if (!tableVF.contains("MONTANT_FACTURABLE")) {
465
        if (!tableVF.contains("MONTANT_FACTURABLE")) {
466
            alter.addColumn("MONTANT_FACTURABLE", "numeric (16,8)");
466
            alter.addColumn("MONTANT_FACTURABLE", "numeric (16,8)");
467
            doAlter = true;
467
            doAlter = true;
468
        }
468
        }
469
 
469
 
470
        if (!tableVF.contains("SOLDE")) {
470
        if (!tableVF.contains("SOLDE")) {
471
            alter.addColumn("SOLDE", "boolean DEFAULT false");
471
            alter.addColumn("SOLDE", "boolean DEFAULT false");
472
            doAlter = true;
472
            doAlter = true;
473
        }
473
        }
474
 
474
 
475
        if (!tableVF.contains("PARTIAL")) {
475
        if (!tableVF.contains("PARTIAL")) {
476
            alter.addColumn("PARTIAL", "boolean DEFAULT false");
476
            alter.addColumn("PARTIAL", "boolean DEFAULT false");
477
            doAlter = true;
477
            doAlter = true;
478
        }
478
        }
479
 
479
 
480
        if (doAlter) {
480
        if (doAlter) {
481
            root.getDBSystemRoot().getDataSource().execute(alter.asString());
481
            root.getDBSystemRoot().getDataSource().execute(alter.asString());
482
            root.refetchTable(tableVF.getName());
482
            root.refetchTable(tableVF.getName());
483
        }
483
        }
484
 
484
 
485
        // ELT
485
        // ELT
486
        final SQLTable tableVFElt = root.getTable("SAISIE_VENTE_FACTURE_ELEMENT");
486
        final SQLTable tableVFElt = root.getTable("SAISIE_VENTE_FACTURE_ELEMENT");
487
        AlterTable alterElt = new AlterTable(tableVFElt);
487
        AlterTable alterElt = new AlterTable(tableVFElt);
488
        boolean doAlterElt = false;
488
        boolean doAlterElt = false;
489
        if (!tableVFElt.contains("MONTANT_FACTURABLE")) {
489
        if (!tableVFElt.contains("MONTANT_FACTURABLE")) {
490
            alterElt.addColumn("MONTANT_FACTURABLE", "numeric (16,8)");
490
            alterElt.addColumn("MONTANT_FACTURABLE", "numeric (16,8)");
491
            doAlterElt = true;
491
            doAlterElt = true;
492
        }
492
        }
493
 
493
 
494
        if (!tableVFElt.contains("POURCENT_FACTURABLE")) {
494
        if (!tableVFElt.contains("POURCENT_FACTURABLE")) {
495
            alterElt.addColumn("POURCENT_FACTURABLE", "numeric (16,8)");
495
            alterElt.addColumn("POURCENT_FACTURABLE", "numeric (16,8)");
496
            doAlterElt = true;
496
            doAlterElt = true;
497
        }
497
        }
498
 
498
 
499
        if (doAlterElt) {
499
        if (doAlterElt) {
500
            root.getDBSystemRoot().getDataSource().execute(alterElt.asString());
500
            root.getDBSystemRoot().getDataSource().execute(alterElt.asString());
501
            root.refetchTable(tableVFElt.getName());
501
            root.refetchTable(tableVFElt.getName());
502
        }
502
        }
503
 
503
 
504
    }
504
    }
505
 
505
 
506
    private void createAssocAnalytique(DBRoot root, ComptaPropsConfiguration conf) {
506
    private void createAssocAnalytique(DBRoot root, ComptaPropsConfiguration conf) {
507
 
507
 
508
        if (!root.contains("ASSOCIATION_ANALYTIQUE")) {
508
        if (!root.contains("ASSOCIATION_ANALYTIQUE")) {
509
 
509
 
510
            SQLCreateTable createAssoc = new SQLCreateTable(root, "ASSOCIATION_ANALYTIQUE");
510
            SQLCreateTable createAssoc = new SQLCreateTable(root, "ASSOCIATION_ANALYTIQUE");
511
            createAssoc.addForeignColumn("ID_ECRITURE", root.findTable("ECRITURE", true));
511
            createAssoc.addForeignColumn("ID_ECRITURE", root.findTable("ECRITURE", true));
512
            createAssoc.addForeignColumn("ID_SAISIE_KM_ELEMENT", root.findTable("SAISIE_KM_ELEMENT", true));
512
            createAssoc.addForeignColumn("ID_SAISIE_KM_ELEMENT", root.findTable("SAISIE_KM_ELEMENT", true));
513
            createAssoc.addForeignColumn("ID_POSTE_ANALYTIQUE", root.findTable("POSTE_ANALYTIQUE", true));
513
            createAssoc.addForeignColumn("ID_POSTE_ANALYTIQUE", root.findTable("POSTE_ANALYTIQUE", true));
514
            createAssoc.addColumn("POURCENT", "numeric (16,8) DEFAULT 100");
514
            createAssoc.addColumn("POURCENT", "numeric (16,8) DEFAULT 100");
515
            createAssoc.addColumn("MONTANT", "bigInt DEFAULT 0");
515
            createAssoc.addColumn("MONTANT", "bigInt DEFAULT 0");
516
            createAssoc.addBooleanColumn("GESTION_AUTO", false, false);
516
            createAssoc.addBooleanColumn("GESTION_AUTO", false, false);
517
 
517
 
518
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
518
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
519
 
519
 
520
            try {
520
            try {
521
                ds.execute(createAssoc.asString());
521
                ds.execute(createAssoc.asString());
522
 
522
 
523
                insertUndef(createAssoc);
523
                insertUndef(createAssoc);
524
                root.refetchTable("ASSOCIATION_ANALYTIQUE");
524
                root.refetchTable("ASSOCIATION_ANALYTIQUE");
525
                root.getSchema().updateVersion();
525
                root.getSchema().updateVersion();
526
            } catch (SQLException ex) {
526
            } catch (SQLException ex) {
527
                throw new IllegalStateException("Erreur lors de la création de la table ASSOCIATION_ANALYTIQUE", ex);
527
                throw new IllegalStateException("Erreur lors de la création de la table ASSOCIATION_ANALYTIQUE", ex);
528
            }
528
            }
529
 
529
 
530
        }
530
        }
531
        SQLTable tablePoste = root.getTable("POSTE_ANALYTIQUE");
531
        SQLTable tablePoste = root.getTable("POSTE_ANALYTIQUE");
532
        if (!tablePoste.contains("DEFAULT")) {
532
        if (!tablePoste.contains("DEFAULT")) {
533
            AlterTable a = new AlterTable(tablePoste);
533
            AlterTable a = new AlterTable(tablePoste);
534
            a.addBooleanColumn("DEFAULT", Boolean.FALSE, false);
534
            a.addBooleanColumn("DEFAULT", Boolean.FALSE, false);
535
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
535
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
536
            try {
536
            try {
537
                ds.execute(a.asString());
537
                ds.execute(a.asString());
538
                root.refetchTable("POSTE_ANALYTIQUE");
538
                root.refetchTable("POSTE_ANALYTIQUE");
539
                root.getSchema().updateVersion();
539
                root.getSchema().updateVersion();
540
            } catch (SQLException ex) {
540
            } catch (SQLException ex) {
541
                throw new IllegalStateException("Erreur lors de la création du DEFAULT sur la table POSTE_ANALYTIQUE", ex);
541
                throw new IllegalStateException("Erreur lors de la création du DEFAULT sur la table POSTE_ANALYTIQUE", ex);
542
            }
542
            }
543
        }
543
        }
544
    }
544
    }
545
 
545
 
546
    private void updateStock(DBRoot root) throws SQLException {
546
    private void updateStock(DBRoot root) throws SQLException {
547
 
547
 
548
        final SQLTable tableStock = root.getTable("STOCK");
548
        final SQLTable tableStock = root.getTable("STOCK");
549
        final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
549
        final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
550
        if (!tableStock.contains("QTE_RECEPT_ATTENTE")) {
550
        if (!tableStock.contains("QTE_RECEPT_ATTENTE")) {
551
 
551
 
552
            try {
552
            try {
553
 
553
 
554
                AlterTable alterElt = new AlterTable(root.getTable("STOCK"));
554
                AlterTable alterElt = new AlterTable(root.getTable("STOCK"));
555
                alterElt.addColumn("QTE_RECEPT_ATTENTE", "real DEFAULT 0");
555
                alterElt.addColumn("QTE_RECEPT_ATTENTE", "real DEFAULT 0");
556
                alterElt.addColumn("QTE_LIV_ATTENTE", "real DEFAULT 0");
556
                alterElt.addColumn("QTE_LIV_ATTENTE", "real DEFAULT 0");
557
                ds.execute(alterElt.asString());
557
                ds.execute(alterElt.asString());
558
 
558
 
559
                AlterTable alterMvt = new AlterTable(root.getTable("MOUVEMENT_STOCK"));
559
                AlterTable alterMvt = new AlterTable(root.getTable("MOUVEMENT_STOCK"));
560
                alterMvt.addBooleanColumn("REEL", Boolean.TRUE, false);
560
                alterMvt.addBooleanColumn("REEL", Boolean.TRUE, false);
561
 
561
 
562
                ds.execute(alterMvt.asString());
562
                ds.execute(alterMvt.asString());
563
 
563
 
564
                root.getSchema().updateVersion();
564
                root.getSchema().updateVersion();
565
 
565
 
566
            } catch (SQLException ex) {
566
            } catch (SQLException ex) {
567
                throw new IllegalStateException("Erreur lors de la mise à jour des tables de stock", ex);
567
                throw new IllegalStateException("Erreur lors de la mise à jour des tables de stock", ex);
568
            }
568
            }
569
 
569
 
570
        }
570
        }
571
        // if (!root.contains("ARTICLE_ELEMENT")) {
571
        // if (!root.contains("ARTICLE_ELEMENT")) {
572
        // final SQLCreateTable createTable = new SQLCreateTable(root, "ARTICLE_ELEMENT");
572
        // final SQLCreateTable createTable = new SQLCreateTable(root, "ARTICLE_ELEMENT");
573
        // createTable.addForeignColumn("ARTICLE");
573
        // createTable.addForeignColumn("ARTICLE");
574
        // createTable.addForeignColumn("ID_ARTICLE_PARENT", root.getTable("ARTICLE"));
574
        // createTable.addForeignColumn("ID_ARTICLE_PARENT", root.getTable("ARTICLE"));
575
        // createTable.addIntegerColumn("QTE", 1);
575
        // createTable.addIntegerColumn("QTE", 1);
576
        // createTable.addDecimalColumn("QTE_UNITAIRE", 16, 6, BigDecimal.valueOf(1), false);
576
        // createTable.addDecimalColumn("QTE_UNITAIRE", 16, 6, BigDecimal.valueOf(1), false);
577
        // createTable.addForeignColumn("UNITE_VENTE");
577
        // createTable.addForeignColumn("UNITE_VENTE");
578
        // insertUndef(createTable);
578
        // insertUndef(createTable);
579
        // ds.execute(createTable.asString());
579
        // ds.execute(createTable.asString());
580
        //
580
        //
581
        // root.getSchema().updateVersion();
581
        // root.getSchema().updateVersion();
582
        // root.refetchTable("ARTICLE_ELEMENT");
582
        // root.refetchTable("ARTICLE_ELEMENT");
583
        //
583
        //
584
        // }
584
        // }
585
        //
585
        //
586
        // if (!root.getTable("ARTICLE").contains("COMPOSED")) {
586
        // if (!root.getTable("ARTICLE").contains("COMPOSED")) {
587
        // AlterTable alterMvt = new AlterTable(root.getTable("ARTICLE"));
587
        // AlterTable alterMvt = new AlterTable(root.getTable("ARTICLE"));
588
        // alterMvt.addBooleanColumn("COMPOSED", Boolean.FALSE, false);
588
        // alterMvt.addBooleanColumn("COMPOSED", Boolean.FALSE, false);
589
        //
589
        //
590
        // ds.execute(alterMvt.asString());
590
        // ds.execute(alterMvt.asString());
591
        //
591
        //
592
        // root.getSchema().updateVersion();
592
        // root.getSchema().updateVersion();
593
        // }
593
        // }
594
 
594
 
595
    }
595
    }
596
 
596
 
597
    private void createBanque(DBRoot root) throws SQLException {
597
    private void createBanque(DBRoot root) throws SQLException {
598
 
598
 
599
        // Création de la table
599
        // Création de la table
600
        if (!root.contains("BANQUE") && !root.contains("BANQUE_POLE_PRODUIT")) {
600
        if (!root.contains("BANQUE") && !root.contains("BANQUE_POLE_PRODUIT")) {
601
 
601
 
602
            SQLCreateTable createBanque = new SQLCreateTable(root, "BANQUE");
602
            SQLCreateTable createBanque = new SQLCreateTable(root, "BANQUE");
603
            createBanque.addForeignColumn("ID_JOURNAL", root.findTable("JOURNAL", true));
603
            createBanque.addForeignColumn("ID_JOURNAL", root.findTable("JOURNAL", true));
604
            createBanque.addVarCharColumn("INFOS", 2048);
604
            createBanque.addVarCharColumn("INFOS", 2048);
605
            createBanque.addVarCharColumn("NUMERO_RUE", 45);
605
            createBanque.addVarCharColumn("NUMERO_RUE", 45);
606
            createBanque.addVarCharColumn("RUE", 256);
606
            createBanque.addVarCharColumn("RUE", 256);
607
            createBanque.addVarCharColumn("IBAN", 256);
607
            createBanque.addVarCharColumn("IBAN", 256);
608
            createBanque.addVarCharColumn("BIC", 256);
608
            createBanque.addVarCharColumn("BIC", 256);
609
            createBanque.addVarCharColumn("VOIE", 256);
609
            createBanque.addVarCharColumn("VOIE", 256);
610
            createBanque.addVarCharColumn("VILLE", 256);
610
            createBanque.addVarCharColumn("VILLE", 256);
611
            createBanque.addVarCharColumn("NOM", 256);
611
            createBanque.addVarCharColumn("NOM", 256);
612
            createBanque.addVarCharColumn("DOMICILIATION", 256);
612
            createBanque.addVarCharColumn("DOMICILIATION", 256);
613
            createBanque.addVarCharColumn("CODE", 256);
613
            createBanque.addVarCharColumn("CODE", 256);
614
            createBanque.addBooleanColumn("AFFACTURAGE", Boolean.FALSE, false);
614
            createBanque.addBooleanColumn("AFFACTURAGE", Boolean.FALSE, false);
615
            createBanque.addForeignColumn("ID_COMPTE_PCE", root.findTable("COMPTE_PCE", true));
615
            createBanque.addForeignColumn("ID_COMPTE_PCE", root.findTable("COMPTE_PCE", true));
616
 
616
 
617
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
617
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
618
 
618
 
619
            try {
619
            try {
620
                ds.execute(createBanque.asString());
620
                ds.execute(createBanque.asString());
621
 
621
 
622
                insertUndef(createBanque);
622
                insertUndef(createBanque);
623
                root.refetchTable("BANQUE");
623
                root.refetchTable("BANQUE");
624
                root.getSchema().updateVersion();
624
                root.getSchema().updateVersion();
625
 
625
 
626
            } catch (SQLException ex) {
626
            } catch (SQLException ex) {
627
                throw new IllegalStateException("Erreur lors de la création de la table BANQUE", ex);
627
                throw new IllegalStateException("Erreur lors de la création de la table BANQUE", ex);
628
            }
628
            }
629
        }
629
        }
630
 
630
 
631
        // Création des foreignkeys
631
        // Création des foreignkeys
632
        {
632
        {
633
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
633
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
634
            List<String> tablesWithBanque = Arrays.asList("MODE_REGLEMENT", "CHEQUE_A_ENCAISSER", "CHEQUE_FOURNISSEUR");
634
            List<String> tablesWithBanque = Arrays.asList("MODE_REGLEMENT", "CHEQUE_A_ENCAISSER", "CHEQUE_FOURNISSEUR");
635
 
635
 
636
            for (String string : tablesWithBanque) {
636
            for (String string : tablesWithBanque) {
637
 
637
 
638
                final SQLTable table = root.getTable(string);
638
                final SQLTable table = root.getTable(string);
639
                if (!table.contains("ID_BANQUE") && !table.contains("ID_BANQUE_POLE_PRODUIT")) {
639
                if (!table.contains("ID_BANQUE") && !table.contains("ID_BANQUE_POLE_PRODUIT")) {
640
                    String tableName = (table.contains("ID_BANQUE_PRODUIT")) ? "BANQUE_POLE_PRODUIT" : "BANQUE";
640
                    String tableName = (table.contains("ID_BANQUE_PRODUIT")) ? "BANQUE_POLE_PRODUIT" : "BANQUE";
641
                    AlterTable alterElt = new AlterTable(table);
641
                    AlterTable alterElt = new AlterTable(table);
642
                    alterElt.addForeignColumn("ID_" + tableName, root.getTable(tableName));
642
                    alterElt.addForeignColumn("ID_" + tableName, root.getTable(tableName));
643
                    ds.execute(alterElt.asString());
643
                    ds.execute(alterElt.asString());
644
                    root.refetchTable(string);
644
                    root.refetchTable(string);
645
                    root.getSchema().updateVersion();
645
                    root.getSchema().updateVersion();
646
                }
646
                }
647
            }
647
            }
648
        }
648
        }
649
 
649
 
650
    }
650
    }
651
 
651
 
652
    private void createFactureFournisseur(DBRoot root) throws SQLException {
652
    private void createFactureFournisseur(DBRoot root) throws SQLException {
653
        boolean refetchRoot = false;
653
        boolean refetchRoot = false;
654
        if (!root.contains("FACTURE_FOURNISSEUR")) {
654
        if (!root.contains("FACTURE_FOURNISSEUR")) {
655
 
655
 
656
            SQLCreateTable createFactureF = new SQLCreateTable(root, "FACTURE_FOURNISSEUR");
656
            SQLCreateTable createFactureF = new SQLCreateTable(root, "FACTURE_FOURNISSEUR");
657
            createFactureF.addVarCharColumn("NOM", 256);
657
            createFactureF.addVarCharColumn("NOM", 256);
658
            createFactureF.addVarCharColumn("NUMERO", 45);
658
            createFactureF.addVarCharColumn("NUMERO", 45);
659
            createFactureF.addVarCharColumn("INFOS", 2048);
659
            createFactureF.addVarCharColumn("INFOS", 2048);
660
            createFactureF.addColumn("DATE", "date");
660
            createFactureF.addColumn("DATE", "date");
661
            createFactureF.addForeignColumn("FOURNISSEUR");
661
            createFactureF.addForeignColumn("FOURNISSEUR");
662
            createFactureF.addForeignColumn("AVOIR_FOURNISSEUR");
662
            createFactureF.addForeignColumn("AVOIR_FOURNISSEUR");
663
            createFactureF.addForeignColumn("COMPTE_PCE");
663
            createFactureF.addForeignColumn("COMPTE_PCE");
664
            createFactureF.addForeignColumn("COMMERCIAL");
664
            createFactureF.addForeignColumn("COMMERCIAL");
665
            createFactureF.addForeignColumn("MODE_REGLEMENT");
665
            createFactureF.addForeignColumn("MODE_REGLEMENT");
666
            createFactureF.addForeignColumn("MOUVEMENT");
666
            createFactureF.addForeignColumn("MOUVEMENT");
667
            createFactureF.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
667
            createFactureF.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
668
            createFactureF.addColumn("T_HT", "bigint DEFAULT 0");
668
            createFactureF.addColumn("T_HT", "bigint DEFAULT 0");
669
            createFactureF.addColumn("T_TVA", "bigint DEFAULT 0");
669
            createFactureF.addColumn("T_TVA", "bigint DEFAULT 0");
670
            createFactureF.addColumn("T_TTC", "bigint DEFAULT 0");
670
            createFactureF.addColumn("T_TTC", "bigint DEFAULT 0");
671
            createFactureF.addColumn("T_SERVICE", "bigint DEFAULT 0");
671
            createFactureF.addColumn("T_SERVICE", "bigint DEFAULT 0");
672
            createFactureF.addColumn("T_DEVISE", "bigint DEFAULT 0");
672
            createFactureF.addColumn("T_DEVISE", "bigint DEFAULT 0");
673
            createFactureF.addColumn("T_POIDS", "real DEFAULT 0");
673
            createFactureF.addColumn("T_POIDS", "real DEFAULT 0");
674
 
674
 
675
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
675
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
676
 
676
 
677
            try {
677
            try {
678
                ds.execute(createFactureF.asString());
678
                ds.execute(createFactureF.asString());
679
                insertUndef(createFactureF);
679
                insertUndef(createFactureF);
680
                root.getSchema().updateVersion();
680
                root.getSchema().updateVersion();
681
                root.refetchTable("FACTURE_FOURNISSEUR");
681
                root.refetchTable("FACTURE_FOURNISSEUR");
682
                refetchRoot = true;
682
                refetchRoot = true;
683
            } catch (SQLException ex) {
683
            } catch (SQLException ex) {
684
                throw new IllegalStateException("Erreur lors de la création de la table FACTURE_FOURNISSEUR", ex);
684
                throw new IllegalStateException("Erreur lors de la création de la table FACTURE_FOURNISSEUR", ex);
685
            }
685
            }
686
 
686
 
687
        }
687
        }
688
 
688
 
689
        if (!root.contains("FACTURE_FOURNISSEUR_ELEMENT")) {
689
        if (!root.contains("FACTURE_FOURNISSEUR_ELEMENT")) {
690
 
690
 
691
            SQLCreateTable createFactureF = new SQLCreateTable(root, "FACTURE_FOURNISSEUR_ELEMENT");
691
            SQLCreateTable createFactureF = new SQLCreateTable(root, "FACTURE_FOURNISSEUR_ELEMENT");
692
 
692
 
693
            createFactureF.addDecimalColumn("PRIX_METRIQUE_HA_1", 16, 6, BigDecimal.ZERO, false);
693
            createFactureF.addDecimalColumn("PRIX_METRIQUE_HA_1", 16, 6, BigDecimal.ZERO, false);
694
            createFactureF.addDecimalColumn("PRIX_METRIQUE_HA_2", 16, 6, BigDecimal.ZERO, false);
694
            createFactureF.addDecimalColumn("PRIX_METRIQUE_HA_2", 16, 6, BigDecimal.ZERO, false);
695
            createFactureF.addDecimalColumn("PRIX_METRIQUE_HA_3", 16, 6, BigDecimal.ZERO, false);
695
            createFactureF.addDecimalColumn("PRIX_METRIQUE_HA_3", 16, 6, BigDecimal.ZERO, false);
696
            createFactureF.addDecimalColumn("PRIX_METRIQUE_VT_1", 16, 6, BigDecimal.ZERO, false);
696
            createFactureF.addDecimalColumn("PRIX_METRIQUE_VT_1", 16, 6, BigDecimal.ZERO, false);
697
            createFactureF.addDecimalColumn("PRIX_METRIQUE_VT_2", 16, 6, BigDecimal.ZERO, false);
697
            createFactureF.addDecimalColumn("PRIX_METRIQUE_VT_2", 16, 6, BigDecimal.ZERO, false);
698
            createFactureF.addDecimalColumn("PRIX_METRIQUE_VT_3", 16, 6, BigDecimal.ZERO, false);
698
            createFactureF.addDecimalColumn("PRIX_METRIQUE_VT_3", 16, 6, BigDecimal.ZERO, false);
699
            createFactureF.addDecimalColumn("T_PV_HT", 16, 6, BigDecimal.ZERO, false);
699
            createFactureF.addDecimalColumn("T_PV_HT", 16, 6, BigDecimal.ZERO, false);
700
            createFactureF.addDecimalColumn("T_PA_HT", 16, 6, BigDecimal.ZERO, false);
700
            createFactureF.addDecimalColumn("T_PA_HT", 16, 6, BigDecimal.ZERO, false);
701
            createFactureF.addDecimalColumn("PV_HT", 16, 6, BigDecimal.ZERO, false);
701
            createFactureF.addDecimalColumn("PV_HT", 16, 6, BigDecimal.ZERO, false);
702
            createFactureF.addDecimalColumn("PA_HT", 16, 6, BigDecimal.ZERO, false);
702
            createFactureF.addDecimalColumn("PA_HT", 16, 6, BigDecimal.ZERO, false);
703
            createFactureF.addDecimalColumn("T_PV_TTC", 16, 6, BigDecimal.ZERO, false);
703
            createFactureF.addDecimalColumn("T_PV_TTC", 16, 6, BigDecimal.ZERO, false);
704
            createFactureF.addDecimalColumn("T_PA_TTC", 16, 6, BigDecimal.ZERO, false);
704
            createFactureF.addDecimalColumn("T_PA_TTC", 16, 6, BigDecimal.ZERO, false);
705
            createFactureF.addDecimalColumn("QTE_UNITAIRE", 16, 6, BigDecimal.ZERO, false);
705
            createFactureF.addDecimalColumn("QTE_UNITAIRE", 16, 6, BigDecimal.ZERO, false);
706
            createFactureF.addDecimalColumn("PA_DEVISE_T", 16, 6, BigDecimal.ZERO, false);
706
            createFactureF.addDecimalColumn("PA_DEVISE_T", 16, 6, BigDecimal.ZERO, false);
707
            createFactureF.addDecimalColumn("PA_DEVISE", 16, 6, BigDecimal.ZERO, false);
707
            createFactureF.addDecimalColumn("PA_DEVISE", 16, 6, BigDecimal.ZERO, false);
708
            createFactureF.addIntegerColumn("QTE", 1);
708
            createFactureF.addIntegerColumn("QTE", 1);
709
            createFactureF.addIntegerColumn("QTE_ACHAT", 1);
709
            createFactureF.addIntegerColumn("QTE_ACHAT", 1);
710
 
710
 
711
            createFactureF.addColumn("VALEUR_METRIQUE_1", "real DEFAULT 0");
711
            createFactureF.addColumn("VALEUR_METRIQUE_1", "real DEFAULT 0");
712
            createFactureF.addColumn("VALEUR_METRIQUE_2", "real DEFAULT 0");
712
            createFactureF.addColumn("VALEUR_METRIQUE_2", "real DEFAULT 0");
713
            createFactureF.addColumn("VALEUR_METRIQUE_3", "real DEFAULT 0");
713
            createFactureF.addColumn("VALEUR_METRIQUE_3", "real DEFAULT 0");
714
            createFactureF.addColumn("T_POIDS", "real DEFAULT 0");
714
            createFactureF.addColumn("T_POIDS", "real DEFAULT 0");
715
            createFactureF.addColumn("POIDS", "real DEFAULT 0");
715
            createFactureF.addColumn("POIDS", "real DEFAULT 0");
716
            createFactureF.addBooleanColumn("SERVICE", Boolean.FALSE, true);
716
            createFactureF.addBooleanColumn("SERVICE", Boolean.FALSE, true);
717
            createFactureF.addVarCharColumn("CODE", 45);
717
            createFactureF.addVarCharColumn("CODE", 45);
718
            createFactureF.addVarCharColumn("NOM", 256);
718
            createFactureF.addVarCharColumn("NOM", 256);
719
            createFactureF.addColumn("DATE", "date");
719
            createFactureF.addColumn("DATE", "date");
720
            createFactureF.addForeignColumn("STYLE");
720
            createFactureF.addForeignColumn("STYLE");
721
            createFactureF.addForeignColumn("METRIQUE", "3");
721
            createFactureF.addForeignColumn("METRIQUE", "3");
722
            createFactureF.addForeignColumn("METRIQUE", "2");
722
            createFactureF.addForeignColumn("METRIQUE", "2");
723
            createFactureF.addForeignColumn("METRIQUE", "1");
723
            createFactureF.addForeignColumn("METRIQUE", "1");
724
            createFactureF.addForeignColumn("FACTURE_FOURNISSEUR");
724
            createFactureF.addForeignColumn("FACTURE_FOURNISSEUR");
725
            createFactureF.addForeignColumn("TAXE");
725
            createFactureF.addForeignColumn("TAXE");
726
            createFactureF.addForeignColumn("ID_MODE_VENTE_ARTICLE", root.findTable("MODE_VENTE_ARTICLE").getSQLName(), "ID", "5");
726
            createFactureF.addForeignColumn("ID_MODE_VENTE_ARTICLE", root.findTable("MODE_VENTE_ARTICLE").getSQLName(), "ID", "5");
727
            createFactureF.addForeignColumn("UNITE_VENTE");
727
            createFactureF.addForeignColumn("UNITE_VENTE");
728
            createFactureF.addForeignColumn("ARTICLE");
728
            createFactureF.addForeignColumn("ARTICLE");
729
            createFactureF.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
729
            createFactureF.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
730
            createFactureF.addForeignColumn("CODE_FOURNISSEUR");
730
            createFactureF.addForeignColumn("CODE_FOURNISSEUR");
731
 
731
 
732
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
732
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
733
 
733
 
734
            try {
734
            try {
735
                ds.execute(createFactureF.asString());
735
                ds.execute(createFactureF.asString());
736
                insertUndef(createFactureF);
736
                insertUndef(createFactureF);
737
                root.getSchema().updateVersion();
737
                root.getSchema().updateVersion();
738
                refetchRoot = true;
738
                refetchRoot = true;
739
            } catch (SQLException ex) {
739
            } catch (SQLException ex) {
740
                throw new IllegalStateException("Erreur lors de la création de la table FACTURE_FOURNISSEUR_ELEMENT", ex);
740
                throw new IllegalStateException("Erreur lors de la création de la table FACTURE_FOURNISSEUR_ELEMENT", ex);
741
            }
741
            }
742
 
742
 
743
        }
743
        }
744
 
744
 
745
        if (root.contains("FACTURE_FOURNISSEUR_ELEMENT")) {
745
        if (root.contains("FACTURE_FOURNISSEUR_ELEMENT")) {
746
            addHAElementField(root.getTable("FACTURE_FOURNISSEUR_ELEMENT"), root);
746
            addHAElementField(root.getTable("FACTURE_FOURNISSEUR_ELEMENT"), root);
747
        }
747
        }
748
 
748
 
749
        if (!root.contains("REGLER_MONTANT_ELEMENT")) {
749
        if (!root.contains("REGLER_MONTANT_ELEMENT")) {
750
 
750
 
751
            SQLCreateTable createReglerElt = new SQLCreateTable(root, "REGLER_MONTANT_ELEMENT");
751
            SQLCreateTable createReglerElt = new SQLCreateTable(root, "REGLER_MONTANT_ELEMENT");
752
 
752
 
753
            createReglerElt.addForeignColumn("ECHEANCE_FOURNISSEUR");
753
            createReglerElt.addForeignColumn("ECHEANCE_FOURNISSEUR");
754
            createReglerElt.addForeignColumn("REGLER_MONTANT");
754
            createReglerElt.addForeignColumn("REGLER_MONTANT");
755
            createReglerElt.addForeignColumn("MOUVEMENT", "ECHEANCE");
755
            createReglerElt.addForeignColumn("MOUVEMENT", "ECHEANCE");
756
            createReglerElt.addColumn("DATE", "date");
756
            createReglerElt.addColumn("DATE", "date");
757
            createReglerElt.addColumn("MONTANT_REGLE", "bigint DEFAULT 0");
757
            createReglerElt.addColumn("MONTANT_REGLE", "bigint DEFAULT 0");
758
            createReglerElt.addColumn("MONTANT_A_REGLER", "bigint DEFAULT 0");
758
            createReglerElt.addColumn("MONTANT_A_REGLER", "bigint DEFAULT 0");
759
 
759
 
760
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
760
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
761
 
761
 
762
            try {
762
            try {
763
                ds.execute(createReglerElt.asString());
763
                ds.execute(createReglerElt.asString());
764
                insertUndef(createReglerElt);
764
                insertUndef(createReglerElt);
765
                root.getSchema().updateVersion();
765
                root.getSchema().updateVersion();
766
                root.refetchTable("REGLER_MONTANT_ELEMENT");
766
                root.refetchTable("REGLER_MONTANT_ELEMENT");
767
                refetchRoot = true;
767
                refetchRoot = true;
768
            } catch (SQLException ex) {
768
            } catch (SQLException ex) {
769
                throw new IllegalStateException("Erreur lors de la création de la table REGLER_MONTANT_ELEMENT", ex);
769
                throw new IllegalStateException("Erreur lors de la création de la table REGLER_MONTANT_ELEMENT", ex);
770
            }
770
            }
771
 
771
 
772
        }
772
        }
773
 
773
 
774
        final SQLTable tableReglerMontant = root.getTable("REGLER_MONTANT");
774
        final SQLTable tableReglerMontant = root.getTable("REGLER_MONTANT");
775
 
775
 
776
        boolean updateRegler = false;
776
        boolean updateRegler = false;
777
 
777
 
778
        AlterTable alterElt = new AlterTable(tableReglerMontant);
778
        AlterTable alterElt = new AlterTable(tableReglerMontant);
779
        if (!tableReglerMontant.contains("ID_FOURNISSEUR")) {
779
        if (!tableReglerMontant.contains("ID_FOURNISSEUR")) {
780
            alterElt.addForeignColumn("ID_FOURNISSEUR", root.getTable("FOURNISSEUR"));
780
            alterElt.addForeignColumn("ID_FOURNISSEUR", root.getTable("FOURNISSEUR"));
781
            updateRegler = true;
781
            updateRegler = true;
782
        }
782
        }
783
 
783
 
784
        if (!tableReglerMontant.contains("NOM")) {
784
        if (!tableReglerMontant.contains("NOM")) {
785
            alterElt.addVarCharColumn("NOM", 256);
785
            alterElt.addVarCharColumn("NOM", 256);
786
            updateRegler = true;
786
            updateRegler = true;
787
        }
787
        }
788
 
788
 
789
        if (updateRegler) {
789
        if (updateRegler) {
790
            root.getDBSystemRoot().getDataSource().execute(alterElt.asString());
790
            root.getDBSystemRoot().getDataSource().execute(alterElt.asString());
791
            root.refetchTable(tableReglerMontant.getName());
791
            root.refetchTable(tableReglerMontant.getName());
792
        }
792
        }
793
 
793
 
794
        if (refetchRoot) {
794
        if (refetchRoot) {
795
            root.refetch();
795
            root.refetch();
796
        }
796
        }
797
    }
797
    }
798
 
798
 
799
    private void fixUnboundedNumeric(DBRoot root) throws SQLException {
799
    private void fixUnboundedNumeric(DBRoot root) throws SQLException {
800
 
800
 
801
        final List<AlterTable> alters = new ArrayList<AlterTable>();
801
        final List<AlterTable> alters = new ArrayList<AlterTable>();
802
        final List<UpdateBuilder> builds = new ArrayList<UpdateBuilder>();
802
        final List<UpdateBuilder> builds = new ArrayList<UpdateBuilder>();
803
        {
803
        {
804
            SQLTable tableAvoir = root.getTable("AVOIR_CLIENT_ELEMENT");
804
            SQLTable tableAvoir = root.getTable("AVOIR_CLIENT_ELEMENT");
805
            final AlterTable alter = new AlterTable(tableAvoir);
805
            final AlterTable alter = new AlterTable(tableAvoir);
806
            if (tableAvoir.contains("POURCENT_ACOMPTE")) {
806
            if (tableAvoir.contains("POURCENT_ACOMPTE")) {
807
                SQLField fieldAcompteAvoir = tableAvoir.getField("POURCENT_ACOMPTE");
807
                SQLField fieldAcompteAvoir = tableAvoir.getField("POURCENT_ACOMPTE");
808
                if (fieldAcompteAvoir.getType().getSize() > 500) {
808
                if (fieldAcompteAvoir.getType().getSize() > 500) {
809
                    final String fName = fieldAcompteAvoir.getName();
809
                    final String fName = fieldAcompteAvoir.getName();
810
                    alter.alterColumn(fName, EnumSet.allOf(Properties.class), "numeric(6,2)", "100", false);
810
                    alter.alterColumn(fName, EnumSet.allOf(Properties.class), "numeric(6,2)", "100", false);
811
 
811
 
812
                    UpdateBuilder build = new UpdateBuilder(tableAvoir);
812
                    UpdateBuilder build = new UpdateBuilder(tableAvoir);
813
                    build.set(fieldAcompteAvoir.getName(), "100");
813
                    build.set(fieldAcompteAvoir.getName(), "100");
814
                    build.setWhere(new Where(fieldAcompteAvoir, "=", (Object) null));
814
                    build.setWhere(new Where(fieldAcompteAvoir, "=", (Object) null));
815
                    builds.add(build);
815
                    builds.add(build);
816
                }
816
                }
817
            }
817
            }
818
            if (tableAvoir.contains("POURCENT_REMISE")) {
818
            if (tableAvoir.contains("POURCENT_REMISE")) {
819
                SQLField fieldRemiseAvoir = tableAvoir.getField("POURCENT_REMISE");
819
                SQLField fieldRemiseAvoir = tableAvoir.getField("POURCENT_REMISE");
820
                if (fieldRemiseAvoir.getType().getSize() > 500) {
820
                if (fieldRemiseAvoir.getType().getSize() > 500) {
821
                    final String fName = fieldRemiseAvoir.getName();
821
                    final String fName = fieldRemiseAvoir.getName();
822
                    alter.alterColumn(fName, EnumSet.allOf(Properties.class), "numeric(6,2)", "0", false);
822
                    alter.alterColumn(fName, EnumSet.allOf(Properties.class), "numeric(6,2)", "0", false);
823
 
823
 
824
                    UpdateBuilder build = new UpdateBuilder(tableAvoir);
824
                    UpdateBuilder build = new UpdateBuilder(tableAvoir);
825
                    build.set(fieldRemiseAvoir.getName(), "0");
825
                    build.set(fieldRemiseAvoir.getName(), "0");
826
                    build.setWhere(new Where(fieldRemiseAvoir, "=", (Object) null));
826
                    build.setWhere(new Where(fieldRemiseAvoir, "=", (Object) null));
827
                    builds.add(build);
827
                    builds.add(build);
828
                }
828
                }
829
            }
829
            }
830
            if (!alter.isEmpty())
830
            if (!alter.isEmpty())
831
                alters.add(alter);
831
                alters.add(alter);
832
        }
832
        }
833
 
833
 
834
        {
834
        {
835
            SQLTable tableFacture = root.getTable("SAISIE_VENTE_FACTURE_ELEMENT");
835
            SQLTable tableFacture = root.getTable("SAISIE_VENTE_FACTURE_ELEMENT");
836
            final AlterTable alter = new AlterTable(tableFacture);
836
            final AlterTable alter = new AlterTable(tableFacture);
837
            if (tableFacture.contains("POURCENT_ACOMPTE")) {
837
            if (tableFacture.contains("POURCENT_ACOMPTE")) {
838
                SQLField fieldAcompteFacture = tableFacture.getField("POURCENT_ACOMPTE");
838
                SQLField fieldAcompteFacture = tableFacture.getField("POURCENT_ACOMPTE");
839
                if (fieldAcompteFacture.getType().getSize() > 500) {
839
                if (fieldAcompteFacture.getType().getSize() > 500) {
840
                    final String fName = fieldAcompteFacture.getName();
840
                    final String fName = fieldAcompteFacture.getName();
841
                    alter.alterColumn(fName, EnumSet.allOf(Properties.class), "numeric(6,2)", "100", false);
841
                    alter.alterColumn(fName, EnumSet.allOf(Properties.class), "numeric(6,2)", "100", false);
842
 
842
 
843
                    UpdateBuilder build = new UpdateBuilder(tableFacture);
843
                    UpdateBuilder build = new UpdateBuilder(tableFacture);
844
                    build.set(fieldAcompteFacture.getName(), "100");
844
                    build.set(fieldAcompteFacture.getName(), "100");
845
                    build.setWhere(new Where(fieldAcompteFacture, "=", (Object) null));
845
                    build.setWhere(new Where(fieldAcompteFacture, "=", (Object) null));
846
                    builds.add(build);
846
                    builds.add(build);
847
                }
847
                }
848
            }
848
            }
849
 
849
 
850
            if (tableFacture.contains("POURCENT_REMISE")) {
850
            if (tableFacture.contains("POURCENT_REMISE")) {
851
                SQLField fieldRemiseFacture = tableFacture.getField("POURCENT_REMISE");
851
                SQLField fieldRemiseFacture = tableFacture.getField("POURCENT_REMISE");
852
                if (fieldRemiseFacture.getType().getSize() > 500) {
852
                if (fieldRemiseFacture.getType().getSize() > 500) {
853
                    final String fName = fieldRemiseFacture.getName();
853
                    final String fName = fieldRemiseFacture.getName();
854
                    alter.alterColumn(fName, EnumSet.allOf(Properties.class), "numeric(6,2)", "0", false);
854
                    alter.alterColumn(fName, EnumSet.allOf(Properties.class), "numeric(6,2)", "0", false);
855
 
855
 
856
                    UpdateBuilder build = new UpdateBuilder(tableFacture);
856
                    UpdateBuilder build = new UpdateBuilder(tableFacture);
857
                    build.set(fieldRemiseFacture.getName(), "0");
857
                    build.set(fieldRemiseFacture.getName(), "0");
858
                    build.setWhere(new Where(fieldRemiseFacture, "=", (Object) null));
858
                    build.setWhere(new Where(fieldRemiseFacture, "=", (Object) null));
859
                    builds.add(build);
859
                    builds.add(build);
860
                }
860
                }
861
            }
861
            }
862
            if (tableFacture.getFieldsName().contains("REPARTITION_POURCENT")) {
862
            if (tableFacture.getFieldsName().contains("REPARTITION_POURCENT")) {
863
                SQLField fieldRepFacture = tableFacture.getField("REPARTITION_POURCENT");
863
                SQLField fieldRepFacture = tableFacture.getField("REPARTITION_POURCENT");
864
                if (fieldRepFacture.getType().getSize() > 500) {
864
                if (fieldRepFacture.getType().getSize() > 500) {
865
                    final String fName = fieldRepFacture.getName();
865
                    final String fName = fieldRepFacture.getName();
866
                    alter.alterColumn(fName, EnumSet.allOf(Properties.class), "numeric(6,2)", "0", false);
866
                    alter.alterColumn(fName, EnumSet.allOf(Properties.class), "numeric(6,2)", "0", false);
867
 
867
 
868
                    UpdateBuilder build = new UpdateBuilder(tableFacture);
868
                    UpdateBuilder build = new UpdateBuilder(tableFacture);
869
                    build.set(fieldRepFacture.getName(), "0");
869
                    build.set(fieldRepFacture.getName(), "0");
870
                    build.setWhere(new Where(fieldRepFacture, "=", (Object) null));
870
                    build.setWhere(new Where(fieldRepFacture, "=", (Object) null));
871
                    builds.add(build);
871
                    builds.add(build);
872
                }
872
                }
873
            }
873
            }
874
 
874
 
875
            if (!alter.isEmpty())
875
            if (!alter.isEmpty())
876
                alters.add(alter);
876
                alters.add(alter);
877
 
877
 
878
        }
878
        }
879
        if (alters.size() > 0) {
879
        if (alters.size() > 0) {
880
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
880
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
881
 
881
 
882
            for (UpdateBuilder updateBuilder : builds) {
882
            for (UpdateBuilder updateBuilder : builds) {
883
                ds.execute(updateBuilder.asString());
883
                ds.execute(updateBuilder.asString());
884
            }
884
            }
885
 
885
 
886
            for (final String sql : ChangeTable.cat(alters, root.getName())) {
886
            for (final String sql : ChangeTable.cat(alters, root.getName())) {
887
                ds.execute(sql);
887
                ds.execute(sql);
888
            }
888
            }
889
            root.refetch();
889
            root.refetch();
890
        }
890
        }
891
    }
891
    }
892
 
892
 
893
    private void fixUnboundedVarchar(DBRoot root) throws SQLException {
893
    private void fixUnboundedVarchar(DBRoot root) throws SQLException {
894
        final Set<String> namesSet = CollectionUtils.createSet("NOM", "PRENOM", "SURNOM", "LOGIN", "PASSWORD");
894
        final Set<String> namesSet = CollectionUtils.createSet("NOM", "PRENOM", "SURNOM", "LOGIN", "PASSWORD");
895
        final List<AlterTable> alters = new ArrayList<AlterTable>();
895
        final List<AlterTable> alters = new ArrayList<AlterTable>();
896
        final List<UpdateBuilder> builds = new ArrayList<UpdateBuilder>();
896
        final List<UpdateBuilder> builds = new ArrayList<UpdateBuilder>();
897
        for (final SQLTable t : root.getTables()) {
897
        for (final SQLTable t : root.getTables()) {
898
            final AlterTable alter = new AlterTable(t);
898
            final AlterTable alter = new AlterTable(t);
899
            for (final SQLField f : t.getFields()) {
899
            for (final SQLField f : t.getFields()) {
900
                // on PG, CLOB are text and the JDBC driver returns Types.VARCHAR, not CLOB. So test
900
                // on PG, CLOB are text and the JDBC driver returns Types.VARCHAR, not CLOB. So test
901
                // if the type name contains "char", since we only want unbounded varchar, not
901
                // if the type name contains "char", since we only want unbounded varchar, not
902
                // text/clob.
902
                // text/clob.
903
                if (f.getType().getType() == Types.VARCHAR && f.getType().getSize() == Integer.MAX_VALUE && f.getTypeDecl().contains("char")) {
903
                if (f.getType().getType() == Types.VARCHAR && f.getType().getSize() == Integer.MAX_VALUE && f.getTypeDecl().contains("char")) {
904
 
904
 
905
                    UpdateBuilder build = new UpdateBuilder(t);
905
                    UpdateBuilder build = new UpdateBuilder(t);
906
                    build.setObject(f.getName(), "");
906
                    build.setObject(f.getName(), "");
907
                    build.setWhere(Where.isNull(f));
907
                    build.setWhere(Where.isNull(f));
908
                    builds.add(build);
908
                    builds.add(build);
909
 
909
 
910
                    final String fName = f.getName();
910
                    final String fName = f.getName();
911
                    final int size;
911
                    final int size;
912
                    if (t.getName().contains("USER") && namesSet.contains(fName))
912
                    if (t.getName().contains("USER") && namesSet.contains(fName))
913
                        size = 128;
913
                        size = 128;
914
                    else if (fName.equals("TEL") || fName.startsWith("TEL_"))
914
                    else if (fName.equals("TEL") || fName.startsWith("TEL_"))
915
                        size = 32;
915
                        size = 32;
916
                    else if (fName.contains("INFO"))
916
                    else if (fName.contains("INFO"))
917
                        size = 4096;
917
                        size = 4096;
918
                    else if (fName.contains("FORMULE"))
918
                    else if (fName.contains("FORMULE"))
919
                        size = 1024;
919
                        size = 1024;
920
                    else if (fName.equals("CONTENU"))
920
                    else if (fName.equals("CONTENU"))
921
                        size = 2048;
921
                        size = 2048;
922
                    else
922
                    else
923
                        // e.g. IDCC.NOM > 350
923
                        // e.g. IDCC.NOM > 350
924
                        size = 512;
924
                        size = 512;
925
                    alter.alterColumn(fName, EnumSet.allOf(Properties.class), "varchar(" + size + ")", "''", false);
925
                    alter.alterColumn(fName, EnumSet.allOf(Properties.class), "varchar(" + size + ")", "''", false);
926
                }
926
                }
927
            }
927
            }
928
            if (!alter.isEmpty())
928
            if (!alter.isEmpty())
929
                alters.add(alter);
929
                alters.add(alter);
930
        }
930
        }
931
        if (alters.size() > 0) {
931
        if (alters.size() > 0) {
932
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
932
            final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
933
 
933
 
934
            for (UpdateBuilder build : builds) {
934
            for (UpdateBuilder build : builds) {
935
                ds.execute(build.asString());
935
                ds.execute(build.asString());
936
            }
936
            }
937
 
937
 
938
            for (final String sql : ChangeTable.cat(alters, root.getName())) {
938
            for (final String sql : ChangeTable.cat(alters, root.getName())) {
939
                ds.execute(sql);
939
                ds.execute(sql);
940
            }
940
            }
941
            root.refetch();
941
            root.refetch();
942
        }
942
        }
943
 
943
 
944
    }
944
    }
945
 
945
 
946
    private void updateToV1Dot3(final DBRoot root) throws SQLException {
946
    private void updateToV1Dot3(final DBRoot root) throws SQLException {
947
        final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
947
        final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
948
 
948
 
949
        addForeignKeyFactureOnEcheance(root);
949
        addForeignKeyFactureOnEcheance(root);
950
        addFieldForPartialInvoice(root);
950
        addFieldForPartialInvoice(root);
951
 
951
 
952
        // Numérotation client
952
        // Numérotation client
953
        {
953
        {
954
            SQLTable tableNum = root.getTable("NUMEROTATION_AUTO");
954
            SQLTable tableNum = root.getTable("NUMEROTATION_AUTO");
955
            boolean alterNum = false;
955
            boolean alterNum = false;
956
            AlterTable t = new AlterTable(tableNum);
956
            AlterTable t = new AlterTable(tableNum);
957
            if (!tableNum.getFieldsName().contains("CLIENT_START")) {
957
            if (!tableNum.getFieldsName().contains("CLIENT_START")) {
958
                t.addColumn("CLIENT_START", "integer DEFAULT 0");
958
                t.addColumn("CLIENT_START", "integer DEFAULT 0");
959
                alterNum = true;
959
                alterNum = true;
960
            }
960
            }
961
            if (!tableNum.getFieldsName().contains("CLIENT_FORMAT")) {
961
            if (!tableNum.getFieldsName().contains("CLIENT_FORMAT")) {
962
                t.addVarCharColumn("CLIENT_FORMAT", 48);
962
                t.addVarCharColumn("CLIENT_FORMAT", 48);
963
                alterNum = true;
963
                alterNum = true;
964
            }
964
            }
965
 
965
 
966
            if (alterNum) {
966
            if (alterNum) {
967
                try {
967
                try {
968
                    ds.execute(t.asString());
968
                    ds.execute(t.asString());
969
                    tableNum.getSchema().updateVersion();
969
                    tableNum.getSchema().updateVersion();
970
                    tableNum.fetchFields();
970
                    tableNum.fetchFields();
971
                } catch (SQLException ex) {
971
                } catch (SQLException ex) {
972
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table NUMEROTATION_AUTO", ex);
972
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table NUMEROTATION_AUTO", ex);
973
                }
973
                }
974
            }
974
            }
975
        }
975
        }
976
 
976
 
977
        // Eecheance founisseur
977
        // Eecheance founisseur
978
        {
978
        {
979
            SQLTable tableEchF = root.getTable("ECHEANCE_FOURNISSEUR");
979
            SQLTable tableEchF = root.getTable("ECHEANCE_FOURNISSEUR");
980
            AlterTable t = new AlterTable(tableEchF);
980
            AlterTable t = new AlterTable(tableEchF);
981
            if (!tableEchF.getFieldsName().contains("REG_COMPTA")) {
981
            if (!tableEchF.getFieldsName().contains("REG_COMPTA")) {
982
                t.addColumn("REG_COMPTA", "boolean DEFAULT false");
982
                t.addColumn("REG_COMPTA", "boolean DEFAULT false");
983
                try {
983
                try {
984
                    ds.execute(t.asString());
984
                    ds.execute(t.asString());
985
                    tableEchF.getSchema().updateVersion();
985
                    tableEchF.getSchema().updateVersion();
986
                    tableEchF.fetchFields();
986
                    tableEchF.fetchFields();
987
                } catch (SQLException ex) {
987
                } catch (SQLException ex) {
988
                    throw new IllegalStateException("Erreur lors de l'ajout du champ REG_COMPTA sur la table ECHEANCE_FOUNISSEUR", ex);
988
                    throw new IllegalStateException("Erreur lors de l'ajout du champ REG_COMPTA sur la table ECHEANCE_FOUNISSEUR", ex);
989
                }
989
                }
990
            }
990
            }
991
        }
991
        }
992
 
992
 
993
        SQLTable tableTaxe = root.getTable("TAXE");
993
        SQLTable tableTaxe = root.getTable("TAXE");
994
        boolean containsTaxeDefault = tableTaxe.contains("DEFAULT");
994
        boolean containsTaxeDefault = tableTaxe.contains("DEFAULT");
995
        if (!containsTaxeDefault) {
995
        if (!containsTaxeDefault) {
996
            AlterTable t = new AlterTable(tableTaxe);
996
            AlterTable t = new AlterTable(tableTaxe);
997
            t.addColumn("DEFAULT", "boolean DEFAULT false");
997
            t.addColumn("DEFAULT", "boolean DEFAULT false");
998
 
998
 
999
            try {
999
            try {
1000
                ds.execute(t.asString());
1000
                ds.execute(t.asString());
1001
                tableTaxe.getSchema().updateVersion();
1001
                tableTaxe.getSchema().updateVersion();
1002
                tableTaxe.fetchFields();
1002
                tableTaxe.fetchFields();
1003
            } catch (SQLException ex) {
1003
            } catch (SQLException ex) {
1004
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table TAXE", ex);
1004
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table TAXE", ex);
1005
            }
1005
            }
1006
 
1006
 
1007
        }
1007
        }
1008
 
1008
 
1009
        // Ajout de la TVA à 20
1009
        // Ajout de la TVA à 20
1010
        SQLSelect selTVA = new SQLSelect();
1010
        SQLSelect selTVA = new SQLSelect();
1011
        selTVA.addSelect(tableTaxe.getKey(), "COUNT");
1011
        selTVA.addSelect(tableTaxe.getKey(), "COUNT");
1012
        selTVA.setWhere(new Where(tableTaxe.getField("TAUX"), "=", 20));
1012
        selTVA.setWhere(new Where(tableTaxe.getField("TAUX"), "=", 20));
1013
        Object result = root.getBase().getDataSource().executeScalar(selTVA.asString());
1013
        Object result = root.getBase().getDataSource().executeScalar(selTVA.asString());
1014
        if (result == null || ((Number) result).longValue() == 0) {
1014
        if (result == null || ((Number) result).longValue() == 0) {
1015
            SQLRowValues rowVals = new SQLRowValues(tableTaxe);
1015
            SQLRowValues rowVals = new SQLRowValues(tableTaxe);
1016
            rowVals.put("NOM", "TVA 20%");
1016
            rowVals.put("NOM", "TVA 20%");
1017
            rowVals.put("TAUX", Float.valueOf(20));
1017
            rowVals.put("TAUX", Float.valueOf(20));
1018
            rowVals.put("DEFAULT", Boolean.TRUE);
1018
            rowVals.put("DEFAULT", Boolean.TRUE);
1019
            rowVals.commit();
1019
            rowVals.commit();
1020
        } else if (!containsTaxeDefault) {
1020
        } else if (!containsTaxeDefault) {
1021
            SQLSelect selTVA20 = new SQLSelect();
1021
            SQLSelect selTVA20 = new SQLSelect();
1022
            selTVA20.addSelectStar(tableTaxe);
1022
            selTVA20.addSelectStar(tableTaxe);
1023
            selTVA20.setWhere(new Where(tableTaxe.getField("TAUX"), "=", 20));
1023
            selTVA20.setWhere(new Where(tableTaxe.getField("TAUX"), "=", 20));
1024
            List<SQLRow> lTVA = SQLRowListRSH.execute(selTVA20);
1024
            List<SQLRow> lTVA = SQLRowListRSH.execute(selTVA20);
1025
            if (lTVA != null && lTVA.size() > 0) {
1025
            if (lTVA != null && lTVA.size() > 0) {
1026
                SQLRowValues rowVals = lTVA.get(0).asRowValues();
1026
                SQLRowValues rowVals = lTVA.get(0).asRowValues();
1027
                rowVals.put("DEFAULT", Boolean.TRUE);
1027
                rowVals.put("DEFAULT", Boolean.TRUE);
1028
                rowVals.update();
1028
                rowVals.update();
1029
            }
1029
            }
1030
 
1030
 
1031
        }
1031
        }
1032
 
1032
 
1033
        // Article
1033
        // Article
1034
        {
1034
        {
1035
            SQLTable tableProduct = root.getTable("ARTICLE");
1035
            SQLTable tableProduct = root.getTable("ARTICLE");
1036
            boolean alterTableProduct = false;
1036
            boolean alterTableProduct = false;
1037
            AlterTable t = new AlterTable(tableProduct);
1037
            AlterTable t = new AlterTable(tableProduct);
1038
            if (!tableProduct.getFieldsName().contains("ID_COMPTE_PCE")) {
1038
            if (!tableProduct.getFieldsName().contains("ID_COMPTE_PCE")) {
1039
                t.addForeignColumn("ID_COMPTE_PCE", root.getTable("COMPTE_PCE"));
1039
                t.addForeignColumn("ID_COMPTE_PCE", root.getTable("COMPTE_PCE"));
1040
                alterTableProduct = true;
1040
                alterTableProduct = true;
1041
            }
1041
            }
1042
            if (!tableProduct.getFieldsName().contains("ID_COMPTE_PCE_ACHAT")) {
1042
            if (!tableProduct.getFieldsName().contains("ID_COMPTE_PCE_ACHAT")) {
1043
                t.addForeignColumn("ID_COMPTE_PCE_ACHAT", root.getTable("COMPTE_PCE"));
1043
                t.addForeignColumn("ID_COMPTE_PCE_ACHAT", root.getTable("COMPTE_PCE"));
1044
                alterTableProduct = true;
1044
                alterTableProduct = true;
1045
            }
1045
            }
1046
            if (alterTableProduct) {
1046
            if (alterTableProduct) {
1047
                try {
1047
                try {
1048
                    ds.execute(t.asString());
1048
                    ds.execute(t.asString());
1049
                    tableProduct.getSchema().updateVersion();
1049
                    tableProduct.getSchema().updateVersion();
1050
                    tableProduct.fetchFields();
1050
                    tableProduct.fetchFields();
1051
                } catch (SQLException ex) {
1051
                } catch (SQLException ex) {
1052
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table ARTICLE", ex);
1052
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table ARTICLE", ex);
1053
                }
1053
                }
1054
            }
1054
            }
1055
        }
1055
        }
1056
 
1056
 
1057
        // Famille Article
1057
        // Famille Article
1058
        {
1058
        {
1059
            SQLTable tableArticleFamily = root.getTable("FAMILLE_ARTICLE");
1059
            SQLTable tableArticleFamily = root.getTable("FAMILLE_ARTICLE");
1060
            boolean alterArticleFamily = false;
1060
            boolean alterArticleFamily = false;
1061
            AlterTable t = new AlterTable(tableArticleFamily);
1061
            AlterTable t = new AlterTable(tableArticleFamily);
1062
            if (!tableArticleFamily.getFieldsName().contains("ID_COMPTE_PCE")) {
1062
            if (!tableArticleFamily.getFieldsName().contains("ID_COMPTE_PCE")) {
1063
                t.addForeignColumn("ID_COMPTE_PCE", root.getTable("COMPTE_PCE"));
1063
                t.addForeignColumn("ID_COMPTE_PCE", root.getTable("COMPTE_PCE"));
1064
                alterArticleFamily = true;
1064
                alterArticleFamily = true;
1065
            }
1065
            }
1066
            if (!tableArticleFamily.getFieldsName().contains("ID_COMPTE_PCE_ACHAT")) {
1066
            if (!tableArticleFamily.getFieldsName().contains("ID_COMPTE_PCE_ACHAT")) {
1067
                t.addForeignColumn("ID_COMPTE_PCE_ACHAT", root.getTable("COMPTE_PCE"));
1067
                t.addForeignColumn("ID_COMPTE_PCE_ACHAT", root.getTable("COMPTE_PCE"));
1068
                alterArticleFamily = true;
1068
                alterArticleFamily = true;
1069
            }
1069
            }
1070
            if (alterArticleFamily) {
1070
            if (alterArticleFamily) {
1071
                try {
1071
                try {
1072
                    ds.execute(t.asString());
1072
                    ds.execute(t.asString());
1073
                    tableArticleFamily.getSchema().updateVersion();
1073
                    tableArticleFamily.getSchema().updateVersion();
1074
                    tableArticleFamily.fetchFields();
1074
                    tableArticleFamily.fetchFields();
1075
                } catch (SQLException ex) {
1075
                } catch (SQLException ex) {
1076
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table FAMILLE_ARTICLE", ex);
1076
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table FAMILLE_ARTICLE", ex);
1077
                }
1077
                }
1078
            }
1078
            }
1079
        }
1079
        }
1080
 
1080
 
1081
        // ECRITURE
1081
        // ECRITURE
1082
        {
1082
        {
1083
            SQLTable tableRecords = root.getTable("ECRITURE");
1083
            SQLTable tableRecords = root.getTable("ECRITURE");
1084
            boolean alterRecords = false;
1084
            boolean alterRecords = false;
1085
            AlterTable t = new AlterTable(tableRecords);
1085
            AlterTable t = new AlterTable(tableRecords);
1086
            if (!tableRecords.getFieldsName().contains("DATE_EXPORT")) {
1086
            if (!tableRecords.getFieldsName().contains("DATE_EXPORT")) {
1087
                t.addColumn("DATE_EXPORT", "date");
1087
                t.addColumn("DATE_EXPORT", "date");
1088
                alterRecords = true;
1088
                alterRecords = true;
1089
            }
1089
            }
1090
 
1090
 
1091
            if (!tableRecords.getFieldsName().contains("CODE_CLIENT")) {
1091
            if (!tableRecords.getFieldsName().contains("CODE_CLIENT")) {
1092
                t.addVarCharColumn("CODE_CLIENT", 256);
1092
                t.addVarCharColumn("CODE_CLIENT", 256);
1093
                alterRecords = true;
1093
                alterRecords = true;
1094
            }
1094
            }
1095
            if (alterRecords) {
1095
            if (alterRecords) {
1096
                try {
1096
                try {
1097
                    ds.execute(t.asString());
1097
                    ds.execute(t.asString());
1098
                    tableRecords.getSchema().updateVersion();
1098
                    tableRecords.getSchema().updateVersion();
1099
                    tableRecords.fetchFields();
1099
                    tableRecords.fetchFields();
1100
                } catch (SQLException ex) {
1100
                } catch (SQLException ex) {
1101
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table ECRITURE", ex);
1101
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table ECRITURE", ex);
1102
                }
1102
                }
1103
            }
1103
            }
1104
        }
1104
        }
1105
        addInfoField(root, ds, "AVOIR_FOURNISSEUR");
1105
        addInfoField(root, ds, "AVOIR_FOURNISSEUR");
1106
        addInfoField(root, ds, "AVOIR_CLIENT");
1106
        addInfoField(root, ds, "AVOIR_CLIENT");
1107
 
1107
 
1108
        boolean refetchRoot = false;
1108
        boolean refetchRoot = false;
1109
        if (!root.contains("CODE_FOURNISSEUR")) {
1109
        if (!root.contains("CODE_FOURNISSEUR")) {
1110
 
1110
 
1111
            SQLCreateTable createCode = new SQLCreateTable(root, "CODE_FOURNISSEUR");
1111
            SQLCreateTable createCode = new SQLCreateTable(root, "CODE_FOURNISSEUR");
1112
            createCode.addVarCharColumn("CODE", 256);
1112
            createCode.addVarCharColumn("CODE", 256);
1113
            createCode.addForeignColumn("FOURNISSEUR");
1113
            createCode.addForeignColumn("FOURNISSEUR");
1114
            createCode.addForeignColumn("ARTICLE");
1114
            createCode.addForeignColumn("ARTICLE");
1115
            try {
1115
            try {
1116
                ds.execute(createCode.asString());
1116
                ds.execute(createCode.asString());
1117
                insertUndef(createCode);
1117
                insertUndef(createCode);
1118
                root.getSchema().updateVersion();
1118
                root.getSchema().updateVersion();
1119
                refetchRoot = true;
1119
                refetchRoot = true;
1120
            } catch (SQLException ex) {
1120
            } catch (SQLException ex) {
1121
                throw new IllegalStateException("Erreur lors de la création de la table CODE_FOURNISSEUR", ex);
1121
                throw new IllegalStateException("Erreur lors de la création de la table CODE_FOURNISSEUR", ex);
1122
            }
1122
            }
1123
 
1123
 
1124
        }
1124
        }
1125
 
1125
 
1126
        // Chargement des tables fraichement créées
1126
        // Chargement des tables fraichement créées
1127
        if (refetchRoot)
1127
        if (refetchRoot)
1128
            root.refetch();
1128
            root.refetch();
1129
 
1129
 
1130
        createFactureFournisseur(root);
1130
        createFactureFournisseur(root);
1131
 
1131
 
1132
        addSupplierCode(root, ds, "BON_RECEPTION_ELEMENT");
1132
        addSupplierCode(root, ds, "BON_RECEPTION_ELEMENT");
1133
        addSupplierCode(root, ds, "COMMANDE_ELEMENT");
1133
        addSupplierCode(root, ds, "COMMANDE_ELEMENT");
1134
 
1134
 
1135
        // Undefined
1135
        // Undefined
1136
        SQLTable.setUndefID(root.getSchema(), "ARTICLE_DESIGNATION", 1);
1136
        SQLTable.setUndefID(root.getSchema(), "ARTICLE_DESIGNATION", 1);
1137
        SQLTable.setUndefID(root.getSchema(), "ARTICLE_TARIF", 1);
1137
        SQLTable.setUndefID(root.getSchema(), "ARTICLE_TARIF", 1);
1138
        SQLTable.setUndefID(root.getSchema(), "CODE_STATUT_CAT_CONV", 1);
1138
        SQLTable.setUndefID(root.getSchema(), "CODE_STATUT_CAT_CONV", 1);
1139
        SQLTable.setUndefID(root.getSchema(), "CONTACT_ADMINISTRATIF", 1);
1139
        SQLTable.setUndefID(root.getSchema(), "CONTACT_ADMINISTRATIF", 1);
1140
        SQLTable.setUndefID(root.getSchema(), "CONTACT_FOURNISSEUR", 1);
1140
        SQLTable.setUndefID(root.getSchema(), "CONTACT_FOURNISSEUR", 1);
1141
 
1141
 
1142
        SQLTable.setUndefID(root.getSchema(), "LANGUE", 1);
1142
        SQLTable.setUndefID(root.getSchema(), "LANGUE", 1);
1143
        SQLTable.setUndefID(root.getSchema(), "MODELE", 1);
1143
        SQLTable.setUndefID(root.getSchema(), "MODELE", 1);
1144
        SQLTable.setUndefID(root.getSchema(), "OBJECTIF_COMMERCIAL", 1);
1144
        SQLTable.setUndefID(root.getSchema(), "OBJECTIF_COMMERCIAL", 1);
1145
        SQLTable.setUndefID(root.getSchema(), "TARIF", 1);
1145
        SQLTable.setUndefID(root.getSchema(), "TARIF", 1);
1146
 
1146
 
1147
        SQLTable.setUndefID(root.getSchema(), "UNITE_VENTE", 1);
1147
        SQLTable.setUndefID(root.getSchema(), "UNITE_VENTE", 1);
1148
 
1148
 
1149
        // Create transfer tables
1149
        // Create transfer tables
1150
        ComptaPropsConfiguration.setSocieteSQLInjector(root);
1150
        ComptaPropsConfiguration.setSocieteSQLInjector(root);
1151
        SQLInjector.createTransferTables(root);
1151
        SQLInjector.createTransferTables(root);
1152
        // Move transfer info to SAISIE_VENTE_FACTURE
1152
        // Move transfer info to SAISIE_VENTE_FACTURE
1153
        convertTransfer(root, Arrays.asList("COMMANDE_CLIENT", "DEVIS", "BON_DE_LIVRAISON"), "SAISIE_VENTE_FACTURE");
1153
        convertTransfer(root, Arrays.asList("COMMANDE_CLIENT", "DEVIS", "BON_DE_LIVRAISON"), "SAISIE_VENTE_FACTURE");
1154
        // Fix keys
1154
        // Fix keys
1155
        if (root.getServer().getSQLSystem().equals(SQLSystem.H2)) {
1155
        if (root.getServer().getSQLSystem().equals(SQLSystem.H2)) {
1156
            final ChangeIDToInt c = new ChangeIDToInt(root.getDBSystemRoot());
1156
            final ChangeIDToInt c = new ChangeIDToInt(root.getDBSystemRoot());
1157
            c.changeAll(root);
1157
            c.changeAll(root);
1158
            root.getDBSystemRoot().reload(Collections.singleton(root.getName()));
1158
            root.getDBSystemRoot().reload(Collections.singleton(root.getName()));
1159
        }
1159
        }
1160
    }
1160
    }
1161
 
1161
 
1162
    private void convertTransfer(DBRoot root, List<String> tablesSrc, String tableDest) throws SQLException {
1162
    private void convertTransfer(DBRoot root, List<String> tablesSrc, String tableDest) throws SQLException {
1163
        final SQLTable tableDestination = root.getTable(tableDest);
1163
        final SQLTable tableDestination = root.getTable(tableDest);
1164
        if (tableDestination.contains("SOURCE") && tableDestination.contains("IDSOURCE")) {
1164
        if (tableDestination.contains("SOURCE") && tableDestination.contains("IDSOURCE")) {
1165
            for (String tableSrc : tablesSrc) {
1165
            for (String tableSrc : tablesSrc) {
1166
                convertTransfer(root.getTable(tableSrc), tableDestination);
1166
                convertTransfer(root.getTable(tableSrc), tableDestination);
1167
            }
1167
            }
1168
            final AlterTable alter = new AlterTable(tableDestination);
1168
            final AlterTable alter = new AlterTable(tableDestination);
1169
            alter.dropColumn("SOURCE");
1169
            alter.dropColumn("SOURCE");
1170
            alter.dropColumn("IDSOURCE");
1170
            alter.dropColumn("IDSOURCE");
1171
            final String req = alter.asString();
1171
            final String req = alter.asString();
1172
            root.getDBSystemRoot().getDataSource().execute(req);
1172
            root.getDBSystemRoot().getDataSource().execute(req);
1173
            root.refetchTable(tableDest);
1173
            root.refetchTable(tableDest);
1174
        }
1174
        }
1175
    }
1175
    }
1176
 
1176
 
1177
    private void convertTransfer(final SQLTable tableSource, final SQLTable tableDest) throws SQLException {
1177
    private void convertTransfer(final SQLTable tableSource, final SQLTable tableDest) throws SQLException {
1178
        SQLInjector inj = SQLInjector.getInjector(tableSource, tableDest);
1178
        SQLInjector inj = SQLInjector.getInjector(tableSource, tableDest);
1179
        final SQLRowValues vals = new SQLRowValues(tableDest);
1179
        final SQLRowValues vals = new SQLRowValues(tableDest);
1180
        vals.putNulls("SOURCE", "IDSOURCE");
1180
        vals.putNulls("SOURCE", "IDSOURCE");
1181
        final SQLRowValuesListFetcher fetcher = new SQLRowValuesListFetcher(vals);
1181
        final SQLRowValuesListFetcher fetcher = new SQLRowValuesListFetcher(vals);
1182
        fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
1182
        fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
1183
 
1183
 
1184
            @Override
1184
            @Override
1185
            public SQLSelect transformChecked(SQLSelect input) {
1185
            public SQLSelect transformChecked(SQLSelect input) {
1186
                Where w = new Where(tableDest.getField("SOURCE"), "=", tableSource.getName());
1186
                Where w = new Where(tableDest.getField("SOURCE"), "=", tableSource.getName());
1187
                w = w.and(new Where(tableDest.getField("IDSOURCE"), "!=", tableSource.getUndefinedIDNumber()));
1187
                w = w.and(new Where(tableDest.getField("IDSOURCE"), "!=", tableSource.getUndefinedIDNumber()));
1188
                // remove archive idsource
1188
                // remove archive idsource
1189
                w = w.and(new Where(tableDest.getField("IDSOURCE"), "=", tableSource.getKey()));
1189
                w = w.and(new Where(tableDest.getField("IDSOURCE"), "=", tableSource.getKey()));
1190
                input.setWhere(w);
1190
                input.setWhere(w);
1191
                return input;
1191
                return input;
1192
            }
1192
            }
1193
        });
1193
        });
1194
        List<SQLRowValues> rows = fetcher.fetch();
1194
        List<SQLRowValues> rows = fetcher.fetch();
1195
        for (SQLRowValues sqlRowValues : rows) {
1195
        for (SQLRowValues sqlRowValues : rows) {
1196
            inj.addTransfert(sqlRowValues.getInt("IDSOURCE"), sqlRowValues.getID());
1196
            inj.addTransfert(sqlRowValues.getInt("IDSOURCE"), sqlRowValues.getID());
1197
        }
1197
        }
1198
    }
1198
    }
1199
 
1199
 
1200
    private void addInfoField(final DBRoot root, final SQLDataSource ds, String tableName) {
1200
    private void addInfoField(final DBRoot root, final SQLDataSource ds, String tableName) {
1201
        SQLTable tableBL = root.getTable(tableName);
1201
        SQLTable tableBL = root.getTable(tableName);
1202
        boolean alterBL = false;
1202
        boolean alterBL = false;
1203
        AlterTable t = new AlterTable(tableBL);
1203
        AlterTable t = new AlterTable(tableBL);
1204
        if (!tableBL.getFieldsName().contains("INFOS")) {
1204
        if (!tableBL.getFieldsName().contains("INFOS")) {
1205
            t.addVarCharColumn("INFOS", 1024);
1205
            t.addVarCharColumn("INFOS", 1024);
1206
            alterBL = true;
1206
            alterBL = true;
1207
        }
1207
        }
1208
        if (alterBL) {
1208
        if (alterBL) {
1209
            try {
1209
            try {
1210
                ds.execute(t.asString());
1210
                ds.execute(t.asString());
1211
                tableBL.getSchema().updateVersion();
1211
                tableBL.getSchema().updateVersion();
1212
                tableBL.fetchFields();
1212
                tableBL.fetchFields();
1213
            } catch (SQLException ex) {
1213
            } catch (SQLException ex) {
1214
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table AVOIR FOURNISSEUR", ex);
1214
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table AVOIR FOURNISSEUR", ex);
1215
            }
1215
            }
1216
        }
1216
        }
1217
    }
1217
    }
1218
 
1218
 
1219
    private void addSupplierCode(final DBRoot root, final SQLDataSource ds, String tableName) {
1219
    private void addSupplierCode(final DBRoot root, final SQLDataSource ds, String tableName) {
1220
        SQLTable tableBL = root.getTable(tableName);
1220
        SQLTable tableBL = root.getTable(tableName);
1221
        boolean alterBL = false;
1221
        boolean alterBL = false;
1222
        AlterTable t = new AlterTable(tableBL);
1222
        AlterTable t = new AlterTable(tableBL);
1223
        if (!tableBL.contains("ID_CODE_FOURNISSEUR")) {
1223
        if (!tableBL.contains("ID_CODE_FOURNISSEUR")) {
1224
            t.addForeignColumn("ID_CODE_FOURNISSEUR", root.getTable("CODE_FOURNISSEUR"));
1224
            t.addForeignColumn("ID_CODE_FOURNISSEUR", root.getTable("CODE_FOURNISSEUR"));
1225
            alterBL = true;
1225
            alterBL = true;
1226
        }
1226
        }
1227
        if (alterBL) {
1227
        if (alterBL) {
1228
            try {
1228
            try {
1229
                ds.execute(t.asString());
1229
                ds.execute(t.asString());
1230
                tableBL.getSchema().updateVersion();
1230
                tableBL.getSchema().updateVersion();
1231
                tableBL.fetchFields();
1231
                tableBL.fetchFields();
1232
            } catch (SQLException ex) {
1232
            } catch (SQLException ex) {
1233
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table " + tableName, ex);
1233
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table " + tableName, ex);
1234
            }
1234
            }
1235
        }
1235
        }
1236
    }
1236
    }
1237
 
1237
 
1238
    private void checkDepartementExists(DBRoot root, String dpt, String chefLieu, String regionAdmin, String numero) throws SQLException {
1238
    private void checkDepartementExists(DBRoot root, String dpt, String chefLieu, String regionAdmin, String numero) throws SQLException {
1239
        SQLSelect sel = new SQLSelect();
1239
        SQLSelect sel = new SQLSelect();
1240
        final SQLTable tableDpt = root.getTable("DEPARTEMENT");
1240
        final SQLTable tableDpt = root.getTable("DEPARTEMENT");
1241
        sel.addSelect(tableDpt.getKey());
1241
        sel.addSelect(tableDpt.getKey());
1242
        sel.addSelect(tableDpt.getField("NOM"));
1242
        sel.addSelect(tableDpt.getField("NOM"));
1243
        Where w = new Where(tableDpt.getField("NOM"), "=", dpt);
1243
        Where w = new Where(tableDpt.getField("NOM"), "=", dpt);
1244
        sel.setWhere(w);
1244
        sel.setWhere(w);
1245
        int result = SQLRowListRSH.execute(sel).size();
1245
        int result = SQLRowListRSH.execute(sel).size();
1246
        if (result == 0) {
1246
        if (result == 0) {
1247
            SQLRowValues rowVals = new SQLRowValues(tableDpt);
1247
            SQLRowValues rowVals = new SQLRowValues(tableDpt);
1248
            rowVals.put("NOM", dpt);
1248
            rowVals.put("NOM", dpt);
1249
            rowVals.put("CHEF_LIEU", chefLieu);
1249
            rowVals.put("CHEF_LIEU", chefLieu);
1250
            rowVals.put("REGION_ADMIN", regionAdmin);
1250
            rowVals.put("REGION_ADMIN", regionAdmin);
1251
            rowVals.put("NUMERO", numero);
1251
            rowVals.put("NUMERO", numero);
1252
            rowVals.commit();
1252
            rowVals.commit();
1253
        }
1253
        }
1254
    }
1254
    }
1255
 
1255
 
1256
    private void updateToV1Dot4(final DBRoot root) throws SQLException {
1256
    private void updateToV1Dot4(final DBRoot root) throws SQLException {
1257
 
1257
 
1258
        checkPrefsComptable(root);
1258
        checkPrefsComptable(root);
1259
        checkDepartementExists(root, "Aisne", "Laon", "Picardie", "02");
1259
        checkDepartementExists(root, "Aisne", "Laon", "Picardie", "02");
1260
 
1260
 
1261
        if (root.contains("TARIF_AGENCE")) {
1261
        if (root.contains("TARIF_AGENCE")) {
1262
            SQLTable tableCmdFA = root.getTable("COMMANDE");
1262
            SQLTable tableCmdFA = root.getTable("COMMANDE");
1263
            if (!tableCmdFA.contains("INCOTERM")) {
1263
            if (!tableCmdFA.contains("INCOTERM")) {
1264
                AlterTable t = new AlterTable(tableCmdFA);
1264
                AlterTable t = new AlterTable(tableCmdFA);
1265
                t.addVarCharColumn("INCOTERM", 256);
1265
                t.addVarCharColumn("INCOTERM", 256);
1266
                tableCmdFA.getBase().getDataSource().execute(t.asString());
1266
                tableCmdFA.getBase().getDataSource().execute(t.asString());
1267
                tableCmdFA.getSchema().updateVersion();
1267
                tableCmdFA.getSchema().updateVersion();
1268
                tableCmdFA.fetchFields();
1268
                tableCmdFA.fetchFields();
1269
            }
1269
            }
1270
 
1270
 
1271
            SQLTable tableArticleA = root.getTable("ARTICLE");
1271
            SQLTable tableArticleA = root.getTable("ARTICLE");
1272
            if (!tableArticleA.contains("CLOSED_KIT")) {
1272
            if (!tableArticleA.contains("CLOSED_KIT")) {
1273
                AlterTable t = new AlterTable(tableArticleA);
1273
                AlterTable t = new AlterTable(tableArticleA);
1274
                t.addBooleanColumn("CLOSED_KIT", Boolean.FALSE, true);
1274
                t.addBooleanColumn("CLOSED_KIT", Boolean.FALSE, true);
1275
                tableArticleA.getBase().getDataSource().execute(t.asString());
1275
                tableArticleA.getBase().getDataSource().execute(t.asString());
1276
                tableArticleA.getSchema().updateVersion();
1276
                tableArticleA.getSchema().updateVersion();
1277
                tableArticleA.fetchFields();
1277
                tableArticleA.fetchFields();
1278
            }
1278
            }
1279
 
1279
 
1280
            if (!tableArticleA.contains("CLOSED_KIT_DESC")) {
1280
            if (!tableArticleA.contains("CLOSED_KIT_DESC")) {
1281
                AlterTable t = new AlterTable(tableArticleA);
1281
                AlterTable t = new AlterTable(tableArticleA);
1282
                t.addVarCharColumn("CLOSED_KIT_DESC", 4096);
1282
                t.addVarCharColumn("CLOSED_KIT_DESC", 4096);
1283
                tableArticleA.getBase().getDataSource().execute(t.asString());
1283
                tableArticleA.getBase().getDataSource().execute(t.asString());
1284
                tableArticleA.getSchema().updateVersion();
1284
                tableArticleA.getSchema().updateVersion();
1285
                tableArticleA.fetchFields();
1285
                tableArticleA.fetchFields();
1286
            }
1286
            }
1287
 
1287
 
1288
            SQLTable tableCmdFEltA = root.getTable("COMMANDE_ELEMENT");
1288
            SQLTable tableCmdFEltA = root.getTable("COMMANDE_ELEMENT");
1289
            if (!tableCmdFEltA.contains("INCOTERM")) {
1289
            if (!tableCmdFEltA.contains("INCOTERM")) {
1290
                AlterTable t = new AlterTable(tableCmdFEltA);
1290
                AlterTable t = new AlterTable(tableCmdFEltA);
1291
                t.addVarCharColumn("INCOTERM", 256);
1291
                t.addVarCharColumn("INCOTERM", 256);
1292
                tableCmdFEltA.getBase().getDataSource().execute(t.asString());
1292
                tableCmdFEltA.getBase().getDataSource().execute(t.asString());
1293
                tableCmdFEltA.getSchema().updateVersion();
1293
                tableCmdFEltA.getSchema().updateVersion();
1294
                tableCmdFEltA.fetchFields();
1294
                tableCmdFEltA.fetchFields();
1295
            }
1295
            }
1296
 
1296
 
1297
            if (root.getTable("VILLE") == null) {
1297
            if (root.getTable("VILLE") == null) {
1298
 
1298
 
1299
                // INSERT INTO "OpenConcerto49"."VILLE" ("CODE_POSTAL","NOM") SELECT
1299
                // INSERT INTO "OpenConcerto49"."VILLE" ("CODE_POSTAL","NOM") SELECT
1300
                // "CODE_POSTAL",
1300
                // "CODE_POSTAL",
1301
                // "VILLE" FROM "OpenConcerto49"."ADRESSE" a WHERE a."ARCHIVE"=0
1301
                // "VILLE" FROM "OpenConcerto49"."ADRESSE" a WHERE a."ARCHIVE"=0
1302
                final SQLCreateTable createTableVille = new SQLCreateTable(root, "VILLE");
1302
                final SQLCreateTable createTableVille = new SQLCreateTable(root, "VILLE");
1303
                createTableVille.addVarCharColumn("NOM", 2048);
1303
                createTableVille.addVarCharColumn("NOM", 2048);
1304
                createTableVille.addVarCharColumn("CODE_POSTAL", 2048);
1304
                createTableVille.addVarCharColumn("CODE_POSTAL", 2048);
1305
                createTableVille.addLongColumn("X_LAMBERT", 0L, true);
1305
                createTableVille.addLongColumn("X_LAMBERT", 0L, true);
1306
                createTableVille.addLongColumn("Y_LAMBERT", 0L, true);
1306
                createTableVille.addLongColumn("Y_LAMBERT", 0L, true);
1307
                createTableVille.addLongColumn("POPULATION", 0L, true);
1307
                createTableVille.addLongColumn("POPULATION", 0L, true);
1308
                try {
1308
                try {
1309
                    root.getBase().getDataSource().execute(createTableVille.asString());
1309
                    root.getBase().getDataSource().execute(createTableVille.asString());
1310
                    insertUndef(createTableVille);
1310
                    insertUndef(createTableVille);
1311
                    root.refetchTable("VILLE");
1311
                    root.refetchTable("VILLE");
1312
                    root.getSchema().updateVersion();
1312
                    root.getSchema().updateVersion();
1313
                } catch (SQLException ex2) {
1313
                } catch (SQLException ex2) {
1314
                    throw new IllegalStateException("Erreur lors de la création de la table " + "VILLE", ex2);
1314
                    throw new IllegalStateException("Erreur lors de la création de la table " + "VILLE", ex2);
1315
                }
1315
                }
1316
            }
1316
            }
1317
 
1317
 
1318
            if (root.getTable("ARTICLE_PRIX_MIN_VENTE") == null) {
1318
            if (root.getTable("ARTICLE_PRIX_MIN_VENTE") == null) {
1319
                final SQLCreateTable createTablePrixMin = new SQLCreateTable(root, "ARTICLE_PRIX_MIN_VENTE");
1319
                final SQLCreateTable createTablePrixMin = new SQLCreateTable(root, "ARTICLE_PRIX_MIN_VENTE");
1320
                createTablePrixMin.addForeignColumn("ARTICLE");
1320
                createTablePrixMin.addForeignColumn("ARTICLE");
1321
                createTablePrixMin.addIntegerColumn("QTE", 1);
1321
                createTablePrixMin.addIntegerColumn("QTE", 1);
1322
                createTablePrixMin.addDecimalColumn("PRIX", 16, 8, BigDecimal.ZERO, true);
1322
                createTablePrixMin.addDecimalColumn("PRIX", 16, 8, BigDecimal.ZERO, true);
1323
                createTablePrixMin.addDateAndTimeColumn("DATE");
1323
                createTablePrixMin.addDateAndTimeColumn("DATE");
1324
                try {
1324
                try {
1325
                    root.getBase().getDataSource().execute(createTablePrixMin.asString());
1325
                    root.getBase().getDataSource().execute(createTablePrixMin.asString());
1326
                    insertUndef(createTablePrixMin);
1326
                    insertUndef(createTablePrixMin);
1327
                    root.refetchTable("ARTICLE_PRIX_MIN_VENTE");
1327
                    root.refetchTable("ARTICLE_PRIX_MIN_VENTE");
1328
                    root.getSchema().updateVersion();
1328
                    root.getSchema().updateVersion();
1329
                } catch (SQLException ex2) {
1329
                } catch (SQLException ex2) {
1330
                    throw new IllegalStateException("Erreur lors de la création de la table " + "ARTICLE_PRIX_MIN_VENTE", ex2);
1330
                    throw new IllegalStateException("Erreur lors de la création de la table " + "ARTICLE_PRIX_MIN_VENTE", ex2);
1331
                }
1331
                }
1332
            }
1332
            }
1333
 
1333
 
1334
            {
1334
            {
1335
                final SQLTable tableTarifAgence = root.getTable("TARIF_AGENCE");
1335
                final SQLTable tableTarifAgence = root.getTable("TARIF_AGENCE");
1336
                AlterTable tTarifAgence = new AlterTable(tableTarifAgence);
1336
                AlterTable tTarifAgence = new AlterTable(tableTarifAgence);
1337
                boolean updateTarifAgence = false;
1337
                boolean updateTarifAgence = false;
1338
 
1338
 
1339
                if (!tableTarifAgence.contains("PRC_AGENCE")) {
1339
                if (!tableTarifAgence.contains("PRC_AGENCE")) {
1340
                    updateTarifAgence = true;
1340
                    updateTarifAgence = true;
1341
                    tTarifAgence.addDecimalColumn("PRC_AGENCE", 16, 8, BigDecimal.ZERO, true);
1341
                    tTarifAgence.addDecimalColumn("PRC_AGENCE", 16, 8, BigDecimal.ZERO, true);
1342
                }
1342
                }
1343
                if (!tableTarifAgence.contains("CLOSED_KIT")) {
1343
                if (!tableTarifAgence.contains("CLOSED_KIT")) {
1344
                    updateTarifAgence = true;
1344
                    updateTarifAgence = true;
1345
                    tTarifAgence.addBooleanColumn("CLOSED_KIT", false, true);
1345
                    tTarifAgence.addBooleanColumn("CLOSED_KIT", false, true);
1346
                }
1346
                }
1347
                if (!tableTarifAgence.contains("PRIX_MIN_VENTE")) {
1347
                if (!tableTarifAgence.contains("PRIX_MIN_VENTE")) {
1348
                    updateTarifAgence = true;
1348
                    updateTarifAgence = true;
1349
                    tTarifAgence.addDecimalColumn("PRIX_MIN_VENTE", 16, 8, BigDecimal.ZERO, true);
1349
                    tTarifAgence.addDecimalColumn("PRIX_MIN_VENTE", 16, 8, BigDecimal.ZERO, true);
1350
                }
1350
                }
1351
 
1351
 
1352
                if (updateTarifAgence) {
1352
                if (updateTarifAgence) {
1353
                    tableTarifAgence.getBase().getDataSource().execute(tTarifAgence.asString());
1353
                    tableTarifAgence.getBase().getDataSource().execute(tTarifAgence.asString());
1354
                    tableTarifAgence.getSchema().updateVersion();
1354
                    tableTarifAgence.getSchema().updateVersion();
1355
                    tableTarifAgence.fetchFields();
1355
                    tableTarifAgence.fetchFields();
1356
                }
1356
                }
1357
            }
1357
            }
1358
            {
1358
            {
1359
                final SQLTable tableClient = root.getTable("CLIENT");
1359
                final SQLTable tableClient = root.getTable("CLIENT");
1360
                AlterTable tClient = new AlterTable(tableClient);
1360
                AlterTable tClient = new AlterTable(tableClient);
1361
                boolean updateClient = false;
1361
                boolean updateClient = false;
1362
 
1362
 
1363
                if (!tableClient.contains("ALG_REGISTRE")) {
1363
                if (!tableClient.contains("ALG_REGISTRE")) {
1364
                    updateClient = true;
1364
                    updateClient = true;
1365
                    tClient.addVarCharColumn("ALG_REGISTRE", 512);
1365
                    tClient.addVarCharColumn("ALG_REGISTRE", 512);
1366
                }
1366
                }
1367
                if (!tableClient.contains("ALG_MATRICULE")) {
1367
                if (!tableClient.contains("ALG_MATRICULE")) {
1368
                    updateClient = true;
1368
                    updateClient = true;
1369
                    tClient.addVarCharColumn("ALG_MATRICULE", 512);
1369
                    tClient.addVarCharColumn("ALG_MATRICULE", 512);
1370
                }
1370
                }
1371
                if (!tableClient.contains("ALG_ARTICLE")) {
1371
                if (!tableClient.contains("ALG_ARTICLE")) {
1372
                    updateClient = true;
1372
                    updateClient = true;
1373
                    tClient.addVarCharColumn("ALG_ARTICLE", 512);
1373
                    tClient.addVarCharColumn("ALG_ARTICLE", 512);
1374
                }
1374
                }
1375
 
1375
 
1376
                if (updateClient) {
1376
                if (updateClient) {
1377
                    tableClient.getBase().getDataSource().execute(tClient.asString());
1377
                    tableClient.getBase().getDataSource().execute(tClient.asString());
1378
                    tableClient.getSchema().updateVersion();
1378
                    tableClient.getSchema().updateVersion();
1379
                    tableClient.fetchFields();
1379
                    tableClient.fetchFields();
1380
                }
1380
                }
1381
            }
1381
            }
1382
            final SQLTable tableMvtStock = root.getTable("MOUVEMENT_STOCK");
1382
            final SQLTable tableMvtStock = root.getTable("MOUVEMENT_STOCK");
1383
 
1383
 
1384
            if (!tableMvtStock.contains("PRICE")) {
1384
            if (!tableMvtStock.contains("PRICE")) {
1385
                AlterTable tMvt = new AlterTable(tableMvtStock);
1385
                AlterTable tMvt = new AlterTable(tableMvtStock);
1386
                tMvt.addDecimalColumn("PRICE", 16, 6, BigDecimal.ZERO, true);
1386
                tMvt.addDecimalColumn("PRICE", 16, 6, BigDecimal.ZERO, true);
1387
                tableMvtStock.getBase().getDataSource().execute(tMvt.asString());
1387
                tableMvtStock.getBase().getDataSource().execute(tMvt.asString());
1388
                tableMvtStock.getSchema().updateVersion();
1388
                tableMvtStock.getSchema().updateVersion();
1389
                tableMvtStock.fetchFields();
1389
                tableMvtStock.fetchFields();
1390
            }
1390
            }
1391
 
1391
 
1392
            final SQLTable tableArticle = root.getTable("ARTICLE");
1392
            final SQLTable tableArticle = root.getTable("ARTICLE");
1393
 
1393
 
1394
            if (!tableArticle.contains("AUTO_PRIX_MIN_VENTE_NOMENCLATURE")) {
1394
            if (!tableArticle.contains("AUTO_PRIX_MIN_VENTE_NOMENCLATURE")) {
1395
                AlterTable tArt = new AlterTable(tableArticle);
1395
                AlterTable tArt = new AlterTable(tableArticle);
1396
                tArt.addBooleanColumn("AUTO_PRIX_MIN_VENTE_NOMENCLATURE", false, true);
1396
                tArt.addBooleanColumn("AUTO_PRIX_MIN_VENTE_NOMENCLATURE", false, true);
1397
                tableMvtStock.getBase().getDataSource().execute(tArt.asString());
1397
                tableMvtStock.getBase().getDataSource().execute(tArt.asString());
1398
                tableMvtStock.getSchema().updateVersion();
1398
                tableMvtStock.getSchema().updateVersion();
1399
                tableMvtStock.fetchFields();
1399
                tableMvtStock.fetchFields();
1400
            }
1400
            }
1401
            SQLTable tableContact = root.getTable("CONTACT");
1401
            SQLTable tableContact = root.getTable("CONTACT");
1402
            if (!tableContact.contains("TYPE")) {
1402
            if (!tableContact.contains("TYPE")) {
1403
                AlterTable t = new AlterTable(tableContact);
1403
                AlterTable t = new AlterTable(tableContact);
1404
                t.addVarCharColumn("TYPE", 256);
1404
                t.addVarCharColumn("TYPE", 256);
1405
                t.addVarCharColumn("SERVICE", 256);
1405
                t.addVarCharColumn("SERVICE", 256);
1406
                t.addVarCharColumn("PAYS", 256);
1406
                t.addVarCharColumn("PAYS", 256);
1407
                t.addForeignColumn("ID_ADRESSE", root.getTable("ADRESSE"));
1407
                t.addForeignColumn("ID_ADRESSE", root.getTable("ADRESSE"));
1408
                tableContact.getBase().getDataSource().execute(t.asString());
1408
                tableContact.getBase().getDataSource().execute(t.asString());
1409
                tableContact.getSchema().updateVersion();
1409
                tableContact.getSchema().updateVersion();
1410
                tableContact.fetchFields();
1410
                tableContact.fetchFields();
1411
            }
1411
            }
1412
 
1412
 
1413
            if (!root.contains("PERSONNEL_AFHYMAT")) {
1413
            if (!root.contains("PERSONNEL_AFHYMAT")) {
1414
                final SQLCreateTable createTablePers = new SQLCreateTable(root, "PERSONNEL_AFHYMAT");
1414
                final SQLCreateTable createTablePers = new SQLCreateTable(root, "PERSONNEL_AFHYMAT");
1415
                createTablePers.addVarCharColumn("NOM", 256);
1415
                createTablePers.addVarCharColumn("NOM", 256);
1416
                createTablePers.addVarCharColumn("PRENOM", 256);
1416
                createTablePers.addVarCharColumn("PRENOM", 256);
1417
                createTablePers.addVarCharColumn("FONCTION", 256);
1417
                createTablePers.addVarCharColumn("FONCTION", 256);
1418
 
1418
 
1419
                try {
1419
                try {
1420
                    root.getBase().getDataSource().execute(createTablePers.asString());
1420
                    root.getBase().getDataSource().execute(createTablePers.asString());
1421
                    insertUndef(createTablePers);
1421
                    insertUndef(createTablePers);
1422
                    root.refetchTable("PERSONNEL_AFHYMAT");
1422
                    root.refetchTable("PERSONNEL_AFHYMAT");
1423
                    root.getSchema().updateVersion();
1423
                    root.getSchema().updateVersion();
1424
                } catch (SQLException ex) {
1424
                } catch (SQLException ex) {
1425
                    throw new IllegalStateException("Erreur lors de la création de la table " + "PERSONNEL_AFHYMAT", ex);
1425
                    throw new IllegalStateException("Erreur lors de la création de la table " + "PERSONNEL_AFHYMAT", ex);
1426
                }
1426
                }
1427
 
1427
 
1428
                final SQLCreateTable createTable = new SQLCreateTable(root, "PERSONNEL_AFHYMAT_COUT");
1428
                final SQLCreateTable createTable = new SQLCreateTable(root, "PERSONNEL_AFHYMAT_COUT");
1429
                for (int i = 1; i <= 12; i++) {
1429
                for (int i = 1; i <= 12; i++) {
1430
                    createTable.addDecimalColumn("SAL_MONTH_" + i, 16, 2, BigDecimal.ZERO, false);
1430
                    createTable.addDecimalColumn("SAL_MONTH_" + i, 16, 2, BigDecimal.ZERO, false);
1431
                    createTable.addDecimalColumn("COM_MONTH_" + i, 16, 2, BigDecimal.ZERO, false);
1431
                    createTable.addDecimalColumn("COM_MONTH_" + i, 16, 2, BigDecimal.ZERO, false);
1432
                }
1432
                }
1433
                createTable.addIntegerColumn("ANNEE", 0);
1433
                createTable.addIntegerColumn("ANNEE", 0);
1434
                createTable.addForeignColumn("ID_PERSONNEL_AFHYMAT", root.getTable("PERSONNEL_AFHYMAT"));
1434
                createTable.addForeignColumn("ID_PERSONNEL_AFHYMAT", root.getTable("PERSONNEL_AFHYMAT"));
1435
 
1435
 
1436
                try {
1436
                try {
1437
                    root.getBase().getDataSource().execute(createTable.asString());
1437
                    root.getBase().getDataSource().execute(createTable.asString());
1438
                    insertUndef(createTable);
1438
                    insertUndef(createTable);
1439
                    root.refetchTable("PERSONNEL_AFHYMAT_COUT");
1439
                    root.refetchTable("PERSONNEL_AFHYMAT_COUT");
1440
                    root.getSchema().updateVersion();
1440
                    root.getSchema().updateVersion();
1441
                } catch (SQLException ex) {
1441
                } catch (SQLException ex) {
1442
                    throw new IllegalStateException("Erreur lors de la création de la table " + "PERSONNEL_AFHYMAT_COUT", ex);
1442
                    throw new IllegalStateException("Erreur lors de la création de la table " + "PERSONNEL_AFHYMAT_COUT", ex);
1443
                }
1443
                }
1444
            }
1444
            }
1445
 
1445
 
1446
            List<String> tablesUiLocked = Arrays.asList("BON_DE_LIVRAISON", "COMMANDE_CLIENT", "SAISIE_VENTE_FACTURE", "AVOIR_CLIENT", "COMMANDE", "BON_RECEPTION", "FACTURE_FOURNISSEUR");
1446
            List<String> tablesUiLocked = Arrays.asList("BON_DE_LIVRAISON", "COMMANDE_CLIENT", "SAISIE_VENTE_FACTURE", "AVOIR_CLIENT", "COMMANDE", "BON_RECEPTION", "FACTURE_FOURNISSEUR");
1447
            for (String tableName : tablesUiLocked) {
1447
            for (String tableName : tablesUiLocked) {
1448
                final SQLTable table = root.getTable(tableName);
1448
                final SQLTable table = root.getTable(tableName);
1449
                AlterTable t = new AlterTable(table);
1449
                AlterTable t = new AlterTable(table);
1450
                if (!table.contains("UI_LOCK")) {
1450
                if (!table.contains("UI_LOCK")) {
1451
                    t.addVarCharColumn("UI_LOCK", 512);
1451
                    t.addVarCharColumn("UI_LOCK", 512);
1452
                    t.addForeignColumn("ID_USER_UI_LOCK", root.findTable("USER_COMMON"));
1452
                    t.addForeignColumn("ID_USER_UI_LOCK", root.findTable("USER_COMMON"));
1453
                    table.getBase().getDataSource().execute(t.asString());
1453
                    table.getBase().getDataSource().execute(t.asString());
1454
                    table.getSchema().updateVersion();
1454
                    table.getSchema().updateVersion();
1455
                    table.fetchFields();
1455
                    table.fetchFields();
1456
                }
1456
                }
1457
 
1457
 
1458
            }
1458
            }
1459
 
1459
 
1460
            if (!root.contains("RELIQUAT_BL")) {
1460
            if (!root.contains("RELIQUAT_BL")) {
1461
                final SQLCreateTable createTable = new SQLCreateTable(root, "RELIQUAT_BL");
1461
                final SQLCreateTable createTable = new SQLCreateTable(root, "RELIQUAT_BL");
1462
                createTable.addForeignColumn("ARTICLE");
1462
                createTable.addForeignColumn("ARTICLE");
1463
                createTable.addForeignColumn("ID_BON_DE_LIVRAISON_ORIGINE", root.getTable("BON_DE_LIVRAISON"));
1463
                createTable.addForeignColumn("ID_BON_DE_LIVRAISON_ORIGINE", root.getTable("BON_DE_LIVRAISON"));
1464
                createTable.addForeignColumn("ID_BON_DE_LIVRAISON", root.getTable("BON_DE_LIVRAISON"));
1464
                createTable.addForeignColumn("ID_BON_DE_LIVRAISON", root.getTable("BON_DE_LIVRAISON"));
1465
                createTable.addForeignColumn("ID_BON_DE_LIVRAISON_ELEMENT", root.getTable("BON_DE_LIVRAISON_ELEMENT"));
1465
                createTable.addForeignColumn("ID_BON_DE_LIVRAISON_ELEMENT", root.getTable("BON_DE_LIVRAISON_ELEMENT"));
1466
                createTable.addIntegerColumn("QTE", 1);
1466
                createTable.addIntegerColumn("QTE", 1);
1467
                createTable.addDecimalColumn("QTE_UNITAIRE", 16, 6, BigDecimal.valueOf(1), false);
1467
                createTable.addDecimalColumn("QTE_UNITAIRE", 16, 6, BigDecimal.valueOf(1), false);
1468
                createTable.addForeignColumn("UNITE_VENTE");
1468
                createTable.addForeignColumn("UNITE_VENTE");
1469
 
1469
 
1470
                try {
1470
                try {
1471
                    root.getBase().getDataSource().execute(createTable.asString());
1471
                    root.getBase().getDataSource().execute(createTable.asString());
1472
                    insertUndef(createTable);
1472
                    insertUndef(createTable);
1473
                    root.refetchTable("RELIQUAT_BL");
1473
                    root.refetchTable("RELIQUAT_BL");
1474
                    root.getSchema().updateVersion();
1474
                    root.getSchema().updateVersion();
1475
                } catch (SQLException ex) {
1475
                } catch (SQLException ex) {
1476
                    throw new IllegalStateException("Erreur lors de la création de la table " + "RELIQUAT_BL", ex);
1476
                    throw new IllegalStateException("Erreur lors de la création de la table " + "RELIQUAT_BL", ex);
1477
                }
1477
                }
1478
            }
1478
            }
1479
 
1479
 
1480
            if (!root.getTable("ARTICLE").contains("TRANSPORT")) {
1480
            if (!root.getTable("ARTICLE").contains("TRANSPORT")) {
1481
                AlterTable alterArticle = new AlterTable(tableArticle);
1481
                AlterTable alterArticle = new AlterTable(tableArticle);
1482
                alterArticle.addBooleanColumn("TRANSPORT", false, false);
1482
                alterArticle.addBooleanColumn("TRANSPORT", false, false);
1483
                tableArticle.getBase().getDataSource().execute(alterArticle.asString());
1483
                tableArticle.getBase().getDataSource().execute(alterArticle.asString());
1484
                tableArticle.getSchema().updateVersion();
1484
                tableArticle.getSchema().updateVersion();
1485
                tableArticle.fetchFields();
1485
                tableArticle.fetchFields();
1486
            }
1486
            }
1487
 
1487
 
1488
            if (!root.contains("RELIQUAT_BR")) {
1488
            if (!root.contains("RELIQUAT_BR")) {
1489
                final SQLCreateTable createTable = new SQLCreateTable(root, "RELIQUAT_BR");
1489
                final SQLCreateTable createTable = new SQLCreateTable(root, "RELIQUAT_BR");
1490
                createTable.addForeignColumn("ARTICLE");
1490
                createTable.addForeignColumn("ARTICLE");
1491
                createTable.addForeignColumn("ID_BON_RECEPTION_ORIGINE", root.getTable("BON_RECEPTION"));
1491
                createTable.addForeignColumn("ID_BON_RECEPTION_ORIGINE", root.getTable("BON_RECEPTION"));
1492
                createTable.addForeignColumn("ID_BON_RECEPTION", root.getTable("BON_RECEPTION"));
1492
                createTable.addForeignColumn("ID_BON_RECEPTION", root.getTable("BON_RECEPTION"));
1493
                createTable.addForeignColumn("ID_BON_RECEPTION_ELEMENT", root.getTable("BON_RECEPTION_ELEMENT"));
1493
                createTable.addForeignColumn("ID_BON_RECEPTION_ELEMENT", root.getTable("BON_RECEPTION_ELEMENT"));
1494
                createTable.addIntegerColumn("QTE", 1);
1494
                createTable.addIntegerColumn("QTE", 1);
1495
                createTable.addDecimalColumn("QTE_UNITAIRE", 16, 6, BigDecimal.valueOf(1), false);
1495
                createTable.addDecimalColumn("QTE_UNITAIRE", 16, 6, BigDecimal.valueOf(1), false);
1496
                createTable.addForeignColumn("UNITE_VENTE");
1496
                createTable.addForeignColumn("UNITE_VENTE");
1497
 
1497
 
1498
                try {
1498
                try {
1499
                    root.getBase().getDataSource().execute(createTable.asString());
1499
                    root.getBase().getDataSource().execute(createTable.asString());
1500
                    insertUndef(createTable);
1500
                    insertUndef(createTable);
1501
                    root.refetchTable("RELIQUAT_BL");
1501
                    root.refetchTable("RELIQUAT_BL");
1502
                    root.getSchema().updateVersion();
1502
                    root.getSchema().updateVersion();
1503
                } catch (SQLException ex) {
1503
                } catch (SQLException ex) {
1504
                    throw new IllegalStateException("Erreur lors de la création de la table " + "RELIQUAT_BR", ex);
1504
                    throw new IllegalStateException("Erreur lors de la création de la table " + "RELIQUAT_BR", ex);
1505
                }
1505
                }
1506
            }
1506
            }
1507
 
1507
 
1508
            {
1508
            {
1509
                if (root.getName().endsWith("54")) {
1509
                if (root.getName().endsWith("54")) {
1510
                    AlterTable tArt = new AlterTable(tableArticle);
1510
                    AlterTable tArt = new AlterTable(tableArticle);
1511
                    if (!tableArticle.contains("LABEL_DOUANE")) {
1511
                    if (!tableArticle.contains("LABEL_DOUANE")) {
1512
                        tArt.addVarCharColumn("LABEL_DOUANE", 512);
1512
                        tArt.addVarCharColumn("LABEL_DOUANE", 512);
1513
                        tableArticle.getBase().getDataSource().execute(tArt.asString());
1513
                        tableArticle.getBase().getDataSource().execute(tArt.asString());
1514
                        tableArticle.getSchema().updateVersion();
1514
                        tableArticle.getSchema().updateVersion();
1515
                        tableArticle.fetchFields();
1515
                        tableArticle.fetchFields();
1516
                    }
1516
                    }
1517
                }
1517
                }
1518
            }
1518
            }
1519
 
1519
 
1520
            {
1520
            {
1521
                final SQLTable tableFour = root.getTable("FOURNISSEUR");
1521
                final SQLTable tableFour = root.getTable("FOURNISSEUR");
1522
                AlterTable tFour = new AlterTable(tableFour);
1522
                AlterTable tFour = new AlterTable(tableFour);
1523
                boolean updateFour = false;
1523
                boolean updateFour = false;
1524
 
1524
 
1525
                if (!tableFour.contains("ALG_REGISTRE")) {
1525
                if (!tableFour.contains("ALG_REGISTRE")) {
1526
                    updateFour = true;
1526
                    updateFour = true;
1527
                    tFour.addVarCharColumn("ALG_REGISTRE", 512);
1527
                    tFour.addVarCharColumn("ALG_REGISTRE", 512);
1528
                }
1528
                }
1529
                if (!tableFour.contains("ALG_MATRICULE")) {
1529
                if (!tableFour.contains("ALG_MATRICULE")) {
1530
                    updateFour = true;
1530
                    updateFour = true;
1531
                    tFour.addVarCharColumn("ALG_MATRICULE", 512);
1531
                    tFour.addVarCharColumn("ALG_MATRICULE", 512);
1532
                }
1532
                }
1533
                if (!tableFour.contains("ALG_ARTICLE")) {
1533
                if (!tableFour.contains("ALG_ARTICLE")) {
1534
                    updateFour = true;
1534
                    updateFour = true;
1535
                    tFour.addVarCharColumn("ALG_ARTICLE", 512);
1535
                    tFour.addVarCharColumn("ALG_ARTICLE", 512);
1536
                }
1536
                }
1537
 
1537
 
1538
                if (updateFour) {
1538
                if (updateFour) {
1539
                    tableFour.getBase().getDataSource().execute(tFour.asString());
1539
                    tableFour.getBase().getDataSource().execute(tFour.asString());
1540
                    tableFour.getSchema().updateVersion();
1540
                    tableFour.getSchema().updateVersion();
1541
                    tableFour.fetchFields();
1541
                    tableFour.fetchFields();
1542
                }
1542
                }
1543
            }
1543
            }
1544
 
1544
 
1545
        }
1545
        }
1546
 
1546
 
1547
        if (root.getTable("COEFF_PRIME") == null) {
1547
        if (root.getTable("COEFF_PRIME") == null) {
1548
            final SQLCreateTable createTable = new SQLCreateTable(root, "COEFF_PRIME");
1548
            final SQLCreateTable createTable = new SQLCreateTable(root, "COEFF_PRIME");
1549
            // TODO numeric to real
1549
            // TODO numeric to real
1550
            createTable.addColumn("PRIME_PERSO", "real DEFAULT 0");
1550
            createTable.addColumn("PRIME_PERSO", "real DEFAULT 0");
1551
            createTable.addColumn("PRIME_RECONSTRUCTION", "real DEFAULT 0");
1551
            createTable.addColumn("PRIME_RECONSTRUCTION", "real DEFAULT 0");
1552
            createTable.addColumn("PRIME_ANCIENNETE", "real DEFAULT 0");
1552
            createTable.addColumn("PRIME_ANCIENNETE", "real DEFAULT 0");
1553
            createTable.addColumn("PRIME_DEROULEMENT", "real DEFAULT 0");
1553
            createTable.addColumn("PRIME_DEROULEMENT", "real DEFAULT 0");
1554
 
1554
 
1555
            try {
1555
            try {
1556
                root.getDBSystemRoot().getDataSource().execute(createTable.asString());
1556
                root.getDBSystemRoot().getDataSource().execute(createTable.asString());
1557
                insertUndef(createTable);
1557
                insertUndef(createTable);
1558
                root.refetchTable("COEFF_PRIME");
1558
                root.refetchTable("COEFF_PRIME");
1559
                root.getSchema().updateVersion();
1559
                root.getSchema().updateVersion();
1560
            } catch (SQLException ex) {
1560
            } catch (SQLException ex) {
1561
                throw new IllegalStateException("Erreur lors de la création de la table " + "COEFF_PRIME", ex);
1561
                throw new IllegalStateException("Erreur lors de la création de la table " + "COEFF_PRIME", ex);
1562
            }
1562
            }
1563
 
1563
 
1564
            SQLTable tableInfosSal = root.getTable("INFOS_SALARIE_PAYE");
1564
            SQLTable tableInfosSal = root.getTable("INFOS_SALARIE_PAYE");
1565
            if (!tableInfosSal.contains("ID_COEFF_PRIME")) {
1565
            if (!tableInfosSal.contains("ID_COEFF_PRIME")) {
1566
                AlterTable t = new AlterTable(tableInfosSal);
1566
                AlterTable t = new AlterTable(tableInfosSal);
1567
                t.addForeignColumn("ID_COEFF_PRIME", root.getTable("COEFF_PRIME"));
1567
                t.addForeignColumn("ID_COEFF_PRIME", root.getTable("COEFF_PRIME"));
1568
 
1568
 
1569
                try {
1569
                try {
1570
 
1570
 
1571
                    tableInfosSal.getBase().getDataSource().execute(t.asString());
1571
                    tableInfosSal.getBase().getDataSource().execute(t.asString());
1572
                    tableInfosSal.getSchema().updateVersion();
1572
                    tableInfosSal.getSchema().updateVersion();
1573
                    tableInfosSal.fetchFields();
1573
                    tableInfosSal.fetchFields();
1574
                } catch (SQLException ex) {
1574
                } catch (SQLException ex) {
1575
                    throw new IllegalStateException("Erreur lors de l'ajout des champs à la table " + tableInfosSal.getName(), ex);
1575
                    throw new IllegalStateException("Erreur lors de l'ajout des champs à la table " + tableInfosSal.getName(), ex);
1576
                }
1576
                }
1577
            }
1577
            }
1578
        }
1578
        }
1579
 
1579
 
1580
        SQLTable tableInfosSal = root.getTable("INFOS_SALARIE_PAYE");
1580
        SQLTable tableInfosSal = root.getTable("INFOS_SALARIE_PAYE");
1581
        if (!tableInfosSal.contains("ID_SALARIE")) {
1581
        if (!tableInfosSal.contains("ID_SALARIE")) {
1582
            // Ajout INFOS_SALARIE_PAYE.ID_SALARIE
1582
            // Ajout INFOS_SALARIE_PAYE.ID_SALARIE
1583
            AlterTable t = new AlterTable(tableInfosSal);
1583
            AlterTable t = new AlterTable(tableInfosSal);
1584
            t.addForeignColumn("ID_SALARIE", root.getTable("SALARIE"));
1584
            t.addForeignColumn("ID_SALARIE", root.getTable("SALARIE"));
1585
 
1585
 
1586
            try {
1586
            try {
1587
 
1587
 
1588
                tableInfosSal.getBase().getDataSource().execute(t.asString());
1588
                tableInfosSal.getBase().getDataSource().execute(t.asString());
1589
                tableInfosSal.getSchema().updateVersion();
1589
                tableInfosSal.getSchema().updateVersion();
1590
                tableInfosSal.fetchFields();
1590
                tableInfosSal.fetchFields();
1591
            } catch (SQLException ex) {
1591
            } catch (SQLException ex) {
1592
                throw new IllegalStateException("Erreur lors de l'ajout des champs à la table " + tableInfosSal.getName(), ex);
1592
                throw new IllegalStateException("Erreur lors de l'ajout des champs à la table " + tableInfosSal.getName(), ex);
1593
            }
1593
            }
1594
 
1594
 
1595
            // Ajout CONTRAT.DEBUT_CONTRAT
1595
            // Ajout CONTRAT.DEBUT_CONTRAT
1596
            SQLTable tableContrat = root.getTable("CONTRAT_SALARIE");
1596
            SQLTable tableContrat = root.getTable("CONTRAT_SALARIE");
1597
            AlterTable tContrat = new AlterTable(tableContrat);
1597
            AlterTable tContrat = new AlterTable(tableContrat);
1598
            tContrat.addDateAndTimeColumn("DATE_DEBUT");
1598
            tContrat.addDateAndTimeColumn("DATE_DEBUT");
1599
            tContrat.addDateAndTimeColumn("DATE_MODIFICATION");
1599
            tContrat.addDateAndTimeColumn("DATE_MODIFICATION");
1600
            // tContrat.addForeignColumn("ID_INFOS_SALARIE_PAYE_MODIFIE", tableInfosSal);
1600
            // tContrat.addForeignColumn("ID_INFOS_SALARIE_PAYE_MODIFIE", tableInfosSal);
1601
            try {
1601
            try {
1602
                tableContrat.getBase().getDataSource().execute(tContrat.asString());
1602
                tableContrat.getBase().getDataSource().execute(tContrat.asString());
1603
                tableContrat.getSchema().updateVersion();
1603
                tableContrat.getSchema().updateVersion();
1604
                tableContrat.fetchFields();
1604
                tableContrat.fetchFields();
1605
            } catch (SQLException ex) {
1605
            } catch (SQLException ex) {
1606
                throw new IllegalStateException("Erreur lors de l'ajout des champs à la table " + tableContrat.getName(), ex);
1606
                throw new IllegalStateException("Erreur lors de l'ajout des champs à la table " + tableContrat.getName(), ex);
1607
            }
1607
            }
1608
 
1608
 
1609
            // Ajout FICHE_PAYE.INFOS_SALARIE_PAYE
1609
            // Ajout FICHE_PAYE.INFOS_SALARIE_PAYE
1610
            SQLTable tableFichePaye = root.getTable("FICHE_PAYE");
1610
            SQLTable tableFichePaye = root.getTable("FICHE_PAYE");
1611
            AlterTable tFicheSal = new AlterTable(tableFichePaye);
1611
            AlterTable tFicheSal = new AlterTable(tableFichePaye);
1612
            tFicheSal.addForeignColumn("ID_INFOS_SALARIE_PAYE", root.getTable("INFOS_SALARIE_PAYE"));
1612
            tFicheSal.addForeignColumn("ID_INFOS_SALARIE_PAYE", root.getTable("INFOS_SALARIE_PAYE"));
1613
            try {
1613
            try {
1614
 
1614
 
1615
                tableFichePaye.getBase().getDataSource().execute(tFicheSal.asString());
1615
                tableFichePaye.getBase().getDataSource().execute(tFicheSal.asString());
1616
                tableFichePaye.getSchema().updateVersion();
1616
                tableFichePaye.getSchema().updateVersion();
1617
                tableFichePaye.fetchFields();
1617
                tableFichePaye.fetchFields();
1618
            } catch (SQLException ex) {
1618
            } catch (SQLException ex) {
1619
                throw new IllegalStateException("Erreur lors de l'ajout des champs à la table " + tableFichePaye.getName(), ex);
1619
                throw new IllegalStateException("Erreur lors de l'ajout des champs à la table " + tableFichePaye.getName(), ex);
1620
            }
1620
            }
1621
 
1621
 
1622
            {
1622
            {
1623
                // Mise à jour des dates de début de contrat
1623
                // Mise à jour des dates de début de contrat
1624
                UpdateBuilder builderContrat = new UpdateBuilder(tableContrat);
1624
                UpdateBuilder builderContrat = new UpdateBuilder(tableContrat);
1625
                builderContrat.addBackwardVirtualJoin(tableInfosSal, "ID_CONTRAT_SALARIE");
1625
                builderContrat.addBackwardVirtualJoin(tableInfosSal, "ID_CONTRAT_SALARIE");
1626
                builderContrat.setFromVirtualJoinField("DATE_DEBUT", tableInfosSal.getAlias(), "DATE_ARRIVE");
1626
                builderContrat.setFromVirtualJoinField("DATE_DEBUT", tableInfosSal.getAlias(), "DATE_ARRIVE");
1627
                tableInfosSal.getDBSystemRoot().getDataSource().execute(builderContrat.asString());
1627
                tableInfosSal.getDBSystemRoot().getDataSource().execute(builderContrat.asString());
1628
            }
1628
            }
1629
            {
1629
            {
1630
                // Mise à jour des INFOS_SALARIE_PAYE dans les fiches
1630
                // Mise à jour des INFOS_SALARIE_PAYE dans les fiches
1631
                SQLTable tableSalarie = root.getTable("SALARIE");
1631
                SQLTable tableSalarie = root.getTable("SALARIE");
1632
                UpdateBuilder builderFiche = new UpdateBuilder(tableFichePaye);
1632
                UpdateBuilder builderFiche = new UpdateBuilder(tableFichePaye);
1633
                builderFiche.addForwardVirtualJoin(tableSalarie, "ID_SALARIE");
1633
                builderFiche.addForwardVirtualJoin(tableSalarie, "ID_SALARIE");
1634
                builderFiche.setFromVirtualJoinField("ID_INFOS_SALARIE_PAYE", tableSalarie.getAlias(), "ID_INFOS_SALARIE_PAYE");
1634
                builderFiche.setFromVirtualJoinField("ID_INFOS_SALARIE_PAYE", tableSalarie.getAlias(), "ID_INFOS_SALARIE_PAYE");
1635
                tableInfosSal.getDBSystemRoot().getDataSource().execute(builderFiche.asString());
1635
                tableInfosSal.getDBSystemRoot().getDataSource().execute(builderFiche.asString());
1636
            }
1636
            }
1637
        }
1637
        }
1638
 
1638
 
1639
        // Cumuls paye
1639
        // Cumuls paye
1640
        SQLTable tableCumulsPaye = root.getTable("CUMULS_PAYE");
1640
        SQLTable tableCumulsPaye = root.getTable("CUMULS_PAYE");
1641
 
1641
 
1642
        AlterTable tCumuls = new AlterTable(tableCumulsPaye);
1642
        AlterTable tCumuls = new AlterTable(tableCumulsPaye);
1643
        tCumuls.alterColumn("NET_IMP_C", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1643
        tCumuls.alterColumn("NET_IMP_C", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1644
        tCumuls.alterColumn("COT_PAT_C", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1644
        tCumuls.alterColumn("COT_PAT_C", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1645
        tCumuls.alterColumn("COT_SAL_C", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1645
        tCumuls.alterColumn("COT_SAL_C", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1646
        tCumuls.alterColumn("SAL_BRUT_C", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1646
        tCumuls.alterColumn("SAL_BRUT_C", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1647
        tCumuls.alterColumn("NET_A_PAYER_C", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1647
        tCumuls.alterColumn("NET_A_PAYER_C", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1648
        tCumuls.alterColumn("CSG_C", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1648
        tCumuls.alterColumn("CSG_C", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1649
        if (tableCumulsPaye.contains("HEURE_TRAV") && !tableCumulsPaye.contains("HEURE_TRAV_C")) {
1649
        if (tableCumulsPaye.contains("HEURE_TRAV") && !tableCumulsPaye.contains("HEURE_TRAV_C")) {
1650
 
1650
 
1651
            AlterTable tColumnNameCumuls = new AlterTable(tableCumulsPaye);
1651
            AlterTable tColumnNameCumuls = new AlterTable(tableCumulsPaye);
1652
 
1652
 
1653
            tColumnNameCumuls.addClause(new DeferredClause() {
1653
            tColumnNameCumuls.addClause(new DeferredClause() {
1654
                @Override
1654
                @Override
1655
                public String asString(ChangeTable<?> ct, SQLName tableName) {
1655
                public String asString(ChangeTable<?> ct, SQLName tableName) {
1656
                    return (root.getServer().getSQLSystem() == SQLSystem.POSTGRESQL ? "RENAME COLUMN \"HEURE_TRAV\" TO \"HEURE_TRAV_C\"" : "ALTER COLUMN \"HEURE_TRAV\" RENAME TO \"HEURE_TRAV_C\"");
1656
                    return (root.getServer().getSQLSystem() == SQLSystem.POSTGRESQL ? "RENAME COLUMN \"HEURE_TRAV\" TO \"HEURE_TRAV_C\"" : "ALTER COLUMN \"HEURE_TRAV\" RENAME TO \"HEURE_TRAV_C\"");
1657
                }
1657
                }
1658
 
1658
 
1659
                @Override
1659
                @Override
1660
                public ClauseType getType() {
1660
                public ClauseType getType() {
1661
                    return ClauseType.OTHER;
1661
                    return ClauseType.OTHER;
1662
                }
1662
                }
1663
            });
1663
            });
1664
            try {
1664
            try {
1665
 
1665
 
1666
                tableCumulsPaye.getBase().getDataSource().execute(tColumnNameCumuls.asString());
1666
                tableCumulsPaye.getBase().getDataSource().execute(tColumnNameCumuls.asString());
1667
                tableCumulsPaye.getSchema().updateVersion();
1667
                tableCumulsPaye.getSchema().updateVersion();
1668
                tableCumulsPaye.fetchFields();
1668
                tableCumulsPaye.fetchFields();
1669
            } catch (SQLException ex) {
1669
            } catch (SQLException ex) {
1670
                throw new IllegalStateException("Erreur lors de la modification du champ de la table " + tableCumulsPaye.getName(), ex);
1670
                throw new IllegalStateException("Erreur lors de la modification du champ de la table " + tableCumulsPaye.getName(), ex);
1671
            }
1671
            }
1672
        } else if (!tableCumulsPaye.contains("HEURE_TRAV_C")) {
1672
        } else if (!tableCumulsPaye.contains("HEURE_TRAV_C")) {
1673
            tCumuls.addDecimalColumn("HEURE_TRAV_C", 16, 2, BigDecimal.ZERO, false);
1673
            tCumuls.addDecimalColumn("HEURE_TRAV_C", 16, 2, BigDecimal.ZERO, false);
1674
        }
1674
        }
1675
 
1675
 
1676
        try {
1676
        try {
1677
 
1677
 
1678
            tableCumulsPaye.getBase().getDataSource().execute(tCumuls.asString());
1678
            tableCumulsPaye.getBase().getDataSource().execute(tCumuls.asString());
1679
            tableCumulsPaye.getSchema().updateVersion();
1679
            tableCumulsPaye.getSchema().updateVersion();
1680
            tableCumulsPaye.fetchFields();
1680
            tableCumulsPaye.fetchFields();
1681
        } catch (SQLException ex) {
1681
        } catch (SQLException ex) {
1682
            throw new IllegalStateException("Erreur lors de la modification des champs de la table " + tableCumulsPaye.getName(), ex);
1682
            throw new IllegalStateException("Erreur lors de la modification des champs de la table " + tableCumulsPaye.getName(), ex);
1683
        }
1683
        }
1684
 
1684
 
1685
        // element paye
1685
        // element paye
1686
        SQLTable tableElementPaye = root.getTable("FICHE_PAYE_ELEMENT");
1686
        SQLTable tableElementPaye = root.getTable("FICHE_PAYE_ELEMENT");
1687
 
1687
 
1688
        AlterTable tEltPaye = new AlterTable(tableElementPaye);
1688
        AlterTable tEltPaye = new AlterTable(tableElementPaye);
1689
        tEltPaye.alterColumn("TAUX_PAT", EnumSet.allOf(Properties.class), "numeric(16,6)", "0", true);
1689
        tEltPaye.alterColumn("TAUX_PAT", EnumSet.allOf(Properties.class), "numeric(16,6)", "0", true);
1690
        tEltPaye.alterColumn("MONTANT_SAL_AJ", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1690
        tEltPaye.alterColumn("MONTANT_SAL_AJ", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1691
        tEltPaye.alterColumn("TAUX_SAL", EnumSet.allOf(Properties.class), "numeric(16,6)", "0", true);
1691
        tEltPaye.alterColumn("TAUX_SAL", EnumSet.allOf(Properties.class), "numeric(16,6)", "0", true);
1692
        tEltPaye.alterColumn("MONTANT_SAL_DED", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1692
        tEltPaye.alterColumn("MONTANT_SAL_DED", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1693
        tEltPaye.alterColumn("MONTANT_PAT", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1693
        tEltPaye.alterColumn("MONTANT_PAT", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1694
        tEltPaye.alterColumn("NB_BASE", EnumSet.allOf(Properties.class), "numeric(16,6)", "0", true);
1694
        tEltPaye.alterColumn("NB_BASE", EnumSet.allOf(Properties.class), "numeric(16,6)", "0", true);
1695
 
1695
 
1696
        try {
1696
        try {
1697
 
1697
 
1698
            tableElementPaye.getBase().getDataSource().execute(tEltPaye.asString());
1698
            tableElementPaye.getBase().getDataSource().execute(tEltPaye.asString());
1699
            tableElementPaye.getSchema().updateVersion();
1699
            tableElementPaye.getSchema().updateVersion();
1700
            tableElementPaye.fetchFields();
1700
            tableElementPaye.fetchFields();
1701
        } catch (SQLException ex) {
1701
        } catch (SQLException ex) {
1702
            throw new IllegalStateException("Erreur lors de la modification des champs de la table " + tableElementPaye.getName(), ex);
1702
            throw new IllegalStateException("Erreur lors de la modification des champs de la table " + tableElementPaye.getName(), ex);
1703
        }
1703
        }
1704
 
1704
 
1705
        // paye
1705
        // paye
1706
        SQLTable tablePaye = root.getTable("FICHE_PAYE");
1706
        SQLTable tablePaye = root.getTable("FICHE_PAYE");
1707
 
1707
 
1708
        AlterTable tPaye = new AlterTable(tablePaye);
1708
        AlterTable tPaye = new AlterTable(tablePaye);
1709
        tPaye.alterColumn("ACOMPTE", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1709
        tPaye.alterColumn("ACOMPTE", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1710
        tPaye.alterColumn("NET_IMP", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1710
        tPaye.alterColumn("NET_IMP", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1711
        tPaye.alterColumn("COT_PAT", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1711
        tPaye.alterColumn("COT_PAT", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1712
        tPaye.alterColumn("NET_A_PAYER", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1712
        tPaye.alterColumn("NET_A_PAYER", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1713
        tPaye.alterColumn("SAL_BRUT", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1713
        tPaye.alterColumn("SAL_BRUT", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1714
        tPaye.alterColumn("CSG", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1714
        tPaye.alterColumn("CSG", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1715
        tPaye.alterColumn("COT_SAL", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1715
        tPaye.alterColumn("COT_SAL", EnumSet.allOf(Properties.class), "numeric(16,2)", "0", true);
1716
 
1716
 
1717
        try {
1717
        try {
1718
            tablePaye.getBase().getDataSource().execute(tPaye.asString());
1718
            tablePaye.getBase().getDataSource().execute(tPaye.asString());
1719
            tablePaye.getSchema().updateVersion();
1719
            tablePaye.getSchema().updateVersion();
1720
            tablePaye.fetchFields();
1720
            tablePaye.fetchFields();
1721
        } catch (SQLException ex) {
1721
        } catch (SQLException ex) {
1722
            throw new IllegalStateException("Erreur lors de la modification des champs de la table " + tablePaye.getName(), ex);
1722
            throw new IllegalStateException("Erreur lors de la modification des champs de la table " + tablePaye.getName(), ex);
1723
        }
1723
        }
1724
 
1724
 
1725
        if (root.getTable("ARTICLE_ELEMENT") == null) {
1725
        if (root.getTable("ARTICLE_ELEMENT") == null) {
1726
            final SQLCreateTable createTable = new SQLCreateTable(root, "ARTICLE_ELEMENT");
1726
            final SQLCreateTable createTable = new SQLCreateTable(root, "ARTICLE_ELEMENT");
1727
            createTable.addForeignColumn("ARTICLE");
1727
            createTable.addForeignColumn("ARTICLE");
1728
            createTable.addForeignColumn("ID_ARTICLE_PARENT", root.getTable("ARTICLE"));
1728
            createTable.addForeignColumn("ID_ARTICLE_PARENT", root.getTable("ARTICLE"));
1729
            createTable.addIntegerColumn("QTE", 1);
1729
            createTable.addIntegerColumn("QTE", 1);
1730
            createTable.addDecimalColumn("QTE_UNITAIRE", 16, 6, BigDecimal.valueOf(1), false);
1730
            createTable.addDecimalColumn("QTE_UNITAIRE", 16, 6, BigDecimal.valueOf(1), false);
1731
            createTable.addForeignColumn("UNITE_VENTE");
1731
            createTable.addForeignColumn("UNITE_VENTE");
1732
            try {
1732
            try {
1733
                root.getBase().getDataSource().execute(createTable.asString());
1733
                root.getBase().getDataSource().execute(createTable.asString());
1734
                insertUndef(createTable);
1734
                insertUndef(createTable);
1735
                root.refetchTable("ARTICLE_ELEMENT");
1735
                root.refetchTable("ARTICLE_ELEMENT");
1736
                root.getSchema().updateVersion();
1736
                root.getSchema().updateVersion();
1737
            } catch (SQLException ex) {
1737
            } catch (SQLException ex) {
1738
                throw new IllegalStateException("Erreur lors de la création de la table " + "ARTICLE_ELEMENT", ex);
1738
                throw new IllegalStateException("Erreur lors de la création de la table " + "ARTICLE_ELEMENT", ex);
1739
            }
1739
            }
1740
        }
1740
        }
1741
 
1741
 
1742
        if (root.getTable("VILLE") == null) {
1742
        if (root.getTable("VILLE") == null) {
1743
            final SQLCreateTable createTable = new SQLCreateTable(root, "VILLE");
1743
            final SQLCreateTable createTable = new SQLCreateTable(root, "VILLE");
1744
            createTable.addLongColumn("X_LAMBERT", 0L, true);
1744
            createTable.addLongColumn("X_LAMBERT", 0L, true);
1745
            createTable.addLongColumn("Y_LAMBERT", 0L, true);
1745
            createTable.addLongColumn("Y_LAMBERT", 0L, true);
1746
            createTable.addLongColumn("POPULATION", 0L, true);
1746
            createTable.addLongColumn("POPULATION", 0L, true);
1747
            createTable.addVarCharColumn("NOM", 512);
1747
            createTable.addVarCharColumn("NOM", 512);
1748
            createTable.addVarCharColumn("CODE_POSTAL", 256);
1748
            createTable.addVarCharColumn("CODE_POSTAL", 256);
1749
            try {
1749
            try {
1750
                root.getBase().getDataSource().execute(createTable.asString());
1750
                root.getBase().getDataSource().execute(createTable.asString());
1751
                insertUndef(createTable);
1751
                insertUndef(createTable);
1752
                root.refetchTable("VILLE");
1752
                root.refetchTable("VILLE");
1753
                root.getSchema().updateVersion();
1753
                root.getSchema().updateVersion();
1754
            } catch (SQLException ex) {
1754
            } catch (SQLException ex) {
1755
                throw new IllegalStateException("Erreur lors de la création de la table " + "VILLE", ex);
1755
                throw new IllegalStateException("Erreur lors de la création de la table " + "VILLE", ex);
1756
            }
1756
            }
1757
        }
1757
        }
1758
 
1758
 
1759
        // Gestion des différentes numérotation
1759
        // Gestion des différentes numérotation
1760
        if (!root.getTable("NUMEROTATION_AUTO").contains("NOM")) {
1760
        if (!root.getTable("NUMEROTATION_AUTO").contains("NOM")) {
1761
            final SQLTable tableNum = root.getTable("NUMEROTATION_AUTO");
1761
            final SQLTable tableNum = root.getTable("NUMEROTATION_AUTO");
1762
            AlterTable tNum = new AlterTable(tableNum);
1762
            AlterTable tNum = new AlterTable(tableNum);
1763
            tNum.addColumn("NOM", "varchar (256)", "'Standard'", true);
1763
            tNum.addColumn("NOM", "varchar (256)", "'Standard'", true);
1764
 
1764
 
1765
            root.getBase().getDataSource().execute(tNum.asString());
1765
            root.getBase().getDataSource().execute(tNum.asString());
1766
            tableNum.fetchFields();
1766
            tableNum.fetchFields();
1767
            root.getSchema().updateVersion();
1767
            root.getSchema().updateVersion();
1768
 
1768
 
1769
        }
1769
        }
1770
 
1770
 
1771
        // Gestion du timbre fiscal
1771
        // Gestion du timbre fiscal
1772
        if (!root.getTable("CLIENT").contains("TIMBRE_FISCAL")) {
1772
        if (!root.getTable("CLIENT").contains("TIMBRE_FISCAL")) {
1773
            AlterTable tClient = new AlterTable(root.getTable("CLIENT"));
1773
            AlterTable tClient = new AlterTable(root.getTable("CLIENT"));
1774
            tClient.addBooleanColumn("TIMBRE_FISCAL", Boolean.FALSE, false);
1774
            tClient.addBooleanColumn("TIMBRE_FISCAL", Boolean.FALSE, false);
1775
            root.getBase().getDataSource().execute(tClient.asString());
1775
            root.getBase().getDataSource().execute(tClient.asString());
1776
            root.getSchema().updateVersion();
1776
            root.getSchema().updateVersion();
1777
        }
1777
        }
1778
        // Obsolete
1778
        // Obsolete
1779
        if (!root.getTable("CLIENT").contains("OBSOLETE")) {
1779
        if (!root.getTable("CLIENT").contains("OBSOLETE")) {
1780
            AlterTable tClient = new AlterTable(root.getTable("CLIENT"));
1780
            AlterTable tClient = new AlterTable(root.getTable("CLIENT"));
1781
            tClient.addBooleanColumn("OBSOLETE", Boolean.FALSE, false);
1781
            tClient.addBooleanColumn("OBSOLETE", Boolean.FALSE, false);
1782
            root.getBase().getDataSource().execute(tClient.asString());
1782
            root.getBase().getDataSource().execute(tClient.asString());
1783
            root.getSchema().updateVersion();
1783
            root.getSchema().updateVersion();
1784
        }
1784
        }
1785
 
1785
 
1786
        // Relance
1786
        // Relance
1787
        if (!root.getTable("RELANCE").contains("ID_ECHEANCE_CLIENT")) {
1787
        if (!root.getTable("RELANCE").contains("ID_ECHEANCE_CLIENT")) {
1788
            AlterTable tRelance = new AlterTable(root.getTable("RELANCE"));
1788
            AlterTable tRelance = new AlterTable(root.getTable("RELANCE"));
1789
            tRelance.addForeignColumn("ID_ECHEANCE_CLIENT", root.getTable("ECHEANCE_CLIENT"));
1789
            tRelance.addForeignColumn("ID_ECHEANCE_CLIENT", root.getTable("ECHEANCE_CLIENT"));
1790
            root.getBase().getDataSource().execute(tRelance.asString());
1790
            root.getBase().getDataSource().execute(tRelance.asString());
1791
            root.getSchema().updateVersion();
1791
            root.getSchema().updateVersion();
1792
        }
1792
        }
1793
 
1793
 
1794
        if (!root.getTable("AVOIR_CLIENT_ELEMENT").contains("RETOUR_STOCK")) {
1794
        if (!root.getTable("AVOIR_CLIENT_ELEMENT").contains("RETOUR_STOCK")) {
1795
            final SQLTable tableAvoirElt = root.getTable("AVOIR_CLIENT_ELEMENT");
1795
            final SQLTable tableAvoirElt = root.getTable("AVOIR_CLIENT_ELEMENT");
1796
            AlterTable tAvoir = new AlterTable(tableAvoirElt);
1796
            AlterTable tAvoir = new AlterTable(tableAvoirElt);
1797
            tAvoir.addBooleanColumn("RETOUR_STOCK", Boolean.FALSE, false);
1797
            tAvoir.addBooleanColumn("RETOUR_STOCK", Boolean.FALSE, false);
1798
            root.getBase().getDataSource().execute(tAvoir.asString());
1798
            root.getBase().getDataSource().execute(tAvoir.asString());
1799
            root.getSchema().updateVersion();
1799
            root.getSchema().updateVersion();
1800
            tableAvoirElt.fetchFields();
1800
            tableAvoirElt.fetchFields();
1801
        }
1801
        }
1802
 
1802
 
1803
        final SQLTable tableVenteFacture = root.getTable("SAISIE_VENTE_FACTURE");
1803
        final SQLTable tableVenteFacture = root.getTable("SAISIE_VENTE_FACTURE");
1804
        AlterTable tFacture = new AlterTable(tableVenteFacture);
1804
        AlterTable tFacture = new AlterTable(tableVenteFacture);
1805
        boolean alterFacture = false;
1805
        boolean alterFacture = false;
1806
        boolean upNET = false;
1806
        boolean upNET = false;
1807
        if (!tableVenteFacture.contains("SOUMIS_TIMBRE_FISCAL")) {
1807
        if (!tableVenteFacture.contains("SOUMIS_TIMBRE_FISCAL")) {
1808
            tFacture.addBooleanColumn("SOUMIS_TIMBRE_FISCAL", Boolean.FALSE, true);
1808
            tFacture.addBooleanColumn("SOUMIS_TIMBRE_FISCAL", Boolean.FALSE, true);
1809
            alterFacture = true;
1809
            alterFacture = true;
1810
        }
1810
        }
1811
        if (!tableVenteFacture.contains("TAUX_TIMBRE_FISCAL")) {
1811
        if (!tableVenteFacture.contains("TAUX_TIMBRE_FISCAL")) {
1812
            tFacture.addDecimalColumn("TAUX_TIMBRE_FISCAL", 16, 4, BigDecimal.ONE, true);
1812
            tFacture.addDecimalColumn("TAUX_TIMBRE_FISCAL", 16, 4, BigDecimal.ONE, true);
1813
            alterFacture = true;
1813
            alterFacture = true;
1814
        }
1814
        }
1815
        if (!tableVenteFacture.contains("TOTAL_TIMBRE_FISCAL")) {
1815
        if (!tableVenteFacture.contains("TOTAL_TIMBRE_FISCAL")) {
1816
            tFacture.addLongColumn("TOTAL_TIMBRE_FISCAL", 0L, true);
1816
            tFacture.addLongColumn("TOTAL_TIMBRE_FISCAL", 0L, true);
1817
            alterFacture = true;
1817
            alterFacture = true;
1818
        }
1818
        }
1819
        if (!tableVenteFacture.contains("NET_A_PAYER")) {
1819
        if (!tableVenteFacture.contains("NET_A_PAYER")) {
1820
            tFacture.addLongColumn("NET_A_PAYER", 0L, true);
1820
            tFacture.addLongColumn("NET_A_PAYER", 0L, true);
1821
            alterFacture = true;
1821
            alterFacture = true;
1822
            upNET = true;
1822
            upNET = true;
1823
        }
1823
        }
1824
        if (alterFacture) {
1824
        if (alterFacture) {
1825
            root.getBase().getDataSource().execute(tFacture.asString());
1825
            root.getBase().getDataSource().execute(tFacture.asString());
1826
            root.getSchema().updateVersion();
1826
            root.getSchema().updateVersion();
1827
            tableVenteFacture.fetchFields();
1827
            tableVenteFacture.fetchFields();
1828
            if (upNET) {
1828
            if (upNET) {
1829
                String req = "UPDATE " + tableVenteFacture.getSQLName().quote() + " SET \"NET_A_PAYER\"=(\"T_TTC\"-\"T_AVOIR_TTC\")";
1829
                String req = "UPDATE " + tableVenteFacture.getSQLName().quote() + " SET \"NET_A_PAYER\"=(\"T_TTC\"-\"T_AVOIR_TTC\")";
1830
                root.getBase().getDataSource().execute(req);
1830
                root.getBase().getDataSource().execute(req);
1831
            }
1831
            }
1832
        }
1832
        }
1833
 
1833
 
1834
        SQLTable tableTaxe = root.getTable("TAXE");
1834
        SQLTable tableTaxe = root.getTable("TAXE");
1835
        boolean updateTaxe = false;
1835
        boolean updateTaxe = false;
1836
        AlterTable tTaxe = new AlterTable(tableTaxe);
1836
        AlterTable tTaxe = new AlterTable(tableTaxe);
1837
        if (!tableTaxe.contains("ID_COMPTE_PCE_VENTE")) {
1837
        if (!tableTaxe.contains("ID_COMPTE_PCE_VENTE")) {
1838
            tTaxe.addForeignColumn("ID_COMPTE_PCE_VENTE", root.getTable("COMPTE_PCE"));
1838
            tTaxe.addForeignColumn("ID_COMPTE_PCE_VENTE", root.getTable("COMPTE_PCE"));
1839
            updateTaxe = true;
1839
            updateTaxe = true;
1840
        }
1840
        }
1841
        if (!tableTaxe.contains("ID_COMPTE_PCE_VENTE_SERVICE")) {
1841
        if (!tableTaxe.contains("ID_COMPTE_PCE_VENTE_SERVICE")) {
1842
            tTaxe.addForeignColumn("ID_COMPTE_PCE_VENTE_SERVICE", root.getTable("COMPTE_PCE"));
1842
            tTaxe.addForeignColumn("ID_COMPTE_PCE_VENTE_SERVICE", root.getTable("COMPTE_PCE"));
1843
            updateTaxe = true;
1843
            updateTaxe = true;
1844
        }
1844
        }
1845
 
1845
 
1846
        if (updateTaxe) {
1846
        if (updateTaxe) {
1847
            try {
1847
            try {
1848
                tableTaxe.getBase().getDataSource().execute(tTaxe.asString());
1848
                tableTaxe.getBase().getDataSource().execute(tTaxe.asString());
1849
                tableTaxe.getSchema().updateVersion();
1849
                tableTaxe.getSchema().updateVersion();
1850
                tableTaxe.fetchFields();
1850
                tableTaxe.fetchFields();
1851
            } catch (SQLException ex) {
1851
            } catch (SQLException ex) {
1852
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table TAXE", ex);
1852
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table TAXE", ex);
1853
            }
1853
            }
1854
 
1854
 
1855
        }
1855
        }
1856
 
1856
 
1857
        // Tarification par quantite
1857
        // Tarification par quantite
1858
        if (root.getTable("TARIF_QUANTITE") == null) {
1858
        if (root.getTable("TARIF_QUANTITE") == null) {
1859
            final SQLCreateTable createTableQtyTarif = new SQLCreateTable(root, "TARIF_QUANTITE");
1859
            final SQLCreateTable createTableQtyTarif = new SQLCreateTable(root, "TARIF_QUANTITE");
1860
            createTableQtyTarif.addForeignColumn("ID_ARTICLE", root.getTable("ARTICLE"));
1860
            createTableQtyTarif.addForeignColumn("ID_ARTICLE", root.getTable("ARTICLE"));
1861
            createTableQtyTarif.addDecimalColumn("QUANTITE", 16, 3, BigDecimal.ONE, false);
1861
            createTableQtyTarif.addDecimalColumn("QUANTITE", 16, 3, BigDecimal.ONE, false);
1862
            createTableQtyTarif.addDecimalColumn("POURCENT_REMISE", 16, 3, null, true);
1862
            createTableQtyTarif.addDecimalColumn("POURCENT_REMISE", 16, 3, null, true);
1863
            createTableQtyTarif.addDecimalColumn("PRIX_METRIQUE_VT_1", 16, 6, null, true);
1863
            createTableQtyTarif.addDecimalColumn("PRIX_METRIQUE_VT_1", 16, 6, null, true);
1864
            try {
1864
            try {
1865
                root.getBase().getDataSource().execute(createTableQtyTarif.asString());
1865
                root.getBase().getDataSource().execute(createTableQtyTarif.asString());
1866
                insertUndef(createTableQtyTarif);
1866
                insertUndef(createTableQtyTarif);
1867
                root.refetchTable("TARIF_QUANTITE");
1867
                root.refetchTable("TARIF_QUANTITE");
1868
                root.getSchema().updateVersion();
1868
                root.getSchema().updateVersion();
1869
            } catch (SQLException ex) {
1869
            } catch (SQLException ex) {
1870
                throw new IllegalStateException("Erreur lors de la création de la table " + "TARIF_QUANTITE", ex);
1870
                throw new IllegalStateException("Erreur lors de la création de la table " + "TARIF_QUANTITE", ex);
1871
            }
1871
            }
1872
        }
1872
        }
1873
        // Articles fournisseurs
1873
        // Articles fournisseurs
1874
        addArticleFournisseur(root);
1874
        addArticleFournisseur(root);
1875
 
1875
 
1876
        SQLTable tableCmdF = root.getTable("COMMANDE");
1876
        SQLTable tableCmdF = root.getTable("COMMANDE");
1877
        if (!tableCmdF.contains("ID_MODELE")) {
1877
        if (!tableCmdF.contains("ID_MODELE")) {
1878
            AlterTable t = new AlterTable(tableCmdF);
1878
            AlterTable t = new AlterTable(tableCmdF);
1879
            t.addForeignColumn("ID_MODELE", root.getTable("MODELE"));
1879
            t.addForeignColumn("ID_MODELE", root.getTable("MODELE"));
1880
            tableCmdF.getBase().getDataSource().execute(t.asString());
1880
            tableCmdF.getBase().getDataSource().execute(t.asString());
1881
            tableCmdF.getSchema().updateVersion();
1881
            tableCmdF.getSchema().updateVersion();
1882
            tableCmdF.fetchFields();
1882
            tableCmdF.fetchFields();
1883
        }
1883
        }
1884
 
1884
 
1885
        SQLTable tableArtF = root.getTable("ARTICLE_FOURNISSEUR");
1885
        SQLTable tableArtF = root.getTable("ARTICLE_FOURNISSEUR");
1886
        if (!tableArtF.contains("ID_FAMILLE_ARTICLE")) {
1886
        if (!tableArtF.contains("ID_FAMILLE_ARTICLE")) {
1887
            AlterTable t = new AlterTable(tableArtF);
1887
            AlterTable t = new AlterTable(tableArtF);
1888
            t.addForeignColumn("ID_FAMILLE_ARTICLE", root.getTable("FAMILLE_ARTICLE"));
1888
            t.addForeignColumn("ID_FAMILLE_ARTICLE", root.getTable("FAMILLE_ARTICLE"));
1889
            tableArtF.getBase().getDataSource().execute(t.asString());
1889
            tableArtF.getBase().getDataSource().execute(t.asString());
1890
            tableArtF.getSchema().updateVersion();
1890
            tableArtF.getSchema().updateVersion();
1891
            tableArtF.fetchFields();
1891
            tableArtF.fetchFields();
1892
        }
1892
        }
1893
 
1893
 
1894
        if (!tableCmdF.contains("DATE_RECEPTION_DEMANDEE")) {
1894
        if (!tableCmdF.contains("DATE_RECEPTION_DEMANDEE")) {
1895
            AlterTable t = new AlterTable(tableCmdF);
1895
            AlterTable t = new AlterTable(tableCmdF);
1896
            t.addColumn("DATE_RECEPTION_DEMANDEE", "date");
1896
            t.addColumn("DATE_RECEPTION_DEMANDEE", "date");
1897
            t.addColumn("DATE_RECEPTION_CONFIRMEE", "date");
1897
            t.addColumn("DATE_RECEPTION_CONFIRMEE", "date");
1898
            tableCmdF.getBase().getDataSource().execute(t.asString());
1898
            tableCmdF.getBase().getDataSource().execute(t.asString());
1899
            tableCmdF.getSchema().updateVersion();
1899
            tableCmdF.getSchema().updateVersion();
1900
            tableCmdF.fetchFields();
1900
            tableCmdF.fetchFields();
1901
        }
1901
        }
1902
 
1902
 
1903
        SQLTable tableEcr = root.getTable("ECRITURE");
1903
        SQLTable tableEcr = root.getTable("ECRITURE");
1904
        if (!tableEcr.contains("NOM_PIECE")) {
1904
        if (!tableEcr.contains("NOM_PIECE")) {
1905
            AlterTable t = new AlterTable(tableEcr);
1905
            AlterTable t = new AlterTable(tableEcr);
1906
            t.addVarCharColumn("NOM_PIECE", 1024);
1906
            t.addVarCharColumn("NOM_PIECE", 1024);
1907
            tableEcr.getBase().getDataSource().execute(t.asString());
1907
            tableEcr.getBase().getDataSource().execute(t.asString());
1908
            tableEcr.getSchema().updateVersion();
1908
            tableEcr.getSchema().updateVersion();
1909
            tableEcr.fetchFields();
1909
            tableEcr.fetchFields();
1910
        }
1910
        }
1911
 
1911
 
1912
        SQLTable tableKm = root.getTable("SAISIE_KM_ELEMENT");
1912
        SQLTable tableKm = root.getTable("SAISIE_KM_ELEMENT");
1913
        if (!tableKm.contains("NOM_PIECE")) {
1913
        if (!tableKm.contains("NOM_PIECE")) {
1914
            AlterTable t = new AlterTable(tableKm);
1914
            AlterTable t = new AlterTable(tableKm);
1915
            t.addVarCharColumn("NOM_PIECE", 1024);
1915
            t.addVarCharColumn("NOM_PIECE", 1024);
1916
 
1916
 
1917
            tableKm.getBase().getDataSource().execute(t.asString());
1917
            tableKm.getBase().getDataSource().execute(t.asString());
1918
            tableKm.getSchema().updateVersion();
1918
            tableKm.getSchema().updateVersion();
1919
            tableKm.fetchFields();
1919
            tableKm.fetchFields();
1920
        }
1920
        }
1921
 
1921
 
1922
        {
1922
        {
1923
            SQLSelect sel = new SQLSelect();
1923
            SQLSelect sel = new SQLSelect();
1924
            final SQLTable tableStyle = root.getTable("STYLE");
1924
            final SQLTable tableStyle = root.getTable("STYLE");
1925
            sel.addSelect(tableStyle.getKey());
1925
            sel.addSelect(tableStyle.getKey());
1926
            sel.setWhere(new Where(tableStyle.getField("NOM"), "=", "Composant"));
1926
            sel.setWhere(new Where(tableStyle.getField("NOM"), "=", "Composant"));
1927
            String req = sel.asString();
1927
            String req = sel.asString();
1928
            List<Map<String, Object>> l = root.getDBSystemRoot().getDataSource().execute(req);
1928
            List<Map<String, Object>> l = root.getDBSystemRoot().getDataSource().execute(req);
1929
 
1929
 
1930
            if (l.size() == 0) {
1930
            if (l.size() == 0) {
1931
                SQLRowValues rowValsStyle = new SQLRowValues(tableStyle);
1931
                SQLRowValues rowValsStyle = new SQLRowValues(tableStyle);
1932
                rowValsStyle.put("NOM", "Composant");
1932
                rowValsStyle.put("NOM", "Composant");
1933
                rowValsStyle.put("CODE", "COMP");
1933
                rowValsStyle.put("CODE", "COMP");
1934
                rowValsStyle.insert();
1934
                rowValsStyle.insert();
1935
            }
1935
            }
1936
        }
1936
        }
1937
 
1937
 
1938
        {
1938
        {
1939
            // Fix qté et style
1939
            // Fix qté et style
1940
            List<String> tableElt = Arrays.asList("AVOIR_CLIENT_ELEMENT", "BON_DE_LIVRAISON_ELEMENT", "BON_RECEPTION_ELEMENT", "COMMANDE_CLIENT_ELEMENT", "COMMANDE_ELEMENT", "DEVIS_ELEMENT",
1940
            List<String> tableElt = Arrays.asList("AVOIR_CLIENT_ELEMENT", "BON_DE_LIVRAISON_ELEMENT", "BON_RECEPTION_ELEMENT", "COMMANDE_CLIENT_ELEMENT", "COMMANDE_ELEMENT", "DEVIS_ELEMENT",
1941
                    "SAISIE_VENTE_FACTURE_ELEMENT");
1941
                    "SAISIE_VENTE_FACTURE_ELEMENT");
1942
            for (String string : tableElt) {
1942
            for (String string : tableElt) {
1943
                final SQLTable table = root.getTable(string);
1943
                final SQLTable table = root.getTable(string);
1944
                Number undefined = table.getUndefinedIDNumber();
1944
                Number undefined = table.getUndefinedIDNumber();
1945
                if (undefined != null && undefined.intValue() > 0) {
1945
                if (undefined != null && undefined.intValue() > 0) {
1946
                    UpdateBuilder build = new UpdateBuilder(table);
1946
                    UpdateBuilder build = new UpdateBuilder(table);
1947
                    build.setObject("ID_STYLE", 2);
1947
                    build.setObject("ID_STYLE", 2);
1948
                    build.setObject("QTE", 1);
1948
                    build.setObject("QTE", 1);
1949
                    build.setWhere(new Where(table.getKey(), "=", undefined.intValue()));
1949
                    build.setWhere(new Where(table.getKey(), "=", undefined.intValue()));
1950
                    table.getDBSystemRoot().getDataSource().execute(build.asString());
1950
                    table.getDBSystemRoot().getDataSource().execute(build.asString());
1951
                }
1951
                }
1952
            }
1952
            }
1953
        }
1953
        }
1954
 
1954
 
1955
        // ADresse de livraison et remise
1955
        // ADresse de livraison et remise
1956
        {
1956
        {
1957
            SQLTable tableDevis = root.getTable("DEVIS");
1957
            SQLTable tableDevis = root.getTable("DEVIS");
1958
            addAdresseField(tableDevis, root);
1958
            addAdresseField(tableDevis, root);
1959
            addRemiseField(tableDevis, root);
1959
            addRemiseField(tableDevis, root);
1960
 
1960
 
1961
            SQLTable tableVF = root.getTable("SAISIE_VENTE_FACTURE");
1961
            SQLTable tableVF = root.getTable("SAISIE_VENTE_FACTURE");
1962
            addAdresseField(tableVF, root);
1962
            addAdresseField(tableVF, root);
1963
            addRemiseField(tableVF, root);
1963
            addRemiseField(tableVF, root);
1964
 
1964
 
1965
            SQLTable tableCmd = root.getTable("COMMANDE_CLIENT");
1965
            SQLTable tableCmd = root.getTable("COMMANDE_CLIENT");
1966
            addAdresseField(tableCmd, root);
1966
            addAdresseField(tableCmd, root);
1967
            addRemiseField(tableCmd, root);
1967
            addRemiseField(tableCmd, root);
1968
 
1968
 
1969
            SQLTable tableBon = root.getTable("BON_DE_LIVRAISON");
1969
            SQLTable tableBon = root.getTable("BON_DE_LIVRAISON");
1970
            addAdresseField(tableBon, root);
1970
            addAdresseField(tableBon, root);
1971
            addRemiseField(tableBon, root);
1971
            addRemiseField(tableBon, root);
1972
 
1972
 
1973
            SQLTable tableAvoir = root.getTable("AVOIR_CLIENT");
1973
            SQLTable tableAvoir = root.getTable("AVOIR_CLIENT");
1974
            addAdresseField(tableAvoir, root);
1974
            addAdresseField(tableAvoir, root);
1975
            addRemiseField(tableAvoir, root);
1975
            addRemiseField(tableAvoir, root);
1976
        }
1976
        }
1977
        // Service client
1977
        // Service client
1978
        if (root.getTable("CLIENT_DEPARTEMENT") == null) {
1978
        if (root.getTable("CLIENT_DEPARTEMENT") == null) {
1979
            final SQLCreateTable createTableDpt = new SQLCreateTable(root, "CLIENT_DEPARTEMENT");
1979
            final SQLCreateTable createTableDpt = new SQLCreateTable(root, "CLIENT_DEPARTEMENT");
1980
            createTableDpt.addForeignColumn("CLIENT");
1980
            createTableDpt.addForeignColumn("CLIENT");
1981
            if (root.contains("ADRESSE")) {
1981
            if (root.contains("ADRESSE")) {
1982
                createTableDpt.addForeignColumn("ADRESSE");
1982
                createTableDpt.addForeignColumn("ADRESSE");
1983
            } else {
1983
            } else {
1984
                createTableDpt.addForeignColumn("ID_ADRESSE", root.findTable("ADRESSE"));
1984
                createTableDpt.addForeignColumn("ID_ADRESSE", root.findTable("ADRESSE"));
1985
            }
1985
            }
1986
            createTableDpt.addVarCharColumn("INFOS", 2048);
1986
            createTableDpt.addVarCharColumn("INFOS", 2048);
1987
            createTableDpt.addVarCharColumn("NOM", 256);
1987
            createTableDpt.addVarCharColumn("NOM", 256);
1988
            try {
1988
            try {
1989
                root.getBase().getDataSource().execute(createTableDpt.asString());
1989
                root.getBase().getDataSource().execute(createTableDpt.asString());
1990
                insertUndef(createTableDpt);
1990
                insertUndef(createTableDpt);
1991
                root.refetchTable("CLIENT_DEPARTEMENT");
1991
                root.refetchTable("CLIENT_DEPARTEMENT");
1992
                root.getSchema().updateVersion();
1992
                root.getSchema().updateVersion();
1993
            } catch (SQLException ex2) {
1993
            } catch (SQLException ex2) {
1994
                throw new IllegalStateException("Erreur lors de la création de la table " + "CLIENT_DEPARTEMENT", ex2);
1994
                throw new IllegalStateException("Erreur lors de la création de la table " + "CLIENT_DEPARTEMENT", ex2);
1995
            }
1995
            }
1996
        }
1996
        }
1997
 
1997
 
1998
        SQLTable tableVFElt = root.getTable("SAISIE_VENTE_FACTURE_ELEMENT");
1998
        SQLTable tableVFElt = root.getTable("SAISIE_VENTE_FACTURE_ELEMENT");
1999
        patchFieldElt1Dot4(tableVFElt, root);
1999
        patchFieldElt1Dot4(tableVFElt, root);
2000
 
2000
 
2001
        SQLTable tableDevisElt = root.getTable("DEVIS_ELEMENT");
2001
        SQLTable tableDevisElt = root.getTable("DEVIS_ELEMENT");
2002
        patchFieldElt1Dot4(tableDevisElt, root);
2002
        patchFieldElt1Dot4(tableDevisElt, root);
2003
 
2003
 
2004
        SQLTable tableCmdElt = root.getTable("COMMANDE_CLIENT_ELEMENT");
2004
        SQLTable tableCmdElt = root.getTable("COMMANDE_CLIENT_ELEMENT");
2005
 
2005
 
2006
        patchFieldElt1Dot4(tableCmdElt, root);
2006
        patchFieldElt1Dot4(tableCmdElt, root);
2007
 
2007
 
2008
        SQLTable tableBonElt = root.getTable("BON_DE_LIVRAISON_ELEMENT");
2008
        SQLTable tableBonElt = root.getTable("BON_DE_LIVRAISON_ELEMENT");
2009
        patchFieldElt1Dot4(tableBonElt, root);
2009
        patchFieldElt1Dot4(tableBonElt, root);
2010
 
2010
 
2011
        SQLTable tableAvoirElt = root.getTable("AVOIR_CLIENT_ELEMENT");
2011
        SQLTable tableAvoirElt = root.getTable("AVOIR_CLIENT_ELEMENT");
2012
        patchFieldElt1Dot4(tableAvoirElt, root);
2012
        patchFieldElt1Dot4(tableAvoirElt, root);
2013
 
2013
 
2014
        addNiveauElementField(root.getTable("COMMANDE_ELEMENT"));
2014
        addNiveauElementField(root.getTable("COMMANDE_ELEMENT"));
2015
        addNiveauElementField(root.getTable("BON_RECEPTION_ELEMENT"));
2015
        addNiveauElementField(root.getTable("BON_RECEPTION_ELEMENT"));
2016
        addNiveauElementField(root.getTable("FACTURE_FOURNISSEUR_ELEMENT"));
2016
        addNiveauElementField(root.getTable("FACTURE_FOURNISSEUR_ELEMENT"));
2017
 
2017
 
2018
        addContact(root);
2018
        addContact(root);
2019
 
2019
 
2020
        {
2020
        {
2021
            // Gestion des préparations de commandes
2021
            // Gestion des préparations de commandes
2022
            final SQLTable tableCommandeClient = root.getTable("COMMANDE_CLIENT");
2022
            final SQLTable tableCommandeClient = root.getTable("COMMANDE_CLIENT");
2023
            AlterTable tCommandeClient = new AlterTable(tableCommandeClient);
2023
            AlterTable tCommandeClient = new AlterTable(tableCommandeClient);
2024
            boolean updateCmdCli = false;
2024
            boolean updateCmdCli = false;
2025
 
2025
 
2026
            if (!tableCommandeClient.contains("ETAT_COMMANDE")) {
2026
            if (!tableCommandeClient.contains("ETAT_COMMANDE")) {
2027
                updateCmdCli = true;
2027
                updateCmdCli = true;
2028
                tCommandeClient.addIntegerColumn("ETAT_COMMANDE", EtatCommandeClient.A_PREPARER.getId());
2028
                tCommandeClient.addIntegerColumn("ETAT_COMMANDE", EtatCommandeClient.A_PREPARER.getId());
2029
            }
2029
            }
2030
            if (!tableCommandeClient.contains("EMBALLAGE")) {
2030
            if (!tableCommandeClient.contains("EMBALLAGE")) {
2031
                updateCmdCli = true;
2031
                updateCmdCli = true;
2032
                tCommandeClient.addVarCharColumn("EMBALLAGE", 256);
2032
                tCommandeClient.addVarCharColumn("EMBALLAGE", 256);
2033
            }
2033
            }
2034
            if (!tableCommandeClient.contains("NUMERO_EXPEDITION")) {
2034
            if (!tableCommandeClient.contains("NUMERO_EXPEDITION")) {
2035
                updateCmdCli = true;
2035
                updateCmdCli = true;
2036
                tCommandeClient.addVarCharColumn("NUMERO_EXPEDITION", 256);
2036
                tCommandeClient.addVarCharColumn("NUMERO_EXPEDITION", 256);
2037
            }
2037
            }
2038
 
2038
 
2039
            if (!tableCommandeClient.contains("ID_TAXE_PORT")) {
2039
            if (!tableCommandeClient.contains("ID_TAXE_PORT")) {
2040
                updateCmdCli = true;
2040
                updateCmdCli = true;
2041
                tCommandeClient.addForeignColumn("ID_TAXE_PORT", root.getTable("TAXE"));
2041
                tCommandeClient.addForeignColumn("ID_TAXE_PORT", root.getTable("TAXE"));
2042
            }
2042
            }
2043
 
2043
 
2044
            if (!tableCommandeClient.contains("PORT_HT")) {
2044
            if (!tableCommandeClient.contains("PORT_HT")) {
2045
                updateCmdCli = true;
2045
                updateCmdCli = true;
2046
                tCommandeClient.addLongColumn("PORT_HT", Long.valueOf(0), false);
2046
                tCommandeClient.addLongColumn("PORT_HT", Long.valueOf(0), false);
2047
            }
2047
            }
2048
 
2048
 
2049
            if (!tableCommandeClient.contains("REMISE_HT")) {
2049
            if (!tableCommandeClient.contains("REMISE_HT")) {
2050
                updateCmdCli = true;
2050
                updateCmdCli = true;
2051
                tCommandeClient.addLongColumn("REMISE_HT", Long.valueOf(0), false);
2051
                tCommandeClient.addLongColumn("REMISE_HT", Long.valueOf(0), false);
2052
            }
2052
            }
2053
 
2053
 
2054
            if (updateCmdCli) {
2054
            if (updateCmdCli) {
2055
                tableCommandeClient.getBase().getDataSource().execute(tCommandeClient.asString());
2055
                tableCommandeClient.getBase().getDataSource().execute(tCommandeClient.asString());
2056
                tableCommandeClient.getSchema().updateVersion();
2056
                tableCommandeClient.getSchema().updateVersion();
2057
                tableCommandeClient.fetchFields();
2057
                tableCommandeClient.fetchFields();
2058
            }
2058
            }
2059
        }
2059
        }
2060
 
2060
 
2061
        {
2061
        {
2062
            // Gestion des préparations de commandes
2062
            // Gestion des préparations de commandes
2063
            final SQLTable tableBonL = root.getTable("BON_DE_LIVRAISON");
2063
            final SQLTable tableBonL = root.getTable("BON_DE_LIVRAISON");
2064
            AlterTable tBonL = new AlterTable(tableBonL);
2064
            AlterTable tBonL = new AlterTable(tableBonL);
2065
            boolean updateBonL = false;
2065
            boolean updateBonL = false;
2066
 
2066
 
2067
            if (!tableBonL.contains("TOTAL_DEVISE")) {
2067
            if (!tableBonL.contains("TOTAL_DEVISE")) {
2068
                updateBonL = true;
2068
                updateBonL = true;
2069
                tBonL.addLongColumn("TOTAL_DEVISE", Long.valueOf(0), false);
2069
                tBonL.addLongColumn("TOTAL_DEVISE", Long.valueOf(0), false);
2070
            }
2070
            }
2071
 
2071
 
2072
            if (!tableBonL.contains("TOTAL_SERVICE")) {
2072
            if (!tableBonL.contains("TOTAL_SERVICE")) {
2073
                updateBonL = true;
2073
                updateBonL = true;
2074
                tBonL.addLongColumn("TOTAL_SERVICE", Long.valueOf(0), false);
2074
                tBonL.addLongColumn("TOTAL_SERVICE", Long.valueOf(0), false);
2075
            }
2075
            }
2076
 
2076
 
2077
            if (!tableBonL.contains("ID_TAXE_PORT")) {
2077
            if (!tableBonL.contains("ID_TAXE_PORT")) {
2078
                updateBonL = true;
2078
                updateBonL = true;
2079
                tBonL.addForeignColumn("ID_TAXE_PORT", root.getTable("TAXE"));
2079
                tBonL.addForeignColumn("ID_TAXE_PORT", root.getTable("TAXE"));
2080
            }
2080
            }
2081
 
2081
 
2082
            if (!tableBonL.contains("PORT_HT")) {
2082
            if (!tableBonL.contains("PORT_HT")) {
2083
                updateBonL = true;
2083
                updateBonL = true;
2084
                tBonL.addLongColumn("PORT_HT", Long.valueOf(0), false);
2084
                tBonL.addLongColumn("PORT_HT", Long.valueOf(0), false);
2085
            }
2085
            }
2086
 
2086
 
2087
            if (!tableBonL.contains("REMISE_HT")) {
2087
            if (!tableBonL.contains("REMISE_HT")) {
2088
                updateBonL = true;
2088
                updateBonL = true;
2089
                tBonL.addLongColumn("REMISE_HT", Long.valueOf(0), false);
2089
                tBonL.addLongColumn("REMISE_HT", Long.valueOf(0), false);
2090
            }
2090
            }
2091
 
2091
 
2092
            if (updateBonL) {
2092
            if (updateBonL) {
2093
                tableBonL.getBase().getDataSource().execute(tBonL.asString());
2093
                tableBonL.getBase().getDataSource().execute(tBonL.asString());
2094
                tableBonL.getSchema().updateVersion();
2094
                tableBonL.getSchema().updateVersion();
2095
                tableBonL.fetchFields();
2095
                tableBonL.fetchFields();
2096
            }
2096
            }
2097
        }
2097
        }
2098
 
2098
 
2099
        final List<String> asList = Arrays.asList("SAISIE_VENTE_FACTURE", "BON_RECEPTION", "BON_DE_LIVRAISON");
2099
        final List<String> asList = Arrays.asList("SAISIE_VENTE_FACTURE", "BON_RECEPTION", "BON_DE_LIVRAISON");
2100
        for (String tableVirtualStockName : asList) {
2100
        for (String tableVirtualStockName : asList) {
2101
            SQLTable tableVirtualStock = root.getTable(tableVirtualStockName);
2101
            SQLTable tableVirtualStock = root.getTable(tableVirtualStockName);
2102
            if (!tableVirtualStock.contains("CREATE_VIRTUAL_STOCK")) {
2102
            if (!tableVirtualStock.contains("CREATE_VIRTUAL_STOCK")) {
2103
                AlterTable t = new AlterTable(tableVirtualStock);
2103
                AlterTable t = new AlterTable(tableVirtualStock);
2104
                t.addBooleanColumn("CREATE_VIRTUAL_STOCK", Boolean.TRUE, false);
2104
                t.addBooleanColumn("CREATE_VIRTUAL_STOCK", Boolean.TRUE, false);
2105
                tableVirtualStock.getBase().getDataSource().execute(t.asString());
2105
                tableVirtualStock.getBase().getDataSource().execute(t.asString());
2106
                tableVirtualStock.getSchema().updateVersion();
2106
                tableVirtualStock.getSchema().updateVersion();
2107
                tableVirtualStock.fetchFields();
2107
                tableVirtualStock.fetchFields();
2108
            }
2108
            }
2109
        }
2109
        }
2110
 
2110
 
2111
        // Remise dans les devis
2111
        // Remise dans les devis
2112
        final SQLTable tableDevis = root.getTable("DEVIS");
2112
        final SQLTable tableDevis = root.getTable("DEVIS");
2113
        AlterTable tDevis = new AlterTable(tableDevis);
2113
        AlterTable tDevis = new AlterTable(tableDevis);
2114
        boolean updateDevis = false;
2114
        boolean updateDevis = false;
2115
 
2115
 
2116
        if (!tableDevis.contains("POURCENT_REMISE")) {
2116
        if (!tableDevis.contains("POURCENT_REMISE")) {
2117
            updateDevis = true;
2117
            updateDevis = true;
2118
            tDevis.addColumn("POURCENT_REMISE", "numeric (12,8)");
2118
            tDevis.addColumn("POURCENT_REMISE", "numeric (12,8)");
2119
        }
2119
        }
2120
        if (!tableDevis.contains("MONTANT_REMISE")) {
2120
        if (!tableDevis.contains("MONTANT_REMISE")) {
2121
            updateDevis = true;
2121
            updateDevis = true;
2122
            tDevis.addColumn("MONTANT_REMISE", "numeric (16,8)");
2122
            tDevis.addColumn("MONTANT_REMISE", "numeric (16,8)");
2123
        }
2123
        }
2124
        if (!tableDevis.contains("T_HA")) {
2124
        if (!tableDevis.contains("T_HA")) {
2125
            updateDevis = true;
2125
            updateDevis = true;
2126
            tDevis.addColumn("T_HA", "bigint", "0", false);
2126
            tDevis.addColumn("T_HA", "bigint", "0", false);
2127
        }
2127
        }
2128
 
2128
 
2129
        if (!tableDevis.contains("DUNNING_DATE")) {
2129
        if (!tableDevis.contains("DUNNING_DATE")) {
2130
            updateDevis = true;
2130
            updateDevis = true;
2131
            tDevis.addColumn("DUNNING_DATE", "date");
2131
            tDevis.addColumn("DUNNING_DATE", "date");
2132
        }
2132
        }
2133
 
2133
 
2134
        if (updateDevis) {
2134
        if (updateDevis) {
2135
            tableDevis.getBase().getDataSource().execute(tDevis.asString());
2135
            tableDevis.getBase().getDataSource().execute(tDevis.asString());
2136
            tableDevis.getSchema().updateVersion();
2136
            tableDevis.getSchema().updateVersion();
2137
            tableDevis.fetchFields();
2137
            tableDevis.fetchFields();
2138
        }
2138
        }
2139
 
2139
 
2140
        final SQLTable tableKmElt = root.getTable("SAISIE_KM_ELEMENT");
2140
        final SQLTable tableKmElt = root.getTable("SAISIE_KM_ELEMENT");
2141
        if (!tableKmElt.contains("ANALYTIQUE")) {
2141
        if (!tableKmElt.contains("ANALYTIQUE")) {
2142
            AlterTable t = new AlterTable(tableKmElt);
2142
            AlterTable t = new AlterTable(tableKmElt);
2143
            t.addVarCharColumn("ANALYTIQUE", 256);
2143
            t.addVarCharColumn("ANALYTIQUE", 256);
2144
            tableKmElt.getBase().getDataSource().execute(t.asString());
2144
            tableKmElt.getBase().getDataSource().execute(t.asString());
2145
            tableKmElt.getSchema().updateVersion();
2145
            tableKmElt.getSchema().updateVersion();
2146
            tableKmElt.fetchFields();
2146
            tableKmElt.fetchFields();
2147
 
2147
 
2148
        }
2148
        }
2149
 
2149
 
2150
        final SQLTable tableClient = root.getTable("CLIENT");
2150
        final SQLTable tableClient = root.getTable("CLIENT");
2151
        final SQLTable tableAdresse = tableClient.getForeignTable("ID_ADRESSE");
2151
        final SQLTable tableAdresse = tableClient.getForeignTable("ID_ADRESSE");
2152
        if (tableAdresse != null) {
2152
        if (tableAdresse != null) {
2153
            AlterTable t = new AlterTable(tableAdresse);
2153
            AlterTable t = new AlterTable(tableAdresse);
2154
            boolean updateADr = false;
2154
            boolean updateADr = false;
2155
            if (!tableAdresse.contains("PROVINCE")) {
2155
            if (!tableAdresse.contains("PROVINCE")) {
2156
                t.addVarCharColumn("PROVINCE", 256);
2156
                t.addVarCharColumn("PROVINCE", 256);
2157
                updateADr = true;
2157
                updateADr = true;
2158
            }
2158
            }
2159
            if (!tableAdresse.contains("LIBELLE")) {
2159
            if (!tableAdresse.contains("LIBELLE")) {
2160
                t.addVarCharColumn("LIBELLE", 256);
2160
                t.addVarCharColumn("LIBELLE", 256);
2161
                updateADr = true;
2161
                updateADr = true;
2162
            }
2162
            }
2163
            if (!tableAdresse.contains("TYPE")) {
2163
            if (!tableAdresse.contains("TYPE")) {
2164
                t.addVarCharColumn("TYPE", 256);
2164
                t.addVarCharColumn("TYPE", 256);
2165
                updateADr = true;
2165
                updateADr = true;
2166
            }
2166
            }
2167
            if (!tableAdresse.contains("EMAIL_CONTACT")) {
2167
            if (!tableAdresse.contains("EMAIL_CONTACT")) {
2168
                t.addVarCharColumn("EMAIL_CONTACT", 256);
2168
                t.addVarCharColumn("EMAIL_CONTACT", 256);
2169
                updateADr = true;
2169
                updateADr = true;
2170
            }
2170
            }
2171
            if (updateADr) {
2171
            if (updateADr) {
2172
                tableAdresse.getBase().getDataSource().execute(t.asString());
2172
                tableAdresse.getBase().getDataSource().execute(t.asString());
2173
                tableAdresse.getSchema().updateVersion();
2173
                tableAdresse.getSchema().updateVersion();
2174
                tableAdresse.fetchFields();
2174
                tableAdresse.fetchFields();
2175
            }
2175
            }
2176
        }
2176
        }
2177
 
2177
 
2178
        if (tableClient != null) {
2178
        if (tableClient != null) {
2179
            AlterTable t = new AlterTable(tableClient);
2179
            AlterTable t = new AlterTable(tableClient);
2180
            boolean upClient = false;
2180
            boolean upClient = false;
2181
            if (!tableClient.contains("REMIND_DATE")) {
2181
            if (!tableClient.contains("REMIND_DATE")) {
2182
                t.addDateAndTimeColumn("REMIND_DATE");
2182
                t.addDateAndTimeColumn("REMIND_DATE");
2183
                upClient = true;
2183
                upClient = true;
2184
            }
2184
            }
2185
            if (!tableClient.contains("BLOQUE_LIVRAISON")) {
2185
            if (!tableClient.contains("BLOQUE_LIVRAISON")) {
2186
                t.addBooleanColumn("BLOQUE_LIVRAISON", false, false);
2186
                t.addBooleanColumn("BLOQUE_LIVRAISON", false, false);
2187
                upClient = true;
2187
                upClient = true;
2188
            }
2188
            }
2189
            if (!tableClient.contains("BLOQUE")) {
2189
            if (!tableClient.contains("BLOQUE")) {
2190
                upClient = true;
2190
                upClient = true;
2191
                t.addBooleanColumn("BLOQUE", false, false);
2191
                t.addBooleanColumn("BLOQUE", false, false);
2192
            }
2192
            }
2193
            if (!tableClient.contains("ID_COMPTE_PCE_SERVICE")) {
2193
            if (!tableClient.contains("ID_COMPTE_PCE_SERVICE")) {
2194
                upClient = true;
2194
                upClient = true;
2195
                t.addForeignColumn("ID_COMPTE_PCE_SERVICE", tableClient.getTable("COMPTE_PCE"));
2195
                t.addForeignColumn("ID_COMPTE_PCE_SERVICE", tableClient.getTable("COMPTE_PCE"));
2196
            }
2196
            }
2197
 
2197
 
2198
            if (!tableClient.contains("ID_COMPTE_PCE_PRODUIT")) {
2198
            if (!tableClient.contains("ID_COMPTE_PCE_PRODUIT")) {
2199
                upClient = true;
2199
                upClient = true;
2200
                t.addForeignColumn("ID_COMPTE_PCE_PRODUIT", tableClient.getTable("COMPTE_PCE"));
2200
                t.addForeignColumn("ID_COMPTE_PCE_PRODUIT", tableClient.getTable("COMPTE_PCE"));
2201
            }
2201
            }
2202
 
2202
 
2203
            if (!tableClient.contains("ENCOURS_MAX")) {
2203
            if (!tableClient.contains("ENCOURS_MAX")) {
2204
                upClient = true;
2204
                upClient = true;
2205
                t.addDecimalColumn("ENCOURS_MAX", 16, 2, BigDecimal.valueOf(0), false);
2205
                t.addDecimalColumn("ENCOURS_MAX", 16, 2, BigDecimal.valueOf(0), false);
2206
            }
2206
            }
2207
            if (!tableClient.contains("CATEGORIES")) {
2207
            if (!tableClient.contains("CATEGORIES")) {
2208
                upClient = true;
2208
                upClient = true;
2209
                t.addVarCharColumn("CATEGORIES", 2048);
2209
                t.addVarCharColumn("CATEGORIES", 2048);
2210
            }
2210
            }
2211
            if (!tableClient.contains("NOTE_FINANCIERE")) {
2211
            if (!tableClient.contains("NOTE_FINANCIERE")) {
2212
                upClient = true;
2212
                upClient = true;
2213
                t.addVarCharColumn("NOTE_FINANCIERE", 1024);
2213
                t.addVarCharColumn("NOTE_FINANCIERE", 1024);
2214
            }
2214
            }
2215
            if (!tableClient.contains("CENTRE_GESTION")) {
2215
            if (!tableClient.contains("CENTRE_GESTION")) {
2216
                upClient = true;
2216
                upClient = true;
2217
                t.addVarCharColumn("CENTRE_GESTION", 1024);
2217
                t.addVarCharColumn("CENTRE_GESTION", 1024);
2218
            }
2218
            }
2219
            if (!tableClient.contains("METHODE_RELANCE")) {
2219
            if (!tableClient.contains("METHODE_RELANCE")) {
2220
                upClient = true;
2220
                upClient = true;
2221
                t.addVarCharColumn("METHODE_RELANCE", 1024);
2221
                t.addVarCharColumn("METHODE_RELANCE", 1024);
2222
            }
2222
            }
2223
            if (!tableClient.contains("SITE_INTERNET")) {
2223
            if (!tableClient.contains("SITE_INTERNET")) {
2224
                upClient = true;
2224
                upClient = true;
2225
                t.addVarCharColumn("SITE_INTERNET", 2048);
2225
                t.addVarCharColumn("SITE_INTERNET", 2048);
2226
            }
2226
            }
2227
            if (!tableClient.contains("GROUPE")) {
2227
            if (!tableClient.contains("GROUPE")) {
2228
                upClient = true;
2228
                upClient = true;
2229
                t.addVarCharColumn("GROUPE", 1024);
2229
                t.addVarCharColumn("GROUPE", 1024);
2230
            }
2230
            }
2231
            if (!tableClient.contains("ID_COMMERCIAL")) {
2231
            if (!tableClient.contains("ID_COMMERCIAL")) {
2232
                upClient = true;
2232
                upClient = true;
2233
                t.addForeignColumn("ID_COMMERCIAL", tableClient.getTable("COMMERCIAL"));
2233
                t.addForeignColumn("ID_COMMERCIAL", tableClient.getTable("COMMERCIAL"));
2234
            }
2234
            }
2235
 
2235
 
2236
            if (upClient) {
2236
            if (upClient) {
2237
                tableClient.getBase().getDataSource().execute(t.asString());
2237
                tableClient.getBase().getDataSource().execute(t.asString());
2238
                tableClient.getSchema().updateVersion();
2238
                tableClient.getSchema().updateVersion();
2239
                tableClient.fetchFields();
2239
                tableClient.fetchFields();
2240
            }
2240
            }
2241
        }
2241
        }
2242
        if (!root.contains("CATEGORIE_CLIENT")) {
2242
        if (!root.contains("CATEGORIE_CLIENT")) {
2243
            final SQLCreateTable createCategorieClientTable = new SQLCreateTable(root, "CATEGORIE_CLIENT");
2243
            final SQLCreateTable createCategorieClientTable = new SQLCreateTable(root, "CATEGORIE_CLIENT");
2244
            createCategorieClientTable.addVarCharColumn("NOM", 1024);
2244
            createCategorieClientTable.addVarCharColumn("NOM", 1024);
2245
 
2245
 
2246
            try {
2246
            try {
2247
                root.getDBSystemRoot().getDataSource().execute(createCategorieClientTable.asString());
2247
                root.getDBSystemRoot().getDataSource().execute(createCategorieClientTable.asString());
2248
                insertUndef(createCategorieClientTable);
2248
                insertUndef(createCategorieClientTable);
2249
                tableDevis.getSchema().updateVersion();
2249
                tableDevis.getSchema().updateVersion();
2250
            } catch (SQLException ex) {
2250
            } catch (SQLException ex) {
2251
                throw new IllegalStateException("Erreur lors de la création de la table CATEGORIE_CLIENT", ex);
2251
                throw new IllegalStateException("Erreur lors de la création de la table CATEGORIE_CLIENT", ex);
2252
            }
2252
            }
2253
 
2253
 
2254
        }
2254
        }
2255
 
2255
 
2256
        final SQLTable tableAssoc = root.getTable("ASSOCIATION_ANALYTIQUE");
2256
        final SQLTable tableAssoc = root.getTable("ASSOCIATION_ANALYTIQUE");
2257
        if (tableAssoc != null && !tableAssoc.contains("GESTION_AUTO")) {
2257
        if (tableAssoc != null && !tableAssoc.contains("GESTION_AUTO")) {
2258
            AlterTable t = new AlterTable(tableAssoc);
2258
            AlterTable t = new AlterTable(tableAssoc);
2259
            t.addBooleanColumn("GESTION_AUTO", false, false);
2259
            t.addBooleanColumn("GESTION_AUTO", false, false);
2260
            tableAssoc.getBase().getDataSource().execute(t.asString());
2260
            tableAssoc.getBase().getDataSource().execute(t.asString());
2261
            tableAssoc.getSchema().updateVersion();
2261
            tableAssoc.getSchema().updateVersion();
2262
            tableAssoc.fetchFields();
2262
            tableAssoc.fetchFields();
2263
        }
2263
        }
2264
        if (!root.contains("CALENDAR_ITEM")) {
2264
        if (!root.contains("CALENDAR_ITEM")) {
2265
            final SQLCreateTable createTaskGroupTable = new SQLCreateTable(root, "CALENDAR_ITEM_GROUP");
2265
            final SQLCreateTable createTaskGroupTable = new SQLCreateTable(root, "CALENDAR_ITEM_GROUP");
2266
            createTaskGroupTable.addVarCharColumn("NAME", 1024);
2266
            createTaskGroupTable.addVarCharColumn("NAME", 1024);
2267
            createTaskGroupTable.addVarCharColumn("DESCRIPTION", 1024 * 8);
2267
            createTaskGroupTable.addVarCharColumn("DESCRIPTION", 1024 * 8);
2268
 
2268
 
2269
            final SQLCreateTable createTaskTable = new SQLCreateTable(root, "CALENDAR_ITEM");
2269
            final SQLCreateTable createTaskTable = new SQLCreateTable(root, "CALENDAR_ITEM");
2270
            createTaskTable.addDateAndTimeColumn("START");
2270
            createTaskTable.addDateAndTimeColumn("START");
2271
            createTaskTable.addDateAndTimeColumn("END");
2271
            createTaskTable.addDateAndTimeColumn("END");
2272
            createTaskTable.addLongColumn("DURATION_S", 0L, false);
2272
            createTaskTable.addLongColumn("DURATION_S", 0L, false);
2273
            createTaskTable.addVarCharColumn("SUMMARY", 1024);
2273
            createTaskTable.addVarCharColumn("SUMMARY", 1024);
2274
            createTaskTable.addVarCharColumn("DESCRIPTION", 1024 * 8);
2274
            createTaskTable.addVarCharColumn("DESCRIPTION", 1024 * 8);
2275
            createTaskTable.addVarCharColumn("FLAGS", 1024);
2275
            createTaskTable.addVarCharColumn("FLAGS", 1024);
2276
            createTaskTable.addVarCharColumn("STATUS", 128);
2276
            createTaskTable.addVarCharColumn("STATUS", 128);
2277
            createTaskTable.addForeignColumn(createTaskGroupTable);
2277
            createTaskTable.addForeignColumn(createTaskGroupTable);
2278
            createTaskTable.addLongColumn("SOURCE_ID", null, true);
2278
            createTaskTable.addLongColumn("SOURCE_ID", null, true);
2279
            createTaskTable.addVarCharColumn("SOURCE_TABLE", 256);
2279
            createTaskTable.addVarCharColumn("SOURCE_TABLE", 256);
2280
            createTaskTable.addVarCharColumn("UID", 1024);
2280
            createTaskTable.addVarCharColumn("UID", 1024);
2281
            createTaskTable.addVarCharColumn("LOCATION", 4096);
2281
            createTaskTable.addVarCharColumn("LOCATION", 4096);
2282
            try {
2282
            try {
2283
                root.getDBSystemRoot().getDataSource().execute(createTaskGroupTable.asString());
2283
                root.getDBSystemRoot().getDataSource().execute(createTaskGroupTable.asString());
2284
                insertUndef(createTaskGroupTable);
2284
                insertUndef(createTaskGroupTable);
2285
                root.getDBSystemRoot().getDataSource().execute(createTaskTable.asString());
2285
                root.getDBSystemRoot().getDataSource().execute(createTaskTable.asString());
2286
                insertUndef(createTaskTable);
2286
                insertUndef(createTaskTable);
2287
                tableDevis.getSchema().updateVersion();
2287
                tableDevis.getSchema().updateVersion();
2288
                root.refetchTable("CALENDAR_ITEM_GROUP");
2288
                root.refetchTable("CALENDAR_ITEM_GROUP");
2289
                root.refetchTable("CALENDAR_ITEM");
2289
                root.refetchTable("CALENDAR_ITEM");
2290
 
2290
 
2291
            } catch (SQLException ex) {
2291
            } catch (SQLException ex) {
2292
                throw new IllegalStateException("Erreur lors de la création de la table TASK", ex);
2292
                throw new IllegalStateException("Erreur lors de la création de la table TASK", ex);
2293
            }
2293
            }
2294
 
2294
 
2295
        }
2295
        }
2296
 
2296
 
2297
        // Remise sur tarif client
2297
        // Remise sur tarif client
2298
        if (root.contains("ARTICLE_TARIF")) {
2298
        if (root.contains("ARTICLE_TARIF")) {
2299
 
2299
 
2300
            AlterTable t = new AlterTable(root.getTable("ARTICLE_TARIF"));
2300
            AlterTable t = new AlterTable(root.getTable("ARTICLE_TARIF"));
2301
            boolean alterTarif = false;
2301
            boolean alterTarif = false;
2302
            if (!root.getTable("ARTICLE_TARIF").contains("POURCENT_REMISE")) {
2302
            if (!root.getTable("ARTICLE_TARIF").contains("POURCENT_REMISE")) {
2303
                t.addDecimalColumn("POURCENT_REMISE", 16, 6, BigDecimal.valueOf(0), false);
2303
                t.addDecimalColumn("POURCENT_REMISE", 16, 6, BigDecimal.valueOf(0), false);
2304
                alterTarif = true;
2304
                alterTarif = true;
2305
            }
2305
            }
2306
 
2306
 
2307
            if (!root.getTable("ARTICLE_TARIF").contains("QTE")) {
2307
            if (!root.getTable("ARTICLE_TARIF").contains("QTE")) {
2308
                t.addIntegerColumn("QTE", 1);
2308
                t.addIntegerColumn("QTE", 1);
2309
                alterTarif = true;
2309
                alterTarif = true;
2310
            }
2310
            }
2311
            if (alterTarif) {
2311
            if (alterTarif) {
2312
                root.getTable("ARTICLE_TARIF").getBase().getDataSource().execute(t.asString());
2312
                root.getTable("ARTICLE_TARIF").getBase().getDataSource().execute(t.asString());
2313
                root.getTable("ARTICLE_TARIF").fetchFields();
2313
                root.getTable("ARTICLE_TARIF").fetchFields();
2314
                root.getTable("ARTICLE").getSchema().updateVersion();
2314
                root.getTable("ARTICLE").getSchema().updateVersion();
2315
            }
2315
            }
2316
        }
2316
        }
2317
        // SKU et Type d'expedition
2317
        // SKU et Type d'expedition
2318
        final SQLTable articleTable = root.getTable("ARTICLE");
2318
        final SQLTable articleTable = root.getTable("ARTICLE");
2319
        if (!articleTable.contains("SKU")) {
2319
        if (!articleTable.contains("SKU")) {
2320
            AlterTable a = new AlterTable(articleTable);
2320
            AlterTable a = new AlterTable(articleTable);
2321
            a.addVarCharColumn("SKU", 256);
2321
            a.addVarCharColumn("SKU", 256);
2322
            try {
2322
            try {
2323
                articleTable.getBase().getDataSource().execute(a.asString());
2323
                articleTable.getBase().getDataSource().execute(a.asString());
2324
                articleTable.getSchema().updateVersion();
2324
                articleTable.getSchema().updateVersion();
2325
                articleTable.fetchFields();
2325
                articleTable.fetchFields();
2326
            } catch (SQLException ex2) {
2326
            } catch (SQLException ex2) {
2327
                throw new IllegalStateException("Erreur lors de l'ajout du champs SKU sur la table ARTICLE", ex2);
2327
                throw new IllegalStateException("Erreur lors de l'ajout du champs SKU sur la table ARTICLE", ex2);
2328
            }
2328
            }
2329
        }
2329
        }
2330
 
2330
 
2331
        try {
2331
        try {
2332
            final SQLTable cmdClientTable = root.getTable("COMMANDE_CLIENT");
2332
            final SQLTable cmdClientTable = root.getTable("COMMANDE_CLIENT");
2333
            if (!cmdClientTable.contains("TYPE_EXPEDITION")) {
2333
            if (!cmdClientTable.contains("TYPE_EXPEDITION")) {
2334
                final AlterTable a = new AlterTable(cmdClientTable);
2334
                final AlterTable a = new AlterTable(cmdClientTable);
2335
                a.addVarCharColumn("TYPE_EXPEDITION", 256);
2335
                a.addVarCharColumn("TYPE_EXPEDITION", 256);
2336
                cmdClientTable.getBase().getDataSource().execute(a.asString());
2336
                cmdClientTable.getBase().getDataSource().execute(a.asString());
2337
                cmdClientTable.getSchema().updateVersion();
2337
                cmdClientTable.getSchema().updateVersion();
2338
                cmdClientTable.fetchFields();
2338
                cmdClientTable.fetchFields();
2339
            }
2339
            }
2340
        } catch (SQLException ex2) {
2340
        } catch (SQLException ex2) {
2341
            throw new IllegalStateException("Erreur lors de l'ajout du champs TYPE_EXPEDITION sur la table COMMANDE_CLIENT", ex2);
2341
            throw new IllegalStateException("Erreur lors de l'ajout du champs TYPE_EXPEDITION sur la table COMMANDE_CLIENT", ex2);
2342
        }
2342
        }
2343
        try {
2343
        try {
2344
            final SQLTable axeTable = root.getTable("AXE_ANALYTIQUE");
2344
            final SQLTable axeTable = root.getTable("AXE_ANALYTIQUE");
2345
            if (!axeTable.contains("TYPE")) {
2345
            if (!axeTable.contains("TYPE")) {
2346
                final AlterTable a = new AlterTable(axeTable);
2346
                final AlterTable a = new AlterTable(axeTable);
2347
                a.addVarCharColumn("TYPE", 256);
2347
                a.addVarCharColumn("TYPE", 256);
2348
                axeTable.getBase().getDataSource().execute(a.asString());
2348
                axeTable.getBase().getDataSource().execute(a.asString());
2349
                axeTable.getSchema().updateVersion();
2349
                axeTable.getSchema().updateVersion();
2350
                axeTable.fetchFields();
2350
                axeTable.fetchFields();
2351
            }
2351
            }
2352
        } catch (SQLException ex2) {
2352
        } catch (SQLException ex2) {
2353
            throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table AXE_ANALYTIQUE", ex2);
2353
            throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table AXE_ANALYTIQUE", ex2);
2354
        }
2354
        }
2355
        // Historique des taux
2355
        // Historique des taux
2356
        if (!root.contains("DEVISE_HISTORIQUE")) {
2356
        if (!root.contains("DEVISE_HISTORIQUE")) {
2357
            final SQLCreateTable createTable = new SQLCreateTable(root, "DEVISE_HISTORIQUE");
2357
            final SQLCreateTable createTable = new SQLCreateTable(root, "DEVISE_HISTORIQUE");
2358
            createTable.addDateAndTimeColumn("DATE");
2358
            createTable.addDateAndTimeColumn("DATE");
2359
            createTable.addVarCharColumn("SRC", 8);
2359
            createTable.addVarCharColumn("SRC", 8);
2360
            createTable.addVarCharColumn("DST", 8);
2360
            createTable.addVarCharColumn("DST", 8);
2361
            createTable.addDecimalColumn("TAUX", 12, 6, new BigDecimal(1), false);
2361
            createTable.addDecimalColumn("TAUX", 12, 6, new BigDecimal(1), false);
2362
            createTable.addDecimalColumn("TAUX_COMMERCIAL", 12, 6, new BigDecimal(1), false);
2362
            createTable.addDecimalColumn("TAUX_COMMERCIAL", 12, 6, new BigDecimal(1), false);
2363
            try {
2363
            try {
2364
                root.getDBSystemRoot().getDataSource().execute(createTable.asString());
2364
                root.getDBSystemRoot().getDataSource().execute(createTable.asString());
2365
                insertUndef(createTable);
2365
                insertUndef(createTable);
2366
                tableDevis.getSchema().updateVersion();
2366
                tableDevis.getSchema().updateVersion();
2367
                root.refetchTable("DEVISE_HISTORIQUE");
2367
                root.refetchTable("DEVISE_HISTORIQUE");
2368
            } catch (SQLException ex) {
2368
            } catch (SQLException ex) {
2369
                throw new IllegalStateException("Erreur lors de la création de la table TASK", ex);
2369
                throw new IllegalStateException("Erreur lors de la création de la table TASK", ex);
2370
            }
2370
            }
2371
        }
2371
        }
2372
 
2372
 
2373
        final SQLTable tableContact = root.getTable("CONTACT");
2373
        final SQLTable tableContact = root.getTable("CONTACT");
2374
        if (tableContact != null && !tableContact.contains("NO_MAILING")) {
2374
        if (tableContact != null && !tableContact.contains("NO_MAILING")) {
2375
            AlterTable t = new AlterTable(tableContact);
2375
            AlterTable t = new AlterTable(tableContact);
2376
            t.addBooleanColumn("NO_MAILING", false, false);
2376
            t.addBooleanColumn("NO_MAILING", false, false);
2377
            tableContact.getBase().getDataSource().execute(t.asString());
2377
            tableContact.getBase().getDataSource().execute(t.asString());
2378
            tableContact.getSchema().updateVersion();
2378
            tableContact.getSchema().updateVersion();
2379
            tableContact.fetchFields();
2379
            tableContact.fetchFields();
2380
        }
2380
        }
2381
 
2381
 
2382
        SQLTable tableBonR = root.getTable("FACTURE_FOURNISSEUR");
2382
        SQLTable tableBonR = root.getTable("FACTURE_FOURNISSEUR");
2383
        if (!tableBonR.contains("TAUX_APPLIQUE")) {
2383
        if (!tableBonR.contains("TAUX_APPLIQUE")) {
2384
            AlterTable t = new AlterTable(tableBonR);
2384
            AlterTable t = new AlterTable(tableBonR);
2385
            t.addDecimalColumn("TAUX_APPLIQUE", 12, 6, BigDecimal.ONE, true);
2385
            t.addDecimalColumn("TAUX_APPLIQUE", 12, 6, BigDecimal.ONE, true);
2386
            tableBonR.getBase().getDataSource().execute(t.asString());
2386
            tableBonR.getBase().getDataSource().execute(t.asString());
2387
            tableBonR.getSchema().updateVersion();
2387
            tableBonR.getSchema().updateVersion();
2388
            tableBonR.fetchFields();
2388
            tableBonR.fetchFields();
2389
        }
2389
        }
2390
        root.getTable("ARTICLE").getSchema().updateVersion();
2390
        root.getTable("ARTICLE").getSchema().updateVersion();
2391
        // Valeur par défaut des numérotations
2391
        // Valeur par défaut des numérotations
2392
        if (root.contains("NUMEROTATION_AUTO")) {
2392
        if (root.contains("NUMEROTATION_AUTO")) {
2393
            SQLRow rowNumerotation = root.getTable("NUMEROTATION_AUTO").getRow(2);
2393
            SQLRow rowNumerotation = root.getTable("NUMEROTATION_AUTO").getRow(2);
2394
            if (rowNumerotation != null) {
2394
            if (rowNumerotation != null) {
2395
                SQLRowValues rNumerotation = rowNumerotation.asRowValues();
2395
                SQLRowValues rNumerotation = rowNumerotation.asRowValues();
2396
                boolean numerotationFixed = false;
2396
                boolean numerotationFixed = false;
2397
                if (StringUtils.isEmpty(rNumerotation.getString("AVOIR_F_FORMAT"), true)) {
2397
                if (StringUtils.isEmpty(rNumerotation.getString("AVOIR_F_FORMAT"), true)) {
2398
                    rNumerotation.put("AVOIR_F_FORMAT", "'AVOIR'yyMM-000");
2398
                    rNumerotation.put("AVOIR_F_FORMAT", "'AVOIR'yyMM-000");
2399
                    numerotationFixed = true;
2399
                    numerotationFixed = true;
2400
                }
2400
                }
2401
                if (StringUtils.isEmpty(rNumerotation.getString("CLIENT_FORMAT"), true)) {
2401
                if (StringUtils.isEmpty(rNumerotation.getString("CLIENT_FORMAT"), true)) {
2402
                    rNumerotation.put("CLIENT_FORMAT", "'CLI'00000");
2402
                    rNumerotation.put("CLIENT_FORMAT", "'CLI'00000");
2403
                    numerotationFixed = true;
2403
                    numerotationFixed = true;
2404
                }
2404
                }
2405
                if (numerotationFixed) {
2405
                if (numerotationFixed) {
2406
                    rNumerotation.commit();
2406
                    rNumerotation.commit();
2407
                }
2407
                }
2408
            }
2408
            }
2409
        }
2409
        }
2410
        //
2410
        //
2411
 
2411
 
2412
        final SQLTable tableCalendarItem = root.getTable("CALENDAR_ITEM");
2412
        final SQLTable tableCalendarItem = root.getTable("CALENDAR_ITEM");
2413
        if (tableCalendarItem != null) {
2413
        if (tableCalendarItem != null) {
2414
            final AlterTable tVF = new AlterTable(tableCalendarItem);
2414
            final AlterTable tVF = new AlterTable(tableCalendarItem);
2415
            boolean needUpdate = false;
2415
            boolean needUpdate = false;
2416
            if (!tableCalendarItem.getFieldsName().contains("UID")) {
2416
            if (!tableCalendarItem.getFieldsName().contains("UID")) {
2417
                tVF.addVarCharColumn("UID", 1024);
2417
                tVF.addVarCharColumn("UID", 1024);
2418
                needUpdate = true;
2418
                needUpdate = true;
2419
            }
2419
            }
2420
            if (!tableCalendarItem.getFieldsName().contains("LOCATION")) {
2420
            if (!tableCalendarItem.getFieldsName().contains("LOCATION")) {
2421
                tVF.addVarCharColumn("LOCATION", 4096);
2421
                tVF.addVarCharColumn("LOCATION", 4096);
2422
                needUpdate = true;
2422
                needUpdate = true;
2423
            }
2423
            }
2424
            if (needUpdate) {
2424
            if (needUpdate) {
2425
                try {
2425
                try {
2426
                    tableCalendarItem.getBase().getDataSource().execute(tVF.asString());
2426
                    tableCalendarItem.getBase().getDataSource().execute(tVF.asString());
2427
                    tableCalendarItem.getSchema().updateVersion();
2427
                    tableCalendarItem.getSchema().updateVersion();
2428
                    tableCalendarItem.fetchFields();
2428
                    tableCalendarItem.fetchFields();
2429
                } catch (SQLException ex) {
2429
                } catch (SQLException ex) {
2430
                    throw new IllegalStateException("Erreur lors de l'ajout de UID sur la table CALENDAR_ITEM", ex);
2430
                    throw new IllegalStateException("Erreur lors de l'ajout de UID sur la table CALENDAR_ITEM", ex);
2431
                }
2431
                }
2432
            }
2432
            }
2433
        }
2433
        }
2434
 
2434
 
2435
    }
2435
    }
2436
 
2436
 
2437
    private void updateStyle(final DBRoot root) throws SQLException {
2437
    private void updateStyle(final DBRoot root) throws SQLException {
2438
        SQLTable style = root.getTable("STYLE");
2438
        SQLTable style = root.getTable("STYLE");
2439
        SQLRowValues rowVals = new SQLRowValues(style);
2439
        SQLRowValues rowVals = new SQLRowValues(style);
2440
        rowVals.put("NOM", null);
2440
        rowVals.put("NOM", null);
2441
        SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
2441
        SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
2442
        List<SQLRowValues> list = fetcher.fetch();
2442
        List<SQLRowValues> list = fetcher.fetch();
2443
        boolean containsInvisible = false;
2443
        boolean containsInvisible = false;
2444
        for (SQLRowValues sqlRowValues : list) {
2444
        for (SQLRowValues sqlRowValues : list) {
2445
            if (sqlRowValues.getString("NOM").equals("Invisible")) {
2445
            if (sqlRowValues.getString("NOM").equals("Invisible")) {
2446
                containsInvisible = true;
2446
                containsInvisible = true;
2447
            }
2447
            }
2448
        }
2448
        }
2449
        if (!containsInvisible) {
2449
        if (!containsInvisible) {
2450
            SQLRowValues rowValsStyle = new SQLRowValues(style);
2450
            SQLRowValues rowValsStyle = new SQLRowValues(style);
2451
            rowValsStyle.put("NOM", "Invisible");
2451
            rowValsStyle.put("NOM", "Invisible");
2452
            rowValsStyle.put("CODE", "INV");
2452
            rowValsStyle.put("CODE", "INV");
2453
            rowValsStyle.insert();
2453
            rowValsStyle.insert();
2454
        }
2454
        }
2455
 
2455
 
2456
    }
2456
    }
2457
 
2457
 
2458
    private void updateToV1Dot2(final DBRoot root) throws SQLException {
2458
    private void updateToV1Dot2(final DBRoot root) throws SQLException {
2459
        // bigint -> int ID_METRIQUE BON_DE_LIVRAISON_ELEMENT
2459
        // bigint -> int ID_METRIQUE BON_DE_LIVRAISON_ELEMENT
2460
        final SQLTable tableLivraisonElement = root.getTable("BON_DE_LIVRAISON_ELEMENT");
2460
        final SQLTable tableLivraisonElement = root.getTable("BON_DE_LIVRAISON_ELEMENT");
2461
        AlterTable alter = new AlterTable(tableLivraisonElement);
2461
        AlterTable alter = new AlterTable(tableLivraisonElement);
2462
        alter.alterColumn("ID_METRIQUE_2", EnumSet.of(Properties.TYPE), "integer", null, null);
2462
        alter.alterColumn("ID_METRIQUE_2", EnumSet.of(Properties.TYPE), "integer", null, null);
2463
        String req3 = alter.asString();
2463
        String req3 = alter.asString();
2464
        root.getDBSystemRoot().getDataSource().execute(req3);
2464
        root.getDBSystemRoot().getDataSource().execute(req3);
2465
 
2465
 
2466
        final SQLTable tableDevis = root.getTable("DEVIS");
2466
        final SQLTable tableDevis = root.getTable("DEVIS");
2467
        final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
2467
        final SQLDataSource ds = root.getDBSystemRoot().getDataSource();
2468
        if (!tableDevis.getFieldsName().contains("DATE_VALIDITE")) {
2468
        if (!tableDevis.getFieldsName().contains("DATE_VALIDITE")) {
2469
            AlterTable t = new AlterTable(tableDevis);
2469
            AlterTable t = new AlterTable(tableDevis);
2470
            t.addColumn("DATE_VALIDITE", "date");
2470
            t.addColumn("DATE_VALIDITE", "date");
2471
            try {
2471
            try {
2472
                ds.execute(t.asString());
2472
                ds.execute(t.asString());
2473
                tableDevis.getSchema().updateVersion();
2473
                tableDevis.getSchema().updateVersion();
2474
            } catch (SQLException ex) {
2474
            } catch (SQLException ex) {
2475
                throw new IllegalStateException("Erreur lors de l'ajout du champ DATE_VALIDITE à la table DEVIS", ex);
2475
                throw new IllegalStateException("Erreur lors de l'ajout du champ DATE_VALIDITE à la table DEVIS", ex);
2476
            }
2476
            }
2477
        } else {
2477
        } else {
2478
            AlterTable t = new AlterTable(tableDevis);
2478
            AlterTable t = new AlterTable(tableDevis);
2479
            t.alterColumn("DATE_VALIDITE", EnumSet.allOf(Properties.class), "date", null, true);
2479
            t.alterColumn("DATE_VALIDITE", EnumSet.allOf(Properties.class), "date", null, true);
2480
            try {
2480
            try {
2481
                ds.execute(t.asString());
2481
                ds.execute(t.asString());
2482
                tableDevis.getSchema().updateVersion();
2482
                tableDevis.getSchema().updateVersion();
2483
            } catch (SQLException ex) {
2483
            } catch (SQLException ex) {
2484
                throw new IllegalStateException("Erreur lors de l'ajout du champ DATE_VALIDITE à la table DEVIS", ex);
2484
                throw new IllegalStateException("Erreur lors de l'ajout du champ DATE_VALIDITE à la table DEVIS", ex);
2485
            }
2485
            }
2486
        }
2486
        }
2487
 
2487
 
2488
        final SQLTable tableEtatDevis = root.getTable("ETAT_DEVIS");
2488
        final SQLTable tableEtatDevis = root.getTable("ETAT_DEVIS");
2489
        if (tableEtatDevis.getRow(5) == null && tableEtatDevis.getRowCount() <= 4) {
2489
        if (tableEtatDevis.getRow(5) == null && tableEtatDevis.getRowCount() <= 4) {
2490
            SQLRowValues rowVals = new SQLRowValues(tableEtatDevis);
2490
            SQLRowValues rowVals = new SQLRowValues(tableEtatDevis);
2491
            rowVals.put("NOM", "En cours de rédaction");
2491
            rowVals.put("NOM", "En cours de rédaction");
2492
            rowVals.commit();
2492
            rowVals.commit();
2493
 
2493
 
2494
        }
2494
        }
2495
 
2495
 
2496
        SQLRowValues rowValsOrdre = new SQLRowValues(tableEtatDevis);
2496
        SQLRowValues rowValsOrdre = new SQLRowValues(tableEtatDevis);
2497
        rowValsOrdre.put("ORDRE", new BigDecimal("1.505"));
2497
        rowValsOrdre.put("ORDRE", new BigDecimal("1.505"));
2498
        rowValsOrdre.update(EtatDevisSQLElement.EN_ATTENTE);
2498
        rowValsOrdre.update(EtatDevisSQLElement.EN_ATTENTE);
2499
 
2499
 
2500
        rowValsOrdre.put("ORDRE", new BigDecimal("2.505"));
2500
        rowValsOrdre.put("ORDRE", new BigDecimal("2.505"));
2501
        rowValsOrdre.update(EtatDevisSQLElement.ACCEPTE);
2501
        rowValsOrdre.update(EtatDevisSQLElement.ACCEPTE);
2502
 
2502
 
2503
        rowValsOrdre.put("ORDRE", new BigDecimal("3.505"));
2503
        rowValsOrdre.put("ORDRE", new BigDecimal("3.505"));
2504
        rowValsOrdre.update(EtatDevisSQLElement.REFUSE);
2504
        rowValsOrdre.update(EtatDevisSQLElement.REFUSE);
2505
 
2505
 
2506
        rowValsOrdre.put("ORDRE", new BigDecimal("4.505"));
2506
        rowValsOrdre.put("ORDRE", new BigDecimal("4.505"));
2507
        rowValsOrdre.update(EtatDevisSQLElement.EN_COURS);
2507
        rowValsOrdre.update(EtatDevisSQLElement.EN_COURS);
2508
 
2508
 
2509
        // Ajout de la TVA à 0
2509
        // Ajout de la TVA à 0
2510
        SQLSelect selTVA = new SQLSelect();
2510
        SQLSelect selTVA = new SQLSelect();
2511
        SQLTable tableTaxe = root.getTable("TAXE");
2511
        SQLTable tableTaxe = root.getTable("TAXE");
2512
        selTVA.addSelect(tableTaxe.getKey(), "COUNT");
2512
        selTVA.addSelect(tableTaxe.getKey(), "COUNT");
2513
        selTVA.setWhere(new Where(tableTaxe.getField("TAUX"), "=", 0));
2513
        selTVA.setWhere(new Where(tableTaxe.getField("TAUX"), "=", 0));
2514
        Object result = root.getBase().getDataSource().executeScalar(selTVA.asString());
2514
        Object result = root.getBase().getDataSource().executeScalar(selTVA.asString());
2515
        if (result == null || ((Number) result).longValue() == 0) {
2515
        if (result == null || ((Number) result).longValue() == 0) {
2516
            SQLRowValues rowVals = new SQLRowValues(tableTaxe);
2516
            SQLRowValues rowVals = new SQLRowValues(tableTaxe);
2517
            rowVals.put("NOM", "Non applicable");
2517
            rowVals.put("NOM", "Non applicable");
2518
            rowVals.put("TAUX", Float.valueOf(0));
2518
            rowVals.put("TAUX", Float.valueOf(0));
2519
            rowVals.commit();
2519
            rowVals.commit();
2520
        }
2520
        }
2521
 
2521
 
2522
        // Bon de livraison
2522
        // Bon de livraison
2523
        {
2523
        {
2524
            SQLTable tableBL = root.getTable("BON_DE_LIVRAISON");
2524
            SQLTable tableBL = root.getTable("BON_DE_LIVRAISON");
2525
            boolean alterBL = false;
2525
            boolean alterBL = false;
2526
            AlterTable t = new AlterTable(tableBL);
2526
            AlterTable t = new AlterTable(tableBL);
2527
            if (!tableBL.getFieldsName().contains("SOURCE")) {
2527
            if (!tableBL.getFieldsName().contains("SOURCE")) {
2528
                t.addVarCharColumn("SOURCE", 512);
2528
                t.addVarCharColumn("SOURCE", 512);
2529
                alterBL = true;
2529
                alterBL = true;
2530
            }
2530
            }
2531
            if (!tableBL.getFieldsName().contains("IDSOURCE")) {
2531
            if (!tableBL.getFieldsName().contains("IDSOURCE")) {
2532
                t.addColumn("IDSOURCE", "integer DEFAULT 1");
2532
                t.addColumn("IDSOURCE", "integer DEFAULT 1");
2533
                alterBL = true;
2533
                alterBL = true;
2534
            }
2534
            }
2535
 
2535
 
2536
            if (!tableBL.getFieldsName().contains("DATE_LIVRAISON")) {
2536
            if (!tableBL.getFieldsName().contains("DATE_LIVRAISON")) {
2537
                t.addColumn("DATE_LIVRAISON", "date");
2537
                t.addColumn("DATE_LIVRAISON", "date");
2538
                alterBL = true;
2538
                alterBL = true;
2539
            }
2539
            }
2540
            if (alterBL) {
2540
            if (alterBL) {
2541
                try {
2541
                try {
2542
                    ds.execute(t.asString());
2542
                    ds.execute(t.asString());
2543
                    tableBL.getSchema().updateVersion();
2543
                    tableBL.getSchema().updateVersion();
2544
                    tableBL.fetchFields();
2544
                    tableBL.fetchFields();
2545
                } catch (SQLException ex) {
2545
                } catch (SQLException ex) {
2546
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table BON_DE_LIVRAISON", ex);
2546
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table BON_DE_LIVRAISON", ex);
2547
                }
2547
                }
2548
            }
2548
            }
2549
        }
2549
        }
2550
 
2550
 
2551
        // Fournisseur
2551
        // Fournisseur
2552
        {
2552
        {
2553
            SQLTable tableBL = root.getTable("FOURNISSEUR");
2553
            SQLTable tableBL = root.getTable("FOURNISSEUR");
2554
            boolean alterBL = false;
2554
            boolean alterBL = false;
2555
            AlterTable t = new AlterTable(tableBL);
2555
            AlterTable t = new AlterTable(tableBL);
2556
            if (!tableBL.getFieldsName().contains("ID_COMPTE_PCE_CHARGE")) {
2556
            if (!tableBL.getFieldsName().contains("ID_COMPTE_PCE_CHARGE")) {
2557
                t.addForeignColumn("ID_COMPTE_PCE_CHARGE", root.getTable("COMPTE_PCE"));
2557
                t.addForeignColumn("ID_COMPTE_PCE_CHARGE", root.getTable("COMPTE_PCE"));
2558
                alterBL = true;
2558
                alterBL = true;
2559
            }
2559
            }
2560
            if (alterBL) {
2560
            if (alterBL) {
2561
                try {
2561
                try {
2562
                    ds.execute(t.asString());
2562
                    ds.execute(t.asString());
2563
                    tableBL.getSchema().updateVersion();
2563
                    tableBL.getSchema().updateVersion();
2564
                    tableBL.fetchFields();
2564
                    tableBL.fetchFields();
2565
                } catch (SQLException ex) {
2565
                } catch (SQLException ex) {
2566
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table FOURNISSEUR", ex);
2566
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table FOURNISSEUR", ex);
2567
                }
2567
                }
2568
            }
2568
            }
2569
        }
2569
        }
2570
 
2570
 
2571
        // Numérotation
2571
        // Numérotation
2572
        {
2572
        {
2573
            SQLTable tableNum = root.getTable("NUMEROTATION_AUTO");
2573
            SQLTable tableNum = root.getTable("NUMEROTATION_AUTO");
2574
            boolean alterNum = false;
2574
            boolean alterNum = false;
2575
            AlterTable t = new AlterTable(tableNum);
2575
            AlterTable t = new AlterTable(tableNum);
2576
            if (!tableNum.getFieldsName().contains("AVOIR_F_START")) {
2576
            if (!tableNum.getFieldsName().contains("AVOIR_F_START")) {
2577
                t.addColumn("AVOIR_F_START", "integer DEFAULT 0");
2577
                t.addColumn("AVOIR_F_START", "integer DEFAULT 0");
2578
                alterNum = true;
2578
                alterNum = true;
2579
            }
2579
            }
2580
            if (!tableNum.getFieldsName().contains("AVOIR_F_FORMAT")) {
2580
            if (!tableNum.getFieldsName().contains("AVOIR_F_FORMAT")) {
2581
                t.addVarCharColumn("AVOIR_F_FORMAT", 48);
2581
                t.addVarCharColumn("AVOIR_F_FORMAT", 48);
2582
                alterNum = true;
2582
                alterNum = true;
2583
            }
2583
            }
2584
 
2584
 
2585
            if (alterNum) {
2585
            if (alterNum) {
2586
                try {
2586
                try {
2587
                    ds.execute(t.asString());
2587
                    ds.execute(t.asString());
2588
                    tableNum.getSchema().updateVersion();
2588
                    tableNum.getSchema().updateVersion();
2589
                    tableNum.fetchFields();
2589
                    tableNum.fetchFields();
2590
                } catch (SQLException ex) {
2590
                } catch (SQLException ex) {
2591
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table NUMEROTATION_AUTO", ex);
2591
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table NUMEROTATION_AUTO", ex);
2592
                }
2592
                }
2593
            }
2593
            }
2594
        }
2594
        }
2595
 
2595
 
2596
        SQLTable tableArticle = root.getTable("ARTICLE");
2596
        SQLTable tableArticle = root.getTable("ARTICLE");
2597
 
2597
 
2598
        AlterTable t = new AlterTable(tableArticle);
2598
        AlterTable t = new AlterTable(tableArticle);
2599
        boolean alterArticle = false;
2599
        boolean alterArticle = false;
2600
        if (!tableArticle.getFieldsName().contains("QTE_ACHAT")) {
2600
        if (!tableArticle.getFieldsName().contains("QTE_ACHAT")) {
2601
            t.addColumn("QTE_ACHAT", "integer DEFAULT 1");
2601
            t.addColumn("QTE_ACHAT", "integer DEFAULT 1");
2602
            alterArticle = true;
2602
            alterArticle = true;
2603
        }
2603
        }
2604
        if (!tableArticle.getFieldsName().contains("DESCRIPTIF")) {
2604
        if (!tableArticle.getFieldsName().contains("DESCRIPTIF")) {
2605
            t.addVarCharColumn("DESCRIPTIF", 2048);
2605
            t.addVarCharColumn("DESCRIPTIF", 2048);
2606
            alterArticle = true;
2606
            alterArticle = true;
2607
        }
2607
        }
2608
        if (!tableArticle.getFieldsName().contains("CODE_BARRE")) {
2608
        if (!tableArticle.getFieldsName().contains("CODE_BARRE")) {
2609
            t.addVarCharColumn("CODE_BARRE", 256);
2609
            t.addVarCharColumn("CODE_BARRE", 256);
2610
            alterArticle = true;
2610
            alterArticle = true;
2611
        }
2611
        }
2612
        if (!tableArticle.getFieldsName().contains("GESTION_STOCK")) {
2612
        if (!tableArticle.getFieldsName().contains("GESTION_STOCK")) {
2613
            t.addColumn("GESTION_STOCK", "boolean DEFAULT true");
2613
            t.addColumn("GESTION_STOCK", "boolean DEFAULT true");
2614
            alterArticle = true;
2614
            alterArticle = true;
2615
        }
2615
        }
2616
        if (!tableArticle.getFieldsName().contains("CODE_DOUANIER")) {
2616
        if (!tableArticle.getFieldsName().contains("CODE_DOUANIER")) {
2617
            t.addVarCharColumn("CODE_DOUANIER", 256);
2617
            t.addVarCharColumn("CODE_DOUANIER", 256);
2618
            alterArticle = true;
2618
            alterArticle = true;
2619
        }
2619
        }
2620
        if (!tableArticle.getFieldsName().contains("QTE_MIN")) {
2620
        if (!tableArticle.getFieldsName().contains("QTE_MIN")) {
2621
            t.addColumn("QTE_MIN", "integer DEFAULT 1");
2621
            t.addColumn("QTE_MIN", "integer DEFAULT 1");
2622
            alterArticle = true;
2622
            alterArticle = true;
2623
        }
2623
        }
2624
        if (!tableArticle.getFieldsName().contains("ID_DEVISE")) {
2624
        if (!tableArticle.getFieldsName().contains("ID_DEVISE")) {
2625
            t.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
2625
            t.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
2626
            alterArticle = true;
2626
            alterArticle = true;
2627
        }
2627
        }
2628
        if (!tableArticle.getFieldsName().contains("ID_FOURNISSEUR")) {
2628
        if (!tableArticle.getFieldsName().contains("ID_FOURNISSEUR")) {
2629
            t.addForeignColumn("ID_FOURNISSEUR", root.findTable("FOURNISSEUR", true));
2629
            t.addForeignColumn("ID_FOURNISSEUR", root.findTable("FOURNISSEUR", true));
2630
            alterArticle = true;
2630
            alterArticle = true;
2631
        }
2631
        }
2632
        if (!tableArticle.getFieldsName().contains("PV_U_DEVISE")) {
2632
        if (!tableArticle.getFieldsName().contains("PV_U_DEVISE")) {
2633
            t.addColumn("PV_U_DEVISE", "bigint default 0");
2633
            t.addColumn("PV_U_DEVISE", "bigint default 0");
2634
            alterArticle = true;
2634
            alterArticle = true;
2635
        }
2635
        }
2636
        if (!tableArticle.getFieldsName().contains("ID_DEVISE_HA")) {
2636
        if (!tableArticle.getFieldsName().contains("ID_DEVISE_HA")) {
2637
            t.addForeignColumn("ID_DEVISE_HA", root.findTable("DEVISE", true));
2637
            t.addForeignColumn("ID_DEVISE_HA", root.findTable("DEVISE", true));
2638
            alterArticle = true;
2638
            alterArticle = true;
2639
        }
2639
        }
2640
        if (!tableArticle.getFieldsName().contains("PA_DEVISE")) {
2640
        if (!tableArticle.getFieldsName().contains("PA_DEVISE")) {
2641
            t.addColumn("PA_DEVISE", "bigint default 0");
2641
            t.addColumn("PA_DEVISE", "bigint default 0");
2642
            alterArticle = true;
2642
            alterArticle = true;
2643
        }
2643
        }
2644
        if (!tableArticle.getFieldsName().contains("ID_PAYS")) {
2644
        if (!tableArticle.getFieldsName().contains("ID_PAYS")) {
2645
            t.addForeignColumn("ID_PAYS", root.findTable("PAYS", true));
2645
            t.addForeignColumn("ID_PAYS", root.findTable("PAYS", true));
2646
            alterArticle = true;
2646
            alterArticle = true;
2647
        }
2647
        }
2648
        if (alterArticle) {
2648
        if (alterArticle) {
2649
            try {
2649
            try {
2650
                ds.execute(t.asString());
2650
                ds.execute(t.asString());
2651
                tableArticle.getSchema().updateVersion();
2651
                tableArticle.getSchema().updateVersion();
2652
                tableArticle.fetchFields();
2652
                tableArticle.fetchFields();
2653
            } catch (SQLException ex) {
2653
            } catch (SQLException ex) {
2654
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table ARTICLE", ex);
2654
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table ARTICLE", ex);
2655
            }
2655
            }
2656
        }
2656
        }
2657
 
2657
 
2658
        // Création de la table Langue
2658
        // Création de la table Langue
2659
        boolean refetchRoot = false;
2659
        boolean refetchRoot = false;
2660
        if (!root.contains("OBJECTIF_COMMERCIAL")) {
2660
        if (!root.contains("OBJECTIF_COMMERCIAL")) {
2661
 
2661
 
2662
            SQLCreateTable createObjectif = new SQLCreateTable(root, "OBJECTIF_COMMERCIAL");
2662
            SQLCreateTable createObjectif = new SQLCreateTable(root, "OBJECTIF_COMMERCIAL");
2663
            createObjectif.addVarCharColumn("MOIS", 32);
2663
            createObjectif.addVarCharColumn("MOIS", 32);
2664
            createObjectif.addColumn("ANNEE", "integer");
2664
            createObjectif.addColumn("ANNEE", "integer");
2665
            createObjectif.addColumn("MARGE_HT", "bigint DEFAULT 0");
2665
            createObjectif.addColumn("MARGE_HT", "bigint DEFAULT 0");
2666
            createObjectif.addColumn("POURCENT_MARGE", "numeric (16,8)");
2666
            createObjectif.addColumn("POURCENT_MARGE", "numeric (16,8)");
2667
            createObjectif.addColumn("CHIFFRE_AFFAIRE", "bigint DeFAULT 0");
2667
            createObjectif.addColumn("CHIFFRE_AFFAIRE", "bigint DeFAULT 0");
2668
            createObjectif.addForeignColumn("COMMERCIAL");
2668
            createObjectif.addForeignColumn("COMMERCIAL");
2669
            try {
2669
            try {
2670
                ds.execute(createObjectif.asString());
2670
                ds.execute(createObjectif.asString());
2671
                insertUndef(createObjectif);
2671
                insertUndef(createObjectif);
2672
                tableDevis.getSchema().updateVersion();
2672
                tableDevis.getSchema().updateVersion();
2673
                refetchRoot = true;
2673
                refetchRoot = true;
2674
            } catch (SQLException ex) {
2674
            } catch (SQLException ex) {
2675
                throw new IllegalStateException("Erreur lors de la création de la table OBJECTIF_COMMERCIAL", ex);
2675
                throw new IllegalStateException("Erreur lors de la création de la table OBJECTIF_COMMERCIAL", ex);
2676
            }
2676
            }
2677
 
2677
 
2678
        }
2678
        }
2679
 
2679
 
2680
        if (!root.contains("LANGUE")) {
2680
        if (!root.contains("LANGUE")) {
2681
 
2681
 
2682
            SQLCreateTable createLangue = new SQLCreateTable(root, "LANGUE");
2682
            SQLCreateTable createLangue = new SQLCreateTable(root, "LANGUE");
2683
            createLangue.addVarCharColumn("CODE", 256);
2683
            createLangue.addVarCharColumn("CODE", 256);
2684
            createLangue.addVarCharColumn("NOM", 256);
2684
            createLangue.addVarCharColumn("NOM", 256);
2685
            createLangue.addVarCharColumn("CHEMIN", 256);
2685
            createLangue.addVarCharColumn("CHEMIN", 256);
2686
            try {
2686
            try {
2687
                ds.execute(createLangue.asString());
2687
                ds.execute(createLangue.asString());
2688
                insertUndef(createLangue);
2688
                insertUndef(createLangue);
2689
                tableDevis.getSchema().updateVersion();
2689
                tableDevis.getSchema().updateVersion();
2690
                root.refetchTable(createLangue.getName());
2690
                root.refetchTable(createLangue.getName());
2691
            } catch (SQLException ex) {
2691
            } catch (SQLException ex) {
2692
                throw new IllegalStateException("Erreur lors de la création de la table LANGUE", ex);
2692
                throw new IllegalStateException("Erreur lors de la création de la table LANGUE", ex);
2693
            }
2693
            }
2694
 
2694
 
2695
            final String[] langs = new String[] { "FR", "Français", "EN", "Anglais", "SP", "Espagnol", "DE", "Allemand", "NL", "Néerlandais", "IT", "Italien" };
2695
            final String[] langs = new String[] { "FR", "Français", "EN", "Anglais", "SP", "Espagnol", "DE", "Allemand", "NL", "Néerlandais", "IT", "Italien" };
2696
            // ('FR', 'Français', 1.000), ('EN', 'Anglais', 2.000)
2696
            // ('FR', 'Français', 1.000), ('EN', 'Anglais', 2.000)
2697
            final List<String> values = new ArrayList<String>();
2697
            final List<String> values = new ArrayList<String>();
2698
            final SQLBase base = root.getBase();
2698
            final SQLBase base = root.getBase();
2699
            for (int i = 0; i < langs.length; i += 2) {
2699
            for (int i = 0; i < langs.length; i += 2) {
2700
                final int order = values.size() + 1;
2700
                final int order = values.size() + 1;
2701
                values.add("(" + base.quoteString(langs[i]) + ", " + base.quoteString(langs[i + 1]) + ", " + order + ")");
2701
                values.add("(" + base.quoteString(langs[i]) + ", " + base.quoteString(langs[i + 1]) + ", " + order + ")");
2702
            }
2702
            }
2703
            final String valuesStr = CollectionUtils.join(values, ", ");
2703
            final String valuesStr = CollectionUtils.join(values, ", ");
2704
            final String insertVals = "INSERT INTO " + getTableName(createLangue).quote() + "(" + SQLBase.quoteIdentifier("CODE") + ", " + SQLBase.quoteIdentifier("NOM") + ", "
2704
            final String insertVals = "INSERT INTO " + getTableName(createLangue).quote() + "(" + SQLBase.quoteIdentifier("CODE") + ", " + SQLBase.quoteIdentifier("NOM") + ", "
2705
                    + SQLBase.quoteIdentifier(SQLSyntax.ORDER_NAME) + ") VALUES" + valuesStr;
2705
                    + SQLBase.quoteIdentifier(SQLSyntax.ORDER_NAME) + ") VALUES" + valuesStr;
2706
            ds.execute(insertVals);
2706
            ds.execute(insertVals);
2707
        }
2707
        }
2708
 
2708
 
2709
        // Création de la table Modéle
2709
        // Création de la table Modéle
2710
        if (!root.contains("MODELE")) {
2710
        if (!root.contains("MODELE")) {
2711
 
2711
 
2712
            SQLCreateTable createModele = new SQLCreateTable(root, "MODELE");
2712
            SQLCreateTable createModele = new SQLCreateTable(root, "MODELE");
2713
            createModele.addVarCharColumn("NOM", 256);
2713
            createModele.addVarCharColumn("NOM", 256);
2714
            createModele.addForeignColumn("ID_TYPE_MODELE", root.findTable("TYPE_MODELE", true));
2714
            createModele.addForeignColumn("ID_TYPE_MODELE", root.findTable("TYPE_MODELE", true));
2715
            try {
2715
            try {
2716
                ds.execute(createModele.asString());
2716
                ds.execute(createModele.asString());
2717
                insertUndef(createModele);
2717
                insertUndef(createModele);
2718
                tableDevis.getSchema().updateVersion();
2718
                tableDevis.getSchema().updateVersion();
2719
                refetchRoot = true;
2719
                refetchRoot = true;
2720
            } catch (SQLException ex) {
2720
            } catch (SQLException ex) {
2721
                throw new IllegalStateException("Erreur lors de la création de la table MODELE", ex);
2721
                throw new IllegalStateException("Erreur lors de la création de la table MODELE", ex);
2722
            }
2722
            }
2723
        }
2723
        }
2724
 
2724
 
2725
        // Création de la table Modéle
2725
        // Création de la table Modéle
2726
        if (!root.contains("CONTACT_FOURNISSEUR")) {
2726
        if (!root.contains("CONTACT_FOURNISSEUR")) {
2727
 
2727
 
2728
            SQLCreateTable createModele = new SQLCreateTable(root, "CONTACT_FOURNISSEUR");
2728
            SQLCreateTable createModele = new SQLCreateTable(root, "CONTACT_FOURNISSEUR");
2729
            createModele.addVarCharColumn("NOM", 256);
2729
            createModele.addVarCharColumn("NOM", 256);
2730
            createModele.addVarCharColumn("PRENOM", 256);
2730
            createModele.addVarCharColumn("PRENOM", 256);
2731
            createModele.addVarCharColumn("TEL_DIRECT", 256);
2731
            createModele.addVarCharColumn("TEL_DIRECT", 256);
2732
            createModele.addVarCharColumn("TEL_MOBILE", 256);
2732
            createModele.addVarCharColumn("TEL_MOBILE", 256);
2733
            createModele.addVarCharColumn("EMAIL", 256);
2733
            createModele.addVarCharColumn("EMAIL", 256);
2734
            createModele.addVarCharColumn("FAX", 256);
2734
            createModele.addVarCharColumn("FAX", 256);
2735
            createModele.addVarCharColumn("FONCTION", 256);
2735
            createModele.addVarCharColumn("FONCTION", 256);
2736
            createModele.addVarCharColumn("TEL_PERSONEL", 256);
2736
            createModele.addVarCharColumn("TEL_PERSONEL", 256);
2737
            createModele.addVarCharColumn("TEL_STANDARD", 256);
2737
            createModele.addVarCharColumn("TEL_STANDARD", 256);
2738
            createModele.addForeignColumn("ID_TITRE_PERSONNEL", root.findTable("TITRE_PERSONNEL"));
2738
            createModele.addForeignColumn("ID_TITRE_PERSONNEL", root.findTable("TITRE_PERSONNEL"));
2739
            createModele.addForeignColumn("ID_FOURNISSEUR", root.findTable("FOURNISSEUR"));
2739
            createModele.addForeignColumn("ID_FOURNISSEUR", root.findTable("FOURNISSEUR"));
2740
 
2740
 
2741
            try {
2741
            try {
2742
                ds.execute(createModele.asString());
2742
                ds.execute(createModele.asString());
2743
                insertUndef(createModele);
2743
                insertUndef(createModele);
2744
                tableDevis.getSchema().updateVersion();
2744
                tableDevis.getSchema().updateVersion();
2745
                refetchRoot = true;
2745
                refetchRoot = true;
2746
            } catch (SQLException ex) {
2746
            } catch (SQLException ex) {
2747
                throw new IllegalStateException("Erreur lors de la création de la table MODELE", ex);
2747
                throw new IllegalStateException("Erreur lors de la création de la table MODELE", ex);
2748
            }
2748
            }
2749
        }
2749
        }
2750
 
2750
 
2751
        // Création de la table Tarif
2751
        // Création de la table Tarif
2752
        if (!root.contains("TARIF")) {
2752
        if (!root.contains("TARIF")) {
2753
 
2753
 
2754
            SQLCreateTable createTarif = new SQLCreateTable(root, "TARIF");
2754
            SQLCreateTable createTarif = new SQLCreateTable(root, "TARIF");
2755
            createTarif.addVarCharColumn("NOM", 256);
2755
            createTarif.addVarCharColumn("NOM", 256);
2756
            createTarif.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
2756
            createTarif.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
2757
            createTarif.addForeignColumn("ID_TAXE", root.findTable("TAXE", true));
2757
            createTarif.addForeignColumn("ID_TAXE", root.findTable("TAXE", true));
2758
            createTarif.asString();
2758
            createTarif.asString();
2759
            try {
2759
            try {
2760
                ds.execute(createTarif.asString());
2760
                ds.execute(createTarif.asString());
2761
                insertUndef(createTarif);
2761
                insertUndef(createTarif);
2762
                tableDevis.getSchema().updateVersion();
2762
                tableDevis.getSchema().updateVersion();
2763
                root.refetchTable(createTarif.getName());
2763
                root.refetchTable(createTarif.getName());
2764
            } catch (SQLException ex) {
2764
            } catch (SQLException ex) {
2765
                throw new IllegalStateException("Erreur lors de la création de la table TARIF", ex);
2765
                throw new IllegalStateException("Erreur lors de la création de la table TARIF", ex);
2766
            }
2766
            }
2767
        }
2767
        }
2768
 
2768
 
2769
        // Création de la table article Tarif
2769
        // Création de la table article Tarif
2770
        if (!root.contains("ARTICLE_TARIF")) {
2770
        if (!root.contains("ARTICLE_TARIF")) {
2771
 
2771
 
2772
            SQLCreateTable createTarif = new SQLCreateTable(root, "ARTICLE_TARIF");
2772
            SQLCreateTable createTarif = new SQLCreateTable(root, "ARTICLE_TARIF");
2773
            createTarif.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
2773
            createTarif.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
2774
            createTarif.addForeignColumn("ID_TAXE", root.findTable("TAXE", true));
2774
            createTarif.addForeignColumn("ID_TAXE", root.findTable("TAXE", true));
2775
            createTarif.addForeignColumn("ID_TARIF", root.findTable("TARIF", true));
2775
            createTarif.addForeignColumn("ID_TARIF", root.findTable("TARIF", true));
2776
            createTarif.addForeignColumn("ID_ARTICLE", root.findTable("ARTICLE", true));
2776
            createTarif.addForeignColumn("ID_ARTICLE", root.findTable("ARTICLE", true));
2777
            createTarif.addColumn("PV_HT", "bigint DEFAULT 0");
2777
            createTarif.addColumn("PV_HT", "bigint DEFAULT 0");
2778
            createTarif.addColumn("PV_TTC", "bigint DEFAULT 0");
2778
            createTarif.addColumn("PV_TTC", "bigint DEFAULT 0");
2779
            createTarif.addColumn("PRIX_METRIQUE_VT_1", "bigint DEFAULT 0");
2779
            createTarif.addColumn("PRIX_METRIQUE_VT_1", "bigint DEFAULT 0");
2780
            createTarif.addColumn("PRIX_METRIQUE_VT_2", "bigint DEFAULT 0");
2780
            createTarif.addColumn("PRIX_METRIQUE_VT_2", "bigint DEFAULT 0");
2781
            createTarif.addColumn("PRIX_METRIQUE_VT_3", "bigint DEFAULT 0");
2781
            createTarif.addColumn("PRIX_METRIQUE_VT_3", "bigint DEFAULT 0");
2782
            createTarif.asString();
2782
            createTarif.asString();
2783
            try {
2783
            try {
2784
                ds.execute(createTarif.asString());
2784
                ds.execute(createTarif.asString());
2785
                insertUndef(createTarif);
2785
                insertUndef(createTarif);
2786
                tableDevis.getSchema().updateVersion();
2786
                tableDevis.getSchema().updateVersion();
2787
                refetchRoot = true;
2787
                refetchRoot = true;
2788
            } catch (SQLException ex) {
2788
            } catch (SQLException ex) {
2789
                throw new IllegalStateException("Erreur lors de la création de la table ARTICLE_TARIF", ex);
2789
                throw new IllegalStateException("Erreur lors de la création de la table ARTICLE_TARIF", ex);
2790
            }
2790
            }
2791
        }
2791
        }
2792
 
2792
 
2793
        // Création de la table article Désignation
2793
        // Création de la table article Désignation
2794
        if (!root.contains("ARTICLE_DESIGNATION")) {
2794
        if (!root.contains("ARTICLE_DESIGNATION")) {
2795
 
2795
 
2796
            SQLCreateTable createTarif = new SQLCreateTable(root, "ARTICLE_DESIGNATION");
2796
            SQLCreateTable createTarif = new SQLCreateTable(root, "ARTICLE_DESIGNATION");
2797
            createTarif.addForeignColumn("ID_ARTICLE", root.findTable("ARTICLE", true));
2797
            createTarif.addForeignColumn("ID_ARTICLE", root.findTable("ARTICLE", true));
2798
            createTarif.addForeignColumn("ID_LANGUE", root.findTable("LANGUE", true));
2798
            createTarif.addForeignColumn("ID_LANGUE", root.findTable("LANGUE", true));
2799
            createTarif.addVarCharColumn("NOM", 1024);
2799
            createTarif.addVarCharColumn("NOM", 1024);
2800
            createTarif.asString();
2800
            createTarif.asString();
2801
            try {
2801
            try {
2802
                ds.execute(createTarif.asString());
2802
                ds.execute(createTarif.asString());
2803
                insertUndef(createTarif);
2803
                insertUndef(createTarif);
2804
                tableDevis.getSchema().updateVersion();
2804
                tableDevis.getSchema().updateVersion();
2805
                refetchRoot = true;
2805
                refetchRoot = true;
2806
            } catch (SQLException ex) {
2806
            } catch (SQLException ex) {
2807
                throw new IllegalStateException("Erreur lors de la création de la table ARTICLE_DESIGNATION", ex);
2807
                throw new IllegalStateException("Erreur lors de la création de la table ARTICLE_DESIGNATION", ex);
2808
            }
2808
            }
2809
        }
2809
        }
2810
 
2810
 
2811
        if (!root.contains("UNITE_VENTE")) {
2811
        if (!root.contains("UNITE_VENTE")) {
2812
 
2812
 
2813
            SQLCreateTable createUnite = new SQLCreateTable(root, "UNITE_VENTE");
2813
            SQLCreateTable createUnite = new SQLCreateTable(root, "UNITE_VENTE");
2814
            createUnite.addVarCharColumn("CODE", 32);
2814
            createUnite.addVarCharColumn("CODE", 32);
2815
            createUnite.addVarCharColumn("NOM", 256);
2815
            createUnite.addVarCharColumn("NOM", 256);
2816
            createUnite.addColumn("A_LA_PIECE", "boolean DEFAULT false");
2816
            createUnite.addColumn("A_LA_PIECE", "boolean DEFAULT false");
2817
            createUnite.addVarCharColumn("INFOS", 256);
2817
            createUnite.addVarCharColumn("INFOS", 256);
2818
            try {
2818
            try {
2819
                ds.execute(createUnite.asString());
2819
                ds.execute(createUnite.asString());
2820
                insertUndef(createUnite);
2820
                insertUndef(createUnite);
2821
                final String insert = "INSERT into " + getTableName(createUnite).quote()
2821
                final String insert = "INSERT into " + getTableName(createUnite).quote()
2822
                        + "(\"CODE\",\"NOM\",\"A_LA_PIECE\",\"ORDRE\") VALUES('pièce','à la pièce',true,1),('m','mètres',false,2),('m²','mètres carré',false,3),('m3','mètres cube',false,4),('l','litres',false,5),('kg','kilos',false,6),('h','heures',false,7),('j','jours',false,8),('mois','mois',false,9)";
2822
                        + "(\"CODE\",\"NOM\",\"A_LA_PIECE\",\"ORDRE\") VALUES('pièce','à la pièce',true,1),('m','mètres',false,2),('m²','mètres carré',false,3),('m3','mètres cube',false,4),('l','litres',false,5),('kg','kilos',false,6),('h','heures',false,7),('j','jours',false,8),('mois','mois',false,9)";
2823
                root.getDBSystemRoot().getDataSource().execute(insert);
2823
                root.getDBSystemRoot().getDataSource().execute(insert);
2824
                tableDevis.getSchema().updateVersion();
2824
                tableDevis.getSchema().updateVersion();
2825
                refetchRoot = true;
2825
                refetchRoot = true;
2826
            } catch (SQLException ex) {
2826
            } catch (SQLException ex) {
2827
                throw new IllegalStateException("Erreur lors de la création de la table UNITE_VENTE", ex);
2827
                throw new IllegalStateException("Erreur lors de la création de la table UNITE_VENTE", ex);
2828
            }
2828
            }
2829
 
2829
 
2830
        }
2830
        }
2831
 
2831
 
2832
        // Chargement des tables fraichement créées
2832
        // Chargement des tables fraichement créées
2833
        if (refetchRoot)
2833
        if (refetchRoot)
2834
            root.refetch();
2834
            root.refetch();
2835
 
2835
 
2836
        if (!tableArticle.getFieldsName().contains("ID_UNITE_VENTE")) {
2836
        if (!tableArticle.getFieldsName().contains("ID_UNITE_VENTE")) {
2837
            AlterTable alterTableArticle = new AlterTable(tableArticle);
2837
            AlterTable alterTableArticle = new AlterTable(tableArticle);
2838
            alterTableArticle.addForeignColumn("ID_UNITE_VENTE", root.findTable("UNITE_VENTE", true).getSQLName(), "ID", "2");
2838
            alterTableArticle.addForeignColumn("ID_UNITE_VENTE", root.findTable("UNITE_VENTE", true).getSQLName(), "ID", "2");
2839
            try {
2839
            try {
2840
                ds.execute(alterTableArticle.asString());
2840
                ds.execute(alterTableArticle.asString());
2841
                tableArticle.getSchema().updateVersion();
2841
                tableArticle.getSchema().updateVersion();
2842
                tableArticle.fetchFields();
2842
                tableArticle.fetchFields();
2843
            } catch (SQLException ex) {
2843
            } catch (SQLException ex) {
2844
                throw new IllegalStateException("Erreur lors de l'ajout du champ UNITE_VENTE sur la table ARTICLE", ex);
2844
                throw new IllegalStateException("Erreur lors de l'ajout du champ UNITE_VENTE sur la table ARTICLE", ex);
2845
            }
2845
            }
2846
        }
2846
        }
2847
 
2847
 
2848
        SQLTable tableVFElt = root.getTable("SAISIE_VENTE_FACTURE_ELEMENT");
2848
        SQLTable tableVFElt = root.getTable("SAISIE_VENTE_FACTURE_ELEMENT");
2849
        addVenteEltField(tableVFElt, root);
2849
        addVenteEltField(tableVFElt, root);
2850
 
2850
 
2851
        SQLTable tableDevisElt = root.getTable("DEVIS_ELEMENT");
2851
        SQLTable tableDevisElt = root.getTable("DEVIS_ELEMENT");
2852
        addVenteEltField(tableDevisElt, root);
2852
        addVenteEltField(tableDevisElt, root);
2853
 
2853
 
2854
        SQLTable tableCmdElt = root.getTable("COMMANDE_CLIENT_ELEMENT");
2854
        SQLTable tableCmdElt = root.getTable("COMMANDE_CLIENT_ELEMENT");
2855
        addVenteEltField(tableCmdElt, root);
2855
        addVenteEltField(tableCmdElt, root);
2856
 
2856
 
2857
        SQLTable tableBonElt = root.getTable("BON_DE_LIVRAISON_ELEMENT");
2857
        SQLTable tableBonElt = root.getTable("BON_DE_LIVRAISON_ELEMENT");
2858
        addVenteEltField(tableBonElt, root);
2858
        addVenteEltField(tableBonElt, root);
2859
 
2859
 
2860
        SQLTable tableAvoirElt = root.getTable("AVOIR_CLIENT_ELEMENT");
2860
        SQLTable tableAvoirElt = root.getTable("AVOIR_CLIENT_ELEMENT");
2861
        addVenteEltField(tableAvoirElt, root);
2861
        addVenteEltField(tableAvoirElt, root);
2862
 
2862
 
2863
        SQLTable tableCmdFournElt = root.getTable("COMMANDE_ELEMENT");
2863
        SQLTable tableCmdFournElt = root.getTable("COMMANDE_ELEMENT");
2864
        addHAElementField(tableCmdFournElt, root);
2864
        addHAElementField(tableCmdFournElt, root);
2865
        if (root.contains("DEMANDE_PRIX_ELEMENT")) {
2865
        if (root.contains("DEMANDE_PRIX_ELEMENT")) {
2866
            SQLTable tableDmdFournElt = root.getTable("DEMANDE_PRIX_ELEMENT");
2866
            SQLTable tableDmdFournElt = root.getTable("DEMANDE_PRIX_ELEMENT");
2867
            addHAElementField(tableDmdFournElt, root);
2867
            addHAElementField(tableDmdFournElt, root);
2868
        }
2868
        }
2869
 
2869
 
2870
        SQLTable tableBonRecptElt = root.getTable("BON_RECEPTION_ELEMENT");
2870
        SQLTable tableBonRecptElt = root.getTable("BON_RECEPTION_ELEMENT");
2871
        addHAElementField(tableBonRecptElt, root);
2871
        addHAElementField(tableBonRecptElt, root);
2872
 
2872
 
2873
        SQLTable tableBonRecpt = root.getTable("BON_RECEPTION");
2873
        SQLTable tableBonRecpt = root.getTable("BON_RECEPTION");
2874
        addDeviseHAField(tableBonRecpt, root);
2874
        addDeviseHAField(tableBonRecpt, root);
2875
 
2875
 
2876
        SQLTable tableCommande = root.getTable("COMMANDE");
2876
        SQLTable tableCommande = root.getTable("COMMANDE");
2877
        addDeviseHAField(tableCommande, root);
2877
        addDeviseHAField(tableCommande, root);
2878
 
2878
 
2879
        patchFieldElt1Dot3(root.getTable("ARTICLE"), root);
2879
        patchFieldElt1Dot3(root.getTable("ARTICLE"), root);
2880
        patchFieldElt1Dot3(root.getTable("ARTICLE_TARIF"), root);
2880
        patchFieldElt1Dot3(root.getTable("ARTICLE_TARIF"), root);
2881
 
2881
 
2882
        if (!tableCommande.getFieldsName().contains("ID_ADRESSE")) {
2882
        if (!tableCommande.getFieldsName().contains("ID_ADRESSE")) {
2883
            AlterTable alterCmd = new AlterTable(tableCommande);
2883
            AlterTable alterCmd = new AlterTable(tableCommande);
2884
            alterCmd.addForeignColumn("ID_ADRESSE", root.findTable("ADRESSE", true));
2884
            alterCmd.addForeignColumn("ID_ADRESSE", root.findTable("ADRESSE", true));
2885
            try {
2885
            try {
2886
                ds.execute(alterCmd.asString());
2886
                ds.execute(alterCmd.asString());
2887
                tableCommande.getSchema().updateVersion();
2887
                tableCommande.getSchema().updateVersion();
2888
            } catch (SQLException ex) {
2888
            } catch (SQLException ex) {
2889
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table COMMANDE", ex);
2889
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table COMMANDE", ex);
2890
            }
2890
            }
2891
 
2891
 
2892
        }
2892
        }
2893
        if (!tableCommande.getFieldsName().contains("ID_CLIENT")) {
2893
        if (!tableCommande.getFieldsName().contains("ID_CLIENT")) {
2894
            AlterTable alterCmd = new AlterTable(tableCommande);
2894
            AlterTable alterCmd = new AlterTable(tableCommande);
2895
            alterCmd.addForeignColumn("ID_CLIENT", root.findTable("CLIENT"));
2895
            alterCmd.addForeignColumn("ID_CLIENT", root.findTable("CLIENT"));
2896
            try {
2896
            try {
2897
                ds.execute(alterCmd.asString());
2897
                ds.execute(alterCmd.asString());
2898
                tableCommande.getSchema().updateVersion();
2898
                tableCommande.getSchema().updateVersion();
2899
            } catch (SQLException ex) {
2899
            } catch (SQLException ex) {
2900
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table COMMANDE", ex);
2900
                throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table COMMANDE", ex);
2901
            }
2901
            }
2902
 
2902
 
2903
        }
2903
        }
2904
 
2904
 
2905
        {
2905
        {
2906
            addTotalDeviseField(tableDevis, root);
2906
            addTotalDeviseField(tableDevis, root);
2907
            addModeleField(tableDevis, root);
2907
            addModeleField(tableDevis, root);
2908
 
2908
 
2909
            SQLTable tableVF = root.getTable("SAISIE_VENTE_FACTURE");
2909
            SQLTable tableVF = root.getTable("SAISIE_VENTE_FACTURE");
2910
            addTotalDeviseField(tableVF, root);
2910
            addTotalDeviseField(tableVF, root);
2911
            addModeleField(tableVF, root);
2911
            addModeleField(tableVF, root);
2912
 
2912
 
2913
            addTotalDeviseField(tableDevis, root);
2913
            addTotalDeviseField(tableDevis, root);
2914
            addModeleField(tableDevis, root);
2914
            addModeleField(tableDevis, root);
2915
 
2915
 
2916
            SQLTable tableCmd = root.getTable("COMMANDE_CLIENT");
2916
            SQLTable tableCmd = root.getTable("COMMANDE_CLIENT");
2917
            addTotalDeviseField(tableCmd, root);
2917
            addTotalDeviseField(tableCmd, root);
2918
            addModeleField(tableCmd, root);
2918
            addModeleField(tableCmd, root);
2919
 
2919
 
2920
            SQLTable tableBon = root.getTable("BON_DE_LIVRAISON");
2920
            SQLTable tableBon = root.getTable("BON_DE_LIVRAISON");
2921
            addTotalDeviseField(tableBon, root);
2921
            addTotalDeviseField(tableBon, root);
2922
            addModeleField(tableBon, root);
2922
            addModeleField(tableBon, root);
2923
 
2923
 
2924
            SQLTable tableAvoir = root.getTable("AVOIR_CLIENT");
2924
            SQLTable tableAvoir = root.getTable("AVOIR_CLIENT");
2925
            addTotalDeviseField(tableAvoir, root);
2925
            addTotalDeviseField(tableAvoir, root);
2926
            addModeleField(tableAvoir, root);
2926
            addModeleField(tableAvoir, root);
2927
        }
2927
        }
2928
        // Change client
2928
        // Change client
2929
        {
2929
        {
2930
            SQLTable tableClient = root.getTable("CLIENT");
2930
            SQLTable tableClient = root.getTable("CLIENT");
2931
 
2931
 
2932
            AlterTable tClient = new AlterTable(tableClient);
2932
            AlterTable tClient = new AlterTable(tableClient);
2933
            boolean alterClient = false;
2933
            boolean alterClient = false;
2934
 
2934
 
2935
            if (!tableClient.getFieldsName().contains("ID_TARIF")) {
2935
            if (!tableClient.getFieldsName().contains("ID_TARIF")) {
2936
                tClient.addForeignColumn("ID_TARIF", root.findTable("TARIF", true));
2936
                tClient.addForeignColumn("ID_TARIF", root.findTable("TARIF", true));
2937
                alterClient = true;
2937
                alterClient = true;
2938
            }
2938
            }
2939
            if (!tableClient.getFieldsName().contains("ID_PAYS")) {
2939
            if (!tableClient.getFieldsName().contains("ID_PAYS")) {
2940
                tClient.addForeignColumn("ID_PAYS", root.findTable("PAYS", true));
2940
                tClient.addForeignColumn("ID_PAYS", root.findTable("PAYS", true));
2941
                alterClient = true;
2941
                alterClient = true;
2942
            }
2942
            }
2943
            if (!tableClient.getFieldsName().contains("ID_LANGUE")) {
2943
            if (!tableClient.getFieldsName().contains("ID_LANGUE")) {
2944
                tClient.addForeignColumn("ID_LANGUE", root.findTable("LANGUE", true));
2944
                tClient.addForeignColumn("ID_LANGUE", root.findTable("LANGUE", true));
2945
                alterClient = true;
2945
                alterClient = true;
2946
            }
2946
            }
2947
 
2947
 
2948
            if (!tableClient.getFieldsName().contains("ID_DEVISE")) {
2948
            if (!tableClient.getFieldsName().contains("ID_DEVISE")) {
2949
                tClient.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
2949
                tClient.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
2950
                alterClient = true;
2950
                alterClient = true;
2951
            }
2951
            }
2952
            if (alterClient) {
2952
            if (alterClient) {
2953
                try {
2953
                try {
2954
                    ds.execute(tClient.asString());
2954
                    ds.execute(tClient.asString());
2955
                    tableClient.getSchema().updateVersion();
2955
                    tableClient.getSchema().updateVersion();
2956
                } catch (SQLException ex) {
2956
                } catch (SQLException ex) {
2957
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table CLIENT", ex);
2957
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table CLIENT", ex);
2958
                }
2958
                }
2959
            }
2959
            }
2960
        }
2960
        }
2961
 
2961
 
2962
        // Change Pays
2962
        // Change Pays
2963
        {
2963
        {
2964
            SQLTable tablePays = root.getTable("PAYS");
2964
            SQLTable tablePays = root.getTable("PAYS");
2965
 
2965
 
2966
            AlterTable tPays = new AlterTable(tablePays);
2966
            AlterTable tPays = new AlterTable(tablePays);
2967
            boolean alterPays = false;
2967
            boolean alterPays = false;
2968
 
2968
 
2969
            if (!tablePays.getFieldsName().contains("ID_TARIF")) {
2969
            if (!tablePays.getFieldsName().contains("ID_TARIF")) {
2970
                tPays.addForeignColumn("ID_TARIF", root.findTable("TARIF", true));
2970
                tPays.addForeignColumn("ID_TARIF", root.findTable("TARIF", true));
2971
                alterPays = true;
2971
                alterPays = true;
2972
            }
2972
            }
2973
            if (!tablePays.getFieldsName().contains("ID_LANGUE")) {
2973
            if (!tablePays.getFieldsName().contains("ID_LANGUE")) {
2974
                tPays.addForeignColumn("ID_LANGUE", root.findTable("LANGUE", true));
2974
                tPays.addForeignColumn("ID_LANGUE", root.findTable("LANGUE", true));
2975
                alterPays = true;
2975
                alterPays = true;
2976
            }
2976
            }
2977
            if (alterPays) {
2977
            if (alterPays) {
2978
                try {
2978
                try {
2979
                    ds.execute(tPays.asString());
2979
                    ds.execute(tPays.asString());
2980
                    tablePays.getSchema().updateVersion();
2980
                    tablePays.getSchema().updateVersion();
2981
                } catch (SQLException ex) {
2981
                } catch (SQLException ex) {
2982
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table PAYS", ex);
2982
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table PAYS", ex);
2983
                }
2983
                }
2984
            }
2984
            }
2985
        }
2985
        }
2986
        // Change Commande
2986
        // Change Commande
2987
        {
2987
        {
2988
            SQLTable tableCmd = root.getTable("COMMANDE");
2988
            SQLTable tableCmd = root.getTable("COMMANDE");
2989
 
2989
 
2990
            AlterTable tCmd = new AlterTable(tableCmd);
2990
            AlterTable tCmd = new AlterTable(tableCmd);
2991
            boolean alterCmd = false;
2991
            boolean alterCmd = false;
2992
 
2992
 
2993
            if (!tableCmd.getFieldsName().contains("EN_COURS")) {
2993
            if (!tableCmd.getFieldsName().contains("EN_COURS")) {
2994
                tCmd.addColumn("EN_COURS", "boolean default true");
2994
                tCmd.addColumn("EN_COURS", "boolean default true");
2995
                alterCmd = true;
2995
                alterCmd = true;
2996
            }
2996
            }
2997
            if (alterCmd) {
2997
            if (alterCmd) {
2998
                try {
2998
                try {
2999
                    ds.execute(tCmd.asString());
2999
                    ds.execute(tCmd.asString());
3000
                    tableCmd.getSchema().updateVersion();
3000
                    tableCmd.getSchema().updateVersion();
3001
                } catch (SQLException ex) {
3001
                } catch (SQLException ex) {
3002
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table COMMANDE", ex);
3002
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table COMMANDE", ex);
3003
                }
3003
                }
3004
            }
3004
            }
3005
        }
3005
        }
3006
 
3006
 
3007
        // Change VF
3007
        // Change VF
3008
        {
3008
        {
3009
            SQLTable tableVenteFacture = root.getTable("SAISIE_VENTE_FACTURE");
3009
            SQLTable tableVenteFacture = root.getTable("SAISIE_VENTE_FACTURE");
3010
 
3010
 
3011
            AlterTable tVF = new AlterTable(tableVenteFacture);
3011
            AlterTable tVF = new AlterTable(tableVenteFacture);
3012
            boolean alterVF = false;
3012
            boolean alterVF = false;
3013
 
3013
 
3014
            if (!tableVenteFacture.getFieldsName().contains("ID_TAXE_PORT")) {
3014
            if (!tableVenteFacture.getFieldsName().contains("ID_TAXE_PORT")) {
3015
                tVF.addForeignColumn("ID_TAXE_PORT", root.findTable("TAXE"));
3015
                tVF.addForeignColumn("ID_TAXE_PORT", root.findTable("TAXE"));
3016
                alterVF = true;
3016
                alterVF = true;
3017
            }
3017
            }
3018
            if (alterVF) {
3018
            if (alterVF) {
3019
                try {
3019
                try {
3020
                    ds.execute(tVF.asString());
3020
                    ds.execute(tVF.asString());
3021
                    tableVenteFacture.getSchema().updateVersion();
3021
                    tableVenteFacture.getSchema().updateVersion();
3022
                } catch (SQLException ex) {
3022
                } catch (SQLException ex) {
3023
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table SAISIE_VENTE_FACTURE", ex);
3023
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table SAISIE_VENTE_FACTURE", ex);
3024
                }
3024
                }
3025
            }
3025
            }
3026
        }
3026
        }
3027
 
3027
 
3028
        // Change Fournisseur
3028
        // Change Fournisseur
3029
        {
3029
        {
3030
            SQLTable tableFournisseur = root.getTable("FOURNISSEUR");
3030
            SQLTable tableFournisseur = root.getTable("FOURNISSEUR");
3031
 
3031
 
3032
            AlterTable tFourn = new AlterTable(tableFournisseur);
3032
            AlterTable tFourn = new AlterTable(tableFournisseur);
3033
            boolean alterFourn = false;
3033
            boolean alterFourn = false;
3034
 
3034
 
3035
            if (!tableFournisseur.getFieldsName().contains("ID_LANGUE")) {
3035
            if (!tableFournisseur.getFieldsName().contains("ID_LANGUE")) {
3036
                tFourn.addForeignColumn("ID_LANGUE", root.findTable("LANGUE", true));
3036
                tFourn.addForeignColumn("ID_LANGUE", root.findTable("LANGUE", true));
3037
                alterFourn = true;
3037
                alterFourn = true;
3038
            }
3038
            }
3039
            if (!tableFournisseur.getFieldsName().contains("ID_DEVISE")) {
3039
            if (!tableFournisseur.getFieldsName().contains("ID_DEVISE")) {
3040
                tFourn.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
3040
                tFourn.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
3041
                alterFourn = true;
3041
                alterFourn = true;
3042
            }
3042
            }
3043
            if (!tableFournisseur.getFieldsName().contains("RESPONSABLE")) {
3043
            if (!tableFournisseur.getFieldsName().contains("RESPONSABLE")) {
3044
                tFourn.addVarCharColumn("RESPONSABLE", 256);
3044
                tFourn.addVarCharColumn("RESPONSABLE", 256);
3045
                alterFourn = true;
3045
                alterFourn = true;
3046
            }
3046
            }
3047
            if (!tableFournisseur.getFieldsName().contains("TEL_P")) {
3047
            if (!tableFournisseur.getFieldsName().contains("TEL_P")) {
3048
                tFourn.addVarCharColumn("TEL_P", 256);
3048
                tFourn.addVarCharColumn("TEL_P", 256);
3049
                alterFourn = true;
3049
                alterFourn = true;
3050
            }
3050
            }
3051
            if (!tableFournisseur.getFieldsName().contains("MAIL")) {
3051
            if (!tableFournisseur.getFieldsName().contains("MAIL")) {
3052
                tFourn.addVarCharColumn("MAIL", 256);
3052
                tFourn.addVarCharColumn("MAIL", 256);
3053
                alterFourn = true;
3053
                alterFourn = true;
3054
            }
3054
            }
3055
            if (!tableFournisseur.getFieldsName().contains("INFOS")) {
3055
            if (!tableFournisseur.getFieldsName().contains("INFOS")) {
3056
                tFourn.addVarCharColumn("INFOS", 2048);
3056
                tFourn.addVarCharColumn("INFOS", 2048);
3057
                alterFourn = true;
3057
                alterFourn = true;
3058
            }
3058
            }
3059
 
3059
 
3060
            if (alterFourn) {
3060
            if (alterFourn) {
3061
                try {
3061
                try {
3062
                    ds.execute(tFourn.asString());
3062
                    ds.execute(tFourn.asString());
3063
                    tableFournisseur.getSchema().updateVersion();
3063
                    tableFournisseur.getSchema().updateVersion();
3064
                } catch (SQLException ex) {
3064
                } catch (SQLException ex) {
3065
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table FOURNISSEUR", ex);
3065
                    throw new IllegalStateException("Erreur lors de l'ajout des champs sur la table FOURNISSEUR", ex);
3066
                }
3066
                }
3067
            }
3067
            }
3068
        }
3068
        }
3069
 
3069
 
3070
        updateN4DS(root);
3070
        updateN4DS(root);
3071
 
3071
 
3072
        root.refetch();
3072
        root.refetch();
3073
    }
3073
    }
3074
 
3074
 
3075
    /**
3075
    /**
3076
     * Mise à jour du schéma pour N4DS
3076
     * Mise à jour du schéma pour N4DS
3077
     * 
3077
     * 
3078
     * @param root
3078
     * @param root
3079
     * @throws SQLException
3079
     * @throws SQLException
3080
     */
3080
     */
3081
    private void updateN4DS(DBRoot root) throws SQLException {
3081
    private void updateN4DS(DBRoot root) throws SQLException {
3082
 
3082
 
3083
        {
3083
        {
3084
            SQLTable table = root.findTable("INFOS_SALARIE_PAYE");
3084
            SQLTable table = root.findTable("INFOS_SALARIE_PAYE");
3085
            boolean alter = false;
3085
            boolean alter = false;
3086
            AlterTable t = new AlterTable(table);
3086
            AlterTable t = new AlterTable(table);
3087
            if (!table.getFieldsName().contains("CODE_AT")) {
3087
            if (!table.getFieldsName().contains("CODE_AT")) {
3088
                t.addVarCharColumn("CODE_AT", 18);
3088
                t.addVarCharColumn("CODE_AT", 18);
3089
                alter = true;
3089
                alter = true;
3090
            }
3090
            }
3091
            if (!table.getFieldsName().contains("CODE_SECTION_AT")) {
3091
            if (!table.getFieldsName().contains("CODE_SECTION_AT")) {
3092
                t.addVarCharColumn("CODE_SECTION_AT", 18);
3092
                t.addVarCharColumn("CODE_SECTION_AT", 18);
3093
                alter = true;
3093
                alter = true;
3094
            }
3094
            }
3095
 
3095
 
3096
            if (alter) {
3096
            if (alter) {
3097
                try {
3097
                try {
3098
                    table.getBase().getDataSource().execute(t.asString());
3098
                    table.getBase().getDataSource().execute(t.asString());
3099
                    table.getSchema().updateVersion();
3099
                    table.getSchema().updateVersion();
3100
                    table.fetchFields();
3100
                    table.fetchFields();
3101
                } catch (SQLException ex) {
3101
                } catch (SQLException ex) {
3102
                    throw new IllegalStateException("Erreur lors de l'ajout des champs à la table " + table.getName(), ex);
3102
                    throw new IllegalStateException("Erreur lors de l'ajout des champs à la table " + table.getName(), ex);
3103
                }
3103
                }
3104
            }
3104
            }
3105
 
3105
 
3106
        }
3106
        }
3107
 
3107
 
3108
        if (!root.contains("CODE_STATUT_CAT_CONV")) {
3108
        if (!root.contains("CODE_STATUT_CAT_CONV")) {
3109
 
3109
 
3110
            SQLCreateTable createTarif = new SQLCreateTable(root, "CODE_STATUT_CAT_CONV");
3110
            SQLCreateTable createTarif = new SQLCreateTable(root, "CODE_STATUT_CAT_CONV");
3111
 
3111
 
3112
            createTarif.addVarCharColumn("CODE", 6);
3112
            createTarif.addVarCharColumn("CODE", 6);
3113
            createTarif.addVarCharColumn("NOM", 256);
3113
            createTarif.addVarCharColumn("NOM", 256);
3114
            createTarif.asString();
3114
            createTarif.asString();
3115
            try {
3115
            try {
3116
                root.getBase().getDataSource().execute(createTarif.asString());
3116
                root.getBase().getDataSource().execute(createTarif.asString());
3117
                insertUndef(createTarif);
3117
                insertUndef(createTarif);
3118
 
3118
 
3119
                String insert = "INSERT into " + getTableName(createTarif).quote() + "(\"CODE\",\"NOM\") VALUES ";
3119
                String insert = "INSERT into " + getTableName(createTarif).quote() + "(\"CODE\",\"NOM\") VALUES ";
3120
                insert += " ('01','agriculteur salarié de son exploitation')";
3120
                insert += " ('01','agriculteur salarié de son exploitation')";
3121
                insert += ", ('02','artisan ou commerçant salarié de son entreprise')";
3121
                insert += ", ('02','artisan ou commerçant salarié de son entreprise')";
3122
                insert += ", ('03','cadre dirigeant (votant au collège employeur des élections prud''''hommales)')";
3122
                insert += ", ('03','cadre dirigeant (votant au collège employeur des élections prud''''hommales)')";
3123
                insert += ", ('04','autres cadres au sens de la convention collective (ou du statut pour les régimes spéciaux)')";
3123
                insert += ", ('04','autres cadres au sens de la convention collective (ou du statut pour les régimes spéciaux)')";
3124
                insert += ", ('05','profession intermédiaire (technicien, contremaître, agent de maîtrise, clergé)')";
3124
                insert += ", ('05','profession intermédiaire (technicien, contremaître, agent de maîtrise, clergé)')";
3125
                insert += ", ('06','employé administratif d''''entreprise, de commerce, agent de service')";
3125
                insert += ", ('06','employé administratif d''''entreprise, de commerce, agent de service')";
3126
                insert += ", ('07','ouvriers qualifiés et non qualifiés y compris ouvriers agricoles');";
3126
                insert += ", ('07','ouvriers qualifiés et non qualifiés y compris ouvriers agricoles');";
3127
                createTarif.getRoot().getDBSystemRoot().getDataSource().execute(insert);
3127
                createTarif.getRoot().getDBSystemRoot().getDataSource().execute(insert);
3128
 
3128
 
3129
                root.getSchema().updateVersion();
3129
                root.getSchema().updateVersion();
3130
                root.refetch();
3130
                root.refetch();
3131
            } catch (SQLException ex) {
3131
            } catch (SQLException ex) {
3132
                throw new IllegalStateException("Erreur lors de la création de la table CODE_STATUT_CAT_CONV", ex);
3132
                throw new IllegalStateException("Erreur lors de la création de la table CODE_STATUT_CAT_CONV", ex);
3133
            }
3133
            }
3134
        }
3134
        }
3135
 
3135
 
3136
        // Création de la table Modéle
3136
        // Création de la table Modéle
3137
        if (!root.contains("CONTACT_ADMINISTRATIF")) {
3137
        if (!root.contains("CONTACT_ADMINISTRATIF")) {
3138
 
3138
 
3139
            SQLCreateTable createModele = new SQLCreateTable(root, "CONTACT_ADMINISTRATIF");
3139
            SQLCreateTable createModele = new SQLCreateTable(root, "CONTACT_ADMINISTRATIF");
3140
            createModele.addVarCharColumn("NOM", 256);
3140
            createModele.addVarCharColumn("NOM", 256);
3141
            createModele.addVarCharColumn("PRENOM", 256);
3141
            createModele.addVarCharColumn("PRENOM", 256);