Search in sources :

Example 41 with MLookup

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

the class WOrderReceiptIssue method fillPicks.

//	init
/**
	 *	Fill Picks
	 *		Column_ID from C_Order
	 *	This is only run as part of the windows initialization process
	 *  @throws Exception if Lookups cannot be initialized
	 */
private void fillPicks() throws Exception {
    Properties ctx = Env.getCtx();
    // Base Language
    Language language = Language.getLoginLanguage();
    MLookup orderLookup = MLookupFactory.get(ctx, m_WindowNo, MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_PP_Order_ID), DisplayType.Search, language, "PP_Order_ID", 0, false, "PP_Order.DocStatus = '" + MPPOrder.DOCACTION_Complete + "'");
    orderField = new WSearchEditor(MPPOrder.COLUMNNAME_PP_Order_ID, false, false, true, orderLookup);
    orderField.addValueChangeListener(this);
    MLookup resourceLookup = MLookupFactory.get(ctx, m_WindowNo, 0, MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_S_Resource_ID), DisplayType.TableDir);
    resourceField = new WSearchEditor(MPPOrder.COLUMNNAME_S_Resource_ID, false, false, false, resourceLookup);
    MLookup warehouseLookup = MLookupFactory.get(ctx, m_WindowNo, 0, MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_M_Warehouse_ID), DisplayType.TableDir);
    warehouseField = new WSearchEditor(MPPOrder.COLUMNNAME_M_Warehouse_ID, false, false, false, warehouseLookup);
    MLookup productLookup = MLookupFactory.get(ctx, m_WindowNo, 0, MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_M_Product_ID), DisplayType.TableDir);
    productField = new WSearchEditor(MPPOrder.COLUMNNAME_M_Product_ID, false, false, false, productLookup);
    MLookup uomLookup = MLookupFactory.get(ctx, m_WindowNo, 0, MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_C_UOM_ID), DisplayType.TableDir);
    uomField = new WSearchEditor(MPPOrder.COLUMNNAME_C_UOM_ID, false, false, false, uomLookup);
    MLookup uomOrderLookup = MLookupFactory.get(ctx, m_WindowNo, 0, MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_C_UOM_ID), DisplayType.TableDir);
    uomorderField = new WSearchEditor(MPPOrder.COLUMNNAME_C_UOM_ID, false, false, false, uomOrderLookup);
    MLocatorLookup locatorL = new MLocatorLookup(ctx, m_WindowNo);
    locatorField = new WLocatorEditor(MLocator.COLUMNNAME_M_Locator_ID, true, false, true, locatorL, m_WindowNo);
    //  Tab, Window
    int m_Window = MWindow.getWindow_ID("Manufacturing Order");
    GridFieldVO vo = GridFieldVO.createStdField(ctx, m_WindowNo, 0, m_Window, MTab.getTab_ID(m_Window, "Manufacturing Order"), false, false, false);
    vo.AD_Column_ID = MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_M_AttributeSetInstance_ID);
    vo.ColumnName = MPPOrder.COLUMNNAME_M_AttributeSetInstance_ID;
    vo.displayType = DisplayType.PAttribute;
    GridField field = new GridField(vo);
    // M_AttributeSetInstance_ID
    attribute = new WPAttributeEditor(field.getGridTab(), field);
    attribute.setReadWrite(true);
    attribute.setValue(0);
    // 4Layers - Further init
    scrapQtyField.setValue(Env.ZERO);
    rejectQty.setValue(Env.ZERO);
    // 4Layers - end
    pickcombo.appendItem(Msg.parseTranslation(Env.getCtx(), "@IsBackflush@"), 1);
    pickcombo.appendItem(Msg.parseTranslation(Env.getCtx(), "@OnlyIssue@"), 2);
    pickcombo.appendItem(Msg.parseTranslation(Env.getCtx(), "@OnlyReceiptProduct@"), 3);
    pickcombo.addEventListener(Events.ON_CHANGE, this);
    Process.addActionListener(this);
    toDeliverQty.addValueChangeListener(this);
    scrapQtyField.addValueChangeListener(this);
}
Also used : MLocatorLookup(org.compiere.model.MLocatorLookup) WLocatorEditor(org.adempiere.webui.editor.WLocatorEditor) Language(org.compiere.util.Language) GridFieldVO(org.compiere.model.GridFieldVO) MLookup(org.compiere.model.MLookup) WSearchEditor(org.adempiere.webui.editor.WSearchEditor) GridField(org.compiere.model.GridField) Properties(java.util.Properties) WPAttributeEditor(org.adempiere.webui.editor.WPAttributeEditor)

Example 42 with MLookup

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

the class FieldRecordInfo method addLine.

//	dynInit
/**
	 * 	Add Line
	 *	@param AD_Column_ID column
	 *	@param Updated updated
	 *	@param UpdatedBy user
	 *	@param OldValue old
	 *	@param NewValue new
	 */
private void addLine(int AD_Column_ID, Timestamp Updated, int UpdatedBy, String OldValue, String NewValue) {
    Vector<String> line = new Vector<String>();
    //	Column
    MColumn column = MColumn.get(Env.getCtx(), AD_Column_ID);
    //
    if (OldValue != null && OldValue.equals(MChangeLog.NULL))
        OldValue = null;
    String showOldValue = OldValue;
    if (NewValue != null && NewValue.equals(MChangeLog.NULL))
        NewValue = null;
    String showNewValue = NewValue;
    //
    try {
        if (DisplayType.isText(column.getAD_Reference_ID()))
            ;
        else if (column.getAD_Reference_ID() == DisplayType.YesNo) {
            if (OldValue != null) {
                boolean yes = OldValue.equals("true") || OldValue.equals("Y");
                showOldValue = Msg.getMsg(Env.getCtx(), yes ? "Y" : "N");
            }
            if (NewValue != null) {
                boolean yes = NewValue.equals("true") || NewValue.equals("Y");
                showNewValue = Msg.getMsg(Env.getCtx(), yes ? "Y" : "N");
            }
        } else if (column.getAD_Reference_ID() == DisplayType.Amount) {
            if (OldValue != null)
                showOldValue = m_amtFormat.format(new BigDecimal(OldValue));
            if (NewValue != null)
                showNewValue = m_amtFormat.format(new BigDecimal(NewValue));
        } else if (column.getAD_Reference_ID() == DisplayType.Integer) {
            if (OldValue != null)
                showOldValue = m_intFormat.format(new Integer(OldValue));
            if (NewValue != null)
                showNewValue = m_intFormat.format(new Integer(NewValue));
        } else if (DisplayType.isNumeric(column.getAD_Reference_ID())) {
            if (OldValue != null)
                showOldValue = m_numberFormat.format(new BigDecimal(OldValue));
            if (NewValue != null)
                showNewValue = m_numberFormat.format(new BigDecimal(NewValue));
        } else if (column.getAD_Reference_ID() == DisplayType.Date) {
            if (OldValue != null)
                showOldValue = m_dateFormat.format(Timestamp.valueOf(OldValue));
            if (NewValue != null)
                showNewValue = m_dateFormat.format(Timestamp.valueOf(NewValue));
        } else if (column.getAD_Reference_ID() == DisplayType.DateTime) {
            if (OldValue != null)
                showOldValue = m_dateTimeFormat.format(Timestamp.valueOf(OldValue));
            if (NewValue != null)
                showNewValue = m_dateTimeFormat.format(Timestamp.valueOf(NewValue));
        } else if (DisplayType.isLookup(column.getAD_Reference_ID())) {
            MLookup lookup = MLookupFactory.get(Env.getCtx(), 0, AD_Column_ID, column.getAD_Reference_ID(), Env.getLanguage(Env.getCtx()), column.getColumnName(), column.getAD_Reference_Value_ID(), column.isParent(), null);
            if (OldValue != null) {
                Object key = OldValue;
                NamePair pp = lookup.get(key);
                if (pp != null)
                    showOldValue = pp.getName();
            }
            if (NewValue != null) {
                Object key = NewValue;
                NamePair pp = lookup.get(key);
                if (pp != null)
                    showNewValue = pp.getName();
            }
        } else if (DisplayType.isLOB(column.getAD_Reference_ID()))
            ;
    } catch (Exception e) {
        log.log(Level.WARNING, OldValue + "->" + NewValue, e);
    }
    //
    line.add(showNewValue);
    line.add(showOldValue);
    //	UpdatedBy
    MUser user = MUser.get(Env.getCtx(), UpdatedBy);
    line.add(user.getName());
    //	Updated
    line.add(m_dateFormat.format(Updated));
    m_data.add(line);
}
Also used : MColumn(org.compiere.model.MColumn) MLookup(org.compiere.model.MLookup) NamePair(org.compiere.util.NamePair) Vector(java.util.Vector) MUser(org.compiere.model.MUser) BigDecimal(java.math.BigDecimal)

Example 43 with MLookup

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

the class CollectDetail method getCreditMemoLockup.

/**
	 * Get Credit Memo 
	 * @author Dixon Martinez, dmartinez@erpcya.com, ERPCyA http://www.erpcya.com
	 * @param p_C_BPartner_ID
	 * @return
	 * @return MLookup
	 */
protected MLookup getCreditMemoLockup(int p_C_BPartner_ID) {
    MLookup lookup = null;
    //
    //	RV_OpenItem C_Invoice_ID
    int AD_Column_ID = 12349;
    //	Where Clause
    String whereClause = "IsPaid='N' and Processed='Y' and C_BPartner_ID= " + p_C_BPartner_ID + " and exists ( select 1 from C_DocType C_DocType where C_DocType.DocBaseType ='ARC' " + "	and C_Invoice.C_DocTypeTarget_ID = C_DocType.C_DocType_ID)";
    try {
        lookup = MLookupFactory.get(Env.getCtx(), 0, AD_Column_ID, DisplayType.TableDir, Env.getLanguage(Env.getCtx()), MInvoice.COLUMNNAME_C_Invoice_ID, 0, false, whereClause);
    } catch (Exception e) {
    }
    //
    return lookup;
}
Also used : MLookup(org.compiere.model.MLookup)

Example 44 with MLookup

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

the class ADLookup method getDirectAccessSQL.

//	actionText	
/**
	 * 	Generate Access SQL for Search.
	 * 	The SQL returns the ID of the value entered
	 * 	Also sets m_tableName and m_keyColumnName
	 *	@param text uppercase text for LIKE comparison
	 *	@return sql or ""
	 *  Example
	 *	SELECT C_Payment_ID FROM C_Payment WHERE UPPER(DocumentNo) LIKE x OR ...
	 */
private String getDirectAccessSQL(String text) {
    //Tutaj trzeba doda� dodatkowe pole dla odpowiednich typ�w wyszukiwania w selectach
    StringBuffer sql = new StringBuffer();
    // without _ID
    m_tableName = m_columnName.substring(0, m_columnName.length() - 3);
    m_keyColumnName = m_columnName;
    if (m_columnName.equals("C_Invoice_ID")) {
        sql.append("SELECT C_Invoice_ID, DocumentNo FROM C_Invoice WHERE UPPER(DocumentNo) LIKE ").append(DB.TO_STRING(text));
    } else if (m_columnName.equals("M_InOut_ID")) {
        sql.append("SELECT M_InOut_ID, '' FROM M_InOut WHERE UPPER(DocumentNo) LIKE ").append(DB.TO_STRING(text));
    } else if (m_columnName.equals("C_Payment_ID")) {
        sql.append("SELECT C_Payment_ID, DocumentNo FROM C_Payment WHERE UPPER(DocumentNo) LIKE ").append(DB.TO_STRING(text));
    } else if (m_columnName.equals("GL_JournalBatch_ID")) {
        sql.append("SELECT GL_JournalBatch_ID, '' FROM GL_JournalBatch WHERE UPPER(DocumentNo) LIKE ").append(DB.TO_STRING(text));
    } else if (m_columnName.equals("SalesRep_ID")) {
        sql.append("SELECT AD_User_ID, NAME FROM AD_User WHERE UPPER(Name) LIKE ").append(DB.TO_STRING(text));
        m_tableName = "AD_User";
        m_keyColumnName = "AD_User_ID";
    }
    //	Predefined
    if (sql.length() > 0) {
        String wc = getWhereClause();
        if (wc != null && wc.length() > 0)
            sql.append(" AND ").append(wc);
        sql.append(" AND IsActive='Y'");
        if (DB.isOracle())
            sql.append(" AND ROWNUM < " + MAX_PRODUCT_ROWS + " ");
        //	***
        //log.finest("(predefined) " + sql.toString());
        String sqlret = MRole.getDefault().addAccessSQL(sql.toString(), m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
        if (DB.isPostgreSQL())
            sqlret = sqlret + " LIMIT " + MAX_PRODUCT_ROWS;
        return sqlret;
    }
    // TODO  dorobic obsluge where z ad_ref_table !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    if (m_lookup != null && m_lookup instanceof MLookup) {
        int AD_Reference_ID = ((MLookup) m_lookup).getAD_Reference_Value_ID();
        if (AD_Reference_ID != 0) {
            String query = "SELECT kc.ColumnName, dc.ColumnName, t.TableName " + "FROM AD_Ref_Table rt" + " INNER JOIN AD_Column kc ON (rt.AD_Key=kc.AD_Column_ID)" + " INNER JOIN AD_Column dc ON (rt.AD_Display=dc.AD_Column_ID)" + " INNER JOIN AD_Table t ON (rt.AD_Table_ID=t.AD_Table_ID) " + "WHERE rt.AD_Reference_ID=?";
            String displayColumnName = null;
            PreparedStatement pstmt = null;
            try {
                pstmt = DB.prepareStatement(query);
                pstmt.setInt(1, AD_Reference_ID);
                ResultSet rs = pstmt.executeQuery();
                if (rs.next()) {
                    m_keyColumnName = rs.getString(1);
                    displayColumnName = rs.getString(2);
                    m_tableName = rs.getString(3);
                }
                rs.close();
                pstmt.close();
                pstmt = null;
            } catch (Exception e) {
            //log.log(Level.SEVERE, "getDirectAccessSQL", e);
            }
            try {
                if (pstmt != null)
                    pstmt.close();
                pstmt = null;
            } catch (Exception e) {
                pstmt = null;
            }
            if (displayColumnName != null) {
                sql = new StringBuffer();
                // kolec  - bylo m_displayColumnName
                sql.append("SELECT ").append(m_keyColumnName).append(", " + displayColumnName).append(" FROM ").append(m_tableName).append(" WHERE UPPER(").append(displayColumnName).append(") LIKE ").append(DB.TO_STRING(text)).append(" AND IsActive='Y'");
                if (DB.isOracle())
                    sql.append(" AND ROWNUM < " + MAX_PRODUCT_ROWS + " ");
                String wc = getWhereClause();
                if (wc != null && wc.length() > 0)
                    sql.append(" AND ").append(wc);
                //	***
                //log.finest("(Table) " + sql.toString());
                String sqlret = MRole.getDefault().addAccessSQL(sql.toString(), m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
                if (DB.isPostgreSQL())
                    sqlret = sqlret + " LIMIT " + MAX_PRODUCT_ROWS;
                return sqlret;
            }
        }
    //	Table Reference
    }
    //	MLookup
    /** Check Well Known Columns of Table - assumes TableDir	**/
    String query = "SELECT t.TableName, c.ColumnName " + "FROM AD_Column c " + " INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID AND t.IsView='N') " + "WHERE (c.ColumnName IN ('DocumentNo', 'Value', 'Name') OR c.IsIdentifier='Y')" + " AND c.AD_Reference_ID IN (10,14)" + " AND EXISTS (SELECT * FROM AD_Column cc WHERE cc.AD_Table_ID=t.AD_Table_ID" + " AND cc.IsKey='Y' AND cc.ColumnName=?)";
    m_keyColumnName = m_columnName;
    sql = new StringBuffer();
    PreparedStatement pstmt = null;
    try {
        pstmt = DB.prepareStatement(query);
        pstmt.setString(1, m_keyColumnName);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            if (sql.length() != 0)
                sql.append(" OR ");
            m_tableName = rs.getString(1);
            sql.append("UPPER(").append(rs.getString(2)).append(") LIKE ").append(DB.TO_STRING(text));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (SQLException ex) {
        log.log(Level.SEVERE, "getDirectAccessSQL", ex);
    }
    try {
        if (pstmt != null)
            pstmt.close();
    } catch (SQLException ex1) {
    }
    pstmt = null;
    //
    if (sql.length() == 0) {
        log.log(Level.SEVERE, "(TableDir) - no standard/identifier columns");
        return "";
    }
    //
    StringBuffer retValue = new StringBuffer("SELECT ").append(m_columnName).append(" , NAME").append(" FROM ").append(m_tableName).append(" WHERE ").append(sql).append(" AND IsActive='Y' ");
    if (DB.isOracle())
        retValue.append(" AND ROWNUM < " + MAX_PRODUCT_ROWS + " ");
    String wc = getWhereClause();
    if (wc != null && wc.length() > 0)
        retValue.append(" AND ").append(wc);
    //	***
    log.finest("(TableDir) " + sql.toString());
    String sqlret = MRole.getDefault().addAccessSQL(retValue.toString(), m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    if (DB.isPostgreSQL())
        sqlret = sqlret + " LIMIT " + MAX_PRODUCT_ROWS;
    return sqlret;
}
Also used : SQLException(java.sql.SQLException) MLookup(org.compiere.model.MLookup) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 45 with MLookup

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

the class WCollectDetail method loadStandardPanel.

/**
	 * Load standard Panel
	 * @return void
	 */
public void loadStandardPanel() {
    v_StandarPanel = GridFactory.newGridLayout();
    v_StandarPanel.setWidth("100%");
    v_StandarPanel.setHeight("75px");
    groupPanel.appendChild(v_StandarPanel);
    Rows rows = null;
    Row row = null;
    rows = v_StandarPanel.newRows();
    row = rows.newRow();
    // Payment type selection
    //C_Payment_v.TenderType
    int AD_Column_ID = 8416;
    MLookup lookup = MLookupFactory.get(Env.getCtx(), 0, 0, AD_Column_ID, DisplayType.List);
    ArrayList<Object> types = lookup.getData(true, false, true, true);
    bMinus = v_Parent.createButtonAction("Minus", KeyStroke.getKeyStroke(KeyEvent.VK_F3, Event.F3));
    bMinus.addActionListener(this);
    row.setHeight("55px");
    fTenderType = ListboxFactory.newDropdownListbox();
    fTenderType.addActionListener(this);
    int pos = 0;
    // default to cash payment
    for (Object obj : types) {
        if (obj instanceof ValueNamePair) {
            ValueNamePair key = (ValueNamePair) obj;
            fTenderType.appendItem(key.getName(), key);
            if (key.getID().equals(getTenderType())) {
                fTenderType.setSelectedIndex(pos);
            }
            pos++;
        }
    }
    fTenderType.setStyle(HEIGHT + WIDTH + FONT_SIZE);
    row.appendChild(fTenderType);
    Label lPayAmt = new Label(Msg.translate(p_ctx, "PayAmt"));
    lPayAmt.setWidth("225px");
    fPayAmt = new POSNumberBox(false);
    row.appendChild(fPayAmt);
    row.appendChild(bMinus);
    fPayAmt.setValue(new BigDecimal("0.0"));
    fPayAmt.setStyle("text-align:right;" + HEIGHT + WIDTH + FONT_SIZE);
    fPayAmt.addEventListener("onBlur", this);
    fPayAmt.addEventListener(Events.ON_CHANGING, this);
    fPayAmt.addEventListener(Events.ON_CHANGE, this);
}
Also used : MLookup(org.compiere.model.MLookup) Label(org.adempiere.webui.component.Label) Row(org.adempiere.webui.component.Row) ValueNamePair(org.compiere.util.ValueNamePair) BigDecimal(java.math.BigDecimal) Rows(org.adempiere.webui.component.Rows)

Aggregations

MLookup (org.compiere.model.MLookup)62 VLookup (org.compiere.grid.ed.VLookup)25 WSearchEditor (org.adempiere.webui.editor.WSearchEditor)17 Properties (java.util.Properties)14 SQLException (java.sql.SQLException)9 WTableDirEditor (org.adempiere.webui.editor.WTableDirEditor)9 KeyNamePair (org.compiere.util.KeyNamePair)9 Language (org.compiere.util.Language)7 MLocatorLookup (org.compiere.model.MLocatorLookup)6 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 Dimension (java.awt.Dimension)4 Insets (java.awt.Insets)4 BigDecimal (java.math.BigDecimal)4 Row (org.adempiere.webui.component.Row)4 Rows (org.adempiere.webui.component.Rows)4 GridField (org.compiere.model.GridField)4 MColumn (org.compiere.model.MColumn)4 CPanel (org.compiere.swing.CPanel)4 GridBagConstraints (java.awt.GridBagConstraints)3