OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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