18 |
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.
|
18 |
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.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;
|
94 |
ilm |
33 |
import java.util.ArrayList;
|
174 |
ilm |
34 |
import java.util.Collections;
|
|
|
35 |
import java.util.Comparator;
|
18 |
ilm |
36 |
import java.util.List;
|
|
|
37 |
|
|
|
38 |
import javax.swing.JButton;
|
|
|
39 |
import javax.swing.JFrame;
|
|
|
40 |
import javax.swing.JLabel;
|
|
|
41 |
import javax.swing.JPanel;
|
19 |
ilm |
42 |
import javax.swing.JProgressBar;
|
18 |
ilm |
43 |
import javax.swing.SwingUtilities;
|
|
|
44 |
|
|
|
45 |
public class GenListeVentePanel extends JPanel implements ActionListener {
|
|
|
46 |
|
|
|
47 |
private final JButton buttonGen = new JButton("Créer");
|
|
|
48 |
private final JDate du;
|
|
|
49 |
private final JDate au;
|
19 |
ilm |
50 |
JProgressBar bar = new JProgressBar();
|
18 |
ilm |
51 |
|
|
|
52 |
public GenListeVentePanel() {
|
|
|
53 |
super(new GridBagLayout());
|
|
|
54 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
55 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
56 |
c.anchor = GridBagConstraints.CENTER;
|
|
|
57 |
this.add(new JLabelBold("Journal des Ventes"), c);
|
|
|
58 |
|
|
|
59 |
c.gridwidth = 1;
|
|
|
60 |
c.gridy++;
|
|
|
61 |
c.anchor = GridBagConstraints.WEST;
|
41 |
ilm |
62 |
this.add(new JLabel("Du"), c);
|
18 |
ilm |
63 |
|
|
|
64 |
c.gridx++;
|
41 |
ilm |
65 |
c.weightx = 1;
|
18 |
ilm |
66 |
this.du = new JDate(true);
|
|
|
67 |
this.add(this.du, c);
|
|
|
68 |
|
|
|
69 |
c.gridx++;
|
41 |
ilm |
70 |
c.weightx = 0;
|
18 |
ilm |
71 |
this.add(new JLabel("au"), c);
|
|
|
72 |
|
|
|
73 |
c.gridx++;
|
41 |
ilm |
74 |
c.weightx = 1;
|
18 |
ilm |
75 |
this.au = new JDate(true);
|
|
|
76 |
this.add(this.au, c);
|
|
|
77 |
|
|
|
78 |
c.gridy++;
|
|
|
79 |
c.gridx = 0;
|
19 |
ilm |
80 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
81 |
c.weightx = 1;
|
|
|
82 |
this.add(this.bar, c);
|
18 |
ilm |
83 |
|
19 |
ilm |
84 |
c.gridy++;
|
|
|
85 |
c.gridx = 0;
|
|
|
86 |
c.gridwidth = 1;
|
18 |
ilm |
87 |
JPanel panelButton = new JPanel();
|
|
|
88 |
panelButton.add(this.buttonGen);
|
|
|
89 |
final JButton buttonClose = new JButton("Fermer");
|
|
|
90 |
panelButton.add(buttonClose);
|
|
|
91 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
92 |
c.fill = GridBagConstraints.NONE;
|
41 |
ilm |
93 |
c.anchor = GridBagConstraints.SOUTHEAST;
|
18 |
ilm |
94 |
c.weightx = 0;
|
41 |
ilm |
95 |
c.weighty = 1;
|
18 |
ilm |
96 |
this.add(panelButton, c);
|
|
|
97 |
this.buttonGen.addActionListener(this);
|
|
|
98 |
buttonClose.addActionListener(this);
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
@Override
|
|
|
102 |
public void actionPerformed(ActionEvent e) {
|
|
|
103 |
if (e.getSource() == this.buttonGen) {
|
19 |
ilm |
104 |
final Thread thread = new Thread(new Runnable() {
|
|
|
105 |
public void run() {
|
|
|
106 |
try {
|
25 |
ilm |
107 |
SQLTable tableFact = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE").getTable();
|
|
|
108 |
SQLTable tableAvoir = Configuration.getInstance().getDirectory().getElement("AVOIR_CLIENT").getTable();
|
|
|
109 |
SQLSelect sel = new SQLSelect(Configuration.getInstance().getBase());
|
|
|
110 |
final SQLDataSource dataSource = Configuration.getInstance().getBase().getDataSource();
|
|
|
111 |
sel.addSelectStar(tableFact);
|
|
|
112 |
sel.setDistinct(true);
|
|
|
113 |
sel.setWhere(new Where(tableFact.getField("DATE"), GenListeVentePanel.this.du.getDate(), GenListeVentePanel.this.au.getDate()));
|
174 |
ilm |
114 |
List<SQLRow> l = new ArrayList((List<SQLRow>) dataSource.execute(sel.asString(), SQLRowListRSH.createFromSelect(sel, tableFact)));
|
|
|
115 |
Collections.sort(l, new Comparator<SQLRow>() {
|
|
|
116 |
@Override
|
|
|
117 |
public int compare(SQLRow o1, SQLRow o2) {
|
|
|
118 |
int dateComp = o1.getDate("DATE").compareTo(o2.getDate("DATE"));
|
|
|
119 |
if (dateComp == 0) {
|
|
|
120 |
return o1.getString("NUMERO").compareTo(o2.getString("NUMERO"));
|
|
|
121 |
} else {
|
|
|
122 |
return dateComp;
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
});
|
|
|
126 |
|
25 |
ilm |
127 |
SQLSelect sel2 = new SQLSelect(Configuration.getInstance().getBase());
|
|
|
128 |
sel2.addSelectStar(tableAvoir);
|
|
|
129 |
sel2.setWhere(new Where(tableAvoir.getField("DATE"), GenListeVentePanel.this.du.getDate(), GenListeVentePanel.this.au.getDate()));
|
|
|
130 |
sel2.setDistinct(true);
|
174 |
ilm |
131 |
List<SQLRow> l2 = new ArrayList((List<SQLRow>) dataSource.execute(sel2.asString(), SQLRowListRSH.createFromSelect(sel2, tableAvoir)));
|
|
|
132 |
Collections.sort(l2, new Comparator<SQLRow>() {
|
|
|
133 |
@Override
|
|
|
134 |
public int compare(SQLRow o1, SQLRow o2) {
|
|
|
135 |
int dateComp = o1.getDate("DATE").compareTo(o2.getDate("DATE"));
|
|
|
136 |
if (dateComp == 0) {
|
|
|
137 |
return o1.getString("NUMERO").compareTo(o2.getString("NUMERO"));
|
|
|
138 |
} else {
|
|
|
139 |
return dateComp;
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
});
|
25 |
ilm |
143 |
|
94 |
ilm |
144 |
List<SQLRow> lTotal = new ArrayList<SQLRow>();
|
|
|
145 |
lTotal.addAll(l);
|
|
|
146 |
lTotal.addAll(l2);
|
174 |
ilm |
147 |
|
94 |
ilm |
148 |
ListeVenteXmlSheet sheet = new ListeVenteXmlSheet(lTotal, GenListeVentePanel.this.du.getDate(), GenListeVentePanel.this.au.getDate(), GenListeVentePanel.this.bar);
|
|
|
149 |
|
25 |
ilm |
150 |
sheet.createDocumentAsynchronous().get();
|
182 |
ilm |
151 |
sheet.showPrintAndExport(true, false, false, Collections.emptyList());
|
25 |
ilm |
152 |
} catch (Exception e) {
|
|
|
153 |
ExceptionHandler.handle("Erreur de traitement", e);
|
19 |
ilm |
154 |
}
|
|
|
155 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
156 |
public void run() {
|
|
|
157 |
((JFrame) SwingUtilities.getRoot(GenListeVentePanel.this)).dispose();
|
|
|
158 |
}
|
|
|
159 |
});
|
|
|
160 |
}
|
|
|
161 |
});
|
|
|
162 |
thread.start();
|
|
|
163 |
} else {
|
|
|
164 |
((JFrame) SwingUtilities.getRoot(this)).dispose();
|
18 |
ilm |
165 |
}
|
|
|
166 |
}
|
|
|
167 |
}
|