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 - Check stock of the product

Contents

Code snippet

Name: POS - –°heck stock of the product
Version: POS 2.30
Author: Andrej Svininykh



Add Four variables into evalScript method in JPanelTicket

(In JPanelTicket add this line : import com.openbravo.pos.util.AltEncrypter;)

Modify the method evalScript in ScriptObject class inside JPanelTicket.

Get user and password of database.

 
  String sDBUser = m_App.getProperties().getProperty("db.user");
  String sDBPassword = m_App.getProperties().getProperty("db.password");
  if (sDBUser != null && sDBPassword != null && sDBPassword.startsWith("crypt:")) {
     AltEncrypter cypher = new AltEncrypter("cypherkey" + sDBUser);
     sDBPassword = cypher.decrypt(sDBPassword.substring(6));
   }

Create variable for connecting into the database and getting resources.

 
  script.put("hostname", m_App.getProperties().getProperty("machine.hostname"));
  script.put("dbURL", m_App.getProperties().getProperty("db.URL")); 
  script.put("dbUser", sDBUser);
  script.put("dbPassword", sDBPassword);

All the together looks like:

 
 public Object evalScript(String code, ScriptArg... args) throws ScriptException {
 
 ScriptEngine script = ScriptFactory.getScriptEngine(ScriptFactory.BEANSHELL);
 
 String sDBUser = m_App.getProperties().getProperty("db.user");
 String sDBPassword = m_App.getProperties().getProperty("db.password");
 if (sDBUser != null && sDBPassword != null && sDBPassword.startsWith("crypt:")) {
     AltEncrypter cypher = new AltEncrypter("cypherkey" + sDBUser);
     sDBPassword = cypher.decrypt(sDBPassword.substring(6));
 }
 
 script.put("hostname", m_App.getProperties().getProperty("machine.hostname"));
 script.put("dbURL", m_App.getProperties().getProperty("db.URL")); 
 script.put("dbUser", sDBUser);
 script.put("dbPassword", sDBPassword);
 
 script.put("ticket", ticket);
 script.put("place", ticketext);
 script.put("taxes", taxcollection);
 script.put("taxeslogic", taxeslogic);             
 script.put("user", m_App.getAppUserView().getUser());
 script.put("sales", this);
  
 // more arguments
 for(ScriptArg arg : args) {
     script.put(arg.getKey(), arg.getValue());
 }             
 
 return script.eval(code);
 }

Create Script.StockCurrentAdd resource

 
 import com.openbravo.pos.forms.DataLogicSales;
 import com.openbravo.pos.forms.DataLogicSystem;
 import com.openbravo.data.loader.Session;
 import java.util.Properties;
 
 Session session = new Session(dbURL, dbUser, dbPassword);
 DataLogicSales logicsale = new DataLogicSales();
 logicsale.init(session);
 DataLogicSystem logicsystem = new DataLogicSystem();
 logicsystem.init(session);
 Properties p = logicsystem.getResourceAsProperties(hostname + "/properties");
 String loc = p.getProperty("location");
 
 product = line.getProductID();
 units = logicsale.findProductStock(loc,product,null);
 multiply = 0;
 for (int i= 0; i < ticket.getLinesCount(); i++) {
     row = ticket.getLine(i);
     if (row.getProductID() == product) {
        multiply = multiply + row.getMultiply();
     }
 }
 diff = units - line.getMultiply() - multiply;
 if (diff < 0.0) {
    javax.swing.JOptionPane.showMessageDialog(null, "There is no enough in the location number " + loc + ".", "Stock", JOptionPane.WARNING_MESSAGE);
    return "Cancel";
 } else {
         return null;
 }

Create Script.StockCurrentSet resource

 
 import com.openbravo.pos.forms.DataLogicSales;
 import com.openbravo.pos.forms.DataLogicSystem;
 import com.openbravo.data.loader.Session;
 import java.util.Properties;
 
 Session session = new Session(dbURL, dbUser, dbPassword);
 DataLogicSales logicsale = new DataLogicSales();
 logicsale.init(session);
 DataLogicSystem logicsystem = new DataLogicSystem();
 logicsystem.init(session);
 Properties p = logicsystem.getResourceAsProperties(hostname + "/properties");
 String loc = p.getProperty("location");
 
 product = line.getProductID();
 units = logicsale.findProductStock(loc,product,null);
 multiply = 0;
 index = sales.getSelectedIndex();
 if (index != -1) {
     currentrow = ticket.getLine(index);
     multiply = multiply - currentrow.getMultiply();
 }
 for (int i= 0; i < ticket.getLinesCount(); i++) {
     row = ticket.getLine(i);
     if (row.getProductID() == product) {
        multiply = multiply + row.getMultiply();
     }
 }
 diff = units - line.getMultiply() - multiply;
 if (diff < 0.0) {
    javax.swing.JOptionPane.showMessageDialog(null, "There is no enough in the location number " + loc + ".", "Stock", JOptionPane.WARNING_MESSAGE);
    return "Cancel";
 } else {
         return null;
 }

Insert two events

Go to Maintenance --> Resources --> Ticket.Buttons and create two new events:

 
 <event key="ticket.addline" code="Script.StockCurrentAdd"/>
 <event key="ticket.setline" code="Script.StockCurrentSet"/>

It is all.

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

This page has been accessed 16,404 times. This page was last modified on 24 July 2010, at 14:45. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.