Search in sources :

Example 11 with MQuery

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

the class WGenForm method onPrint.

public void onPrint() {
    //		Loop through all items
    List<File> pdfList = new ArrayList<File>();
    for (int i = 0; i < m_ids.length; i++) {
        int RecordID = m_ids[i];
        ReportEngine re = null;
        if (genForm.getPrintFormat() != null) {
            MPrintFormat format = genForm.getPrintFormat();
            MTable table = MTable.get(Env.getCtx(), format.getAD_Table_ID());
            MQuery query = new MQuery(table.getTableName());
            query.addRestriction(table.getTableName() + "_ID", MQuery.EQUAL, RecordID);
            //	Engine
            PrintInfo info = new PrintInfo(table.getTableName(), table.get_Table_ID(), RecordID);
            re = new ReportEngine(Env.getCtx(), format, query, info);
        } else {
            re = ReportEngine.get(Env.getCtx(), genForm.getReportEngineType(), RecordID);
        }
        if (re != null)
            pdfList.add(re.getPDF());
    }
    if (pdfList.size() > 1) {
        try {
            File outFile = File.createTempFile(genForm.getClass().getName(), ".pdf");
            AEnv.mergePdf(pdfList, outFile);
            Clients.clearBusy();
            Window win = new SimplePDFViewer(getFormName(), new FileInputStream(outFile));
            SessionManager.getAppDesktop().showWindow(win, "center");
        } catch (Exception e) {
            log.log(Level.SEVERE, e.getLocalizedMessage(), e);
        }
    } else if (pdfList.size() > 0) {
        Clients.clearBusy();
        try {
            Window win = new SimplePDFViewer(getFormName(), new FileInputStream(pdfList.get(0)));
            SessionManager.getAppDesktop().showWindow(win, "center");
        } catch (Exception e) {
            log.log(Level.SEVERE, e.getLocalizedMessage(), e);
        }
    }
}
Also used : Window(org.adempiere.webui.component.Window) SimplePDFViewer(org.adempiere.webui.window.SimplePDFViewer) ArrayList(java.util.ArrayList) MQuery(org.compiere.model.MQuery) PrintInfo(org.compiere.model.PrintInfo) FileInputStream(java.io.FileInputStream) ReportEngine(org.compiere.print.ReportEngine) MPrintFormat(org.compiere.print.MPrintFormat) MTable(org.compiere.model.MTable) File(java.io.File)

Example 12 with MQuery

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

the class DunningPrint method doIt.

//	prepare
/**
	 * Process
	 * @return info
	 * @throws Exception
	 */
protected String doIt() throws Exception {
    log.info("C_DunningRun_ID=" + p_C_DunningRun_ID + ",R_MailText_ID=" + p_R_MailText_ID + ", EmailPDF=" + p_EMailPDF + ",IsOnlyIfBPBalance=" + p_IsOnlyIfBPBalance + ",PrintUnprocessedOnly=" + p_PrintUnprocessedOnly);
    //	Need to have Template
    if (p_EMailPDF && p_R_MailText_ID == 0)
        throw new AdempiereUserError("@NotFound@: @R_MailText_ID@");
    //		String subject = "";
    MMailText mText = null;
    if (p_EMailPDF) {
        mText = new MMailText(getCtx(), p_R_MailText_ID, get_TrxName());
        if (p_EMailPDF && mText.get_ID() == 0)
            throw new AdempiereUserError("@NotFound@: @R_MailText_ID@ - " + p_R_MailText_ID);
    //			subject = mText.getMailHeader();
    }
    //
    MDunningRun run = new MDunningRun(getCtx(), p_C_DunningRun_ID, get_TrxName());
    if (run.get_ID() == 0)
        throw new AdempiereUserError("@NotFound@: @C_DunningRun_ID@ - " + p_C_DunningRun_ID);
    MClient client = MClient.get(getCtx());
    int count = 0;
    int errors = 0;
    MDunningRunEntry[] entries = run.getEntries(false);
    for (int i = 0; i < entries.length; i++) {
        MDunningRunEntry entry = entries[i];
        //	Print Format on Dunning Level
        MDunningLevel level = new MDunningLevel(getCtx(), entry.getC_DunningLevel_ID(), get_TrxName());
        MPrintFormat format = null;
        if (level.getDunning_PrintFormat_ID() > 0)
            format = MPrintFormat.get(getCtx(), level.getDunning_PrintFormat_ID(), false);
        if (p_IsOnlyIfBPBalance && entry.getAmt().signum() <= 0)
            continue;
        if (p_PrintUnprocessedOnly && entry.isProcessed())
            continue;
        //	To BPartner
        MBPartner bp = new MBPartner(getCtx(), entry.getC_BPartner_ID(), get_TrxName());
        if (bp.get_ID() == 0) {
            addLog(entry.get_ID(), null, null, "@NotFound@: @C_BPartner_ID@ " + entry.getC_BPartner_ID());
            errors++;
            continue;
        }
        //	To User
        MUser to = new MUser(getCtx(), entry.getAD_User_ID(), get_TrxName());
        if (p_EMailPDF) {
            if (to.get_ID() == 0) {
                addLog(entry.get_ID(), null, null, "@NotFound@: @AD_User_ID@ - " + bp.getName());
                errors++;
                continue;
            } else if (to.getEMail() == null || to.getEMail().length() == 0) {
                addLog(entry.get_ID(), null, null, "@NotFound@: @EMail@ - " + to.getName());
                errors++;
                continue;
            }
        }
        //	query
        MQuery query = new MQuery("C_Dunning_Header_v");
        query.addRestriction("C_DunningRunEntry_ID", MQuery.EQUAL, new Integer(entry.getC_DunningRunEntry_ID()));
        //	Engine
        PrintInfo info = new PrintInfo(bp.getName(), MDunningRunEntry.Table_ID, entry.getC_DunningRunEntry_ID(), entry.getC_BPartner_ID());
        info.setDescription(bp.getName() + ", Amt=" + entry.getAmt());
        ReportEngine re = null;
        if (format != null)
            re = new ReportEngine(getCtx(), format, query, info);
        boolean printed = false;
        if (p_EMailPDF) {
            EMail email = client.createEMail(to.getEMail(), null, null);
            if (!email.isValid()) {
                addLog(entry.get_ID(), null, null, "@RequestActionEMailError@ Invalid EMail: " + to);
                errors++;
                continue;
            }
            //	variable context
            mText.setUser(to);
            mText.setBPartner(bp);
            mText.setPO(entry);
            String message = mText.getMailText(true);
            if (mText.isHtml())
                email.setMessageHTML(mText.getMailHeader(), message);
            else {
                email.setSubject(mText.getMailHeader());
                email.setMessageText(message);
            }
            //
            if (re != null) {
                File attachment = re.getPDF(File.createTempFile("Dunning", ".pdf"));
                log.fine(to + " - " + attachment);
                email.addAttachment(attachment);
            }
            //
            String msg = email.send();
            MUserMail um = new MUserMail(mText, entry.getAD_User_ID(), email);
            um.saveEx();
            if (msg.equals(EMail.SENT_OK)) {
                addLog(entry.get_ID(), null, null, bp.getName() + " @RequestActionEMailOK@");
                count++;
                printed = true;
            } else {
                addLog(entry.get_ID(), null, null, bp.getName() + " @RequestActionEMailError@ " + msg);
                errors++;
            }
        } else {
            if (re != null) {
                re.print();
                count++;
                printed = true;
            }
        }
        if (printed) {
            entry.setProcessed(true);
            entry.save();
        }
    }
    //	for all dunning letters
    if (errors == 0) {
        run.setProcessed(true);
        run.saveEx();
    }
    if (p_EMailPDF)
        return "@Sent@=" + count + " - @Errors@=" + errors;
    return "@Printed@=" + count;
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) MMailText(org.compiere.model.MMailText) MUserMail(org.compiere.model.MUserMail) MQuery(org.compiere.model.MQuery) PrintInfo(org.compiere.model.PrintInfo) MDunningRun(org.compiere.model.MDunningRun) MBPartner(org.compiere.model.MBPartner) EMail(org.compiere.util.EMail) MClient(org.compiere.model.MClient) MDunningRunEntry(org.compiere.model.MDunningRunEntry) MPrintFormat(org.compiere.print.MPrintFormat) ReportEngine(org.compiere.print.ReportEngine) MUser(org.compiere.model.MUser) File(java.io.File) MDunningLevel(org.compiere.model.MDunningLevel)

Example 13 with MQuery

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

the class VAccountDialog method initAccount.

//	jbInit
/**
	 *	Dyanmic Init.
	 *  When a row is selected, the editor values are set
	 *  (editors do not change grid)
	 *  @return true if initialized
	 */
private boolean initAccount() {
    m_AD_Client_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_Client_ID");
    //	Get AcctSchema Info
    if (s_AcctSchema == null || s_AcctSchema.getC_AcctSchema_ID() != m_C_AcctSchema_ID)
        s_AcctSchema = new MAcctSchema(Env.getCtx(), m_C_AcctSchema_ID, null);
    log.config(s_AcctSchema.toString() + ", #" + s_AcctSchema.getAcctSchemaElements().length);
    Env.setContext(Env.getCtx(), m_WindowNo, "C_AcctSchema_ID", m_C_AcctSchema_ID);
    //  Model
    //	Maintain Account Combinations 
    int AD_Window_ID = 153;
    GridWindowVO wVO = AEnv.getMWindowVO(m_WindowNo, AD_Window_ID, 0);
    if (wVO == null)
        return false;
    m_mWindow = new GridWindow(wVO);
    m_mTab = m_mWindow.getTab(0);
    // Make sure is the tab is loaded - teo_sarca [ 1659124 ]
    if (!m_mTab.isLoadComplete())
        m_mWindow.initTab(0);
    //  ParameterPanel restrictions
    m_mTab.getField("Alias").setDisplayLength(15);
    m_mTab.getField("Combination").setDisplayLength(15);
    //  Grid restrictions
    m_mTab.getField("AD_Client_ID").setDisplayed(false);
    m_mTab.getField("C_AcctSchema_ID").setDisplayed(false);
    m_mTab.getField("IsActive").setDisplayed(false);
    m_mTab.getField("IsFullyQualified").setDisplayed(false);
    //  don't show fields not being displayed in this environment
    for (int i = 0; i < m_mTab.getFieldCount(); i++) {
        GridField field = m_mTab.getField(i);
        if (//  check context
        !field.isDisplayed(true))
            field.setDisplayed(false);
    }
    //  GridController
    m_gridController = new GridController();
    m_gridController.initGrid(m_mTab, true, m_WindowNo, null, null);
    m_gridController.setPreferredSize(new Dimension(300, 100));
    panel.add(m_gridController, BorderLayout.CENTER);
    //  Prepare Parameter
    m_gbc.anchor = GridBagConstraints.NORTHWEST;
    //	line
    m_gbc.gridy = 0;
    m_gbc.gridx = 0;
    m_gbc.gridwidth = 1;
    m_gbc.insets = m_fieldInsets;
    m_gbc.fill = GridBagConstraints.HORIZONTAL;
    m_gbc.weightx = 0;
    m_gbc.weighty = 0;
    int TabNo = 0;
    //	Alias
    if (s_AcctSchema.isHasAlias()) {
        GridField alias = m_mTab.getField("Alias");
        f_Alias = VEditorFactory.getEditor(m_mTab, alias, false);
        addLine(alias, f_Alias, false);
    }
    //	Alias
    //	Combination
    GridField combination = m_mTab.getField("Combination");
    f_Combination = VEditorFactory.getEditor(m_mTab, combination, false);
    addLine(combination, f_Combination, false);
    m_newRow = true;
    /**
		 *	Create Fields in Element Order
		 */
    MAcctSchemaElement[] elements = s_AcctSchema.getAcctSchemaElements();
    for (int i = 0; i < elements.length; i++) {
        MAcctSchemaElement ase = elements[i];
        String type = ase.getElementType();
        boolean isMandatory = ase.isMandatory();
        //
        if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Organization)) {
            GridField field = m_mTab.getField("AD_Org_ID");
            f_AD_Org_ID = VEditorFactory.getEditor(m_mTab, field, false);
            addLine(field, f_AD_Org_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Account)) {
            GridField field = m_mTab.getField("Account_ID");
            f_Account_ID = VEditorFactory.getEditor(m_mTab, field, false);
            //	((VLookup)f_Account_ID).setWidth(400);
            addLine(field, f_Account_ID, isMandatory);
            f_Account_ID.addVetoableChangeListener(this);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount)) {
            GridField field = m_mTab.getField("C_SubAcct_ID");
            f_SubAcct_ID = VEditorFactory.getEditor(m_mTab, field, false);
            //	((VLookup)f_SubAcct_ID).setWidth(400);
            addLine(field, f_SubAcct_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Product)) {
            GridField field = m_mTab.getField("M_Product_ID");
            f_M_Product_ID = VEditorFactory.getEditor(m_mTab, field, false);
            addLine(field, f_M_Product_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_BPartner)) {
            GridField field = m_mTab.getField("C_BPartner_ID");
            f_C_BPartner_ID = VEditorFactory.getEditor(m_mTab, field, false);
            addLine(field, f_C_BPartner_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Campaign)) {
            GridField field = m_mTab.getField("C_Campaign_ID");
            f_C_Campaign_ID = VEditorFactory.getEditor(m_mTab, field, false);
            addLine(field, f_C_Campaign_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationFrom)) {
            GridField field = m_mTab.getField("C_LocFrom_ID");
            f_C_LocFrom_ID = VEditorFactory.getEditor(m_mTab, field, false);
            addLine(field, f_C_LocFrom_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationTo)) {
            GridField field = m_mTab.getField("C_LocTo_ID");
            f_C_LocTo_ID = VEditorFactory.getEditor(m_mTab, field, false);
            addLine(field, f_C_LocTo_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Project)) {
            GridField field = m_mTab.getField("C_Project_ID");
            f_C_Project_ID = VEditorFactory.getEditor(m_mTab, field, false);
            addLine(field, f_C_Project_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SalesRegion)) {
            GridField field = m_mTab.getField("C_SalesRegion_ID");
            f_C_SalesRegion_ID = VEditorFactory.getEditor(m_mTab, field, false);
            addLine(field, f_C_SalesRegion_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_OrgTrx)) {
            GridField field = m_mTab.getField("AD_OrgTrx_ID");
            f_AD_OrgTrx_ID = VEditorFactory.getEditor(m_mTab, field, false);
            addLine(field, f_AD_OrgTrx_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Activity)) {
            GridField field = m_mTab.getField("C_Activity_ID");
            f_C_Activity_ID = VEditorFactory.getEditor(m_mTab, field, false);
            addLine(field, f_C_Activity_ID, isMandatory);
        } else //	User1
        if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList1)) {
            GridField field = m_mTab.getField("User1_ID");
            f_User1_ID = VEditorFactory.getEditor(m_mTab, field, false);
            GridFieldVO newFieldVO = f_User1_ID.getField().getVO();
            newFieldVO.Header = f_User1_ID.getName();
            field = new GridField(newFieldVO);
            addLine(field, f_User1_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList2)) {
            GridField field = m_mTab.getField("User2_ID");
            f_User2_ID = VEditorFactory.getEditor(m_mTab, field, false);
            GridFieldVO newFieldVO = f_User2_ID.getField().getVO();
            newFieldVO.Header = f_User2_ID.getName();
            field = new GridField(newFieldVO);
            addLine(field, f_User2_ID, isMandatory);
        } else //	User3
        if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList3)) {
            GridField field = m_mTab.getField("User3_ID");
            f_User3_ID = VEditorFactory.getEditor(m_mTab, field, false);
            GridFieldVO newFieldVO = f_User3_ID.getField().getVO();
            newFieldVO.Header = f_User3_ID.getName();
            field = new GridField(newFieldVO);
            addLine(field, f_User3_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList4)) {
            GridField field = m_mTab.getField("User4_ID");
            f_User4_ID = VEditorFactory.getEditor(m_mTab, field, false);
            GridFieldVO newFieldVO = f_User4_ID.getField().getVO();
            newFieldVO.Header = f_User4_ID.getName();
            field = new GridField(newFieldVO);
            addLine(field, f_User4_ID, isMandatory);
        }
    }
    //	Create Fields in Element Order
    //	Add description
    m_newRow = true;
    m_gbc.gridy = m_line++;
    m_gbc.gridx = 0;
    m_gbc.gridwidth = 4;
    // 	top,left,bottom,right
    m_gbc.insets = new Insets(5, 15, 2, 0);
    m_gbc.fill = GridBagConstraints.HORIZONTAL;
    f_Description.setFont(f_Description.getFont().deriveFont(Font.ITALIC));
    parameterPanel.add(f_Description, m_gbc);
    //	Finish
    m_query = new MQuery();
    m_query.addRestriction("C_AcctSchema_ID", MQuery.EQUAL, m_C_AcctSchema_ID);
    m_query.addRestriction("IsFullyQualified", MQuery.EQUAL, "Y");
    if (m_mAccount.C_ValidCombination_ID == 0)
        m_mTab.setQuery(MQuery.getEqualQuery("1", "2"));
    else {
        MQuery query = new MQuery();
        query.addRestriction("C_AcctSchema_ID", MQuery.EQUAL, m_C_AcctSchema_ID);
        query.addRestriction("C_ValidCombination_ID", MQuery.EQUAL, m_mAccount.C_ValidCombination_ID);
        m_mTab.setQuery(query);
    }
    m_mTab.query(false);
    m_gridController.getTable().addMouseListener(new VAccountDialog_mouseAdapter(this));
    m_gridController.addDataStatusListener(this);
    statusBar.setStatusLine(s_AcctSchema.toString());
    statusBar.setStatusDB("?");
    //	Initial value
    if (m_mAccount.C_ValidCombination_ID != 0)
        m_mTab.navigate(0);
    log.config("fini");
    return true;
}
Also used : Insets(java.awt.Insets) GridWindow(org.compiere.model.GridWindow) GridFieldVO(org.compiere.model.GridFieldVO) MQuery(org.compiere.model.MQuery) GridField(org.compiere.model.GridField) Dimension(java.awt.Dimension) MAcctSchema(org.compiere.model.MAcctSchema) GridWindowVO(org.compiere.model.GridWindowVO) GridController(org.compiere.grid.GridController) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Example 14 with MQuery

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

the class VChart method chartMouseClicked.

@Override
public void chartMouseClicked(ChartMouseEvent event) {
    if ((event.getEntity() != null) && (event.getTrigger().getClickCount() > 1)) {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        try {
            ChartEntity entity = event.getEntity();
            String key = null;
            String seriesName = null;
            if (entity instanceof CategoryItemEntity) {
                CategoryItemEntity item = ((CategoryItemEntity) entity);
                Comparable<?> colKey = item.getColumnKey();
                Comparable<?> rowKey = item.getRowKey();
                if (colKey != null && rowKey != null) {
                    key = colKey.toString();
                    seriesName = rowKey.toString();
                }
            } else if (entity instanceof PieSectionEntity) {
                Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
                if (sectionKey != null) {
                    key = sectionKey.toString();
                }
            }
            if (entity instanceof XYItemEntity) {
                XYItemEntity item = ((XYItemEntity) entity);
                if (item.getDataset() instanceof TimeSeriesCollection) {
                    TimeSeriesCollection data = (TimeSeriesCollection) item.getDataset();
                    TimeSeries series = data.getSeries(item.getSeriesIndex());
                    TimeSeriesDataItem dataitem = series.getDataItem(item.getItem());
                    seriesName = series.getKey().toString();
                    key = dataitem.getPeriod().toString();
                }
            }
            if (key == null)
                return;
            MQuery query = chartModel.getQuery(seriesName == null ? key : seriesName + "__" + key);
            if (query != null)
                AEnv.zoom(query);
        } finally {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    }
}
Also used : XYItemEntity(org.jfree.chart.entity.XYItemEntity) TimeSeries(org.jfree.data.time.TimeSeries) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem) MQuery(org.compiere.model.MQuery) ChartEntity(org.jfree.chart.entity.ChartEntity) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity)

Example 15 with MQuery

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

the class ADServiceImpl method getWindowTabData.

public WindowTabDataDocument getWindowTabData(WindowTabDataReqDocument reqd) throws XFireFault {
    authenticate(webServiceName, "getWindowTabData");
    WindowTabDataReq req = reqd.getWindowTabDataReq();
    WindowTabDataDocument ret = WindowTabDataDocument.Factory.newInstance();
    WindowTabData wd = ret.addNewWindowTabData();
    DataSet ds = wd.addNewDataSet();
    WWindowStatus ws = WWindowStatus.get(WindowStatusMap, req.getWindowNo(), false, 0, false, 0);
    if (ws == null) {
        GridWindowVO wo = getWindowVO(req.getWindowNo(), req.getADWindowID(), req.getADMenuID());
        ws = new WWindowStatus(wo);
        WindowStatusMap.put(new Integer(req.getWindowNo()), ws);
        //!!!!!!!!!!
        ws.curTab.query(ws.mWindow.isTransaction());
        ws.curTab.navigate(0);
        ws.curTab.setSingleRow(true);
    }
    if (ws.curTab.getTabNo() != req.getPrevTabNo()) {
        ws.curTab.removeDataStatusListener(ws.ads);
        ws.curTab = ws.mWindow.getTab(req.getPrevTabNo());
        // false
        ws.curTab.query(ws.mWindow.isTransaction());
        ws.curTab.navigate(0);
        ws.updateRecIDMap();
    }
    /*
    	if (ws.curTab.getCurrentRow() != req.getPrevRecNo())  
    	{
    		if (req.getPrevRecNo() >=0)
    			ws.curTab.navigate( req.getPrevRecNo() );     		
    	}
    	*/
    // we assume that it RecordID
    int prevRecNo = ws.getRowNoFromRecordID(req.getPrevRecNo());
    if (ws.curTab.getCurrentRow() != prevRecNo) {
        if (prevRecNo >= 0)
            ws.curTab.navigate(prevRecNo);
    }
    WWindowStatus.changeTabIfNeeded(ws, req.getTabNo());
    if (req.getGetData()) {
        if (req.getFromZoom()) {
            WWindowStatus ws2 = WWindowStatus.get(WindowStatusMap, req.getFromZoomWindowID(), true, req.getFromZoomTabID(), true, req.getFromZoomRowID());
            System.out.println(ws2.curTab.getTableName());
            GridField field = ws2.curTab.getField(req.getFromZoomColumnName());
            ws2 = null;
            if (field == null)
                return null;
            MLookup lookup = (MLookup) field.getLookup();
            if (lookup == null)
                return null;
            //
            MQuery zoomQuery = lookup.getZoomQuery();
            Object value = field.getValue();
            if (value == null) {
                value = req.getFromZoomColumnValue();
            }
            //	If not already exist or exact value
            if (zoomQuery == null || value != null) {
                //	ColumnName might be changed in GridTab.validateQuery
                zoomQuery = new MQuery();
                zoomQuery.addRestriction(req.getFromZoomColumnName(), MQuery.EQUAL, value);
            }
            ws.curTab.setQuery(zoomQuery);
            //ws.curTab.query(ws.mWindow.isTransaction());
            // ADEMPIERE/COMPIERE
            // adempiere
            ws.curTab.query(false, 0, 0);
        //ws.curTab.query(false, 0); // compiere
        } else {
            DataRow findDR = req.getFindCriteria();
            MQuery currentQuery = ws.curTab.getQuery();
            MQuery newQuery = createQuery(ws.curTab.getTableName(), findDR);
            if (findDR.getFieldArray().length > 0) {
                //(!currentQuery.getWhereClause().equals( newQuery.getWhereClause() )) { // change the query for zak�adki
                ws.curTab.setQuery(newQuery);
                //ws.curTab.query(ws.mWindow.isTransaction());
                //ADEMPIERE/COMPIERE
                // adempiere
                ws.curTab.query(false, 0, 0);
            //ws.curTab.query(false, 0); // compiere
            }
        }
        int rc = 0;
        if (req.getRowCount() > 0)
            rc = req.getRowCount();
        else
            rc = ws.curTab.getRowCount();
        int initRowNo = 0;
        if (req.getRowStart() > 0)
            initRowNo = req.getRowStart();
        //ok
        int lastRow = Math.min(rc, initRowNo + MAX_ROWS);
        //initRowNo + 5; // only for testing
        wd.setNumRows(lastRow);
        //lastRow += initRowNo;
        // ok
        wd.setTotalRows(ws.curTab.getRowCount());
        //wd.setTotalRows( 5 ); // only for testing
        wd.setStartRow(initRowNo);
        Map<Integer, Integer> RecordIDMap = ws.getRecordIDMap();
        try {
            RecordIDMap.clear();
            for (int lineNo = initRowNo; lineNo < lastRow; lineNo++) {
                ws.curTab.navigate(lineNo);
                int recID = ws.curTab.getRecord_ID();
                RecordIDMap.put(recID, lineNo);
                DataRow dr = ds.addNewDataRow();
                //System.out.println("row "+lineNo);
                fillDataRow(dr, ws, false, false);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        ;
        if (lastRow <= ws.curTab.getRowCount()) {
            //last row
            ws.updateRecIDMap();
        }
    }
    return ret;
}
Also used : DataSet(pl.x3E.adInterface.DataSet) MLookup(org.compiere.model.MLookup) WindowTabData(pl.x3E.adInterface.WindowTabData) MQuery(org.compiere.model.MQuery) GridField(org.compiere.model.GridField) DataRow(pl.x3E.adInterface.DataRow) TransformerException(javax.xml.transform.TransformerException) WindowTabDataDocument(pl.x3E.adInterface.WindowTabDataDocument) WindowTabDataReq(pl.x3E.adInterface.WindowTabDataReq) GridWindowVO(org.compiere.model.GridWindowVO)

Aggregations

MQuery (org.compiere.model.MQuery)109 PrintInfo (org.compiere.model.PrintInfo)19 GridField (org.compiere.model.GridField)15 MPrintFormat (org.compiere.print.MPrintFormat)14 ReportEngine (org.compiere.print.ReportEngine)12 Point (java.awt.Point)11 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)9 GridWindowVO (org.compiere.model.GridWindowVO)9 SQLException (java.sql.SQLException)8 GridTab (org.compiere.model.GridTab)8 GridWindow (org.compiere.model.GridWindow)7 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 AWindow (org.compiere.apps.AWindow)6 File (java.io.File)5 IOException (java.io.IOException)5 Language (org.compiere.util.Language)4 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MClient (org.compiere.model.MClient)3 MLookup (org.compiere.model.MLookup)3