OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Rev 90 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 73 Rev 83
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.core.sales.order.component;
14
 package org.openconcerto.erp.core.sales.order.component;
15
 
15
 
16
import static org.openconcerto.utils.CollectionUtils.createSet;
16
import static org.openconcerto.utils.CollectionUtils.createSet;
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
18
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
18
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
19
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
19
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
20
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
20
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
21
import org.openconcerto.erp.core.common.ui.DeviseField;
21
import org.openconcerto.erp.core.common.ui.DeviseField;
22
import org.openconcerto.erp.core.common.ui.TotalPanel;
22
import org.openconcerto.erp.core.common.ui.TotalPanel;
23
import org.openconcerto.erp.core.sales.order.element.CommandeClientSQLElement;
23
import org.openconcerto.erp.core.sales.order.element.CommandeClientSQLElement;
24
import org.openconcerto.erp.core.sales.order.report.CommandeClientXmlSheet;
24
import org.openconcerto.erp.core.sales.order.report.CommandeClientXmlSheet;
25
import org.openconcerto.erp.core.sales.order.ui.CommandeClientItemTable;
25
import org.openconcerto.erp.core.sales.order.ui.CommandeClientItemTable;
-
 
26
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
-
 
27
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater;
-
 
28
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater.Type;
-
 
29
import org.openconcerto.erp.core.supplychain.stock.element.StockLabel;
26
import org.openconcerto.erp.panel.PanelOOSQLComponent;
30
import org.openconcerto.erp.panel.PanelOOSQLComponent;
27
import org.openconcerto.erp.preferences.DefaultNXProps;
31
import org.openconcerto.erp.preferences.DefaultNXProps;
28
import org.openconcerto.sql.Configuration;
32
import org.openconcerto.sql.Configuration;
29
import org.openconcerto.sql.element.SQLElement;
33
import org.openconcerto.sql.element.SQLElement;
30
import org.openconcerto.sql.model.SQLBackgroundTableCache;
34
import org.openconcerto.sql.model.SQLBackgroundTableCache;
31
import org.openconcerto.sql.model.SQLInjector;
35
import org.openconcerto.sql.model.SQLInjector;
32
import org.openconcerto.sql.model.SQLRow;
36
import org.openconcerto.sql.model.SQLRow;
33
import org.openconcerto.sql.model.SQLRowAccessor;
37
import org.openconcerto.sql.model.SQLRowAccessor;
34
import org.openconcerto.sql.model.SQLRowValues;
38
import org.openconcerto.sql.model.SQLRowValues;
-
 
39
import org.openconcerto.sql.model.SQLSelect;
35
import org.openconcerto.sql.model.SQLTable;
40
import org.openconcerto.sql.model.SQLTable;
-
 
41
import org.openconcerto.sql.model.Where;
36
import org.openconcerto.sql.sqlobject.ElementComboBox;
42
import org.openconcerto.sql.sqlobject.ElementComboBox;
37
import org.openconcerto.sql.sqlobject.JUniqueTextField;
43
import org.openconcerto.sql.sqlobject.JUniqueTextField;
38
import org.openconcerto.sql.sqlobject.SQLTextCombo;
44
import org.openconcerto.sql.sqlobject.SQLTextCombo;
39
import org.openconcerto.sql.users.UserManager;
45
import org.openconcerto.sql.users.UserManager;
40
import org.openconcerto.sql.view.EditFrame;
46
import org.openconcerto.sql.view.EditFrame;
41
import org.openconcerto.sql.view.list.RowValuesTable;
47
import org.openconcerto.sql.view.list.RowValuesTable;
42
import org.openconcerto.ui.DefaultGridBagConstraints;
48
import org.openconcerto.ui.DefaultGridBagConstraints;
43
import org.openconcerto.ui.FormLayouter;
49
import org.openconcerto.ui.FormLayouter;
44
import org.openconcerto.ui.JDate;
50
import org.openconcerto.ui.JDate;
45
import org.openconcerto.ui.TitledSeparator;
51
import org.openconcerto.ui.TitledSeparator;
46
import org.openconcerto.ui.component.ITextArea;
52
import org.openconcerto.ui.component.ITextArea;
47
import org.openconcerto.ui.preferences.DefaultProps;
53
import org.openconcerto.ui.preferences.DefaultProps;
48
import org.openconcerto.utils.ExceptionHandler;
54
import org.openconcerto.utils.ExceptionHandler;
49
 
55
 
50
import java.awt.Color;
56
import java.awt.Color;
51
import java.awt.GridBagConstraints;
57
import java.awt.GridBagConstraints;
52
import java.awt.GridBagLayout;
58
import java.awt.GridBagLayout;
53
import java.beans.PropertyChangeEvent;
59
import java.beans.PropertyChangeEvent;
54
import java.beans.PropertyChangeListener;
60
import java.beans.PropertyChangeListener;
55
import java.sql.SQLException;
61
import java.sql.SQLException;
56
import java.util.Date;
62
import java.util.Date;
-
 
63
import java.util.List;
57
 
64
 
58
import javax.swing.JLabel;
65
import javax.swing.JLabel;
59
import javax.swing.JOptionPane;
66
import javax.swing.JOptionPane;
60
import javax.swing.JPanel;
67
import javax.swing.JPanel;
61
import javax.swing.JScrollPane;
68
import javax.swing.JScrollPane;
62
import javax.swing.JTextField;
69
import javax.swing.JTextField;
63
import javax.swing.SwingConstants;
70
import javax.swing.SwingConstants;
64
import javax.swing.SwingUtilities;
71
import javax.swing.SwingUtilities;
65
import javax.swing.event.DocumentEvent;
72
import javax.swing.event.DocumentEvent;
66
import javax.swing.event.DocumentListener;
73
import javax.swing.event.DocumentListener;
67
import javax.swing.event.TableModelEvent;
74
import javax.swing.event.TableModelEvent;
68
import javax.swing.event.TableModelListener;
75
import javax.swing.event.TableModelListener;
69
 
76
 
-
 
77
import org.apache.commons.dbutils.handlers.ArrayListHandler;
-
 
78
 
70
public class CommandeClientSQLComponent extends TransfertBaseSQLComponent {
79
public class CommandeClientSQLComponent extends TransfertBaseSQLComponent {
71
 
80
 
72
    private CommandeClientItemTable table;
81
    private CommandeClientItemTable table;
73
    private JUniqueTextField numeroUniqueCommande;
82
    private JUniqueTextField numeroUniqueCommande;
74
    private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
83
    private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
75
    private final ITextArea infos = new ITextArea(3, 3);
84
    private final ITextArea infos = new ITextArea(3, 3);
76
    private ElementComboBox comboCommercial, comboDevis, comboClient;
85
    private ElementComboBox comboCommercial, comboDevis, comboClient;
77
    private PanelOOSQLComponent panelOO;
86
    private PanelOOSQLComponent panelOO;
78
 
87
 
79
    private final SQLTextCombo textObjet = new SQLTextCombo();
88
    private final SQLTextCombo textObjet = new SQLTextCombo();
80
 
89
 
81
    public CommandeClientSQLComponent() {
90
    public CommandeClientSQLComponent() {
82
        super(Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT"));
91
        super(Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT"));
83
    }
92
    }
84
 
93
 
85
    public RowValuesTable getRowValuesTable() {
94
    public RowValuesTable getRowValuesTable() {
86
        return this.table.getRowValuesTable();
95
        return this.table.getRowValuesTable();
87
    }
96
    }
88
 
97
 
89
    public void addViews() {
98
    public void addViews() {
90
        this.setLayout(new GridBagLayout());
99
        this.setLayout(new GridBagLayout());
91
        final GridBagConstraints c = new DefaultGridBagConstraints();
100
        final GridBagConstraints c = new DefaultGridBagConstraints();
92
 
101
 
93
        // Numero du commande
102
        // Numero du commande
94
        c.gridx = 0;
103
        c.gridx = 0;
95
        this.add(new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT), c);
104
        this.add(new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT), c);
96
 
105
 
97
        this.numeroUniqueCommande = new JUniqueTextField(16);
106
        this.numeroUniqueCommande = new JUniqueTextField(16);
98
        c.fill = GridBagConstraints.NONE;
107
        c.fill = GridBagConstraints.NONE;
99
        c.gridx++;
108
        c.gridx++;
100
        c.weightx = 1;
109
        c.weightx = 1;
101
        this.add(this.numeroUniqueCommande, c);
110
        this.add(this.numeroUniqueCommande, c);
102
 
111
 
103
        // Date
112
        // Date
104
        JLabel labelDate = new JLabel(getLabelFor("DATE"));
113
        JLabel labelDate = new JLabel(getLabelFor("DATE"));
105
        labelDate.setHorizontalAlignment(SwingConstants.RIGHT);
114
        labelDate.setHorizontalAlignment(SwingConstants.RIGHT);
106
        c.gridx = 2;
115
        c.gridx = 2;
107
        c.fill = GridBagConstraints.HORIZONTAL;
116
        c.fill = GridBagConstraints.HORIZONTAL;
108
        c.weightx = 0;
117
        c.weightx = 0;
109
        this.add(labelDate, c);
118
        this.add(labelDate, c);
110
 
119
 
111
        JDate dateCommande = new JDate(true);
120
        JDate dateCommande = new JDate(true);
112
        c.gridx++;
121
        c.gridx++;
113
        c.fill = GridBagConstraints.NONE;
122
        c.fill = GridBagConstraints.NONE;
114
        this.add(dateCommande, c);
123
        this.add(dateCommande, c);
115
 
124
 
116
        // Champ Module
125
        // Champ Module
117
        c.gridx = 0;
126
        c.gridx = 0;
118
        c.gridy++;
127
        c.gridy++;
119
        c.gridwidth = GridBagConstraints.REMAINDER;
128
        c.gridwidth = GridBagConstraints.REMAINDER;
120
        final JPanel addP = ComptaSQLConfElement.createAdditionalPanel();
129
        final JPanel addP = ComptaSQLConfElement.createAdditionalPanel();
121
 
130
 
122
        this.setAdditionalFieldsPanel(new FormLayouter(addP, 2));
131
        this.setAdditionalFieldsPanel(new FormLayouter(addP, 2));
123
        c.fill = GridBagConstraints.HORIZONTAL;
132
        c.fill = GridBagConstraints.HORIZONTAL;
124
        c.weightx = 1;
133
        c.weightx = 1;
125
        this.add(addP, c);
134
        this.add(addP, c);
126
 
135
 
127
        c.gridy++;
136
        c.gridy++;
128
        c.gridwidth = 1;
137
        c.gridwidth = 1;
129
 
138
 
130
        this.comboDevis = new ElementComboBox();
139
        this.comboDevis = new ElementComboBox();
131
 
140
 
132
        // Reference
141
        // Reference
133
        c.gridx = 0;
142
        c.gridx = 0;
134
        c.gridy++;
143
        c.gridy++;
135
        c.gridwidth = 1;
144
        c.gridwidth = 1;
136
        c.gridwidth = 1;
145
        c.gridwidth = 1;
137
        c.gridheight = 1;
146
        c.gridheight = 1;
138
        c.fill = GridBagConstraints.HORIZONTAL;
147
        c.fill = GridBagConstraints.HORIZONTAL;
139
 
148
 
140
        JLabel labelObjet = new JLabel(getLabelFor("NOM"));
149
        JLabel labelObjet = new JLabel(getLabelFor("NOM"));
141
        labelObjet.setHorizontalAlignment(SwingConstants.RIGHT);
150
        labelObjet.setHorizontalAlignment(SwingConstants.RIGHT);
142
        c.weightx = 0;
151
        c.weightx = 0;
143
        this.add(labelObjet, c);
152
        this.add(labelObjet, c);
144
 
153
 
145
        c.gridx++;
154
        c.gridx++;
146
        c.weightx = 1;
155
        c.weightx = 1;
147
        c.fill = GridBagConstraints.BOTH;
156
        c.fill = GridBagConstraints.BOTH;
148
        this.add(this.textObjet, c);
157
        this.add(this.textObjet, c);
149
 
158
 
150
        String field;
159
        String field;
151
            field = "ID_COMMERCIAL";
160
            field = "ID_COMMERCIAL";
152
        c.fill = GridBagConstraints.HORIZONTAL;
161
        c.fill = GridBagConstraints.HORIZONTAL;
153
        // Commercial
162
        // Commercial
154
        JLabel labelCommercial = new JLabel(getLabelFor(field));
163
        JLabel labelCommercial = new JLabel(getLabelFor(field));
155
        labelCommercial.setHorizontalAlignment(SwingConstants.RIGHT);
164
        labelCommercial.setHorizontalAlignment(SwingConstants.RIGHT);
156
 
165
 
157
        c.gridx++;
166
        c.gridx++;
158
        c.weightx = 0;
167
        c.weightx = 0;
159
        this.add(labelCommercial, c);
168
        this.add(labelCommercial, c);
160
 
169
 
161
        this.comboCommercial = new ElementComboBox(false, 25);
170
        this.comboCommercial = new ElementComboBox(false, 25);
162
        this.comboCommercial.setListIconVisible(false);
171
        this.comboCommercial.setListIconVisible(false);
163
        c.gridx++;
172
        c.gridx++;
164
        c.fill = GridBagConstraints.NONE;
173
        c.fill = GridBagConstraints.NONE;
165
        c.weightx = 1;
174
        c.weightx = 1;
166
        this.add(this.comboCommercial, c);
175
        this.add(this.comboCommercial, c);
167
        addRequiredSQLObject(this.comboCommercial, field);
176
        addRequiredSQLObject(this.comboCommercial, field);
168
 
177
 
169
        // Ligne 3: Client
178
        // Ligne 3: Client
170
        c.gridx = 0;
179
        c.gridx = 0;
171
        c.gridy++;
180
        c.gridy++;
172
        c.weightx = 0;
181
        c.weightx = 0;
173
        c.fill = GridBagConstraints.HORIZONTAL;
182
        c.fill = GridBagConstraints.HORIZONTAL;
174
        this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c);
183
        this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c);
175
 
184
 
176
        this.comboClient = new ElementComboBox();
185
        this.comboClient = new ElementComboBox();
177
        c.gridx = GridBagConstraints.RELATIVE;
186
        c.gridx = GridBagConstraints.RELATIVE;
178
        c.gridwidth = 3;
187
        c.gridwidth = 3;
179
        c.weightx = 1;
188
        c.weightx = 1;
180
        c.weighty = 0;
189
        c.weighty = 0;
181
        c.fill = GridBagConstraints.NONE;
190
        c.fill = GridBagConstraints.NONE;
182
        this.add(this.comboClient, c);
191
        this.add(this.comboClient, c);
183
        final ElementComboBox boxTarif = new ElementComboBox();
192
        final ElementComboBox boxTarif = new ElementComboBox();
184
        this.comboClient.addValueListener(new PropertyChangeListener() {
193
        this.comboClient.addValueListener(new PropertyChangeListener() {
185
 
194
 
186
            @Override
195
            @Override
187
            public void propertyChange(PropertyChangeEvent evt) {
196
            public void propertyChange(PropertyChangeEvent evt) {
188
                if (!isFilling() && comboClient.getValue() != null) {
197
                if (!isFilling() && comboClient.getValue() != null) {
189
                    Integer id = comboClient.getValue();
198
                    Integer id = comboClient.getValue();
190
 
199
 
191
                    if (id > 1) {
200
                    if (id > 1) {
192
 
201
 
193
                        SQLRow row = comboClient.getElement().getTable().getRow(id);
202
                        SQLRow row = comboClient.getElement().getTable().getRow(id);
194
                        if (comboClient.getElement().getTable().getFieldsName().contains("ID_TARIF")) {
203
                        if (comboClient.getElement().getTable().getFieldsName().contains("ID_TARIF")) {
195
 
204
 
196
                            SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
205
                            SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
197
                            if (!foreignRow.isUndefined() && (boxTarif.getSelectedRow() == null || boxTarif.getSelectedId() != foreignRow.getID())
206
                            if (!foreignRow.isUndefined() && (boxTarif.getSelectedRow() == null || boxTarif.getSelectedId() != foreignRow.getID())
198
                                    && JOptionPane.showConfirmDialog(null, "Appliquer les tarifs associés au client?") == JOptionPane.YES_OPTION) {
207
                                    && JOptionPane.showConfirmDialog(null, "Appliquer les tarifs associés au client?") == JOptionPane.YES_OPTION) {
199
                                boxTarif.setValue(foreignRow.getID());
208
                                boxTarif.setValue(foreignRow.getID());
200
                                // SaisieVenteFactureSQLComponent.this.tableFacture.setTarif(foreignRow,
209
                                // SaisieVenteFactureSQLComponent.this.tableFacture.setTarif(foreignRow,
201
                                // true);
210
                                // true);
202
                            } else {
211
                            } else {
203
                                boxTarif.setValue(foreignRow.getID());
212
                                boxTarif.setValue(foreignRow.getID());
204
                            }
213
                            }
205
                            // SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
214
                            // SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
206
                            // if (foreignRow.isUndefined() &&
215
                            // if (foreignRow.isUndefined() &&
207
                            // !row.getForeignRow("ID_DEVISE").isUndefined()) {
216
                            // !row.getForeignRow("ID_DEVISE").isUndefined()) {
208
                            // SQLRowValues rowValsD = new SQLRowValues(foreignRow.getTable());
217
                            // SQLRowValues rowValsD = new SQLRowValues(foreignRow.getTable());
209
                            // rowValsD.put("ID_DEVISE", row.getObject("ID_DEVISE"));
218
                            // rowValsD.put("ID_DEVISE", row.getObject("ID_DEVISE"));
210
                            // foreignRow = rowValsD;
219
                            // foreignRow = rowValsD;
211
                            //
220
                            //
212
                            // }
221
                            // }
213
                            // table.setTarif(foreignRow, true);
222
                            // table.setTarif(foreignRow, true);
214
                        }
223
                        }
215
                    }
224
                    }
216
                }
225
                }
217
 
226
 
218
            }
227
            }
219
        });
228
        });
220
        // tarif
229
        // tarif
221
        if (this.getTable().getFieldsName().contains("ID_TARIF")) {
230
        if (this.getTable().getFieldsName().contains("ID_TARIF")) {
222
            // TARIF
231
            // TARIF
223
            c.gridy++;
232
            c.gridy++;
224
            c.gridx = 0;
233
            c.gridx = 0;
225
            c.weightx = 0;
234
            c.weightx = 0;
226
            c.weighty = 0;
235
            c.weighty = 0;
227
            c.gridwidth = 1;
236
            c.gridwidth = 1;
228
            this.add(new JLabel("Tarif à appliquer"), c);
237
            this.add(new JLabel("Tarif à appliquer"), c);
229
            c.gridx++;
238
            c.gridx++;
230
            c.gridwidth = GridBagConstraints.REMAINDER;
239
            c.gridwidth = GridBagConstraints.REMAINDER;
231
 
240
 
232
            c.weightx = 1;
241
            c.weightx = 1;
233
            this.add(boxTarif, c);
242
            this.add(boxTarif, c);
234
            this.addView(boxTarif, "ID_TARIF");
243
            this.addView(boxTarif, "ID_TARIF");
235
            boxTarif.addModelListener("wantedID", new PropertyChangeListener() {
244
            boxTarif.addModelListener("wantedID", new PropertyChangeListener() {
236
 
245
 
237
                @Override
246
                @Override
238
                public void propertyChange(PropertyChangeEvent evt) {
247
                public void propertyChange(PropertyChangeEvent evt) {
239
                    SQLRow selectedRow = boxTarif.getRequest().getPrimaryTable().getRow(boxTarif.getWantedID());
248
                    SQLRow selectedRow = boxTarif.getRequest().getPrimaryTable().getRow(boxTarif.getWantedID());
240
                    table.setTarif(selectedRow, false);
249
                    table.setTarif(selectedRow, false);
241
                }
250
                }
242
            });
251
            });
243
        }
252
        }
244
 
253
 
245
        // Table d'élément
254
        // Table d'élément
246
        this.table = new CommandeClientItemTable();
255
        this.table = new CommandeClientItemTable();
247
        c.fill = GridBagConstraints.BOTH;
256
        c.fill = GridBagConstraints.BOTH;
248
        c.gridy++;
257
        c.gridy++;
249
        c.gridx = 0;
258
        c.gridx = 0;
250
        c.weightx = 1;
259
        c.weightx = 1;
251
        c.weighty = 1;
260
        c.weighty = 1;
252
        c.gridwidth = GridBagConstraints.REMAINDER;
261
        c.gridwidth = GridBagConstraints.REMAINDER;
253
        this.add(this.table, c);
262
        this.add(this.table, c);
254
 
263
 
255
        DeviseField textPortHT = new DeviseField();
264
        DeviseField textPortHT = new DeviseField();
256
        DeviseField textRemiseHT = new DeviseField();
265
        DeviseField textRemiseHT = new DeviseField();
257
 
266
 
258
        // INfos
267
        // INfos
259
        c.gridx = 0;
268
        c.gridx = 0;
260
        c.gridy++;
269
        c.gridy++;
261
        c.gridheight = 1;
270
        c.gridheight = 1;
262
        c.weighty = 0;
271
        c.weighty = 0;
263
        c.weightx = 1;
272
        c.weightx = 1;
264
        c.anchor = GridBagConstraints.WEST;
273
        c.anchor = GridBagConstraints.WEST;
265
        c.gridwidth = 2;
274
        c.gridwidth = 2;
266
        this.add(new TitledSeparator(getLabelFor("INFOS")), c);
275
        this.add(new TitledSeparator(getLabelFor("INFOS")), c);
267
 
276
 
268
        c.gridy++;
277
        c.gridy++;
269
        c.weightx = 1;
278
        c.weightx = 1;
270
        c.weighty = 0;
279
        c.weighty = 0;
271
        c.fill = GridBagConstraints.BOTH;
280
        c.fill = GridBagConstraints.BOTH;
272
        final JScrollPane scrollPane = new JScrollPane(this.infos);
281
        final JScrollPane scrollPane = new JScrollPane(this.infos);
273
        scrollPane.setBorder(null);
282
        scrollPane.setBorder(null);
274
        this.add(scrollPane, c);
283
        this.add(scrollPane, c);
275
 
284
 
276
        // Poids
285
        // Poids
277
        c.gridwidth = 1;
286
        c.gridwidth = 1;
278
 
287
 
279
        DefaultProps props = DefaultNXProps.getInstance();
288
        DefaultProps props = DefaultNXProps.getInstance();
280
        Boolean b = props.getBooleanValue("ArticleShowPoids");
289
        Boolean b = props.getBooleanValue("ArticleShowPoids");
281
        final JTextField textPoidsTotal = new JTextField(8);
290
        final JTextField textPoidsTotal = new JTextField(8);
282
        if (b) {
291
        if (b) {
283
            JPanel panel = new JPanel();
292
            JPanel panel = new JPanel();
284
 
293
 
285
            panel.add(new JLabel(getLabelFor("T_POIDS")), c);
294
            panel.add(new JLabel(getLabelFor("T_POIDS")), c);
286
 
295
 
287
            textPoidsTotal.setEnabled(false);
296
            textPoidsTotal.setEnabled(false);
288
            textPoidsTotal.setHorizontalAlignment(JTextField.RIGHT);
297
            textPoidsTotal.setHorizontalAlignment(JTextField.RIGHT);
289
            textPoidsTotal.setDisabledTextColor(Color.BLACK);
298
            textPoidsTotal.setDisabledTextColor(Color.BLACK);
290
            panel.add(textPoidsTotal, c);
299
            panel.add(textPoidsTotal, c);
291
 
300
 
292
            panel.setOpaque(false);
301
            panel.setOpaque(false);
293
            DefaultGridBagConstraints.lockMinimumSize(panel);
302
            DefaultGridBagConstraints.lockMinimumSize(panel);
294
 
303
 
295
            c.gridx = 2;
304
            c.gridx = 2;
296
            c.weightx = 0;
305
            c.weightx = 0;
297
            c.weighty = 0;
306
            c.weighty = 0;
298
            c.gridwidth = 1;
307
            c.gridwidth = 1;
299
            c.fill = GridBagConstraints.NONE;
308
            c.fill = GridBagConstraints.NONE;
300
            c.anchor = GridBagConstraints.NORTHEAST;
309
            c.anchor = GridBagConstraints.NORTHEAST;
301
            this.add(panel, c);
310
            this.add(panel, c);
302
        }
311
        }
303
 
312
 
304
        // Total
313
        // Total
305
        DeviseField fieldHT = new DeviseField();
314
        DeviseField fieldHT = new DeviseField();
306
        DeviseField fieldTVA = new DeviseField();
315
        DeviseField fieldTVA = new DeviseField();
307
        DeviseField fieldTTC = new DeviseField();
316
        DeviseField fieldTTC = new DeviseField();
308
        DeviseField fieldDevise = new DeviseField();
317
        DeviseField fieldDevise = new DeviseField();
309
        DeviseField fieldService = new DeviseField();
318
        DeviseField fieldService = new DeviseField();
310
        DeviseField fieldHA = new DeviseField();
319
        DeviseField fieldHA = new DeviseField();
311
        fieldHT.setOpaque(false);
320
        fieldHT.setOpaque(false);
312
        fieldHA.setOpaque(false);
321
        fieldHA.setOpaque(false);
313
        fieldTVA.setOpaque(false);
322
        fieldTVA.setOpaque(false);
314
        fieldTTC.setOpaque(false);
323
        fieldTTC.setOpaque(false);
315
        fieldService.setOpaque(false);
324
        fieldService.setOpaque(false);
316
        addSQLObject(fieldDevise, "T_DEVISE");
325
        addSQLObject(fieldDevise, "T_DEVISE");
317
        addRequiredSQLObject(fieldHT, "T_HT");
326
        addRequiredSQLObject(fieldHT, "T_HT");
318
        addRequiredSQLObject(fieldTVA, "T_TVA");
327
        addRequiredSQLObject(fieldTVA, "T_TVA");
319
        addRequiredSQLObject(fieldTTC, "T_TTC");
328
        addRequiredSQLObject(fieldTTC, "T_TTC");
320
        addRequiredSQLObject(fieldService, "T_SERVICE");
329
        addRequiredSQLObject(fieldService, "T_SERVICE");
321
        if (getTable().contains("PREBILAN")) {
330
        if (getTable().contains("PREBILAN")) {
322
            addSQLObject(fieldHA, "PREBILAN");
331
            addSQLObject(fieldHA, "PREBILAN");
323
        } else if (getTable().contains("T_HA")) {
332
        } else if (getTable().contains("T_HA")) {
324
            addSQLObject(fieldHA, "T_HA");
333
            addSQLObject(fieldHA, "T_HA");
325
        }
334
        }
326
 
335
 
327
        JTextField poids = new JTextField();
336
        JTextField poids = new JTextField();
328
        // addSQLObject(poids, "T_POIDS");
337
        // addSQLObject(poids, "T_POIDS");
329
        final TotalPanel totalTTC = new TotalPanel(this.table, fieldHT, fieldTVA, fieldTTC, textPortHT, textRemiseHT, fieldService, fieldHA, fieldDevise, poids, null);
338
        final TotalPanel totalTTC = new TotalPanel(this.table, fieldHT, fieldTVA, fieldTTC, textPortHT, textRemiseHT, fieldService, fieldHA, fieldDevise, poids, null);
330
 
339
 
331
        c.gridx = GridBagConstraints.RELATIVE;
340
        c.gridx = GridBagConstraints.RELATIVE;
332
        c.gridy--;
341
        c.gridy--;
333
        c.gridwidth = GridBagConstraints.REMAINDER;
342
        c.gridwidth = GridBagConstraints.REMAINDER;
334
        c.gridheight = 2;
343
        c.gridheight = 2;
335
        c.anchor = GridBagConstraints.NORTHEAST;
344
        c.anchor = GridBagConstraints.NORTHEAST;
336
        c.fill = GridBagConstraints.NONE;
345
        c.fill = GridBagConstraints.NONE;
337
        c.weighty = 0;
346
        c.weighty = 0;
338
 
347
 
339
        this.add(totalTTC, c);
348
        this.add(totalTTC, c);
340
 
349
 
341
        this.panelOO = new PanelOOSQLComponent(this);
350
        this.panelOO = new PanelOOSQLComponent(this);
342
        c.gridwidth = 1;
351
        c.gridwidth = 1;
343
        c.fill = GridBagConstraints.NONE;
352
        c.fill = GridBagConstraints.NONE;
344
        c.anchor = GridBagConstraints.EAST;
353
        c.anchor = GridBagConstraints.EAST;
345
        c.gridx = 0;
354
        c.gridx = 0;
346
        c.gridy += 3;
355
        c.gridy += 3;
347
        c.weightx = 0;
356
        c.weightx = 0;
348
        c.gridwidth = GridBagConstraints.REMAINDER;
357
        c.gridwidth = GridBagConstraints.REMAINDER;
349
        this.add(this.panelOO, c);
358
        this.add(this.panelOO, c);
350
 
359
 
351
        textPortHT.getDocument().addDocumentListener(new DocumentListener() {
360
        textPortHT.getDocument().addDocumentListener(new DocumentListener() {
352
            public void changedUpdate(DocumentEvent e) {
361
            public void changedUpdate(DocumentEvent e) {
353
                totalTTC.updateTotal();
362
                totalTTC.updateTotal();
354
            }
363
            }
355
 
364
 
356
            public void removeUpdate(DocumentEvent e) {
365
            public void removeUpdate(DocumentEvent e) {
357
                totalTTC.updateTotal();
366
                totalTTC.updateTotal();
358
            }
367
            }
359
 
368
 
360
            public void insertUpdate(DocumentEvent e) {
369
            public void insertUpdate(DocumentEvent e) {
361
                totalTTC.updateTotal();
370
                totalTTC.updateTotal();
362
            }
371
            }
363
        });
372
        });
364
 
373
 
365
        textRemiseHT.getDocument().addDocumentListener(new DocumentListener() {
374
        textRemiseHT.getDocument().addDocumentListener(new DocumentListener() {
366
            public void changedUpdate(DocumentEvent e) {
375
            public void changedUpdate(DocumentEvent e) {
367
                totalTTC.updateTotal();
376
                totalTTC.updateTotal();
368
            }
377
            }
369
 
378
 
370
            public void removeUpdate(DocumentEvent e) {
379
            public void removeUpdate(DocumentEvent e) {
371
                totalTTC.updateTotal();
380
                totalTTC.updateTotal();
372
            }
381
            }
373
 
382
 
374
            public void insertUpdate(DocumentEvent e) {
383
            public void insertUpdate(DocumentEvent e) {
375
                totalTTC.updateTotal();
384
                totalTTC.updateTotal();
376
            }
385
            }
377
        });
386
        });
378
 
387
 
379
        addRequiredSQLObject(this.comboClient, "ID_CLIENT");
388
        addRequiredSQLObject(this.comboClient, "ID_CLIENT");
380
        addSQLObject(this.textObjet, "NOM");
389
        addSQLObject(this.textObjet, "NOM");
381
        addSQLObject(textPoidsTotal, "T_POIDS");
390
        addSQLObject(textPoidsTotal, "T_POIDS");
382
        addRequiredSQLObject(dateCommande, "DATE");
391
        addRequiredSQLObject(dateCommande, "DATE");
383
        // addRequiredSQLObject(radioEtat, "ID_ETAT_DEVIS");
392
        // addRequiredSQLObject(radioEtat, "ID_ETAT_DEVIS");
384
        addRequiredSQLObject(this.numeroUniqueCommande, "NUMERO");
393
        addRequiredSQLObject(this.numeroUniqueCommande, "NUMERO");
385
        addSQLObject(this.infos, "INFOS");
394
        addSQLObject(this.infos, "INFOS");
386
        addSQLObject(this.comboDevis, "ID_DEVIS");
395
        addSQLObject(this.comboDevis, "ID_DEVIS");
387
 
396
 
388
        this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(CommandeClientSQLElement.class, new Date()));
397
        this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(CommandeClientSQLElement.class, new Date()));
389
 
398
 
390
        this.table.getModel().addTableModelListener(new TableModelListener() {
399
        this.table.getModel().addTableModelListener(new TableModelListener() {
391
 
400
 
392
            public void tableChanged(TableModelEvent e) {
401
            public void tableChanged(TableModelEvent e) {
393
                textPoidsTotal.setText(String.valueOf(CommandeClientSQLComponent.this.table.getPoidsTotal()));
402
                textPoidsTotal.setText(String.valueOf(CommandeClientSQLComponent.this.table.getPoidsTotal()));
394
            }
403
            }
395
        });
404
        });
396
        DefaultGridBagConstraints.lockMinimumSize(comboClient);
405
        DefaultGridBagConstraints.lockMinimumSize(comboClient);
397
        DefaultGridBagConstraints.lockMinimumSize(comboCommercial);
406
        DefaultGridBagConstraints.lockMinimumSize(comboCommercial);
398
        DefaultGridBagConstraints.lockMinimumSize(comboDevis);
407
        DefaultGridBagConstraints.lockMinimumSize(comboDevis);
399
        DefaultGridBagConstraints.lockMinimumSize(totalTTC);
408
        DefaultGridBagConstraints.lockMinimumSize(totalTTC);
400
        DefaultGridBagConstraints.lockMaximumSize(totalTTC);
409
        DefaultGridBagConstraints.lockMaximumSize(totalTTC);
401
        DefaultGridBagConstraints.lockMinimumSize(numeroUniqueCommande);
410
        DefaultGridBagConstraints.lockMinimumSize(numeroUniqueCommande);
402
 
411
 
403
    }
412
    }
404
 
413
 
405
    public int insert(SQLRow order) {
414
    public int insert(SQLRow order) {
406
        final int idCommande;
415
        final int idCommande;
407
        // on verifie qu'un devis du meme numero n'a pas été inséré entre temps
416
        // on verifie qu'un devis du meme numero n'a pas été inséré entre temps
408
        if (this.numeroUniqueCommande.checkValidation()) {
417
        if (this.numeroUniqueCommande.checkValidation()) {
409
 
418
 
410
            idCommande = super.insert(order);
419
            idCommande = super.insert(order);
411
            this.table.updateField("ID_COMMANDE_CLIENT", idCommande);
420
            this.table.updateField("ID_COMMANDE_CLIENT", idCommande);
-
 
421
            try {
-
 
422
                updateStock(idCommande);
-
 
423
            } catch (SQLException e1) {
-
 
424
                ExceptionHandler.handle("Erreur lors de la mise à du stock!", e1);
412
 
425
            }
413
            // Création des articles
426
            // Création des articles
414
            this.table.createArticle(idCommande, this.getElement());
427
            this.table.createArticle(idCommande, this.getElement());
415
            // generation du document
428
            // generation du document
416
 
429
 
417
            try {
430
            try {
418
                CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(getTable().getRow(idCommande));
431
                CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(getTable().getRow(idCommande));
419
                sheet.createDocumentAsynchronous();
432
                sheet.createDocumentAsynchronous();
420
                sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true);
433
                sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true);
421
            } catch (Exception e) {
434
            } catch (Exception e) {
422
                ExceptionHandler.handle("Impossible de créer la commande", e);
435
                ExceptionHandler.handle("Impossible de créer la commande", e);
423
            }
436
            }
424
 
437
 
425
            // incrémentation du numéro auto
438
            // incrémentation du numéro auto
426
            if (NumerotationAutoSQLElement.getNextNumero(CommandeClientSQLElement.class, new Date()).equalsIgnoreCase(this.numeroUniqueCommande.getText().trim())) {
439
            if (NumerotationAutoSQLElement.getNextNumero(CommandeClientSQLElement.class, new Date()).equalsIgnoreCase(this.numeroUniqueCommande.getText().trim())) {
427
                SQLRowValues rowVals = new SQLRowValues(this.tableNum);
440
                SQLRowValues rowVals = new SQLRowValues(this.tableNum);
428
                int val = this.tableNum.getRow(2).getInt("COMMANDE_CLIENT_START");
441
                int val = this.tableNum.getRow(2).getInt("COMMANDE_CLIENT_START");
429
                val++;
442
                val++;
430
                rowVals.put("COMMANDE_CLIENT_START", new Integer(val));
443
                rowVals.put("COMMANDE_CLIENT_START", new Integer(val));
431
 
444
 
432
                try {
445
                try {
433
                    rowVals.update(2);
446
                    rowVals.update(2);
434
                } catch (SQLException e) {
447
                } catch (SQLException e) {
435
                    e.printStackTrace();
448
                    e.printStackTrace();
436
                }
449
                }
437
            }
450
            }
438
        } else {
451
        } else {
439
            idCommande = getSelectedID();
452
            idCommande = getSelectedID();
440
            ExceptionHandler.handle("Impossible d'ajouter, numéro de commande client existant.");
453
            ExceptionHandler.handle("Impossible d'ajouter, numéro de commande client existant.");
441
            Object root = SwingUtilities.getRoot(this);
454
            Object root = SwingUtilities.getRoot(this);
442
            if (root instanceof EditFrame) {
455
            if (root instanceof EditFrame) {
443
                EditFrame frame = (EditFrame) root;
456
                EditFrame frame = (EditFrame) root;
444
                frame.getPanel().setAlwaysVisible(true);
457
                frame.getPanel().setAlwaysVisible(true);
445
            }
458
            }
446
        }
459
        }
447
 
460
 
448
        return idCommande;
461
        return idCommande;
449
    }
462
    }
450
 
463
 
451
    @Override
464
    @Override
452
    public void select(SQLRowAccessor r) {
465
    public void select(SQLRowAccessor r) {
453
 
466
 
454
        if (r != null) {
467
        if (r != null) {
455
            this.numeroUniqueCommande.setIdSelected(r.getID());
468
            this.numeroUniqueCommande.setIdSelected(r.getID());
456
        }
469
        }
457
        if (r == null || r.getIDNumber() == null)
470
        if (r == null || r.getIDNumber() == null)
458
            super.select(r);
471
            super.select(r);
459
        else {
472
        else {
460
            System.err.println(r);
473
            System.err.println(r);
461
            final SQLRowValues rVals = r.asRowValues();
474
            final SQLRowValues rVals = r.asRowValues();
462
            final SQLRowValues vals = new SQLRowValues(r.getTable());
475
            final SQLRowValues vals = new SQLRowValues(r.getTable());
463
            vals.load(rVals, createSet("ID_CLIENT"));
476
            vals.load(rVals, createSet("ID_CLIENT"));
464
            vals.setID(rVals.getID());
477
            vals.setID(rVals.getID());
465
            System.err.println("Select CLIENT");
478
            System.err.println("Select CLIENT");
466
            super.select(vals);
479
            super.select(vals);
467
            rVals.remove("ID_CLIENT");
480
            rVals.remove("ID_CLIENT");
468
            super.select(rVals);
481
            super.select(rVals);
469
        }
482
        }
470
        if (r != null) {
483
        if (r != null) {
471
            this.table.insertFrom("ID_COMMANDE_CLIENT", r.getID());
484
            this.table.insertFrom("ID_COMMANDE_CLIENT", r.getID());
472
        }
485
        }
473
        // this.radioEtat.setVisible(r.getID() > 1);
486
        // this.radioEtat.setVisible(r.getID() > 1);
474
    }
487
    }
475
 
488
 
476
    @Override
489
    @Override
477
    public void update() {
490
    public void update() {
478
 
491
 
479
        if (!this.numeroUniqueCommande.checkValidation()) {
492
        if (!this.numeroUniqueCommande.checkValidation()) {
480
            ExceptionHandler.handle("Impossible d'ajouter, numéro de commande client existant.");
493
            ExceptionHandler.handle("Impossible d'ajouter, numéro de commande client existant.");
481
            Object root = SwingUtilities.getRoot(this);
494
            Object root = SwingUtilities.getRoot(this);
482
            if (root instanceof EditFrame) {
495
            if (root instanceof EditFrame) {
483
                EditFrame frame = (EditFrame) root;
496
                EditFrame frame = (EditFrame) root;
484
                frame.getPanel().setAlwaysVisible(true);
497
                frame.getPanel().setAlwaysVisible(true);
485
            }
498
            }
486
            return;
499
            return;
487
        }
500
        }
488
        super.update();
501
        super.update();
-
 
502
        final int id = getSelectedID();
489
        this.table.updateField("ID_COMMANDE_CLIENT", getSelectedID());
503
        this.table.updateField("ID_COMMANDE_CLIENT", id);
490
        this.table.createArticle(getSelectedID(), this.getElement());
504
        this.table.createArticle(id, this.getElement());
491
 
505
 
-
 
506
        final SQLRow row = getTable().getRow(id);
-
 
507
        try {
492
        // generation du document
508
            updateStock(id);
-
 
509
        } catch (SQLException e1) {
-
 
510
            ExceptionHandler.handle("Erreur lors de la mise à du stock!", e1);
-
 
511
        }
493
 
512
 
-
 
513
        // generation du document
494
        try {
514
        try {
495
            CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(getTable().getRow(getSelectedID()));
515
            CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(row);
496
            sheet.createDocumentAsynchronous();
516
            sheet.createDocumentAsynchronous();
497
            sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true);
517
            sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true);
498
        } catch (Exception e) {
518
        } catch (Exception e) {
499
            ExceptionHandler.handle("Impossible de créer la commande", e);
519
            ExceptionHandler.handle("Impossible de créer la commande", e);
500
        }
520
        }
501
 
521
 
502
    }
522
    }
-
 
523
 
-
 
524
    protected String getLibelleStock(SQLRowAccessor row, SQLRowAccessor rowElt) {
-
 
525
        return "Commande client N°" + row.getString("NUMERO");
-
 
526
    }
-
 
527
 
-
 
528
    /**
-
 
529
     * Mise à jour des stocks pour chaque article composant la facture
-
 
530
     * 
-
 
531
     * @throws SQLException
-
 
532
     */
-
 
533
    private void updateStock(int id) throws SQLException {
-
 
534
 
-
 
535
        SQLRow row = getTable().getRow(id);
-
 
536
        StockItemsUpdater stockUpdater = new StockItemsUpdater(new StockLabel() {
-
 
537
            @Override
-
 
538
            public String getLabel(SQLRowAccessor rowOrigin, SQLRowAccessor rowElt) {
-
 
539
                return getLibelleStock(rowOrigin, rowElt);
-
 
540
            }
-
 
541
        }, row, row.getReferentRows(getTable().getTable("COMMANDE_CLIENT_ELEMENT")), Type.VIRTUAL_DELIVER);
-
 
542
 
-
 
543
        stockUpdater.update();
-
 
544
    }
503
 
545
 
504
    public void setDefaults() {
546
    public void setDefaults() {
505
        this.resetValue();
547
        this.resetValue();
506
        this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(CommandeClientSQLElement.class, new Date()));
548
        this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(CommandeClientSQLElement.class, new Date()));
507
        this.table.getModel().clearRows();
549
        this.table.getModel().clearRows();
508
    }
550
    }
509
 
551
 
510
    /**
552
    /**
511
     * Création d'une commande à partir d'un devis
553
     * Création d'une commande à partir d'un devis
512
     * 
554
     * 
513
     * @param idDevis
555
     * @param idDevis
514
     * 
556
     * 
515
     */
557
     */
516
    public void loadDevis(int idDevis) {
558
    public void loadDevis(int idDevis) {
517
 
559
 
518
        SQLElement devis = Configuration.getInstance().getDirectory().getElement("DEVIS");
560
        SQLElement devis = Configuration.getInstance().getDirectory().getElement("DEVIS");
519
        SQLElement devisElt = Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT");
561
        SQLElement devisElt = Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT");
520
 
562
 
521
        if (idDevis > 1) {
563
        if (idDevis > 1) {
522
            SQLInjector injector = SQLInjector.getInjector(devis.getTable(), this.getTable());
564
            SQLInjector injector = SQLInjector.getInjector(devis.getTable(), this.getTable());
523
            SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(idDevis);
565
            SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(idDevis);
524
            SQLRow rowDevis = devis.getTable().getRow(idDevis);
566
            SQLRow rowDevis = devis.getTable().getRow(idDevis);
525
 
567
 
526
            String string = rowDevis.getString("OBJET");
568
            String string = rowDevis.getString("OBJET");
527
            createRowValuesFrom.put("NOM", string + (string.trim().length() == 0 ? "" : ",") + rowDevis.getString("NUMERO"));
569
            createRowValuesFrom.put("NOM", string + (string.trim().length() == 0 ? "" : ",") + rowDevis.getString("NUMERO"));
528
            this.select(createRowValuesFrom);
570
            this.select(createRowValuesFrom);
529
        }
571
        }
530
 
572
 
531
        loadItem(this.table, devis, idDevis, devisElt);
573
        loadItem(this.table, devis, idDevis, devisElt);
532
    }
574
    }
533
 
575
 
534
    @Override
576
    @Override
535
    protected SQLRowValues createDefaults() {
577
    protected SQLRowValues createDefaults() {
536
        SQLRowValues rowVals = new SQLRowValues(getTable());
578
        SQLRowValues rowVals = new SQLRowValues(getTable());
537
        rowVals.put("T_POIDS", 0.0F);
579
        rowVals.put("T_POIDS", 0.0F);
538
        rowVals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(CommandeClientSQLElement.class, new Date()));
580
        rowVals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(CommandeClientSQLElement.class, new Date()));
539
        // User
581
        // User
540
        // SQLSelect sel = new SQLSelect(Configuration.getInstance().getBase());
582
        // SQLSelect sel = new SQLSelect(Configuration.getInstance().getBase());
541
        SQLElement eltComm = Configuration.getInstance().getDirectory().getElement("COMMERCIAL");
583
        SQLElement eltComm = Configuration.getInstance().getDirectory().getElement("COMMERCIAL");
542
        int idUser = UserManager.getInstance().getCurrentUser().getId();
584
        int idUser = UserManager.getInstance().getCurrentUser().getId();
543
        //
585
        //
544
        // sel.addSelect(eltComm.getTable().getKey());
586
        // sel.addSelect(eltComm.getTable().getKey());
545
        // sel.setWhere(new Where(eltComm.getTable().getField("ID_USER_COMMON"), "=", idUser));
587
        // sel.setWhere(new Where(eltComm.getTable().getField("ID_USER_COMMON"), "=", idUser));
546
        // List<SQLRow> rowsComm = (List<SQLRow>)
588
        // List<SQLRow> rowsComm = (List<SQLRow>)
547
        // Configuration.getInstance().getBase().getDataSource().execute(sel.asString(), new
589
        // Configuration.getInstance().getBase().getDataSource().execute(sel.asString(), new
548
        // SQLRowListRSH(eltComm.getTable()));
590
        // SQLRowListRSH(eltComm.getTable()));
549
        SQLRow rowsComm = SQLBackgroundTableCache.getInstance().getCacheForTable(eltComm.getTable()).getFirstRowContains(idUser, eltComm.getTable().getField("ID_USER_COMMON"));
591
        SQLRow rowsComm = SQLBackgroundTableCache.getInstance().getCacheForTable(eltComm.getTable()).getFirstRowContains(idUser, eltComm.getTable().getField("ID_USER_COMMON"));
550
 
592
 
551
        if (rowsComm != null) {
593
        if (rowsComm != null) {
552
            rowVals.put("ID_COMMERCIAL", rowsComm.getID());
594
            rowVals.put("ID_COMMERCIAL", rowsComm.getID());
553
        }
595
        }
554
        return rowVals;
596
        return rowVals;
555
    }
597
    }
556
}
598
}