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.sales.invoice.report.ListeVenteXmlSheet;
|
|
|
17 |
import org.openconcerto.sql.Configuration;
|
|
|
18 |
import org.openconcerto.sql.model.SQLDataSource;
|
|
|
19 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
20 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
|
|
21 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
22 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
23 |
import org.openconcerto.sql.model.Where;
|
|
|
24 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
25 |
import org.openconcerto.ui.JDate;
|
|
|
26 |
import org.openconcerto.ui.JLabelBold;
|
25 |
ilm |
27 |
import org.openconcerto.utils.ExceptionHandler;
|
18 |
ilm |
28 |
|
|
|
29 |
import java.awt.GridBagConstraints;
|
|
|
30 |
import java.awt.GridBagLayout;
|
|
|
31 |
import java.awt.event.ActionEvent;
|
|
|
32 |
import java.awt.event.ActionListener;
|
|
|
33 |
import java.util.List;
|
|
|
34 |
|
|
|
35 |
import javax.swing.JButton;
|
|
|
36 |
import javax.swing.JFrame;
|
|
|
37 |
import javax.swing.JLabel;
|
|
|
38 |
import javax.swing.JPanel;
|
19 |
ilm |
39 |
import javax.swing.JProgressBar;
|
18 |
ilm |
40 |
import javax.swing.SwingUtilities;
|
|
|
41 |
|
|
|
42 |
public class GenListeVentePanel extends JPanel implements ActionListener {
|
|
|
43 |
|
|
|
44 |
private final JButton buttonGen = new JButton("Créer");
|
|
|
45 |
private final JDate du;
|
|
|
46 |
private final JDate au;
|
19 |
ilm |
47 |
JProgressBar bar = new JProgressBar();
|
18 |
ilm |
48 |
|
|
|
49 |
public GenListeVentePanel() {
|
|
|
50 |
super(new GridBagLayout());
|
|
|
51 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
52 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
53 |
c.anchor = GridBagConstraints.CENTER;
|
|
|
54 |
this.add(new JLabelBold("Journal des Ventes"), 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 |
this.du = new JDate(true);
|
|
|
63 |
this.add(this.du, c);
|
|
|
64 |
|
|
|
65 |
c.gridx++;
|
|
|
66 |
this.add(new JLabel("au"), c);
|
|
|
67 |
|
|
|
68 |
c.gridx++;
|
|
|
69 |
this.au = new JDate(true);
|
|
|
70 |
this.add(this.au, c);
|
|
|
71 |
|
|
|
72 |
c.gridy++;
|
|
|
73 |
c.gridx = 0;
|
19 |
ilm |
74 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
75 |
c.weightx = 1;
|
|
|
76 |
this.add(this.bar, c);
|
18 |
ilm |
77 |
|
19 |
ilm |
78 |
c.gridy++;
|
|
|
79 |
c.gridx = 0;
|
|
|
80 |
c.gridwidth = 1;
|
18 |
ilm |
81 |
JPanel panelButton = new JPanel();
|
|
|
82 |
panelButton.add(this.buttonGen);
|
|
|
83 |
final JButton buttonClose = new JButton("Fermer");
|
|
|
84 |
panelButton.add(buttonClose);
|
|
|
85 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
86 |
c.fill = GridBagConstraints.NONE;
|
|
|
87 |
c.anchor = GridBagConstraints.CENTER;
|
|
|
88 |
c.weightx = 0;
|
|
|
89 |
this.add(panelButton, c);
|
|
|
90 |
this.buttonGen.addActionListener(this);
|
|
|
91 |
buttonClose.addActionListener(this);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
@Override
|
|
|
95 |
public void actionPerformed(ActionEvent e) {
|
|
|
96 |
if (e.getSource() == this.buttonGen) {
|
19 |
ilm |
97 |
final Thread thread = new Thread(new Runnable() {
|
|
|
98 |
public void run() {
|
|
|
99 |
try {
|
25 |
ilm |
100 |
SQLTable tableFact = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE").getTable();
|
|
|
101 |
SQLTable tableAvoir = Configuration.getInstance().getDirectory().getElement("AVOIR_CLIENT").getTable();
|
|
|
102 |
SQLSelect sel = new SQLSelect(Configuration.getInstance().getBase());
|
|
|
103 |
final SQLDataSource dataSource = Configuration.getInstance().getBase().getDataSource();
|
|
|
104 |
sel.addSelectStar(tableFact);
|
|
|
105 |
sel.setDistinct(true);
|
|
|
106 |
sel.setWhere(new Where(tableFact.getField("DATE"), GenListeVentePanel.this.du.getDate(), GenListeVentePanel.this.au.getDate()));
|
|
|
107 |
List<SQLRow> l = (List<SQLRow>) dataSource.execute(sel.asString(), SQLRowListRSH.createFromSelect(sel, tableFact));
|
|
|
108 |
SQLSelect sel2 = new SQLSelect(Configuration.getInstance().getBase());
|
|
|
109 |
sel2.addSelectStar(tableAvoir);
|
|
|
110 |
sel2.setWhere(new Where(tableAvoir.getField("DATE"), GenListeVentePanel.this.du.getDate(), GenListeVentePanel.this.au.getDate()));
|
|
|
111 |
sel2.setDistinct(true);
|
|
|
112 |
l.addAll((List<SQLRow>) dataSource.execute(sel2.asString(), SQLRowListRSH.createFromSelect(sel2, tableAvoir)));
|
|
|
113 |
ListeVenteXmlSheet sheet = new ListeVenteXmlSheet(l, GenListeVentePanel.this.du.getDate(), GenListeVentePanel.this.au.getDate(), GenListeVentePanel.this.bar);
|
|
|
114 |
|
|
|
115 |
sheet.createDocumentAsynchronous().get();
|
|
|
116 |
sheet.showPrintAndExport(true, false, false);
|
|
|
117 |
} catch (Exception e) {
|
|
|
118 |
ExceptionHandler.handle("Erreur de traitement", e);
|
19 |
ilm |
119 |
}
|
|
|
120 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
121 |
public void run() {
|
|
|
122 |
((JFrame) SwingUtilities.getRoot(GenListeVentePanel.this)).dispose();
|
|
|
123 |
}
|
|
|
124 |
});
|
|
|
125 |
}
|
|
|
126 |
});
|
|
|
127 |
thread.start();
|
|
|
128 |
} else {
|
|
|
129 |
((JFrame) SwingUtilities.getRoot(this)).dispose();
|
18 |
ilm |
130 |
}
|
|
|
131 |
}
|
|
|
132 |
}
|