Search in sources :

Example 1 with MQuery

use of org.compiere.model.MQuery 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 MQuery

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

the class WReport method doGet.

//  init
/**
	 * Process the HTTP Get request
	 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    log.fine("doGet");
    log.info(response.toString());
    WebSessionCtx wsc = WebSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    m_curTab = ws.curTab;
    //
    WebDoc doc = null;
    File file = null;
    if (ws == null) {
        doc = WebDoc.createPopup("No Context");
        doc.addPopupClose(wsc.ctx);
    } else /**else if (fileName!=null)
		{			
			int AD_PInstance_ID = WebUtil.getParameterAsInt(request, "AD_PInstance_ID");
			File file = new File (fileName);
			String error = WebUtil.streamFile(response, file);
			if (error == null)
				return;
			doc = WebDoc.createWindow(error);
		}**/
    {
        log.info("");
        if (!MRole.getDefault().isCanReport(ws.curTab.getAD_Table_ID())) {
            doc = WebDoc.createPopup("Access Cannot Report");
            doc.addPopupClose(wsc.ctx);
        }
        //	Query
        MQuery query = new MQuery(m_curTab.getTableName());
        //	Link for detail records
        String queryColumn = m_curTab.getLinkColumnName();
        //	Current row otherwise
        if (queryColumn.length() == 0)
            queryColumn = m_curTab.getKeyColumnName();
        //	Find display
        String infoName = null;
        String infoDisplay = null;
        for (int i = 0; i < m_curTab.getFieldCount(); i++) {
            GridField field = m_curTab.getField(i);
            if (field.isKey())
                infoName = field.getHeader();
            if ((field.getColumnName().equals("Name") || field.getColumnName().equals("DocumentNo")) && field.getValue() != null)
                infoDisplay = field.getValue().toString();
            if (infoName != null && infoDisplay != null)
                break;
        }
        if (queryColumn.length() != 0) {
            if (queryColumn.endsWith("_ID"))
                query.addRestriction(queryColumn, MQuery.EQUAL, new Integer(Env.getContextAsInt(wsc.ctx, m_curTab.getWindowNo(), queryColumn)), infoName, infoDisplay);
            else
                query.addRestriction(queryColumn, MQuery.EQUAL, Env.getContext(wsc.ctx, m_curTab.getWindowNo(), queryColumn), infoName, infoDisplay);
        }
        file = getPrintFormats(m_curTab.getAD_Table_ID(), request, m_curTab, query);
        String error = WebUtil.streamFile(response, file);
        if (error == null)
            return;
        doc = WebDoc.createWindow(error);
    }
    //
    WebUtil.createResponse(request, response, this, null, doc, false);
}
Also used : WebDoc(org.compiere.util.WebDoc) MQuery(org.compiere.model.MQuery) GridField(org.compiere.model.GridField) WebSessionCtx(org.compiere.util.WebSessionCtx) File(java.io.File)

Example 3 with MQuery

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

the class AbstractADWindowPanel method onReport.

/**
     * @see ToolbarListener#onReport()
     */
public void onReport() {
    GridTab currentTab = toolbar.getCurrentPanel().getGridTab();
    if (!MRole.getDefault().isCanReport(currentTab.getAD_Table_ID())) {
        FDialog.error(curWindowNo, parent, "AccessCannotReport");
        return;
    }
    if (!onSave(false))
        return;
    //	Query
    //MQuery query = curTabx.getQuery() ; //  new MQuery(curTabx.getTableName());
    //  new MQuery(curTabx.getTableName());
    MQuery oldQuery = currentTab.getQuery();
    MQuery query = new MQuery(currentTab.getTableName());
    try {
        query = oldQuery.deepCopy();
    } catch (Exception e) {
        query = oldQuery;
        e.printStackTrace();
    }
    if (currentTab.getWhereClause() != null) {
        if (currentTab.getWhereClause().length() > 0)
            query.addRestriction(Env.parseContext(ctx, curWindowNo, currentTab.getWhereClause(), false));
    }
    //	Link for detail records
    String queryColumn = currentTab.getLinkColumnName();
    //	Current row otherwise
    if (queryColumn.length() == 0)
        queryColumn = currentTab.getKeyColumnName();
    //	Find display
    String infoName = null;
    String infoDisplay = null;
    for (int i = 0; i < currentTab.getFieldCount(); i++) {
        GridField field = currentTab.getField(i);
        if (field.isKey())
            infoName = field.getHeader();
        if ((field.getColumnName().equals("Name") || field.getColumnName().equals("DocumentNo")) && field.getValue() != null)
            infoDisplay = field.getValue().toString();
        if (infoName != null && infoDisplay != null)
            break;
    }
    if (queryColumn.length() != 0) {
        if (queryColumn.endsWith("_ID"))
            query.addRestriction(queryColumn, MQuery.EQUAL, new Integer(Env.getContextAsInt(ctx, curWindowNo, queryColumn)), infoName, infoDisplay);
        else
            query.addRestriction(queryColumn, MQuery.EQUAL, Env.getContext(ctx, curWindowNo, queryColumn), infoName, infoDisplay);
    }
    new WReport(currentTab.getAD_Table_ID(), query, toolbar.getEvent().getTarget(), curWindowNo);
}
Also used : WReport(org.adempiere.webui.apps.WReport) GridTab(org.compiere.model.GridTab) MQuery(org.compiere.model.MQuery) GridField(org.compiere.model.GridField) ApplicationException(org.adempiere.webui.exception.ApplicationException)

Example 4 with MQuery

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

the class InfoAssetPanel method zoom.

// saveSelectionDetail
// Elaine 2008/12/16
/**
	 *	Zoom
	 */
public void zoom(int record_id) {
    log.info("InfoAsset.zoom");
    Integer A_Asset_ID = record_id;
    if (A_Asset_ID == null)
        return;
    MQuery query = new MQuery("A_Asset");
    query.addRestriction("A_Asset_ID", MQuery.EQUAL, A_Asset_ID);
    query.setRecordCount(1);
    int AD_WindowNo = getAD_Window_ID("A_Asset", true);
    AEnv.zoom(AD_WindowNo, query);
}
Also used : MQuery(org.compiere.model.MQuery)

Example 5 with MQuery

use of org.compiere.model.MQuery 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)

Aggregations

MQuery (org.compiere.model.MQuery)118 PrintInfo (org.compiere.model.PrintInfo)19 GridField (org.compiere.model.GridField)17 MPrintFormat (org.compiere.print.MPrintFormat)14 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)13 ReportEngine (org.compiere.print.ReportEngine)12 Point (java.awt.Point)11 SQLException (java.sql.SQLException)9 GridWindowVO (org.compiere.model.GridWindowVO)9 AWindow (org.compiere.apps.AWindow)8 GridTab (org.compiere.model.GridTab)8 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 GridWindow (org.compiere.model.GridWindow)7 ValueNamePair (org.compiere.util.ValueNamePair)6 File (java.io.File)5 IOException (java.io.IOException)5 KeyNamePair (org.compiere.util.KeyNamePair)4 Language (org.compiere.util.Language)4 Component (java.awt.Component)3