updated receipt handling
This commit is contained in:
parent
bc51ba83fd
commit
a3b83838b2
1 changed files with 82 additions and 1 deletions
|
@ -12,11 +12,66 @@ import tech.iBeans.POSware.Lite.data_test.*;
|
||||||
*/
|
*/
|
||||||
public class receipt {
|
public class receipt {
|
||||||
public static String content = "";
|
public static String content = "";
|
||||||
|
private static Dictionary<String, String> data = new Hashtable<>();
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
content = "";
|
content = "";
|
||||||
|
data.put("headers", "");
|
||||||
|
data.put("cart", "");
|
||||||
|
data.put("payment", "");
|
||||||
|
data.put("footer", "");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static String create() {
|
||||||
|
/* This is different from an initialization or reset — this alsof adds the headers!
|
||||||
|
|
||||||
|
Returns: (String) the content
|
||||||
|
*/
|
||||||
|
|
||||||
|
init();
|
||||||
|
headers();
|
||||||
|
|
||||||
|
return(content);
|
||||||
|
};
|
||||||
|
|
||||||
|
private static String ready() {
|
||||||
|
/* Prepare for a new data entry.
|
||||||
|
|
||||||
|
Returns: (String) the updated receipt
|
||||||
|
*/
|
||||||
|
|
||||||
|
content = content.concat("\n\n");
|
||||||
|
|
||||||
|
return(content);
|
||||||
|
};
|
||||||
|
|
||||||
|
public static String refresh() {
|
||||||
|
/* Refresh the receipt's content.
|
||||||
|
Returns: (string) the updated conntent
|
||||||
|
*/
|
||||||
|
|
||||||
|
content = "";
|
||||||
|
|
||||||
|
if (data.get("headers") != null) {
|
||||||
|
content = content.concat(data.get("headers").toString());
|
||||||
|
ready();
|
||||||
|
};
|
||||||
|
if (data.get("cart") != null) {
|
||||||
|
content = content.concat(data.get("cart").toString());
|
||||||
|
ready();
|
||||||
|
};
|
||||||
|
if (data.get("payment") != null) {
|
||||||
|
content = content.concat(data.get("payment").toString());
|
||||||
|
ready();
|
||||||
|
};
|
||||||
|
if (data.get("footer") != null) {
|
||||||
|
content = content.concat(data.get("footer").toString());
|
||||||
|
ready();
|
||||||
|
};
|
||||||
|
|
||||||
|
return(content);
|
||||||
|
};
|
||||||
|
|
||||||
public static String headers() {
|
public static String headers() {
|
||||||
/* Generate the headers.
|
/* Generate the headers.
|
||||||
*/
|
*/
|
||||||
|
@ -43,9 +98,35 @@ public class receipt {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
content = content.concat(content_headers);
|
data.put("headers", content_headers);
|
||||||
|
refresh();
|
||||||
|
|
||||||
return(content_headers);
|
return(content_headers);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static String action(String NAME, int QUANTITY, double PRICE, double TOTAL) {
|
||||||
|
/* Add an item to the cart.
|
||||||
|
Parameters:
|
||||||
|
(String) NAME: the name of the item
|
||||||
|
(int) QUANTITY: the quantity of the items in the cart
|
||||||
|
(double) PRICE: the unit price
|
||||||
|
(double) TOTAL: the total price
|
||||||
|
Returns: (String) the updated list of items in the cart
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (data.get("cart").toString().isBlank()) {
|
||||||
|
data.put("cart", "Quantity\tItem\tPrice\tTotal");
|
||||||
|
};
|
||||||
|
|
||||||
|
data.put("cart", data.get("cart").toString().concat("\n"));
|
||||||
|
String item_current = String.join("\t", String.valueOf(QUANTITY), NAME, String.valueOf(PRICE), String.valueOf(TOTAL));
|
||||||
|
data.put("cart", data.get("cart").toString().concat(item_current));
|
||||||
|
|
||||||
|
// Refresh.
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
// Return the updated receipt section preview.
|
||||||
|
return(data.get("cart").toString());
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue