use of org.compiere.process.ProcessInfo in project adempiere by adempiere.
the class WPOSActionMenu method executeCommand.
private void executeCommand(Command command) {
BusyDialog waiting = new BusyDialog();
try {
CommandReceiver receiver = commandManager.getCommandReceivers(command.getEvent());
if (command.getCommand() == CommandManager.GENERATE_IMMEDIATE_INVOICE && pos.getC_Order_ID() > 0 && pos.isCompleted() && !pos.isVoided()) {
receiver.setCtx(pos.getCtx());
receiver.setPartnerId(queryPartner.getRecord_ID());
receiver.setOrderId(pos.getC_Order_ID());
receiver.setPOSId(pos.getC_POS_ID());
receiver.setBankAccountId(pos.getC_BankAccount_ID());
MBPartner partner = MBPartner.get(pos.getCtx(), receiver.getPartnerId());
Optional<String> taxId = Optional.ofNullable(partner.getTaxID());
String processMessage = receiver.getName() + " @DisplayDocumentInfo@ : " + pos.getDocumentNo() + " @To@ @C_BPartner_ID@ : " + partner.getName() + " @TaxID@ : " + taxId.orElse("");
if (FDialog.ask(pos.getWindowNo(), popupMenu, "StartProcess?", Msg.parseTranslation(pos.getCtx(), processMessage))) {
waiting.setPage(pos.v_Panel.getPage());
waiting.doHighlighted();
command.execute(receiver);
ProcessInfo processInfo = receiver.getProcessInfo();
waiting.dispose();
if (processInfo != null && processInfo.isError()) {
showError(processInfo);
} else {
afterExecutionCommand(command);
showOkMessage(processInfo);
if (processInfo != null)
pos.setOrder(processInfo.getRecord_ID());
pos.refreshHeader();
// Print Ticket
pos.printTicket();
}
}
} else //Reverse The Sales Transaction
if (command.getCommand() == CommandManager.GENERATE_REVERSE_SALES && pos.getC_Order_ID() > 0 && !pos.isReturnMaterial() && !pos.isVoided() && !pos.isClosed()) {
receiver.setCtx(pos.getCtx());
receiver.setOrderId(pos.getC_Order_ID());
receiver.setPOSId(pos.getC_POS_ID());
receiver.setPartnerId(pos.getC_BPartner_ID());
receiver.setBankAccountId(pos.getC_BankAccount_ID());
String processMessage = receiver.getName() + " @order.no@ : " + pos.getDocumentNo() + " @To@ @C_BPartner_ID@ : " + pos.getBPName();
if (FDialog.ask(pos.getWindowNo(), popupMenu, "StartProcess?", Msg.parseTranslation(pos.getCtx(), processMessage))) {
waiting.setPage(pos.v_Panel.getPage());
waiting.doHighlighted();
command.execute(receiver);
ProcessInfo processInfo = receiver.getProcessInfo();
waiting.dispose();
if (processInfo != null && processInfo.isError()) {
showError(processInfo);
} else {
afterExecutionCommand(command);
showOkMessage(processInfo);
}
pos.printTicket();
}
} else //Return product
if (command.getCommand() == CommandManager.GENERATE_RETURN && pos.getC_Order_ID() > 0 && !pos.isReturnMaterial() && pos.isCompleted()) {
receiver.setCtx(pos.getCtx());
receiver.setOrderId(pos.getC_Order_ID());
receiver.setPOSId(pos.getC_POS_ID());
receiver.setPartnerId(pos.getC_BPartner_ID());
receiver.setBankAccountId(pos.getC_BankAccount_ID());
String processMessage = receiver.getName() + " @DisplayDocumentInfo@ : " + pos.getDocumentNo() + " @To@ @C_BPartner_ID@ : " + pos.getBPName();
if (FDialog.ask(pos.getWindowNo(), popupMenu, "StartProcess?", Msg.parseTranslation(pos.getCtx(), processMessage))) {
waiting.setPage(pos.v_Panel.getPage());
waiting.doHighlighted();
command.execute(receiver);
ProcessInfo processInfo = receiver.getProcessInfo();
waiting.dispose();
if (processInfo != null && processInfo.isError()) {
showError(processInfo);
} else {
afterExecutionCommand(command);
showOkMessage(processInfo);
//execute out transaction
if (processInfo != null && processInfo.getRecord_ID() > 0) {
pos.setOrder(processInfo.getRecord_ID());
pos.refreshHeader();
}
}
}
} else if (command.getCommand() == CommandManager.GENERATE_WITHDRAWAL) {
Env.setContext(pos.getCtx(), pos.getWindowNo(), "C_POS_ID", pos.getC_POS_ID());
MBrowse browse = new MBrowse(Env.getCtx(), 50056, null);
WBrowser browser = new WBrowser(true, pos.getWindowNo(), "", browse, "", true, "", true);
CustomForm ff = browser.getForm();
ff.setAttribute(org.adempiere.webui.component.Window.MODE_KEY, org.adempiere.webui.component.Window.MODE_EMBEDDED);
ff.setAttribute(org.adempiere.webui.component.Window.INSERT_POSITION_KEY, org.adempiere.webui.component.Window.INSERT_NEXT);
ff.setTitle(browse.getTitle());
SessionManager.getAppDesktop().showWindow(ff);
} else if (command.getCommand() == CommandManager.CLOSE_STATEMENT) {
Env.setContext(pos.getCtx(), pos.getWindowNo(), "C_POS_ID", pos.getC_POS_ID());
MBrowse browse = new MBrowse(Env.getCtx(), 50057, null);
WBrowser browser = new WBrowser(true, pos.getWindowNo(), "", browse, "", true, "", true);
CustomForm ff = browser.getForm();
ff.setAttribute(org.adempiere.webui.component.Window.MODE_KEY, org.adempiere.webui.component.Window.MODE_EMBEDDED);
ff.setAttribute(org.adempiere.webui.component.Window.INSERT_POSITION_KEY, org.adempiere.webui.component.Window.INSERT_NEXT);
ff.setTitle(browse.getTitle());
SessionManager.getAppDesktop().showWindow(ff);
}
} catch (Exception exception) {
waiting.dispose();
FDialog.error(pos.getWindowNo(), pos.getForm(), exception.getLocalizedMessage());
} finally {
waiting.dispose();
waiting = null;
}
}
use of org.compiere.process.ProcessInfo in project adempiere by adempiere.
the class DistributionRunOrders method executeDistribution.
/**
* Execute Distribution Run
* @return
* @throws Exception
*/
public boolean executeDistribution() throws Exception {
int M_DocType_ID = 0;
MDocType[] doc = MDocType.getOfDocBaseType(getCtx(), MDocType.DOCBASETYPE_DistributionOrder);
if (doc == null || doc.length == 0) {
log.severe("Not found default document type for docbasetype " + MDocType.DOCBASETYPE_DistributionOrder);
throw new Exception(Msg.getMsg(getCtx(), "SequenceDocNotFound"), CLogger.retrieveException());
} else
M_DocType_ID = doc[0].getC_DocType_ID();
String trxName = Trx.createTrxName("Run Distribution to DRP");
//trx needs to be committed too
Trx trx = Trx.get(trxName, true);
//Prepare Process
int AD_Process_ID = 271;
AD_Process_ID = MProcess.getProcess_ID("M_DistributionRun Create", get_TrxName());
MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
if (!instance.save()) {
throw new Exception(Msg.getMsg(getCtx(), "ProcessNoInstance"), CLogger.retrieveException());
}
//call process
ProcessInfo pi = new ProcessInfo("M_DistributionRun Orders", AD_Process_ID);
pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
pi.setRecord_ID(m_run.getM_DistributionRun_ID());
// Add Parameter - Selection=Y
MPInstancePara ip = new MPInstancePara(instance, 10);
ip.setParameter("C_DocType_ID", M_DocType_ID);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
// Add Parameter - DatePromised
ip = new MPInstancePara(instance, 20);
ip.setParameter("DatePromised", "");
ip.setP_Date(p_DatePromised);
//ip.setP_Date_To(p_DatePromised_To);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
// Add Parameter - M_Warehouse_ID
ip = new MPInstancePara(instance, 30);
ip.setParameter("M_Warehouse_ID", p_M_Warehouse_ID);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
// Add Parameter - CreateDO
ip = new MPInstancePara(instance, 40);
ip.setParameter("ConsolidateDocument", p_ConsolidateDocument);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
// Add Parameter - IsTest=Y
ip = new MPInstancePara(instance, 50);
ip.setParameter("IsTest", p_IsTest);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
//Distribution List
ip = new MPInstancePara(instance, 60);
ip.setParameter("M_DistributionList_ID", p_M_DistributionList_ID);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
//Based in DRP Demand
ip = new MPInstancePara(instance, 70);
ip.setParameter("IsRequiredDRP", p_BasedInDamnd);
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
throw new Exception(msg, CLogger.retrieveException());
}
// Execute Process
MProcess worker = new MProcess(getCtx(), AD_Process_ID, get_TrxName());
worker.processIt(pi, Trx.get(get_TrxName(), true));
m_run.delete(true);
return true;
}
use of org.compiere.process.ProcessInfo in project adempiere by adempiere.
the class ServerReportCtl method runJasperProcess.
// StartDocumentPrint
/**
* Runs a Jasper process that prints the record
*
* @param recordId
* @param reportEngine
* @param isDirectPrint
* @param printerName
* @param processInfo
* @return
*/
public static boolean runJasperProcess(int recordId, ReportEngine reportEngine, boolean isDirectPrint, String printerName, ProcessInfo processInfo) {
Trx trx;
if (processInfo != null)
trx = Trx.get(processInfo.getTransactionName(), false);
else
trx = null;
MPrintFormat format = reportEngine.getPrintFormat();
ProcessInfo jasperProcessInfo = new ProcessInfo("", format.getJasperProcess_ID());
jasperProcessInfo.setPrintPreview(!isDirectPrint);
MQuery query = reportEngine.getQuery();
if (query != null)
recordId = (Integer) query.getCode(0);
jasperProcessInfo.setRecord_ID(recordId);
Vector<ProcessInfoParameter> jasperPrintParams = new Vector<ProcessInfoParameter>();
ProcessInfoParameter pip;
if (printerName != null && printerName.trim().length() > 0) {
// Override printer name
pip = new ProcessInfoParameter(PARAM_PRINTER_NAME, printerName, null, null, null);
jasperPrintParams.add(pip);
}
pip = new ProcessInfoParameter(PARAM_PRINT_FORMAT, format, null, null, null);
jasperPrintParams.add(pip);
pip = new ProcessInfoParameter(PARAM_PRINT_INFO, reportEngine.getPrintInfo(), null, null, null);
jasperPrintParams.add(pip);
jasperProcessInfo.setParameter(jasperPrintParams.toArray(new ProcessInfoParameter[] {}));
// Parent set to null for synchronous processing, see bugtracker 3010932
ServerProcessCtl.process(// Parent set to null for synchronous processing, see bugtracker 3010932
null, jasperProcessInfo, trx);
if (processInfo != null)
processInfo.setPDFReport(jasperProcessInfo.getPDFReport());
boolean result = true;
return (result);
}
use of org.compiere.process.ProcessInfo in project adempiere by adempiere.
the class FinReportJasper method doIt.
/**************************************************************************
* Perform process.
* @return Message to be translated
* @throws Exception
*/
protected String doIt() throws Exception {
// Call the normal FinReport to fill the T_Report table
String finReportMsg = super.doIt();
// Now invoke the associated jasper report (must report on the T_Report table)
ArrayList<ProcessInfoParameter> list = new ArrayList<ProcessInfoParameter>();
// Copy the list of parameters from the financial report
ProcessInfoParameter[] oldpara = getParameter();
for (int i = 0; i < oldpara.length; i++) list.add(oldpara[i]);
// and add the T_Report_AD_PInstance_ID parameter
list.add(new ProcessInfoParameter("T_Report_AD_PInstance_ID", new Integer(getAD_PInstance_ID()), null, null, null));
ProcessInfoParameter[] pars = new ProcessInfoParameter[list.size()];
list.toArray(pars);
// Load Report Definition
m_report = new MReport(getCtx(), getRecord_ID(), get_TrxName());
MProcess proc = new MProcess(getCtx(), m_report.getJasperProcess_ID(), get_TrxName());
MPInstance instance = new MPInstance(proc, getRecord_ID());
instance.saveEx();
ProcessInfo poInfo = new ProcessInfo(proc.getName(), proc.getAD_Process_ID());
poInfo.setParameter(pars);
poInfo.setRecord_ID(getRecord_ID());
poInfo.setAD_Process_ID(proc.getAD_Process_ID());
poInfo.setAD_PInstance_ID(instance.getAD_PInstance_ID());
// need to commit in order to allow jasper to view the data
Trx trx = Trx.get(get_TrxName(), true);
trx.commit();
// CarlosRuiz - globalqss - allow procedure preprocess
if (proc.getProcedureName() != null && proc.getProcedureName().length() > 0) {
// execute on this thread/connection
String sql = "{call " + proc.getProcedureName() + "(?)}";
try {
// ro??
CallableStatement cstmt = DB.prepareCall(sql);
cstmt.setInt(1, getAD_PInstance_ID());
cstmt.executeUpdate();
cstmt.close();
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
poInfo.setSummary(Msg.getMsg(Env.getCtx(), "ProcessRunError") + " " + e.getLocalizedMessage());
}
}
// TODO - allow java class preprocess if the classname <> ProcessUtil.JASPER_STARTER_CLASS
ProcessUtil.startJavaProcess(getCtx(), poInfo, trx);
return finReportMsg;
}
use of org.compiere.process.ProcessInfo in project adempiere by adempiere.
the class ProcessBuilder method processCtl.
/**
* Create instancel for process control
* @param className
* @param parent
* @param windowNo
* @param processInfo
* @param trx
* @return
* @throws RuntimeException
*/
private Runnable processCtl(String className, ASyncProcess parent, int windowNo, ProcessInfo processInfo, Trx trx) throws RuntimeException {
Class<?> clazz;
Runnable result = null;
try {
clazz = Class.forName(className);
Constructor<?> constructor = null;
if (windowNo == 0) {
constructor = clazz.getDeclaredConstructor(ASyncProcess.class, ProcessInfo.class, Trx.class);
result = (Runnable) constructor.newInstance(parent, processInfo, trx);
} else {
constructor = clazz.getDeclaredConstructor(ASyncProcess.class, Integer.class, ProcessInfo.class, Trx.class);
result = (Runnable) constructor.newInstance(parent, windowNo, processInfo, trx);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return result;
}
Aggregations