OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 21 | Rev 28 | Go to most recent revision | 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.shipment.component;
15
 
16
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
17
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
18
import org.openconcerto.erp.core.common.ui.DeviseField;
19
import org.openconcerto.erp.core.sales.invoice.element.SaisieVenteFactureItemSQLElement;
20
import org.openconcerto.erp.core.sales.shipment.element.BonDeLivraisonItemSQLElement;
21
import org.openconcerto.erp.core.sales.shipment.element.BonDeLivraisonSQLElement;
22
import org.openconcerto.erp.core.sales.shipment.report.BonLivraisonXmlSheet;
23
import org.openconcerto.erp.core.sales.shipment.ui.BonDeLivraisonItemTable;
21 ilm 24
import org.openconcerto.erp.panel.PanelOOSQLComponent;
18 ilm 25
import org.openconcerto.erp.preferences.DefaultNXProps;
26
import org.openconcerto.sql.Configuration;
27
import org.openconcerto.sql.element.SQLElement;
28
import org.openconcerto.sql.model.SQLInjector;
29
import org.openconcerto.sql.model.SQLRow;
30
import org.openconcerto.sql.model.SQLRowAccessor;
31
import org.openconcerto.sql.model.SQLRowValues;
32
import org.openconcerto.sql.model.SQLSelect;
33
import org.openconcerto.sql.model.SQLTable;
34
import org.openconcerto.sql.sqlobject.ElementComboBox;
35
import org.openconcerto.sql.sqlobject.JUniqueTextField;
36
import org.openconcerto.sql.view.EditFrame;
37
import org.openconcerto.sql.view.list.RowValuesTableModel;
38
import org.openconcerto.ui.DefaultGridBagConstraints;
25 ilm 39
import org.openconcerto.ui.FormLayouter;
18 ilm 40
import org.openconcerto.ui.JDate;
41
import org.openconcerto.ui.JLabelBold;
42
import org.openconcerto.ui.TitledSeparator;
43
import org.openconcerto.ui.component.ITextArea;
44
import org.openconcerto.ui.preferences.DefaultProps;
45
import org.openconcerto.utils.ExceptionHandler;
46
import org.openconcerto.utils.GestionDevise;
47
 
48
import java.awt.Color;
49
import java.awt.GridBagConstraints;
50
import java.awt.GridBagLayout;
51
import java.awt.Insets;
52
import java.awt.event.ActionEvent;
53
import java.awt.event.ActionListener;
19 ilm 54
import java.beans.PropertyChangeEvent;
55
import java.beans.PropertyChangeListener;
18 ilm 56
import java.sql.SQLException;
57
import java.util.ArrayList;
58
import java.util.List;
59
 
60
import javax.swing.JButton;
61
import javax.swing.JLabel;
19 ilm 62
import javax.swing.JOptionPane;
18 ilm 63
import javax.swing.JPanel;
64
import javax.swing.JScrollPane;
65
import javax.swing.JSeparator;
66
import javax.swing.JTextField;
67
import javax.swing.SwingConstants;
68
import javax.swing.SwingUtilities;
69
import javax.swing.event.TableModelEvent;
70
import javax.swing.event.TableModelListener;
71
 
72
import org.apache.commons.dbutils.handlers.ArrayListHandler;
73
 
74
public class BonDeLivraisonSQLComponent extends TransfertBaseSQLComponent {
75
    private BonDeLivraisonItemTable tableBonItem;
76
    private ElementComboBox selectCommande, comboClient;
21 ilm 77
    private PanelOOSQLComponent panelOO;
18 ilm 78
    private JUniqueTextField textNumeroUnique;
79
    private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
80
    private final DeviseField textTotalHT = new DeviseField(6);
81
    private final DeviseField textTotalTVA = new DeviseField(6);
82
    private final DeviseField textTotalTTC = new DeviseField(6);
83
    private final JTextField textPoidsTotal = new JTextField(6);
84
    private final JTextField textNom = new JTextField(25);
85
 
86
    public BonDeLivraisonSQLComponent() {
87
        super(Configuration.getInstance().getDirectory().getElement("BON_DE_LIVRAISON"));
88
    }
89
 
90
    @Override
91
    protected SQLRowValues createDefaults() {
92
        this.textNumeroUnique.setText(NumerotationAutoSQLElement.getNextNumero(BonDeLivraisonSQLElement.class));
93
        this.tableBonItem.getModel().clearRows();
94
        return super.createDefaults();
95
    }
96
 
97
    public void addViews() {
98
        this.textTotalHT.setOpaque(false);
99
        this.textTotalTVA.setOpaque(false);
100
        this.textTotalTTC.setOpaque(false);
101
 
102
        this.selectCommande = new ElementComboBox();
103
 
104
        this.setLayout(new GridBagLayout());
105
 
106
        final GridBagConstraints c = new DefaultGridBagConstraints();
107
 
25 ilm 108
        // Champ Module
109
        c.gridx = 0;
110
        c.gridy++;
111
        c.gridwidth = GridBagConstraints.REMAINDER;
112
        final JPanel addP = new JPanel();
113
        this.setAdditionalFieldsPanel(new FormLayouter(addP, 1));
114
        this.add(addP, c);
115
 
116
        c.gridy++;
117
        c.gridwidth = 1;
118
 
18 ilm 119
        // Numero
120
        JLabel labelNum = new JLabel(getLabelFor("NUMERO"));
121
        labelNum.setHorizontalAlignment(SwingConstants.RIGHT);
122
        this.add(labelNum, c);
123
 
124
        this.textNumeroUnique = new JUniqueTextField(16);
125
        c.gridx++;
126
        c.weightx = 1;
127
        c.weighty = 0;
128
        c.fill = GridBagConstraints.NONE;
129
        DefaultGridBagConstraints.lockMinimumSize(textNumeroUnique);
130
        this.add(this.textNumeroUnique, c);
131
 
132
        // Date
133
        c.gridx++;
134
        c.fill = GridBagConstraints.HORIZONTAL;
135
        c.weightx = 0;
136
        this.add(new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT), c);
137
 
138
        JDate date = new JDate(true);
139
        c.gridx++;
140
        c.weightx = 0;
141
        c.weighty = 0;
142
        c.fill = GridBagConstraints.NONE;
143
        this.add(date, c);
144
 
145
        // Reference
146
        c.gridy++;
147
        c.gridx = 0;
148
        c.fill = GridBagConstraints.HORIZONTAL;
149
        this.add(new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT), c);
150
        c.gridx++;
151
        c.weightx = 1;
152
        this.add(this.textNom, c);
153
 
154
        // Client
155
        JLabel labelClient = new JLabel(getLabelFor("ID_CLIENT"));
156
        labelClient.setHorizontalAlignment(SwingConstants.RIGHT);
157
        c.gridx = 0;
158
        c.gridy++;
159
        c.weightx = 0;
160
        c.weighty = 0;
161
        this.add(labelClient, c);
162
 
163
        c.gridx++;
164
        c.weightx = 0;
165
        c.weighty = 0;
166
        c.fill = GridBagConstraints.NONE;
167
        this.comboClient = new ElementComboBox();
168
 
169
        this.add(this.comboClient, c);
19 ilm 170
        final ElementComboBox boxTarif = new ElementComboBox();
171
        this.comboClient.addValueListener(new PropertyChangeListener() {
18 ilm 172
 
19 ilm 173
            @Override
174
            public void propertyChange(PropertyChangeEvent evt) {
175
                if (comboClient.getValue() != null) {
176
                    Integer id = comboClient.getValue();
177
 
178
                    if (id > 1) {
179
 
180
                        SQLRow row = comboClient.getElement().getTable().getRow(id);
181
                        if (comboClient.getElement().getTable().getFieldsName().contains("ID_TARIF")) {
182
 
183
                            // SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
184
                            // if (foreignRow.isUndefined() &&
185
                            // !row.getForeignRow("ID_DEVISE").isUndefined()) {
186
                            // SQLRowValues rowValsD = new SQLRowValues(foreignRow.getTable());
187
                            // rowValsD.put("ID_DEVISE", row.getObject("ID_DEVISE"));
188
                            // foreignRow = rowValsD;
189
                            //
190
                            // }
191
                            // tableBonItem.setTarif(foreignRow, true);
192
                            SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
193
                            if (!foreignRow.isUndefined() && (boxTarif.getSelectedRow() == null || boxTarif.getSelectedId() != foreignRow.getID())
194
                                    && JOptionPane.showConfirmDialog(null, "Appliquer les tarifs associés au client?") == JOptionPane.YES_OPTION) {
195
                                boxTarif.setValue(foreignRow.getID());
196
                                // SaisieVenteFactureSQLComponent.this.tableFacture.setTarif(foreignRow,
197
                                // true);
198
                            } else {
199
                                boxTarif.setValue(foreignRow.getID());
200
                            }
201
                        }
202
                    }
203
                }
204
 
205
            }
206
        });
207
 
18 ilm 208
        // Bouton tout livrer
209
        JButton boutonAll = new JButton("Tout livrer");
210
 
211
        boutonAll.addActionListener(new ActionListener() {
212
            public void actionPerformed(ActionEvent e) {
213
                RowValuesTableModel m = BonDeLivraisonSQLComponent.this.tableBonItem.getModel();
214
 
215
                // on livre tout les éléments
216
                for (int i = 0; i < m.getRowCount(); i++) {
217
                    SQLRowValues rowVals = m.getRowValuesAt(i);
218
                    Object o = rowVals.getObject("QTE");
219
                    int qte = o == null ? 0 : ((Number) o).intValue();
220
                    m.putValue(qte, i, "QTE_LIVREE");
221
                }
222
            }
223
        });
224
 
19 ilm 225
        // Tarif
226
        if (this.getTable().getFieldsName().contains("ID_TARIF")) {
227
            // TARIF
228
            c.gridy++;
229
            c.gridx = 0;
230
            c.weightx = 0;
231
            c.weighty = 0;
232
            c.gridwidth = 1;
233
            this.add(new JLabel("Tarif à appliquer"), c);
234
            c.gridx++;
235
            c.gridwidth = GridBagConstraints.REMAINDER;
236
 
237
            c.weightx = 1;
238
            this.add(boxTarif, c);
239
            this.addView(boxTarif, "ID_TARIF");
240
            boxTarif.addValueListener(new PropertyChangeListener() {
241
 
242
                @Override
243
                public void propertyChange(PropertyChangeEvent evt) {
244
                    tableBonItem.setTarif(boxTarif.getSelectedRow(), false);
245
                }
246
            });
247
        }
18 ilm 248
        // Element du bon
249
        List<JButton> l = new ArrayList<JButton>();
250
        l.add(boutonAll);
251
        this.tableBonItem = new BonDeLivraisonItemTable(l);
252
 
253
        c.gridx = 0;
254
        c.gridy++;
255
        c.weightx = 1;
256
        c.weighty = 1;
257
        c.gridwidth = GridBagConstraints.REMAINDER;
258
        c.fill = GridBagConstraints.BOTH;
259
        this.add(this.tableBonItem, c);
260
        c.anchor = GridBagConstraints.EAST;
261
        // Totaux
262
        reconfigure(this.textTotalHT);
263
        reconfigure(this.textTotalTVA);
264
        reconfigure(this.textTotalTTC);
265
 
266
        // Poids Total
267
        c.gridy++;
268
        c.gridx = 1;
269
        c.weightx = 0;
270
        c.weighty = 0;
271
        c.anchor = GridBagConstraints.EAST;
272
        c.gridwidth = 1;
273
        c.fill = GridBagConstraints.NONE;
274
 
275
        DefaultProps props = DefaultNXProps.getInstance();
276
        Boolean b = props.getBooleanValue("ArticleShowPoids");
277
        if (b) {
278
            JPanel panelPoids = new JPanel();
279
            final JLabel labelPoids = new JLabel(getLabelFor("TOTAL_POIDS"));
280
            panelPoids.add(labelPoids);
281
            this.textPoidsTotal.setEnabled(false);
282
            this.textPoidsTotal.setHorizontalAlignment(JTextField.RIGHT);
283
            this.textPoidsTotal.setDisabledTextColor(Color.BLACK);
284
            panelPoids.add(this.textPoidsTotal);
285
 
286
            this.textPoidsTotal.setVisible(b);
287
            labelPoids.setVisible(b);
288
            DefaultGridBagConstraints.lockMinimumSize(panelPoids);
289
            this.add(panelPoids, c);
290
        }
291
        c.gridx = 2;
292
        c.gridwidth = GridBagConstraints.REMAINDER;
293
        c.weightx = 0;
294
        c.weighty = 0;
295
        c.anchor = GridBagConstraints.EAST;
296
        c.fill = GridBagConstraints.HORIZONTAL;
297
 
298
        final GridBagConstraints cTotalPan = new DefaultGridBagConstraints();
299
 
300
        JPanel panelTotalHT = new JPanel();
301
        panelTotalHT.setLayout(new GridBagLayout());
302
        cTotalPan.gridx = 0;
303
        cTotalPan.anchor = GridBagConstraints.WEST;
304
        cTotalPan.weightx = 0;
305
        final JLabelBold labelTotalHT = new JLabelBold(getLabelFor("TOTAL_HT"));
306
        panelTotalHT.add(labelTotalHT, cTotalPan);
307
        cTotalPan.anchor = GridBagConstraints.EAST;
308
        cTotalPan.gridx++;
309
        cTotalPan.weightx = 1;
310
        textTotalHT.setFont(labelTotalHT.getFont());
311
        panelTotalHT.add(this.textTotalHT, cTotalPan);
312
        this.add(panelTotalHT, c);
313
 
314
        JPanel panelTotalTVA = new JPanel();
315
        panelTotalTVA.setLayout(new GridBagLayout());
316
        cTotalPan.gridx = 0;
317
        cTotalPan.anchor = GridBagConstraints.WEST;
318
        cTotalPan.weightx = 0;
319
        panelTotalTVA.add(new JLabelBold(getLabelFor("TOTAL_TVA")), cTotalPan);
320
        cTotalPan.anchor = GridBagConstraints.EAST;
321
        cTotalPan.gridx++;
322
        cTotalPan.weightx = 1;
323
        panelTotalTVA.add(this.textTotalTVA, cTotalPan);
324
        c.gridy++;
325
        this.add(panelTotalTVA, c);
326
 
327
        JPanel panelTotalTTC = new JPanel();
328
        panelTotalTTC.setLayout(new GridBagLayout());
329
        cTotalPan.gridx = 0;
330
        cTotalPan.anchor = GridBagConstraints.WEST;
331
        cTotalPan.gridwidth = GridBagConstraints.REMAINDER;
332
        cTotalPan.fill = GridBagConstraints.BOTH;
333
 
334
        panelTotalTTC.add(new JSeparator(), cTotalPan);
335
        cTotalPan.gridwidth = 1;
336
        cTotalPan.fill = GridBagConstraints.HORIZONTAL;
337
        cTotalPan.weightx = 0;
338
        cTotalPan.gridy++;
339
        panelTotalTTC.add(new JLabelBold(getLabelFor("TOTAL_TTC")), cTotalPan);
340
        cTotalPan.anchor = GridBagConstraints.EAST;
341
        cTotalPan.gridx++;
342
        cTotalPan.weightx = 1;
343
        textTotalTTC.setFont(labelTotalHT.getFont());
344
        panelTotalTTC.add(this.textTotalTTC, cTotalPan);
345
        c.gridy++;
346
        this.add(panelTotalTTC, c);
347
        c.anchor = GridBagConstraints.WEST;
348
 
349
        /*******************************************************************************************
350
         * * INFORMATIONS COMPLEMENTAIRES
351
         ******************************************************************************************/
352
        c.gridwidth = GridBagConstraints.REMAINDER;
353
        c.weightx = 1;
354
        c.fill = GridBagConstraints.HORIZONTAL;
355
        c.gridx = 0;
356
        c.gridy++;
357
        TitledSeparator sep = new TitledSeparator("Informations complémentaires");
358
        c.insets = new Insets(10, 2, 1, 2);
359
        this.add(sep, c);
360
        c.insets = new Insets(2, 2, 1, 2);
361
 
362
        ITextArea textInfos = new ITextArea(4, 4);
363
 
364
        c.gridx = 0;
365
        c.gridy++;
366
        c.gridheight = 1;
367
        c.gridwidth = GridBagConstraints.REMAINDER;
368
        c.weightx = 1;
369
        c.weighty = 0;
370
        c.fill = GridBagConstraints.BOTH;
371
 
372
        final JScrollPane scrollPane = new JScrollPane(textInfos);
373
        this.add(scrollPane, c);
374
        textInfos.setBorder(null);
375
        DefaultGridBagConstraints.lockMinimumSize(scrollPane);
376
 
377
        c.gridx = 0;
378
        c.gridy++;
379
        c.gridheight = 1;
380
        c.gridwidth = 4;
381
        c.weightx = 0;
382
        c.weighty = 0;
383
        c.fill = GridBagConstraints.NONE;
384
        c.anchor = GridBagConstraints.EAST;
385
 
21 ilm 386
        this.panelOO = new PanelOOSQLComponent(this);
387
        this.add(this.panelOO, c);
388
 
18 ilm 389
        this.addRequiredSQLObject(date, "DATE");
390
        this.addSQLObject(textInfos, "INFOS");
391
        this.addSQLObject(this.textNom, "NOM");
392
        this.addSQLObject(this.selectCommande, "ID_COMMANDE_CLIENT");
393
        this.addRequiredSQLObject(this.textNumeroUnique, "NUMERO");
394
        this.addSQLObject(this.textPoidsTotal, "TOTAL_POIDS");
395
        this.addRequiredSQLObject(this.textTotalHT, "TOTAL_HT");
396
        this.addRequiredSQLObject(this.textTotalTVA, "TOTAL_TVA");
397
        this.addRequiredSQLObject(this.textTotalTTC, "TOTAL_TTC");
398
        this.addRequiredSQLObject(this.comboClient, "ID_CLIENT");
399
 
400
        this.tableBonItem.getModel().addTableModelListener(new TableModelListener() {
401
            public void tableChanged(TableModelEvent e) {
402
 
403
                int columnIndexHT = BonDeLivraisonSQLComponent.this.tableBonItem.getModel().getColumnIndexForElement(BonDeLivraisonSQLComponent.this.tableBonItem.getPrixTotalHTElement());
404
                int columnIndexTTC = BonDeLivraisonSQLComponent.this.tableBonItem.getModel().getColumnIndexForElement(BonDeLivraisonSQLComponent.this.tableBonItem.getPrixTotalTTCElement());
405
                int columnIndexPoids = BonDeLivraisonSQLComponent.this.tableBonItem.getModel().getColumnIndexForElement(BonDeLivraisonSQLComponent.this.tableBonItem.getPoidsTotalElement());
406
 
407
                if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == columnIndexHT || e.getColumn() == columnIndexTTC) {
408
                    updateTotal();
409
                }
410
                if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == columnIndexPoids) {
411
                    BonDeLivraisonSQLComponent.this.textPoidsTotal.setText(String.valueOf(Math.round(BonDeLivraisonSQLComponent.this.tableBonItem.getPoidsTotal() * 1000) / 1000.0));
412
                }
413
            }
414
        });
415
        // Doit etre locké a la fin
416
        DefaultGridBagConstraints.lockMinimumSize(comboClient);
417
 
418
    }
419
 
420
    private void reconfigure(JTextField field) {
421
        field.setEnabled(false);
422
        field.setHorizontalAlignment(JTextField.RIGHT);
423
        field.setDisabledTextColor(Color.BLACK);
424
        field.setBorder(null);
425
    }
426
 
427
    public int insert(SQLRow order) {
428
 
429
        int idBon = getSelectedID();
430
        // on verifie qu'un bon du meme numero n'a pas été inséré entre temps
431
        if (this.textNumeroUnique.checkValidation()) {
432
            idBon = super.insert(order);
433
            this.tableBonItem.updateField("ID_BON_DE_LIVRAISON", idBon);
434
            this.tableBonItem.createArticle(idBon, this.getElement());
435
 
436
            // generation du document
437
            BonLivraisonXmlSheet bSheet = new BonLivraisonXmlSheet(getTable().getRow(idBon));
25 ilm 438
            bSheet.createDocumentAsynchronous();
439
            bSheet.showPrintAndExportAsynchronous(this.panelOO.isVisualisationSelected(), this.panelOO.isImpressionSelected(), true);
18 ilm 440
 
441
            // incrémentation du numéro auto
442
            if (NumerotationAutoSQLElement.getNextNumero(BonDeLivraisonSQLElement.class).equalsIgnoreCase(this.textNumeroUnique.getText().trim())) {
443
                SQLRowValues rowVals = new SQLRowValues(this.tableNum);
444
                int val = this.tableNum.getRow(2).getInt("BON_L_START");
445
                val++;
446
                rowVals.put("BON_L_START", new Integer(val));
447
 
448
                try {
449
                    rowVals.update(2);
450
                } catch (SQLException e) {
451
                    e.printStackTrace();
452
                }
453
            }
454
 
455
            // updateQte(idBon);
456
        } else {
457
            ExceptionHandler.handle("Impossible d'ajouter, numéro de bon de livraison existant.");
458
            Object root = SwingUtilities.getRoot(this);
459
            if (root instanceof EditFrame) {
460
                EditFrame frame = (EditFrame) root;
461
                frame.getPanel().setAlwaysVisible(true);
462
            }
463
        }
464
 
465
        return idBon;
466
    }
467
 
468
    @Override
469
    public void select(SQLRowAccessor r) {
470
        if (r != null) {
471
            this.textNumeroUnique.setIdSelected(r.getID());
472
        }
473
        super.select(r);
474
        if (r != null) {
475
            this.tableBonItem.insertFrom("ID_BON_DE_LIVRAISON", r.getID());
476
        }
477
    }
478
 
479
    @Override
480
    public void update() {
481
        if (!this.textNumeroUnique.checkValidation()) {
482
            ExceptionHandler.handle("Impossible d'ajouter, numéro de bon de livraison existant.");
483
            Object root = SwingUtilities.getRoot(this);
484
            if (root instanceof EditFrame) {
485
                EditFrame frame = (EditFrame) root;
486
                frame.getPanel().setAlwaysVisible(true);
487
            }
488
            return;
489
        }
490
        super.update();
491
        this.tableBonItem.updateField("ID_BON_DE_LIVRAISON", getSelectedID());
492
        this.tableBonItem.createArticle(getSelectedID(), this.getElement());
493
 
494
        // generation du document
495
        BonLivraisonXmlSheet bSheet = new BonLivraisonXmlSheet(getTable().getRow(getSelectedID()));
25 ilm 496
        bSheet.createDocumentAsynchronous();
497
        bSheet.showPrintAndExportAsynchronous(this.panelOO.isVisualisationSelected(), this.panelOO.isImpressionSelected(), true);
498
 
18 ilm 499
    }
500
 
501
    private void updateTotal() {
502
        RowValuesTableModel model = this.tableBonItem.getModel();
503
 
504
        long totalHT = 0;
505
        long totalTTC = 0;
506
        int columnIndexHT = model.getColumnIndexForElement(this.tableBonItem.getPrixTotalHTElement());
507
        int columnIndexTTC = model.getColumnIndexForElement(this.tableBonItem.getPrixTotalTTCElement());
508
 
509
        // columnIndexHT = model.getColumnIndexForElement(getTable().get);
510
        for (int i = 0; i < model.getRowCount(); i++) {
511
            Number nHT = (Number) model.getValueAt(i, columnIndexHT);
512
            totalHT += nHT.longValue();
513
 
514
            Number nTTC = (Number) model.getValueAt(i, columnIndexTTC);
515
            totalTTC += nTTC.longValue();
516
        }
517
 
518
        this.textTotalHT.setText(GestionDevise.currencyToString(totalHT));
519
        this.textTotalTVA.setText(GestionDevise.currencyToString(totalTTC - totalHT));
520
        this.textTotalTTC.setText(GestionDevise.currencyToString(totalTTC));
521
    }
522
 
523
    /**
524
     * Chargement des éléments d'une commande dans la table
525
     *
526
     * @param idCommande
527
     *
528
     */
529
    public void loadCommande(int idCommande) {
530
 
531
        SQLElement commande = Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT");
532
        SQLElement commandeElt = Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT_ELEMENT");
533
 
534
        if (idCommande > 1) {
535
            SQLInjector injector = SQLInjector.getInjector(commande.getTable(), this.getTable());
19 ilm 536
            SQLRow rowCmd = commande.getTable().getRow(idCommande);
537
            SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(idCommande);
538
            String string = rowCmd.getString("NOM");
539
            createRowValuesFrom.put("NOM", string + (string.trim().length() == 0 ? "" : ",") + rowCmd.getString("NUMERO"));
540
            this.select(createRowValuesFrom);
18 ilm 541
        }
542
 
543
        loadItem(this.tableBonItem, commande, idCommande, commandeElt);
544
    }
545
 
546
    /**
547
     * Chargement des éléments d'une facture dans la table
548
     *
19 ilm 549
     * @param idFacture
550
     *
551
     */
552
    public void loadFacture(int idFacture) {
553
 
554
        SQLElement facture = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
555
        SQLElement factureElt = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE_ELEMENT");
556
 
557
        if (idFacture > 1) {
558
            SQLInjector injector = SQLInjector.getInjector(facture.getTable(), this.getTable());
559
            SQLRow rowFact = facture.getTable().getRow(idFacture);
560
            SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(idFacture);
561
            String string = rowFact.getString("NOM");
562
            createRowValuesFrom.put("NOM", string + (string.trim().length() == 0 ? "" : ",") + rowFact.getString("NUMERO"));
563
            this.select(createRowValuesFrom);
564
        }
565
 
566
        loadItem(this.tableBonItem, facture, idFacture, factureElt);
567
 
568
    }
569
 
570
    /**
571
     * Chargement des éléments d'une facture dans la table
572
     *
18 ilm 573
     * @param idSaisieVenteFacture
574
     *
575
     */
576
    public void loadFactureItem(int idSaisieVenteFacture) {
577
        SQLElement facture = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
578
        SQLElement factureElt = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE_ELEMENT");
579
        loadItem(this.tableBonItem, facture, idSaisieVenteFacture, factureElt);
19 ilm 580
        for (int i = 0; i < this.tableBonItem.getRowValuesTable().getRowCount(); i++) {
581
            SQLRowValues rowVals = this.tableBonItem.getRowValuesTable().getRowValuesTableModel().getRowValuesAt(i);
582
            this.tableBonItem.getRowValuesTable().getRowValuesTableModel().putValue(rowVals.getObject("QTE"), i, "QTE_LIVREE");
583
        }
18 ilm 584
    }
585
 
586
    /***********************************************************************************************
587
     * Mise à jour des quantités livrées dans les élements de facture
588
     *
589
     * @param idBon id du bon de livraison
590
     */
591
    public void updateQte(int idBon) {
592
 
593
        SQLTable tableFactureElem = new SaisieVenteFactureItemSQLElement().getTable();
594
        SQLSelect selBonItem = new SQLSelect(getTable().getBase());
595
        BonDeLivraisonItemSQLElement bonElt = new BonDeLivraisonItemSQLElement();
596
        selBonItem.addSelect(bonElt.getTable().getField("ID_SAISIE_VENTE_FACTURE_ELEMENT"));
597
        selBonItem.addSelect(bonElt.getTable().getField("QTE_LIVREE"));
598
        selBonItem.setWhere("BON_DE_LIVRAISON_ELEMENT.ID_BON_DE_LIVRAISON", "=", idBon);
599
 
600
        String reqBonItem = selBonItem.asString();
601
        Object obBonItem = getTable().getBase().getDataSource().execute(reqBonItem, new ArrayListHandler());
602
 
603
        final List<Object[]> myListBonItem = (List<Object[]>) obBonItem;
604
        final int size = myListBonItem.size();
605
        try {
606
            for (int i = 0; i < size; i++) {
607
                final Object[] objTmp = myListBonItem.get(i);
608
                final SQLRow rowFactElem = tableFactureElem.getRow(((Number) objTmp[0]).intValue());
609
                final SQLRowValues rowVals = new SQLRowValues(tableFactureElem);
610
                rowVals.put("QTE_LIVREE", Integer.valueOf(rowFactElem.getInt("QTE_LIVREE") + ((Number) objTmp[1]).intValue()));
611
                rowVals.update(rowFactElem.getID());
612
            }
613
        } catch (SQLException e) {
614
            e.printStackTrace();
615
        }
616
 
617
    }
618
 
619
    /***********************************************************************************************
620
     * Mise à jour des quantités livrées dans les élements de facture
621
     *
622
     * @param idBon id du bon de livraison
623
     */
624
    public void cancelUpdateQte(int idBon) {
625
 
626
        SQLTable tableFactureElem = new SaisieVenteFactureItemSQLElement().getTable();
627
        SQLSelect selBonItem = new SQLSelect(getTable().getBase());
628
        BonDeLivraisonItemSQLElement bonElt = new BonDeLivraisonItemSQLElement();
629
        selBonItem.addSelect(bonElt.getTable().getField("ID_SAISIE_VENTE_FACTURE_ELEMENT"));
630
        selBonItem.addSelect(bonElt.getTable().getField("QTE_LIVREE"));
631
        selBonItem.setWhere("BON_DE_LIVRAISON_ELEMENT.ID_BON_DE_LIVRAISON", "=", idBon);
632
 
633
        String reqBonItem = selBonItem.asString();
634
        Object obBonItem = getTable().getBase().getDataSource().execute(reqBonItem, new ArrayListHandler());
635
 
636
        final List<Object[]> myListBonItem = (List<Object[]>) obBonItem;
637
        final int size = myListBonItem.size();
638
        try {
639
            for (int i = 0; i < size; i++) {
640
                final Object[] objTmp = myListBonItem.get(i);
641
                final SQLRow rowFactElem = tableFactureElem.getRow(((Number) objTmp[0]).intValue());
642
                final SQLRowValues rowVals = new SQLRowValues(tableFactureElem);
643
                rowVals.put("QTE_LIVREE", Integer.valueOf(((Number) objTmp[1]).intValue() - rowFactElem.getInt("QTE_LIVREE")));
644
                rowVals.update(rowFactElem.getID());
645
            }
646
        } catch (SQLException e) {
647
            e.printStackTrace();
648
        }
649
 
650
    }
651
 
652
}