Search in sources :

Example 6 with MPrintFormat

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

the class OrderDistribution method dynInit.

public void dynInit() throws Exception {
    setTitle("MovementGenerateInfo");
    MPrintFormat format = MPrintFormat.get(Env.getCtx(), MPrintFormat.getPrintFormat_ID("Inventory Move Hdr (Example)", MMovement.Table_ID, 0), false);
    setPrintFormat(format);
    setAskPrintMsg("PrintMovements");
}
Also used : MPrintFormat(org.compiere.print.MPrintFormat)

Example 7 with MPrintFormat

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

the class LayoutEngine method includeFormat.

//	layoutForm
/**
	 * 	Include Table Format
	 *	@param item print format item
	 *	@param data print data
	 *	@return Print Element
	 */
private PrintElement includeFormat(MPrintFormatItem item, PrintData data) {
    newLine();
    PrintElement element = null;
    //
    MPrintFormat format = MPrintFormat.get(getCtx(), item.getAD_PrintFormatChild_ID(), false);
    format.setLanguage(m_format.getLanguage());
    if (m_format.isTranslationView())
        format.setTranslationLanguage(m_format.getLanguage());
    int AD_Column_ID = item.getAD_Column_ID();
    log.info(format + " - Item=" + item.getName() + " (" + AD_Column_ID + ")");
    //
    Object obj = data.getNode(new Integer(AD_Column_ID));
    //	Object obj = data.getNode(item.getColumnName());	//	slower
    if (obj == null) {
        data.dumpHeader();
        data.dumpCurrentRow();
        log.log(Level.SEVERE, "No Node - AD_Column_ID=" + AD_Column_ID + " - " + item + " - " + data);
        return null;
    }
    PrintDataElement dataElement = (PrintDataElement) obj;
    String recordString = dataElement.getValueKey();
    if (recordString == null || recordString.length() == 0) {
        data.dumpHeader();
        data.dumpCurrentRow();
        log.log(Level.SEVERE, "No Record Key - " + dataElement + " - AD_Column_ID=" + AD_Column_ID + " - " + item);
        return null;
    }
    int Record_ID = 0;
    try {
        Record_ID = Integer.parseInt(recordString);
    } catch (Exception e) {
        data.dumpCurrentRow();
        log.log(Level.SEVERE, "Invalid Record Key - " + recordString + " (" + e.getMessage() + ") - AD_Column_ID=" + AD_Column_ID + " - " + item);
        return null;
    }
    MQuery query = new MQuery(format.getAD_Table_ID());
    query.addRestriction(item.getColumnName(), MQuery.EQUAL, new Integer(Record_ID));
    format.setTranslationViewQuery(query);
    log.fine(query.toString());
    //
    DataEngine de = new DataEngine(format.getLanguage(), m_TrxName);
    PrintData includedData = de.getPrintData(data.getCtx(), format, query);
    if (includedData == null)
        return null;
    data.addNode(includedData);
    log.fine(includedData.toString());
    //
    element = layoutTable(format, includedData, item.getXSpace());
    //	handle multi page tables
    if (element.getPageCount() > 1) {
        Point2D.Double loc = m_position[m_area];
        element.setLocation(loc);
        for (//	don't add last one
        int p = 1; //	don't add last one
        p < element.getPageCount(); //	don't add last one
        p++) {
            m_currPage.addElement(element);
            newPage(true, false);
        }
        m_position[m_area] = loc;
        ((TableElement) element).setHeightToLastPage();
    }
    m_lastWidth[m_area] = element.getWidth();
    m_lastHeight[m_area] = element.getHeight();
    if (!isXspaceFor(m_lastWidth[m_area])) {
        log.finest("Not enough X space for " + m_lastWidth[m_area] + " - remaining " + getXspace() + " - Area=" + m_area);
        newLine();
    }
    if (m_area == AREA_CONTENT && !isYspaceFor(m_lastHeight[m_area])) {
        log.finest("Not enough Y space " + m_lastHeight[m_area] + " - remaining " + getYspace() + " - Area=" + m_area);
        newPage(true, false);
    }
    //
    return element;
}
Also used : MQuery(org.compiere.model.MQuery) Point(java.awt.Point) PrinterException(java.awt.print.PrinterException) IOException(java.io.IOException) MPrintFormat(org.compiere.print.MPrintFormat) PrintDataElement(org.compiere.print.PrintDataElement) Point2D(java.awt.geom.Point2D) PrintData(org.compiere.print.PrintData) DataEngine(org.compiere.print.DataEngine)

Example 8 with MPrintFormat

use of org.compiere.print.MPrintFormat 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)

Example 9 with MPrintFormat

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

the class ReportEngineEx method createEXCEL_HTML.

//	createHTML
/**
	 * 	Write EXCEL HTML to writer
	 * 	@param writer writer
	 *  @param onlyTable if false create complete HTML document
	 *  @param language optional language - if null nubers/dates are not formatted
	 * 	@return true if success
	 */
public static boolean createEXCEL_HTML(ReportEngine re, Properties m_ctx, Writer writer, boolean onlyTable, Language language) {
    PrintData m_printData = re.getPrintData();
    MPrintFormat m_printFormat = re.getPrintFormat();
    ///Properties m_ctx = new Properties();
    MQuery m_query = re.getQuery();
    try {
        table table = new table();
        //	for all rows (-1 = header row)
        for (int row = -1; row < m_printData.getRowCount(); row++) {
            tr tr = new tr();
            table.addElement(tr);
            if (row != -1)
                m_printData.setRowIndex(row);
            //	for all columns
            for (int col = 0; col < m_printFormat.getItemCount(); col++) {
                MPrintFormatItem item = m_printFormat.getItem(col);
                if (item.isPrinted()) {
                    //	header row
                    if (row == -1) {
                        th th = new th();
                        tr.addElement(th);
                        th.addElement(Util.maskHTML(item.getPrintName(language)));
                        th.setClass("xl_head");
                    } else {
                        td td = new td();
                        tr.addElement(td);
                        Object obj = m_printData.getNode(new Integer(item.getAD_Column_ID()));
                        if (obj == null)
                            td.addElement("&nbsp;");
                        else if (obj instanceof PrintDataElement) {
                            //	formatted
                            String value = ((PrintDataElement) obj).getValueDisplay(null);
                            int displayType = ((PrintDataElement) obj).getDisplayType();
                            if (((PrintDataElement) obj).isNumeric()) {
                                if (displayType == DisplayType.Integer) {
                                    td.addAttribute("x:num", value);
                                    td.addElement(Util.maskHTML(value));
                                } else if (displayType == DisplayType.Quantity) {
                                    td.addAttribute("x:num", value);
                                    td.addElement(Util.maskHTML(value));
                                } else if (displayType == DisplayType.Amount) {
                                    td.addAttribute("x:num", value);
                                    td.addElement(Util.maskHTML(value));
                                } else if (displayType == DisplayType.CostPrice) {
                                    td.addAttribute("x:num", "");
                                    td.addAttribute("u1:num", value);
                                    td.setClass("xl25");
                                    td.addElement(Util.maskHTML(value));
                                } else //else if (displayType == DisplayType.YesNo)
                                //{
                                //}
                                //	if (displayType == Number)										
                                {
                                    td.addElement(Util.maskHTML(value));
                                }
                            } else if (((PrintDataElement) obj).isDate()) {
                                if (displayType == DisplayType.Date) {
                                    td.setClass("xl24");
                                    td.addElement(Util.maskHTML(value));
                                } else if (displayType == DisplayType.DateTime) {
                                    td.setClass("xl26");
                                    td.addElement(Util.maskHTML(value));
                                } else {
                                    td.addElement(Util.maskHTML(value));
                                }
                            } else
                                td.addElement(Util.maskHTML(value));
                        } else if (obj instanceof PrintData) {
                        //	ignore contained Data
                        } else
                            log.log(Level.SEVERE, "createHTML - Element not PrintData(Element) " + obj.getClass());
                    }
                }
            //	printed
            }
        //	for all columns
        }
        //	for all rows
        table table1 = new table();
        table1.setBorder(0).setCols(10).setCellPadding(0).setCellSpacing(2);
        table1.addElement(new tr().addElement(new td().setColSpan(10).addElement(new h1(re.getName())).setStyle("border:none;")));
        tr tr1;
        String tmp = "Jednostka: ";
        MOrg o = MOrg.get(m_ctx, Env.getAD_Org_ID(m_ctx));
        tmp += o.getName();
        tr1 = new tr();
        tr1.addElement(new td().addElement(tmp).setColSpan(10).setStyle("border:none;"));
        table1.addElement(tr1);
        java.text.DateFormat dateFormat = java.text.DateFormat.getDateInstance(java.text.DateFormat.FULL, new Locale("pl_PL"));
        String dateData = "Czas wygenerowania: " + dateFormat.format(new java.util.Date());
        tr1 = new tr();
        tr1.addElement(new td().addElement(dateData).setColSpan(10).setStyle("border:none;"));
        table1.addElement(tr1);
        for (int r = 0; r < m_query.getRestrictionCount(); r++) {
            tr1 = new tr();
            td td1 = new td().addElement(new i(m_query.getInfoName(r)));
            td1.addElement("   " + m_query.getInfoOperator(r) + "   " + m_query.getInfoDisplayAll(r)).setColSpan(10);
            td1.setStyle("border:none;");
            tr1.addElement(td1);
            table1.addElement(tr1);
        }
        tr1 = new tr();
        tr1.addElement(new td().addElement("&nbsp;").setColSpan(10).setStyle("border:none;height:20px;"));
        table1.addElement(tr1);
        //
        PrintWriter w = new PrintWriter(writer);
        if (onlyTable)
            table.output(w);
        else {
            XhtmlDocument doc = new XhtmlDocument();
            String st = "<!--table " + "	{mso-displayed-decimal-separator:\".\"; " + "	mso-displayed-thousand-separator:\" \";} " + "@page " + "	{margin:.98in .79in .98in .79in; " + "	mso-header-margin:.5in; " + "	mso-footer-margin:.5in;} " + "tr " + "	{mso-height-source:auto;} " + "col " + "	{mso-width-source:auto;} " + "br " + "	{mso-data-placement:same-cell;} " + ".style0 " + "	{mso-number-format:General; " + "	text-align:general; " + "	vertical-align:bottom; " + "	white-space:nowrap; " + "	mso-rotate:0; " + "	mso-background-source:auto; " + "	mso-pattern:auto; " + "	color:windowtext; " + "	font-size:10.0pt; " + "	font-weight:400; " + "	font-style:normal; " + "	text-decoration:none; " + "	font-family:Arial; " + "	mso-generic-font-family:auto; " + "	mso-font-charset:238; " + "	border:none; " + "	mso-protection:locked visible; " + "	mso-style-name:Normalny; " + "	mso-style-id:0;} " + "td " + "	{mso-style-parent:style0; " + "	padding-top:1px; " + "	padding-right:1px; " + "	padding-left:1px; " + "	mso-ignore:padding; " + "	color:windowtext; " + "	font-size:10.0pt; " + "	font-weight:400; " + "	font-style:normal; " + "	text-decoration:none; " + "	font-family:Arial; " + "	mso-generic-font-family:auto; " + "	mso-font-charset:238; " + "	mso-number-format:General; " + "	text-align:general; " + "	vertical-align:bottom; " + //"	border:none; "+
            "border:.5pt solid #a0a0a0; " + //windowtext
            "	mso-background-source:auto; " + "	mso-pattern:auto; " + "	mso-protection:locked visible; " + "	white-space:nowrap; " + "	mso-rotate:0;} " + ".xl24 " + "{mso-style-parent:style0; " + "mso-number-format:\"Short Date\";} " + ".xl25 " + "{mso-style-parent:style0; " + "mso-number-format:Fixed;} " + ".xl26 " + "{mso-style-parent:style0; " + "mso-number-format:\"yy\\/mm\\/dd\\ h\\:mm\\;\\@\";} " + ".xl_head " + "{text-align:center; mso-style-parent:style0; " + "font-weight:700; " + "font-family:Arial, sans-serif; " + "mso-font-charset:238; " + "border:.5pt solid windowtext; " + "background:silver; " + "mso-pattern:auto none;} " + "-->  ";
            doc.appendHead(new style().addElement(st));
            doc.appendBody(table1);
            doc.appendBody(table);
            doc.output(w);
        }
        w.flush();
        w.close();
    } catch (Exception e) {
        log.log(Level.SEVERE, "createHTML(w)", e);
    }
    return false;
}
Also used : Locale(java.util.Locale) org.apache.ecs.xhtml.h1(org.apache.ecs.xhtml.h1) XhtmlDocument(org.apache.ecs.XhtmlDocument) PrintData(org.compiere.print.PrintData) org.apache.ecs.xhtml.table(org.apache.ecs.xhtml.table) PrintWriter(java.io.PrintWriter) MPrintFormatItem(org.compiere.print.MPrintFormatItem) org.apache.ecs.xhtml.i(org.apache.ecs.xhtml.i) MQuery(org.compiere.model.MQuery) FileNotFoundException(java.io.FileNotFoundException) org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) MPrintFormat(org.compiere.print.MPrintFormat) MOrg(org.compiere.model.MOrg) org.apache.ecs.xhtml.th(org.apache.ecs.xhtml.th) PrintDataElement(org.compiere.print.PrintDataElement) org.apache.ecs.xhtml.style(org.apache.ecs.xhtml.style) org.apache.ecs.xhtml.tr(org.apache.ecs.xhtml.tr)

Example 10 with MPrintFormat

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

the class WReport method launchReport.

//	copyFormatFromClient
/**
	 * 	Launch Report
	 * 	@param pp Key=AD_PrintFormat_ID
	 */
private File launchReport(KeyNamePair pp, HttpServletRequest request, GridTab m_curTab, MQuery m_query) {
    WebSessionCtx wsc = WebSessionCtx.get(request);
    MPrintFormat pf = MPrintFormat.get(wsc.ctx, pp.getKey(), false);
    File file = launchReport(pf, request, m_curTab, m_query);
    return file;
}
Also used : MPrintFormat(org.compiere.print.MPrintFormat) WebSessionCtx(org.compiere.util.WebSessionCtx) File(java.io.File)

Aggregations

MPrintFormat (org.compiere.print.MPrintFormat)34 MQuery (org.compiere.model.MQuery)14 PrintInfo (org.compiere.model.PrintInfo)13 ReportEngine (org.compiere.print.ReportEngine)13 File (java.io.File)11 WebSessionCtx (org.compiere.util.WebSessionCtx)6 Language (org.compiere.util.Language)4 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 JasperPrint (net.sf.jasperreports.engine.JasperPrint)3 MTable (org.compiere.model.MTable)3 MPrintFormatItem (org.compiere.print.MPrintFormatItem)3 AdempiereUserError (org.compiere.util.AdempiereUserError)3 Locale (java.util.Locale)2 RowSet (javax.sql.RowSet)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 SimplePDFViewer (org.adempiere.webui.window.SimplePDFViewer)2 ADialogDialog (org.compiere.apps.ADialogDialog)2 MClient (org.compiere.model.MClient)2