add payment recording

This commit is contained in:
buzzcode2007 2024-02-28 09:43:35 +08:00
parent 8f0193f55f
commit 49e089f0e5

View file

@ -85,33 +85,33 @@ public class receipt {
/* Generate the headers. /* Generate the headers.
*/ */
Dictionary <String, String> content_headers_raw = data_test.read_properties(); Dictionary <String, String> content_headers_raw = data_test.read_properties();
Enumeration<String> content_headers_raw_headers = content_headers_raw.keys(); Enumeration<String> content_headers_raw_headers = content_headers_raw.keys();
String content_headers = ""; String content_headers = "";
if (content_headers_raw.get("Full Name") != null) { if (content_headers_raw.get("Full Name") != null) {
content_headers = content_headers_raw.get("Full Name"); content_headers = content_headers_raw.get("Full Name").toUpperCase();
} else if (content_headers_raw.get("Name") != null) { } else if (content_headers_raw.get("Name") != null) {
content_headers = content_headers_raw.get("Name"); content_headers = content_headers_raw.get("Name").toUpperCase();
}; };
while (content_headers_raw_headers.hasMoreElements()) { while (content_headers_raw_headers.hasMoreElements()) {
String content_headers_header = content_headers_raw_headers.nextElement(); String content_headers_header = content_headers_raw_headers.nextElement();
if (content_headers_raw.get(content_headers_header) != null) { if (content_headers_raw.get(content_headers_header) != null) {
if (!content_headers_header.contains("Name")) { if (!content_headers_header.contains("Name")) {
content_headers = content_headers.concat("\n"); content_headers = content_headers.concat("\n");
content_headers = content_headers.concat(content_headers_header.concat(": ")); content_headers = content_headers.concat(content_headers_header.concat(": "));
content_headers = content_headers.concat(content_headers_raw.get(content_headers_header)); content_headers = content_headers.concat(content_headers_raw.get(content_headers_header));
}; };
}; };
}; };
data.put("headers", content_headers); data.put("headers", content_headers);
refresh(); refresh();
return(content_headers); return(content_headers);
}; };
public static String action(String NAME, int QUANTITY, double PRICE, double TOTAL) { public static String action(String NAME, int QUANTITY, double PRICE, double TOTAL) {
/* Add an item to the cart. /* Add an item to the cart.
@ -127,15 +127,42 @@ public class receipt {
data.put("cart", "Quantity\tItem\n\tPrice\tTotal"); data.put("cart", "Quantity\tItem\n\tPrice\tTotal");
}; };
data.put("cart", data.get("cart").toString().concat("\n")); data.put("cart", data.get("cart").toString().concat("\n"));
String item_current = String.join("\t", String.valueOf(QUANTITY), NAME, "\n", String.valueOf(PRICE), String.valueOf(TOTAL)); String item_current = String.join("\t", String.valueOf(QUANTITY), NAME, "\n", String.valueOf(PRICE), String.valueOf(TOTAL));
data.put("cart", data.get("cart").toString().concat(item_current)); data.put("cart", data.get("cart").toString().concat(item_current));
// Refresh. // Refresh.
refresh(); refresh();
// Return the updated receipt section preview. // Return the updated receipt section preview.
return(data.get("cart").toString()); return(data.get("cart").toString());
}; };
public static String payment(Dictionary<String, Float> details) {
/* Add the payment data.
*
* Parameters:
* (Dict) details: the payment details, including total, subtotal, and change
*
* Returns: (String) the portion of the receipt
*/
// re-initialize the payment details
data.put("payment", "");
// Check for the details
Enumeration<String> details_contents = details.keys();
while (details_contents.hasMoreElements()) {
String details_content = details_contents.nextElement();
data.put("payment", data.get("payment").concat("\n"));
data.put("payment", data.get("payment").concat(String.join(": ", (details_content.contains("total")) ? details_content.toUpperCase() : details_content.substring(0, 1).toUpperCase() + details_content.substring(1), String.valueOf(details.get(details_content)))));
};
refresh();
return(data.get("payment"));
};
} }