updated code
enable finalization store transaction status checking
This commit is contained in:
		
							parent
							
								
									a37e9240bb
								
							
						
					
					
						commit
						eee0848dff
					
				
					 1 changed files with 34 additions and 24 deletions
				
			
		|  | @ -4,9 +4,6 @@ | ||||||
|  */ |  */ | ||||||
| package tech.iBeans.POSware.Lite; | package tech.iBeans.POSware.Lite; | ||||||
| 
 | 
 | ||||||
| // Import local modules.  |  | ||||||
| import tech.iBeans.POSware.Lite.inventory.*; |  | ||||||
| import tech.iBeans.POSware.Lite.receipt.*; |  | ||||||
| 
 | 
 | ||||||
| import java.text.DecimalFormat; | import java.text.DecimalFormat; | ||||||
| // Import global modules.  | // Import global modules.  | ||||||
|  | @ -17,9 +14,10 @@ import java.util.*; | ||||||
|  * @author eleven |  * @author eleven | ||||||
|  */ |  */ | ||||||
| public class transact { | public class transact { | ||||||
|     public static Dictionary<String, Dictionary> items = new Hashtable<>();  |     public static Dictionary<String, Dictionary<String, Object>> items = new Hashtable<>();  | ||||||
|     public static Dictionary<String, Float> price = new Hashtable<>(); |     public static Dictionary<String, Float> price = new Hashtable<>(); | ||||||
| 	public static Boolean state = false; | 	public static Boolean state = false; | ||||||
|  |     public static Boolean progress = false; | ||||||
|      |      | ||||||
|     /*  |     /*  | ||||||
|     {item: { |     {item: { | ||||||
|  | @ -41,6 +39,7 @@ public class transact { | ||||||
|         /* Initialize the variables, setting them with default values.  |         /* Initialize the variables, setting them with default values.  | ||||||
|         */ |         */ | ||||||
|          |          | ||||||
|  |         progress = true; | ||||||
|         items = new Hashtable<>(); |         items = new Hashtable<>(); | ||||||
|         price = new Hashtable<>(); |         price = new Hashtable<>(); | ||||||
|          |          | ||||||
|  | @ -66,7 +65,8 @@ public class transact { | ||||||
| 		return(state); | 		return(state); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
|     public static Dictionary calculate() { |     @SuppressWarnings("unchecked") | ||||||
|  |     public static Dictionary<String, Float> calculate() { | ||||||
|         /* Calculate the subtotal, total, and VAT.  |         /* Calculate the subtotal, total, and VAT.  | ||||||
|          |          | ||||||
|         Returns: (Dictionary) the contents of the price variable |         Returns: (Dictionary) the contents of the price variable | ||||||
|  | @ -84,17 +84,17 @@ public class transact { | ||||||
|         while (items_list.hasMoreElements()) { |         while (items_list.hasMoreElements()) { | ||||||
|             String item = items_list.nextElement(); |             String item = items_list.nextElement(); | ||||||
|              |              | ||||||
|             if (((Dictionary) items.get(item).get("price")).get("tax") != null) { |             if (((Dictionary<String, Object>) items.get(item).get("price")).get("tax") != null) { | ||||||
|                 price.put("tax", (float) price.get("tax") + (float) ((Dictionary) items.get(item).get("price")).get("tax")); |                 price.put("tax", (float) price.get("tax") + (float) ((Dictionary<String, Object>) items.get(item).get("price")).get("tax")); | ||||||
|             }; |             }; | ||||||
|             if (((Dictionary) items.get(item).get("price")).get("subtotal") != null) { |             if (((Dictionary<String, Object>) items.get(item).get("price")).get("subtotal") != null) { | ||||||
|                 price.put("subtotal", (float) price.get("subtotal") + (float) ((Dictionary) items.get(item).get("price")).get("subtotal")); |                 price.put("subtotal", (float) price.get("subtotal") + (float) ((Dictionary<String, Object>) items.get(item).get("price")).get("subtotal")); | ||||||
|             }; |             }; | ||||||
|             if (((Dictionary) items.get(item).get("price")).get("total") != null) { |             if (((Dictionary<String, Object>) items.get(item).get("price")).get("total") != null) { | ||||||
|                 price.put("total", (float) price.get("total") + (float) ((Dictionary) items.get(item).get("price")).get("total")); |                 price.put("total", (float) price.get("total") + (float) ((Dictionary<String, Object>) items.get(item).get("price")).get("total")); | ||||||
|             }; |             }; | ||||||
|             if (((Dictionary) items.get(item).get("price")).get("discount") != null) { |             if (((Dictionary<String, Object>) items.get(item).get("price")).get("discount") != null) { | ||||||
|                 price.put("discount", (float) price.get("discount") + (float) ((Dictionary) items.get(item).get("price")).get("discount")); |                 price.put("discount", (float) price.get("discount") + (float) ((Dictionary<String, Object>) items.get(item).get("price")).get("discount")); | ||||||
|             }; |             }; | ||||||
|         }; |         }; | ||||||
|          |          | ||||||
|  | @ -108,9 +108,10 @@ public class transact { | ||||||
|         return(price); |         return(price); | ||||||
|     }; |     }; | ||||||
|      |      | ||||||
|  |     @SuppressWarnings("unchecked") | ||||||
|     public static Dictionary<String, Float> calculate(String SKU, int QUANTITY) { |     public static Dictionary<String, Float> calculate(String SKU, int QUANTITY) { | ||||||
|         inventory.refresh(); |         inventory.refresh(); | ||||||
|         Dictionary item_details = inventory.items.get(SKU); |         Dictionary<String, Object> item_details = inventory.items.get(SKU); | ||||||
|          |          | ||||||
|         // Create an output dictionary.  |         // Create an output dictionary.  | ||||||
|         Dictionary<String, Float> item_pricing = new Hashtable<>(); |         Dictionary<String, Float> item_pricing = new Hashtable<>(); | ||||||
|  | @ -174,11 +175,11 @@ public class transact { | ||||||
|         Returns: (boolean) the calculation state |         Returns: (boolean) the calculation state | ||||||
|         */ |         */ | ||||||
|          |          | ||||||
|         if (QUANTITY == 0) {return(false);} |         if (QUANTITY == 0 || !progress) {return(false);} | ||||||
|         else if (QUANTITY < 0) {return(remove(SKU, QUANTITY));}; |         else if (QUANTITY < 0) {return(remove(SKU, QUANTITY));}; | ||||||
|          |          | ||||||
|         // containing the current data's information |         // containing the current data's information | ||||||
|         Dictionary ITEM_CURRENT_DATA = items.get(SKU); |         Dictionary<String, Object> ITEM_CURRENT_DATA = items.get(SKU); | ||||||
|          |          | ||||||
|         // check if the item exists |         // check if the item exists | ||||||
|         if (ITEM_CURRENT_DATA != null) { |         if (ITEM_CURRENT_DATA != null) { | ||||||
|  | @ -218,11 +219,11 @@ public class transact { | ||||||
|         Returns: (boolean) the removal state |         Returns: (boolean) the removal state | ||||||
|         */ |         */ | ||||||
|          |          | ||||||
|         if (QUANTITY == 0) {return(false);} |         if (QUANTITY == 0 || !progress) {return(false);} | ||||||
|         else if (QUANTITY < 0) {return(add(SKU, QUANTITY));}; |         else if (QUANTITY < 0) {return(add(SKU, QUANTITY));}; | ||||||
|          |          | ||||||
|         // containing the current data's information |         // containing the current data's information | ||||||
|         Dictionary ITEM_CURRENT_DATA = items.get(SKU); |         Dictionary<String, Object> ITEM_CURRENT_DATA = items.get(SKU); | ||||||
|          |          | ||||||
|         // check if the item exists. There's no need to remove an item that's already been removed.  |         // check if the item exists. There's no need to remove an item that's already been removed.  | ||||||
|         if (ITEM_CURRENT_DATA != null) { |         if (ITEM_CURRENT_DATA != null) { | ||||||
|  | @ -252,15 +253,24 @@ public class transact { | ||||||
| 
 | 
 | ||||||
|     public static void pay() { |     public static void pay() { | ||||||
|         /* Initialize the payment process of the transaction.  */ |         /* Initialize the payment process of the transaction.  */ | ||||||
|  |         if (state && progress) { | ||||||
|  |             // Can only run when the transaction is active (you don't want to pay again right after you've paid, right?) | ||||||
|             payment.init(Float.valueOf(FORMAT_DECIMAL.format(Float.valueOf(price.get("total").toString())))); |             payment.init(Float.valueOf(FORMAT_DECIMAL.format(Float.valueOf(price.get("total").toString())))); | ||||||
|         }; |         }; | ||||||
|  |     }; | ||||||
| 
 | 
 | ||||||
|     public static void finalise() { |     public static void finalise() { | ||||||
|         /* Finalize the transaction. */ |         /* Finalize the transaction. */ | ||||||
| 
 | 
 | ||||||
|         // TODO Replace this section with wrapping up the payment, "saving" the receipt, and then initializing it.  |         // Can only be run if the payment has been confirmed | ||||||
|          |         if (payment.state != null) { | ||||||
|         // receipt.finalise(); |             if (payment.OK && payment.state) { | ||||||
|  |                 progress = false; // no more modifications | ||||||
|  |                 price.put("change", payment.change); | ||||||
|  |                 receipt.payment(price); | ||||||
|  |             }; | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
| } |         receipt.finish(); | ||||||
|  |     }; | ||||||
|  | }; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue