OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | 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;
174 ilm 21
import org.openconcerto.utils.NoneSelectedButtonGroup;
18 ilm 22
import org.openconcerto.utils.Tuple2;
23
 
80 ilm 24
import java.awt.FlowLayout;
18 ilm 25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
149 ilm 29
import java.util.Calendar;
18 ilm 30
import java.util.Date;
31
import java.util.Map;
32
 
33
import javax.swing.DefaultComboBoxModel;
34
import javax.swing.JButton;
149 ilm 35
import javax.swing.JCheckBox;
18 ilm 36
import javax.swing.JComboBox;
37
import javax.swing.JFrame;
38
import javax.swing.JLabel;
39
import javax.swing.JPanel;
40
import javax.swing.SwingUtilities;
41
 
42
public class EtatVentesPanel extends JPanel implements ActionListener {
43
 
44
    private JDate du, au;
45
    private JButton buttonGen = new JButton("Créer");
46
    private JButton buttonClose = new JButton("Fermer");
174 ilm 47
    private JCheckBox boxTicket = new JCheckBox("Uniquement les ventes en caisse");
48
    private JCheckBox boxFacture = new JCheckBox("Uniquement les ventes sur facture");
18 ilm 49
 
50
    public EtatVentesPanel() {
51
        super(new GridBagLayout());
52
        GridBagConstraints c = new DefaultGridBagConstraints();
53
        c.gridwidth = GridBagConstraints.REMAINDER;
80 ilm 54
        c.anchor = GridBagConstraints.EAST;
18 ilm 55
        this.add(new JLabelBold("Etat des Ventes"), c);
56
 
57
        c.gridwidth = 1;
58
        c.gridy++;
59
        c.anchor = GridBagConstraints.WEST;
60
 
61
        // Période pédéfini
62
        final Map<String, Tuple2<Date, Date>> map = IListFilterDatePanel.getDefaultMap();
63
        if (map != null && map.keySet().size() > 0) {
80 ilm 64
            final JPanel p = new JPanel();
65
            p.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 1));
66
            final DefaultComboBoxModel model = new DefaultComboBoxModel();
149 ilm 67
            Calendar cal = Calendar.getInstance();
68
            cal.set(Calendar.HOUR_OF_DAY, 0);
69
            cal.set(Calendar.MINUTE, 0);
70
            cal.set(Calendar.SECOND, 0);
71
            Date d1 = cal.getTime();
72
            cal.set(Calendar.HOUR_OF_DAY, 23);
73
            cal.set(Calendar.MINUTE, 59);
74
            cal.set(Calendar.SECOND, 59);
75
            Date d2 = cal.getTime();
76
            map.put("Aujourd'hui", Tuple2.create(d1, d2));
18 ilm 77
            for (String s : map.keySet()) {
78
                model.addElement(s);
79
            }
80
 
81
            final JComboBox combo = new JComboBox(model);
82
            c.weightx = 0;
80 ilm 83
            c.gridwidth = 4;
84
            p.add(new JLabel("Période "));
85
            p.add(combo);
86
            c.fill = GridBagConstraints.NONE;
87
            this.add(p, c);
88
            c.gridy++;
18 ilm 89
            combo.addActionListener(new ActionListener() {
90
                @Override
91
                public void actionPerformed(ActionEvent e) {
92
                    String s = (String) combo.getSelectedItem();
93
                    setPeriode(map.get(s));
94
                }
95
            });
96
        }
80 ilm 97
        c.gridwidth = 1;
98
        c.weightx = 0;
99
        c.fill = GridBagConstraints.HORIZONTAL;
100
        this.add(new JLabel("Du"), c);
18 ilm 101
 
102
        c.gridx++;
80 ilm 103
        c.weightx = 1;
104
        this.du = new JDate(false);
18 ilm 105
        this.add(this.du, c);
106
 
107
        c.gridx++;
80 ilm 108
        c.weightx = 0;
18 ilm 109
        this.add(new JLabel("au"), c);
110
 
111
        c.gridx++;
80 ilm 112
        c.weightx = 1;
113
        this.au = new JDate(false);
18 ilm 114
        this.add(this.au, c);
115
 
116
        c.gridy++;
117
        c.gridx = 0;
149 ilm 118
        c.weightx = 1;
119
        c.gridwidth = GridBagConstraints.REMAINDER;
18 ilm 120
 
149 ilm 121
        this.add(boxTicket, c);
122
 
123
        c.gridy++;
124
        c.gridx = 0;
174 ilm 125
        c.weightx = 1;
126
        c.gridwidth = GridBagConstraints.REMAINDER;
149 ilm 127
 
174 ilm 128
        this.add(boxFacture, c);
129
 
130
        NoneSelectedButtonGroup grou = new NoneSelectedButtonGroup();
131
        grou.add(boxFacture);
132
        grou.add(boxTicket);
133
 
134
        c.gridy++;
135
        c.gridx = 0;
136
 
18 ilm 137
        JPanel panelButton = new JPanel();
138
        panelButton.add(this.buttonGen);
139
        panelButton.add(this.buttonClose);
140
        c.gridwidth = GridBagConstraints.REMAINDER;
141
        c.fill = GridBagConstraints.NONE;
80 ilm 142
        c.anchor = GridBagConstraints.SOUTHEAST;
143
        c.weightx = 1;
18 ilm 144
        this.add(panelButton, c);
145
        this.buttonGen.addActionListener(this);
146
        this.buttonClose.addActionListener(this);
147
    }
148
 
149
    public void setPeriode(Tuple2<Date, Date> t) {
150
        if (t == null) {
151
            setPeriode(null, null);
152
        } else {
153
            setPeriode(t.get0(), t.get1());
154
        }
155
    }
156
 
157
    public void setDateDu(Date d) {
80 ilm 158
        if (d != null) {
159
            d.setHours(0);
160
            d.setMinutes(0);
161
        }
18 ilm 162
        this.du.setValue(d);
163
    }
164
 
165
    public void setDateAu(Date d) {
80 ilm 166
        if (d != null) {
167
            d.setHours(23);
168
            d.setMinutes(59);
169
        }
18 ilm 170
        this.au.setValue(d);
171
    }
172
 
173
    private void setPeriode(Date du, Date au) {
174
        setDateAu(au);
175
        setDateDu(du);
176
    }
177
 
178
    @Override
179
    public void actionPerformed(ActionEvent e) {
180
        if (e.getSource() == this.buttonGen) {
80 ilm 181
            final Date start = this.du.getDate();
182
            final Date stop = this.au.getDate();
174 ilm 183
            final EtatVentesXmlSheet sheet = new EtatVentesXmlSheet(start, stop, boxTicket.isSelected(), boxFacture.isSelected());
18 ilm 184
            try {
25 ilm 185
                // FIXME probleme de rendu avec le viewer
186
                sheet.createDocumentAsynchronous().get();
187
                sheet.openDocument(false);
188
            } catch (Exception e1) {
18 ilm 189
                e1.printStackTrace();
190
            }
191
 
192
        }
193
        ((JFrame) SwingUtilities.getRoot(this)).dispose();
194
    }
195
}