use of org.compiere.process.ProcessInfo in project adempiere by adempiere.
the class AbstractADWindowPanel method actionButton.
//
/**************************************************************************
* Start Button Process
* @param wButton button
*/
private void actionButton(WButtonEditor wButton) {
GridTab currentTab = toolbar.getCurrentPanel().getGridTab();
if (currentTab.hasChangedCurrentTabAndParents()) {
String msg = CLogger.retrieveErrorString("Please ReQuery Window");
FDialog.error(curWindowNo, parent, null, msg);
return;
}
logger.info(wButton.toString());
boolean startWOasking = false;
String col = wButton.getColumnName();
// Zoom
if (col.equals("Record_ID")) {
int AD_Table_ID = Env.getContextAsInt(ctx, curWindowNo, "AD_Table_ID");
int Record_ID = Env.getContextAsInt(ctx, curWindowNo, "Record_ID");
AEnv.zoom(AD_Table_ID, Record_ID);
return;
}
if (currentTab.needSave(true, false)) {
if (!onSave(false))
return;
}
int table_ID = currentTab.getAD_Table_ID();
// Record_ID
int record_ID = currentTab.getRecord_ID();
if (record_ID == -1 && currentTab.getKeyColumnName().equals("AD_Language"))
record_ID = Env.getContextAsInt(ctx, curWindowNo, "AD_Language_ID");
if (record_ID == -1 && (wButton.getProcess_ID() == 306 || wButton.getProcess_ID() == 307)) {
Integer id = (Integer) currentTab.getValue("AD_ChangeLog_ID");
record_ID = id.intValue();
}
if (record_ID == -1 && currentTab.getKeyColumnName().endsWith("_ID")) {
FDialog.error(curWindowNo, parent, "SaveErrorRowNotFound");
return;
}
boolean isProcessMandatory = false;
if (col.equals("PaymentRule")) {
WPayment vp = new WPayment(curWindowNo, currentTab, wButton);
if (// may not be allowed
vp.isInitOK()) {
vp.setVisible(true);
AEnv.showWindow(vp);
}
if (vp.needSave()) {
onSave(false);
onRefresh(false);
}
} else if (col.equals("DocAction")) {
isProcessMandatory = true;
WDocActionPanel win = new WDocActionPanel(currentTab);
if (win.getNumberOfOptions() == 0) {
logger.info("DocAction - No Options");
return;
} else {
AEnv.showWindow(win);
if (!win.isStartProcess())
return;
//batch = win.isBatch();
startWOasking = true;
//vda.dispose();
}
} else if (col.equals("CreateFrom")) {
ICreateFrom cf = WCreateFromFactory.create(currentTab);
if (cf != null) {
if (cf.isInitOK()) {
cf.showWindow();
currentTab.dataRefresh();
}
return;
}
// else may start process
} else if (col.equals("Posted") && MRole.getDefault().isShowAcct()) {
// Check Doc Status
String processed = Env.getContext(ctx, curWindowNo, "Processed");
if (!processed.equals("Y")) {
String docStatus = Env.getContext(ctx, curWindowNo, "DocStatus");
if (DocAction.STATUS_Completed.equals(docStatus) || DocAction.STATUS_Closed.equals(docStatus) || DocAction.STATUS_Reversed.equals(docStatus) || DocAction.STATUS_Voided.equals(docStatus))
;
else {
FDialog.error(curWindowNo, parent, "PostDocNotComplete");
return;
}
}
// try to get table and record id from context data (eg for unposted view)
// otherwise use current table/record
int tableId = Env.getContextAsInt(ctx, curWindowNo, "AD_Table_ID", true);
int recordId = Env.getContextAsInt(ctx, curWindowNo, "Record_ID", true);
if (tableId == 0 || recordId == 0) {
tableId = currentTab.getAD_Table_ID();
recordId = currentTab.getRecord_ID();
}
// Check Post Status
Object ps = currentTab.getValue("Posted");
if (ps != null && ps.equals("Y")) {
new org.adempiere.webui.acct.WAcctViewer(Env.getContextAsInt(ctx, curWindowNo, "AD_Client_ID"), tableId, recordId);
} else {
if (FDialog.ask(curWindowNo, null, "PostImmediate?")) {
// force when problems
boolean force = ps != null && !ps.equals("N");
String error = AEnv.postImmediate(curWindowNo, Env.getAD_Client_ID(ctx), tableId, recordId, force);
if (error != null)
FDialog.error(curWindowNo, null, "PostingError-N", error);
onRefresh(false);
}
}
return;
}
// Posted
/**
* Start Process ----
*/
logger.config("Process_ID=" + wButton.getProcess_ID() + ", Record_ID=" + record_ID);
if (wButton.getProcess_ID() == 0) {
if (isProcessMandatory) {
FDialog.error(curWindowNo, null, null, Msg.parseTranslation(ctx, "@NotFound@ @AD_Process_ID@"));
}
return;
}
if (currentTab.needSave(true, false)) {
if (!onSave(false))
return;
}
// call form
MProcess pr = new MProcess(ctx, wButton.getProcess_ID(), null);
// Validate Access
// BR [ 147 ]
MRole role = MRole.getDefault(ctx, false);
Boolean accessRW = role.checkProcessAccess(pr.getAD_Process_ID());
if (accessRW == null || !accessRW.booleanValue()) {
FDialog.error(curWindowNo, parent, "AccessCannotProcess");
return;
}
int adFormID = pr.getAD_Form_ID();
// Yamel Senih BR[ 127 ], 2015-11-25
// Bug with launch form
int adBrowseID = pr.getAD_Browse_ID();
if (adFormID != 0) {
String title = wButton.getDescription();
if (title == null || title.length() == 0)
title = wButton.getDisplay();
ProcessInfo pi = new ProcessInfo(title, wButton.getProcess_ID(), table_ID, record_ID);
pi.setWindowNo(curWindowNo);
pi.setAD_User_ID(Env.getAD_User_ID(ctx));
pi.setAD_Client_ID(Env.getAD_Client_ID(ctx));
ADForm form = ADForm.openForm(adFormID);
form.setProcessInfo(pi);
// Yamel Senih FR [ 114 ], 2015-11-25
form.setAttribute(Window.MODE_KEY, Window.MODE_MODAL);
form.setAttribute(Window.INSERT_POSITION_KEY, Window.INSERT_NEXT);
form.setClosable(true);
form.setMaximizable(true);
form.setSizable(true);
form.setContentStyle("overflow: auto");
AEnv.showWindow(form);
// End Yamel Senih
currentTab.dataRefreshAll();
} else if (adBrowseID != 0) {
String title = wButton.getDescription();
if (title == null || title.length() == 0)
title = wButton.getDisplay();
ProcessInfo pi = new ProcessInfo(title, wButton.getProcess_ID(), table_ID, record_ID);
pi.setAD_User_ID(Env.getAD_User_ID(ctx));
pi.setAD_Client_ID(Env.getAD_Client_ID(ctx));
MBrowse browse = new MBrowse(Env.getCtx(), adBrowseID, null);
WBrowser browser = new WBrowser(true, curWindowNo, "", browse, "", true, "", "Y".equals(Env.isSOTrx(Env.getCtx(), curWindowNo)));
browser.setProcessInfo(pi);
CustomForm ff = browser.getForm();
ff.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED);
ff.setAttribute(Window.INSERT_POSITION_KEY, Window.INSERT_NEXT);
ff.setTitle(title);
SessionManager.getAppDesktop().showWindow(ff);
onRefresh(false);
} else {
ProcessModalDialog dialog = new ProcessModalDialog(this, curWindowNo, wButton.getProcess_ID(), table_ID, record_ID, startWOasking);
if (dialog.isValid()) {
dialog.setWidth("500px");
dialog.setVisible(true);
dialog.setPosition("center");
AEnv.showWindow(dialog);
}
//onRefresh(true); // Need to fire events to activate subordinate tabs.
}
}
use of org.compiere.process.ProcessInfo in project adempiere by adempiere.
the class MProduction method recalculate.
/**
* Recalculate quantity will be produced
* @return
*/
private String recalculate() {
MProduct product = MProduct.get(getCtx(), getM_Product_ID());
MAcctSchema as = MClient.get(getCtx()).getAcctSchema();
MCostType ct = MCostType.getByMethodCosting(as, as.getCostingMethod());
String costingLevel = product.getCostingLevel(as);
if (!as.getM_CostType().getCostingMethod().equals(MCostType.COSTINGMETHOD_StandardCosting))
return "";
int AD_Org_ID = costingLevel.equals(MAcctSchema.COSTINGLEVEL_Organization) ? getAD_Org_ID() : 0;
int M_Warehouse_ID = costingLevel.equals(MAcctSchema.COSTINGLEVEL_Warehouse) ? getM_Locator().getM_Warehouse_ID() : 0;
ProcessInfo processInfo = ProcessBuilder.create(getCtx()).process(53062).withRecordId(MProduction.Table_ID, getM_Product_ID()).withParameter("C_AcctSchema_ID", as.getC_AcctSchema_ID()).withParameter("S_Resource_ID", as.getC_AcctSchema_ID()).withParameter("", as.getCostingMethod()).withParameter("M_CostType_ID", ct.getM_CostType_ID()).withParameter("ADOrg_ID", AD_Org_ID).withParameter("M_Warehouse_ID", M_Warehouse_ID).withParameter("CostingMethod", as.getCostingMethod()).withoutTransactionClose().execute(get_TrxName());
if (processInfo.isError())
throw new AdempiereException(processInfo.getSummary());
// Log
log.info(processInfo.getSummary());
return "";
}
use of org.compiere.process.ProcessInfo in project adempiere by adempiere.
the class MProcess method processIt.
/**************************************************************************
* Process w/o parameter
* @param Record_ID record
* @param trx transaction
* @return Process Instance
*/
public MPInstance processIt(int Record_ID, Trx trx, boolean managedTrx) {
MPInstance pInstance = new MPInstance(this, Record_ID);
// Lock
pInstance.setIsProcessing(true);
pInstance.saveEx();
boolean ok = true;
ProcessInfo processInfo = new ProcessInfo("", this.getAD_Process_ID());
processInfo.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
//@Trifon - pass Record_Id to ProcessInfo class
processInfo.setRecord_ID(Record_ID);
ok = processIt(processInfo, trx, managedTrx);
// Unlock
pInstance.setResult(ok ? MPInstance.RESULT_OK : MPInstance.RESULT_ERROR);
pInstance.setErrorMsg(processInfo.getSummary());
pInstance.setIsProcessing(false);
pInstance.saveEx();
//
pInstance.log();
return pInstance;
}
use of org.compiere.process.ProcessInfo in project adempiere by adempiere.
the class EnableNativeSequence method main.
/**
* Main test
* @param args
* @throws Exception
*/
public static void main(String[] args) {
Adempiere.startupEnvironment(true);
CLogMgt.setLevel(Level.INFO);
Properties ctx = Env.getCtx();
// HARDCODED
int AD_Process_ID = 53156;
MPInstance pinstance = new MPInstance(ctx, AD_Process_ID, -1);
pinstance.saveEx();
ProcessInfo pi = new ProcessInfo("", AD_Process_ID, 0, 0);
pi.setAD_Client_ID(Env.getAD_Client_ID(ctx));
pi.setAD_User_ID(Env.getAD_User_ID(ctx));
pi.setAD_PInstance_ID(pinstance.getAD_PInstance_ID());
//
EnableNativeSequence proc = new EnableNativeSequence();
proc.startProcess(ctx, pi, null);
if (pi.isError()) {
throw new AdempiereException(pi.getSummary());
}
}
use of org.compiere.process.ProcessInfo in project adempiere by adempiere.
the class InOutGen method generate.
// saveSelection
/**************************************************************************
* Generate Shipments
*/
public String generate(IStatusBar statusBar, KeyNamePair docTypeKNPair, String docActionSelected) {
String info = "";
log.info("M_Warehouse_ID=" + m_M_Warehouse_ID);
String trxName = Trx.createTrxName("IOG");
//trx needs to be committed too
Trx trx = Trx.get(trxName, true);
// prevents from being called twice
setSelectionActive(false);
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateGen"));
statusBar.setStatusDB(String.valueOf(getSelection().size()));
// Prepare Process
int AD_Process_ID = 0;
if (docTypeKNPair.getKey() == MRMA.Table_ID) {
// M_InOut_GenerateRMA - org.adempiere.process.InOutGenerateRMA
AD_Process_ID = 52001;
} else {
// M_InOut_Generate - org.compiere.process.InOutGenerate
AD_Process_ID = 199;
}
MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
if (!instance.save()) {
info = Msg.getMsg(Env.getCtx(), "ProcessNoInstance");
return info;
}
//insert selection
StringBuffer insert = new StringBuffer();
insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
int counter = 0;
for (Integer selectedId : getSelection()) {
counter++;
if (counter > 1)
insert.append(" UNION ");
insert.append("SELECT ");
insert.append(instance.getAD_PInstance_ID());
insert.append(", ");
insert.append(selectedId);
insert.append(" FROM DUAL ");
if (counter == 1000) {
if (DB.executeUpdate(insert.toString(), trxName) < 0) {
// not translated!
String msg = "No Shipments";
log.config(msg);
info = msg;
trx.rollback();
return info;
}
insert = new StringBuffer();
insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
counter = 0;
}
}
if (counter > 0) {
if (DB.executeUpdate(insert.toString(), trxName) < 0) {
// not translated!
String msg = "No Shipments";
log.config(msg);
info = msg;
trx.rollback();
return info;
}
}
//call process
ProcessInfo pi = new ProcessInfo("VInOutGen", AD_Process_ID);
pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
// Add Parameter - Selection=Y
MPInstancePara ip = new MPInstancePara(instance, 10);
ip.setParameter("Selection", "Y");
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
info = msg;
log.log(Level.SEVERE, msg);
return info;
}
//Add Document action parameter
ip = new MPInstancePara(instance, 20);
// String docActionSelected = (String)docAction.getValue();
ip.setParameter("DocAction", docActionSelected);
if (!ip.save()) {
String msg = "No DocACtion Parameter added";
info = msg;
log.log(Level.SEVERE, msg);
return info;
}
// Add Parameter - M_Warehouse_ID=x
ip = new MPInstancePara(instance, 30);
ip.setParameter("M_Warehouse_ID", Integer.parseInt(m_M_Warehouse_ID.toString()));
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
info = msg;
log.log(Level.SEVERE, msg);
return info;
}
setTrx(trx);
setProcessInfo(pi);
return info;
}
Aggregations