update code to add payment

This commit is contained in:
buzz-lightsnack-2007 2024-02-28 00:57:26 +08:00
parent f602027e88
commit b21f48c4ff
2 changed files with 39 additions and 18 deletions

View file

@ -6,9 +6,11 @@ package tech.iBeans.POSware.Lite;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*; import javax.swing.event.*;
import java.awt.event.*;
import tech.iBeans.POSware.Lite.transact; import tech.iBeans.POSware.Lite.transact;
import tech.iBeans.POSware.Lite.WindowManagement; import tech.iBeans.POSware.Lite.WindowManagement;
import tech.iBeans.POSware.Lite.receipt; import tech.iBeans.POSware.Lite.receipt;
import tech.iBeans.POSware.Lite.OnPayment;
/** /**
* *
@ -24,13 +26,7 @@ public class OnTransact extends javax.swing.JFrame {
initComponents(); initComponents();
} }
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() { private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints; java.awt.GridBagConstraints gridBagConstraints;
@ -241,14 +237,15 @@ public class OnTransact extends javax.swing.JFrame {
gridBagConstraints.gridy = 2; gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0; gridBagConstraints.weightx = 1.0;
jPanel_Inventory.add(jPanel_Inventory_Actions, gridBagConstraints);
jList1_Inventory.setModel(refresh_inventory_list()); jList1_Inventory.setModel(refresh_inventory_list());
jList1_Inventory.addListSelectionListener(new javax.swing.event.ListSelectionListener() { jList1_Inventory.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) { public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
jList1_InventoryValueChanged(evt); jList1_InventoryValueChanged(evt);
} }
}); });
jPanel_Inventory.add(jPanel_Inventory_Actions, gridBagConstraints);
jScrollPane_Inventory.setViewportView(jList1_Inventory); jScrollPane_Inventory.setViewportView(jList1_Inventory);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints = new java.awt.GridBagConstraints();
@ -318,6 +315,9 @@ public class OnTransact extends javax.swing.JFrame {
getContentPane().add(jPanel_Main, java.awt.BorderLayout.CENTER); getContentPane().add(jPanel_Main, java.awt.BorderLayout.CENTER);
// Add action listeners.
jButton_Action_Pay.addActionListener(select_payment);
pack(); pack();
}// </editor-fold> }// </editor-fold>
@ -598,7 +598,13 @@ public class OnTransact extends javax.swing.JFrame {
return(state); return(state);
}; };
// Action events.
ActionListener select_payment = new ActionListener() {
public void actionPerformed(ActionEvent e) {
transact.pay();
OnPayment.display();
};
};

View file

@ -1,5 +1,7 @@
package tech.iBeans.POSware.Lite; package tech.iBeans.POSware.Lite;
import tech.iBeans.POSware.Lite.receipt.*;
// Import module // Import module
import java.util.*; import java.util.*;
import java.math.*; import java.math.*;
@ -8,26 +10,28 @@ public class payment{
public static Float total = null; public static Float total = null;
public static Float change = null; public static Float change = null;
public static Float in = null; public static Float in = null;
public static boolean OK = false;
public static Boolean state = null;
public static void init() { public static void init(float TOTAL) {
/* Set up the payment. */ /* Set up the payment. */
change = (float) 0; change = (float) 0;
in = (float) 0; in = (float) 0;
total = TOTAL;
}; };
public static Float calculate() { public static boolean calculate() {
/* Calculate the change. /* Calculate the change.
* *
* Returns: (float) the calculated change * Returns: (float) the transaction state
*/ */
OK = (total <= in);
if (total > in) {return (null);}; // Do not calculate a smaller change. if (OK) {change = in - total;}; // Do not calculate a smaller change.
change = in - total; return(OK);
return(change);
}; };
public static Float calculate(float TOTAL, float IN) { public static boolean calculate(float TOTAL, float IN) {
/* Calculate the change from a provided total and input. /* Calculate the change from a provided total and input.
* *
* Returns: (float) the calculated change * Returns: (float) the calculated change
@ -39,6 +43,17 @@ public class payment{
return(calculate()); return(calculate());
}; };
public static boolean calculate(float IN) {
/* Calculate the change from a provided input.
*
* Returns: (float) the calculated change
*/
in = IN;
return(calculate());
};
public static void log() { public static void log() {
/* Log the payment. /* Log the payment.
*/ */