OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.sales.order.component;
15
 
28 ilm 16
import static org.openconcerto.utils.CollectionUtils.createSet;
142 ilm 17
 
18 ilm 18
import org.openconcerto.erp.config.ComptaPropsConfiguration;
19
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
63 ilm 20
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18 ilm 21
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
22
import org.openconcerto.erp.core.common.ui.DeviseField;
23
import org.openconcerto.erp.core.common.ui.TotalPanel;
93 ilm 24
import org.openconcerto.erp.core.customerrelationship.customer.ui.AddressChoiceUI;
25
import org.openconcerto.erp.core.customerrelationship.customer.ui.AdresseType;
174 ilm 26
import org.openconcerto.erp.core.customerrelationship.customer.ui.CategorieComptableChoiceUI;
93 ilm 27
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
18 ilm 28
import org.openconcerto.erp.core.sales.order.report.CommandeClientXmlSheet;
29
import org.openconcerto.erp.core.sales.order.ui.CommandeClientItemTable;
93 ilm 30
import org.openconcerto.erp.core.sales.order.ui.EtatCommandeClient;
31
import org.openconcerto.erp.core.sales.order.ui.EtatCommandeClientComboBox;
32
import org.openconcerto.erp.core.sales.order.ui.EtatCommandeRowItemView;
144 ilm 33
import org.openconcerto.erp.core.supplychain.order.table.ChiffrageCommandeTable;
34
import org.openconcerto.erp.core.supplychain.order.table.FacturationCommandeTable;
83 ilm 35
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater;
93 ilm 36
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater.TypeStockUpdate;
83 ilm 37
import org.openconcerto.erp.core.supplychain.stock.element.StockLabel;
21 ilm 38
import org.openconcerto.erp.panel.PanelOOSQLComponent;
93 ilm 39
import org.openconcerto.erp.preferences.GestionClientPreferencePanel;
40
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
41
import org.openconcerto.erp.utils.TM;
18 ilm 42
import org.openconcerto.sql.Configuration;
43
import org.openconcerto.sql.element.SQLElement;
44
import org.openconcerto.sql.model.SQLBackgroundTableCache;
45
import org.openconcerto.sql.model.SQLInjector;
46
import org.openconcerto.sql.model.SQLRow;
47
import org.openconcerto.sql.model.SQLRowAccessor;
48
import org.openconcerto.sql.model.SQLRowValues;
49
import org.openconcerto.sql.model.SQLTable;
93 ilm 50
import org.openconcerto.sql.model.Where;
51
import org.openconcerto.sql.preferences.SQLPreferences;
18 ilm 52
import org.openconcerto.sql.sqlobject.ElementComboBox;
53
import org.openconcerto.sql.sqlobject.JUniqueTextField;
93 ilm 54
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
18 ilm 55
import org.openconcerto.sql.sqlobject.SQLTextCombo;
56
import org.openconcerto.sql.users.UserManager;
57
import org.openconcerto.sql.view.EditFrame;
73 ilm 58
import org.openconcerto.sql.view.list.RowValuesTable;
18 ilm 59
import org.openconcerto.ui.DefaultGridBagConstraints;
25 ilm 60
import org.openconcerto.ui.FormLayouter;
18 ilm 61
import org.openconcerto.ui.JDate;
62
import org.openconcerto.ui.TitledSeparator;
63
import org.openconcerto.ui.component.ITextArea;
64
import org.openconcerto.utils.ExceptionHandler;
156 ilm 65
import org.openconcerto.utils.text.SimpleDocumentListener;
18 ilm 66
 
67
import java.awt.Color;
68
import java.awt.GridBagConstraints;
69
import java.awt.GridBagLayout;
19 ilm 70
import java.beans.PropertyChangeEvent;
71
import java.beans.PropertyChangeListener;
18 ilm 72
import java.sql.SQLException;
28 ilm 73
import java.util.Date;
142 ilm 74
import java.util.HashSet;
75
import java.util.Set;
18 ilm 76
 
77
import javax.swing.JLabel;
19 ilm 78
import javax.swing.JOptionPane;
18 ilm 79
import javax.swing.JPanel;
80
import javax.swing.JScrollPane;
144 ilm 81
import javax.swing.JTabbedPane;
18 ilm 82
import javax.swing.JTextField;
83
import javax.swing.SwingConstants;
84
import javax.swing.SwingUtilities;
85
import javax.swing.event.DocumentEvent;
86
import javax.swing.event.DocumentListener;
87
import javax.swing.event.TableModelEvent;
88
import javax.swing.event.TableModelListener;
89
 
90
public class CommandeClientSQLComponent extends TransfertBaseSQLComponent {
91
 
92
    private CommandeClientItemTable table;
144 ilm 93
    private FacturationCommandeTable tableFacturationItem;
94
    private ChiffrageCommandeTable tableChiffrageItem;
18 ilm 95
    private JUniqueTextField numeroUniqueCommande;
96
    private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
97
    private final ITextArea infos = new ITextArea(3, 3);
98
    private ElementComboBox comboCommercial, comboDevis, comboClient;
21 ilm 99
    private PanelOOSQLComponent panelOO;
93 ilm 100
    final JDate dateCommande = new JDate(true);
101
    private final boolean displayDpt;
102
    private final ElementComboBox comboDpt = new ElementComboBox();
18 ilm 103
 
104
    private final SQLTextCombo textObjet = new SQLTextCombo();
105
 
106
    public CommandeClientSQLComponent() {
107
        super(Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT"));
93 ilm 108
        SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
109
        this.displayDpt = prefs.getBoolean(GestionClientPreferencePanel.DISPLAY_CLIENT_DPT, false);
18 ilm 110
    }
111
 
73 ilm 112
    public RowValuesTable getRowValuesTable() {
113
        return this.table.getRowValuesTable();
41 ilm 114
    }
115
 
18 ilm 116
    public void addViews() {
117
        this.setLayout(new GridBagLayout());
118
        final GridBagConstraints c = new DefaultGridBagConstraints();
119
 
120
        // Numero du commande
121
        c.gridx = 0;
122
        this.add(new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT), c);
123
 
142 ilm 124
        this.numeroUniqueCommande = new JUniqueTextField(16) {
125
            @Override
126
            public String getAutoRefreshNumber() {
127
                if (getMode() == Mode.INSERTION) {
128
                    return NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), dateCommande.getDate());
129
                } else {
130
                    return null;
131
                }
132
            }
133
        };
18 ilm 134
        c.fill = GridBagConstraints.NONE;
135
        c.gridx++;
136
        c.weightx = 1;
137
        this.add(this.numeroUniqueCommande, c);
138
 
139
        // Date
140
        JLabel labelDate = new JLabel(getLabelFor("DATE"));
141
        labelDate.setHorizontalAlignment(SwingConstants.RIGHT);
142
        c.gridx = 2;
143
        c.fill = GridBagConstraints.HORIZONTAL;
144
        c.weightx = 0;
145
        this.add(labelDate, c);
146
 
147
        c.gridx++;
148
        c.fill = GridBagConstraints.NONE;
149
        this.add(dateCommande, c);
93 ilm 150
        dateCommande.addValueListener(new PropertyChangeListener() {
18 ilm 151
 
93 ilm 152
            @Override
153
            public void propertyChange(PropertyChangeEvent evt) {
154
                if (!isFilling() && dateCommande.getValue() != null) {
155
                    table.setDateDevise(dateCommande.getValue());
156
                }
157
            }
158
        });
159
 
28 ilm 160
        // Champ Module
161
        c.gridx = 0;
162
        c.gridy++;
163
        c.gridwidth = GridBagConstraints.REMAINDER;
63 ilm 164
        final JPanel addP = ComptaSQLConfElement.createAdditionalPanel();
28 ilm 165
 
166
        this.setAdditionalFieldsPanel(new FormLayouter(addP, 2));
167
        c.fill = GridBagConstraints.HORIZONTAL;
168
        c.weightx = 1;
169
        this.add(addP, c);
170
 
171
        c.gridy++;
172
        c.gridwidth = 1;
173
 
174
        this.comboDevis = new ElementComboBox();
175
 
18 ilm 176
        // Reference
177
        c.gridx = 0;
178
        c.gridy++;
179
        c.gridwidth = 1;
180
        c.gridwidth = 1;
181
        c.gridheight = 1;
182
        c.fill = GridBagConstraints.HORIZONTAL;
183
 
184
        JLabel labelObjet = new JLabel(getLabelFor("NOM"));
185
        labelObjet.setHorizontalAlignment(SwingConstants.RIGHT);
186
        c.weightx = 0;
187
        this.add(labelObjet, c);
188
 
189
        c.gridx++;
190
        c.weightx = 1;
191
        c.fill = GridBagConstraints.BOTH;
192
        this.add(this.textObjet, c);
193
 
194
        String field;
195
            field = "ID_COMMERCIAL";
196
        c.fill = GridBagConstraints.HORIZONTAL;
197
        // Commercial
198
        JLabel labelCommercial = new JLabel(getLabelFor(field));
199
        labelCommercial.setHorizontalAlignment(SwingConstants.RIGHT);
200
 
201
        c.gridx++;
202
        c.weightx = 0;
203
        this.add(labelCommercial, c);
204
 
205
        this.comboCommercial = new ElementComboBox(false, 25);
206
        this.comboCommercial.setListIconVisible(false);
207
        c.gridx++;
208
        c.fill = GridBagConstraints.NONE;
209
        c.weightx = 1;
210
        this.add(this.comboCommercial, c);
211
        addRequiredSQLObject(this.comboCommercial, field);
212
 
213
        // Ligne 3: Client
214
        c.gridx = 0;
215
        c.gridy++;
216
        c.weightx = 0;
217
        c.fill = GridBagConstraints.HORIZONTAL;
218
        this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c);
219
 
220
        this.comboClient = new ElementComboBox();
93 ilm 221
        c.gridx++;
222
        c.gridwidth = 1;
18 ilm 223
        c.weightx = 1;
224
        c.weighty = 0;
225
        c.fill = GridBagConstraints.NONE;
226
        this.add(this.comboClient, c);
19 ilm 227
        final ElementComboBox boxTarif = new ElementComboBox();
228
        this.comboClient.addValueListener(new PropertyChangeListener() {
18 ilm 229
 
19 ilm 230
            @Override
231
            public void propertyChange(PropertyChangeEvent evt) {
28 ilm 232
                if (!isFilling() && comboClient.getValue() != null) {
19 ilm 233
                    Integer id = comboClient.getValue();
234
 
235
                    if (id > 1) {
236
 
237
                        SQLRow row = comboClient.getElement().getTable().getRow(id);
238
                        if (comboClient.getElement().getTable().getFieldsName().contains("ID_TARIF")) {
239
 
240
                            SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
241
                            if (!foreignRow.isUndefined() && (boxTarif.getSelectedRow() == null || boxTarif.getSelectedId() != foreignRow.getID())
93 ilm 242
                                    && JOptionPane.showConfirmDialog(null, TM.tr("apply.associated.pricelist.to.customer")) == JOptionPane.YES_OPTION) {
19 ilm 243
                                boxTarif.setValue(foreignRow.getID());
244
                                // SaisieVenteFactureSQLComponent.this.tableFacture.setTarif(foreignRow,
245
                                // true);
246
                            } else {
247
                                boxTarif.setValue(foreignRow.getID());
248
                            }
249
                            // SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
250
                            // if (foreignRow.isUndefined() &&
251
                            // !row.getForeignRow("ID_DEVISE").isUndefined()) {
252
                            // SQLRowValues rowValsD = new SQLRowValues(foreignRow.getTable());
253
                            // rowValsD.put("ID_DEVISE", row.getObject("ID_DEVISE"));
254
                            // foreignRow = rowValsD;
255
                            //
256
                            // }
257
                            // table.setTarif(foreignRow, true);
258
                        }
174 ilm 259
                        if (!isFilling()) {
260
                            table.setClient(row, true);
261
                        }
262
 
263
                    } else {
264
                        if (!isFilling()) {
265
                            table.setClient(null, true);
266
                        }
19 ilm 267
                    }
268
                }
269
 
270
            }
271
        });
93 ilm 272
        addRequiredSQLObject(this.comboClient, "ID_CLIENT");
273
 
274
        if (this.displayDpt) {
275
            c.gridx++;
276
            c.gridwidth = 1;
277
            final JLabel labelDpt = new JLabel(getLabelFor("ID_CLIENT_DEPARTEMENT"));
278
            labelDpt.setHorizontalAlignment(SwingConstants.RIGHT);
279
            c.weightx = 0;
280
            c.gridwidth = 1;
281
            c.fill = GridBagConstraints.HORIZONTAL;
282
            this.add(labelDpt, c);
283
 
284
            c.gridx++;
285
            c.gridwidth = 1;
286
            c.weightx = 0;
287
            c.weighty = 0;
288
            c.fill = GridBagConstraints.NONE;
289
            this.add(this.comboDpt, c);
290
            DefaultGridBagConstraints.lockMinimumSize(this.comboDpt);
291
            addSQLObject(this.comboDpt, "ID_CLIENT_DEPARTEMENT");
292
 
293
            comboClient.addModelListener("wantedID", new PropertyChangeListener() {
294
 
295
                @Override
296
                public void propertyChange(PropertyChangeEvent evt) {
297
                    int wantedID = comboClient.getWantedID();
298
 
299
                    if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) {
300
                        final SQLRow rowClient = getTable().getForeignTable("ID_CLIENT").getRow(wantedID);
301
                        comboDpt.getRequest().setWhere(new Where(comboDpt.getRequest().getPrimaryTable().getField("ID_CLIENT"), "=", rowClient.getID()));
302
                    } else {
303
                        comboDpt.getRequest().setWhere(null);
304
                    }
305
                }
306
            });
307
 
308
        }
309
        if (getTable().contains("ID_CONTACT")) {
310
            // Contact Client
311
            c.gridx = 0;
312
            c.gridy++;
313
            c.gridwidth = 1;
314
            final JLabel labelContact = new JLabel(getLabelFor("ID_CONTACT"));
315
            labelContact.setHorizontalAlignment(SwingConstants.RIGHT);
316
            c.weightx = 0;
317
            c.gridwidth = 1;
318
            c.fill = GridBagConstraints.HORIZONTAL;
319
            this.add(labelContact, c);
320
 
321
            final ElementComboBox comboContact = new ElementComboBox();
322
            c.gridx++;
323
            c.gridwidth = 1;
324
            c.weightx = 0;
325
            c.weighty = 0;
326
            c.fill = GridBagConstraints.NONE;
327
            this.add(comboContact, c);
328
            final SQLElement contactElement = getElement().getForeignElement("ID_CONTACT");
329
            comboContact.init(contactElement, contactElement.getComboRequest(true));
330
            comboContact.getRequest().setWhere(Where.FALSE);
331
            DefaultGridBagConstraints.lockMinimumSize(comboContact);
332
            this.addView(comboContact, "ID_CONTACT");
333
            comboClient.addModelListener("wantedID", new PropertyChangeListener() {
334
 
335
                @Override
336
                public void propertyChange(PropertyChangeEvent evt) {
337
                    int wantedID = comboClient.getWantedID();
338
                    System.err.println("SET WHERE ID_CLIENT = " + wantedID);
339
                    if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) {
340
 
341
                        final SQLRow rowClient = getTable().getForeignTable("ID_CLIENT").getRow(wantedID);
144 ilm 342
 
156 ilm 343
                        if (rowClient.getObject("ID_CATEGORIE_COMPTABLE") != null && !rowClient.isForeignEmpty("ID_CATEGORIE_COMPTABLE")) {
344
                            table.setRowCatComptable(rowClient.getForeign("ID_CATEGORIE_COMPTABLE"));
345
                        } else {
346
                            table.setRowCatComptable(null);
347
                        }
348
 
94 ilm 349
                        if (!rowClient.isForeignEmpty("ID_COMMERCIAL")) {
350
                            comboCommercial.setValue(rowClient.getForeignID("ID_COMMERCIAL"));
351
                        }
93 ilm 352
                        int idClient = rowClient.getID();
353
                        comboContact.getRequest().setWhere(new Where(contactElement.getTable().getField("ID_CLIENT"), "=", idClient));
354
                    } else {
156 ilm 355
                        table.setRowCatComptable(null);
93 ilm 356
                        comboContact.getRequest().setWhere(Where.FALSE);
357
                        // DevisSQLComponent.this.table.setTarif(null, false);
358
                    }
359
                }
360
            });
361
 
142 ilm 362
            if (getTable().contains("DATE_LIVRAISON_PREV")) {
363
                // Date
364
                JLabel labelDatePrev = new JLabel(getLabelFor("DATE_LIVRAISON_PREV"));
365
                labelDatePrev.setHorizontalAlignment(SwingConstants.RIGHT);
366
                c.gridx = 2;
367
                c.fill = GridBagConstraints.HORIZONTAL;
368
                c.weightx = 0;
369
                this.add(labelDatePrev, c);
370
 
371
                c.gridx++;
372
                c.fill = GridBagConstraints.NONE;
373
                JDate datePrev = new JDate();
374
                this.add(datePrev, c);
375
                this.addView(datePrev, "DATE_LIVRAISON_PREV");
376
            }
377
 
93 ilm 378
        }
94 ilm 379
        SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
380
        if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.ADDRESS_SPEC, true)) {
93 ilm 381
 
94 ilm 382
            final SQLElement adrElement = getElement().getForeignElement("ID_ADRESSE");
383
            final AddressChoiceUI addressUI = new AddressChoiceUI();
384
            addressUI.addToUI(this, c);
385
            comboClient.addModelListener("wantedID", new PropertyChangeListener() {
93 ilm 386
 
94 ilm 387
                @Override
388
                public void propertyChange(PropertyChangeEvent evt) {
389
                    int wantedID = comboClient.getWantedID();
390
                    System.err.println("SET WHERE ID_CLIENT = " + wantedID);
391
                    if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) {
392
 
132 ilm 393
                        addressUI.getComboAdrF().getRequest().setWhere(
394
                                new Where(adrElement.getTable().getField("ID_CLIENT"), "=", wantedID).and(new Where(adrElement.getTable().getField("TYPE"), "=", AdresseType.Invoice.getId())));
395
                        addressUI.getComboAdrL().getRequest().setWhere(
396
                                new Where(adrElement.getTable().getField("ID_CLIENT"), "=", wantedID).and(new Where(adrElement.getTable().getField("TYPE"), "=", AdresseType.Delivery.getId())));
94 ilm 397
                    } else {
398
                        addressUI.getComboAdrF().getRequest().setWhere(Where.FALSE);
399
                        addressUI.getComboAdrL().getRequest().setWhere(Where.FALSE);
400
                    }
93 ilm 401
                }
94 ilm 402
            });
403
        }
93 ilm 404
 
174 ilm 405
        if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.CATEGORIE_COMPTABLE_SPEC, false)) {
406
            // cat spe
407
            final CategorieComptableChoiceUI catUI = new CategorieComptableChoiceUI();
408
            catUI.addToUI(this, c);
409
            catUI.getCombo().addModelListener("wantedID", new PropertyChangeListener() {
410
 
411
                @Override
412
                public void propertyChange(PropertyChangeEvent evt) {
413
                    int wantedID = catUI.getCombo().getWantedID();
414
                    if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) {
415
                        table.setRowCatComptable(catUI.getCombo().getElement().getTable().getRow(wantedID));
416
                    } else {
417
                        table.setRowCatComptable(null);
418
                    }
419
                }
420
            });
421
        }
422
 
93 ilm 423
        if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.ORDER_PACKAGING_MANAGEMENT, true)) {
424
            // Emballage
425
            c.gridy++;
426
            c.gridx = 0;
427
            c.weightx = 0;
428
            c.fill = GridBagConstraints.HORIZONTAL;
429
            this.add(new JLabel(getLabelFor("EMBALLAGE"), SwingConstants.RIGHT), c);
430
 
431
            c.fill = GridBagConstraints.HORIZONTAL;
432
            c.gridx++;
433
            c.weightx = 1;
434
            SQLTextCombo fieldEmballage = new SQLTextCombo();
435
            this.add(fieldEmballage, c);
436
            this.addView(fieldEmballage, "EMBALLAGE");
437
 
438
            // N° Exp
439
            JLabel labelNumExp = new JLabel(getLabelFor("NUMERO_EXPEDITION"));
440
            labelNumExp.setHorizontalAlignment(SwingConstants.RIGHT);
441
            c.gridx = 2;
442
            c.fill = GridBagConstraints.HORIZONTAL;
443
            c.weightx = 0;
444
            this.add(labelNumExp, c);
445
 
446
            JTextField fieldNumExp = new JTextField();
447
            c.gridx++;
448
            c.weightx = 1;
449
            this.add(fieldNumExp, c);
450
            this.addView(fieldNumExp, "NUMERO_EXPEDITION");
451
 
452
            // expedition
453
 
454
            c.gridy++;
455
            c.gridx = 0;
456
            c.weightx = 0;
457
            c.weighty = 0;
458
            c.gridwidth = 1;
459
            c.fill = GridBagConstraints.HORIZONTAL;
460
            this.add(new JLabel(getLabelFor("TYPE_EXPEDITION"), SwingConstants.RIGHT), c);
461
            c.gridx++;
462
            c.gridwidth = 1;
463
            c.weightx = 1;
464
            c.fill = GridBagConstraints.NONE;
465
            SQLTextCombo tTypeExpedition = new SQLTextCombo();
466
            this.add(tTypeExpedition, c);
467
            this.addView(tTypeExpedition, "TYPE_EXPEDITION");
468
 
469
            // Etat
470
            final JLabel labelEtat = new JLabel(getLabelFor("ETAT_COMMANDE"), SwingConstants.RIGHT);
471
            c.gridx++;
472
            c.weightx = 0;
473
            c.fill = GridBagConstraints.HORIZONTAL;
474
            this.add(labelEtat, c);
475
            final EtatCommandeClientComboBox comboEtat = new EtatCommandeClientComboBox();
476
            c.gridx++;
477
            c.fill = GridBagConstraints.NONE;
478
            c.weightx = 1;
479
            this.add(comboEtat, c);
480
            addView(new EtatCommandeRowItemView(comboEtat), "ETAT_COMMANDE", REQ);
481
        }
19 ilm 482
        // tarif
483
        if (this.getTable().getFieldsName().contains("ID_TARIF")) {
484
            // TARIF
93 ilm 485
            c.fill = GridBagConstraints.HORIZONTAL;
19 ilm 486
            c.gridy++;
487
            c.gridx = 0;
488
            c.weightx = 0;
489
            c.weighty = 0;
490
            c.gridwidth = 1;
93 ilm 491
            this.add(new JLabel(getLabelFor("ID_TARIF"), SwingConstants.RIGHT), c);
19 ilm 492
            c.gridx++;
93 ilm 493
            c.gridwidth = 1;
19 ilm 494
 
495
            c.weightx = 1;
496
            this.add(boxTarif, c);
497
            this.addView(boxTarif, "ID_TARIF");
73 ilm 498
            boxTarif.addModelListener("wantedID", new PropertyChangeListener() {
19 ilm 499
 
500
                @Override
501
                public void propertyChange(PropertyChangeEvent evt) {
73 ilm 502
                    SQLRow selectedRow = boxTarif.getRequest().getPrimaryTable().getRow(boxTarif.getWantedID());
503
                    table.setTarif(selectedRow, false);
19 ilm 504
                }
505
            });
144 ilm 506
            if (getTable().contains("DATE_LIVRAISON_REELLE")) {
507
                // Date
508
                JLabel labelDatePrev = new JLabel(getLabelFor("DATE_LIVRAISON_REELLE"));
509
                labelDatePrev.setHorizontalAlignment(SwingConstants.RIGHT);
510
                c.gridx++;
511
                c.fill = GridBagConstraints.HORIZONTAL;
512
                c.weightx = 0;
513
                this.add(labelDatePrev, c);
514
 
515
                c.gridx++;
516
                c.fill = GridBagConstraints.NONE;
517
                JDate datePrev = new JDate();
518
                this.add(datePrev, c);
519
                this.addView(datePrev, "DATE_LIVRAISON_REELLE");
520
            }
19 ilm 521
        }
142 ilm 522
        if (this.getTable().getFieldsName().contains("ACOMPTE_COMMANDE")) {
523
            // ACOMPTE
524
            c.gridy += (this.getTable().getFieldsName().contains("ID_TARIF") ? 0 : 1);
525
            c.gridx += (this.getTable().getFieldsName().contains("ID_TARIF") ? 1 : 2);
526
            c.weightx = 0;
527
            c.weighty = 0;
528
            c.gridwidth = 1;
529
            c.fill = GridBagConstraints.HORIZONTAL;
530
            this.add(new JLabel(getLabelFor("ACOMPTE_COMMANDE"), SwingConstants.RIGHT), c);
531
            c.gridx++;
532
            c.gridwidth = GridBagConstraints.REMAINDER;
533
            c.fill = GridBagConstraints.NONE;
534
            c.weightx = 1;
535
            JTextField acompteCmd = new JTextField(15);
536
            DefaultGridBagConstraints.lockMinimumSize(acompteCmd);
537
            this.add(acompteCmd, c);
538
            this.addView(acompteCmd, "ACOMPTE_COMMANDE");
539
        }
19 ilm 540
 
18 ilm 541
        // Table d'élément
542
        this.table = new CommandeClientItemTable();
144 ilm 543
        JTabbedPane pane = new JTabbedPane();
18 ilm 544
        c.fill = GridBagConstraints.BOTH;
545
        c.gridy++;
546
        c.gridx = 0;
547
        c.weightx = 1;
548
        c.weighty = 1;
549
        c.gridwidth = GridBagConstraints.REMAINDER;
144 ilm 550
        pane.add("Eléments", this.table);
551
        this.tableFacturationItem = new FacturationCommandeTable(this);
552
        pane.add("Facturation", this.tableFacturationItem);
553
        if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.CHIFFRAGE_COMMANDE_CLIENT, false)) {
554
            this.tableChiffrageItem = new ChiffrageCommandeTable(this);
555
            pane.add("Chiffrage", this.tableChiffrageItem);
556
        }
557
        this.add(pane, c);
18 ilm 558
 
93 ilm 559
        DeviseField textPortHT = new DeviseField(5);
18 ilm 560
        DeviseField textRemiseHT = new DeviseField();
561
 
93 ilm 562
        // Total
563
        DeviseField fieldHT = new DeviseField();
564
        DeviseField fieldTVA = new DeviseField();
565
        DeviseField fieldTTC = new DeviseField();
566
        DeviseField fieldDevise = new DeviseField();
567
        DeviseField fieldService = new DeviseField();
568
        DeviseField fieldHA = new DeviseField();
142 ilm 569
        DeviseField fieldEco = new DeviseField();
93 ilm 570
        fieldHT.setOpaque(false);
571
        fieldHA.setOpaque(false);
572
        fieldTVA.setOpaque(false);
573
        fieldTTC.setOpaque(false);
574
        fieldService.setOpaque(false);
575
        addSQLObject(fieldDevise, "T_DEVISE");
142 ilm 576
        addSQLObject(fieldEco, "T_ECO_CONTRIBUTION");
93 ilm 577
        addRequiredSQLObject(fieldHT, "T_HT");
578
        addRequiredSQLObject(fieldTVA, "T_TVA");
579
        addRequiredSQLObject(fieldTTC, "T_TTC");
580
        addRequiredSQLObject(fieldService, "T_SERVICE");
581
        if (getTable().contains("PREBILAN")) {
582
            addSQLObject(fieldHA, "PREBILAN");
583
        } else if (getTable().contains("T_HA")) {
94 ilm 584
            this.allowEditable("T_HA", false);
93 ilm 585
            addSQLObject(fieldHA, "T_HA");
586
        }
94 ilm 587
        // Disable
142 ilm 588
        this.allowEditable("T_ECO_CONTRIBUTION", false);
94 ilm 589
        this.allowEditable("T_HT", false);
590
        this.allowEditable("T_TVA", false);
591
        this.allowEditable("T_TTC", false);
592
        this.allowEditable("T_SERVICE", false);
93 ilm 593
 
594
        JTextField poids = new JTextField();
595
        SQLRequestComboBox boxTaxePort = new SQLRequestComboBox(false, 8);
156 ilm 596
 
93 ilm 597
        // addSQLObject(poids, "T_POIDS");
142 ilm 598
        final TotalPanel totalTTC = new TotalPanel(this.table, fieldEco, fieldHT, fieldTVA, fieldTTC, textPortHT, textRemiseHT, fieldService, fieldHA, fieldDevise, poids, null,
599
                (getTable().contains("ID_TAXE_PORT") ? boxTaxePort : null), null);
93 ilm 600
 
18 ilm 601
        // INfos
602
        c.gridx = 0;
603
        c.gridy++;
604
        c.gridheight = 1;
605
        c.weighty = 0;
606
        c.weightx = 1;
607
        c.anchor = GridBagConstraints.WEST;
608
        c.gridwidth = 2;
609
        this.add(new TitledSeparator(getLabelFor("INFOS")), c);
610
 
611
        c.gridy++;
612
        c.weightx = 1;
613
        c.weighty = 0;
614
        c.fill = GridBagConstraints.BOTH;
615
        final JScrollPane scrollPane = new JScrollPane(this.infos);
616
        scrollPane.setBorder(null);
617
        this.add(scrollPane, c);
618
 
619
        // Poids
620
 
621
        final JTextField textPoidsTotal = new JTextField(8);
93 ilm 622
        JPanel panel = new JPanel(new GridBagLayout());
623
        GridBagConstraints cFrais = new DefaultGridBagConstraints();
624
        c.fill = GridBagConstraints.HORIZONTAL;
625
        panel.add(new JLabel(getLabelFor("T_POIDS"), JTextField.RIGHT), cFrais);
626
        textPoidsTotal.setEnabled(false);
627
        textPoidsTotal.setDisabledTextColor(Color.BLACK);
628
        cFrais.gridx++;
629
        panel.add(textPoidsTotal, cFrais);
18 ilm 630
 
93 ilm 631
        panel.setOpaque(false);
18 ilm 632
 
93 ilm 633
        DefaultGridBagConstraints.lockMinimumSize(textPortHT);
634
        addSQLObject(textPortHT, "PORT_HT");
635
        DefaultGridBagConstraints.lockMinimumSize(textRemiseHT);
636
        addSQLObject(textRemiseHT, "REMISE_HT");
18 ilm 637
 
93 ilm 638
        // Frais de port
18 ilm 639
 
93 ilm 640
        if (getTable().contains("ID_TAXE_PORT")) {
18 ilm 641
 
93 ilm 642
            JLabel labelPortHT = new JLabel(getLabelFor("PORT_HT"));
643
            labelPortHT.setHorizontalAlignment(SwingConstants.RIGHT);
644
            cFrais.gridx = 0;
645
            cFrais.gridy++;
646
            panel.add(labelPortHT, cFrais);
647
            cFrais.gridx++;
648
            panel.add(textPortHT, cFrais);
649
 
650
            JLabel labelTaxeHT = new JLabel(getLabelFor("ID_TAXE_PORT"));
651
            labelTaxeHT.setHorizontalAlignment(SwingConstants.RIGHT);
652
            cFrais.gridx = 0;
653
            cFrais.gridy++;
654
            panel.add(labelTaxeHT, cFrais);
655
            cFrais.gridx++;
656
            panel.add(boxTaxePort, cFrais);
657
            this.addView(boxTaxePort, "ID_TAXE_PORT", REQ);
658
 
659
            boxTaxePort.addValueListener(new PropertyChangeListener() {
660
 
661
                @Override
662
                public void propertyChange(PropertyChangeEvent evt) {
663
                    totalTTC.updateTotal();
664
                }
665
            });
61 ilm 666
        }
667
 
93 ilm 668
        // Remise
669
        JLabel labelRemiseHT = new JLabel(getLabelFor("REMISE_HT"));
670
        labelRemiseHT.setHorizontalAlignment(SwingConstants.RIGHT);
671
        cFrais.gridy++;
672
        cFrais.gridx = 0;
673
        panel.add(labelRemiseHT, cFrais);
674
        cFrais.gridx++;
675
        panel.add(textRemiseHT, cFrais);
18 ilm 676
 
93 ilm 677
        c.gridx = 2;
678
        c.weightx = 0;
679
        c.weighty = 0;
680
        c.gridwidth = 1;
681
        c.fill = GridBagConstraints.NONE;
682
        c.anchor = GridBagConstraints.NORTHEAST;
683
        DefaultGridBagConstraints.lockMinimumSize(panel);
684
        this.add(panel, c);
685
 
18 ilm 686
        c.gridx = GridBagConstraints.RELATIVE;
687
        c.gridy--;
688
        c.gridwidth = GridBagConstraints.REMAINDER;
689
        c.gridheight = 2;
690
        c.anchor = GridBagConstraints.NORTHEAST;
691
        c.fill = GridBagConstraints.NONE;
692
        c.weighty = 0;
693
 
694
        this.add(totalTTC, c);
695
 
21 ilm 696
        this.panelOO = new PanelOOSQLComponent(this);
18 ilm 697
        c.gridwidth = 1;
61 ilm 698
        c.fill = GridBagConstraints.NONE;
18 ilm 699
        c.anchor = GridBagConstraints.EAST;
700
        c.gridx = 0;
701
        c.gridy += 3;
702
        c.weightx = 0;
703
        c.gridwidth = GridBagConstraints.REMAINDER;
21 ilm 704
        this.add(this.panelOO, c);
18 ilm 705
 
706
        textPortHT.getDocument().addDocumentListener(new DocumentListener() {
707
            public void changedUpdate(DocumentEvent e) {
708
                totalTTC.updateTotal();
709
            }
710
 
711
            public void removeUpdate(DocumentEvent e) {
712
                totalTTC.updateTotal();
713
            }
714
 
715
            public void insertUpdate(DocumentEvent e) {
716
                totalTTC.updateTotal();
717
            }
718
        });
719
 
720
        textRemiseHT.getDocument().addDocumentListener(new DocumentListener() {
721
            public void changedUpdate(DocumentEvent e) {
722
                totalTTC.updateTotal();
723
            }
724
 
725
            public void removeUpdate(DocumentEvent e) {
726
                totalTTC.updateTotal();
727
            }
728
 
729
            public void insertUpdate(DocumentEvent e) {
730
                totalTTC.updateTotal();
731
            }
732
        });
733
 
734
        addSQLObject(this.textObjet, "NOM");
735
        addSQLObject(textPoidsTotal, "T_POIDS");
736
        addRequiredSQLObject(dateCommande, "DATE");
737
        // addRequiredSQLObject(radioEtat, "ID_ETAT_DEVIS");
738
        addRequiredSQLObject(this.numeroUniqueCommande, "NUMERO");
739
        addSQLObject(this.infos, "INFOS");
740
        addSQLObject(this.comboDevis, "ID_DEVIS");
741
 
90 ilm 742
        this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), new Date()));
18 ilm 743
 
744
        this.table.getModel().addTableModelListener(new TableModelListener() {
745
 
746
            public void tableChanged(TableModelEvent e) {
747
                textPoidsTotal.setText(String.valueOf(CommandeClientSQLComponent.this.table.getPoidsTotal()));
748
            }
749
        });
750
        DefaultGridBagConstraints.lockMinimumSize(comboClient);
751
        DefaultGridBagConstraints.lockMinimumSize(comboCommercial);
752
        DefaultGridBagConstraints.lockMinimumSize(comboDevis);
753
        DefaultGridBagConstraints.lockMinimumSize(totalTTC);
754
        DefaultGridBagConstraints.lockMaximumSize(totalTTC);
755
        DefaultGridBagConstraints.lockMinimumSize(numeroUniqueCommande);
756
 
757
    }
758
 
759
    public int insert(SQLRow order) {
25 ilm 760
        final int idCommande;
142 ilm 761
 
762
        int attempt = 0;
18 ilm 763
        // on verifie qu'un devis du meme numero n'a pas été inséré entre temps
142 ilm 764
        if (!this.numeroUniqueCommande.checkValidation(false)) {
765
            while (attempt < JUniqueTextField.RETRY_COUNT) {
766
                String num = NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), dateCommande.getDate());
767
                this.numeroUniqueCommande.setText(num);
768
                attempt++;
769
                if (this.numeroUniqueCommande.checkValidation(false)) {
770
                    System.err.println("ATEMPT " + attempt + " SUCCESS WITH NUMERO " + num);
771
                    break;
772
                }
773
                try {
774
                    Thread.sleep(JUniqueTextField.SLEEP_WAIT_MS);
775
                } catch (InterruptedException e) {
776
                    e.printStackTrace();
777
                }
778
            }
779
        }
780
        final String num = this.numeroUniqueCommande.getText();
781
        if (attempt == JUniqueTextField.RETRY_COUNT) {
782
            idCommande = getSelectedID();
783
            ExceptionHandler.handle("Impossible d'ajouter, numéro de commande existant.");
784
            final Object root = SwingUtilities.getRoot(this);
785
            if (root instanceof EditFrame) {
786
                final EditFrame frame = (EditFrame) root;
787
                frame.getPanel().setAlwaysVisible(true);
788
            }
789
        } else {
18 ilm 790
            idCommande = super.insert(order);
791
            this.table.updateField("ID_COMMANDE_CLIENT", idCommande);
144 ilm 792
            this.tableFacturationItem.updateField("ID_COMMANDE_CLIENT", idCommande);
793
            if (this.tableChiffrageItem != null) {
794
                this.tableChiffrageItem.updateField("ID_COMMANDE_CLIENT", idCommande);
795
            }
83 ilm 796
            try {
797
                updateStock(idCommande);
798
            } catch (SQLException e1) {
799
                ExceptionHandler.handle("Erreur lors de la mise à du stock!", e1);
800
            }
18 ilm 801
            // Création des articles
802
            this.table.createArticle(idCommande, this.getElement());
803
            // generation du document
804
 
25 ilm 805
            try {
806
                CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(getTable().getRow(idCommande));
807
                sheet.createDocumentAsynchronous();
808
                sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true);
809
            } catch (Exception e) {
810
                ExceptionHandler.handle("Impossible de créer la commande", e);
811
            }
812
 
18 ilm 813
            // incrémentation du numéro auto
90 ilm 814
            if (NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), new Date()).equalsIgnoreCase(this.numeroUniqueCommande.getText().trim())) {
18 ilm 815
                SQLRowValues rowVals = new SQLRowValues(this.tableNum);
816
                int val = this.tableNum.getRow(2).getInt("COMMANDE_CLIENT_START");
817
                val++;
818
                rowVals.put("COMMANDE_CLIENT_START", new Integer(val));
819
 
820
                try {
821
                    rowVals.update(2);
822
                } catch (SQLException e) {
823
                    e.printStackTrace();
824
                }
825
            }
142 ilm 826
            if (attempt > 0) {
827
                SwingUtilities.invokeLater(new Runnable() {
828
                    public void run() {
829
                        JOptionPane.showMessageDialog(null, "Le numéro a été actualisé en " + num);
830
                    }
831
                });
18 ilm 832
            }
833
        }
834
 
835
        return idCommande;
836
    }
837
 
838
    @Override
142 ilm 839
    public Set<String> getPartialResetNames() {
840
        Set<String> s = new HashSet<String>();
841
        s.add("NOM");
842
        s.add("NUMERO");
843
        s.add("INFOS");
844
        s.add("ID_CLIENT");
845
        if (getTable().contains("ACOMPTE_COMMANDE")) {
846
            s.add("ACOMPTE_COMMANDE");
847
        }
848
        return s;
849
    }
850
 
851
    @Override
18 ilm 852
    public void select(SQLRowAccessor r) {
28 ilm 853
        if (r == null || r.getIDNumber() == null)
854
            super.select(r);
855
        else {
856
            System.err.println(r);
132 ilm 857
            final SQLRowValues rVals = r.asRowValues().deepCopy();
28 ilm 858
            final SQLRowValues vals = new SQLRowValues(r.getTable());
859
            vals.load(rVals, createSet("ID_CLIENT"));
860
            vals.setID(rVals.getID());
861
            System.err.println("Select CLIENT");
862
            super.select(vals);
863
            rVals.remove("ID_CLIENT");
864
            super.select(rVals);
865
        }
18 ilm 866
        if (r != null) {
867
            this.table.insertFrom("ID_COMMANDE_CLIENT", r.getID());
144 ilm 868
            this.tableFacturationItem.insertFrom("ID_COMMANDE_CLIENT", r.getID());
869
            if (this.tableChiffrageItem != null) {
870
                this.tableChiffrageItem.insertFrom("ID_COMMANDE_CLIENT", r.getID());
871
            }
18 ilm 872
        }
873
        // this.radioEtat.setVisible(r.getID() > 1);
874
    }
875
 
876
    @Override
877
    public void update() {
878
 
879
        if (!this.numeroUniqueCommande.checkValidation()) {
880
            ExceptionHandler.handle("Impossible d'ajouter, numéro de commande client existant.");
881
            Object root = SwingUtilities.getRoot(this);
882
            if (root instanceof EditFrame) {
883
                EditFrame frame = (EditFrame) root;
884
                frame.getPanel().setAlwaysVisible(true);
885
            }
886
            return;
887
        }
888
        super.update();
83 ilm 889
        final int id = getSelectedID();
890
        this.table.updateField("ID_COMMANDE_CLIENT", id);
144 ilm 891
        this.tableFacturationItem.updateField("ID_COMMANDE_CLIENT", id);
892
        if (this.tableChiffrageItem != null) {
893
            this.tableChiffrageItem.updateField("ID_COMMANDE_CLIENT", id);
894
        }
83 ilm 895
        this.table.createArticle(id, this.getElement());
18 ilm 896
 
83 ilm 897
        final SQLRow row = getTable().getRow(id);
898
        try {
899
            updateStock(id);
900
        } catch (SQLException e1) {
901
            ExceptionHandler.handle("Erreur lors de la mise à du stock!", e1);
902
        }
903
 
18 ilm 904
        // generation du document
25 ilm 905
        try {
83 ilm 906
            CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(row);
25 ilm 907
            sheet.createDocumentAsynchronous();
908
            sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true);
909
        } catch (Exception e) {
910
            ExceptionHandler.handle("Impossible de créer la commande", e);
911
        }
912
 
18 ilm 913
    }
914
 
83 ilm 915
    protected String getLibelleStock(SQLRowAccessor row, SQLRowAccessor rowElt) {
916
        return "Commande client N°" + row.getString("NUMERO");
917
    }
918
 
919
    /**
920
     * Mise à jour des stocks pour chaque article composant la facture
921
     *
922
     * @throws SQLException
923
     */
924
    private void updateStock(int id) throws SQLException {
925
 
926
        SQLRow row = getTable().getRow(id);
927
        StockItemsUpdater stockUpdater = new StockItemsUpdater(new StockLabel() {
928
            @Override
929
            public String getLabel(SQLRowAccessor rowOrigin, SQLRowAccessor rowElt) {
930
                return getLibelleStock(rowOrigin, rowElt);
931
            }
93 ilm 932
        }, row, row.getReferentRows(getTable().getTable("COMMANDE_CLIENT_ELEMENT")), TypeStockUpdate.VIRTUAL_DELIVER);
83 ilm 933
 
934
        stockUpdater.update();
935
    }
936
 
18 ilm 937
    public void setDefaults() {
938
        this.resetValue();
90 ilm 939
        this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), new Date()));
18 ilm 940
        this.table.getModel().clearRows();
941
    }
942
 
943
    /**
944
     * Création d'une commande à partir d'un devis
945
     *
946
     * @param idDevis
947
     *
948
     */
949
    public void loadDevis(int idDevis) {
950
 
951
        SQLElement devis = Configuration.getInstance().getDirectory().getElement("DEVIS");
952
        SQLElement devisElt = Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT");
953
 
954
        if (idDevis > 1) {
955
            SQLInjector injector = SQLInjector.getInjector(devis.getTable(), this.getTable());
19 ilm 956
            SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(idDevis);
957
            SQLRow rowDevis = devis.getTable().getRow(idDevis);
958
 
959
            String string = rowDevis.getString("OBJET");
960
            createRowValuesFrom.put("NOM", string + (string.trim().length() == 0 ? "" : ",") + rowDevis.getString("NUMERO"));
961
            this.select(createRowValuesFrom);
18 ilm 962
        }
963
 
964
        loadItem(this.table, devis, idDevis, devisElt);
965
    }
966
 
967
    @Override
968
    protected SQLRowValues createDefaults() {
969
        SQLRowValues rowVals = new SQLRowValues(getTable());
970
        rowVals.put("T_POIDS", 0.0F);
90 ilm 971
        rowVals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), new Date()));
18 ilm 972
        // User
973
        // SQLSelect sel = new SQLSelect(Configuration.getInstance().getBase());
974
        SQLElement eltComm = Configuration.getInstance().getDirectory().getElement("COMMERCIAL");
975
        int idUser = UserManager.getInstance().getCurrentUser().getId();
976
        //
977
        // sel.addSelect(eltComm.getTable().getKey());
978
        // sel.setWhere(new Where(eltComm.getTable().getField("ID_USER_COMMON"), "=", idUser));
979
        // List<SQLRow> rowsComm = (List<SQLRow>)
980
        // Configuration.getInstance().getBase().getDataSource().execute(sel.asString(), new
981
        // SQLRowListRSH(eltComm.getTable()));
982
        SQLRow rowsComm = SQLBackgroundTableCache.getInstance().getCacheForTable(eltComm.getTable()).getFirstRowContains(idUser, eltComm.getTable().getField("ID_USER_COMMON"));
983
 
984
        if (rowsComm != null) {
985
            rowVals.put("ID_COMMERCIAL", rowsComm.getID());
986
        }
93 ilm 987
        if (getTable().contains("ETAT_COMMANDE")) {
988
            rowVals.put("ETAT_COMMANDE", EtatCommandeClient.A_PREPARER.getId());
989
        }
990
        if (getTable().contains("ID_TAXE_PORT")) {
991
            SQLRow taxeDefault = TaxeCache.getCache().getFirstTaxe();
992
            rowVals.put("ID_TAXE_PORT", taxeDefault.getID());
993
        }
994
 
156 ilm 995
        if (getTable().contains("ID_TAXE_FRAIS_DOCUMENT")) {
996
            SQLRow taxeDefault = TaxeCache.getCache().getFirstTaxe();
997
            rowVals.put("ID_TAXE_FRAIS_DOCUMENT", taxeDefault.getID());
998
        }
999
 
18 ilm 1000
        return rowVals;
1001
    }
93 ilm 1002
 
1003
    @Override
1004
    protected void refreshAfterSelect(SQLRowAccessor r) {
1005
        if (this.dateCommande.getValue() != null && r.getObject("DATE") != null) {
1006
            this.table.setDateDevise(r.getDate("DATE").getTime());
1007
        }
1008
    }
18 ilm 1009
}