Source code: com/globalretailtech/pos/events/LookupItem.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.events;
21
22 import java.util.Vector;
23
24 import com.globalretailtech.util.Log;
25 import com.globalretailtech.util.Application;
26 import com.globalretailtech.data.Plu;
27 import com.globalretailtech.data.Item;
28 import com.globalretailtech.pos.ej.EjItem;
29 import com.globalretailtech.pos.context.*;
30 import com.globalretailtech.pos.events.*;
31 import com.globalretailtech.pos.devices.OperPrompt;
32
33 /**
34 * Simulates an item lookup by creating an EjItem then engaging that class with
35 * the value from the input. If the input line is less than 8 (MAX_PLU_LEN) digits
36 * use the plu else lookup the sku directly.
37 *
38 * @author Quentin Olson
39 */
40 public class LookupItem extends PosEvent
41 {
42
43 public static final int MAX_PLU_LEN = 8;
44
45 /** Simple constructor for dynamic load */
46 public LookupItem ()
47 { }
48
49 /**
50 * If the input line is a certain length test to see if it
51 * exists as an item in the PLU file. Note: a 1-to-1 PLU
52 * to SKU map must be set up. Note: this should be connected
53 * to a filter instead of the hard-coded MAX_PLU_LEN. Otherwise
54 * Assume the PLU is coming from the input line, again Note: a 1-to-1 PLU
55 * to SKU map must be set up.
56 */
57 public void engage (int value)
58 {
59 // If there is a Size object on the stack, add the size
60 // to the value to get the plu (drinks, etc...)
61
62 if (context ().eventStack ().event () instanceof Size)
63 {
64 Size size = (Size) context ().eventStack ().event ();
65
66 value += size.size ();
67 context ().eventStack ().popEvent ();
68 }
69
70 if ( (value == 0) && (context ().inputLine ().length () < MAX_PLU_LEN) )
71 {
72 new EjItem (context ()).engage (context ().input ());
73 }
74 else
75 {
76 Vector tmp = Application.dbConnection ().fetch (new Plu (), Plu.getByPlu (value));
77
78 if (tmp.size () > 0)
79 {
80 // Item found
81 Plu plu = (Plu) tmp.elementAt (0);
82 EjItem ejitem = new EjItem (plu.item ());
83 ejitem.setContext (context ());
84 ejitem.engage (0);
85 }
86 }
87 }
88
89 /** Validate transistions state */
90 public boolean validTransition (String event)
91 {
92 return true;
93 }
94 /** Clear key implementation for this class */
95 public void clear ()
96 { }
97 private static String eventname = "LookupItem";
98 /** Return staic name. */
99 public String toString ()
100 {
101 return eventname;
102 }
103 /** Return staic name. */
104 public static String eventName ()
105 {
106 return eventname;
107 }
108 }
109
110
111 /**
112 * $Log: LookupItem.java,v $
113 * Revision 1.1.1.1 2001/08/13 22:17:11 qolson
114 * Initial Checkin 0.2-2
115 *
116 *
117 */