OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 19 | 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.finance.accounting.ui;
15
 
174 ilm 16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
18
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.model.SQLRow;
18 ilm 20
import org.openconcerto.sql.model.SQLRowValues;
21
import org.openconcerto.sql.view.list.ITableModel;
22
import org.openconcerto.ui.DefaultGridBagConstraints;
23
import org.openconcerto.utils.GestionDevise;
24
 
25
import java.awt.Color;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.Insets;
174 ilm 29
import java.util.Date;
18 ilm 30
 
31
import javax.swing.BorderFactory;
32
import javax.swing.JLabel;
33
import javax.swing.JPanel;
34
import javax.swing.event.TableModelEvent;
35
import javax.swing.event.TableModelListener;
36
import javax.swing.table.TableModel;
37
 
38
public class ListeDesEcrituresPanel extends JPanel {
39
 
40
    private ListPanelEcritures panelEcritures;
41
    private JPanel panelTotal;
42
    private JPanel panelLegende;
43
    private JLabel montantDebit;
44
    private JLabel montantCredit;
45
    private JLabel montantSolde;
46
 
47
    public ListeDesEcrituresPanel() {
48
 
49
        this.panelEcritures = new ListPanelEcritures();
50
        this.montantDebit = new JLabel("0.0");
51
        this.montantCredit = new JLabel("0.0");
52
        this.montantSolde = new JLabel("0.0");
53
 
54
        this.setLayout(new GridBagLayout());
55
        final GridBagConstraints c = new DefaultGridBagConstraints();
56
        c.weightx = 1;
57
        c.weighty = 1;
58
        c.gridwidth = 2;
59
        c.fill = GridBagConstraints.BOTH;
60
        this.add(this.panelEcritures, c);
61
 
174 ilm 62
        SQLRow rowExercice = Configuration.getInstance().getBase().getTable("EXERCICE_COMMON").getRow(ComptaPropsConfiguration.getInstanceCompta().getRowSociete().getInt("ID_EXERCICE_COMMON"));
63
 
64
        final IListFilterDatePanel comp = new IListFilterDatePanel(this.panelEcritures.getListe(), this.panelEcritures.getListe().getSource().getElem().getTable().getField("DATE"),
65
                IListFilterDatePanel.getDefaultMap());
66
        comp.setDateDu((Date) rowExercice.getObject("DATE_DEB"));
67
        c.weightx = 1;
68
        c.gridy++;
69
        this.add(comp, c);
70
 
18 ilm 71
        /* Panel Legende */
72
        c.gridwidth = 1;
174 ilm 73
        c.gridy++;
18 ilm 74
        this.panelLegende = new JPanel();
75
        this.panelLegende.setLayout(new GridBagLayout());
76
        this.panelLegende.setBorder(BorderFactory.createTitledBorder("Légende"));
77
 
78
        c.insets = new Insets(0, 0, 0, 0);
79
        JPanel panelValide = new JPanel();
80
        panelValide.setLayout(new GridBagLayout());
81
        panelValide.add(new JLabel("Ecritures validées"));
82
        panelValide.setBackground(Color.WHITE);
83
        // panelValide.setBorder(BorderFactory.createLineBorder(Color.BLACK));
174 ilm 84
        c.gridy++;
18 ilm 85
        this.panelLegende.add(panelValide, c);
86
 
87
        JPanel panelNonValide = new JPanel();
88
        panelNonValide.setLayout(new GridBagLayout());
89
        panelNonValide.add(new JLabel("Ecritures non validées"));
19 ilm 90
        panelNonValide.setBackground(ListEcritureRenderer.getCouleurEcritureNonValide());
18 ilm 91
        // panelNonValide.setBorder(BorderFactory.createLineBorder(Color.BLACK));
174 ilm 92
        c.gridy++;
18 ilm 93
        this.panelLegende.add(panelNonValide, c);
94
 
95
        JPanel panelNonValideToDay = new JPanel();
96
        panelNonValideToDay.setLayout(new GridBagLayout());
97
        panelNonValideToDay.add(new JLabel("Ecritures non validées du jour"));
98
        panelNonValideToDay.setBackground(ListEcritureRenderer.getCouleurEcritureToDay());
99
        // panelNonValideToDay.setBorder(BorderFactory.createLineBorder(Color.BLACK));
174 ilm 100
        c.gridy++;
18 ilm 101
        this.panelLegende.add(panelNonValideToDay, c);
102
 
174 ilm 103
        c.gridy = 2;
18 ilm 104
        c.weightx = 0;
105
        c.weighty = 0;
106
        c.insets = new Insets(2, 2, 1, 2);
107
        this.add(this.panelLegende, c);
108
 
109
        /* Panel Total */
110
        c.gridx = 0;
174 ilm 111
        // c.gridy = 0;
18 ilm 112
        this.panelTotal = new JPanel();
113
        this.panelTotal.setLayout(new GridBagLayout());
114
        this.panelTotal.setBorder(BorderFactory.createTitledBorder("Totaux"));
115
 
116
        JLabel labelDebit = new JLabel("Débit");
117
        c.anchor = GridBagConstraints.EAST;
118
        c.weightx = 0;
119
        c.weighty = 0;
120
        this.panelTotal.add(labelDebit, c);
121
 
122
        c.gridx++;
123
        this.panelTotal.add(this.montantDebit, c);
124
 
125
        JLabel labelCredit = new JLabel("Crédit");
126
 
127
        c.gridy++;
128
        c.gridx = 0;
129
        c.weightx = 0;
130
        this.panelTotal.add(labelCredit, c);
131
 
132
        c.gridx++;
133
        this.panelTotal.add(this.montantCredit, c);
134
 
135
        JLabel labelSolde = new JLabel("Solde");
136
 
137
        c.weightx = 0;
138
        c.gridx = 0;
139
        c.gridy++;
140
        this.panelTotal.add(labelSolde, c);
141
 
142
        c.gridx++;
143
        this.panelTotal.add(this.montantSolde, c);
144
 
174 ilm 145
        c.gridy = 2;
18 ilm 146
        c.gridx = 1;
147
        c.weightx = 0;
148
        c.fill = GridBagConstraints.NONE;
149
        this.add(this.panelTotal, c);
150
 
151
        // Mise à jour des totaux Solde, débit, crédit
152
        this.panelEcritures.getListe().addListener(new TableModelListener() {
153
 
154
            public void tableChanged(TableModelEvent e) {
155
 
156
                long totalDebit = 0;
157
                long totalCredit = 0;
158
                TableModel tableModel = ListeDesEcrituresPanel.this.panelEcritures.getListe().getTableModel();
159
 
160
                if (tableModel instanceof ITableModel) {
161
                    final ITableModel model = ListeDesEcrituresPanel.this.panelEcritures.getListe().getModel();
162
                    for (int i = 0; i < model.getRowCount(); i++) {
163
                        // no need to handle sorter since we don't care about order
164
                        final SQLRowValues ecritureRow = model.getRow(i).getRow();
165
 
166
                        totalDebit += ((Long) ecritureRow.getObject("DEBIT")).longValue();
167
                        totalCredit += ((Long) ecritureRow.getObject("CREDIT")).longValue();
168
                    }
169
 
170
                    ListeDesEcrituresPanel.this.montantDebit.setText(GestionDevise.currencyToString(totalDebit));
171
                    ListeDesEcrituresPanel.this.montantCredit.setText(GestionDevise.currencyToString(totalCredit));
172
                    ListeDesEcrituresPanel.this.montantSolde.setText(GestionDevise.currencyToString(totalDebit - totalCredit));
173
                }
174
            }
175
        });
176
    }
177
 
178
    public ListPanelEcritures getListPanelEcritures() {
179
        return this.panelEcritures;
180
    }
181
}