OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 180 Rev 182
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.common.ui;
14
 package org.openconcerto.erp.core.common.ui;
15
 
15
 
16
import org.openconcerto.erp.core.finance.accounting.model.Currency;
16
import org.openconcerto.erp.core.finance.accounting.model.Currency;
17
import org.openconcerto.erp.core.finance.accounting.model.CurrencyConverter;
17
import org.openconcerto.erp.core.finance.accounting.model.CurrencyConverter;
18
import org.openconcerto.sql.model.SQLField;
18
import org.openconcerto.sql.model.SQLField;
19
import org.openconcerto.sql.model.SQLRowValues;
19
import org.openconcerto.sql.model.SQLRowAccessor;
20
import org.openconcerto.sql.view.list.IListe;
20
import org.openconcerto.sql.view.list.IListe;
21
import org.openconcerto.sql.view.list.ITableModel;
21
import org.openconcerto.sql.view.list.ITableModel;
22
import org.openconcerto.sql.view.list.ListSQLLine;
22
import org.openconcerto.sql.view.list.ListSQLLine;
23
import org.openconcerto.sql.view.list.SQLTableModelColumn;
23
import org.openconcerto.sql.view.list.SQLTableModelColumn;
24
import org.openconcerto.ui.DefaultGridBagConstraints;
24
import org.openconcerto.ui.DefaultGridBagConstraints;
25
import org.openconcerto.ui.JLabelBold;
25
import org.openconcerto.ui.JLabelBold;
26
import org.openconcerto.utils.TableSorter;
26
import org.openconcerto.utils.TableSorter;
27
import org.openconcerto.utils.Tuple2;
27
import org.openconcerto.utils.Tuple2;
28
 
28
 
29
import java.awt.GridBagConstraints;
29
import java.awt.GridBagConstraints;
30
import java.awt.GridBagLayout;
30
import java.awt.GridBagLayout;
31
import java.beans.PropertyChangeListener;
31
import java.beans.PropertyChangeListener;
32
import java.math.BigDecimal;
32
import java.math.BigDecimal;
33
import java.math.MathContext;
33
import java.math.MathContext;
34
import java.text.DecimalFormat;
34
import java.text.DecimalFormat;
35
import java.util.ArrayList;
35
import java.util.ArrayList;
36
import java.util.HashMap;
36
import java.util.HashMap;
37
import java.util.List;
37
import java.util.List;
38
import java.util.Map;
38
import java.util.Map;
39
 
39
 
40
import javax.swing.JLabel;
40
import javax.swing.JLabel;
41
import javax.swing.JPanel;
41
import javax.swing.JPanel;
42
import javax.swing.SwingConstants;
42
import javax.swing.SwingConstants;
43
import javax.swing.event.EventListenerList;
43
import javax.swing.event.EventListenerList;
44
import javax.swing.event.ListSelectionEvent;
44
import javax.swing.event.ListSelectionEvent;
45
import javax.swing.event.ListSelectionListener;
45
import javax.swing.event.ListSelectionListener;
46
import javax.swing.event.TableModelEvent;
46
import javax.swing.event.TableModelEvent;
47
import javax.swing.event.TableModelListener;
47
import javax.swing.event.TableModelListener;
48
import javax.swing.table.TableModel;
48
import javax.swing.table.TableModel;
49
 
49
 
50
public class IListTotalPanel extends JPanel {
50
public class IListTotalPanel extends JPanel {
51
    CurrencyConverter cc = new CurrencyConverter();
51
    CurrencyConverter cc = new CurrencyConverter();
52
 
52
 
53
    public enum Type {
53
    public enum Type {
54
        // Pourcentage moyen d'une colonne
54
        // Pourcentage moyen d'une colonne
55
        MOYENNE_POURCENT,
55
        MOYENNE_POURCENT,
56
        // Moyenne d'une colonne
56
        // Moyenne d'une colonne
57
        MOYENNE_DEVISE,
57
        MOYENNE_DEVISE,
58
        // Somme total d'une colonne
58
        // Somme total d'une colonne
59
        SOMME,
59
        SOMME,
60
        // Somme total d'une colonne
60
        // Somme total d'une colonne
61
        SOMME_QTE,
61
        SOMME_QTE,
62
        // Marge en pourcentage requiert dans la liste la colonne achat en premier et vente en
62
        // Marge en pourcentage requiert dans la liste la colonne achat en premier et vente en
63
        // deuxieme
63
        // deuxieme
64
        MOYENNE_MARGE,
64
        MOYENNE_MARGE,
65
        // Requiert le field TTC
65
        // Requiert le field TTC
66
        AVANCEMENT_TTC,
66
        AVANCEMENT_TTC,
67
        // TOTAL DES LIGNES
67
        // TOTAL DES LIGNES
68
        COUNT;
68
        COUNT;
69
    };
69
    };
70
 
70
 
71
    DecimalFormat decimalFormat = new DecimalFormat("##,##0.00");
71
    DecimalFormat decimalFormat = new DecimalFormat("##,##0.00");
72
 
72
 
73
    EventListenerList loadingListener = new EventListenerList();
73
    EventListenerList loadingListener = new EventListenerList();
74
    private final IListe list;
74
    private final IListe list;
75
    private final Map<SQLTableModelColumn, JLabel> map = new HashMap<SQLTableModelColumn, JLabel>();
75
    private final Map<SQLTableModelColumn, JLabel> map = new HashMap<SQLTableModelColumn, JLabel>();
76
 
76
 
77
    public IListTotalPanel(IListe l, final List<SQLField> listField) {
77
    public IListTotalPanel(IListe l, final List<SQLField> listField) {
78
        this(l, initListe(l, listField), null, null);
78
        this(l, initListe(l, listField), null, null);
79
    }
79
    }
80
 
80
 
81
    public IListTotalPanel(IListe l, final List<SQLField> listField, String title) {
81
    public IListTotalPanel(IListe l, final List<SQLField> listField, String title) {
82
        this(l, initListe(l, listField), null, title);
82
        this(l, initListe(l, listField), null, title);
83
    }
83
    }
84
 
84
 
85
    public static List<Tuple2<? extends SQLTableModelColumn, Type>> initListe(IListe iL, List<SQLField> l) {
85
    public static List<Tuple2<? extends SQLTableModelColumn, Type>> initListe(IListe iL, List<SQLField> l) {
86
        List<Tuple2<? extends SQLTableModelColumn, Type>> lFinal = new ArrayList<Tuple2<? extends SQLTableModelColumn, Type>>();
86
        List<Tuple2<? extends SQLTableModelColumn, Type>> lFinal = new ArrayList<Tuple2<? extends SQLTableModelColumn, Type>>();
87
 
87
 
88
        for (SQLField field : l) {
88
        for (SQLField field : l) {
89
            final SQLTableModelColumn col = iL.getSource().getColumn(field);
89
            final SQLTableModelColumn col = iL.getSource().getColumn(field);
90
            if (col == null)
90
            if (col == null)
91
                throw new IllegalArgumentException("No column with just " + field + " : " + iL.getSource().getColumns());
91
                throw new IllegalArgumentException("No column with just " + field + " : " + iL.getSource().getColumns());
92
            lFinal.add(Tuple2.create(col, Type.SOMME));
92
            lFinal.add(Tuple2.create(col, Type.SOMME));
93
        }
93
        }
94
        return lFinal;
94
        return lFinal;
95
    }
95
    }
96
 
96
 
97
    public IListTotalPanel(IListe l, final List<Tuple2<? extends SQLTableModelColumn, Type>> listField, final List<Tuple2<SQLField, ?>> filters, String title) {
97
    public IListTotalPanel(IListe l, final List<Tuple2<? extends SQLTableModelColumn, Type>> listField, final List<Tuple2<SQLField, ?>> filters, String title) {
98
        this(l, listField, filters, null, title, false);
98
        this(l, listField, filters, null, title, false);
99
    }
99
    }
100
 
100
 
101
    public IListTotalPanel(IListe l, final List<Tuple2<? extends SQLTableModelColumn, Type>> listField, final List<Tuple2<SQLField, ?>> filters, final List<Tuple2<SQLField, ?>> filtersNot,
101
    public IListTotalPanel(IListe l, final List<Tuple2<? extends SQLTableModelColumn, Type>> listField, final List<Tuple2<SQLField, ?>> filters, final List<Tuple2<SQLField, ?>> filtersNot,
102
            String title) {
102
            String title) {
103
        this(l, listField, filters, filtersNot, title, false);
103
        this(l, listField, filters, filtersNot, title, false);
104
    }
104
    }
105
 
105
 
106
    private final boolean onSelection;
106
    private final boolean onSelection;
107
 
107
 
108
    /**
108
    /**
109
     * 
109
     * 
110
     * @param l
110
     * @param l
111
     * @param listField Liste des fields à totaliser
111
     * @param listField Liste des fields à totaliser
112
     * @param filters filtre ex : Tuple((SQLField)NATEXIER,(Boolean)FALSE)
112
     * @param filters filtre ex : Tuple((SQLField)NATEXIER,(Boolean)FALSE)
113
     */
113
     */
114
    public IListTotalPanel(IListe l, final List<Tuple2<? extends SQLTableModelColumn, Type>> listField, final List<Tuple2<SQLField, ?>> filters, final List<Tuple2<SQLField, ?>> filtersNot,
114
    public IListTotalPanel(IListe l, final List<Tuple2<? extends SQLTableModelColumn, Type>> listField, final List<Tuple2<SQLField, ?>> filters, final List<Tuple2<SQLField, ?>> filtersNot,
115
            String title, boolean onSelection) {
115
            String title, boolean onSelection) {
116
        super(new GridBagLayout());
116
        super(new GridBagLayout());
117
        this.list = l;
117
        this.list = l;
118
        this.setOpaque(false);
118
        this.setOpaque(false);
119
        this.onSelection = onSelection;
119
        this.onSelection = onSelection;
120
        GridBagConstraints c = new DefaultGridBagConstraints();
120
        GridBagConstraints c = new DefaultGridBagConstraints();
121
        c.gridx = GridBagConstraints.RELATIVE;
121
        c.gridx = GridBagConstraints.RELATIVE;
122
        c.weightx = 0;
122
        c.weightx = 0;
123
        if (title != null && title.trim().length() > 0) {
123
        if (title != null && title.trim().length() > 0) {
124
            JLabel sep = new JLabel(title);
124
            JLabel sep = new JLabel(title);
125
            c.weightx = 1;
125
            c.weightx = 1;
126
            c.gridwidth = GridBagConstraints.REMAINDER;
126
            c.gridwidth = GridBagConstraints.REMAINDER;
127
            this.add(sep, c);
127
            this.add(sep, c);
128
            c.gridy++;
128
            c.gridy++;
129
            c.gridwidth = 1;
129
            c.gridwidth = 1;
130
        }
130
        }
131
        // Filtre
131
        // Filtre
132
        for (Tuple2<? extends SQLTableModelColumn, Type> field2 : listField) {
132
        for (Tuple2<? extends SQLTableModelColumn, Type> field2 : listField) {
133
            c.weightx = 0;
133
            c.weightx = 0;
134
            final SQLTableModelColumn col = field2.get0();
134
            final SQLTableModelColumn col = field2.get0();
135
            if (col == null) {
135
            if (col == null) {
136
                throw new IllegalStateException("null SQLTableModelColumn in " + listField);
136
                throw new IllegalStateException("null SQLTableModelColumn in " + listField);
137
            }
137
            }
138
            final JLabelBold comp = new JLabelBold(col.getName());
138
            final JLabelBold comp = new JLabelBold(col.getName());
139
            comp.setHorizontalAlignment(SwingConstants.RIGHT);
139
            comp.setHorizontalAlignment(SwingConstants.RIGHT);
140
            this.add(comp, c);
140
            this.add(comp, c);
141
            JLabelBold textField = new JLabelBold("0");
141
            JLabelBold textField = new JLabelBold("0");
142
            textField.setHorizontalAlignment(SwingConstants.RIGHT);
142
            textField.setHorizontalAlignment(SwingConstants.RIGHT);
143
            this.map.put(field2.get0(), textField);
143
            this.map.put(field2.get0(), textField);
144
            c.weightx = 1;
144
            c.weightx = 1;
145
            this.add(textField, c);
145
            this.add(textField, c);
146
            c.weightx = 0;
146
            c.weightx = 0;
147
            if (field2.get1() == Type.SOMME || field2.get1() == Type.MOYENNE_DEVISE || field2.get1() == Type.AVANCEMENT_TTC) {
147
            if (field2.get1() == Type.SOMME || field2.get1() == Type.MOYENNE_DEVISE || field2.get1() == Type.AVANCEMENT_TTC) {
148
                this.add(new JLabelBold(Currency.getSymbol(cc.getCompanyCurrencyCode())), c);
148
                this.add(new JLabelBold(Currency.getSymbol(cc.getCompanyCurrencyCode())), c);
149
            } else if (field2.get1() == Type.MOYENNE_POURCENT || field2.get1() == Type.MOYENNE_MARGE) {
149
            } else if (field2.get1() == Type.MOYENNE_POURCENT || field2.get1() == Type.MOYENNE_MARGE) {
150
                this.add(new JLabelBold("%"), c);
150
                this.add(new JLabelBold("%"), c);
151
            }
151
            }
152
            c.gridy++;
152
            c.gridy++;
153
        }
153
        }
154
 
154
 
155
        if (this.onSelection) {
155
        if (this.onSelection) {
156
            this.list.getJTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
156
            this.list.getJTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
157
 
157
 
158
                @Override
158
                @Override
159
                public void valueChanged(ListSelectionEvent e) {
159
                public void valueChanged(ListSelectionEvent e) {
160
 
160
 
161
                    final List<ListSQLLine> listLines = list.getSelectedLines();
161
                    final List<ListSQLLine> listLines = list.getSelectedLines();
162
                    for (Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
162
                    for (Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
163
                        if (field.get1() == Type.COUNT) {
163
                        if (field.get1() == Type.COUNT) {
164
                            map.get(field.get0()).setText(String.valueOf(listLines.size()));
164
                            map.get(field.get0()).setText(String.valueOf(listLines.size()));
165
                        }
165
                        }
166
                    }
166
                    }
167
                    computeValues(listField, filters, filtersNot, listLines);
167
                    computeValues(listField, filters, filtersNot, listLines);
168
                }
168
                }
169
            });
169
            });
170
        } else {
170
        } else {
171
 
171
 
172
            this.list.addListener(new TableModelListener() {
172
            this.list.addListener(new TableModelListener() {
173
 
173
 
174
                @Override
174
                @Override
175
                public void tableChanged(TableModelEvent e) {
175
                public void tableChanged(TableModelEvent e) {
176
                    final TableModel model = (TableModel) e.getSource();
176
                    final TableModel model = (TableModel) e.getSource();
177
                    final ITableModel sqlModel;
177
                    final ITableModel sqlModel;
178
                    if (model instanceof ITableModel)
178
                    if (model instanceof ITableModel)
179
                        sqlModel = (ITableModel) model;
179
                        sqlModel = (ITableModel) model;
180
                    else
180
                    else
181
                        sqlModel = (ITableModel) ((TableSorter) model).getTableModel();
181
                        sqlModel = (ITableModel) ((TableSorter) model).getTableModel();
182
 
182
 
183
                    final List<ListSQLLine> listLines = new ArrayList<>();
183
                    final List<ListSQLLine> listLines = new ArrayList<>();
184
                    for (int i = 0; i < sqlModel.getRowCount(); i++) {
184
                    for (int i = 0; i < sqlModel.getRowCount(); i++) {
185
                        listLines.add(sqlModel.getRow(i));
185
                        listLines.add(sqlModel.getRow(i));
186
                    }
186
                    }
187
                    for (Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
187
                    for (Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
188
                        if (field.get1() == Type.COUNT) {
188
                        if (field.get1() == Type.COUNT) {
189
                            map.get(field.get0()).setText(String.valueOf(model.getRowCount()));
189
                            map.get(field.get0()).setText(String.valueOf(model.getRowCount()));
190
                        }
190
                        }
191
                    }
191
                    }
192
                    computeValues(listField, filters, filtersNot, listLines);
192
                    computeValues(listField, filters, filtersNot, listLines);
193
                }
193
                }
194
 
194
 
195
            });
195
            });
196
        }
196
        }
197
    }
197
    }
198
 
198
 
199
    public void fireUpdated() {
199
    public void fireUpdated() {
200
        for (PropertyChangeListener l : this.loadingListener.getListeners(PropertyChangeListener.class)) {
200
        for (PropertyChangeListener l : this.loadingListener.getListeners(PropertyChangeListener.class)) {
201
            l.propertyChange(null);
201
            l.propertyChange(null);
202
        }
202
        }
203
    }
203
    }
204
 
204
 
205
    public void addListener(PropertyChangeListener l) {
205
    public void addListener(PropertyChangeListener l) {
206
        this.loadingListener.add(PropertyChangeListener.class, l);
206
        this.loadingListener.add(PropertyChangeListener.class, l);
207
    }
207
    }
208
 
208
 
209
    private Object getValueAt(final ListSQLLine line, final SQLTableModelColumn col, final List<SQLTableModelColumn> columns) {
209
    private Object getValueAt(final ListSQLLine line, final SQLTableModelColumn col, final List<SQLTableModelColumn> columns) {
210
        final int indexOf = columns.indexOf(col);
210
        final int indexOf = columns.indexOf(col);
211
        final Object res = line.getValueAt(indexOf);
211
        final Object res = line.getValueAt(indexOf);
212
        if (res == null)
212
        if (res == null)
213
            throw new IllegalStateException("Null value for " + col + " in " + line);
213
            throw new IllegalStateException("Null value for " + col + " in " + line);
214
        return res;
214
        return res;
215
    }
215
    }
216
 
216
 
217
    private void computeValues(final List<Tuple2<? extends SQLTableModelColumn, Type>> listField, final List<Tuple2<SQLField, ?>> filters, final List<Tuple2<SQLField, ?>> filtersNot,
217
    private void computeValues(final List<Tuple2<? extends SQLTableModelColumn, Type>> listField, final List<Tuple2<SQLField, ?>> filters, final List<Tuple2<SQLField, ?>> filtersNot,
218
            final List<ListSQLLine> listLines) {
218
            final List<ListSQLLine> listLines) {
219
        Map<SQLTableModelColumn, BigDecimal> mapTotal = new HashMap<SQLTableModelColumn, BigDecimal>();
219
        Map<SQLTableModelColumn, BigDecimal> mapTotal = new HashMap<SQLTableModelColumn, BigDecimal>();
220
        Map<SQLTableModelColumn, Double> mapPourcent = new HashMap<SQLTableModelColumn, Double>();
220
        Map<SQLTableModelColumn, Double> mapPourcent = new HashMap<SQLTableModelColumn, Double>();
221
        Map<SQLTableModelColumn, Integer> mapPourcentSize = new HashMap<SQLTableModelColumn, Integer>();
221
        Map<SQLTableModelColumn, Integer> mapPourcentSize = new HashMap<SQLTableModelColumn, Integer>();
222
 
222
 
223
        for (ListSQLLine line : listLines) {
223
        for (ListSQLLine line : listLines) {
224
 
224
 
225
            final SQLRowValues rowAt = line.getRow();
225
            final SQLRowAccessor rowAt = line.getRowAccessor();
226
            final List<SQLTableModelColumn> columns = line.getColumns().getColumns();
226
            final List<SQLTableModelColumn> columns = line.getColumns().getColumns();
227
 
227
 
228
            for (final Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
228
            for (final Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
229
                final Type type = field.get1();
229
                final Type type = field.get1();
230
 
230
 
231
                if (type == Type.MOYENNE_POURCENT) {
231
                if (type == Type.MOYENNE_POURCENT) {
232
                    final Double n2 = (Double) getValueAt(line, field.get0(), columns);
232
                    final Double n2 = (Double) getValueAt(line, field.get0(), columns);
233
 
233
 
234
                    boolean in = true;
234
                    boolean in = true;
235
 
235
 
236
                    if (filters != null) {
236
                    if (filters != null) {
237
                        for (Tuple2<SQLField, ?> tuple2 : filters) {
237
                        for (Tuple2<SQLField, ?> tuple2 : filters) {
238
                            in = in && rowAt.getObject(tuple2.get0().getName()).equals(tuple2.get1());
238
                            in = in && rowAt.getObject(tuple2.get0().getName()).equals(tuple2.get1());
239
                        }
239
                        }
240
                    }
240
                    }
241
 
241
 
242
                    if (filtersNot != null) {
242
                    if (filtersNot != null) {
243
                        for (Tuple2<SQLField, ?> tuple2 : filtersNot) {
243
                        for (Tuple2<SQLField, ?> tuple2 : filtersNot) {
244
                            in = in && !rowAt.getObject(tuple2.get0().getName()).equals(tuple2.get1());
244
                            in = in && !rowAt.getObject(tuple2.get0().getName()).equals(tuple2.get1());
245
                        }
245
                        }
246
                    }
246
                    }
247
 
247
 
248
                    if (in) {
248
                    if (in) {
249
 
249
 
250
                        if (mapPourcent.get(field.get0()) == null) {
250
                        if (mapPourcent.get(field.get0()) == null) {
251
                            mapPourcent.put(field.get0(), n2);
251
                            mapPourcent.put(field.get0(), n2);
252
                        } else {
252
                        } else {
253
                            mapPourcent.put(field.get0(), n2 + mapPourcent.get(field.get0()));
253
                            mapPourcent.put(field.get0(), n2 + mapPourcent.get(field.get0()));
254
                        }
254
                        }
255
 
255
 
256
                        if (mapPourcentSize.get(field.get0()) == null) {
256
                        if (mapPourcentSize.get(field.get0()) == null) {
257
                            mapPourcentSize.put(field.get0(), 1);
257
                            mapPourcentSize.put(field.get0(), 1);
258
                        } else {
258
                        } else {
259
                            mapPourcentSize.put(field.get0(), mapPourcentSize.get(field.get0()).intValue() + 1);
259
                            mapPourcentSize.put(field.get0(), mapPourcentSize.get(field.get0()).intValue() + 1);
260
                        }
260
                        }
261
 
261
 
262
                    }
262
                    }
263
                } else if (type == Type.AVANCEMENT_TTC) {
263
                } else if (type == Type.AVANCEMENT_TTC) {
264
 
264
 
265
                    BigDecimal n = mapTotal.get(field.get0());
265
                    BigDecimal n = mapTotal.get(field.get0());
266
                    BigDecimal ttc = BigDecimal.valueOf(line.getRow().getObjectAs("T_TTC", Number.class).doubleValue());
266
                    BigDecimal ttc = BigDecimal.valueOf(line.getRow().getObjectAs("T_TTC", Number.class).doubleValue());
267
 
267
 
268
                    BigDecimal av = BigDecimal.valueOf(((Number) getValueAt(line, field.get0(), columns)).doubleValue());
268
                    BigDecimal av = BigDecimal.valueOf(((Number) getValueAt(line, field.get0(), columns)).doubleValue());
269
 
269
 
270
                    boolean in = true;
270
                    boolean in = true;
271
 
271
 
272
                    if (filters != null) {
272
                    if (filters != null) {
273
                        for (Tuple2<SQLField, ?> tuple2 : filters) {
273
                        for (Tuple2<SQLField, ?> tuple2 : filters) {
274
                            in = in && rowAt.getObject(tuple2.get0().getName()).equals(tuple2.get1());
274
                            in = in && rowAt.getObject(tuple2.get0().getName()).equals(tuple2.get1());
275
                        }
275
                        }
276
                    }
276
                    }
277
                    if (filtersNot != null) {
277
                    if (filtersNot != null) {
278
                        for (Tuple2<SQLField, ?> tuple2 : filtersNot) {
278
                        for (Tuple2<SQLField, ?> tuple2 : filtersNot) {
279
                            in = in && !rowAt.getObject(tuple2.get0().getName()).equals(tuple2.get1());
279
                            in = in && !rowAt.getObject(tuple2.get0().getName()).equals(tuple2.get1());
280
                        }
280
                        }
281
                    }
281
                    }
282
 
282
 
283
                    if (in) {
283
                    if (in) {
284
                        if (n == null) {
284
                        if (n == null) {
285
                            mapTotal.put(field.get0(), ttc.multiply(av).movePointLeft(2));
285
                            mapTotal.put(field.get0(), ttc.multiply(av).movePointLeft(2));
286
                        } else {
286
                        } else {
287
                            mapTotal.put(field.get0(), n.add(ttc.multiply(av).movePointLeft(2)));
287
                            mapTotal.put(field.get0(), n.add(ttc.multiply(av).movePointLeft(2)));
288
                        }
288
                        }
289
                    }
289
                    }
290
                } else if (type != Type.MOYENNE_MARGE && type != Type.COUNT) {
290
                } else if (type != Type.MOYENNE_MARGE && type != Type.COUNT) {
-
 
291
 
-
 
292
                    // FIXME Test si la colonne existe sinon exception dans liste des articles quand
-
 
293
                    // on passe de la vue normal à virtuel
-
 
294
                    if (columns.indexOf(field.get0()) != -1) {
-
 
295
 
291
                    BigDecimal n = mapTotal.get(field.get0());
296
                        BigDecimal n = mapTotal.get(field.get0());
292
 
297
 
293
                    final Object value = getValueAt(line, field.get0(), columns);
298
                        final Object value = getValueAt(line, field.get0(), columns);
294
                    final BigDecimal n2 = BigDecimal.valueOf(((Number) value).doubleValue());
299
                        final BigDecimal n2 = BigDecimal.valueOf(((Number) value).doubleValue());
295
 
300
 
296
                    boolean in = true;
301
                        boolean in = true;
297
 
302
 
298
                    if (filters != null) {
303
                        if (filters != null) {
299
                        for (Tuple2<SQLField, ?> tuple2 : filters) {
304
                            for (Tuple2<SQLField, ?> tuple2 : filters) {
300
                            in = in && rowAt.getObject(tuple2.get0().getName()).equals(tuple2.get1());
305
                                in = in && rowAt.getObject(tuple2.get0().getName()).equals(tuple2.get1());
301
                        }
306
                            }
302
                    }
307
                        }
303
                    if (filtersNot != null) {
308
                        if (filtersNot != null) {
304
                        for (Tuple2<SQLField, ?> tuple2 : filtersNot) {
309
                            for (Tuple2<SQLField, ?> tuple2 : filtersNot) {
305
                            in = in && !rowAt.getObject(tuple2.get0().getName()).equals(tuple2.get1());
310
                                in = in && !rowAt.getObject(tuple2.get0().getName()).equals(tuple2.get1());
306
                        }
311
                            }
307
                    }
312
                        }
308
 
313
 
309
                    if (in) {
314
                        if (in) {
310
                        if (n == null) {
315
                            if (n == null) {
311
                            mapTotal.put(field.get0(), n2);
316
                                mapTotal.put(field.get0(), n2);
312
                        } else {
317
                            } else {
313
                            mapTotal.put(field.get0(), n.add(n2));
318
                                mapTotal.put(field.get0(), n.add(n2));
314
                        }
319
                            }
-
 
320
                        }
315
                    }
321
                    }
316
                }
322
                }
317
            }
323
            }
318
        }
324
        }
319
 
325
 
320
        for (Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
326
        for (Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
321
            if (field.get1() == Type.MOYENNE_MARGE) {
327
            if (field.get1() == Type.MOYENNE_MARGE) {
322
 
328
 
323
                BigDecimal totalVT = mapTotal.get(listField.get(0).get0());
329
                BigDecimal totalVT = mapTotal.get(listField.get(0).get0());
324
                BigDecimal totalHA = mapTotal.get(listField.get(1).get0());
330
                BigDecimal totalHA = mapTotal.get(listField.get(1).get0());
325
                if (totalHA != null && totalVT != null && totalVT.longValue() != 0) {
331
                if (totalHA != null && totalVT != null && totalVT.longValue() != 0) {
326
                    map.get(field.get0()).setText(decimalFormat.format(totalVT.subtract(totalHA).divide(totalVT, MathContext.DECIMAL32).doubleValue() * 100.0D));
332
                    map.get(field.get0()).setText(decimalFormat.format(totalVT.subtract(totalHA).divide(totalVT, MathContext.DECIMAL32).doubleValue() * 100.0D));
327
                } else {
333
                } else {
328
                    map.get(field.get0()).setText(decimalFormat.format(0));
334
                    map.get(field.get0()).setText(decimalFormat.format(0));
329
                }
335
                }
330
            } else if (field.get1() == Type.MOYENNE_POURCENT) {
336
            } else if (field.get1() == Type.MOYENNE_POURCENT) {
331
                Double l = mapPourcent.get(field.get0());
337
                Double l = mapPourcent.get(field.get0());
332
                Integer d = mapPourcentSize.get(field.get0());
338
                Integer d = mapPourcentSize.get(field.get0());
333
                if (l != null && d != null && d != 0) {
339
                if (l != null && d != null && d != 0) {
334
                    map.get(field.get0()).setText(decimalFormat.format(l / (double) d));
340
                    map.get(field.get0()).setText(decimalFormat.format(l / (double) d));
335
                } else {
341
                } else {
336
                    map.get(field.get0()).setText(decimalFormat.format(0));
342
                    map.get(field.get0()).setText(decimalFormat.format(0));
337
                }
343
                }
338
            } else if (field.get1() != Type.COUNT) {
344
            } else if (field.get1() != Type.COUNT) {
339
                BigDecimal l = mapTotal.get(field.get0());
345
                BigDecimal l = mapTotal.get(field.get0());
340
                if (l != null) {
346
                if (l != null) {
341
                    map.get(field.get0()).setText(decimalFormat.format(l.doubleValue()));
347
                    map.get(field.get0()).setText(decimalFormat.format(l.doubleValue()));
342
                } else {
348
                } else {
343
                    map.get(field.get0()).setText(decimalFormat.format(0));
349
                    map.get(field.get0()).setText(decimalFormat.format(0));
344
                }
350
                }
345
            }
351
            }
346
        }
352
        }
347
        fireUpdated();
353
        fireUpdated();
348
    }
354
    }
349
}
355
}