OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 94 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
83 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
83 ilm 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
 /*
15
 * Créé le 23 avr. 2012
16
 */
17
package org.openconcerto.erp.core.finance.accounting.report;
18
 
19
import org.openconcerto.erp.config.ComptaPropsConfiguration;
20
import org.openconcerto.erp.config.Gestion;
21
import org.openconcerto.erp.preferences.DefaultNXProps;
22
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.element.SQLElement;
24
import org.openconcerto.sql.model.SQLRow;
25
import org.openconcerto.sql.request.ComboSQLRequest;
26
import org.openconcerto.sql.sqlobject.ElementComboBox;
27
import org.openconcerto.ui.DefaultGridBagConstraints;
28
import org.openconcerto.ui.JDate;
29
 
30
import java.awt.GridBagConstraints;
31
import java.awt.GridBagLayout;
32
import java.awt.event.ActionEvent;
33
import java.beans.PropertyChangeEvent;
34
import java.beans.PropertyChangeListener;
35
import java.io.File;
36
import java.util.Calendar;
182 ilm 37
import java.util.Collections;
83 ilm 38
import java.util.Date;
39
import java.util.concurrent.ExecutionException;
40
 
41
import javax.swing.AbstractAction;
42
import javax.swing.JButton;
43
import javax.swing.JComboBox;
44
import javax.swing.JLabel;
45
import javax.swing.JPanel;
46
import javax.swing.SwingConstants;
47
 
48
import org.jopenchart.Chart;
49
 
50
public class VentilationAnalytiquePanel extends JPanel {
51
 
52
    private final JDate dateDeb, dateEnd;
53
 
54
    public VentilationAnalytiquePanel() {
55
        super(new GridBagLayout());
56
 
57
        SQLRow rowSociete = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
58
        SQLRow rowExercice = Configuration.getInstance().getBase().getTable("EXERCICE_COMMON").getRow(rowSociete.getInt("ID_EXERCICE_COMMON"));
59
 
60
        this.dateDeb = new JDate();
61
        this.dateEnd = new JDate();
62
 
63
        JLabel labelPoste = new JLabel("Poste Analytique");
64
        final ElementComboBox box = new ElementComboBox(false);
65
        SQLElement element = Configuration.getInstance().getDirectory().getElement("POSTE_ANALYTIQUE");
66
        ComboSQLRequest comboRequest = element.getComboRequest(true);
67
        box.init(element, comboRequest);
68
 
69
        GridBagConstraints c = new DefaultGridBagConstraints();
70
        this.add(labelPoste, c);
71
        c.gridx++;
94 ilm 72
        c.gridwidth = GridBagConstraints.REMAINDER;
83 ilm 73
        this.add(box, c);
74
 
94 ilm 75
        c.gridx = 0;
76
        c.gridy++;
77
        c.gridwidth = 1;
78
        c.fill = GridBagConstraints.NONE;
79
        c.weightx = 0;
83 ilm 80
        this.add(new JLabel("Période du", SwingConstants.RIGHT), c);
81
        c.gridx++;
94 ilm 82
        c.weightx = 0;
83 ilm 83
        this.add(this.dateDeb, c);
84
        // Chargement des valeurs par défaut
85
        // String valueDateDeb = DefaultNXProps.getInstance().getStringProperty("JournauxDateDeb");
86
        // if (valueDateDeb.trim().length() > 0) {
87
        // Long l = new Long(valueDateDeb);
88
        // this.dateDeb.setValue(new Date(l.longValue()));
89
        // } else {
90
        this.dateDeb.setValue((Date) rowExercice.getObject("DATE_DEB"));
91
        // }
92
 
93
        c.gridx++;
94
        c.weightx = 0;
94 ilm 95
 
83 ilm 96
        this.add(new JLabel("Au"), c);
97
        c.gridx++;
94 ilm 98
        c.weightx = 0;
83 ilm 99
        this.add(this.dateEnd, c);
100
 
94 ilm 101
        c.gridx++;
102
        c.weightx = 1;
103
        c.fill = GridBagConstraints.HORIZONTAL;
104
        this.add(new JLabel(), c);
105
 
83 ilm 106
        final JButton buttonValid = new JButton(new AbstractAction("Valider") {
107
 
108
            @Override
109
            public void actionPerformed(ActionEvent e) {
110
 
111
                new Thread() {
112
                    public void run() {
113
                        SQLRow poste = box.getSelectedRow();
114
                        VentilationAnalytiqueSheetXML sheet = new VentilationAnalytiqueSheetXML(dateDeb.getDate(), dateEnd.getDate(), poste);
115
                        try {
116
                            sheet.createDocument();
182 ilm 117
                            sheet.showPrintAndExport(true, false, false, Collections.emptyList());
83 ilm 118
                        } catch (InterruptedException e) {
119
                            // TODO Auto-generated catch block
120
                            e.printStackTrace();
121
                        } catch (ExecutionException e) {
122
                            // TODO Auto-generated catch block
123
                            e.printStackTrace();
124
                        }
125
                    };
126
                }.start();
127
 
128
            }
129
        });
94 ilm 130
        c.gridx = 0;
131
        c.gridy++;
132
        c.gridwidth = GridBagConstraints.REMAINDER;
133
        c.anchor = GridBagConstraints.EAST;
134
        c.fill = GridBagConstraints.NONE;
83 ilm 135
        this.add(buttonValid, c);
136
 
137
        // Check validity
138
        buttonValid.setEnabled(false);
139
        final PropertyChangeListener listener = new PropertyChangeListener() {
140
 
141
            @Override
142
            public void propertyChange(PropertyChangeEvent evt) {
143
                buttonValid.setEnabled(box.getSelectedRow() != null && !box.getSelectedRow().isUndefined() && dateDeb.getValue() != null && dateEnd.getValue() != null);
144
 
145
            }
146
        };
147
        box.addValueListener(listener);
148
        dateEnd.addValueListener(listener);
149
        dateDeb.addValueListener(listener);
150
    }
151
 
152
}