update transaction module

connect to receipt generation
This commit is contained in:
buzz-lightsnack-2007 2024-02-27 14:51:26 +08:00
parent 1c4ad00080
commit 3f63c102a9
2 changed files with 29 additions and 35 deletions

View file

@ -6,6 +6,7 @@ package tech.iBeans.POSware.Lite;
// Import local modules.
import tech.iBeans.POSware.Lite.inventory.*;
import tech.iBeans.POSware.Lite.receipt.*;
// Import global modules.
import java.util.*;
@ -44,6 +45,10 @@ public class transact {
price.put("tax", 0.00);
price.put("subtotal", 0.00);
price.put("discount", 0.00);
// Initialize as well the receipt.
receipt.init();
receipt.create();
};
public static Dictionary calculate() {
@ -101,6 +106,7 @@ public class transact {
if (item_details != null) {
if (item_details.get("Price") != null) {
item_pricing.put("unit", Double.valueOf(item_details.get("Price").toString()));
item_pricing.put("subtotal", Double.valueOf(item_details.get("Price").toString()) * QUANTITY);
item_pricing.put("total", Double.valueOf( item_pricing.get("subtotal")));
@ -131,6 +137,18 @@ public class transact {
};
private static void log(String SKU, int QUANTITY) {
/* Log the change in the cart.
Parameters:
(String) SKU: the sku to look for
(int) QUANTITY: the quantity of the product added or removed
*/
var action_pricing = calculate(SKU, QUANTITY);
receipt.action(SKU, QUANTITY, action_pricing.get("unit"), action_pricing.get("total"));
};
public static boolean add(String SKU, int QUANTITY) {
/* Add an item to the shopping cart.
Parameters:
@ -165,6 +183,11 @@ public class transact {
// Calculate all prices.
calculate();
// Add to the receipt when successful.
if ((items.get(SKU) != null)) {
log(SKU, QUANTITY);
};
// Return the success state.
return((items.get(SKU) != null));
};
@ -195,11 +218,14 @@ public class transact {
// Add to the shopping cart's items.
items.put(SKU, ITEM_CURRENT_DATA);
};
// Log the details.
log(SKU, -QUANTITY);
// Calculate all prices.
calculate();
};
// Calculate all prices.
calculate();
// Return the state.
return(true);
};

View file

@ -1,32 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package tech.iBeans.POSware.Lite;
import java.util.*;
/**
*
* @author eleven
*/
public class transaction {
// The current transaction item
public static ArrayList<String> items = new ArrayList<String>();
public static int items_count = items.size();
public static boolean add(String SKU, int QUANTITY) {
/* Add an item to the shopping cart.
Parameters:
SKU (String): the SKU of the item
QUANTITY (int): the quantity
Returns: (boolean) the add state
*/
items.add(SKU);
return(true);
};
};