Search in sources :

Example 36 with MColumn

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

the class ADSortTab method getIdentifier.

//	dynInit
/**
	 * get Identifier
	 * @param tableName
	 * @param columnName
	 * @param AD_Column_ID
	 * @param isTranslated
	 * @return Sql
	 */
private String getIdentifier(String tableName, String columnName, Integer AD_Column_ID, boolean isTranslated) {
    Language language = Language.getLanguage(Env.getAD_Language(Env.getCtx()));
    StringBuilder sql = new StringBuilder("");
    MColumn column = MColumn.get(Env.getCtx(), AD_Column_ID);
    if (DisplayType.TableDir == column.getAD_Reference_ID() || DisplayType.Search == column.getAD_Reference_ID())
        sql.append("(").append(MLookupFactory.getLookup_TableDirEmbed(language, columnName, "t")).append(")");
    else if (DisplayType.Table == column.getAD_Reference_ID())
        sql.append("(").append(MLookupFactory.getLookup_TableEmbed(language, column.getColumnName(), "t", column.getAD_Reference_Value_ID())).append(")");
    else if (DisplayType.List == column.getAD_Reference_ID())
        sql.append("(").append(MLookupFactory.getLookup_ListEmbed(language, column.getAD_Reference_Value_ID(), columnName)).append(")");
    else
        sql.append(isTranslated ? "tt." : "t.").append(columnName);
    return sql.toString();
}
Also used : MColumn(org.compiere.model.MColumn) Language(org.compiere.util.Language)

Example 37 with MColumn

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

the class WFieldRecordInfo 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 38 with MColumn

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

the class ImportInventoryMove method getInventoryMovementLine.

/**
	 * get MMovementLine unique instance based on  X_I_Movement data
	 * @param movement MMovement
	 * @param movementImport X_I_Movement
	 * @return  unique instance of MMovementLine
	 */
private MMovementLine getInventoryMovementLine(MMovement movement, X_I_Movement movementImport) {
    final StringBuilder whereClause = new StringBuilder();
    ArrayList<Object> parameters = new ArrayList();
    MColumn[] columns = getInventoryMovementColumns();
    int count = 0;
    for (MColumn column : columns) {
        if (X_I_Movement.COLUMNNAME_AD_Org_ID.equals(column.getColumnName()) || X_I_Movement.COLUMNNAME_M_Product_ID.equals(column.getColumnName()) || X_I_Movement.COLUMNNAME_M_Locator_ID.equals(column.getColumnName()) || X_I_Movement.COLUMNNAME_M_LocatorTo_ID.equals(column.getColumnName())) {
            whereClause.append(column.getColumnName()).append("=?");
            parameters.add(movementImport.get_Value(column.getColumnName()));
            if (count < 3) {
                whereClause.append(" AND ");
                count++;
            }
        }
    }
    whereClause.append(" AND M_Movement_ID=?");
    parameters.add(movement.getM_Movement_ID());
    return new Query(getCtx(), I_M_MovementLine.Table_Name, whereClause.toString(), get_TrxName()).setClient_ID().setParameters(parameters).first();
}
Also used : MColumn(org.compiere.model.MColumn) Query(org.compiere.model.Query) ArrayList(java.util.ArrayList)

Example 39 with MColumn

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

the class ExportFormatGenerator method createFormat.

//	doIt
private String createFormat(MTable table) throws SQLException {
    log.info("Table Name:" + table.getTableName());
    MColumn[] columns = table.getColumns(true);
    String unique = null;
    boolean isFieldName = false;
    for (MColumn column : columns) {
        if (column.isIdentifier() && column.getSeqNo() == 1) {
            unique = column.getColumnName();
            if (unique.equals("Name"))
                isFieldName = true;
            log.info("Unique Key" + unique);
            break;
        }
    }
    if (unique == null)
        unique = "Name";
    MEXPFormat format = null;
    //String formatValue = table.getTableName()+"_"+unique;
    String formatValue = table.getTableName();
    log.info("Export Format Value:" + formatValue);
    format = (MEXPFormat) exportFormats.get(formatValue);
    if (format != null)
        return format.getValue();
    String where = " value = ? ";
    Query sql = new Query(getCtx(), I_EXP_Format.Table_Name, where, get_TrxName()).setParameters(formatValue);
    if (sql.match()) {
        format = (MEXPFormat) sql.first();
        exportFormats.put(format.getValue(), format);
        return format.getValue();
    }
    format = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(getCtx(), formatValue, getAD_Client_ID(), version, get_TrxName());
    if (format == null)
        format = new MEXPFormat(getCtx(), 0, get_TrxName());
    format.setAD_Org_ID(0);
    format.setValue(formatValue);
    format.setName(table.getName());
    format.setAD_Table_ID(table.getAD_Table_ID());
    format.setDescription(table.getDescription());
    format.setHelp(table.getHelp());
    format.setVersion(version);
    format.saveEx();
    if (format != null)
        exportFormats.put(format.getValue(), format);
    int position = 10;
    for (MColumn column : columns) {
        if (iscludesonlythemandatorycolumns()) {
            if (column.isMandatory())
                createFormatLine(format, table, column, position, false);
        } else
            createFormatLine(format, table, column, position, false);
        position++;
    }
    return format.getValue();
}
Also used : MColumn(org.compiere.model.MColumn) MEXPFormat(org.compiere.model.MEXPFormat) Query(org.compiere.model.Query)

Example 40 with MColumn

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

the class Browser method getMQuery.

/**
	 * Get Query from Record Identifier
	 * @return
	 */
public MQuery getMQuery(IBrowserTable browseTable) {
    Integer record_ID = getSelectedRowKey(browseTable);
    if (record_ID == null)
        return null;
    MBrowseField fieldKey = getFieldKey();
    if (fieldKey == null)
        return null;
    MColumn column = fieldKey.getAD_View_Column().getAD_Column();
    String keyColumn = MQuery.getZoomColumnName(column.getColumnName());
    String tableName = column.getAD_Table().getTableName();
    MQuery query = new MQuery(tableName);
    query.addRestriction(keyColumn, MQuery.EQUAL, record_ID);
    return query;
}
Also used : MColumn(org.compiere.model.MColumn) MBrowseField(org.adempiere.model.MBrowseField) MQuery(org.compiere.model.MQuery)

Aggregations

MColumn (org.compiere.model.MColumn)40 MTable (org.compiere.model.MTable)15 SQLException (java.sql.SQLException)11 BigDecimal (java.math.BigDecimal)9 AdempiereException (org.adempiere.exceptions.AdempiereException)7 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 Query (org.compiere.model.Query)6 MEXPFormat (org.compiere.model.MEXPFormat)5 Timestamp (java.sql.Timestamp)4 ArrayList (java.util.ArrayList)4 Vector (java.util.Vector)4 MEXPFormatLine (org.compiere.model.MEXPFormatLine)4 MLookup (org.compiere.model.MLookup)4 MUser (org.compiere.model.MUser)4 DBException (org.adempiere.exceptions.DBException)3 MField (org.compiere.model.MField)3 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2