Search in sources :

Example 6 with ProcessInfo

use of org.compiere.process.ProcessInfo in project adempiere by adempiere.

the class ZkReportViewer method launchProcessPara.

//	cmd_find
/**
	 * FR [ 295 ]
	 * Launch Parameters for re-query
	 * @return isOk
	 */
private boolean launchProcessPara() {
    //	Create new Instance
    ProcessInfo pi = new ProcessInfo(m_reportEngine.getProcessInfo().getTitle(), m_reportEngine.getProcessInfo().getAD_Process_ID(), m_reportEngine.getProcessInfo().getTable_ID(), m_reportEngine.getProcessInfo().getRecord_ID());
    //	Launch dialog
    ProcessModalDialog dialog = new ProcessModalDialog(null, m_WindowNo, pi);
    if (dialog.isValid()) {
        try {
            dialog.setPage(this.getPage());
            dialog.doModal();
            //	Valid
            if (dialog.isOK()) {
                //	execute
                ProcessCtl worker = new ProcessCtl(null, m_WindowNo, pi, true, null);
                //synchrous
                worker.run();
                //	
                ReportEngine re = ReportEngine.get(Env.getCtx(), pi);
                //	
                if (re != null) {
                    m_reportEngine.setQuery(re.getQuery());
                }
                //	
                return true;
            }
        } catch (InterruptedException e) {
            log.severe(e.getLocalizedMessage());
        }
    }
    //	Default
    return false;
}
Also used : ReportEngine(org.compiere.print.ReportEngine) ProcessCtl(org.compiere.apps.ProcessCtl) ProcessInfo(org.compiere.process.ProcessInfo) ProcessModalDialog(org.adempiere.webui.apps.ProcessModalDialog)

Example 7 with ProcessInfo

use of org.compiere.process.ProcessInfo in project adempiere by adempiere.

the class VCreateFromStatementUI method init.

//  infoStatement
@Override
public void init(int WindowNo, FormFrame frame) {
    p_WindowNo = WindowNo;
    v_Container = frame;
    ProcessInfo info = frame.getProcessInfo();
    try {
        //	Valid for launched from a window
        if (info != null) {
            //	Valid Table and Record
            validTable(info.getTable_ID(), info.getRecord_ID());
        }
        //	Init
        if (!dynInit())
            return;
        jbInit();
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
}
Also used : ProcessInfo(org.compiere.process.ProcessInfo)

Example 8 with ProcessInfo

use of org.compiere.process.ProcessInfo in project adempiere by adempiere.

the class VInOutInvoiceGen method generateInvoices.

//  generateShipments_complete
/**************************************************************************
	 *	Generate Invoices
	 */
private void generateInvoices() {
    String trxName = Trx.createTrxName("IVG");
    //trx needs to be committed too
    Trx trx = Trx.get(trxName, true);
    //String trxName = null;
    //Trx trx = null;
    //  prevents from being called twice
    m_selectionActive = false;
    statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InvGenerateGen"));
    statusBar.setStatusDB(String.valueOf(selection.size()));
    //	Prepare Process
    int AD_Process_ID = 0;
    KeyNamePair docTypeKNPair = (KeyNamePair) cmbDocType.getSelectedItem();
    if (docTypeKNPair.getKey() == MRMA.Table_ID) {
        // C_Invoice_GenerateRMA - org.adempiere.process.InvoiceGenerateRMA
        AD_Process_ID = 52002;
    } else {
        // HARDCODED    C_InvoiceCreate
        AD_Process_ID = 134;
    }
    MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
    if (!instance.save()) {
        info.setText(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
        return;
    }
    //insert selection
    /*Selection exist from shipment*/
    StringBuffer insert = new StringBuffer();
    insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
    int counter = 0;
    for (Integer selectedId : selection) {
        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.setText(msg);
                trx.rollback();
                return;
            }
            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.setText(msg);
            trx.rollback();
            return;
        }
    }
    ProcessInfo pi = new ProcessInfo("", AD_Process_ID);
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    //	Add Parameters
    MPInstancePara para = new MPInstancePara(instance, 10);
    para.setParameter("Selection", "Y");
    if (!para.save()) {
        //  not translated
        String msg = "No Selection Parameter added";
        info.setText(msg);
        log.log(Level.SEVERE, msg);
        return;
    }
    para = new MPInstancePara(instance, 20);
    para.setParameter("DocAction", "CO");
    if (!para.save()) {
        //  not translated
        String msg = "No DocAction Parameter added";
        info.setText(msg);
        log.log(Level.SEVERE, msg);
        return;
    }
    //	Execute Process
    ProcessCtl worker = new ProcessCtl(this, Env.getWindowNo(this), pi, trx);
    //  complete tasks in unlockUI / generateInvoice_complete
    worker.start();
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) ProcessCtl(org.compiere.apps.ProcessCtl) Trx(org.compiere.util.Trx) KeyNamePair(org.compiere.util.KeyNamePair) ProcessInfo(org.compiere.process.ProcessInfo)

Example 9 with ProcessInfo

use of org.compiere.process.ProcessInfo in project adempiere by adempiere.

the class VInOutInvoiceGen method generateShipments.

//	saveSelection
/**************************************************************************
	 *	Generate Shipments
	 */
private void generateShipments() {
    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);
    //String trxName = null;
    //Trx trx = null;
    //  prevents from being called twice
    m_selectionActive = false;
    statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateGen"));
    statusBar.setStatusDB(String.valueOf(selection.size()));
    //	Prepare Process
    int AD_Process_ID = 0;
    KeyNamePair docTypeKNPair = (KeyNamePair) cmbDocType.getSelectedItem();
    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.setText(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
        return;
    }
    //insert selection
    StringBuffer insert = new StringBuffer();
    insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
    int counter = 0;
    for (Integer selectedId : selection) {
        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.setText(msg);
                trx.rollback();
                return;
            }
            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.setText(msg);
            trx.rollback();
            return;
        }
    }
    //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.setText(msg);
        log.log(Level.SEVERE, msg);
        return;
    }
    //	Add Parameter - M_Warehouse_ID=x
    ip = new MPInstancePara(instance, 20);
    ip.setParameter("M_Warehouse_ID", Integer.parseInt(m_M_Warehouse_ID.toString()));
    if (!ip.save()) {
        //  not translated
        String msg = "No Parameter added";
        info.setText(msg);
        log.log(Level.SEVERE, msg);
        return;
    }
    //	Execute Process
    ProcessCtl worker = new ProcessCtl(this, Env.getWindowNo(this), pi, trx);
    //  complete tasks in unlockUI / generateShipments_complete
    worker.start();
//
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) ProcessCtl(org.compiere.apps.ProcessCtl) Trx(org.compiere.util.Trx) KeyNamePair(org.compiere.util.KeyNamePair) ProcessInfo(org.compiere.process.ProcessInfo)

Example 10 with ProcessInfo

use of org.compiere.process.ProcessInfo in project adempiere by adempiere.

the class Process method runProcess.

/**************************************************************************
	 * 	Create Process Page
	 *	@param AD_Process_ID Process
	 *	@return Page
	 */
public static RunProcessResponseDocument runProcess(CompiereService m_cs, RunProcessDocument req) {
    RunProcessResponseDocument res = RunProcessResponseDocument.Factory.newInstance();
    RunProcessResponse r = res.addNewRunProcessResponse();
    RunProcess rp = req.getRunProcess();
    int AD_Process_ID = rp.getADProcessID();
    int m_record_id = rp.getADRecordID();
    //WebSessionCtx wsc = WebSessionCtx.get (request);
    MProcess process = MProcess.get(m_cs.getM_ctx(), AD_Process_ID);
    //	need to check if Role can access
    if (process == null) {
        // WebDoc doc = WebDoc.createWindow("Process not found");
        r.setError("Process not found");
        r.setIsError(true);
        return res;
    }
    //process.getDescription()
    //process.getHelp()
    // Evaluate DocAction, if call have DocAction parameter, then try to set DocAction before calling workflow process
    String docAction = rp.getDocAction();
    if (docAction != null && docAction.length() > 0) {
        // - the process must be a workflow document
        if (process.getAD_Workflow_ID() > 0) {
            MWorkflow wf = MWorkflow.get(m_cs.getM_ctx(), process.getAD_Workflow_ID());
            if (wf.getWorkflowType().equals(MWorkflow.WORKFLOWTYPE_DocumentProcess)) {
                // - get the table associated with the workflow document
                // - set DocAction in such table
                // get the PO for the tablename and record ID
                MTable table = MTable.get(m_cs.getM_ctx(), wf.getAD_Table_ID());
                if (table != null) {
                    PO po = table.getPO(m_record_id, null);
                    if (po != null) {
                        po.set_ValueOfColumn("DocAction", docAction);
                        po.save();
                    }
                }
            }
        }
    }
    //	Create Process Instance
    MPInstance pInstance = null;
    try {
        pInstance = fillParameter(m_cs, rp.getParamValues(), process);
    } catch (Exception ex) {
        //center.addElement(new p("B��d: " + ex.getMessage(), AlignType.LEFT).setClass("ProcesResultError"));
        r.setError(ex.getMessage());
        r.setIsError(true);
        return res;
    }
    if (m_record_id > 0) {
        pInstance.setRecord_ID(m_record_id);
        pInstance.save();
    }
    //
    ProcessInfo pi = new ProcessInfo(process.getName(), process.getAD_Process_ID());
    pi.setAD_User_ID(Env.getAD_User_ID(m_cs.getM_ctx()));
    pi.setAD_Client_ID(Env.getAD_Client_ID(m_cs.getM_ctx()));
    pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
    if (m_record_id > 0)
        pi.setRecord_ID(m_record_id);
    //	Info
    //p p = new p();
    //p.addElement(Msg.translate(wsc.ctx, "AD_PInstance_ID") + ": " + pInstance.getAD_PInstance_ID());
    //center.addElement(p);
    boolean processOK = false;
    boolean jasperreport = (process != null && process.getClassname() != null && process.getClassname().indexOf("net.sf.compilo.report.ReportStarter") >= 0);
    if (jasperreport) {
        //this.jasperReport( request, response, wsc.ctx, pi);
        processOK = true;
    }
    //	Start
    if (process.isWorkflow()) {
        try {
            int AD_Workflow_ID = process.getAD_Workflow_ID();
            MWorkflow wf = MWorkflow.get(Env.getCtx(), AD_Workflow_ID);
            //	may return null
            MWFProcess wfProcess = wf.startWait(pi);
            if (wfProcess != null) {
                //wynik
                r.setSummary(pi.getSummary());
                r.setLogInfo(pi.getLogInfo(true));
                r.setIsError(false);
                return res;
            }
        } catch (Exception ex) {
            r.setError(ex.getMessage());
            r.setLogInfo(pi.getLogInfo(true));
            r.setIsError(true);
            return res;
        //Wyj�tek: pi.getLogInfo(true) pi.getLogInfo(true)
        }
    //started = wfProcess != null;
    }
    if (process.isJavaProcess() && !jasperreport) {
        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()) {
            // b��d:  pi.getSummary()
            r.setSummary(pi.getSummary());
            r.setLogInfo(pi.getLogInfo(true));
            r.setIsError(true);
            processOK = false;
        } else {
            r.setSummary(pi.getSummary());
            r.setLogInfo(pi.getLogInfo(true));
            r.setIsError(false);
        //return res;	
        // wynik - String summary = pi.getSummary();
        }
    }
    //	Report
    if (//&& !m_jasperreport)
    (process.isReport() || jasperreport)) /*processOK &&*/
    {
        r.setIsReport(true);
        //if (m_jasperreport)
        //{
        //	center.addElement(new p("JASPER REPORT", AlignType.LEFT).setClass("Cerror"));
        //} 
        //else
        {
            ReportEngine re = null;
            if (!jasperreport)
                re = start(pi);
            //ReportEngine.get(m_cs.getM_ctx(), pi);
            if (re == null && !jasperreport) {
            //b��d: "Nie uda�o si� uruchomi� silnika raport�w (ReportEngine)", 
            } else {
                try {
                    boolean ok = false;
                    File file;
                    String file_type = "pdf";
                    if (!jasperreport) {
                        //file = File.createTempFile("WProcess", ".pdf");
                        //ok = re.createPDF(file);
                        MPrintFormat pf = re.getPrintFormat();
                        if (pf.isTableBased()) {
                            CharArrayWriter wr = new CharArrayWriter();
                            //file = File.createTempFile("WProcess", ".xls");
                            ok = ReportEngineEx.createEXCEL_HTML_wr(re, m_cs.getM_ctx(), wr, false, re.getPrintFormat().getLanguage());
                            //ok = re.createXML( file );
                            file_type = "xls";
                            String data = wr.toString();
                            if (data != null)
                                r.setData(data.getBytes());
                            r.setReportFormat(file_type);
                        } else {
                            byte[] dat = re.createPDFData();
                            file_type = "pdf";
                            r.setData(dat);
                            r.setReportFormat(file_type);
                        }
                        //r.setReportFormat("xls");							
                        ok = true;
                    } else {
                        JasperPrint jp = getJasperReportPrint(m_cs.getM_ctx(), pi);
                        //file = File.createTempFile("WProcess", ".pdf");
                        ByteArrayOutputStream wr = new ByteArrayOutputStream();
                        net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jp, wr);
                        //exportReportToPdfFile( jp, file.getAbsolutePath() );							
                        file_type = "pdf";
                        r.setData(wr.toByteArray());
                        r.setReportFormat(file_type);
                        ok = true;
                    }
                    if (ok) {
                        //pInstance.getAD_PInstance_ID()
                        //file.getAbsolutePath()
                        //	Marker that Process is OK
                        m_cs.getM_ctx().put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
                    } else {
                        r.setError("Cannot create report");
                        r.setLogInfo(pi.getLogInfo(true));
                        r.setIsError(true);
                        return res;
                    //"Cannot create report:",
                    }
                } catch (Exception e) {
                    r.setError("Cannot create report:" + e.getMessage());
                    r.setLogInfo(pi.getLogInfo(true));
                    r.setIsError(true);
                    return res;
                // , 
                }
            }
        }
    }
    return res;
}
Also used : MProcess(org.compiere.model.MProcess) MWFProcess(org.compiere.wf.MWFProcess) MWorkflow(org.compiere.wf.MWorkflow) JasperPrint(net.sf.jasperreports.engine.JasperPrint) ProcessInfo(org.compiere.process.ProcessInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RunProcessResponse(pl.x3E.adInterface.RunProcessResponse) JasperPrint(net.sf.jasperreports.engine.JasperPrint) SQLException(java.sql.SQLException) IOException(java.io.IOException) CharArrayWriter(java.io.CharArrayWriter) MPInstance(org.compiere.model.MPInstance) ReportEngine(org.compiere.print.ReportEngine) MPrintFormat(org.compiere.print.MPrintFormat) MTable(org.compiere.model.MTable) RunProcess(pl.x3E.adInterface.RunProcess) Trx(org.compiere.util.Trx) File(java.io.File) RunProcessResponseDocument(pl.x3E.adInterface.RunProcessResponseDocument) PO(org.compiere.model.PO)

Aggregations

ProcessInfo (org.compiere.process.ProcessInfo)65 MPInstance (org.compiere.model.MPInstance)21 Trx (org.compiere.util.Trx)17 AdempiereException (org.adempiere.exceptions.AdempiereException)14 MPInstancePara (org.compiere.model.MPInstancePara)12 ReportEngine (org.compiere.print.ReportEngine)11 File (java.io.File)10 MProcess (org.compiere.model.MProcess)9 ProcessCtl (org.compiere.apps.ProcessCtl)8 SQLException (java.sql.SQLException)6 Timestamp (java.sql.Timestamp)6 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 ServletException (javax.servlet.ServletException)4 MBrowse (org.adempiere.model.MBrowse)4 PrintInfo (org.compiere.model.PrintInfo)4 ProcessInfoParameter (org.compiere.process.ProcessInfoParameter)4 Properties (java.util.Properties)3 MMovement (org.compiere.model.MMovement)3 PO (org.compiere.model.PO)3