OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
156 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.supplychain.stock.element;
15
 
16
import org.openconcerto.erp.core.sales.product.ui.CurrencyWithSymbolRenderer;
17
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.element.SQLElement;
19
import org.openconcerto.sql.model.SQLRowValues;
20
import org.openconcerto.sql.view.list.CellDynamicModifier;
21
import org.openconcerto.sql.view.list.RowValuesTable;
22
import org.openconcerto.sql.view.list.RowValuesTableModel;
23
import org.openconcerto.sql.view.list.RowValuesTablePanel;
24
import org.openconcerto.sql.view.list.SQLTableElement;
25
 
26
import java.math.BigDecimal;
27
import java.util.ArrayList;
28
import java.util.List;
29
 
30
import javax.swing.JTextField;
31
import javax.swing.event.TableModelEvent;
32
import javax.swing.event.TableModelListener;
33
 
34
public class EtatStockTable extends RowValuesTablePanel {
35
 
36
    public EtatStockTable(final JTextField fieldTotal) {
37
 
38
        init();
39
        uiInit();
40
        this.table.getModel().addTableModelListener(new TableModelListener() {
41
 
42
            @Override
43
            public void tableChanged(TableModelEvent e) {
44
                BigDecimal total = BigDecimal.ZERO;
45
                for (int i = 0; i < table.getRowValuesTableModel().getRowCount(); i++) {
46
                    total = total.add(table.getRowValuesTableModel().getRowValuesAt(i).getBigDecimal("T_PA"));
47
                }
48
                fieldTotal.setText(total.toString());
49
            }
50
        });
51
 
52
    }
53
 
54
    /**
55
     *
56
     */
57
    protected void init() {
58
 
59
        final SQLElement e = getSQLElement();
60
 
61
        final List<SQLTableElement> list = new ArrayList<>();
62
        list.add(new SQLTableElement(e.getTable().getField("ID_ARTICLE")));
63
        list.add(new SQLTableElement(e.getTable().getField("CODE")));
64
        list.add(new SQLTableElement(e.getTable().getField("NOM")));
65
        final SQLTableElement achat = new SQLTableElement(e.getTable().getField("PA")) {
66
            @Override
67
            protected Object getDefaultNullValue() {
68
                return BigDecimal.ZERO;
69
            }
70
        };
71
        achat.setRenderer(new CurrencyWithSymbolRenderer());
72
 
73
        list.add(achat);
74
        final SQLTableElement qte = new SQLTableElement(e.getTable().getField("QTE")) {
75
            @Override
76
            protected Object getDefaultNullValue() {
77
                return BigDecimal.ZERO;
78
            }
79
 
80
        };
81
 
82
        list.add(qte);
83
        SQLTableElement totalHA = new SQLTableElement(e.getTable().getField("T_PA"));
84
        totalHA.setRenderer(new CurrencyWithSymbolRenderer());
85
        list.add(totalHA);
86
 
87
        this.defaultRowVals = new SQLRowValues(getSQLElement().getTable());
88
        this.model = new RowValuesTableModel(e, list, e.getTable().getField("ID_ARTICLE"), false, this.defaultRowVals);
89
        this.table = new RowValuesTable(this.model, null);
90
 
91
        // Calcul automatique du prix de vente unitaire HT
92
 
93
        qte.addModificationListener(totalHA);
94
        achat.addModificationListener(totalHA);
95
        totalHA.setModifier(new CellDynamicModifier() {
96
            public Object computeValueFrom(SQLRowValues row, SQLTableElement source) {
97
                return row.getBigDecimal("QTE").multiply(row.getBigDecimal("PA"));
98
            }
99
        });
100
 
101
    }
102
 
103
    public SQLElement getSQLElement() {
104
        return Configuration.getInstance().getDirectory().getElement("ETAT_STOCK_ELEMENT");
105
    }
106
 
107
}