OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 174
Line 14... Line 14...
14
 package org.openconcerto.erp.core.sales.pos.ui;
14
 package org.openconcerto.erp.core.sales.pos.ui;
15
 
15
 
16
import org.openconcerto.erp.core.sales.pos.TicketPrinterConfiguration;
16
import org.openconcerto.erp.core.sales.pos.TicketPrinterConfiguration;
17
import org.openconcerto.erp.core.sales.pos.io.Printable;
17
import org.openconcerto.erp.core.sales.pos.io.Printable;
18
import org.openconcerto.erp.core.sales.pos.io.TicketPrinter;
18
import org.openconcerto.erp.core.sales.pos.io.TicketPrinter;
19
import org.openconcerto.erp.core.sales.pos.model.Article;
-
 
20
import org.openconcerto.erp.core.sales.pos.model.RegisterFiles;
19
import org.openconcerto.erp.core.sales.pos.model.RegisterFiles;
21
import org.openconcerto.erp.core.sales.pos.model.RegisterLog;
20
import org.openconcerto.erp.core.sales.pos.model.RegisterLog;
22
import org.openconcerto.erp.core.sales.pos.model.Ticket;
21
import org.openconcerto.erp.core.sales.pos.model.Ticket;
23
import org.openconcerto.ui.DefaultListModel;
22
import org.openconcerto.ui.DefaultListModel;
24
import org.openconcerto.ui.touch.ScrollableList;
23
import org.openconcerto.ui.touch.ScrollableList;
25
import org.openconcerto.utils.ExceptionHandler;
24
import org.openconcerto.utils.ExceptionHandler;
26
import org.openconcerto.utils.Pair;
-
 
27
 
25
 
28
import java.awt.Color;
26
import java.awt.Color;
29
import java.awt.Component;
27
import java.awt.Component;
30
import java.awt.Dimension;
28
import java.awt.Dimension;
31
import java.awt.FlowLayout;
29
import java.awt.FlowLayout;
Line 109... Line 107...
109
        protected Z(final RegisterFiles files, final Calendar day) throws IOException, JDOMException {
107
        protected Z(final RegisterFiles files, final Calendar day) throws IOException, JDOMException {
110
            super("Z", new RegisterLog(files.getLogFile(day)).parse());
108
            super("Z", new RegisterLog(files.getLogFile(day)).parse());
111
        }
109
        }
112
 
110
 
113
        @Override
111
        @Override
114
        protected final List<Ticket> getReceipts() throws ParseException {
112
        protected final List<Ticket> getReceipts() throws ParseException, IOException {
115
            return this.getLog().parseReceipts();
113
            return this.getLog().parseReceipts();
116
        }
114
        }
117
 
115
 
118
        @Override
116
        @Override
119
        public String getLabel() {
117
        public String getLabel() {
Line 158... Line 156...
158
        c.gridheight = 2;
156
        c.gridheight = 2;
159
 
157
 
160
        try {
158
        try {
161
            final RegisterLog lastLog = this.frame.getFiles().getLastLog();
159
            final RegisterLog lastLog = this.frame.getFiles().getLastLog();
162
            final List<Ticket> receipts = lastLog.parseReceipts();
160
            final List<Ticket> receipts = lastLog.parseReceipts();
163
            ticketLlistModel = new DefaultListModel();
161
            this.ticketLlistModel = new DefaultListModel();
164
            ticketLlistModel.addElement(new X(lastLog, receipts));
162
            this.ticketLlistModel.addElement(new X(lastLog, receipts));
165
            ticketLlistModel.addElement(new XLite(lastLog, receipts));
163
            this.ticketLlistModel.addElement(new XLite(lastLog, receipts));
166
            final Date previousDate = lastLog.getFirstRegisterEvent().getPreviousDate();
164
            final Date previousDate = lastLog.getFirstRegisterEvent().getPreviousDate();
167
            if (previousDate != null) {
165
            if (previousDate != null) {
168
                final Calendar cal = Calendar.getInstance();
166
                final Calendar cal = Calendar.getInstance();
169
                cal.setTime(previousDate);
167
                cal.setTime(previousDate);
170
                ticketLlistModel.addElement(new Z(this.frame.getFiles(), cal));
168
                this.ticketLlistModel.addElement(new Z(this.frame.getFiles(), cal));
171
            }
169
            }
172
            ticketLlistModel.addAll(receipts);
170
            this.ticketLlistModel.addAll(receipts);
173
 
171
 
174
        } catch (Exception exn) {
172
        } catch (Exception exn) {
175
            ExceptionHandler.handle(this.frame, "Impossible de charger les tickets", exn);
173
            ExceptionHandler.handle(this.frame, "Impossible de charger les tickets", exn);
176
        }
174
        }
177
        final Font f = new Font(ARIAL_FONT, Font.PLAIN, 24);
175
        final Font f = new Font(ARIAL_FONT, Font.PLAIN, 24);
178
        ticketList = new ScrollableList(ticketLlistModel) {
176
        this.ticketList = new ScrollableList(this.ticketLlistModel) {
179
            @Override
177
            @Override
180
            public void paintCell(Graphics g, Object object, int index, boolean isSelected, int posY) {
178
            public void paintCell(Graphics g, Object object, int index, boolean isSelected, int posY) {
181
                g.setFont(f);
179
                g.setFont(f);
182
 
180
 
183
                if (isSelected) {
181
                if (isSelected) {
Line 209... Line 207...
209
                } else {
207
                } else {
210
                    g.drawString(((RegisterSummary) object).getLabel(), 10, posY + 39);
208
                    g.drawString(((RegisterSummary) object).getLabel(), 10, posY + 39);
211
                }
209
                }
212
            }
210
            }
213
        };
211
        };
214
        this.add(ticketList, c);
212
        this.add(this.ticketList, c);
215
        // Ticket
213
        // Ticket
216
        c.fill = GridBagConstraints.VERTICAL;
214
        c.fill = GridBagConstraints.VERTICAL;
-
 
215
        c.weightx = 0;
217
        c.gridx++;
216
        c.gridx++;
218
        c.gridheight = 1;
217
        c.gridheight = 1;
219
        c.insets = new Insets(10, 10, 10, 10);
218
        c.insets = new Insets(10, 10, 10, 10);
220
        ticketP = new TextAreaTicketPrinter();
219
        this.ticketP = new TextAreaTicketPrinter();
221
 
220
 
222
        JScrollPane scrollPane = new JScrollPane(ticketP);
221
        JScrollPane scrollPane = new JScrollPane(this.ticketP);
223
        scrollPane.setPreferredSize(new Dimension(400, 200));
222
        scrollPane.setPreferredSize(new Dimension(400, 200));
224
        scrollPane.setMinimumSize(new Dimension(400, 200));
223
        scrollPane.setMinimumSize(new Dimension(400, 200));
225
        this.add(scrollPane, c);
224
        this.add(scrollPane, c);
226
 
225
 
227
        ticketList.addListSelectionListener(new ListSelectionListener() {
226
        this.ticketList.addListSelectionListener(new ListSelectionListener() {
228
 
227
 
229
            @Override
228
            @Override
230
            public void valueChanged(ListSelectionEvent e) {
229
            public void valueChanged(ListSelectionEvent e) {
231
                Object selectedValue = ticketList.getSelectedValue();
230
                Object selectedValue = ListeDesTicketsPanel.this.ticketList.getSelectedValue();
232
                setSelectedTicket(selectedValue);
231
                setSelectedTicket(selectedValue);
233
            }
232
            }
234
        });
233
        });
235
 
234
 
236
        // Menu
235
        // Menu
237
 
236
 
238
        c.gridy++;
237
        c.gridy++;
239
        c.weighty = 0;
238
        c.weighty = 0;
240
        c.fill = GridBagConstraints.NONE;
239
        c.fill = GridBagConstraints.NONE;
241
        final Font font = new Font(ARIAL_FONT, Font.PLAIN, 46);
240
        final Font font = new Font(ARIAL_FONT, Font.PLAIN, 46);
242
        l = new JList(new String[] { "Imprimer", "Annuler" });
241
        this.l = new JList(new String[] { "Imprimer", "Annuler le ticket" });
243
        l.setCellRenderer(new ListCellRenderer() {
242
        this.l.setCellRenderer(new ListCellRenderer() {
244
 
243
 
245
            @Override
244
            @Override
246
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
245
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
247
                JLabel l = new JLabel(value.toString()) {
246
                JLabel l = new JLabel(value.toString()) {
248
                    @Override
247
                    @Override
Line 257... Line 256...
257
                l.setFont(font);
256
                l.setFont(font);
258
                return l;
257
                return l;
259
            }
258
            }
260
 
259
 
261
        });
260
        });
262
        l.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
261
        this.l.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
263
        l.getSelectionModel().addListSelectionListener(this);
262
        this.l.getSelectionModel().addListSelectionListener(this);
264
 
263
 
265
        l.setFixedCellHeight(160);
264
        this.l.setFixedCellHeight(100);
266
        this.add(l, c);
265
        this.add(this.l, c);
267
 
266
 
268
        setFont(new Font(ARIAL_FONT, Font.BOLD, 24));
267
        setFont(new Font(ARIAL_FONT, Font.BOLD, 24));
269
 
268
 
270
        // Listeners
269
        // Listeners
271
        bBack.addActionListener(new ActionListener() {
270
        bBack.addActionListener(new ActionListener() {
272
 
271
 
273
            @Override
272
            @Override
274
            public void actionPerformed(ActionEvent e) {
273
            public void actionPerformed(ActionEvent e) {
275
                frame.showCaisse();
274
                ListeDesTicketsPanel.this.frame.showCaisse();
276
 
275
 
277
            }
276
            }
278
        });
277
        });
279
 
278
 
280
    }
279
    }
Line 282... Line 281...
282
    @Override
281
    @Override
283
    public void valueChanged(ListSelectionEvent e) {
282
    public void valueChanged(ListSelectionEvent e) {
284
        if (e.getValueIsAdjusting()) {
283
        if (e.getValueIsAdjusting()) {
285
            return;
284
            return;
286
        }
285
        }
287
        Object selectedValue = ticketList.getSelectedValue();
286
        Object selectedValue = this.ticketList.getSelectedValue();
288
        int selectedIndex = l.getSelectedIndex();
287
        int selectedIndex = this.l.getSelectedIndex();
289
        if (selectedIndex == 0 && selectedValue != null) {
288
        if (selectedIndex == 0 && selectedValue != null) {
290
            this.frame.getPOSConf().printOnceOnFirstPrinter(((Printable) selectedValue));
289
            this.frame.getPOSConf().printOnceOnFirstPrinter(((Printable) selectedValue));
291
        } else if (selectedIndex == 1 && selectedValue != null) {
290
        } else if (selectedIndex == 1 && selectedValue != null && selectedValue instanceof Ticket) {
292
            // Annulation du ticket
-
 
293
            Ticket t = (Ticket) selectedValue;
291
            Ticket t = (Ticket) selectedValue;
294
            for (Pair<Article, Integer> a : t.getArticles()) {
-
 
295
                frame.getControler().addArticle(a.getFirst());
292
            this.frame.getControler().cancel(t);
296
                frame.getControler().setArticleCount(a.getFirst(), -a.getSecond());
-
 
297
                frame.getControler().setArticleHT(a.getFirst(), a.getFirst().getPriceWithoutTax());
-
 
298
            }
293
 
299
            frame.showCaisse();
-
 
300
        }
294
        }
301
        l.clearSelection();
295
        this.l.clearSelection();
302
    }
296
    }
303
 
297
 
304
    public void setSelectedTicket(Object selectedValue) {
298
    public void setSelectedTicket(Object selectedValue) {
305
        ticketP.clear();
299
        this.ticketP.clear();
306
        if (selectedValue != null) {
300
        if (selectedValue != null) {
307
            this.frame.getPOSConf().print(((Printable) selectedValue), new TicketPrinterConfiguration() {
301
            this.frame.getPOSConf().print(((Printable) selectedValue), new TicketPrinterConfiguration() {
308
                @Override
302
                @Override
309
                public TicketPrinter createTicketPrinter() {
303
                public TicketPrinter createTicketPrinter() {
310
                    return ticketP;
304
                    return ListeDesTicketsPanel.this.ticketP;
311
                }
305
                }
312
 
306
 
313
                @Override
307
                @Override
314
                public int getCopyCount() {
308
                public int getCopyCount() {
315
                    return 1;
309
                    return 1;
Line 319... Line 313...
319
                public boolean isValid() {
313
                public boolean isValid() {
320
                    return true;
314
                    return true;
321
                }
315
                }
322
            });
316
            });
323
            try {
317
            try {
324
                ticketP.printBuffer();
318
                this.ticketP.printBuffer();
325
            } catch (Exception e1) {
319
            } catch (Exception e1) {
326
                e1.printStackTrace();
320
                e1.printStackTrace();
327
            }
321
            }
328
        }
322
        }
329
        ticketList.setSelectedValue(selectedValue, true);
323
        this.ticketList.setSelectedValue(selectedValue, true);
330
    }
324
    }
331
}
325
}