OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
144 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.
144 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
 package org.openconcerto.erp.core.sales.invoice.ui;
15
 
16
import org.openconcerto.erp.core.sales.invoice.report.ReportingVenteXmlSheet;
17
import org.openconcerto.ui.DefaultGridBagConstraints;
18
import org.openconcerto.ui.JDate;
19
import org.openconcerto.ui.JLabelBold;
20
import org.openconcerto.utils.ExceptionHandler;
21
 
22
import java.awt.Dimension;
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
182 ilm 27
import java.util.Collections;
144 ilm 28
import java.util.List;
29
 
30
import javax.swing.JButton;
31
import javax.swing.JFrame;
32
import javax.swing.JLabel;
33
import javax.swing.JPanel;
34
import javax.swing.JProgressBar;
35
import javax.swing.JScrollPane;
36
import javax.swing.JTable;
37
import javax.swing.SwingUtilities;
38
 
39
public class GenReportingVentePanel extends JPanel implements ActionListener {
40
 
41
    private final JButton buttonGen = new JButton("Créer");
42
    private final JDate du;
43
    private final JDate au;
44
    JProgressBar bar = new JProgressBar();
45
    private JTable table;
46
    private final boolean commande;
47
 
48
    public GenReportingVentePanel(final boolean commande) {
49
        super(new GridBagLayout());
50
        this.commande = commande;
51
        GridBagConstraints c = new DefaultGridBagConstraints();
52
        c.gridwidth = GridBagConstraints.REMAINDER;
53
        c.anchor = GridBagConstraints.CENTER;
54
        this.add(new JLabelBold("Reporting des " + (commande ? "commandes" : "factures")), c);
55
 
56
        c.gridwidth = 1;
57
        c.gridy++;
58
        c.anchor = GridBagConstraints.WEST;
59
        this.add(new JLabel("Du"), c);
60
 
61
        c.gridx++;
62
        c.weightx = 1;
63
        this.du = new JDate(true);
64
        this.add(this.du, c);
65
 
66
        c.gridx++;
67
        c.weightx = 0;
68
        this.add(new JLabel("au"), c);
69
 
70
        c.gridx++;
71
        c.weightx = 1;
72
        this.au = new JDate(true);
73
        this.add(this.au, c);
74
 
75
        this.table = new JTable(new SelectCommerciauxModel());
76
        JScrollPane scroll = new JScrollPane(this.table);
77
        Dimension d;
78
        if (this.table.getPreferredSize().height > 200) {
79
            d = new Dimension(scroll.getPreferredSize().width, 200);
80
        } else {
81
            d = new Dimension(scroll.getPreferredSize().width, this.table.getPreferredSize().height + 30);
82
        }
83
        scroll.setPreferredSize(d);
84
        c.gridx++;
85
        c.gridwidth = GridBagConstraints.REMAINDER;
86
        this.add(scroll, c);
87
 
88
        c.gridy++;
89
        c.gridx = 0;
90
        c.gridwidth = GridBagConstraints.REMAINDER;
91
        c.weightx = 1;
92
        this.add(this.bar, c);
93
 
94
        c.gridy++;
95
        c.gridx = 0;
96
        c.gridwidth = 1;
97
        JPanel panelButton = new JPanel();
98
        panelButton.add(this.buttonGen);
99
        final JButton buttonClose = new JButton("Fermer");
100
        panelButton.add(buttonClose);
101
        c.gridwidth = GridBagConstraints.REMAINDER;
102
        c.fill = GridBagConstraints.NONE;
103
        c.anchor = GridBagConstraints.SOUTHEAST;
104
        c.weightx = 0;
105
        c.weighty = 1;
106
        this.add(panelButton, c);
107
        this.buttonGen.addActionListener(this);
108
        buttonClose.addActionListener(this);
109
    }
110
 
111
    @Override
112
    public void actionPerformed(ActionEvent e) {
113
        if (e.getSource() == this.buttonGen) {
114
            final List<Integer> idS = ((SelectCommerciauxModel) table.getModel()).getSelectedIds(table.getSelectedRows());
115
            final Thread thread = new Thread(new Runnable() {
116
                public void run() {
117
                    try {
118
 
119
                        ReportingVenteXmlSheet sheet = new ReportingVenteXmlSheet(idS, GenReportingVentePanel.this.du.getDate(), GenReportingVentePanel.this.au.getDate(),
120
                                GenReportingVentePanel.this.bar, commande);
121
 
122
                        sheet.createDocumentAsynchronous().get();
182 ilm 123
                        sheet.showPrintAndExport(true, false, false, false, false, Collections.emptyList());
144 ilm 124
                    } catch (Exception e) {
125
                        ExceptionHandler.handle("Erreur de traitement", e);
126
                    }
127
                    SwingUtilities.invokeLater(new Runnable() {
128
                        public void run() {
129
                            ((JFrame) SwingUtilities.getRoot(GenReportingVentePanel.this)).dispose();
130
                        }
131
                    });
132
                }
133
            });
134
            thread.start();
135
        } else {
136
            ((JFrame) SwingUtilities.getRoot(this)).dispose();
137
        }
138
    }
139
}