Search in sources :

Example 1 with PrintInfo

use of org.compiere.model.PrintInfo 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 2 with PrintInfo

use of org.compiere.model.PrintInfo 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 3 with PrintInfo

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

the class ReportEngine method get.

/**************************************************************************
	 * 	Get Document Print Engine for Document Type.
	 * 	@param ctx context
	 * 	@param type document type
	 * 	@param Record_ID id
	 *  @param trxName
	 * 	@return Report Engine or null
	 */
public static ReportEngine get(Properties ctx, int type, int Record_ID, String trxName) {
    if (Record_ID < 1) {
        log.log(Level.WARNING, "No PrintFormat for Record_ID=" + Record_ID + ", Type=" + type);
        return null;
    }
    //	Order - Print Shipment or Invoice
    if (type == ORDER) {
        int[] what = getDocumentWhat(Record_ID);
        if (what != null) {
            type = what[0];
            Record_ID = what[1];
        }
    }
    //	Order
    int AD_PrintFormat_ID = 0;
    int C_BPartner_ID = 0;
    String DocumentNo = null;
    int copies = 1;
    //	Language
    MClient client = MClient.get(ctx);
    Language language = client.getLanguage();
    //	Get Document Info
    String sql = null;
    if (type == CHECK)
        sql = //	1
        "SELECT bad.Check_PrintFormat_ID," + //	2..5
        "	c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,d.DocumentNo " + "FROM C_PaySelectionCheck d" + " INNER JOIN C_PaySelection ps ON (d.C_PaySelection_ID=ps.C_PaySelection_ID)" + " INNER JOIN C_BankAccountDoc bad ON (ps.C_BankAccount_ID=bad.C_BankAccount_ID AND d.PaymentRule=bad.PaymentRule)" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID) " + //	info from BankAccount
        "WHERE d.C_PaySelectionCheck_ID=?";
    else if (type == HR_CHECK)
        sql = //	1
        "SELECT bad.Check_PrintFormat_ID," + //	2..5
        "	c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,d.DocumentNo " + "FROM HR_PaySelectionCheck d" + " INNER JOIN HR_PaySelection ps ON (d.HR_PaySelection_ID=ps.HR_PaySelection_ID)" + " INNER JOIN C_BankAccountDoc bad ON (ps.C_BankAccount_ID=bad.C_BankAccount_ID AND d.PaymentRule=bad.PaymentRule)" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID) " + //	info from BankAccount
        "WHERE d.HR_PaySelectionCheck_ID=?";
    else if (type == DUNNING)
        sql = "SELECT dl.Dunning_PrintFormat_ID," + " c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,dr.DunningDate " + "FROM C_DunningRunEntry d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID)" + " INNER JOIN C_DunningRun dr ON (d.C_DunningRun_ID=dr.C_DunningRun_ID)" + " INNER JOIN C_DunningLevel dl ON (dl.C_DunningLevel_ID=d.C_DunningLevel_ID) " + //	info from Dunning
        "WHERE d.C_DunningRunEntry_ID=?";
    else if (type == REMITTANCE)
        sql = "SELECT pf.Remittance_PrintFormat_ID," + " c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,d.DocumentNo " + "FROM C_PaySelectionCheck d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID) " + //	info from PrintForm
        "WHERE d.C_PaySelectionCheck_ID=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) ORDER BY pf.AD_Org_ID DESC";
    else if (type == HR_REMITTANCE)
        sql = "SELECT pf.Remittance_PrintFormat_ID," + " c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,d.DocumentNo " + "FROM HR_PaySelectionCheck d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID) " + //	info from PrintForm
        "WHERE d.HR_PaySelectionCheck_ID=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) ORDER BY pf.AD_Org_ID DESC";
    else if (type == PROJECT)
        sql = "SELECT pf.Project_PrintFormat_ID," + " c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,d.Value " + "FROM C_Project d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + " LEFT OUTER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID) " + //	info from PrintForm
        "WHERE d.C_Project_ID=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) ORDER BY pf.AD_Org_ID DESC";
    else if (type == MANUFACTURING_ORDER)
        sql = "SELECT pf.Manuf_Order_PrintFormat_ID," + " c.IsMultiLingualDocument,bp.AD_Language, 0 , d.DocumentNo " + "FROM PP_Order d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " LEFT OUTER JOIN AD_User u ON (u.AD_User_ID=d.Planner_ID)" + " LEFT OUTER JOIN C_BPartner bp ON (u.C_BPartner_ID=bp.C_BPartner_ID) " + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + //	info from PrintForm
        "WHERE d.PP_Order_ID=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) ORDER BY pf.AD_Org_ID DESC";
    else if (type == DISTRIBUTION_ORDER)
        sql = "SELECT pf.Distrib_Order_PrintFormat_ID," + " c.IsMultiLingualDocument,bp.AD_Language, bp.C_BPartner_ID , d.DocumentNo " + "FROM DD_Order d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + " LEFT OUTER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID) " + //	info from PrintForm
        "WHERE d.DD_Order_ID=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) ORDER BY pf.AD_Org_ID DESC";
    else if (type == RFQ)
        sql = "SELECT COALESCE(t.AD_PrintFormat_ID, pf.AD_PrintFormat_ID)," + " c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,rr.Name " + "FROM C_RfQResponse rr" + " INNER JOIN C_RfQ r ON (rr.C_RfQ_ID=r.C_RfQ_ID)" + " INNER JOIN C_RfQ_Topic t ON (r.C_RfQ_Topic_ID=t.C_RfQ_Topic_ID)" + " INNER JOIN AD_Client c ON (rr.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (rr.C_BPartner_ID=bp.C_BPartner_ID)," + " AD_PrintFormat pf " + "WHERE pf.AD_Client_ID IN (0,rr.AD_Client_ID)" + //	from RfQ PrintFormat
        " AND pf.AD_Table_ID=725 AND pf.IsTableBased='N'" + //	Info from RfQTopic
        " AND rr.C_RfQResponse_ID=? " + "ORDER BY t.AD_PrintFormat_ID, pf.AD_Client_ID DESC, pf.AD_Org_ID DESC";
    else // Fix [2574162] Priority to choose invoice print format not working
    if (type == ORDER || type == INVOICE)
        sql = //	1..2
        "SELECT pf.Order_PrintFormat_ID,pf.Shipment_PrintFormat_ID," + //	Prio: 1. BPartner 2. DocType, 3. PrintFormat (Org)	//	see InvoicePrint
        " COALESCE (bp.Invoice_PrintFormat_ID,dt.AD_PrintFormat_ID,pf.Invoice_PrintFormat_ID)," + // 3
        " pf.Project_PrintFormat_ID, pf.Remittance_PrintFormat_ID," + //	4..5
        " c.IsMultiLingualDocument, bp.AD_Language," + //	6..7
        " COALESCE(dt.DocumentCopies,0)+COALESCE(bp.DocumentCopies,1), " + // 	8
        " dt.AD_PrintFormat_ID,bp.C_BPartner_ID,d.DocumentNo " + //	9..11
        "FROM " + DOC_BASETABLES[type] + " d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID)" + " LEFT OUTER JOIN C_DocType dt ON ((d.C_DocType_ID>0 AND d.C_DocType_ID=dt.C_DocType_ID) OR (d.C_DocType_ID=0 AND d.C_DocTypeTarget_ID=dt.C_DocType_ID)) " + "WHERE d." + DOC_IDS[type] + //	info from PrintForm
        "=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) " + "ORDER BY pf.AD_Org_ID DESC";
    else
        //	Get PrintFormat from Org or 0 of document client
        sql = //	1..2
        "SELECT pf.Order_PrintFormat_ID,pf.Shipment_PrintFormat_ID," + //	Prio: 1. BPartner 2. DocType, 3. PrintFormat (Org)	//	see InvoicePrint
        " COALESCE (bp.Invoice_PrintFormat_ID,dt.AD_PrintFormat_ID,pf.Invoice_PrintFormat_ID)," + // 3
        " pf.Project_PrintFormat_ID, pf.Remittance_PrintFormat_ID," + //	4..5
        " c.IsMultiLingualDocument, bp.AD_Language," + //	6..7
        " COALESCE(dt.DocumentCopies,0)+COALESCE(bp.DocumentCopies,1), " + // 	8
        " dt.AD_PrintFormat_ID,bp.C_BPartner_ID,d.DocumentNo, " + //  9..11 
        " pf.Manuf_Order_PrintFormat_ID, pf.Distrib_Order_PrintFormat_ID " + //	12..13
        "FROM " + DOC_BASETABLES[type] + " d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID)" + " LEFT OUTER JOIN C_DocType dt ON (d.C_DocType_ID=dt.C_DocType_ID) " + "WHERE d." + DOC_IDS[type] + //	info from PrintForm
        "=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) " + "ORDER BY pf.AD_Org_ID DESC";
    //
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, trxName);
        pstmt.setInt(1, Record_ID);
        rs = pstmt.executeQuery();
        if (//	first record only
        rs.next()) {
            if (type == CHECK || type == HR_CHECK || type == DUNNING || type == REMITTANCE || type == HR_REMITTANCE || type == PROJECT || type == RFQ || type == MANUFACTURING_ORDER || type == DISTRIBUTION_ORDER) {
                AD_PrintFormat_ID = rs.getInt(1);
                copies = 1;
                //	Set Language when enabled
                String AD_Language = rs.getString(3);
                if (// && "Y".equals(rs.getString(2)))	//	IsMultiLingualDocument
                AD_Language != null)
                    language = Language.getLanguage(AD_Language);
                C_BPartner_ID = rs.getInt(4);
                if (type == DUNNING) {
                    Timestamp ts = rs.getTimestamp(5);
                    DocumentNo = ts.toString();
                } else
                    DocumentNo = rs.getString(5);
            } else {
                //	Set PrintFormat
                AD_PrintFormat_ID = rs.getInt(type + 1);
                if (//	C_DocType.AD_PrintFormat_ID
                type != INVOICE && rs.getInt(9) != 0)
                    AD_PrintFormat_ID = rs.getInt(9);
                copies = rs.getInt(8);
                //	Set Language when enabled
                String AD_Language = rs.getString(7);
                if (// && "Y".equals(rs.getString(6)))	//	IsMultiLingualDocument
                AD_Language != null)
                    language = Language.getLanguage(AD_Language);
                C_BPartner_ID = rs.getInt(10);
                DocumentNo = rs.getString(11);
            }
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "Record_ID=" + Record_ID + ", SQL=" + sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    if (AD_PrintFormat_ID == 0) {
        log.log(Level.SEVERE, "No PrintFormat found for Type=" + type + ", Record_ID=" + Record_ID);
        return null;
    }
    //	Get Format & Data
    MPrintFormat format = MPrintFormat.get(ctx, AD_PrintFormat_ID, false);
    //	BP Language if Multi-Lingual
    format.setLanguage(language);
    //	if (!Env.isBaseLanguage(language, DOC_TABLES[type]))
    format.setTranslationLanguage(language);
    //	query
    MQuery query = new MQuery(format.getAD_Table_ID());
    query.addRestriction(DOC_IDS[type], MQuery.EQUAL, Record_ID);
    //
    if (DocumentNo == null || DocumentNo.length() == 0)
        DocumentNo = "DocPrint";
    PrintInfo info = new PrintInfo(DocumentNo, DOC_TABLE_ID[type], Record_ID, C_BPartner_ID);
    info.setCopies(copies);
    //	true prints "Copy" on second
    info.setDocumentCopy(false);
    info.setPrinterName(format.getPrinterName());
    //	Engine
    ReportEngine re = new ReportEngine(ctx, format, query, info, trxName);
    return re;
}
Also used : PreparedStatement(java.sql.PreparedStatement) MQuery(org.compiere.model.MQuery) PrintInfo(org.compiere.model.PrintInfo) Timestamp(java.sql.Timestamp) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) IOException(java.io.IOException) MClient(org.compiere.model.MClient) Language(org.compiere.util.Language) ResultSet(java.sql.ResultSet)

Example 4 with PrintInfo

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

the class ReportEngine method main.

//	printConfirm
/*************************************************************************
	 * 	Test
	 * 	@param args args
	 */
public static void main(String[] args) {
    org.compiere.Adempiere.startupEnvironment(true);
    //
    int AD_Table_ID = 100;
    MQuery q = new MQuery("AD_Table");
    q.addRestriction("AD_Table_ID", "<", 108);
    //
    MPrintFormat f = MPrintFormat.createFromTable(Env.getCtx(), AD_Table_ID);
    PrintInfo i = new PrintInfo("test", AD_Table_ID, 108, 0);
    i.setAD_Table_ID(AD_Table_ID);
    ReportEngine re = new ReportEngine(Env.getCtx(), f, q, i);
    re.layout();
    /**
		re.createCSV(new File("C:\\Temp\\test.csv"), ',', Language.getLanguage());
		re.createHTML(new File("C:\\Temp\\test.html"), false, Language.getLanguage());
		re.createXML(new File("C:\\Temp\\test.xml"));
		re.createPS(new File ("C:\\Temp\\test.ps"));
		re.createPDF(new File("C:\\Temp\\test.pdf"));
		/****/
    re.print();
    //	re.print(true, 1, false, "Epson Stylus COLOR 900 ESC/P 2");		//	Dialog
    //	re.print(true, 1, false, "HP LaserJet 3300 Series PCL 6");		//	Dialog
    //	re.print(false, 1, false, "Epson Stylus COLOR 900 ESC/P 2");	//	Dialog
    System.exit(0);
}
Also used : MQuery(org.compiere.model.MQuery) PrintInfo(org.compiere.model.PrintInfo)

Example 5 with PrintInfo

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

the class ServerReportCtl method startStandardReport.

/**************************************************************************
	 *	Start Standard Report.
	 *  - Get Table Info & submit.<br>
	 *  A report can be created from:
	 *  <ol>
	 *  <li>attached MPrintFormat, if any (see {@link ProcessInfo#setTransientObject(Object)}, {@link ProcessInfo#setSerializableObject(java.io.Serializable)}
	 *  <li>process information (AD_Process.AD_PrintFormat_ID, AD_Process.AD_ReportView_ID)
	 *  </ol>
	 * @param processInfo
	 * @return true if OK
     */
public static boolean startStandardReport(ProcessInfo processInfo) {
    ReportEngine re = null;
    //
    // Create Report Engine by using attached MPrintFormat (if any)
    Object o = processInfo.getTransientObject();
    if (o == null)
        o = processInfo.getSerializableObject();
    if (o != null && o instanceof MPrintFormat) {
        Properties ctx = Env.getCtx();
        MPrintFormat format = (MPrintFormat) o;
        String TableName = MTable.getTableName(ctx, format.getAD_Table_ID());
        MQuery query = MQuery.get(ctx, processInfo.getAD_PInstance_ID(), TableName);
        PrintInfo info = new PrintInfo(processInfo);
        re = new ReportEngine(ctx, format, query, info);
        createOutput(re, null);
        return true;
    } else //
    // Create Report Engine normally
    {
        re = ReportEngine.get(Env.getCtx(), processInfo);
        if (re == null) {
            processInfo.setSummary("No ReportEngine");
            return false;
        }
    }
    createOutput(re, null);
    return true;
}
Also used : MQuery(org.compiere.model.MQuery) PrintInfo(org.compiere.model.PrintInfo) Properties(java.util.Properties)

Aggregations

PrintInfo (org.compiere.model.PrintInfo)26 MQuery (org.compiere.model.MQuery)19 ReportEngine (org.compiere.print.ReportEngine)15 MPrintFormat (org.compiere.print.MPrintFormat)14 File (java.io.File)7 SQLException (java.sql.SQLException)6 Language (org.compiere.util.Language)6 IOException (java.io.IOException)5 FileInputStream (java.io.FileInputStream)4 ProcessInfo (org.compiere.process.ProcessInfo)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 JasperPrint (net.sf.jasperreports.engine.JasperPrint)3 ADialogDialog (org.compiere.apps.ADialogDialog)3 MClient (org.compiere.model.MClient)3 MTable (org.compiere.model.MTable)3 Viewer (org.compiere.print.Viewer)3 PrinterJob (java.awt.print.PrinterJob)2 MalformedURLException (java.net.MalformedURLException)2 Connection (java.sql.Connection)2