Search in sources :

Example 16 with MProcess

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

the class WProcess method createParameterPage.

//  doPost
//Modified by Rob Klein 4/29/07
/**************************************************************************
	 * 	Create Parameter Page
	 * 	@param wsc web session context
	 *	@param AD_Menu_ID Menu
	 *	@return Page
	 */
private MobileDoc createParameterPage(MobileSessionCtx wsc, int processId, int windowID, int tableID, int recordID, int Type, String columnName, GridTab mTab) {
    MProcess process = null;
    if (Type == 0)
        process = MProcess.getFromMenu(wsc.ctx, processId);
    else
        process = MProcess.get(wsc.ctx, processId);
    //	need to check if Role can access
    if (process == null) {
        MobileDoc doc = MobileDoc.createWindow("Process Not Found");
        return doc;
    }
    //Modified by Rob Klein 4/29/07
    MobileDoc doc = MobileDoc.createWindow(process.getName());
    if (process.isWorkflow()) {
        //Modified by Rob Klein 7/01/07
        if (mTab == null) {
            doc = MobileDoc.createWindow("No Tab found");
            return doc;
        }
        //	Pop up Document Action (Workflow)
        if (columnName.toString().equals("DocAction")) {
            readReference();
            option[] Options = dynInit(windowID, tableID, recordID, columnName, mTab);
            fieldset center = new fieldset();
            WebField wField = new WebField(wsc, columnName, columnName, columnName, //	no display length
            17, 22, 22, false, // 	not r/o, ., not error, not dependent
            false, false, false, false, false, processId, 0, 0, 0, 0, null, null, null, null, null);
            if (process.getDescription() != null)
                center.addElement(new p(new i(process.getDescription())));
            if (process.getHelp() != null)
                center.addElement(new p(process.getHelp(), AlignType.LEFT));
            form myForm = new form("WProcess").setName("process" + process.getAD_Process_ID());
            myForm.setTarget("WProcess");
            myForm.setMethod("GET");
            //myForm.setOnSubmit("this.Submit.disabled=true;return true;");
            myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Process_ID", process.getAD_Process_ID()));
            myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Window_ID", windowID));
            myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Table_ID", tableID));
            myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Record_ID", recordID));
            table myTable = new table("0", "0", "5", "100%", null);
            myTable.setID("WProcessParameter");
            myTable.addElement(new tr().addElement(wField.getLabel(true)).addElement(createSelectField(columnName, Options)));
            // Reset
            String text = "Reset";
            if (wsc.ctx != null)
                text = Msg.getMsg(wsc.ctx, "Reset");
            input restbtn = new input(input.TYPE_RESET, text, "  " + text);
            restbtn.setID(text);
            restbtn.setClass("resetbtn");
            //	Submit
            text = "Submit";
            if (wsc.ctx != null)
                text = Msg.getMsg(wsc.ctx, "Submit");
            input submitbtn = new input(input.TYPE_SUBMIT, text, "  " + text);
            submitbtn.setID(text);
            submitbtn.setClass("submitbtn");
            myTable.addElement(new tr().addElement(new td(null, AlignType.RIGHT, AlignType.MIDDLE, false, restbtn)).addElement(new td(null, AlignType.LEFT, AlignType.MIDDLE, false, submitbtn)).addElement(new td(null, AlignType.RIGHT, AlignType.MIDDLE, false, null)));
            myForm.addElement(myTable);
            center.addElement(myForm);
        }
    //	DocAction
    } else {
        form myForm = new form().setName(process.getName());
        myForm.addAttribute("selected", "true");
        myForm.setClass("panel");
        if (process.getDescription() != null)
            myForm.addElement(new p(new i(process.getDescription())));
        if (process.getHelp() != null)
            myForm.addElement(new p(process.getHelp(), AlignType.LEFT));
        //
        myForm.setMethod("get");
        myForm.setAction(MobileEnv.getBaseDirectory("WProcess?AD_Process_ID=" + process.getAD_Process_ID()));
        myForm.setTarget("_self");
        //myForm.setOnSubmit("this.Submit.disabled=true;return true;");
        myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Process_ID", process.getAD_Process_ID()));
        myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Window_ID", windowID));
        myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Table_ID", tableID));
        myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Record_ID", recordID));
        fieldset fs = new fieldset();
        fs.setID("WProcessParameter");
        MProcessPara[] parameter = process.getParameters();
        for (int i = 0; i < parameter.length; i++) {
            MProcessPara para = parameter[i];
            WebField wField = new WebField(wsc, para.getColumnName(), para.getName(), para.getDescription(), //	no display length
            para.getAD_Reference_ID(), para.getFieldLength(), para.getFieldLength(), false, // 	not r/o, ., not error, not dependent
            false, para.isMandatory(), false, false, false, para.getAD_Process_ID(), 0, 0, 0, i, null, null, null, null, null);
            WebField wFieldforRange = null;
            if (para.isRange())
                wFieldforRange = new WebField(wsc, para.getColumnName(), para.getName(), para.getDescription(), //	no display length
                para.getAD_Reference_ID(), para.getFieldLength(), para.getFieldLength(), false, // 	not r/o, ., not error, not dependent
                false, para.isMandatory(), false, false, false, para.getAD_Process_ID(), 0, 0, 0, i + 1, null, null, null, null, null);
            Element toField = para.isRange() ? wFieldforRange.getField(para.getLookup(), para.getDefaultValue2()) : new td(MobileEnv.NBSP);
            div d = new div();
            d.setClass("row");
            //	Add to list
            fs.addElement(d.addElement(wField.getLabel(true)).addElement(wField.getField(para.getLookup(), para.getDefaultValue())).addElement(toField));
        }
        //	Submit
        String text = "Submit";
        if (wsc.ctx != null)
            text = Msg.getMsg(wsc.ctx, "Submit");
        a submitbtn = new a("#", text);
        submitbtn.setClass("whiteButton");
        submitbtn.addAttribute("type", "submit");
        submitbtn.setID(text);
        // submitbtn.setOnClick("popUp('WProcess','WPopup')");
        myForm.addElement(fs);
        myForm.addElement(submitbtn);
        doc.getBody().addElement(myForm);
    }
    return doc;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) MProcessPara(org.compiere.model.MProcessPara) MProcess(org.compiere.model.MProcess) Element(org.apache.ecs.Element) org.apache.ecs.xhtml.fieldset(org.apache.ecs.xhtml.fieldset) org.apache.ecs.xhtml.i(org.apache.ecs.xhtml.i) org.apache.ecs.xhtml.li(org.apache.ecs.xhtml.li) MProcessPara(org.compiere.model.MProcessPara) org.apache.ecs.xhtml.p(org.apache.ecs.xhtml.p) Timestamp(java.sql.Timestamp) org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) org.apache.ecs.xhtml.div(org.apache.ecs.xhtml.div) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) org.apache.ecs.xhtml.form(org.apache.ecs.xhtml.form) org.apache.ecs.xhtml.table(org.apache.ecs.xhtml.table) org.apache.ecs.xhtml.tr(org.apache.ecs.xhtml.tr) org.apache.ecs.xhtml.option(org.apache.ecs.xhtml.option)

Example 17 with MProcess

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

the class WProcess method createProcessPage.

//	createParameterPage
//Modified by Rob klein 4/29/07	
/**************************************************************************
	 * 	Create Parocess Page
	 * 	@param request request
	 *	@param AD_Process_ID Process
	 *	@return Page
	 */
public void createProcessPage(HttpServletRequest request, HttpServletResponse response, int AD_Process_ID, int AD_Window_ID) {
    MobileSessionCtx wsc = MobileSessionCtx.get(request);
    MProcess process = MProcess.get(wsc.ctx, AD_Process_ID);
    log.info("PI table id " + process.get_Table_ID());
    log.info("PI table name id " + process.get_TableName());
    log.info("PI table client id " + process.getAD_Client_ID());
    log.info("PI table process id " + process.getAD_Process_ID());
    log.info("PI  process class name " + process.getClassname());
    //	need to check if Role can access
    MobileDoc doc = null;
    if (process == null) {
        doc = MobileDoc.createWindow("Process Not Found");
    } else {
        doc = MobileDoc.createWindow(process.getName());
        fieldset center = new fieldset();
        doc.getBody().addElement(center);
        if (process.getDescription() != null)
            center.addElement(new p(new i(process.getDescription())));
        if (process.getHelp() != null)
            center.addElement(new p(process.getHelp(), AlignType.LEFT));
        //	Create Process Instance
        MPInstance pInstance = fillParameter(request, process);
        //		
        int AD_Table_ID = MobileUtil.getParameterAsInt(request, "AD_Table_ID");
        int AD_Record_ID = MobileUtil.getParameterAsInt(request, "AD_Record_ID");
        ProcessInfo pi = new ProcessInfo(process.getName(), process.getAD_Process_ID(), AD_Table_ID, AD_Record_ID);
        pi.setAD_User_ID(Env.getAD_User_ID(wsc.ctx));
        pi.setAD_Client_ID(Env.getAD_Client_ID(wsc.ctx));
        pi.setClassName(process.getClassname());
        log.info("PI client id " + pi.getAD_Client_ID());
        pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
        //	Info
        p p = new p();
        p.addElement(Msg.translate(wsc.ctx, "AD_PInstance_ID") + ": " + pInstance.getAD_PInstance_ID());
        center.addElement(p);
        //	Start
        boolean processOK = false;
        if (process.isWorkflow()) {
            Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
            try {
                WProcessCtl.process(this, AD_Window_ID, pi, trx, request);
                //processOK = process.processIt(pi, trx);			
                trx.commit();
                trx.close();
            } catch (Throwable t) {
                trx.rollback();
                trx.close();
            }
            if (pi.isError()) {
                center.addElement(new p("Error:" + pi.getSummary(), AlignType.LEFT).setClass("Cerror"));
                processOK = false;
            } else {
                center.addElement(new p("OK: Workflow Started", AlignType.LEFT));
                processOK = true;
            }
            center.addElement(new p().addElement(pi.getSummary()));
            center.addElement(pi.getLogInfo(true));
        }
        String jasper = process.getJasperReport();
        if (process.isJavaProcess()) {
            if (jasper != null) {
                pi.setPrintPreview(false);
                pi.setIsBatch(true);
            }
            Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
            try {
                processOK = process.processIt(pi, trx);
                trx.commit();
                trx.close();
            } catch (Throwable t) {
                trx.rollback();
                trx.close();
            }
            if (!processOK || pi.isError()) {
                center.addElement(new p("Error:" + pi.getSummary(), AlignType.LEFT).setClass("Cerror"));
                processOK = false;
            } else {
                if (jasper != null) {
                    String error = MobileUtil.streamFile(response, pi.getPDFReport());
                    //String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
                    if (error == null)
                        return;
                    doc = MobileDoc.create(error);
                    wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
                } else {
                    center.addElement(new p().addElement(pi.getSummary()));
                    center.addElement(pi.getLogInfo(true));
                }
            }
        }
        //	Report
        if (process.isReport()) //if (processOK && process.isReport())
        {
            if (jasper == null) {
                log.info(response.toString());
                ReportEngine re = ReportEngine.get(wsc.ctx, pi);
                if (re == null) {
                    center.addElement(new p("Could not start ReportEngine", AlignType.LEFT).setClass("Cerror"));
                } else {
                    try {
                        File file = File.createTempFile("WProcess", ".pdf");
                        boolean ok = re.createPDF(file);
                        if (ok) {
                            String error = MobileUtil.streamFile(response, file);
                            //String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
                            if (error == null)
                                return;
                            doc = MobileDoc.create(error);
                            //Modified by Rob Klein 6/1/07
                            /**
							String url = "WProcess?AD_PInstance_ID=" 
								+ pInstance.getAD_PInstance_ID()
								+ "&File=" 
								+ URLEncoder.encode(file.getAbsolutePath(), WebEnv.ENCODING);
							a link = new a (url, null, a.TARGET_BLANK, process.getName());
							center
								.addElement(new p()
									.addElement("Report created: ")
									.addElement(link));
							//	Marker that Process is OK
							 * */
                            wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
                        } else
                            center.addElement(new p("Could not create Report", AlignType.LEFT).setClass("Cerror"));
                    } catch (Exception e) {
                        center.addElement(new p("Could not create Report:", AlignType.LEFT).setClass("Cerror"));
                        center.addElement(e.toString());
                    }
                }
            }
        }
    }
    try {
        MobileUtil.createResponse(request, response, this, null, doc, false);
    } catch (IOException e) {
        log.info(e.toString());
    }
}
Also used : MProcess(org.compiere.model.MProcess) org.apache.ecs.xhtml.fieldset(org.apache.ecs.xhtml.fieldset) org.apache.ecs.xhtml.i(org.apache.ecs.xhtml.i) org.apache.ecs.xhtml.li(org.apache.ecs.xhtml.li) ProcessInfo(org.compiere.process.ProcessInfo) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException) org.apache.ecs.xhtml.p(org.apache.ecs.xhtml.p) Timestamp(java.sql.Timestamp) MPInstance(org.compiere.model.MPInstance) ReportEngine(org.compiere.print.ReportEngine) Trx(org.compiere.util.Trx) File(java.io.File)

Example 18 with MProcess

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

the class WLookup method doGet.

//  init
/**
	 * Process the HTTP Get request - initial Start
	 * Needs to have parameters FormName and ColumnName
	 *
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    MobileEnv.dump(request);
    MobileEnv.dump(request.getSession());
    //Modified by Rob Klein 4/29/07
    //
    MobileSessionCtx wsc = MobileSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    if (wsc == null) {
        MobileUtil.createTimeoutPage(request, response, this, null);
        return;
    }
    //  Get Mandatory Parameters
    String columnName = MobileUtil.getParameter(request, "ColumnName");
    //Lookup called from a process
    //Modified by Rob Klein 4/29/07
    int AD_Process_ID = MobileUtil.getParameterAsInt(request, "AD_Process_ID");
    //Lookup modified to include paging
    //Modified by Rob Klein 07/07/07
    int page = MobileUtil.getParameterAsInt(request, "page");
    int refValueId = 0;
    boolean startUpdate = false;
    String targetBase = "'" + columnName;
    String header = null;
    if (AD_Process_ID > 0) {
        if (AD_Process_ID < 1 || columnName == null || columnName.equals("")) {
            MobileUtil.createErrorPage(request, response, this, Msg.getMsg(wsc.ctx, "ParameterMissing"));
            return;
        }
        MProcess process = MProcess.get(wsc.ctx, AD_Process_ID);
        MProcessPara para = null;
        MProcessPara[] parameters = process.getParameters();
        for (int i = 0; i < parameters.length; i++) {
            if (para.getColumnName().equals(columnName))
                para = parameters[i];
        }
        if (para != null)
            refValueId = para.getAD_Reference_Value_ID();
        header = para.getColumnName();
    } else //Lookup called from a window
    {
        //	Modified by Rob Klein 7/01/07
        if (ws == null) {
            MobileUtil.createTimeoutPage(request, response, this, null);
            return;
        }
        GridField mField = ws.curTab.getField(columnName);
        log.config("ColumnName=" + columnName + ", MField=" + mField);
        if (mField == null || columnName == null || columnName.equals("")) {
            MobileUtil.createErrorPage(request, response, this, Msg.getMsg(ws.ctx, "ParameterMissing"));
            return;
        }
        header = mField.getHeader();
        boolean hasDependents = ws.curTab.hasDependants(columnName);
        boolean hasCallout = mField.getCallout().length() > 0;
        startUpdate = hasDependents || hasCallout;
        refValueId = mField.getAD_Reference_Value_ID();
    }
    if (m_searchFields == null || m_searchFields.length == 0) {
        getSearchFields(columnName, refValueId);
    }
    String search = MobileUtil.getParameter(request, "search");
    if (Util.isEmpty(MobileUtil.getParameter(request, "search"))) {
        //  Create Document
        MobileDoc doc = MobileDoc.createPopup(header);
        form panel = new form();
        panel.setMethod("post");
        panel.setClass("dialog");
        panel.setID("WLookup1");
        panel.setAction("WLookup?ColumnName=" + columnName + "&AD_Process_ID=" + AD_Process_ID);
        panel.addAttribute("selected", "true");
        fieldset set = new fieldset();
        h1 h = new h1(header);
        set.addElement(h);
        a a = new a("#", "Cancel");
        a.addAttribute("type", "cancel");
        a.setClass("button leftButton");
        set.addElement(a);
        a = new a("WLookup?ColumnName=" + columnName + "&AD_Process_ID=" + AD_Process_ID, "Search");
        a.addAttribute("type", "submit");
        a.setClass("button");
        set.addElement(a);
        panel.addElement(set);
        for (int i = 0; i < m_searchFields.length; i++) {
            /*
				label l = new label();
				l.addElement(m_searchLabels[i]);
				set.addElement(l)*/
            input f = new input(input.TYPE_TEXT, m_searchFields[i], "");
            f.setID(m_searchFields[i]);
            f.addAttribute("placeholder", m_searchLabels[i]);
            set.addElement(f).addElement(new br());
        }
        input hidden = new input(input.TYPE_HIDDEN, "search", "true");
        set.addElement(hidden);
        doc.getBody().addElement(panel);
        MobileUtil.createResponseFragment(request, response, this, null, doc);
    } else {
        //  Create Document
        MobileDoc doc = MobileDoc.createPopup(header);
        StringBuffer where = new StringBuffer();
        for (String column : m_searchFields) {
            String value = request.getParameter(column);
            if (!Util.isEmpty(value)) {
                value = "%" + value + "%";
                where.append(" AND UPPER(").append(column).append(") LIKE UPPER(").append(DB.TO_STRING(value)).append(") ");
            }
        }
        div panel = new div();
        panel.setClass("dialog");
        panel.addAttribute("selected", "true");
        panel.setID("WLookup2");
        fieldset set = new fieldset();
        panel.addElement(set);
        set.addElement(fillTable(wsc, columnName, refValueId, request.getRequestURI(), targetBase, startUpdate, page, where.toString()));
        //  Reset
        String text = "Reset";
        //if (wsc.ctx != null)
        //	text = Msg.getMsg (wsc.ctx, "Reset");		
        input resetbtn = new input(input.TYPE_RESET, text, "  " + text);
        resetbtn.setID(text);
        resetbtn.setClass("resetbtn");
        String script = targetBase + "F.value='';" + targetBase + "D.value='';self.close();";
        if (startUpdate)
            script += "startUpdate(" + targetBase + "F);";
        resetbtn.setOnClick(script);
        doc.getBody().addElement(panel);
        doc.getBody().addElement(resetbtn);
        MobileUtil.createResponseFragment(request, response, this, null, doc);
    }
}
Also used : MobileSessionCtx(org.compiere.mobile.MobileSessionCtx) MProcessPara(org.compiere.model.MProcessPara) org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) MProcess(org.compiere.model.MProcess) org.apache.ecs.xhtml.fieldset(org.apache.ecs.xhtml.fieldset) org.apache.ecs.xhtml.h1(org.apache.ecs.xhtml.h1) MProcessPara(org.compiere.model.MProcessPara) GridField(org.compiere.model.GridField) org.apache.ecs.xhtml.br(org.apache.ecs.xhtml.br) org.apache.ecs.xhtml.div(org.apache.ecs.xhtml.div) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) org.apache.ecs.xhtml.form(org.apache.ecs.xhtml.form)

Example 19 with MProcess

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

the class Scheduler method doWork.

/**
	 * 	Work
	 */
protected void doWork() {
    m_summary = new StringBuffer(m_model.toString()).append(" - ");
    // Prepare a ctx for the report/process - BF [1966880]
    m_schedulerctx.clear();
    MClient schedclient = MClient.get(getCtx(), m_model.getAD_Client_ID());
    Env.setContext(m_schedulerctx, "#AD_Client_ID", schedclient.getAD_Client_ID());
    Env.setContext(m_schedulerctx, "#AD_Language", schedclient.getAD_Language());
    Env.setContext(m_schedulerctx, "#AD_Org_ID", m_model.getAD_Org_ID());
    if (m_model.getAD_Org_ID() != 0) {
        MOrgInfo schedorg = MOrgInfo.get(getCtx(), m_model.getAD_Org_ID(), null);
        if (schedorg.getM_Warehouse_ID() > 0)
            Env.setContext(m_schedulerctx, "#M_Warehouse_ID", schedorg.getM_Warehouse_ID());
    }
    Env.setContext(m_schedulerctx, "#AD_User_ID", getAD_User_ID());
    Env.setContext(m_schedulerctx, "#SalesRep_ID", getAD_User_ID());
    // TODO: It can be convenient to add  AD_Scheduler.AD_Role_ID
    MUser scheduser = MUser.get(getCtx(), getAD_User_ID());
    MRole[] schedroles = scheduser.getRoles(m_model.getAD_Org_ID());
    if (schedroles != null && schedroles.length > 0)
        // first role, ordered by AD_Role_ID
        Env.setContext(m_schedulerctx, "#AD_Role_ID", schedroles[0].getAD_Role_ID());
    Timestamp ts = new Timestamp(System.currentTimeMillis());
    SimpleDateFormat dateFormat4Timestamp = new SimpleDateFormat("yyyy-MM-dd");
    //  JDBC format
    Env.setContext(m_schedulerctx, "#Date", dateFormat4Timestamp.format(ts) + " 00:00:00");
    Properties currentctx = Env.getCtx();
    Env.setCtx(m_schedulerctx);
    MProcess process = new MProcess(m_schedulerctx, m_model.getAD_Process_ID(), null);
    try {
        m_trx = Trx.get(Trx.createTrxName("Scheduler"), true);
        m_summary.append(runProcess(process));
        m_trx.commit(true);
    } catch (Exception e) {
        if (m_trx != null)
            m_trx.rollback();
        log.log(Level.WARNING, process.toString(), e);
        m_summary.append(e.toString());
    } finally {
        if (m_trx != null)
            m_trx.close();
    }
    // Restore system context
    Env.setCtx(currentctx);
    //
    int no = m_model.deleteLog();
    m_summary.append(" Logs deleted=").append(no);
    //
    MSchedulerLog pLog = new MSchedulerLog(m_model, m_summary.toString());
    pLog.setReference("#" + String.valueOf(p_runCount) + " - " + TimeUtil.formatElapsed(new Timestamp(p_startWork)));
    pLog.saveEx();
}
Also used : MProcess(org.compiere.model.MProcess) MRole(org.compiere.model.MRole) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) MClient(org.compiere.model.MClient) MSchedulerLog(org.compiere.model.MSchedulerLog) MOrgInfo(org.compiere.model.MOrgInfo) MUser(org.compiere.model.MUser) SimpleDateFormat(java.text.SimpleDateFormat)

Example 20 with MProcess

use of org.compiere.model.MProcess 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.
    }
}
Also used : MProcess(org.compiere.model.MProcess) MRole(org.compiere.model.MRole) ProcessInfo(org.compiere.process.ProcessInfo) ProcessModalDialog(org.adempiere.webui.apps.ProcessModalDialog) MBrowse(org.adempiere.model.MBrowse) WBrowser(org.eevolution.form.WBrowser) ICreateFrom(org.compiere.grid.ICreateFrom) WPayment(org.adempiere.webui.apps.form.WPayment) GridTab(org.compiere.model.GridTab)

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