OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 18 | Rev 80 | Go to most recent revision | 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.sales.invoice.ui;
15
 
16
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
17
import org.openconcerto.erp.generationDoc.gestcomm.EtatVentesXmlSheet;
18
import org.openconcerto.ui.DefaultGridBagConstraints;
19
import org.openconcerto.ui.JDate;
20
import org.openconcerto.ui.JLabelBold;
21
import org.openconcerto.utils.Tuple2;
22
 
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27
import java.util.Date;
28
import java.util.Map;
29
import java.util.concurrent.ExecutionException;
30
 
31
import javax.swing.DefaultComboBoxModel;
32
import javax.swing.JButton;
33
import javax.swing.JComboBox;
34
import javax.swing.JFrame;
35
import javax.swing.JLabel;
36
import javax.swing.JPanel;
37
import javax.swing.SwingUtilities;
38
 
39
public class EtatVentesPanel extends JPanel implements ActionListener {
40
 
41
    private JDate du, au;
42
    private JButton buttonGen = new JButton("Créer");
43
    private JButton buttonClose = new JButton("Fermer");
44
 
45
    public EtatVentesPanel() {
46
        super(new GridBagLayout());
47
        GridBagConstraints c = new DefaultGridBagConstraints();
48
        c.gridwidth = GridBagConstraints.REMAINDER;
49
        c.anchor = GridBagConstraints.CENTER;
50
        this.add(new JLabelBold("Etat des Ventes"), c);
51
 
52
        c.gridwidth = 1;
53
        c.gridy++;
54
        c.anchor = GridBagConstraints.WEST;
55
 
56
        // Période pédéfini
57
        final Map<String, Tuple2<Date, Date>> map = IListFilterDatePanel.getDefaultMap();
58
        if (map != null && map.keySet().size() > 0) {
59
            DefaultComboBoxModel model = new DefaultComboBoxModel();
60
            model.addElement("Tous");
61
            for (String s : map.keySet()) {
62
                model.addElement(s);
63
            }
64
 
65
            final JComboBox combo = new JComboBox(model);
66
            c.weightx = 0;
67
            this.add(combo, c);
68
 
69
            combo.addActionListener(new ActionListener() {
70
                @Override
71
                public void actionPerformed(ActionEvent e) {
72
                    String s = (String) combo.getSelectedItem();
73
                    setPeriode(map.get(s));
74
                }
75
            });
76
        }
77
 
78
        c.gridx++;
79
        this.add(new JLabel("du"), c);
80
 
81
        c.gridx++;
82
        this.du = new JDate(true);
83
        this.add(this.du, c);
84
 
85
        c.gridx++;
86
        this.add(new JLabel("au"), c);
87
 
88
        c.gridx++;
89
        this.au = new JDate(true);
90
        this.add(this.au, c);
91
 
92
        c.gridy++;
93
        c.gridx = 0;
94
 
95
        JPanel panelButton = new JPanel();
96
        panelButton.add(this.buttonGen);
97
        panelButton.add(this.buttonClose);
98
        c.gridwidth = GridBagConstraints.REMAINDER;
99
        c.fill = GridBagConstraints.NONE;
100
        c.anchor = GridBagConstraints.CENTER;
101
        c.weightx = 0;
102
        this.add(panelButton, c);
103
        this.buttonGen.addActionListener(this);
104
        this.buttonClose.addActionListener(this);
105
    }
106
 
107
    public void setPeriode(Tuple2<Date, Date> t) {
108
        if (t == null) {
109
            setPeriode(null, null);
110
        } else {
111
 
112
            setPeriode(t.get0(), t.get1());
113
        }
114
    }
115
 
116
    public void setDateDu(Date d) {
117
        d.setHours(0);
118
        d.setMinutes(0);
119
        this.du.setValue(d);
120
    }
121
 
122
    public void setDateAu(Date d) {
123
        d.setHours(23);
124
        d.setMinutes(59);
125
        this.au.setValue(d);
126
    }
127
 
128
    private void setPeriode(Date du, Date au) {
129
 
130
        setDateAu(au);
131
        setDateDu(du);
132
    }
133
 
134
    @Override
135
    public void actionPerformed(ActionEvent e) {
136
        if (e.getSource() == this.buttonGen) {
137
 
138
            EtatVentesXmlSheet sheet = new EtatVentesXmlSheet(this.du.getDate(), this.au.getDate());
139
            try {
25 ilm 140
                // FIXME probleme de rendu avec le viewer
141
                sheet.createDocumentAsynchronous().get();
142
                sheet.openDocument(false);
143
            } catch (Exception e1) {
18 ilm 144
                e1.printStackTrace();
145
            }
146
 
147
        }
148
        ((JFrame) SwingUtilities.getRoot(this)).dispose();
149
    }
150
}