You are on page 1of 3

9/12/2014

Login/createaccount

POSCheckstockoftheproductOpenbravoWiki
Openbravo.com

PartnerPortal

Issues

Blogs

Viewsource|

Forge

Exchange

University

Downloads

Discussthispage|Pagehistory|Printableversion

POSCheckstockoftheproduct
Contents
1C odesnippet
2AddFourvariablesintoevalScript
methodinJPanelTicket
3C reateScript.StockC urrentAdd
resource
4C reateScript.StockC urrentSet
resource
5Inserttwoevents

Codesnippet
Name:POS heckstockoftheproduct
Version:POS2.30
Author:AndrejSvininykh

AddFourvariablesintoevalScriptmethodinJPanelTicket
(InJPanelTicketaddthisline:importcom.openbravo.pos.util.AltEncrypter)
ModifythemethodevalScriptinScriptObjectclassinsideJPanelTicket.
Getuserandpasswordofdatabase.

StringsDBUser=m_App.getProperties().getProperty("db.user");
StringsDBPassword=m_App.getProperties().getProperty("db.password");
if(sDBUser!=null&&sDBPassword!=null&&sDBPassword.startsWith("crypt:")){
AltEncryptercypher=newAltEncrypter("cypherkey"+sDBUser);
sDBPassword=cypher.decrypt(sDBPassword.substring(6));
}
C reatevariableforconnectingintothedatabaseandgettingresources.

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);
Allthetogetherlookslike:

publicObjectevalScript(Stringcode,ScriptArg...args)throwsScriptException{

ScriptEnginescript=ScriptFactory.getScriptEngine(ScriptFactory.BEANSHELL);

StringsDBUser=m_App.getProperties().getProperty("db.user");
StringsDBPassword=m_App.getProperties().getProperty("db.password");
if(sDBUser!=null&&sDBPassword!=null&&sDBPassword.startsWith("crypt:")){
AltEncryptercypher=newAltEncrypter("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);

http://wiki.openbravo.com/wiki/POS__Check_stock_of_the_product

1/3

9/12/2014

POSCheckstockoftheproductOpenbravoWiki

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);

//morearguments
for(ScriptArgarg:args){
script.put(arg.getKey(),arg.getValue());
}

returnscript.eval(code);
}

CreateScript.StockCurrentAddresource

importcom.openbravo.pos.forms.DataLogicSales;
importcom.openbravo.pos.forms.DataLogicSystem;
importcom.openbravo.data.loader.Session;
importjava.util.Properties;

Sessionsession=newSession(dbURL,dbUser,dbPassword);
DataLogicSaleslogicsale=newDataLogicSales();
logicsale.init(session);
DataLogicSystemlogicsystem=newDataLogicSystem();
logicsystem.init(session);
Propertiesp=logicsystem.getResourceAsProperties(hostname+"/properties");
Stringloc=p.getProperty("location");

product=line.getProductID();
units=logicsale.findProductStock(loc,product,null);
multiply=0;
for(inti=0;i<ticket.getLinesCount();i++){
row=ticket.getLine(i);
if(row.getProductID()==product){
multiply=multiply+row.getMultiply();
}
}
diff=unitsline.getMultiply()multiply;
if(diff<0.0){
javax.swing.JOptionPane.showMessageDialog(null,"Thereisnoenoughinthelocationnumber"+loc+".","Stock",JOptionPane.WARNING_MESSAGE);
return"Cancel";
}else{
returnnull;
}

CreateScript.StockCurrentSetresource

importcom.openbravo.pos.forms.DataLogicSales;
importcom.openbravo.pos.forms.DataLogicSystem;
importcom.openbravo.data.loader.Session;
importjava.util.Properties;

Sessionsession=newSession(dbURL,dbUser,dbPassword);
DataLogicSaleslogicsale=newDataLogicSales();
logicsale.init(session);
DataLogicSystemlogicsystem=newDataLogicSystem();
logicsystem.init(session);
Propertiesp=logicsystem.getResourceAsProperties(hostname+"/properties");
Stringloc=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=multiplycurrentrow.getMultiply();
}

http://wiki.openbravo.com/wiki/POS__Check_stock_of_the_product

2/3

9/12/2014

POSCheckstockoftheproductOpenbravoWiki

for(inti=0;i<ticket.getLinesCount();i++){
row=ticket.getLine(i);
if(row.getProductID()==product){
multiply=multiply+row.getMultiply();
}
}
diff=unitsline.getMultiply()multiply;
if(diff<0.0){
javax.swing.JOptionPane.showMessageDialog(null,"Thereisnoenoughinthelocationnumber"+loc+".","Stock",JOptionPane.WARNING_MESSAGE);
return"Cancel";
}else{
returnnull;
}

Inserttwoevents
GotoMaintenance>Resources>Ticket.Buttonsandcreatetwonewevents:

<eventkey="ticket.addline"code="Script.StockCurrentAdd"/>
<eventkey="ticket.setline"code="Script.StockCurrentSet"/>
Itisall.
Retrievedfrom"http://wiki.openbravo.com/wiki/POS__C heck_stock_of_the_product"
Thispagehasbeenaccessed12,817times.Thispagewaslastmodifiedon24July2010,at14:45.C ontentisavailableunderC reativeC ommons
AttributionShareAlike2.5SpainLicense.
Categories:Templates|CodeSnippetsPOS

http://wiki.openbravo.com/wiki/POS__Check_stock_of_the_product

3/3

You might also like