OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 142 Rev 156
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
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.POSConfiguration;
-
 
17
import org.openconcerto.erp.core.sales.pos.TicketPrinterConfiguration;
16
import org.openconcerto.erp.core.sales.pos.TicketPrinterConfiguration;
18
import org.openconcerto.erp.core.sales.pos.io.TicketPrinter;
17
import org.openconcerto.erp.core.sales.pos.io.TicketPrinter;
19
import org.openconcerto.erp.core.sales.pos.model.Client;
18
import org.openconcerto.erp.core.sales.pos.model.Client;
20
import org.openconcerto.erp.core.sales.pos.model.Transaction;
19
import org.openconcerto.erp.core.sales.pos.model.Transaction;
21
import org.openconcerto.ui.DefaultGridBagConstraints;
20
import org.openconcerto.ui.DefaultGridBagConstraints;
22
import org.openconcerto.ui.DefaultListModel;
21
import org.openconcerto.ui.DefaultListModel;
23
import org.openconcerto.ui.touch.ScrollableList;
22
import org.openconcerto.ui.touch.ScrollableList;
24
import org.openconcerto.utils.ExceptionHandler;
23
import org.openconcerto.utils.ExceptionHandler;
25
 
24
 
26
import java.awt.BorderLayout;
25
import java.awt.BorderLayout;
27
import java.awt.Color;
26
import java.awt.Color;
28
import java.awt.Component;
27
import java.awt.Component;
29
import java.awt.Font;
28
import java.awt.Font;
30
import java.awt.Graphics;
29
import java.awt.Graphics;
31
import java.awt.Graphics2D;
30
import java.awt.Graphics2D;
32
import java.awt.GridBagConstraints;
31
import java.awt.GridBagConstraints;
33
import java.awt.GridBagLayout;
32
import java.awt.GridBagLayout;
34
import java.awt.Insets;
33
import java.awt.Insets;
35
import java.awt.RenderingHints;
34
import java.awt.RenderingHints;
36
import java.awt.event.ActionEvent;
35
import java.awt.event.ActionEvent;
37
import java.awt.event.ActionListener;
36
import java.awt.event.ActionListener;
38
import java.math.BigDecimal;
37
import java.math.BigDecimal;
39
import java.math.RoundingMode;
38
import java.math.RoundingMode;
40
import java.util.List;
39
import java.util.List;
41
 
40
 
42
import javax.swing.JButton;
41
import javax.swing.JButton;
43
import javax.swing.JLabel;
42
import javax.swing.JLabel;
44
import javax.swing.JPanel;
43
import javax.swing.JPanel;
45
 
44
 
46
import com.ibm.icu.text.DateFormat;
45
import com.ibm.icu.text.DateFormat;
47
 
46
 
48
public class DetailClientPanel extends JPanel {
47
public class DetailClientPanel extends JPanel {
49
    private CaisseFrame caisseFrame;
48
    private CaisseFrame caisseFrame;
50
 
49
 
51
    DetailClientPanel(CaisseFrame f) {
50
    DetailClientPanel(CaisseFrame f) {
52
        this.caisseFrame = f;
51
        this.caisseFrame = f;
53
        this.setOpaque(false);
52
        this.setOpaque(false);
54
        this.setLayout(new GridBagLayout());
53
        this.setLayout(new GridBagLayout());
55
        GridBagConstraints c = new DefaultGridBagConstraints();
54
        GridBagConstraints c = new DefaultGridBagConstraints();
56
        c.weightx = 1;
55
        c.weightx = 1;
57
        c.weighty = 1;
56
        c.weighty = 1;
58
        c.fill = GridBagConstraints.BOTH;
57
        c.fill = GridBagConstraints.BOTH;
59
        final JPanel filler = new JPanel();
58
        final JPanel filler = new JPanel();
60
        filler.setOpaque(false);
59
        filler.setOpaque(false);
61
        this.add(filler, c);
60
        this.add(filler, c);
62
    }
61
    }
63
 
62
 
64
    public void setSelectedClient(final Client client) {
63
    public void setSelectedClient(final Client client) {
65
 
64
 
66
        this.removeAll();
65
        this.removeAll();
67
        this.invalidate();
66
        this.invalidate();
68
        final Font f = new Font("Arial", Font.PLAIN, 24);
67
        final Font f = new Font("Arial", Font.PLAIN, 24);
69
        GridBagConstraints c = new DefaultGridBagConstraints();
68
        GridBagConstraints c = new DefaultGridBagConstraints();
70
        c.fill = GridBagConstraints.BOTH;
69
        c.fill = GridBagConstraints.BOTH;
71
        c.weightx = 1;
70
        c.weightx = 1;
72
        c.weighty = 0;
71
        c.weighty = 0;
73
        final JLabel label = new JLabel(client.getFullName());
72
        final JLabel label = new JLabel(client.getFullName());
74
        label.setFont(f);
73
        label.setFont(f);
75
        this.add(label, c);
74
        this.add(label, c);
76
        c.gridy++;
75
        c.gridy++;
77
        final JLabel labelTransaction = new JLabel("Transactions");
76
        final JLabel labelTransaction = new JLabel("Transactions");
78
        labelTransaction.setFont(f);
77
        labelTransaction.setFont(f);
79
        this.add(labelTransaction, c);
78
        this.add(labelTransaction, c);
80
        c.gridy++;
79
        c.gridy++;
81
        //
80
        //
82
        c.weighty = 1;
81
        c.weighty = 1;
83
        this.add(createTransactionList(client), c);
82
        this.add(createTransactionList(client), c);
84
        //
83
        //
85
 
84
 
86
        c.fill = GridBagConstraints.NONE;
85
        c.fill = GridBagConstraints.NONE;
87
        c.weighty = 0;
86
        c.weighty = 0;
88
        c.gridy++;
87
        c.gridy++;
89
        final JButton bCredit = new POSButton("Créditer le compte");
88
        final JButton bCredit = new POSButton("Créditer le compte");
90
        this.add(bCredit, c);
89
        this.add(bCredit, c);
91
 
90
 
92
        //
91
        //
93
        c.gridy++;
92
        c.gridy++;
94
        c.anchor = GridBagConstraints.EAST;
93
        c.anchor = GridBagConstraints.EAST;
95
        c.insets = new Insets(20, 20, 5, 2);
94
        c.insets = new Insets(20, 20, 5, 2);
96
        final JButton bSelect = new POSButton("Sélectionner ce client");
95
        final JButton bSelect = new POSButton("Sélectionner ce client");
97
        this.add(bSelect, c);
96
        this.add(bSelect, c);
98
 
97
 
99
        this.validate();
98
        this.validate();
100
        this.repaint();
99
        this.repaint();
101
 
100
 
102
        // Listeners
101
        // Listeners
103
        bCredit.addActionListener(new ActionListener() {
102
        bCredit.addActionListener(new ActionListener() {
104
 
103
 
105
            @Override
104
            @Override
106
            public void actionPerformed(ActionEvent e) {
105
            public void actionPerformed(ActionEvent e) {
107
                TransparentPanel tP = new TransparentPanel(caisseFrame);
106
                TransparentPanel tP = new TransparentPanel(caisseFrame);
108
                //
107
                //
109
                JPanel p = new JPanel();
108
                JPanel p = new JPanel();
110
                p.setBackground(Color.WHITE);
109
                p.setBackground(Color.WHITE);
111
                p.setLayout(new GridBagLayout());
110
                p.setLayout(new GridBagLayout());
112
                GridBagConstraints constraints = new DefaultGridBagConstraints();
111
                GridBagConstraints constraints = new DefaultGridBagConstraints();
113
                constraints.fill = GridBagConstraints.BOTH;
112
                constraints.fill = GridBagConstraints.BOTH;
114
                constraints.insets = new Insets(20, 20, 20, 20);
113
                constraints.insets = new Insets(20, 20, 20, 20);
115
                constraints.gridwidth = 2;
114
                constraints.gridwidth = 2;
116
                constraints.weightx = 1;
115
                constraints.weightx = 1;
117
                POSLabel label = new POSLabel(client.getFullName());
116
                POSLabel label = new POSLabel(client.getFullName());
118
                p.add(label, constraints);
117
                p.add(label, constraints);
119
                constraints.gridy++;
118
                constraints.gridy++;
120
 
119
 
121
                final SoldePaiementPanel soldePanel = new SoldePaiementPanel();
120
                final SoldePaiementPanel soldePanel = new SoldePaiementPanel();
122
                p.add(soldePanel, constraints);
121
                p.add(soldePanel, constraints);
123
                constraints.gridwidth = 1;
122
                constraints.gridwidth = 1;
124
                constraints.gridy++;
123
                constraints.gridy++;
125
                constraints.gridx = 0;
124
                constraints.gridx = 0;
126
                constraints.fill = GridBagConstraints.NONE;
125
                constraints.fill = GridBagConstraints.NONE;
127
                constraints.anchor = GridBagConstraints.EAST;
126
                constraints.anchor = GridBagConstraints.EAST;
128
                POSButton bC = new POSButton("Créditer");
127
                POSButton bC = new POSButton("Créditer");
129
                p.add(bC, constraints);
128
                p.add(bC, constraints);
130
                bC.addActionListener(new ActionListener() {
129
                bC.addActionListener(new ActionListener() {
131
 
130
 
132
                    @Override
131
                    @Override
133
                    public void actionPerformed(ActionEvent e) {
132
                    public void actionPerformed(ActionEvent e) {
134
                        try {
133
                        try {
135
                            final BigDecimal amount = soldePanel.getAmount();
134
                            final BigDecimal amount = soldePanel.getAmount();
136
                            final int paymentType = soldePanel.getPaymentType();
135
                            final int paymentType = soldePanel.getPaymentType();
137
                            client.credit(amount, paymentType);
136
                            client.credit(amount, paymentType);
138
                            final BigDecimal nouveauSolde = client.getSolde();
137
                            final BigDecimal nouveauSolde = client.getSolde();
139
                            final Thread t = new Thread(new Runnable() {
138
                            final Thread t = new Thread(new Runnable() {
140
 
139
 
141
                                @Override
140
                                @Override
142
                                public void run() {
141
                                public void run() {
143
                                    final TicketPrinterConfiguration conf1 = POSConfiguration.getInstance().getTicketPrinterConfiguration1();
142
                                    final TicketPrinterConfiguration conf1 = caisseFrame.getPOSConf().getTicketPrinterConfiguration1();
144
                                    if (conf1.isValid()) {
143
                                    if (conf1.isValid()) {
145
                                        final TicketPrinter prt = conf1.createTicketPrinter();
144
                                        final TicketPrinter prt = conf1.createTicketPrinter();
146
                                        final int ticketWidth = conf1.getTicketWidth();
145
                                        final int ticketWidth = conf1.getTicketWidth();
147
                                        client.printCredit(prt, ticketWidth, amount, paymentType, nouveauSolde);
146
                                        client.printCredit(prt, caisseFrame.getPOSConf().getHeaderLines(), ticketWidth, amount, paymentType, nouveauSolde);
148
                                    }
147
                                    }
149
 
148
 
150
                                }
149
                                }
151
                            });
150
                            });
152
                            t.setDaemon(true);
151
                            t.setDaemon(true);
153
                            t.start();
152
                            t.start();
154
                            caisseFrame.showClients();
153
                            caisseFrame.showClients();
155
                        } catch (Exception e1) {
154
                        } catch (Exception e1) {
156
                            ExceptionHandler.handle("Erreur lors du crédit", e1);
155
                            ExceptionHandler.handle("Erreur lors du crédit", e1);
157
                        }
156
                        }
158
 
157
 
159
                    }
158
                    }
160
                });
159
                });
161
                constraints.gridx++;
160
                constraints.gridx++;
162
                constraints.weightx = 0;
161
                constraints.weightx = 0;
163
                POSButton bClose = new POSButton("Fermer");
162
                POSButton bClose = new POSButton("Fermer");
164
                p.add(bClose, constraints);
163
                p.add(bClose, constraints);
165
                bClose.addActionListener(new ActionListener() {
164
                bClose.addActionListener(new ActionListener() {
166
 
165
 
167
                    @Override
166
                    @Override
168
                    public void actionPerformed(ActionEvent e) {
167
                    public void actionPerformed(ActionEvent e) {
169
                        caisseFrame.showClients();
168
                        caisseFrame.showClients();
170
                    }
169
                    }
171
                });
170
                });
172
                //
171
                //
173
                tP.setLayout(new GridBagLayout());
172
                tP.setLayout(new GridBagLayout());
174
                GridBagConstraints c = new GridBagConstraints();
173
                GridBagConstraints c = new GridBagConstraints();
175
                c.gridwidth = 1;
174
                c.gridwidth = 1;
176
                c.gridheight = 1;
175
                c.gridheight = 1;
177
                c.fill = GridBagConstraints.NONE;
176
                c.fill = GridBagConstraints.NONE;
178
                c.anchor = GridBagConstraints.CENTER;
177
                c.anchor = GridBagConstraints.CENTER;
179
                tP.add(p, c);
178
                tP.add(p, c);
180
                caisseFrame.invalidate();
179
                caisseFrame.invalidate();
181
                caisseFrame.setContentPane(tP);
180
                caisseFrame.setContentPane(tP);
182
                caisseFrame.validate();
181
                caisseFrame.validate();
183
                caisseFrame.repaint();
182
                caisseFrame.repaint();
184
 
183
 
185
            }
184
            }
186
        });
185
        });
187
        bSelect.addActionListener(new ActionListener() {
186
        bSelect.addActionListener(new ActionListener() {
188
 
187
 
189
            @Override
188
            @Override
190
            public void actionPerformed(ActionEvent e) {
189
            public void actionPerformed(ActionEvent e) {
191
                caisseFrame.setClient(client);
190
                caisseFrame.setClient(client);
192
                caisseFrame.showCaisse();
191
                caisseFrame.showCaisse();
193
            }
192
            }
194
        });
193
        });
195
    }
194
    }
196
 
195
 
197
    private Component createTransactionList(Client client) {
196
    private Component createTransactionList(Client client) {
198
        final DefaultListModel ticketLlistModel = new DefaultListModel();
197
        final DefaultListModel ticketLlistModel = new DefaultListModel();
199
        final List<Transaction> transactions = client.getTransactions();
198
        final List<Transaction> transactions = client.getTransactions();
200
        final Font f = new Font("Arial", Font.PLAIN, 24);
199
        final Font f = new Font("Arial", Font.PLAIN, 24);
201
        if (transactions.isEmpty()) {
200
        if (transactions.isEmpty()) {
202
            final JPanel p = new JPanel();
201
            final JPanel p = new JPanel();
203
            p.setBackground(Color.WHITE);
202
            p.setBackground(Color.WHITE);
204
            p.setLayout(new BorderLayout());
203
            p.setLayout(new BorderLayout());
205
            final JLabel label = new JLabel("Aucune transaction pour le moment");
204
            final JLabel label = new JLabel("Aucune transaction pour le moment");
206
            label.setFont(f);
205
            label.setFont(f);
207
            label.setForeground(Color.GRAY);
206
            label.setForeground(Color.GRAY);
208
            p.add(label, BorderLayout.NORTH);
207
            p.add(label, BorderLayout.NORTH);
209
            return p;
208
            return p;
210
        }
209
        }
211
 
210
 
212
        ticketLlistModel.addAll(transactions);
211
        ticketLlistModel.addAll(transactions);
213
 
212
 
214
        final ScrollableList clientList = new ScrollableList(ticketLlistModel) {
213
        final ScrollableList clientList = new ScrollableList(ticketLlistModel) {
215
            @Override
214
            @Override
216
            public void paintCell(Graphics g, Object object, int index, boolean isSelected, int posY) {
215
            public void paintCell(Graphics g, Object object, int index, boolean isSelected, int posY) {
217
                g.setFont(f);
216
                g.setFont(f);
218
                g.setColor(Color.WHITE);
217
                g.setColor(Color.WHITE);
219
                g.fillRect(0, posY, getWidth(), getCellHeight());
218
                g.fillRect(0, posY, getWidth(), getCellHeight());
220
 
219
 
221
                //
220
                //
222
                g.setColor(Color.GRAY);
221
                g.setColor(Color.GRAY);
223
                g.drawLine(0, posY + this.getCellHeight() - 1, this.getWidth(), posY + this.getCellHeight() - 1);
222
                g.drawLine(0, posY + this.getCellHeight() - 1, this.getWidth(), posY + this.getCellHeight() - 1);
224
 
223
 
225
                if (isSelected) {
224
                if (isSelected) {
226
                    g.setColor(Color.BLACK);
225
                    g.setColor(Color.BLACK);
227
                } else {
226
                } else {
228
                    g.setColor(Color.GRAY);
227
                    g.setColor(Color.GRAY);
229
                }
228
                }
230
                ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
229
                ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
231
                Transaction client = (Transaction) object;
230
                Transaction client = (Transaction) object;
232
                String label = DateFormat.getDateTimeInstance().format(client.getDate());
231
                String label = DateFormat.getDateTimeInstance().format(client.getDate());
233
                final int soldeInCents = client.getAmount().movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue();
232
                final int soldeInCents = client.getAmount().movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue();
234
                String euro = TicketCellRenderer.centsToString(soldeInCents) + "€";
233
                String euro = TicketCellRenderer.centsToString(soldeInCents) + "€";
235
 
234
 
236
                int wEuro = (int) g.getFontMetrics().getStringBounds(euro, g).getWidth();
235
                int wEuro = (int) g.getFontMetrics().getStringBounds(euro, g).getWidth();
237
                g.drawString(label, 10, posY + 24);
236
                g.drawString(label, 10, posY + 24);
238
                g.drawString(euro, getWidth() - 5 - wEuro, posY + 24);
237
                g.drawString(euro, getWidth() - 5 - wEuro, posY + 24);
239
 
238
 
240
            }
239
            }
241
        };
240
        };
242
        return clientList;
241
        return clientList;
243
    }
242
    }
244
 
243
 
245
}
244
}