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

POS - Script how to get data from the database

Code snippet

Name: POS - Script how to get data from a database
Version: POS/2.20 & 2.30 Beta
Author: Jarek Wozniak



The following script is an example how to get data from the database

Before reading it you should be famliar with the scripting tutorial

At the begining all additional classes that are going to be used must be imported:

import com.openbravo.pos.forms.DataLogicSales; 
import com.openbravo.pos.ticket.ProductInfoExt; 
import com.openbravo.data.loader.Session;
import com.openbravo.pos.ticket.TicketLineInfo;

Later to work with DataLogicSales object we need to initialize a session:

Session session = new Session("url",  "user", "password"); 
DataLogicSales logic = new DataLogicSales();
logic.init(session);

where:

Then is already easy to do everything like usual:

index = sales.getSelectedIndex();
line = ticket.getLine(index);
ProductInfoExt product = logic.getProductInfo(line.getProductID());

At the end we can show a Dialog message with the name of the product to check if everything works correctly:

JOptionPane.showMessageDialog(null, "Product: " + product.getName(), "",    JOptionPane.PLAIN_MESSAGE);

All the together looks like:

import com.openbravo.pos.forms.DataLogicSales; 
import com.openbravo.pos.ticket.ProductInfoExt; 
import com.openbravo.data.loader.Session;
import com.openbravo.pos.ticket.TicketLineInfo;

Session session = new Session("url",  "user", "password"); 
DataLogicSales logic = new DataLogicSales();
logic.init(session);

index = sales.getSelectedIndex();
line = ticket.getLine(index);
ProductInfoExt product = logic.getProductInfo(line.getProductID());

JOptionPane.showMessageDialog(null, "Product: " + product.getName(), "",    JOptionPane.PLAIN_MESSAGE);

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

This page has been accessed 18,429 times. This page was last modified on 25 March 2009, at 11:54. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.