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