POS - Script how to get data from the database
Code snippetName: POS - Script how to get data from a database
|
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:
- url - url to the database
- user - database user
- password - user's password
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);