diff --git a/src/main/java/tech/iBeans/POSware/Lite/receipt.java b/src/main/java/tech/iBeans/POSware/Lite/receipt.java index 7bf94aa..900bc79 100644 --- a/src/main/java/tech/iBeans/POSware/Lite/receipt.java +++ b/src/main/java/tech/iBeans/POSware/Lite/receipt.java @@ -12,11 +12,66 @@ import tech.iBeans.POSware.Lite.data_test.*; */ public class receipt { public static String content = ""; + private static Dictionary data = new Hashtable<>(); public static void init() { 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() { /* Generate the headers. */ @@ -43,9 +98,35 @@ public class receipt { }; - content = content.concat(content_headers); + data.put("headers", content_headers); + refresh(); 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()); + }; }