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.pos.ui;
|
|
|
15 |
|
182 |
ilm |
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
144 |
ilm |
17 |
import org.openconcerto.erp.core.sales.pos.TicketPrinterConfiguration;
|
182 |
ilm |
18 |
import org.openconcerto.erp.core.sales.pos.TicketSheetXML;
|
149 |
ilm |
19 |
import org.openconcerto.erp.core.sales.pos.io.Printable;
|
144 |
ilm |
20 |
import org.openconcerto.erp.core.sales.pos.io.TicketPrinter;
|
149 |
ilm |
21 |
import org.openconcerto.erp.core.sales.pos.model.RegisterFiles;
|
|
|
22 |
import org.openconcerto.erp.core.sales.pos.model.RegisterLog;
|
144 |
ilm |
23 |
import org.openconcerto.erp.core.sales.pos.model.Ticket;
|
|
|
24 |
import org.openconcerto.ui.DefaultListModel;
|
|
|
25 |
import org.openconcerto.ui.touch.ScrollableList;
|
|
|
26 |
import org.openconcerto.utils.ExceptionHandler;
|
|
|
27 |
|
18 |
ilm |
28 |
import java.awt.Color;
|
|
|
29 |
import java.awt.Component;
|
|
|
30 |
import java.awt.Dimension;
|
142 |
ilm |
31 |
import java.awt.FlowLayout;
|
18 |
ilm |
32 |
import java.awt.Font;
|
|
|
33 |
import java.awt.Graphics;
|
|
|
34 |
import java.awt.Graphics2D;
|
|
|
35 |
import java.awt.GridBagConstraints;
|
|
|
36 |
import java.awt.GridBagLayout;
|
|
|
37 |
import java.awt.Insets;
|
|
|
38 |
import java.awt.RenderingHints;
|
142 |
ilm |
39 |
import java.awt.event.ActionEvent;
|
|
|
40 |
import java.awt.event.ActionListener;
|
149 |
ilm |
41 |
import java.io.IOException;
|
|
|
42 |
import java.text.ParseException;
|
|
|
43 |
import java.util.Calendar;
|
182 |
ilm |
44 |
import java.util.Collections;
|
149 |
ilm |
45 |
import java.util.Date;
|
|
|
46 |
import java.util.List;
|
18 |
ilm |
47 |
|
|
|
48 |
import javax.swing.JLabel;
|
|
|
49 |
import javax.swing.JList;
|
|
|
50 |
import javax.swing.JPanel;
|
|
|
51 |
import javax.swing.JScrollPane;
|
|
|
52 |
import javax.swing.ListCellRenderer;
|
|
|
53 |
import javax.swing.ListSelectionModel;
|
|
|
54 |
import javax.swing.event.ListSelectionEvent;
|
|
|
55 |
import javax.swing.event.ListSelectionListener;
|
|
|
56 |
|
149 |
ilm |
57 |
import org.jdom2.JDOMException;
|
|
|
58 |
|
18 |
ilm |
59 |
public class ListeDesTicketsPanel extends JPanel implements ListSelectionListener {
|
|
|
60 |
|
144 |
ilm |
61 |
private static final String ARIAL_FONT = "Arial";
|
149 |
ilm |
62 |
|
|
|
63 |
static private final class X extends RegisterSummary {
|
|
|
64 |
|
|
|
65 |
private final List<Ticket> receipts;
|
|
|
66 |
|
|
|
67 |
protected X(final RegisterLog log, final List<Ticket> receipts) {
|
|
|
68 |
super("X", log);
|
|
|
69 |
this.receipts = receipts;
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
@Override
|
|
|
73 |
protected final List<Ticket> getReceipts() {
|
|
|
74 |
return this.receipts;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
@Override
|
|
|
78 |
public String getLabel() {
|
|
|
79 |
return "Synthèse actuelle (X)";
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
static private final class XLite extends RegisterSummary {
|
|
|
84 |
|
|
|
85 |
private final List<Ticket> receipts;
|
|
|
86 |
|
|
|
87 |
protected XLite(final RegisterLog log, final List<Ticket> receipts) {
|
|
|
88 |
super("X", log);
|
|
|
89 |
this.receipts = receipts;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
@Override
|
|
|
93 |
public boolean isPrintingTicketsList() {
|
|
|
94 |
return false;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
@Override
|
|
|
98 |
protected final List<Ticket> getReceipts() {
|
|
|
99 |
return this.receipts;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
@Override
|
|
|
103 |
public String getLabel() {
|
|
|
104 |
return "Synthèse actuelle simplifiée (résumé du X)";
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
static private final class Z extends RegisterSummary {
|
|
|
109 |
|
|
|
110 |
protected Z(final RegisterFiles files, final Calendar day) throws IOException, JDOMException {
|
|
|
111 |
super("Z", new RegisterLog(files.getLogFile(day)).parse());
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
@Override
|
174 |
ilm |
115 |
protected final List<Ticket> getReceipts() throws ParseException, IOException {
|
149 |
ilm |
116 |
return this.getLog().parseReceipts();
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
@Override
|
|
|
120 |
public String getLabel() {
|
|
|
121 |
return "Synthèse précédente (Z)";
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
|
18 |
ilm |
125 |
private JList l;
|
|
|
126 |
private CaisseFrame frame;
|
142 |
ilm |
127 |
|
18 |
ilm |
128 |
private TextAreaTicketPrinter ticketP;
|
|
|
129 |
private ScrollableList ticketList;
|
|
|
130 |
private DefaultListModel ticketLlistModel;
|
|
|
131 |
|
|
|
132 |
ListeDesTicketsPanel(CaisseFrame caisseFrame) {
|
|
|
133 |
this.frame = caisseFrame;
|
|
|
134 |
this.setBackground(Color.WHITE);
|
|
|
135 |
this.setOpaque(true);
|
|
|
136 |
this.setLayout(new GridBagLayout());
|
|
|
137 |
GridBagConstraints c = new GridBagConstraints();
|
|
|
138 |
c.fill = GridBagConstraints.BOTH;
|
|
|
139 |
c.anchor = GridBagConstraints.CENTER;
|
|
|
140 |
c.weightx = 1;
|
|
|
141 |
c.weighty = 0;
|
|
|
142 |
c.gridx = 0;
|
|
|
143 |
c.gridy = 0;
|
|
|
144 |
c.gridwidth = 2;
|
|
|
145 |
|
|
|
146 |
// Place pour le menu
|
142 |
ilm |
147 |
StatusBar p = new StatusBar();
|
|
|
148 |
p.setTitle("Liste des tickets");
|
|
|
149 |
p.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
|
|
150 |
POSButton bBack = new POSButton("Fermer");
|
|
|
151 |
p.add(bBack);
|
|
|
152 |
|
18 |
ilm |
153 |
this.add(p, c);
|
|
|
154 |
|
|
|
155 |
// Liste des tickets
|
|
|
156 |
c.gridy++;
|
|
|
157 |
c.gridwidth = 1;
|
|
|
158 |
c.weighty = 1;
|
|
|
159 |
c.gridheight = 2;
|
|
|
160 |
|
144 |
ilm |
161 |
try {
|
149 |
ilm |
162 |
final RegisterLog lastLog = this.frame.getFiles().getLastLog();
|
|
|
163 |
final List<Ticket> receipts = lastLog.parseReceipts();
|
174 |
ilm |
164 |
this.ticketLlistModel = new DefaultListModel();
|
|
|
165 |
this.ticketLlistModel.addElement(new X(lastLog, receipts));
|
|
|
166 |
this.ticketLlistModel.addElement(new XLite(lastLog, receipts));
|
149 |
ilm |
167 |
final Date previousDate = lastLog.getFirstRegisterEvent().getPreviousDate();
|
|
|
168 |
if (previousDate != null) {
|
|
|
169 |
final Calendar cal = Calendar.getInstance();
|
|
|
170 |
cal.setTime(previousDate);
|
174 |
ilm |
171 |
this.ticketLlistModel.addElement(new Z(this.frame.getFiles(), cal));
|
149 |
ilm |
172 |
}
|
174 |
ilm |
173 |
this.ticketLlistModel.addAll(receipts);
|
149 |
ilm |
174 |
|
144 |
ilm |
175 |
} catch (Exception exn) {
|
|
|
176 |
ExceptionHandler.handle(this.frame, "Impossible de charger les tickets", exn);
|
|
|
177 |
}
|
|
|
178 |
final Font f = new Font(ARIAL_FONT, Font.PLAIN, 24);
|
174 |
ilm |
179 |
this.ticketList = new ScrollableList(this.ticketLlistModel) {
|
18 |
ilm |
180 |
@Override
|
|
|
181 |
public void paintCell(Graphics g, Object object, int index, boolean isSelected, int posY) {
|
|
|
182 |
g.setFont(f);
|
|
|
183 |
|
|
|
184 |
if (isSelected) {
|
|
|
185 |
g.setColor(new Color(232, 242, 254));
|
|
|
186 |
} else {
|
|
|
187 |
g.setColor(Color.WHITE);
|
|
|
188 |
}
|
|
|
189 |
g.fillRect(0, posY, getWidth(), getCellHeight());
|
|
|
190 |
|
|
|
191 |
//
|
|
|
192 |
g.setColor(Color.GRAY);
|
|
|
193 |
g.drawLine(0, posY + this.getCellHeight() - 1, this.getWidth(), posY + this.getCellHeight() - 1);
|
|
|
194 |
|
|
|
195 |
if (isSelected) {
|
|
|
196 |
g.setColor(Color.BLACK);
|
|
|
197 |
} else {
|
|
|
198 |
g.setColor(Color.GRAY);
|
|
|
199 |
}
|
|
|
200 |
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
149 |
ilm |
201 |
if (object instanceof Ticket) {
|
|
|
202 |
Ticket article = (Ticket) object;
|
|
|
203 |
String label = "Ticket " + article.getCode();
|
18 |
ilm |
204 |
|
149 |
ilm |
205 |
String euro = TicketCellRenderer.centsToString(article.getTotalInCents()) + "€";
|
18 |
ilm |
206 |
|
149 |
ilm |
207 |
int wEuro = (int) g.getFontMetrics().getStringBounds(euro, g).getWidth();
|
|
|
208 |
g.drawString(label, 10, posY + 39);
|
|
|
209 |
g.drawString(euro, getWidth() - 5 - wEuro, posY + 39);
|
|
|
210 |
} else {
|
|
|
211 |
g.drawString(((RegisterSummary) object).getLabel(), 10, posY + 39);
|
|
|
212 |
}
|
18 |
ilm |
213 |
}
|
|
|
214 |
};
|
174 |
ilm |
215 |
this.add(this.ticketList, c);
|
18 |
ilm |
216 |
// Ticket
|
|
|
217 |
c.fill = GridBagConstraints.VERTICAL;
|
174 |
ilm |
218 |
c.weightx = 0;
|
18 |
ilm |
219 |
c.gridx++;
|
|
|
220 |
c.gridheight = 1;
|
|
|
221 |
c.insets = new Insets(10, 10, 10, 10);
|
174 |
ilm |
222 |
this.ticketP = new TextAreaTicketPrinter();
|
18 |
ilm |
223 |
|
174 |
ilm |
224 |
JScrollPane scrollPane = new JScrollPane(this.ticketP);
|
18 |
ilm |
225 |
scrollPane.setPreferredSize(new Dimension(400, 200));
|
|
|
226 |
scrollPane.setMinimumSize(new Dimension(400, 200));
|
|
|
227 |
this.add(scrollPane, c);
|
|
|
228 |
|
174 |
ilm |
229 |
this.ticketList.addListSelectionListener(new ListSelectionListener() {
|
18 |
ilm |
230 |
|
|
|
231 |
@Override
|
|
|
232 |
public void valueChanged(ListSelectionEvent e) {
|
174 |
ilm |
233 |
Object selectedValue = ListeDesTicketsPanel.this.ticketList.getSelectedValue();
|
18 |
ilm |
234 |
setSelectedTicket(selectedValue);
|
|
|
235 |
}
|
|
|
236 |
});
|
|
|
237 |
|
|
|
238 |
// Menu
|
|
|
239 |
|
|
|
240 |
c.gridy++;
|
|
|
241 |
c.weighty = 0;
|
|
|
242 |
c.fill = GridBagConstraints.NONE;
|
182 |
ilm |
243 |
final Font font = new Font(ARIAL_FONT, Font.PLAIN, 32);
|
|
|
244 |
this.l = new JList(new String[] { "Imprimer la facture", "Imprimer le ticket", "Annuler le ticket" });
|
174 |
ilm |
245 |
this.l.setCellRenderer(new ListCellRenderer() {
|
18 |
ilm |
246 |
|
|
|
247 |
@Override
|
|
|
248 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
|
|
249 |
JLabel l = new JLabel(value.toString()) {
|
|
|
250 |
@Override
|
|
|
251 |
public void paint(Graphics g) {
|
|
|
252 |
|
|
|
253 |
super.paint(g);
|
|
|
254 |
|
|
|
255 |
g.setColor(Color.LIGHT_GRAY);
|
|
|
256 |
g.drawLine(0, 0, this.getWidth(), 0);
|
|
|
257 |
}
|
|
|
258 |
};
|
|
|
259 |
l.setFont(font);
|
|
|
260 |
return l;
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
});
|
174 |
ilm |
264 |
this.l.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
|
265 |
this.l.getSelectionModel().addListSelectionListener(this);
|
18 |
ilm |
266 |
|
174 |
ilm |
267 |
this.l.setFixedCellHeight(100);
|
|
|
268 |
this.add(this.l, c);
|
142 |
ilm |
269 |
|
144 |
ilm |
270 |
setFont(new Font(ARIAL_FONT, Font.BOLD, 24));
|
142 |
ilm |
271 |
|
|
|
272 |
// Listeners
|
|
|
273 |
bBack.addActionListener(new ActionListener() {
|
|
|
274 |
|
|
|
275 |
@Override
|
|
|
276 |
public void actionPerformed(ActionEvent e) {
|
174 |
ilm |
277 |
ListeDesTicketsPanel.this.frame.showCaisse();
|
142 |
ilm |
278 |
|
|
|
279 |
}
|
|
|
280 |
});
|
|
|
281 |
|
18 |
ilm |
282 |
}
|
|
|
283 |
|
|
|
284 |
@Override
|
|
|
285 |
public void valueChanged(ListSelectionEvent e) {
|
|
|
286 |
if (e.getValueIsAdjusting()) {
|
|
|
287 |
return;
|
|
|
288 |
}
|
174 |
ilm |
289 |
Object selectedValue = this.ticketList.getSelectedValue();
|
|
|
290 |
int selectedIndex = this.l.getSelectedIndex();
|
144 |
ilm |
291 |
if (selectedIndex == 0 && selectedValue != null) {
|
182 |
ilm |
292 |
if (selectedValue instanceof Ticket) {
|
|
|
293 |
Ticket ticket = (Ticket) selectedValue;
|
|
|
294 |
ListeDesTicketsPanel.this.frame.showTicketClientNamePanel(ticket);
|
|
|
295 |
return;
|
|
|
296 |
}
|
|
|
297 |
} else if (selectedIndex == 1 && selectedValue != null) {
|
156 |
ilm |
298 |
this.frame.getPOSConf().printOnceOnFirstPrinter(((Printable) selectedValue));
|
182 |
ilm |
299 |
} else if (selectedIndex == 2 && selectedValue != null && selectedValue instanceof Ticket) {
|
151 |
ilm |
300 |
Ticket t = (Ticket) selectedValue;
|
174 |
ilm |
301 |
this.frame.getControler().cancel(t);
|
|
|
302 |
|
18 |
ilm |
303 |
}
|
174 |
ilm |
304 |
this.l.clearSelection();
|
18 |
ilm |
305 |
}
|
|
|
306 |
|
|
|
307 |
public void setSelectedTicket(Object selectedValue) {
|
174 |
ilm |
308 |
this.ticketP.clear();
|
18 |
ilm |
309 |
if (selectedValue != null) {
|
156 |
ilm |
310 |
this.frame.getPOSConf().print(((Printable) selectedValue), new TicketPrinterConfiguration() {
|
142 |
ilm |
311 |
@Override
|
|
|
312 |
public TicketPrinter createTicketPrinter() {
|
174 |
ilm |
313 |
return ListeDesTicketsPanel.this.ticketP;
|
142 |
ilm |
314 |
}
|
|
|
315 |
|
|
|
316 |
@Override
|
|
|
317 |
public int getCopyCount() {
|
|
|
318 |
return 1;
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
@Override
|
|
|
322 |
public boolean isValid() {
|
|
|
323 |
return true;
|
|
|
324 |
}
|
|
|
325 |
});
|
18 |
ilm |
326 |
try {
|
174 |
ilm |
327 |
this.ticketP.printBuffer();
|
18 |
ilm |
328 |
} catch (Exception e1) {
|
|
|
329 |
e1.printStackTrace();
|
|
|
330 |
}
|
|
|
331 |
}
|
174 |
ilm |
332 |
this.ticketList.setSelectedValue(selectedValue, true);
|
18 |
ilm |
333 |
}
|
|
|
334 |
}
|