View source | Discuss this page | Page history | Printable version   

POS - Buy One Get One Free Discount

Code snippet

Name: Buy One Get One Discount
Version: Openbravo POS 2.30
Author: Scott Smith



A simple script which will allow you to have buy one, get one free discounts.

It has it's limitations although it should work with no problems. For example, when the operator enters in two items which have the buy one get one free discount applied to it, the attribute is set to 0 (meaning no discount) so additional discounts will apply. What this means is if the operator removes the discount and one of the items on special, adding additional items will reapply the discount. However the latter is less likely to be a problem than the former.

Add to Maintenance->Resources->Ticket.Buttons

<event key="ticket.change" code="event.change"/>

And add the following to Maintenance->Resources->event.change

import com.openbravo.pos.ticket.TicketLineInfo;

index = sales.getSelectedIndex();
if (index != -1) {
	line = ticket.getLine(index);
	/* Buy One Get One Discount */
	int bogo = Integer.parseInt(line.getProperty("BOGO","0"));
	if (bogo > 0) {
		int product_count = 0;
		String productID = line.getProductID();
		for (i = 0; i < ticket.getLinesCount(); i++) {
			if ((productID.equals(ticket.getLine(i).getProductID()) != null) &&
					(Integer.parseInt(ticket.getLine(i).getProperty("BOGO","0")) > 0)) {
				product_count++;
			}
		}
		if (bogo == product_count) {
			ticket.insertLine(ticket.getLinesCount(),
					new TicketLineInfo(
						"FREE - "+line.getProductName(),
						"000",
						1.0,
						-line.getPrice(),
						taxes.get("000")));
			/* Remove BOGO property to start fresh */
			for (i = 0; i < ticket.getLinesCount(); i++) {
				if (productID.equals(ticket.getLine(i).getProductID()) != null) {
					ticket.getLine(i).setProperty("BOGO","0");
				}
			}
		}
		sales.setSelectedIndex(ticket.getLinesCount()-1);
	}
}

Last but not least, in order for the product to be added as a buy one get one item, add this to the Properties tab of the product you wish to discount.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
    <entry key="BOGO">2</entry> 
</properties>

Where the value for BOGO is the number of product which will be discounted. Enter 0 for no discount, 2 for buy one get one, 3 for buy two get one and so on.

Retrieved from "http://wiki.openbravo.com/wiki/POS_-_Buy_One_Get_One_Free_Discount"

This page has been accessed 15,138 times. This page was last modified on 22 October 2009, at 13:49. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.