How to add products to the sales pannel
How this came about
I just went through this question to make it clearer. http://sourceforge.net/p/openbravopos/discussion/434922/thread/9f5f3eb6/?limit=25#1412 On sales panel say you can see five columns: Item, Price, Unit, Taxes, Value. To include a new column, say inventory stock count,paste this code fragment into your resources Ticket.Line.
<column name="label.value" width="80" align="right" value="$ {ticketline.printInventoryCount()}"/>
This my brother is an Openbravo Script. It gives the name value to the column we want to create, sets the size to 80, aligns right and the interesting part, it has to call the method printIventoryCount() found in the class TicketLineInfo.java. To get more info on this, I'll refer you to the Open bravo wiki page http://wiki.openbravo.com/wiki/Openbravo_POS_Scripting_Tutorial .
Phase 2
Now, about that java class aforementioned, the method does not normally exist you have to create it.
1. Browse through your eclipse package explorer
2. Go to src-pos > com.openbravo.pos.form and find TicketLineInfo.java.
3. Import the following as exlained in this wiki http://wiki.openbravo.com/wiki/POS_-_Script_how_to_get_data_from_the_database
import com.openbravo.pos.forms.DataLogicSales; import com.openbravo.pos.ticket.ProductInfoExt; import com.openbravo.data.loader.Session; import com.openbravo.pos.ticket.TicketLineInfo;
4.Declare object
DataLogicSales logic = new DataLogicSales();
Just incase you'd want to know, DatalogicSales.java has the performs the SQL queries through prepares sentences.
5.Create method
public String printInventoryCount() { String sDBUrl = "jdbc:postgresql://localhost:5432/o"; String sDBUser = "leo"; String sDBPassword = "leo"; Session session = null; /* if (sDBUser != null && sDBPassword != null && sDBPassword.startsWith("crypt:")) { AltEncrypter cypher = new AltEncrypter("cypherkey" + sDBUser); sDBPassword = cypher.decrypt(sDBPassword.substring(6)); } */ try { session = new Session(sDBUrl, sDBUser, sDBPassword); } catch (SQLException ex) { Logger.getLogger(TicketLineInfo.class.getName()).log(Level.SEVERE, null, ex); } logic.init(session); try { double scnt = logic.findProductStock("0",getProductID(), null); return Formats.DOUBLE.formatValue(scnt); } catch (BasicException ex) { Logger.getLogger(TicketLineInfo.class.getName()).log(Level.SEVERE, null, ex); return "err.."; } }
Allow me to explain a few things. JDBC is a Java-based data access technology (Java Standard Edition platform) from Oracle Corporation. This technology is an API for the Java programming language that defines how a client may access a database. It provides methods for querying and updating data in a database. JDBC is oriented towards relational databases. It's implementation is what you see here
jdbc:postgresql://localhost:5432/openbravopostgres
The data I want comes like I said from the DataLogicSales.java class which uses PreparedStatements. The usual practice is to abstract the database logic into an entirely different class and to pass preprocessed strings (perhaps derived themselves from a further abstracted class) containing SQL statements and the connection to the required methods. Abstracting the data model from the application code makes it more likely that changes to the application and data model can be made independently.
6. Resolve imports or insert these ones
import java.sql.SQLException; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger;
7. This last step is pretty ugly, you have to delete your database and create a new one will the appropriate configurations.
I'd look for a way to solve that, God willing. This is alot troublesome especially if you don't have your data centrally stored some where you could pull from and push to. Prochain arrêt. How to activate the POSSync and OrderSync buttons.