Source code: com/globalretailtech/pos/ej/EjAltCurrTender.java
1 /*
2 * Copyright (C) 2001 Global Retail Technology, LLC
3 * <http://www.globalretailtech.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 package com.globalretailtech.pos.ej;
21
22 import java.util.Hashtable;
23 import java.util.Vector;
24 import com.globalretailtech.util.*;
25 import com.globalretailtech.data.*;
26 import com.globalretailtech.pos.context.*;
27 import com.globalretailtech.pos.events.PosEvent;
28 import com.globalretailtech.pos.operators.*;
29 import com.globalretailtech.pos.devices.OperPrompt;
30
31 /**
32 * Alternate currency event. This object is typically tied to a
33 * key with the database alternate currency ID passed to the engage
34 * method. It prompts for the amount of alt currency tendered, prints
35 * the alt currency amount, the local currency amount and the amount
36 * of change in local currency if the amount is enough to complete
37 * the sale. This dialog works a little differently than others, since
38 * this class is tied to a key and it looks up the currency when the
39 * key is pressed we want to start off the dialog with the current
40 * object.
41 *
42 * @author Quentin Olson
43 */
44 public class EjAltCurrTender extends EjLine
45 {
46
47 /** Prompt for amount. */
48 public final static int ENTER_ALT_CURR_AMOUNT = 1;
49 /** get amount. */
50 public final static int GET_ALT_CURR_AMOUNT = 2;
51 /** Complete the transaction. */
52 public final static int TENDER_FINAL = 3;
53
54 private TransTender transtender;
55 private double oonvertamount;
56 private double splitamount;
57 private String prompttext;
58 private String converttext;
59
60 /** Prompt text for displays. */
61 public String promptText ()
62 {
63 return prompttext;
64 }
65 /** Text for receipt. */
66 public String convertText ()
67 {
68 return converttext;
69 }
70 /** Holds split tender amount */
71 public double splitAmount ()
72 {
73 return splitamount;
74 }
75 /** The database tender record. */
76 public TransTender transTender ()
77 {
78 return transtender;
79 }
80 /** Currency language */
81 public String language ()
82 {
83 return transTender ().localeLanguage ();
84 }
85 /** Currency language country */
86 public String country ()
87 {
88 return transTender ().localeCountry ();
89 }
90 public double convertAmount ()
91 {
92 return oonvertamount;
93 }
94
95 /** Set prompt text. */
96 public void setPromptText (String value)
97 {
98 prompttext = value;
99 }
100 /** Set convert text. */
101 public void setConvertText (String value)
102 {
103 converttext = value;
104 }
105 /** Set the currency record. */
106 public void setSplitAmount (double value)
107 {
108 splitamount = value;
109 }
110 /** Set the transaction record */
111 public void setTransTender (TransTender value)
112 {
113 transtender = value;
114 }
115
116 /** Simple constructor, set the line type. */
117 public EjAltCurrTender ()
118 {
119 setLineType (EjLine.ALT_CURRENCY_TENDER);
120 }
121
122 /** Constructor, set the line type and context. */
123 public EjAltCurrTender (PosContext c)
124 {
125 setLineType (EjLine.ALT_CURRENCY_TENDER);
126 setContext (c);
127 }
128
129 /** Constructor, set the line type and trans record,
130 * used in reprints.
131 */
132 public EjAltCurrTender (TransTender t)
133 {
134 setLineType (EjLine.ALT_CURRENCY_TENDER);
135 setTransTender (t);
136 }
137
138 /** Clone method. */
139 public Object clone ()
140 {
141
142 EjAltCurrTender tmp = new EjAltCurrTender ();
143
144 tmp.setLineType (lineType ());
145 // tmp.setEventType (eventType ());
146 tmp.setContext (context ());
147 // tmp.setValidEvents (validEvents ());
148 tmp.setSplitAmount (splitAmount ());
149 tmp.setTransTender (transTender ());
150
151 return tmp;
152 }
153
154 /**
155 * Get the currency record from the database from value (value is
156 * configured in the key database). If the currency is found
157 * start the alt currency dialog, which prompts for the amount
158 * tenderd, and completes the transaction if the tendered amount
159 * covers the sale, else split tender.
160 */
161 public void engage (int value)
162 {
163
164 PosMath math = context ().posMath ();
165
166 switch (state ())
167 {
168
169 case ENTER_ALT_CURR_AMOUNT: // prompts for amount tendered
170
171 setTransTender (new TransTender ()); // create a tender record
172
173 transTender ().setLocaleLanguage (context ().altCurrency ().currencyCode ().language ());
174 transTender ().setLocaleCountry (context ().altCurrency ().currencyCode ().country ());
175 transTender ().setTransID (context ().transID ());
176 transTender ().setSeqNo (context ().currEj ().currLineNo ());
177 transTender ().setTenderType (TransTender.ALT_CURRENCY);
178 transTender ().setTenderDesc (context ().posParameters ().getString ("AltCurrencyDescription"));
179 transTender ().setDataCapture (context ().altCurrency ().locale () + "," + context ().altCurrency ().conversionRate ());
180 oonvertamount = math.mult (context ().currEj ().ejTotal (), context ().altCurrency ().conversionRate ());
181 transTender ().setTenderAmount (math.mult (context ().currEj ().ejTotal (), context ().altCurrency ().conversionRate ()));
182
183 context ().clearInput ();
184 setPromptText (context ().posParameters ().getString ("AltCurrTenderPrompt"));
185 setConvertText (context ().posParameters ().getString ("ConvertedAltCurrency"));
186 context ().operPrompt().update (this);
187 context ().receipt().update (this);
188 states ().pushState (GET_ALT_CURR_AMOUNT);
189
190 break;
191
192 case GET_ALT_CURR_AMOUNT: // Pick up the amount from the input
193
194 popState ();
195 setSplitAmount (context ().inputDouble ());
196
197 if (amountIsValid ())
198 {
199 popState ();
200 }
201 else
202 {
203 return;
204 }
205
206 context ().clearInput ();
207 double amount = splitAmount ();
208 double localAmount = math.div (amount, context ().altCurrency ().conversionRate ());
209
210 transTender ().setTenderAmount (localAmount);
211 transTender ().setChange (math.sub (localAmount, context ().currEj ().ejTotal ()));
212 transTender ().setChangeDesc (context ().posParameters ().getString ("Change"));
213
214 // save the transaction
215
216 context ().receipt ().update (this);
217 context ().currEj ().ejAdd (this);
218 context ().eventStack ().nextEvent ();
219 break;
220 }
221
222
223
224 }
225 /**
226 * Validate alternate currency amount.
227 */
228 private boolean amountIsValid ()
229 {
230 return true;
231 }
232
233
234 // Abstract implementations, PosEvent
235
236 /** Validate transistions state. */
237 public boolean validTransition (String event)
238 {
239 return true;
240 }
241 /** Clear key implementation for this class */
242 public void clear ()
243 { }
244 private static String eventname = "EjAltCurrTender";
245 /** Return staic name. */
246 public String toString ()
247 {
248 return eventname;
249 }
250 /** Return staic name. */
251 public static String eventName ()
252 {
253 return eventname;
254 }
255
256 // Abstract implementations, EjLine
257
258 /** Quantitiy for this line. */
259 public int quantity ()
260 {
261 return 0;
262 }
263 /** Amount for this line. */
264 public double amount ()
265 {
266 return transTender ().tenderAmount ();
267 }
268 /** Extended amount (quantity * amount). */
269 public double extAmount ()
270 {
271 return amount ();
272 }
273 /** Taxable amount. */
274 public double taxAmount ()
275 {
276 return 0;
277 }
278 /** Chage for this transaction. */
279 public double change ()
280 {
281 return transTender ().change ();
282 }
283 /** Save the transaction record */
284 public boolean save ()
285 {
286
287 if (!context ().trainingMode ())
288 {
289 transTender ().save ();
290 }
291 return true;
292 }
293 /** Display prompt. */
294 public String prompt ()
295 {
296 return desc ();
297 }
298 /** Display customer. */
299 public String cust ()
300 {
301 return desc ();
302 }
303 /** Display description. */
304 public String desc ()
305 {
306 return transTender ().tenderDesc ();
307 }
308 /** The line nubmer */
309 public int lineNo ()
310 {
311 return transTender ().seqNo ();
312 }
313 /** The data record */
314 public DBRecord dataRecord ()
315 {
316 return transTender ();
317 }
318
319 /**
320 * Update the alt currncy totals record,
321 * note: the currency ID is used to tag
322 * the record with a type. That means if
323 * the ID changes, then the totals will no
324 * longer be valid, unless all records are
325 * replaced first.
326 */
327 public void updateTotals ()
328 {
329
330 if (context ().trainingMode ())
331 return;
332
333 Total.addToTotal (context ().siteID (),
334 context ().posNo (),
335 Total.ALT_CURRENCY_BASE + context ().altCurrency ().currencyCodeID (),
336 transTender ().tenderAmount ());
337
338 if (transTender ().change () != 0.0)
339 {
340 Total.addToTotal (context ().siteID (),
341 context ().posNo (),
342 Total.CASH_IN_DRAWER,
343 context ().posMath ().mult (transTender ().change (), -1));
344 }
345 }
346 }
347
348 /**
349 * $Log: EjAltCurrTender.java,v $
350 * Revision 1.1.1.1 2001/08/13 22:19:46 qolson
351 * Initial Checkin 0.2-2
352 *
353 *
354 */