//09/02/2011
//betojara: evalScript function to stock control
//more info: http://wiki.openbravo.com/wiki/POS_-_Check_stock_of_the_product
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);
}