Search in sources :

Example 11 with MProcess

use of org.compiere.model.MProcess in project adempiere by adempiere.

the class APanel method actionButton.

/**************************************************************************
	 *	Start Button Process
	 *  @param vButton button
	 */
protected void actionButton(VButton vButton) {
    log.info(vButton.toString());
    if (m_curTab.hasChangedCurrentTabAndParents()) {
        String msg = CLogger.retrieveErrorString("Please ReQuery Window");
        ADialog.error(m_curWindowNo, this, null, msg);
        return;
    }
    boolean startWOasking = false;
    //		boolean batch = false;
    String col = vButton.getColumnName();
    //  Zoom
    if (col.equals("Record_ID")) {
        int AD_Table_ID = Env.getContextAsInt(m_ctx, m_curWindowNo, "AD_Table_ID");
        int Record_ID = Env.getContextAsInt(m_ctx, m_curWindowNo, "Record_ID");
        AEnv.zoom(AD_Table_ID, Record_ID);
        return;
    }
    //  save first	---------------
    if (m_curTab.needSave(true, false))
        if (!cmd_save(true))
            return;
    // Save included tabs if necessary - teo_sarca BF [ 2876892 ]
    for (GridTab includedTab : m_curTab.getIncludedTabs()) {
        if (includedTab.needSave(true, false))
            if (!includedTab.dataSave(true))
                return;
    }
    //
    int table_ID = m_curTab.getAD_Table_ID();
    //	Record_ID
    int record_ID = m_curTab.getRecord_ID();
    //	Record_ID - Language Handling
    if (record_ID == -1 && m_curTab.getKeyColumnName().equals("AD_Language"))
        record_ID = Env.getContextAsInt(m_ctx, m_curWindowNo, "AD_Language_ID");
    //	Record_ID - Change Log ID
    if (record_ID == -1 && (vButton.getProcess_ID() == 306 || vButton.getProcess_ID() == 307)) {
        Integer id = (Integer) m_curTab.getValue("AD_ChangeLog_ID");
        record_ID = id.intValue();
    }
    //	Ensure it's saved
    if (record_ID == -1 && m_curTab.getKeyColumnName().endsWith("_ID")) {
        ADialog.error(m_curWindowNo, this, "SaveErrorRowNotFound");
        return;
    }
    boolean isProcessMandatory = false;
    //	Pop up Payment Rules
    if (col.equals("PaymentRule")) {
        VPayment vp = new VPayment(m_curWindowNo, m_curTab, vButton);
        if (//	may not be allowed
        vp.isInitOK())
            vp.setVisible(true);
        vp.dispose();
        if (vp.needSave()) {
            cmd_save(false);
            cmd_refresh();
        }
    } else //	Pop up Document Action (Workflow)
    if (col.equals("DocAction")) {
        isProcessMandatory = true;
        VDocAction vda = new VDocAction(m_curWindowNo, m_curTab, vButton, record_ID);
        //	Something to select from?
        if (vda.getNumberOfOptions() == 0) {
            vda.dispose();
            log.info("DocAction - No Options");
            return;
        } else {
            vda.setVisible(true);
            if (!vda.isStartProcess())
                return;
            //				batch = vda.isBatch();
            startWOasking = true;
            vda.dispose();
        }
    } else //  Pop up Create From
    if (col.equals("CreateFrom")) {
        // Run form only if the button has no process defined - teo_sarca [ 1974354 ]
        if (vButton.getProcess_ID() <= 0) {
            ICreateFrom cf = VCreateFromFactory.create(m_curTab);
            if (cf != null) {
                if (cf.isInitOK()) {
                    cf.showWindow();
                    cf.closeWindow();
                    m_curTab.dataRefresh();
                } else
                    cf.closeWindow();
                return;
            }
        //	else may start process
        }
    } else //  Posting -----
    if (col.equals("Posted") && MRole.getDefault().isShowAcct()) {
        //  Check Doc Status
        String processed = Env.getContext(m_ctx, m_curWindowNo, "Processed");
        if (!processed.equals("Y")) {
            String docStatus = Env.getContext(m_ctx, m_curWindowNo, "DocStatus");
            if (DocAction.STATUS_Completed.equals(docStatus) || DocAction.STATUS_Closed.equals(docStatus) || DocAction.STATUS_Reversed.equals(docStatus) || DocAction.STATUS_Voided.equals(docStatus))
                ;
            else {
                ADialog.error(m_curWindowNo, this, "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(m_ctx, m_curWindowNo, "AD_Table_ID", true);
        int recordId = Env.getContextAsInt(m_ctx, m_curWindowNo, "Record_ID", true);
        if (tableId == 0 || recordId == 0) {
            tableId = m_curTab.getAD_Table_ID();
            recordId = m_curTab.getRecord_ID();
        }
        //  Check Post Status
        Object ps = m_curTab.getValue("Posted");
        if (ps != null && ps.equals("Y")) {
            new org.compiere.acct.AcctViewer(Env.getContextAsInt(m_ctx, m_curWindowNo, "AD_Client_ID"), tableId, recordId);
        } else {
            if (ADialog.ask(m_curWindowNo, this, "PostImmediate?")) {
                //	force when problems
                boolean force = ps != null && !ps.equals("N");
                String error = AEnv.postImmediate(m_curWindowNo, Env.getAD_Client_ID(m_ctx), tableId, recordId, force);
                if (error != null)
                    ADialog.error(m_curWindowNo, this, "PostingError-N", error);
                cmd_refresh();
            }
        }
        return;
    }
    //  Posted
    /**
		 *  Start Process ----
		 *  or invoke user form
		 */
    log.config("Process_ID=" + vButton.getProcess_ID() + ", Record_ID=" + record_ID);
    if (vButton.getProcess_ID() == 0) {
        if (isProcessMandatory) {
            ADialog.error(m_curWindowNo, this, null, Msg.parseTranslation(m_ctx, "@NotFound@ @AD_Process_ID@"));
        }
        return;
    }
    //	Save item changed
    if (m_curTab.needSave(true, false))
        if (!cmd_save(true))
            return;
    // call form
    MProcess pr = new MProcess(m_ctx, vButton.getProcess_ID(), null);
    //	Validate Access
    MRole role = MRole.getDefault(m_ctx, false);
    Boolean accessRW = role.checkProcessAccess(pr.getAD_Process_ID());
    if (accessRW == null || !accessRW.booleanValue()) {
        ADialog.error(m_curWindowNo, this, null, Msg.parseTranslation(m_ctx, "@AccessCannotProcess@"));
        return;
    }
    //	
    int form_ID = pr.getAD_Form_ID();
    if (form_ID != 0) {
        if (m_curTab.needSave(true, false))
            if (!cmd_save(true))
                return;
        //	Yamel Senih FR [ 114 ] 2015-11-23 Add Support to Dialog for create from
        FormFrame ff = new FormFrame(getWindowNo());
        String title = vButton.getDescription();
        if (title == null || title.length() == 0)
            title = vButton.getName();
        ProcessInfo pi = new ProcessInfo(title, vButton.getProcess_ID(), table_ID, record_ID);
        pi.setAD_User_ID(Env.getAD_User_ID(m_ctx));
        pi.setAD_Client_ID(Env.getAD_Client_ID(m_ctx));
        ff.setProcessInfo(pi);
        ff.openForm(form_ID);
        ff.pack();
        AEnv.showCenterScreen(ff);
        //	Refresh
        m_curTab.dataRefresh();
        //	End Yamel Senih
        return;
    }
    int browse_ID = pr.getAD_Browse_ID();
    if (browse_ID != 0) {
        if (m_curTab.needSave(true, false))
            if (!cmd_save(true))
                return;
        String title = vButton.getDescription();
        if (title == null || title.length() == 0)
            title = vButton.getName();
        ProcessInfo pi = new ProcessInfo(title, vButton.getProcess_ID(), table_ID, record_ID);
        pi.setAD_User_ID(Env.getAD_User_ID(m_ctx));
        pi.setAD_Client_ID(Env.getAD_Client_ID(m_ctx));
        FormFrame ff = new FormFrame(getWindowNo());
        ff.setProcessInfo(pi);
        MBrowse browse = new MBrowse(Env.getCtx(), browse_ID, null);
        new VBrowser(ff, true, getWindowNo(), "", browse, "", true, "", Env.isSOTrx(Env.getCtx(), m_curWindowNo));
        ff.pack();
        AEnv.showCenterScreen(ff);
        //	Yamel Senih
        //	Refresh
        m_curTab.dataRefresh();
        return;
    } else {
        ProcessModalDialog dialog = new ProcessModalDialog(m_ctx, Env.getWindow(m_curWindowNo), Env.getHeader(m_ctx, m_curWindowNo), this, m_curWindowNo, vButton.getProcess_ID(), table_ID, record_ID, startWOasking);
        //	BR [ 323 ]
        if (!startWOasking) {
            dialog.validate();
            dialog.pack();
            AEnv.showCenterWindow(Env.getWindow(m_curWindowNo), dialog);
        }
    }
}
Also used : VDocAction(org.compiere.grid.ed.VDocAction) MProcess(org.compiere.model.MProcess) FormFrame(org.compiere.apps.form.FormFrame) MRole(org.compiere.model.MRole) VPayment(org.compiere.grid.VPayment) ProcessInfo(org.compiere.process.ProcessInfo) MBrowse(org.adempiere.model.MBrowse) Point(java.awt.Point) VBrowser(org.eevolution.form.VBrowser) ICreateFrom(org.compiere.grid.ICreateFrom) GridTab(org.compiere.model.GridTab)

Example 12 with MProcess

use of org.compiere.model.MProcess in project adempiere by adempiere.

the class ProcessAbstractClassGenerator method getParameters.

private MProcessPara[] getParameters() {
    if (parameters != null && parameters.length > 0)
        return parameters;
    MProcess process = new MProcess(Env.getCtx(), processId, null);
    parameters = process.getParameters();
    return parameters;
}
Also used : MProcess(org.compiere.model.MProcess)

Example 13 with MProcess

use of org.compiere.model.MProcess in project adempiere by adempiere.

the class ASPGenerateLevel method generateProcess.

private void generateProcess(int p_AD_Process_ID) {
    // Add Process and Parameters
    MProcess process = new MProcess(getCtx(), p_AD_Process_ID, get_TrxName());
    int asp_process_id = DB.getSQLValueEx(get_TrxName(), "SELECT ASP_Process_ID FROM ASP_Process WHERE ASP_Level_ID = ? AND AD_Process_ID = ?", p_ASP_Level_ID, process.getAD_Process_ID());
    X_ASP_Process aspProcess = null;
    if (asp_process_id < 1) {
        aspProcess = new X_ASP_Process(getCtx(), 0, get_TrxName());
        aspProcess.setASP_Level_ID(p_ASP_Level_ID);
        aspProcess.setAD_Process_ID(process.getAD_Process_ID());
        aspProcess.setASP_Status(p_ASP_Status);
        if (aspProcess.save()) {
            noProcesses++;
            asp_process_id = aspProcess.getASP_Process_ID();
        }
    } else {
        aspProcess = new X_ASP_Process(getCtx(), asp_process_id, get_TrxName());
    }
    // parameters
    for (MProcessPara processpara : process.getParameters()) {
        if (DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM ASP_Process_Para WHERE ASP_Process_ID = ? AND AD_Process_Para_ID = ?", asp_process_id, processpara.getAD_Process_Para_ID()) < 1) {
            X_ASP_Process_Para aspProcess_Para = new X_ASP_Process_Para(getCtx(), 0, get_TrxName());
            aspProcess_Para.setASP_Process_ID(asp_process_id);
            aspProcess_Para.setAD_Process_Para_ID(processpara.getAD_Process_Para_ID());
            aspProcess_Para.setASP_Status(p_ASP_Status);
            if (aspProcess_Para.save())
                noParameters++;
        }
    }
    if (process.getAD_Workflow_ID() > 0) {
        generateWorkflow(process.getAD_Workflow_ID());
    }
}
Also used : MProcess(org.compiere.model.MProcess) X_ASP_Process(org.compiere.model.X_ASP_Process) MProcessPara(org.compiere.model.MProcessPara) X_ASP_Process_Para(org.compiere.model.X_ASP_Process_Para)

Example 14 with MProcess

use of org.compiere.model.MProcess 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;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MDocType(org.compiere.model.MDocType) MPInstance(org.compiere.model.MPInstance) MProcess(org.compiere.model.MProcess) Trx(org.compiere.util.Trx) ProcessInfo(org.compiere.process.ProcessInfo)

Example 15 with MProcess

use of org.compiere.model.MProcess 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;
}
Also used : MProcess(org.compiere.model.MProcess) ArrayList(java.util.ArrayList) ProcessInfo(org.compiere.process.ProcessInfo) ProcessInfoParameter(org.compiere.process.ProcessInfoParameter) MPInstance(org.compiere.model.MPInstance) CallableStatement(java.sql.CallableStatement) Trx(org.compiere.util.Trx)

Aggregations

MProcess (org.compiere.model.MProcess)25 ProcessInfo (org.compiere.process.ProcessInfo)9 MProcessPara (org.compiere.model.MProcessPara)8 MPInstance (org.compiere.model.MPInstance)7 File (java.io.File)6 Timestamp (java.sql.Timestamp)6 SQLException (java.sql.SQLException)5 Trx (org.compiere.util.Trx)5 IOException (java.io.IOException)4 org.apache.ecs.xhtml.i (org.apache.ecs.xhtml.i)4 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)4 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)4 org.apache.ecs.xhtml.td (org.apache.ecs.xhtml.td)4 ReportEngine (org.compiere.print.ReportEngine)4 JasperPrint (net.sf.jasperreports.engine.JasperPrint)3 org.apache.ecs.xhtml.div (org.apache.ecs.xhtml.div)3 org.apache.ecs.xhtml.fieldset (org.apache.ecs.xhtml.fieldset)3 org.apache.ecs.xhtml.form (org.apache.ecs.xhtml.form)3 org.apache.ecs.xhtml.tr (org.apache.ecs.xhtml.tr)3 MPInstancePara (org.compiere.model.MPInstancePara)3