View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Add page
Show collection (0 pages)
Collections help

Search

POS - Consolidate the receipt

Code snippet

Name: POS - Consolidate the receipt
Version: POS/2.20 & 2.30 Beta
Author: prakashbharatkar (Wikieditor:Seballa)



These scripts will consolidate the receipt by, removing duplicate item entries and adding their units to the first entry of the item.

1) Create the Code.ReceiptConsolidate Resource

Create a text resource called Code.ReceiptConsolidate and add the following to it:

// Consolidate the receipt 


// Remove duplicate item entries
// Add their units to the first entry of the item


import com.openbravo.format.Formats;
import com.openbravo.pos.ticket.TicketLineInfo;
import com.openbravo.pos.ticket.TicketInfo;
import com.openbravo.pos.ticket.TicketProductInfo; 
import java.util.Properties;

int numlines = ticket.getLinesCount(); 

for (int i = 0 ; i < numlines ; i++) {  
 	current_ticketline = ticket.getLine(i);
	current_unit  = current_ticketline.getMultiply();
	if ( current_unit != 0){
		for (int j = i + 1 ; j < numlines ; j++) {
			loop_ticketline = ticket.getLine(j);
			loop_unit  = loop_ticketline.getMultiply();  
 			String current_productid = current_ticketline.getProductID();
			String loop_productid    = loop_ticketline.getProductID();

				if ( loop_productid.equals(current_productid) && (loop_ticketline.getPrice() == current_ticketline.getPrice()) && (loop_unit != 0) ){
					current_unit = current_unit + loop_unit;
					loop_ticketline.setMultiply(0);	
			}	
		}
	current_ticketline.setMultiply(current_unit);
	}	
 }


// now remove the ticket lines where the unit = 0
// start deleteing in reverse order

for (int i = numlines - 1 ; i > 0 ; i--) { 
	loop_ticketline = ticket.getLine(i);
	loop_unit  = loop_ticketline.getMultiply();
	if (loop_unit == 0){
		ticket.removeLine(i);
		
	}
} 

2) In Maintanace > Resource > Ticket.Buttons, add the lines

<event  key="ticket.total" code="Code.ReceiptConsolidate"/>

3) Optionaly you can also consolidat the preview Print Note, that all the items are merged and you can not undo it when you do a preview: - Edit this line in Tickets.Buttons

<button key="button.print" titlekey="button.print" code="Printer.consolidate"/>

- create new resource Printer.consolidate with this content:

import com.openbravo.format.Formats;
import com.openbravo.pos.ticket.TicketLineInfo;
import com.openbravo.pos.ticket.TicketInfo;
import com.openbravo.pos.ticket.TicketProductInfo; 
import java.util.Properties;

int numlines = ticket.getLinesCount();

for (int i = 0 ; i < numlines ; i++) {  
	current_ticketline = ticket.getLine(i);
	current_unit  = current_ticketline.getMultiply();
	if ( current_unit != 0){
		for (int j = i + 1 ; j < numlines ; j++) {
			loop_ticketline = ticket.getLine(j);
			loop_unit  = loop_ticketline.getMultiply();  
			String current_productid = current_ticketline.getProductID();
			String loop_productid    = loop_ticketline.getProductID();

			if ( loop_productid.equals(current_productid) && (loop_ticketline.getPrice() == current_ticketline.getPrice()) && (loop_unit != 0) ){
				current_unit = current_unit + loop_unit;
				loop_ticketline.setMultiply(0);	
			}	
		}
	current_ticketline.setMultiply(current_unit);
	}	
}


// now remove the ticket lines where the unit = 0
// start deleteing in reverse order

for (int i = numlines - 1 ; i > 0 ; i--) { 
	loop_ticketline = ticket.getLine(i);
	loop_unit  = loop_ticketline.getMultiply();
	if (loop_unit == 0){
		ticket.removeLine(i);
		
	}
}

sales.printTicket("Printer.TicketPreview");

Have Fun!

Seballa

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

This page has been accessed 9,229 times. This page was last modified on 24 July 2009, at 15:22. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.