Search in sources :

Example 6 with ReportEngine

use of org.compiere.print.ReportEngine in project adempiere by adempiere.

the class WReport method launchReport.

//	launchReport
/**
	 * 	Launch Report
	 * 	@param pf print format
	 */
private void launchReport(MPrintFormat pf) {
    int Record_ID = 0;
    //  The query is passed into A/WReport.java with only the key or link column included.
    if (m_query.getRestrictionCount() == 1 && m_query.getCode(0) instanceof Integer)
        Record_ID = ((Integer) m_query.getCode(0)).intValue();
    //  Add the extended query after the record ID has been identified.
    if (m_whereExtended != null && m_whereExtended.length() > 0 && m_query != null)
        m_query.addRestriction(Env.parseContext(Env.getCtx(), WindowNo, m_whereExtended, false));
    PrintInfo info = new PrintInfo(pf.getName(), pf.getAD_Table_ID(), Record_ID);
    info.setDescription(m_query.getInfo());
    if (pf != null && pf.getJasperProcess_ID() > 0) {
        // It's a report using the JasperReports engine
        ProcessInfo pi = new ProcessInfo("", pf.getJasperProcess_ID(), pf.getAD_Table_ID(), Record_ID);
        //	Execute Process
        WProcessCtl.process(null, WindowNo, pi, null);
    } else {
        // It's a default report using the standard printing engine
        ReportEngine re = new ReportEngine(Env.getCtx(), pf, m_query, info);
        // TODO: Is this required?  The extended query, if any, is included in the query.
        re.setWhereExtended(m_whereExtended);
        ReportCtl.preview(re);
    }
}
Also used : ReportEngine(org.compiere.print.ReportEngine) PrintInfo(org.compiere.model.PrintInfo) ProcessInfo(org.compiere.process.ProcessInfo)

Example 7 with ReportEngine

use of org.compiere.print.ReportEngine in project adempiere by adempiere.

the class CompletePrintOrder method getReportEngine.

// doIt
/*
	 * get the a Report Engine Instance using the view table 
	 * @param tableName
	 */
private ReportEngine getReportEngine(String formatName, String tableName) {
    // Get Format & Data
    int format_id = MPrintFormat.getPrintFormat_ID(formatName, MTable.getTable_ID(tableName), getAD_Client_ID());
    MPrintFormat format = MPrintFormat.get(getCtx(), format_id, true);
    if (format == null) {
        addLog("@NotFound@ @AD_PrintFormat_ID@");
        return null;
    }
    // query
    MQuery query = new MQuery(tableName);
    query.addRestriction("PP_Order_ID", MQuery.EQUAL, p_PP_Order_ID);
    // Engine
    PrintInfo info = new PrintInfo(tableName, MTable.getTable_ID(tableName), p_PP_Order_ID);
    ReportEngine re = new ReportEngine(getCtx(), format, query, info);
    return re;
}
Also used : MPrintFormat(org.compiere.print.MPrintFormat) ReportEngine(org.compiere.print.ReportEngine) MQuery(org.compiere.model.MQuery) PrintInfo(org.compiere.model.PrintInfo)

Example 8 with ReportEngine

use of org.compiere.print.ReportEngine 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) {
    WebSessionCtx wsc = WebSessionCtx.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
    WebDoc doc = null;
    if (process == null) {
        doc = WebDoc.createWindow("Process Not Found");
    } else {
        doc = WebDoc.createWindow(process.getName());
        td center = doc.addWindowCenter(false);
        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 = WebUtil.getParameterAsInt(request, "AD_Table_ID");
        int AD_Record_ID = WebUtil.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 = WebUtil.streamFile(response, pi.getPDFReport());
                    //String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
                    if (error == null)
                        return;
                    doc = WebDoc.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 = WebUtil.streamFile(response, file);
                            //String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
                            if (error == null)
                                return;
                            doc = WebDoc.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());
                    }
                }
            }
        }
    }
    doc.addPopupClose(wsc.ctx);
    try {
        WebUtil.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.i(org.apache.ecs.xhtml.i) ProcessInfo(org.compiere.process.ProcessInfo) IOException(java.io.IOException) WebSessionCtx(org.compiere.util.WebSessionCtx) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException) org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) org.apache.ecs.xhtml.p(org.apache.ecs.xhtml.p) Timestamp(java.sql.Timestamp) MPInstance(org.compiere.model.MPInstance) ReportEngine(org.compiere.print.ReportEngine) WebDoc(org.compiere.util.WebDoc) Trx(org.compiere.util.Trx) File(java.io.File)

Example 9 with ReportEngine

use of org.compiere.print.ReportEngine in project adempiere by adempiere.

the class WReport method launchReport.

//	launchReport
/**
	 * 	Launch Report
	 * 	@param pf print format
	 */
private File launchReport(MPrintFormat pf, HttpServletRequest request, GridTab m_curTab, MQuery m_query) {
    int Record_ID = 0;
    WebSessionCtx wsc = WebSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    //Instance pInstance = new MPInstance (wsc.ctx, 0, 0);
    File fileName = null;
    if (m_query.getRestrictionCount() == 1 && m_query.getCode(0) instanceof Integer) {
        Record_ID = ((Integer) m_query.getCode(0)).intValue();
    }
    PrintInfo info = new PrintInfo(pf.getName(), pf.getAD_Table_ID(), Record_ID);
    info.setDescription(m_query.getInfo());
    if (pf != null && pf.getJasperProcess_ID() > 0) {
        // It's a report using the JasperReports engine
        ProcessInfo pi = new ProcessInfo("", pf.getJasperProcess_ID());
        Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
        //	Execute Process
        WProcessCtl.process(this, m_curTab.getAD_Window_ID(), pi, trx, request);
    } else {
        // It's a default report using the standard printing engine
        ReportEngine re = new ReportEngine(wsc.ctx, pf, m_query, info);
        if (re == null) {
            log.info("Could not start ReportEngine");
        } else {
            try {
                File file = File.createTempFile("WProcess", ".pdf");
                boolean ok = re.createPDF(file);
                if (ok) {
                    fileName = file;
                } else {
                    log.info("Could not create Report");
                }
            } catch (Exception e) {
                log.info(e.toString());
            }
        }
    }
    return fileName;
}
Also used : ReportEngine(org.compiere.print.ReportEngine) PrintInfo(org.compiere.model.PrintInfo) ProcessInfo(org.compiere.process.ProcessInfo) Trx(org.compiere.util.Trx) WebSessionCtx(org.compiere.util.WebSessionCtx) File(java.io.File) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 10 with ReportEngine

use of org.compiere.print.ReportEngine in project adempiere by adempiere.

the class CostResult method createTrxAndInventoryValuationReport.

void createTrxAndInventoryValuationReport() {
    int AD_Process_ID = MProcess.getProcess_ID("Transaction Valuation", trxName);
    ProcessInfo pi = new ProcessInfo("Transaction Valuation", AD_Process_ID);
    MPInstance instance = new MPInstance(getCtx(), AD_Process_ID, 0);
    instance.saveEx();
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    pi.setAD_Client_ID(Env.getAD_Client_ID(getCtx()));
    //	Add Parameters
    MPInstancePara para = new MPInstancePara(instance, 10);
    para.setParameter(MCostDetail.COLUMNNAME_M_Product_ID, product.getM_Product_ID());
    para.saveEx();
    para = new MPInstancePara(instance, 20);
    para.setParameter(MCostDetail.COLUMNNAME_M_CostType_ID, 50000);
    para.saveEx();
    para = new MPInstancePara(instance, 30);
    para.setParameter(MCostDetail.COLUMNNAME_M_CostElement_ID, 100);
    para.saveEx();
    pi.setTransactionName(trxName);
    //ReportCtl.startStandardReport(pi);	
    ReportEngine re = ReportEngine.get(getCtx(), pi);
    File trxValuation = null;
    trxValuation = re.getPDF();
    AD_Process_ID = MProcess.getProcess_ID("Valuation Effective Date", trxName);
    pi = new ProcessInfo("Valuation Effective Date", AD_Process_ID);
    instance = new MPInstance(getCtx(), AD_Process_ID, 0);
    instance.saveEx();
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    pi.setAD_Client_ID(Env.getAD_Client_ID(getCtx()));
    para = new MPInstancePara(instance, 10);
    para.setParameter("DateValue", new Timestamp(System.currentTimeMillis()));
    para.saveEx();
    //	Add Parameters
    para = new MPInstancePara(instance, 20);
    para.setParameter(MCostDetail.COLUMNNAME_M_Product_ID, product.getM_Product_ID());
    para.saveEx();
    para = new MPInstancePara(instance, 30);
    para.setParameter(MCostDetail.COLUMNNAME_M_CostType_ID, 50000);
    para.saveEx();
    para = new MPInstancePara(instance, 40);
    para.setParameter(MCostDetail.COLUMNNAME_M_CostElement_ID, 100);
    para.saveEx();
    ValuationEffectiveDate process = new ValuationEffectiveDate();
    process.startProcess(getCtx(), pi, Trx.get(trxName, false));
    pi.setTransactionName(trxName);
    re = ReportEngine.get(getCtx(), pi);
    File report = null;
    report = re.getPDF();
    EMail email = new EMail(getCtx(), "smtp.gmail.com", "victor.perez@e-evolution.com", "victor.perez@e-evolution.com", "Transaction and Inventory Valuation Report Test", "Transaction and Inventory Valuation " + new Timestamp(System.currentTimeMillis()));
    email.addAttachment(trxValuation);
    email.addAttachment(report);
    email.createAuthenticator(Mail, MailPassword);
    String msg = email.send();
    System.out.println(msg);
}
Also used : ValuationEffectiveDate(org.eevolution.process.ValuationEffectiveDate) MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) ReportEngine(org.compiere.print.ReportEngine) ProcessInfo(org.compiere.process.ProcessInfo) EMail(org.compiere.util.EMail) File(java.io.File) Timestamp(java.sql.Timestamp)

Aggregations

ReportEngine (org.compiere.print.ReportEngine)27 PrintInfo (org.compiere.model.PrintInfo)15 File (java.io.File)13 MPrintFormat (org.compiere.print.MPrintFormat)13 MQuery (org.compiere.model.MQuery)12 ProcessInfo (org.compiere.process.ProcessInfo)10 SQLException (java.sql.SQLException)6 MPInstance (org.compiere.model.MPInstance)6 IOException (java.io.IOException)5 Trx (org.compiere.util.Trx)5 FileInputStream (java.io.FileInputStream)4 Timestamp (java.sql.Timestamp)4 ServletException (javax.servlet.ServletException)4 SimplePDFViewer (org.adempiere.webui.window.SimplePDFViewer)4 MClient (org.compiere.model.MClient)4 MProcess (org.compiere.model.MProcess)4 ArrayList (java.util.ArrayList)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MMailText (org.compiere.model.MMailText)3 MTable (org.compiere.model.MTable)3