OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 151 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 151 Rev 177
Line 17... Line 17...
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.SQLRowValues;
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.SQLTableModelColumn;
23
import org.openconcerto.sql.view.list.SQLTableModelColumn;
23
import org.openconcerto.ui.DefaultGridBagConstraints;
24
import org.openconcerto.ui.DefaultGridBagConstraints;
24
import org.openconcerto.ui.JLabelBold;
25
import org.openconcerto.ui.JLabelBold;
-
 
26
import org.openconcerto.utils.TableSorter;
25
import org.openconcerto.utils.Tuple2;
27
import org.openconcerto.utils.Tuple2;
26
 
28
 
27
import java.awt.GridBagConstraints;
29
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
30
import java.awt.GridBagLayout;
29
import java.beans.PropertyChangeListener;
31
import java.beans.PropertyChangeListener;
Line 39... Line 41...
39
import javax.swing.JPanel;
41
import javax.swing.JPanel;
40
import javax.swing.SwingConstants;
42
import javax.swing.SwingConstants;
41
import javax.swing.event.EventListenerList;
43
import javax.swing.event.EventListenerList;
42
import javax.swing.event.TableModelEvent;
44
import javax.swing.event.TableModelEvent;
43
import javax.swing.event.TableModelListener;
45
import javax.swing.event.TableModelListener;
-
 
46
import javax.swing.table.TableModel;
44
 
47
 
45
public class IListTotalPanel extends JPanel {
48
public class IListTotalPanel extends JPanel {
46
    CurrencyConverter cc = new CurrencyConverter();
49
    CurrencyConverter cc = new CurrencyConverter();
47
 
50
 
48
    public enum Type {
51
    public enum Type {
Line 79... Line 82...
79
 
82
 
80
    public static List<Tuple2<? extends SQLTableModelColumn, Type>> initListe(IListe iL, List<SQLField> l) {
83
    public static List<Tuple2<? extends SQLTableModelColumn, Type>> initListe(IListe iL, List<SQLField> l) {
81
        List<Tuple2<? extends SQLTableModelColumn, Type>> lFinal = new ArrayList<Tuple2<? extends SQLTableModelColumn, Type>>();
84
        List<Tuple2<? extends SQLTableModelColumn, Type>> lFinal = new ArrayList<Tuple2<? extends SQLTableModelColumn, Type>>();
82
 
85
 
83
        for (SQLField field : l) {
86
        for (SQLField field : l) {
-
 
87
            final SQLTableModelColumn col = iL.getSource().getColumn(field);
-
 
88
            if (col == null)
-
 
89
                throw new IllegalArgumentException("No column with just " + field + " : " + iL.getSource().getColumns());
84
            lFinal.add(Tuple2.create(iL.getSource().getColumn(field), Type.SOMME));
90
            lFinal.add(Tuple2.create(col, Type.SOMME));
85
        }
91
        }
86
        return lFinal;
92
        return lFinal;
87
    }
93
    }
88
 
94
 
89
    public IListTotalPanel(IListe l, final List<Tuple2<? extends SQLTableModelColumn, Type>> listField, final List<Tuple2<SQLField, ?>> filters, String title) {
95
    public IListTotalPanel(IListe l, final List<Tuple2<? extends SQLTableModelColumn, Type>> listField, final List<Tuple2<SQLField, ?>> filters, String title) {
Line 136... Line 142...
136
            }
142
            }
137
            c.gridy++;
143
            c.gridy++;
138
        }
144
        }
139
 
145
 
140
        this.list.addListener(new TableModelListener() {
146
        this.list.addListener(new TableModelListener() {
-
 
147
 
-
 
148
            private Object getValueAt(final ListSQLLine line, final SQLTableModelColumn col, final List<SQLTableModelColumn> columns) {
-
 
149
                final int indexOf = columns.indexOf(col);
-
 
150
                final Object res = line.getValueAt(indexOf);
-
 
151
                if (res == null)
-
 
152
                    throw new IllegalStateException("Null value for " + col + " in " + line);
-
 
153
                return res;
-
 
154
            }
-
 
155
 
141
            @Override
156
            @Override
142
            public void tableChanged(TableModelEvent e) {
157
            public void tableChanged(TableModelEvent e) {
-
 
158
                final TableModel model = (TableModel) e.getSource();
-
 
159
                final ITableModel sqlModel;
-
 
160
                if (model instanceof ITableModel)
-
 
161
                    sqlModel = (ITableModel) model;
-
 
162
                else
-
 
163
                    sqlModel = (ITableModel) ((TableSorter) model).getTableModel();
-
 
164
 
143
                Map<SQLTableModelColumn, BigDecimal> mapTotal = new HashMap<SQLTableModelColumn, BigDecimal>();
165
                Map<SQLTableModelColumn, BigDecimal> mapTotal = new HashMap<SQLTableModelColumn, BigDecimal>();
144
                Map<SQLTableModelColumn, Double> mapPourcent = new HashMap<SQLTableModelColumn, Double>();
166
                Map<SQLTableModelColumn, Double> mapPourcent = new HashMap<SQLTableModelColumn, Double>();
145
                Map<SQLTableModelColumn, Integer> mapPourcentSize = new HashMap<SQLTableModelColumn, Integer>();
167
                Map<SQLTableModelColumn, Integer> mapPourcentSize = new HashMap<SQLTableModelColumn, Integer>();
146
                for (Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
168
                for (Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
147
                    if (field.get1() == Type.COUNT) {
169
                    if (field.get1() == Type.COUNT) {
148
                        map.get(field.get0()).setText(String.valueOf(list.getRowCount()));
170
                        map.get(field.get0()).setText(String.valueOf(model.getRowCount()));
149
                    }
171
                    }
150
                }
172
                }
151
 
173
 
152
                for (int i = 0; i < list.getRowCount(); i++) {
174
                for (int i = 0; i < model.getRowCount(); i++) {
153
 
-
 
-
 
175
                    final ListSQLLine line = sqlModel.getRow(i);
154
                    final SQLRowValues rowAt = ITableModel.getLine(list.getModel(), i).getRow();
176
                    final SQLRowValues rowAt = line.getRow();
155
 
-
 
156
                    for (Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
177
                    final List<SQLTableModelColumn> columns = line.getColumns().getColumns();
157
 
178
 
-
 
179
                    for (final Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
158
                        if (field.get1() == Type.MOYENNE_POURCENT) {
180
                        final Type type = field.get1();
159
 
181
 
-
 
182
                        if (type == Type.MOYENNE_POURCENT) {
160
                            Double n2 = (Double) list.getModel().getValueAt(i, list.getSource().getColumns().indexOf(field.get0()));
183
                            final Double n2 = (Double) getValueAt(line, field.get0(), columns);
161
 
184
 
162
                            boolean in = true;
185
                            boolean in = true;
163
 
186
 
164
                            if (filters != null) {
187
                            if (filters != null) {
165
                                for (Tuple2<SQLField, ?> tuple2 : filters) {
188
                                for (Tuple2<SQLField, ?> tuple2 : filters) {
Line 186... Line 209...
186
                                } else {
209
                                } else {
187
                                    mapPourcentSize.put(field.get0(), mapPourcentSize.get(field.get0()).intValue() + 1);
210
                                    mapPourcentSize.put(field.get0(), mapPourcentSize.get(field.get0()).intValue() + 1);
188
                                }
211
                                }
189
 
212
 
190
                            }
213
                            }
191
                        } else if (field.get1() == Type.AVANCEMENT_TTC) {
214
                        } else if (type == Type.AVANCEMENT_TTC) {
192
 
215
 
193
                            BigDecimal n = mapTotal.get(field.get0());
216
                            BigDecimal n = mapTotal.get(field.get0());
194
                            final SQLTableModelColumn columnTTC = list.getSource().getColumn(list.getSource().getPrimaryTable().getField("T_TTC"));
-
 
195
                            BigDecimal ttc = BigDecimal.valueOf(((Number) list.getModel().getValueAt(i, list.getSource().getColumns().indexOf(columnTTC))).doubleValue());
217
                            BigDecimal ttc = BigDecimal.valueOf(line.getRow().getObjectAs("T_TTC", Number.class).doubleValue());
196
 
218
 
197
                            BigDecimal av = BigDecimal.valueOf(((Number) list.getModel().getValueAt(i, list.getSource().getColumns().indexOf(field.get0()))).doubleValue());
219
                            BigDecimal av = BigDecimal.valueOf(((Number) getValueAt(line, field.get0(), columns)).doubleValue());
198
 
220
 
199
                            boolean in = true;
221
                            boolean in = true;
200
 
222
 
201
                            if (filters != null) {
223
                            if (filters != null) {
202
                                for (Tuple2<SQLField, ?> tuple2 : filters) {
224
                                for (Tuple2<SQLField, ?> tuple2 : filters) {
Line 214... Line 236...
214
                                    mapTotal.put(field.get0(), ttc.multiply(av).movePointLeft(2));
236
                                    mapTotal.put(field.get0(), ttc.multiply(av).movePointLeft(2));
215
                                } else {
237
                                } else {
216
                                    mapTotal.put(field.get0(), n.add(ttc.multiply(av).movePointLeft(2)));
238
                                    mapTotal.put(field.get0(), n.add(ttc.multiply(av).movePointLeft(2)));
217
                                }
239
                                }
218
                            }
240
                            }
219
                        } else if (field.get1() != Type.MOYENNE_MARGE && field.get1() != Type.COUNT) {
241
                        } else if (type != Type.MOYENNE_MARGE && type != Type.COUNT) {
220
                            BigDecimal n = mapTotal.get(field.get0());
242
                            BigDecimal n = mapTotal.get(field.get0());
221
 
243
 
-
 
244
                            final Object value = getValueAt(line, field.get0(), columns);
222
                            BigDecimal n2 = BigDecimal.valueOf(((Number) list.getModel().getValueAt(i, list.getSource().getColumns().indexOf(field.get0()))).doubleValue());
245
                            final BigDecimal n2 = BigDecimal.valueOf(((Number) value).doubleValue());
223
 
246
 
224
                            boolean in = true;
247
                            boolean in = true;
225
 
248
 
226
                            if (filters != null) {
249
                            if (filters != null) {
227
                                for (Tuple2<SQLField, ?> tuple2 : filters) {
250
                                for (Tuple2<SQLField, ?> tuple2 : filters) {