POS - Calculate Units from Total Line Price
1) Add Permissions to Roles
Choose the Maintenance option, then choose Roles. Add this to the Roles needed to access this option and click/press the save icon:
<class name="button.calcunits"/>
2) Create Button
Choose the Maintenance option, then Resources. Add this to Tickets.Buttons resource and click/press the save icon:
<button key="button.calcunits" name="button.calcunits" code="Script.CalcUnits"/>
3) Create the Script.CalcUnits Resource
Choose the Maintenance Option, then choose Resources. Click/Press the option for new resource. Make sure the resource is set for "Text" and add the following as the resource Script.CalcUnits and click/press the save icon:
import javax.swing.JOptionPane; value = javax.swing.JOptionPane.showInputDialog("Price", ""); index = sales.getSelectedIndex(); line = ticket.getLine(index); try { Double newUnits = new Double(value); Double pricetax = line.getPriceTax(); line.setMultiply(newUnits/pricetax); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "Not valid number: " + value, "Error", JOptionPane.PLAIN_MESSAGE); }
4) Set Button Name
Add the following to the bottom of the pos_messages.properties file in locales folder:
button.calcunits=Calc Units