POS - Round to nearest 5 cents
Code snippetName: POS - Round to nearest 5 cents
|
This code was created using MySQL in Windows.
This script will allow you to round to the nearest 5 cents when completing a sale. It rounds up and down. For rounding down only, uncomment the two lines in the center of the script.
1) Add Event to the Ticket.Buttons Resource
Add the following event to the Ticket.Buttons resource:
<event key="ticket.total" code="event.total"/>
2) Create the event.total Resource
Create a text resource called event.total and add the following to it:
import com.openbravo.format.Formats; import com.openbravo.pos.ticket.TicketLineInfo; import com.openbravo.pos.ticket.TicketProductInfo; import java.util.Properties; total = ticket.getTotal(); if (total > 0.0) { //rounding m to nearest multiple of n m=total; n=5.0; //round to the nearest 5cents d = Math.floor((m*100.0+n/2.0)/n)*n/100.0-m; //round to 2 decimal places rounding = Math.round(d * Math.pow(10, (double) 2)) / Math.pow(10,(double) 2); //add line if rounding is needed if (rounding <= -0.01 || rounding >= 0.01) { taxes = ticket.getTaxLines(); for (int i = 0; i < taxes.length; i++) { taxline = taxes[i]; // if you only want to round down, remove slashes from the next two lines // if (rounding>0) { // rounding = rounding - .05; } ticket.insertLine(ticket.getLinesCount(), new TicketLineInfo( "Rounding adjustment", taxline.getTaxInfo().getTaxCategoryID(), 1.0, rounding, taxline.getTaxInfo())); } } sales.setSelectedIndex(ticket.getLinesCount() - 1); } else { java.awt.Toolkit.getDefaultToolkit().beep(); }
That should be it. You can obviously change anything you wish to suit your setup. Let me know if something is not working or something can be done better.
Good Luck, Ronny G