OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 182 Rev 185
Line 13... Line 13...
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.FieldPath;
18
import org.openconcerto.sql.model.SQLField;
19
import org.openconcerto.sql.model.SQLField;
19
import org.openconcerto.sql.model.SQLRowAccessor;
20
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
21
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
20
import org.openconcerto.sql.view.list.IListe;
22
import org.openconcerto.sql.view.list.IListe;
21
import org.openconcerto.sql.view.list.ITableModel;
23
import org.openconcerto.sql.view.list.ITableModel;
22
import org.openconcerto.sql.view.list.ListSQLLine;
24
import org.openconcerto.sql.view.list.ListSQLLine;
23
import org.openconcerto.sql.view.list.SQLTableModelColumn;
25
import org.openconcerto.sql.view.list.SQLTableModelColumn;
24
import org.openconcerto.ui.DefaultGridBagConstraints;
26
import org.openconcerto.ui.DefaultGridBagConstraints;
25
import org.openconcerto.ui.JLabelBold;
27
import org.openconcerto.ui.JLabelBold;
26
import org.openconcerto.utils.TableSorter;
28
import org.openconcerto.utils.TableSorter;
27
import org.openconcerto.utils.Tuple2;
29
import org.openconcerto.utils.Tuple2;
-
 
30
import org.openconcerto.utils.Tuple3;
28
 
31
 
29
import java.awt.GridBagConstraints;
32
import java.awt.GridBagConstraints;
30
import java.awt.GridBagLayout;
33
import java.awt.GridBagLayout;
31
import java.beans.PropertyChangeListener;
34
import java.beans.PropertyChangeListener;
32
import java.math.BigDecimal;
35
import java.math.BigDecimal;
Line 34... Line 37...
34
import java.text.DecimalFormat;
37
import java.text.DecimalFormat;
35
import java.util.ArrayList;
38
import java.util.ArrayList;
36
import java.util.HashMap;
39
import java.util.HashMap;
37
import java.util.List;
40
import java.util.List;
38
import java.util.Map;
41
import java.util.Map;
-
 
42
import java.util.Set;
-
 
43
import java.util.concurrent.ExecutionException;
39
 
44
 
40
import javax.swing.JLabel;
45
import javax.swing.JLabel;
41
import javax.swing.JPanel;
46
import javax.swing.JPanel;
42
import javax.swing.SwingConstants;
47
import javax.swing.SwingConstants;
-
 
48
import javax.swing.SwingWorker;
43
import javax.swing.event.EventListenerList;
49
import javax.swing.event.EventListenerList;
44
import javax.swing.event.ListSelectionEvent;
50
import javax.swing.event.ListSelectionEvent;
45
import javax.swing.event.ListSelectionListener;
51
import javax.swing.event.ListSelectionListener;
46
import javax.swing.event.TableModelEvent;
52
import javax.swing.event.TableModelEvent;
47
import javax.swing.event.TableModelListener;
53
import javax.swing.event.TableModelListener;
Line 63... Line 69...
63
        // deuxieme
69
        // deuxieme
64
        MOYENNE_MARGE,
70
        MOYENNE_MARGE,
65
        // Requiert le field TTC
71
        // Requiert le field TTC
66
        AVANCEMENT_TTC,
72
        AVANCEMENT_TTC,
67
        // TOTAL DES LIGNES
73
        // TOTAL DES LIGNES
68
        COUNT;
74
        COUNT,
-
 
75
 
-
 
76
        // DIfference entre parama 1 et 2
-
 
77
        DIFF;
69
    };
78
    };
70
 
79
 
71
    DecimalFormat decimalFormat = new DecimalFormat("##,##0.00");
80
    DecimalFormat decimalFormat = new DecimalFormat("##,##0.00");
72
 
81
 
73
    EventListenerList loadingListener = new EventListenerList();
82
    EventListenerList loadingListener = new EventListenerList();
Line 109... Line 118...
109
     * 
118
     * 
110
     * @param l
119
     * @param l
111
     * @param listField Liste des fields à totaliser
120
     * @param listField Liste des fields à totaliser
112
     * @param filters filtre ex : Tuple((SQLField)NATEXIER,(Boolean)FALSE)
121
     * @param filters filtre ex : Tuple((SQLField)NATEXIER,(Boolean)FALSE)
113
     */
122
     */
-
 
123
    final GridBagConstraints c = new DefaultGridBagConstraints();
-
 
124
 
114
    public IListTotalPanel(IListe l, final List<Tuple2<? extends SQLTableModelColumn, Type>> listField, final List<Tuple2<SQLField, ?>> filters, final List<Tuple2<SQLField, ?>> filtersNot,
125
    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) {
126
            String title, boolean onSelection) {
116
        super(new GridBagLayout());
127
        super(new GridBagLayout());
117
        this.list = l;
128
        this.list = l;
118
        this.setOpaque(false);
129
        this.setOpaque(false);
119
        this.onSelection = onSelection;
130
        this.onSelection = onSelection;
120
        GridBagConstraints c = new DefaultGridBagConstraints();
-
 
121
        c.gridx = GridBagConstraints.RELATIVE;
131
        c.gridx = GridBagConstraints.RELATIVE;
122
        c.weightx = 0;
132
        c.weightx = 0;
123
        if (title != null && title.trim().length() > 0) {
133
        if (title != null && title.trim().length() > 0) {
124
            JLabel sep = new JLabel(title);
134
            JLabel sep = new JLabel(title);
125
            c.weightx = 1;
135
            c.weightx = 1;
Line 194... Line 204...
194
 
204
 
195
            });
205
            });
196
        }
206
        }
197
    }
207
    }
198
 
208
 
-
 
209
    private SQLTableModelColumn fieldDebit, fieldCredit;
-
 
210
    private SQLTableModelColumn soldeEcrColumn;
-
 
211
 
-
 
212
    public void addSubtract(SQLTableModelColumn fieldDebit, SQLTableModelColumn fieldCredit) {
-
 
213
        c.weightx = 0;
-
 
214
 
-
 
215
        this.fieldCredit = fieldCredit;
-
 
216
        this.fieldDebit = fieldDebit;
-
 
217
        final JLabelBold comp = new JLabelBold("Solde");
-
 
218
        comp.setHorizontalAlignment(SwingConstants.RIGHT);
-
 
219
        this.add(comp, c);
-
 
220
        JLabelBold textField = new JLabelBold("0");
-
 
221
        textField.setHorizontalAlignment(SwingConstants.RIGHT);
-
 
222
        this.soldeEcrColumn = new BaseSQLTableModelColumn("SoldeEcr", BigDecimal.class) {
-
 
223
 
-
 
224
            @Override
-
 
225
            protected Object show_(SQLRowAccessor r) {
-
 
226
                // TODO Auto-generated method stub
-
 
227
                return null;
-
 
228
            }
-
 
229
 
-
 
230
            @Override
-
 
231
            public Set<FieldPath> getPaths() {
-
 
232
                // TODO Auto-generated method stub
-
 
233
                return null;
-
 
234
            }
-
 
235
        };
-
 
236
        this.map.put(soldeEcrColumn, textField);
-
 
237
        c.weightx = 1;
-
 
238
        this.add(textField, c);
-
 
239
        c.weightx = 0;
-
 
240
        this.add(new JLabelBold(Currency.getSymbol(cc.getCompanyCurrencyCode())), c);
-
 
241
        c.gridy++;
-
 
242
    }
-
 
243
 
199
    public void fireUpdated() {
244
    public void fireUpdated() {
200
        for (PropertyChangeListener l : this.loadingListener.getListeners(PropertyChangeListener.class)) {
245
        for (PropertyChangeListener l : this.loadingListener.getListeners(PropertyChangeListener.class)) {
201
            l.propertyChange(null);
246
            l.propertyChange(null);
202
        }
247
        }
203
    }
248
    }
Line 214... Line 259...
214
        return res;
259
        return res;
215
    }
260
    }
216
 
261
 
217
    private void computeValues(final List<Tuple2<? extends SQLTableModelColumn, Type>> listField, final List<Tuple2<SQLField, ?>> filters, final List<Tuple2<SQLField, ?>> filtersNot,
262
    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) {
263
            final List<ListSQLLine> listLines) {
-
 
264
 
-
 
265
        SwingWorker<Tuple3<Map<SQLTableModelColumn, BigDecimal>, Map<SQLTableModelColumn, Double>, Map<SQLTableModelColumn, Integer>>, Object> worker = new SwingWorker<Tuple3<Map<SQLTableModelColumn, BigDecimal>, Map<SQLTableModelColumn, Double>, Map<SQLTableModelColumn, Integer>>, Object>() {
-
 
266
            @Override
-
 
267
            protected Tuple3<Map<SQLTableModelColumn, BigDecimal>, Map<SQLTableModelColumn, Double>, Map<SQLTableModelColumn, Integer>> doInBackground() throws Exception {
219
        Map<SQLTableModelColumn, BigDecimal> mapTotal = new HashMap<SQLTableModelColumn, BigDecimal>();
268
                Map<SQLTableModelColumn, BigDecimal> mapTotal = new HashMap<SQLTableModelColumn, BigDecimal>();
220
        Map<SQLTableModelColumn, Double> mapPourcent = new HashMap<SQLTableModelColumn, Double>();
269
                Map<SQLTableModelColumn, Double> mapPourcent = new HashMap<SQLTableModelColumn, Double>();
221
        Map<SQLTableModelColumn, Integer> mapPourcentSize = new HashMap<SQLTableModelColumn, Integer>();
270
                Map<SQLTableModelColumn, Integer> mapPourcentSize = new HashMap<SQLTableModelColumn, Integer>();
222
 
-
 
223
        for (ListSQLLine line : listLines) {
271
                for (ListSQLLine line : listLines) {
224
 
272
 
225
            final SQLRowAccessor rowAt = line.getRowAccessor();
273
                    final SQLRowAccessor rowAt = line.getRowAccessor();
226
            final List<SQLTableModelColumn> columns = line.getColumns().getColumns();
274
                    final List<SQLTableModelColumn> columns = line.getColumns().getColumns();
227
 
275
 
Line 261... Line 309...
261
 
309
 
262
                    }
310
                            }
263
                } else if (type == Type.AVANCEMENT_TTC) {
311
                        } else if (type == Type.AVANCEMENT_TTC) {
264
 
312
 
265
                    BigDecimal n = mapTotal.get(field.get0());
313
                            BigDecimal n = mapTotal.get(field.get0());
266
                    BigDecimal ttc = BigDecimal.valueOf(line.getRow().getObjectAs("T_TTC", Number.class).doubleValue());
314
                            Number objectAs = line.getRow().getObjectAs("T_TTC", Number.class);
267
 
-
 
-
 
315
                            BigDecimal ttc;
-
 
316
                            if (objectAs instanceof Long) {
-
 
317
                                ttc = BigDecimal.valueOf(objectAs.doubleValue() / 100.0);
-
 
318
                            } else {
-
 
319
                                ttc = BigDecimal.valueOf(objectAs.doubleValue());
-
 
320
                            }
268
                    BigDecimal av = BigDecimal.valueOf(((Number) getValueAt(line, field.get0(), columns)).doubleValue());
321
                            BigDecimal av = BigDecimal.valueOf(((Number) getValueAt(line, field.get0(), columns)).doubleValue());
269
 
322
 
270
                    boolean in = true;
323
                            boolean in = true;
271
 
324
 
272
                    if (filters != null) {
325
                            if (filters != null) {
Line 285... Line 338...
285
                            mapTotal.put(field.get0(), ttc.multiply(av).movePointLeft(2));
338
                                    mapTotal.put(field.get0(), ttc.multiply(av).movePointLeft(2));
286
                        } else {
339
                                } else {
287
                            mapTotal.put(field.get0(), n.add(ttc.multiply(av).movePointLeft(2)));
340
                                    mapTotal.put(field.get0(), n.add(ttc.multiply(av).movePointLeft(2)));
288
                        }
341
                                }
289
                    }
342
                            }
-
 
343
 
290
                } else if (type != Type.MOYENNE_MARGE && type != Type.COUNT) {
344
                        } else if (type != Type.MOYENNE_MARGE && type != Type.COUNT) {
291
 
345
 
292
                    // FIXME Test si la colonne existe sinon exception dans liste des articles quand
346
                            // FIXME Test si la colonne existe sinon exception dans liste des
-
 
347
                            // articles quand
293
                    // on passe de la vue normal à virtuel
348
                            // on passe de la vue normal à virtuel
294
                    if (columns.indexOf(field.get0()) != -1) {
349
                            if (columns.indexOf(field.get0()) != -1) {
295
 
350
 
296
                        BigDecimal n = mapTotal.get(field.get0());
351
                                BigDecimal n = mapTotal.get(field.get0());
297
 
352
 
Line 320... Line 375...
320
                        }
375
                                }
321
                    }
376
                            }
322
                }
377
                        }
323
            }
378
                    }
324
        }
379
                }
-
 
380
                return Tuple3.create(mapTotal, mapPourcent, mapPourcentSize);
-
 
381
            }
-
 
382
 
-
 
383
            @Override
-
 
384
            protected void done() {
-
 
385
                try {
-
 
386
                    Tuple3<Map<SQLTableModelColumn, BigDecimal>, Map<SQLTableModelColumn, Double>, Map<SQLTableModelColumn, Integer>> tuple3 = get();
-
 
387
 
-
 
388
                    Map<SQLTableModelColumn, BigDecimal> mapTotal = tuple3.get0();
-
 
389
                    Map<SQLTableModelColumn, Double> mapPourcent = tuple3.get1();
-
 
390
                    Map<SQLTableModelColumn, Integer> mapPourcentSize = tuple3.get2();
325
 
391
 
326
        for (Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
392
                    for (Tuple2<? extends SQLTableModelColumn, Type> field : listField) {
327
            if (field.get1() == Type.MOYENNE_MARGE) {
393
                        if (field.get1() == Type.MOYENNE_MARGE) {
328
 
394
 
329
                BigDecimal totalVT = mapTotal.get(listField.get(0).get0());
395
                            BigDecimal totalVT = mapTotal.get(listField.get(0).get0());
Line 348... Line 414...
348
                } else {
414
                            } else {
349
                    map.get(field.get0()).setText(decimalFormat.format(0));
415
                                map.get(field.get0()).setText(decimalFormat.format(0));
350
                }
416
                            }
351
            }
417
                        }
352
        }
418
                    }
-
 
419
 
-
 
420
                    if (map.containsKey(soldeEcrColumn)) {
-
 
421
                        BigDecimal d = mapTotal.get(fieldDebit);
-
 
422
                        BigDecimal c = mapTotal.get(fieldCredit);
-
 
423
 
-
 
424
                        if (d != null && c != null) {
-
 
425
                            map.get(soldeEcrColumn).setText(decimalFormat.format(d.doubleValue() - c.doubleValue()));
-
 
426
                        } else {
-
 
427
                            map.get(soldeEcrColumn).setText(decimalFormat.format(0));
-
 
428
                        }
-
 
429
                    }
-
 
430
 
353
        fireUpdated();
431
                    fireUpdated();
-
 
432
                } catch (InterruptedException | ExecutionException e) {
-
 
433
                    e.printStackTrace();
-
 
434
                }
-
 
435
            }
-
 
436
        };
-
 
437
        worker.execute();
-
 
438
 
354
    }
439
    }
355
}
440
}