OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | 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
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.finance.accounting.report.BalanceSheet;
18
import org.openconcerto.erp.generationDoc.SpreadSheetGeneratorCompta;
19
import org.openconcerto.erp.generationDoc.SpreadSheetGeneratorListener;
20
import org.openconcerto.erp.preferences.DefaultNXProps;
21
import org.openconcerto.sql.Configuration;
22
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.ui.DefaultGridBagConstraints;
24
import org.openconcerto.ui.JDate;
25
 
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.beans.PropertyChangeEvent;
31
import java.beans.PropertyChangeListener;
32
import java.util.Date;
33
 
34
import javax.swing.JButton;
35
import javax.swing.JCheckBox;
36
import javax.swing.JFrame;
37
import javax.swing.JLabel;
38
import javax.swing.JPanel;
39
import javax.swing.JProgressBar;
40
import javax.swing.JTextField;
41
import javax.swing.SwingUtilities;
42
 
43
public class ImpressionBalancePanel extends JPanel implements SpreadSheetGeneratorListener {
44
 
132 ilm 45
    private final JDate dateEnd, dateStart;
18 ilm 46
    private JButton valid;
47
    private JButton annul;
48
    private JCheckBox checkImpr;
49
    private JCheckBox checkVisu;
50
    private JCheckBox checkClientCentral;
51
    private JCheckBox checkFournCentral;
132 ilm 52
    private JCheckBox checkFournImmoCentral;
177 ilm 53
    private JCheckBox checkTotalRacine;
18 ilm 54
    private JProgressBar bar = new JProgressBar(0, 3);
55
    private JTextField compteDeb, compteEnd;
56
 
57
    public ImpressionBalancePanel() {
58
        this.setLayout(new GridBagLayout());
59
        final GridBagConstraints c = new DefaultGridBagConstraints();
60
 
61
        SQLRow rowSociete = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
62
        SQLRow rowExercice = Configuration.getInstance().getBase().getTable("EXERCICE_COMMON").getRow(rowSociete.getInt("ID_EXERCICE_COMMON"));
63
 
64
        this.dateEnd = new JDate();
132 ilm 65
        this.dateStart = new JDate();
18 ilm 66
 
67
        // Période
93 ilm 68
        this.add(new JLabel("Balance au"), c);
18 ilm 69
        c.gridx++;
70
        c.weightx = 1;
132 ilm 71
        this.add(this.dateStart, c);
72
        c.gridx++;
73
        c.weightx = 1;
74
        c.gridwidth = 2;
18 ilm 75
        this.add(this.dateEnd, c);
76
        // Chargement des valeurs par défaut
77
        String valueDateEnd = DefaultNXProps.getInstance().getStringProperty("BalanceDateEnd");
78
        if (valueDateEnd.trim().length() > 0) {
79
            Long l = new Long(valueDateEnd);
80
            this.dateEnd.setValue(new Date(l.longValue()));
81
        } else {
82
            this.dateEnd.setValue((Date) rowExercice.getObject("DATE_FIN"));
83
        }
84
 
85
        // Compte
86
        this.compteDeb = new JTextField();
87
        this.compteEnd = new JTextField();
88
        c.gridy++;
89
        c.gridx = 0;
132 ilm 90
        c.gridwidth = 1;
18 ilm 91
        this.add(new JLabel("Du compte "), c);
92
        c.gridx++;
93
        c.weightx = 1;
94
        this.add(this.compteDeb, c);
95
        this.compteDeb.setText("1");
96
        this.compteEnd.setText("9");
97
 
98
        c.gridx++;
99
        c.weightx = 0;
100
        this.add(new JLabel("Au"), c);
101
        c.gridx++;
102
        c.weightx = 1;
103
        this.add(this.compteEnd, c);
104
 
105
        // Centralisation Clients
106
        c.gridy++;
107
        c.gridwidth = GridBagConstraints.REMAINDER;
108
        c.gridx = 0;
109
        this.checkClientCentral = new JCheckBox("Centralisation des comptes clients");
110
        this.add(this.checkClientCentral, c);
111
 
112
        // Centralisation Fournisseurs
113
        c.gridy++;
114
        c.gridwidth = GridBagConstraints.REMAINDER;
115
        c.gridx = 0;
116
        this.checkFournCentral = new JCheckBox("Centralisation des comptes fournisseurs");
117
        this.add(this.checkFournCentral, c);
118
 
132 ilm 119
        // Centralisation Fournisseurs
120
        c.gridy++;
121
        c.gridwidth = GridBagConstraints.REMAINDER;
122
        c.gridx = 0;
123
        this.checkFournImmoCentral = new JCheckBox("Centralisation des comptes fournisseurs d'immobilisations");
124
        this.add(this.checkFournImmoCentral, c);
125
 
177 ilm 126
        // Centralisation Fournisseurs
127
        c.gridy++;
128
        c.gridwidth = GridBagConstraints.REMAINDER;
129
        c.gridx = 0;
130
        this.checkTotalRacine = new JCheckBox("Total par racine");
131
        this.add(this.checkTotalRacine, c);
132
 
18 ilm 133
        // Progress bar
134
        c.gridwidth = GridBagConstraints.REMAINDER;
135
        c.gridy++;
136
        c.gridx = 0;
137
        c.weightx = 1;
138
        c.weighty = 0;
139
        c.fill = GridBagConstraints.HORIZONTAL;
140
        this.bar.setStringPainted(true);
141
        this.add(this.bar, c);
142
 
143
        this.valid = new JButton("Valider");
144
        this.annul = new JButton("Fermer");
145
        this.checkImpr = new JCheckBox("Impression");
146
        this.checkVisu = new JCheckBox("Visualisation");
147
 
148
        c.gridwidth = 2;
149
        c.gridy++;
150
        c.weightx = 0;
151
        c.weighty = 0;
152
        this.add(this.checkImpr, c);
153
        this.checkImpr.setSelected(true);
154
        c.gridx += 2;
155
        this.add(this.checkVisu, c);
156
 
157
        c.gridy++;
158
        c.gridx = 0;
159
        c.fill = GridBagConstraints.NONE;
160
        c.anchor = GridBagConstraints.CENTER;
161
        this.add(this.valid, c);
162
        c.gridx += 2;
163
        this.add(this.annul, c);
164
        checkValidity();
165
        this.valid.addActionListener(new ActionListener() {
166
            public void actionPerformed(ActionEvent e) {
167
                valid.setEnabled(false);
168
 
169
                bar.setString(null);
170
                bar.setValue(1);
171
                new Thread(new Runnable() {
172
                    public void run() {
132 ilm 173
                        BalanceSheet bSheet = new BalanceSheet(dateStart.getDate(), dateEnd.getDate(), compteDeb.getText(), compteEnd.getText(), checkClientCentral.isSelected(),
177 ilm 174
                                checkFournCentral.isSelected(), checkFournImmoCentral.isSelected(), checkTotalRacine.isSelected());
18 ilm 175
                        final SpreadSheetGeneratorCompta generator = new SpreadSheetGeneratorCompta(bSheet, "Balance" + new Date().getTime(), checkImpr.isSelected(), checkVisu.isSelected());
176
 
177
                        SwingUtilities.invokeLater(new Runnable() {
178
                            public void run() {
179
                                bar.setValue(2);
180
                                generator.addGenerateListener(ImpressionBalancePanel.this);
181
                            }
182
                        });
183
                    }
184
                }).start();
185
 
186
            }
187
        });
188
        this.annul.addActionListener(new ActionListener() {
189
            public void actionPerformed(ActionEvent e) {
190
                ((JFrame) SwingUtilities.getRoot(ImpressionBalancePanel.this)).dispose();
191
            }
192
        });
193
 
194
        this.dateEnd.addValueListener(new PropertyChangeListener() {
195
            public void propertyChange(PropertyChangeEvent evt) {
196
                checkValidity();
197
                storeValue();
198
            }
199
        });
200
    }
201
 
202
    private void checkValidity() {
203
        Date endDate = this.dateEnd.getDate();
204
 
205
        // System.err.println("Check validity between ");
93 ilm 206
        if (endDate == null) {
18 ilm 207
            this.valid.setEnabled(false);
208
        } else {
93 ilm 209
            this.valid.setEnabled(true);
18 ilm 210
        }
211
    }
212
 
213
    private void storeValue() {
214
 
215
        // Set date Fin
216
        Date dFin = this.dateEnd.getDate();
217
        if (dFin != null) {
218
            DefaultNXProps.getInstance().setProperty("BalanceDateEnd", String.valueOf(dFin.getTime()));
219
        }
220
 
221
        DefaultNXProps.getInstance().store();
222
    }
223
 
224
    public void taskEnd() {
225
        bar.setValue(3);
226
        bar.setString("Terminée");
227
        valid.setEnabled(true);
228
    }
229
}