OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | 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.common.ui;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
93 ilm 17
import org.openconcerto.erp.core.common.element.StyleSQLElement;
18
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
18 ilm 19
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
61 ilm 20
import org.openconcerto.erp.preferences.DefaultNXProps;
21
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
93 ilm 22
import org.openconcerto.erp.utils.TM;
18 ilm 23
import org.openconcerto.sql.Configuration;
24
import org.openconcerto.sql.element.SQLElement;
25
import org.openconcerto.sql.model.SQLField;
26
import org.openconcerto.sql.model.SQLRow;
19 ilm 27
import org.openconcerto.sql.model.SQLRowAccessor;
18 ilm 28
import org.openconcerto.sql.model.SQLRowValues;
156 ilm 29
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
18 ilm 30
import org.openconcerto.sql.model.SQLTable;
156 ilm 31
import org.openconcerto.sql.model.Where;
61 ilm 32
import org.openconcerto.sql.preferences.SQLPreferences;
93 ilm 33
import org.openconcerto.sql.view.list.AutoCompletionManager;
18 ilm 34
import org.openconcerto.sql.view.list.RowValuesTable;
35
import org.openconcerto.sql.view.list.RowValuesTableControlPanel;
36
import org.openconcerto.sql.view.list.RowValuesTableModel;
37
import org.openconcerto.sql.view.list.RowValuesTableRenderer;
38
import org.openconcerto.sql.view.list.SQLTableElement;
39
import org.openconcerto.ui.DefaultGridBagConstraints;
28 ilm 40
import org.openconcerto.ui.table.XTableColumnModel;
93 ilm 41
import org.openconcerto.utils.DecimalUtils;
83 ilm 42
import org.openconcerto.utils.ExceptionHandler;
18 ilm 43
 
44
import java.awt.GridBagConstraints;
45
import java.awt.GridBagLayout;
46
import java.io.File;
83 ilm 47
import java.math.BigDecimal;
48
import java.sql.SQLException;
49
import java.util.ArrayList;
93 ilm 50
import java.util.Collection;
142 ilm 51
import java.util.Collections;
18 ilm 52
import java.util.Date;
53
import java.util.List;
93 ilm 54
import java.util.Map;
18 ilm 55
import java.util.Set;
56
 
142 ilm 57
import javax.swing.AbstractAction;
18 ilm 58
import javax.swing.JButton;
93 ilm 59
import javax.swing.JOptionPane;
18 ilm 60
import javax.swing.JPanel;
61
import javax.swing.JScrollPane;
65 ilm 62
import javax.swing.ScrollPaneConstants;
18 ilm 63
 
64
public abstract class AbstractArticleItemTable extends JPanel {
65
    protected RowValuesTable table;
67 ilm 66
    protected SQLTableElement totalHT, totalHA;
61 ilm 67
    protected SQLTableElement tableElementTVA;
18 ilm 68
    protected SQLTableElement tableElementTotalTTC;
19 ilm 69
    protected SQLTableElement tableElementTotalDevise;
18 ilm 70
    protected SQLTableElement service, qte, ha;
71
    protected SQLTableElement tableElementPoidsTotal;
142 ilm 72
    protected SQLTableElement tableElementEcoID, tableElementEco, tableElementEcoTotal;
61 ilm 73
    protected SQLTableElement prebilan;
156 ilm 74
    protected SQLRowAccessor rowCatComptable;
93 ilm 75
    private RowValuesTableModel model;
18 ilm 76
    protected SQLRowValues defaultRowVals;
77
    private List<JButton> buttons = null;
78
    protected RowValuesTableControlPanel control = null;
19 ilm 79
    private SQLRowAccessor tarif = null;
18 ilm 80
 
142 ilm 81
    public static String SHOW_TOTAL_ECO_CONTRIBUTION = "SHOW_TOTAL_ECO_CONTRIBUTION";
82
    public static String SHOW_ECO_CONTRIBUTION_COLUMNS = "SHOW_ECO_CONTRIBUTION_COLUMNS";
83
 
93 ilm 84
    private Date dateDevise = new Date();
85
    private boolean usedBiasedDevise = true;
86
 
18 ilm 87
    public AbstractArticleItemTable() {
93 ilm 88
        this(null);
18 ilm 89
    }
90
 
91
    public AbstractArticleItemTable(List<JButton> buttons) {
92
        this.buttons = buttons;
93
        init();
94
        uiInit();
95
    }
96
 
156 ilm 97
    public void setRowCatComptable(SQLRowAccessor rowCatComptable) {
98
        this.rowCatComptable = rowCatComptable;
99
    }
100
 
18 ilm 101
    /**
102
     *
103
     */
104
    abstract protected void init();
105
 
93 ilm 106
    protected void setModel(RowValuesTableModel model) {
107
        this.model = model;
108
 
109
    }
110
 
111
    public boolean isUsedBiasedDevise() {
112
        return usedBiasedDevise;
113
    }
114
 
115
    public void setUsedBiasedDevise(boolean usedBiasedDevise) {
116
        this.usedBiasedDevise = usedBiasedDevise;
117
    }
118
 
119
    public void setDateDevise(Date dateDevise) {
120
        if (dateDevise != null) {
121
            this.dateDevise = dateDevise;
122
            refreshDeviseAmount();
123
        }
124
    }
125
 
126
    public Date getDateDevise() {
127
        return dateDevise;
128
    }
129
 
130
    protected abstract void refreshDeviseAmount();
131
 
18 ilm 132
    protected File getConfigurationFile() {
133
        return new File(Configuration.getInstance().getConfDir(), "Table/" + getConfigurationFileName());
134
    }
135
 
136
    /**
137
     *
138
     */
139
    protected void uiInit() {
140
        // Ui init
141
        setLayout(new GridBagLayout());
61 ilm 142
        this.setOpaque(false);
18 ilm 143
        final GridBagConstraints c = new DefaultGridBagConstraints();
144
 
145
        c.weightx = 1;
146
 
147
        control = new RowValuesTableControlPanel(this.table, this.buttons);
61 ilm 148
        control.setOpaque(false);
18 ilm 149
        this.add(control, c);
150
 
151
        c.gridy++;
152
        c.fill = GridBagConstraints.BOTH;
153
        c.weightx = 1;
154
        c.weighty = 1;
155
        final JScrollPane comp = new JScrollPane(this.table);
65 ilm 156
        comp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
18 ilm 157
        this.add(comp, c);
158
        this.table.setDefaultRenderer(Long.class, new RowValuesTableRenderer());
159
    }
160
 
161
    /**
162
     * @return the coniguration file to store pref
163
     */
164
    protected abstract String getConfigurationFileName();
165
 
166
    public abstract SQLElement getSQLElement();
167
 
168
    public void updateField(final String field, final int id) {
169
        this.table.updateField(field, id);
170
    }
171
 
172
    public RowValuesTable getRowValuesTable() {
173
        return this.table;
174
    }
175
 
176
    public void insertFrom(final String field, final int id) {
177
        this.table.insertFrom(field, id);
178
 
179
    }
180
 
181
    public RowValuesTableModel getModel() {
182
        return this.table.getRowValuesTableModel();
183
    }
184
 
61 ilm 185
    public SQLTableElement getPrebilanElement() {
186
        return this.prebilan;
187
    }
188
 
18 ilm 189
    public SQLTableElement getPrixTotalHTElement() {
190
        return this.totalHT;
191
    }
192
 
193
    public SQLTableElement getPoidsTotalElement() {
194
        return this.tableElementPoidsTotal;
195
    }
196
 
197
    public SQLTableElement getPrixTotalTTCElement() {
198
        return this.tableElementTotalTTC;
199
    }
200
 
201
    public SQLTableElement getPrixServiceElement() {
202
        return this.service;
203
    }
204
 
205
    public SQLTableElement getQteElement() {
206
        return this.qte;
207
    }
208
 
209
    public SQLTableElement getHaElement() {
210
        return this.ha;
211
    }
212
 
67 ilm 213
    public SQLTableElement getTotalHaElement() {
214
        return this.totalHA;
215
    }
216
 
61 ilm 217
    public SQLTableElement getTVAElement() {
218
        return this.tableElementTVA;
219
    }
220
 
19 ilm 221
    public SQLTableElement getTableElementTotalDevise() {
222
        return this.tableElementTotalDevise;
223
    }
224
 
142 ilm 225
    public SQLTableElement getTableElementTotalEco() {
226
        return this.tableElementEcoTotal;
227
    }
228
 
18 ilm 229
    public void deplacerDe(final int inc) {
230
        final int rowIndex = this.table.getSelectedRow();
231
 
232
        final int dest = this.model.moveBy(rowIndex, inc);
233
        this.table.getSelectionModel().setSelectionInterval(dest, dest);
234
    }
235
 
236
    /**
83 ilm 237
     * @return le poids total de tous les éléments (niveau 1) du tableau
18 ilm 238
     */
239
    public float getPoidsTotal() {
240
 
241
        float poids = 0.0F;
242
        final int poidsTColIndex = this.model.getColumnIndexForElement(this.tableElementPoidsTotal);
243
        if (poidsTColIndex >= 0) {
244
            for (int i = 0; i < this.table.getRowCount(); i++) {
245
                final Number tmp = (Number) this.model.getValueAt(i, poidsTColIndex);
90 ilm 246
                int level = 1;
247
                if (this.model.getRowValuesAt(i).getObject("NIVEAU") != null) {
248
                    level = this.model.getRowValuesAt(i).getInt("NIVEAU");
249
                }
250
                if (tmp != null && level == 1) {
18 ilm 251
                    poids += tmp.floatValue();
252
                }
253
            }
254
        }
255
        return poids;
256
    }
257
 
258
    public void refreshTable() {
259
        this.table.repaint();
260
    }
261
 
262
    public void createArticle(final int id, final SQLElement eltSource) {
263
 
264
        final SQLElement eltArticleTable = getSQLElement();
265
 
266
        final SQLTable tableArticle = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("ARTICLE");
267
 
61 ilm 268
        final boolean modeAvance = DefaultNXProps.getInstance().getBooleanValue("ArticleModeVenteAvance", false);
67 ilm 269
        SQLPreferences prefs = SQLPreferences.getMemCached(tableArticle.getDBRoot());
61 ilm 270
        final boolean createArticle = prefs.getBoolean(GestionArticleGlobalPreferencePanel.CREATE_ARTICLE_AUTO, true);
271
 
156 ilm 272
        if (createArticle) {
18 ilm 273
 
156 ilm 274
            SQLRowValues rowValsToFetch = new SQLRowValues(eltArticleTable.getTable());
275
            rowValsToFetch.putNulls(eltArticleTable.getTable().getFieldsName());
276
            SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsToFetch);
277
            Where w = new Where(eltArticleTable.getTable().getField("CODE"), "!=", "");
278
            w = w.and(new Where(eltArticleTable.getTable().getField("NOM"), "!=", ""));
279
            Where w2 = new Where(eltArticleTable.getTable().getField("ID_ARTICLE"), "!=", tableArticle.getUndefinedID());
280
            w2 = w2.or(new Where(eltArticleTable.getTable().getField("ID_ARTICLE"), "!=", (Object) null));
281
            final List<SQLRowValues> resultNonAssigned = fetcher.fetch(w.and(w2).and(new Where(eltArticleTable.getTable().getForeignKeys(eltSource.getTable()).iterator().next(), "=", id)));
18 ilm 282
 
156 ilm 283
            // On récupére les articles qui composent la table
284
            // final List<SQLRow> listElts =
285
            // eltSource.getTable().getRow(id).getReferentRows(eltArticleTable.getTable());
286
            final SQLRowValues rowArticle = new SQLRowValues(tableArticle);
287
            final Set<SQLField> fields = tableArticle.getFields();
18 ilm 288
 
156 ilm 289
            for (final SQLRowAccessor rowElt : resultNonAssigned) {
290
                // final SQLRow foreignRow = rowElt.getForeignRow("ID_ARTICLE");
291
                // if (foreignRow == null || foreignRow.isUndefined()) {
292
                final Set<String> fieldsName = rowElt.getTable().getFieldsName();
293
                // on récupére l'article qui lui correspond
294
 
295
                for (final SQLField field : fields) {
296
 
297
                    final String name = field.getName();
298
                    if (fieldsName.contains(name) && !field.isPrimaryKey()) {
299
                        rowArticle.put(name, rowElt.getObject(name));
300
                    }
18 ilm 301
                }
156 ilm 302
                // crée les articles si il n'existe pas
61 ilm 303
 
156 ilm 304
                int idArt = -1;
305
                if (modeAvance)
306
                    idArt = ReferenceArticleSQLElement.getIdForCNM(rowArticle, createArticle);
307
                else {
308
                    idArt = ReferenceArticleSQLElement.getIdForCN(rowArticle, createArticle);
83 ilm 309
                }
156 ilm 310
                if (createArticle && idArt > 1 && rowElt.isForeignEmpty("ID_ARTICLE")) {
311
                    try {
312
                        rowElt.createEmptyUpdateRow().put("ID_ARTICLE", idArt).update();
313
                    } catch (SQLException e) {
314
                        ExceptionHandler.handle("Erreur lors de l'affectation de l'article crée!", e);
315
                    }
316
                }
317
                // ReferenceArticleSQLElement.getIdForCNM(rowArticle, true);
83 ilm 318
            }
18 ilm 319
        }
28 ilm 320
        // }
18 ilm 321
    }
322
 
323
 
324
    public SQLRowValues getDefaultRowValues() {
325
        return this.defaultRowVals;
326
    }
19 ilm 327
 
328
    public SQLRowAccessor getTarif() {
329
        return tarif;
330
    }
331
 
332
    public void setTarif(SQLRowAccessor idTarif, boolean ask) {
333
        this.tarif = idTarif;
132 ilm 334
        // Test si ID_DEVISE est dans la table pour KD
335
        if (this.tarif != null && this.tarif.getTable().contains("ID_DEVISE") && !this.tarif.isForeignEmpty("ID_DEVISE") && this.defaultRowVals != null) {
94 ilm 336
            this.defaultRowVals.put("ID_DEVISE", this.tarif.getForeignID("ID_DEVISE"));
337
        }
19 ilm 338
    }
28 ilm 339
 
340
    protected void setColumnVisible(int col, boolean visible) {
341
        if (col >= 0) {
342
            XTableColumnModel columnModel = this.table.getColumnModel();
343
            columnModel.setColumnVisible(columnModel.getColumnByModelIndex(col), visible);
344
        }
345
    }
83 ilm 346
 
93 ilm 347
    protected void calculTarifNomenclature() {
83 ilm 348
 
93 ilm 349
        if (this.model.getRowCount() == 0) {
350
            return;
90 ilm 351
        }
93 ilm 352
        final int columnForField = this.model.getColumnForField("NIVEAU");
353
        if (columnForField >= 0) {
354
            checkNiveau();
355
 
356
            int rowCount = this.model.getRowCount();
357
 
358
            for (int niveau = 4; niveau > 1; niveau--) {
359
                int index = rowCount - 1;
360
 
361
                while (index > 0) {
362
 
363
                    BigDecimal prixUnitHT = BigDecimal.ZERO;
364
                    BigDecimal prixUnitHA = BigDecimal.ZERO;
365
 
366
                    boolean update = false;
367
                    int indexToUpdate = index;
368
                    // Calcul du sous total
369
                    for (int i = index; i >= 0; i--) {
370
                        indexToUpdate = i;
371
                        SQLRowValues rowVals = this.getRowValuesTable().getRowValuesTableModel().getRowValuesAt(i);
372
                        int niveauCourant = niveau;
373
                        if (rowVals.getObject("NIVEAU") != null) {
374
                            niveauCourant = rowVals.getInt("NIVEAU");
375
                        }
132 ilm 376
                        if (niveauCourant > 0) {
377
                            if (niveauCourant < niveau || niveauCourant == 1) {
378
                                break;
379
                            } else if (niveauCourant == niveau) {
380
                                update = true;
381
                                // Cumul des valeurs
382
                                prixUnitHT = prixUnitHT.add(rowVals.getBigDecimal("PV_HT").multiply(new BigDecimal(rowVals.getInt("QTE"))).multiply(rowVals.getBigDecimal("QTE_UNITAIRE")));
383
                                prixUnitHA = prixUnitHA.add(rowVals.getBigDecimal("PA_HT").multiply(new BigDecimal(rowVals.getInt("QTE"))).multiply(rowVals.getBigDecimal("QTE_UNITAIRE")));
384
                            }
93 ilm 385
                        }
386
                    }
387
                    if (update) {
388
                        final int columnForFieldHA = this.model.getColumnForField("PRIX_METRIQUE_HA_1");
389
                        if (columnForFieldHA >= 0) {
390
                            this.model.setValueAt(prixUnitHA, indexToUpdate, columnForFieldHA);
391
                        }
94 ilm 392
 
393
                        final int columnForFieldPVht1 = this.model.getColumnForField("PRIX_METRIQUE_VT_1");
394
                        if (columnForFieldPVht1 >= 0) {
395
                            this.model.setValueAt(prixUnitHT, indexToUpdate, columnForFieldPVht1);
93 ilm 396
                        }
397
                    }
398
                    index = indexToUpdate - 1;
83 ilm 399
                }
400
            }
93 ilm 401
        }
402
    }
83 ilm 403
 
93 ilm 404
    private void checkNiveau() {
83 ilm 405
 
93 ilm 406
        int n = this.model.getRowCount();
407
        final int columnForField = this.model.getColumnForField("NIVEAU");
408
        if (n > 0 && columnForField >= 0) {
94 ilm 409
            int start = 0;
410
            for (int i = 0; i < n; i++) {
411
                start = i;
412
                SQLRowValues rowVals = this.model.getRowValuesAt(i);
413
                if (rowVals.getObject("NIVEAU") == null || rowVals.getInt("NIVEAU") >= 1) {
414
                    this.model.setValueAt(1, i, columnForField);
415
                    break;
416
                }
93 ilm 417
            }
90 ilm 418
 
93 ilm 419
            // Dernier niveau correct autre que -1
94 ilm 420
            int lastGoodPrevious = this.model.getRowValuesAt(start).getInt("NIVEAU");
421
            for (int i = start + 1; i < n; i++) {
93 ilm 422
                // SQLRowValues rowValsPrev = this.model.getRowValuesAt(i - 1);
423
                SQLRowValues rowVals = this.model.getRowValuesAt(i);
424
                if (rowVals.getObject("NIVEAU") == null) {
425
                    this.model.setValueAt(1, i, columnForField);
426
                }
427
                // int niveauPrev = rowValsPrev.getInt("NIVEAU");
428
                int niveau = rowVals.getInt("NIVEAU");
429
                if (niveau != -1) {
90 ilm 430
 
93 ilm 431
                    if (niveau - lastGoodPrevious > 1) {
432
                        this.model.setValueAt(lastGoodPrevious, i, columnForField);
90 ilm 433
                    }
93 ilm 434
                    lastGoodPrevious = niveau;
83 ilm 435
                }
436
            }
437
        }
438
    }
439
 
440
    public List<SQLRowValues> getRowValuesAtLevel(int level) {
441
        final int rowCount = this.model.getRowCount();
442
        final List<SQLRowValues> result = new ArrayList<SQLRowValues>(rowCount);
443
        for (int i = 0; i < rowCount; i++) {
444
            final SQLRowValues row = this.model.getRowValuesAt(i);
445
            if (row.getObject("NIVEAU") == null || row.getInt("NIVEAU") == level) {
446
                result.add(row);
447
            }
448
        }
449
        return result;
450
    }
93 ilm 451
 
94 ilm 452
    public static enum EXPAND_TYPE {
453
        VIEW_ONLY, EXPAND, FLAT
454
    };
455
 
456
    public void expandNomenclature(int index, AutoCompletionManager m, final EXPAND_TYPE type) {
93 ilm 457
        SQLRowValues rowValsLineFather = this.model.getRowValuesAt(index);
458
        if (!rowValsLineFather.isForeignEmpty("ID_ARTICLE")) {
459
 
94 ilm 460
            if (type == EXPAND_TYPE.EXPAND) {
93 ilm 461
                int a1 = JOptionPane.showConfirmDialog(this.table, TM.tr("product.bom.expand.warning"), "Warning", JOptionPane.OK_CANCEL_OPTION);
462
                if (a1 != JOptionPane.YES_OPTION) {
463
                    return;
464
                }
94 ilm 465
            } else if (type == EXPAND_TYPE.FLAT) {
466
                int a1 = JOptionPane.showConfirmDialog(this.table, TM.tr("product.bom.flatexpand.warning"), "Warning", JOptionPane.OK_CANCEL_OPTION);
467
                if (a1 != JOptionPane.YES_OPTION) {
468
                    return;
469
                }
93 ilm 470
            }
94 ilm 471
 
93 ilm 472
            final int fatherLevel = rowValsLineFather.getInt("NIVEAU");
473
            // Test si il existe déjà des éléments d'un niveau inférieur dans le tableau
474
            if (index < table.getRowCount() - 1) {
475
                SQLRowValues rowValsLineNext = this.model.getRowValuesAt(index + 1);
476
                if (fatherLevel < rowValsLineNext.getInt("NIVEAU")) {
94 ilm 477
                    int a = JOptionPane.showConfirmDialog(this.table, "Cette ligne contient déjà des éléments d'un niveau inférieur. Êtes vous sûr de vouloir éclater la nomenclature?", "Nomenclature",
478
                            JOptionPane.YES_NO_OPTION);
93 ilm 479
                    if (a == JOptionPane.NO_OPTION) {
480
                        return;
481
                    }
482
                }
483
            }
484
 
485
            SQLRowAccessor rowValsArticleFather = rowValsLineFather.getForeign("ID_ARTICLE");
486
            // Elements composant la nomenclature
487
            Collection<? extends SQLRowAccessor> elts = rowValsArticleFather.getReferentRows(rowValsArticleFather.getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT"));
488
 
489
            if (elts.size() == 0) {
490
                JOptionPane.showMessageDialog(this.table, "Cet article ne contient aucun élément.");
491
            }
492
 
493
            List<? extends SQLRowAccessor> eltsList = new ArrayList<SQLRowAccessor>(elts);
94 ilm 494
            if (type == EXPAND_TYPE.FLAT) {
495
                this.model.putValue(-1, index, "NIVEAU");
496
                // this.model.putValue(allStyleByName.get("Composant"), index, "ID_STYLE");
497
            }
142 ilm 498
            Set<String> fieldsFrom = m.getFieldsFrom();
499
            fieldsFrom.remove("POURCENT_REMISE");
93 ilm 500
            for (int i = eltsList.size() - 1; i >= 0; i--) {
501
                SQLRowAccessor sqlRowArticleChildElement = eltsList.get(i);
502
                final SQLRowAccessor foreignArticleChild = sqlRowArticleChildElement.getForeign("ID_ARTICLE");
156 ilm 503
                if (foreignArticleChild != null && !foreignArticleChild.isUndefined()) {
504
                    final SQLRowValues row2Insert = new SQLRowValues(this.model.getDefaultRowValues());
93 ilm 505
 
156 ilm 506
                    m.fillRowValues(foreignArticleChild, fieldsFrom, row2Insert);
93 ilm 507
 
156 ilm 508
                    // Fill prix total
509
                    row2Insert.put("ID_ARTICLE", foreignArticleChild.getID());
93 ilm 510
 
156 ilm 511
                    row2Insert.put("CODE", foreignArticleChild.getObject("CODE"));
512
                    row2Insert.put("NOM", foreignArticleChild.getObject("NOM"));
93 ilm 513
 
156 ilm 514
                    if (type == EXPAND_TYPE.FLAT) {
515
                        row2Insert.put("QTE", sqlRowArticleChildElement.getInt("QTE") * rowValsLineFather.getInt("QTE"));
516
                    } else {
517
                        row2Insert.put("QTE", sqlRowArticleChildElement.getInt("QTE"));
518
                    }
519
                    if (row2Insert.getTable().contains("POURCENT_REMISE")) {
520
                        row2Insert.put("POURCENT_REMISE", BigDecimal.ZERO);
521
                        row2Insert.put("MONTANT_REMISE", BigDecimal.ZERO);
522
                    }
94 ilm 523
 
156 ilm 524
                    if (type == EXPAND_TYPE.EXPAND) {
525
                        row2Insert.put("NIVEAU", fatherLevel + 1);
526
                    } else if (type == EXPAND_TYPE.VIEW_ONLY) {
527
                        row2Insert.put("NIVEAU", -1);
528
                    } else if (type == EXPAND_TYPE.FLAT) {
529
                        row2Insert.put("NIVEAU", 1);
530
                    }
93 ilm 531
 
156 ilm 532
                    if (type != EXPAND_TYPE.VIEW_ONLY) {
93 ilm 533
 
156 ilm 534
                        if (row2Insert.getTable().contains("T_PA_TTC")) {
535
                            row2Insert.put("PA_HT", row2Insert.getObject("PRIX_METRIQUE_HA_1"));
93 ilm 536
 
156 ilm 537
                            final BigDecimal resultTotalHT = row2Insert.getBigDecimal("PA_HT").multiply(new BigDecimal(row2Insert.getInt("QTE")));
538
                            row2Insert.put("T_PA_HT", resultTotalHT);
93 ilm 539
 
156 ilm 540
                            Float resultTaux = TaxeCache.getCache().getTauxFromId(row2Insert.getForeignID("ID_TAXE"));
93 ilm 541
 
156 ilm 542
                            if (resultTaux == null) {
543
                                SQLRow rowTax = TaxeCache.getCache().getFirstTaxe();
544
                                resultTaux = rowTax.getFloat("TAUX");
545
                            }
93 ilm 546
 
156 ilm 547
                            float taux = (resultTaux == null) ? 0.0F : resultTaux.floatValue();
93 ilm 548
 
156 ilm 549
                            BigDecimal r = resultTotalHT.multiply(BigDecimal.valueOf(taux).movePointLeft(2).add(BigDecimal.ONE), DecimalUtils.HIGH_PRECISION);
94 ilm 550
 
156 ilm 551
                            row2Insert.put("T_PA_TTC", r);
552
                        } else {
553
                            row2Insert.put("PV_HT", row2Insert.getObject("PRIX_METRIQUE_VT_1"));
94 ilm 554
 
156 ilm 555
                            final BigDecimal resultTotalHT = row2Insert.getBigDecimal("PV_HT").multiply(new BigDecimal(row2Insert.getInt("QTE")));
556
                            row2Insert.put("T_PV_HT", resultTotalHT);
94 ilm 557
 
156 ilm 558
                            Float resultTaux = TaxeCache.getCache().getTauxFromId(row2Insert.getForeignID("ID_TAXE"));
94 ilm 559
 
156 ilm 560
                            if (resultTaux == null) {
561
                                SQLRow rowTax = TaxeCache.getCache().getFirstTaxe();
562
                                resultTaux = rowTax.getFloat("TAUX");
563
                            }
94 ilm 564
 
156 ilm 565
                            float taux = (resultTaux == null) ? 0.0F : resultTaux.floatValue();
94 ilm 566
 
156 ilm 567
                            BigDecimal r = resultTotalHT.multiply(BigDecimal.valueOf(taux).movePointLeft(2).add(BigDecimal.ONE), DecimalUtils.HIGH_PRECISION);
94 ilm 568
 
156 ilm 569
                            row2Insert.put("T_PV_TTC", r);
94 ilm 570
 
156 ilm 571
                        }
94 ilm 572
                    }
156 ilm 573
                    Map<String, Integer> allStyleByName = getSQLElement().getDirectory().getElement(StyleSQLElement.class).getAllStyleByName();
574
                    row2Insert.put("ID_STYLE", allStyleByName.get("Composant"));
575
                    this.model.addRowAt(index + 1, row2Insert);
93 ilm 576
                }
577
            }
578
        }
579
    }
142 ilm 580
 
581
    protected List<AbstractAction> getAdditionnalMouseAction(final int rowIndex) {
582
        return Collections.emptyList();
583
    }
584
 
585
    public void insertFromReliquat(List<SQLRowValues> reliquats) {
586
 
587
        for (SQLRowValues reliquat : reliquats) {
588
 
589
            final SQLRowValues row2Insert = new SQLRowValues(getRowValuesTable().getRowValuesTableModel().getDefaultRowValues());
590
 
591
            // Completion depuis l'article trouvé
592
            final SQLRowAccessor article = reliquat.getForeign("ID_ARTICLE").asRow();
593
 
594
            row2Insert.put("ID_ARTICLE", article.getID());
595
            row2Insert.put("CODE", article.getObject("CODE"));
596
            row2Insert.put("NOM", article.getObject("NOM"));
597
 
598
            row2Insert.put("QTE", reliquat.getObject("QTE"));
599
            row2Insert.put("QTE_UNITAIRE", reliquat.getObject("QTE_UNITAIRE"));
600
            row2Insert.put("ID_UNITE_VENTE", reliquat.getForeignID("ID_UNITE_VENTE"));
601
            getRowValuesTable().getRowValuesTableModel().addRowAt(0, row2Insert);
602
 
603
        }
604
    }
18 ilm 605
}