CONTROLAR STOCK Y INSERTAR NUEVO PRECIO A PRODUCTO

CONTROLAR STOCK

AÑADIR 4 variables DENTRO DEL METODO evalScript EN JPanelTicket

(En JPanelTicket añadir esta linea: import com.openbravo.pos.util.AltEncrypter;)
Modificar el metodo evalScript en ScriptObject class dentro de 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 {
 //INSERTAR NUEVO PRECIO DEL PRODUCTO
    value = javax.swing.JOptionPane.showInputDialog("Price", "");
 
  try {
    Double newPrice = new Double(value);
    value2 = newPrice/1.18;
    line.setPrice(value2);
 
  } catch (NumberFormatException e) {
    JOptionPane.showMessageDialog(null, "Not valid number: " + value, "Error", JOptionPane.PLAIN_MESSAGE);
 
  } 
         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 {
 //INSERTAR NUEVO PRECIO DEL PRODUCTO
    value = javax.swing.JOptionPane.showInputDialog("Price", "");
 
  try {
    Double newPrice = new Double(value);
    value2 = newPrice/1.18;
    line.setPrice(value2);
 
  } catch (NumberFormatException e) {
    JOptionPane.showMessageDialog(null, "Not valid number: " + value, "Error", JOptionPane.PLAIN_MESSAGE);
 
  } 
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.

Comentarios

Entradas populares