Search in sources :

Example 11 with MColumn

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

the class CalloutBPartnerLocation method formatPhone.

/**
	 *	Format Phone No based on Country.
	 *  Called from C_BPartnerLocation.C_Location_ID
	 *
	 *  @param ctx      Context
	 *  @param WindowNo current Window No
	 *  @param mTab     Model Tab
	 *  @param mField   Model Field
	 *  @param value    The new value
	 *  @param oldvalue The old value
	 *  @return Error message or ""
	 */
public String formatPhone(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value, Object oldValue) {
    log.info("");
    // Called from C_Location_ID field
    Integer location_int = (Integer) mField.getValue();
    String phone_frm = null;
    if (location_int != null)
        // take the phone format from country
        phone_frm = DB.getSQLValueString(null, "SELECT ExpressionPhone FROM C_Country c, C_Location l WHERE c.C_Country_ID = l.C_Country_ID AND l.C_location_ID = ?", location_int);
    GridField fPhone = mTab.getField(MBPartnerLocation.COLUMNNAME_Phone);
    MColumn colPhone = null;
    if (fPhone != null)
        colPhone = MColumn.get(Env.getCtx(), fPhone.getAD_Column_ID());
    GridField fPhone2 = mTab.getField(MBPartnerLocation.COLUMNNAME_Phone2);
    MColumn colPhone2 = null;
    if (fPhone2 != null)
        colPhone2 = MColumn.get(Env.getCtx(), fPhone2.getAD_Column_ID());
    GridField fFax = mTab.getField(MBPartnerLocation.COLUMNNAME_Fax);
    MColumn colFax = null;
    if (fFax != null)
        colFax = MColumn.get(Env.getCtx(), fFax.getAD_Column_ID());
    // Apply the country format if the column doesn't have format
    if (colPhone != null && (colPhone.getVFormat() == null || colPhone.getVFormat().length() == 0))
        fPhone.setVFormat(phone_frm);
    if (colPhone2 != null && (colPhone2.getVFormat() == null || colPhone2.getVFormat().length() == 0))
        fPhone2.setVFormat(phone_frm);
    if (colFax != null && (colFax.getVFormat() == null || colFax.getVFormat().length() == 0))
        fFax.setVFormat(phone_frm);
    return "";
}
Also used : MColumn(org.compiere.model.MColumn) GridField(org.compiere.model.GridField)

Example 12 with MColumn

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

the class Browser method getAxisSQLWhere.

/**
	 * Get SQL where for axis
	 * @param viewColumn
	 * @return
	 */
public String getAxisSQLWhere(I_AD_View_Column viewColumn) {
    MViewDefinition viewDefinition = (MViewDefinition) viewColumn.getAD_View_Definition();
    MTable tableBaseName = (MTable) viewDefinition.getAD_Table();
    StringBuilder whereAxis = new StringBuilder();
    boolean onRange = false;
    setParameters();
    for (int i = 0; i < m_parameters_field.size(); i++) {
        String fieldName = "";
        MColumn column = tableBaseName.getColumn(m_parameters_field.get(i).ColumnName);
        if (column != null)
            fieldName = tableBaseName.getTableName() + "." + column.getColumnName();
        else
            continue;
        if (!onRange) {
            if (parametersValues.get(i) != null && !parametersValues.get(i).toString().isEmpty() && !m_parameters_field.get(i).IsRange) {
                whereAxis.append(" AND ");
                whereAxis.append(fieldName).append("=").append(parametersValues.get(i).toString());
            } else if (parametersValues.get(i) != null && !parametersValues.get(i).toString().isEmpty() && m_parameters_field.get(i).IsRange) {
                whereAxis.append(" AND ");
                whereAxis.append(fieldName).append(" >= ? ");
                axisParameters.add(m_parameters_field.get(i));
                axisParametersValues.add(parametersValues.get(i));
                onRange = true;
            } else
                continue;
        } else if (parametersValues.get(i) != null && !parametersValues.get(i).toString().isEmpty()) {
            whereAxis.append(" AND ");
            whereAxis.append(fieldName).append(" <= ? ");
            axisParameters.add(m_parameters_field.get(i));
            axisParametersValues.add(parametersValues.get(i));
            onRange = false;
        }
    }
    return whereAxis.toString();
}
Also used : MColumn(org.compiere.model.MColumn) MTable(org.compiere.model.MTable) MViewDefinition(org.adempiere.model.MViewDefinition)

Example 13 with MColumn

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

the class Browser method getInfoColumnForAxisField.

/**
	 * Get Info_Column for Axis Field
	 * @param field defined as Axis
	 * @return Info_Column with Axis Field
	 */
public List<MBrowseField> getInfoColumnForAxisField(MBrowseField field) {
    List<MBrowseField> list = new ArrayList<MBrowseField>();
    axisParameters = new ArrayList<>();
    axisParametersValues = new ArrayList<>();
    try {
        I_AD_View_Column xcol, pcol, ycol;
        xcol = field.getAD_View_Column();
        pcol = field.getAxis_Parent_Column();
        ycol = field.getAxis_Column();
        String columnName = xcol.getAD_Column().getColumnName();
        MBrowseField fieldKey = ((MBrowse) field.getAD_Browse()).getFieldKey();
        if (fieldKey == null)
            throw new AdempiereException("@NotFound@ @IsKey@");
        MTable xTable = (MTable) ycol.getAD_View_Definition().getAD_Table();
        String xTableName = xTable.getTableName();
        String keyColumn = MQuery.getZoomColumnName(columnName);
        String tableName = MQuery.getZoomTableName(columnName);
        String whereClause = "";
        if (pcol != null && pcol.getAD_View_Column_ID() > 0) {
            MTable parentTable = MTable.get(field.getCtx(), tableName);
            MColumn parentColumn = getParentColumn(parentTable.getAD_Table_ID());
            if (parentColumn == null)
                throw new AdempiereException("@NotFound@ @IsParent@");
            //	BR [ 242 ]
            if (field.getAD_Val_Rule_ID() > 0)
                whereClause = Env.parseContext(Env.getCtx(), getWindowNo(), field.getAD_Val_Rule().getCode(), false);
        }
        MLookup lookup = MLookupFactory.get(Env.getCtx(), 0, xcol.getAD_Column_ID(), field.getAD_Reference_ID(), m_language, keyColumn, field.getAD_Reference_Value_ID(), false, whereClause);
        int cols = 0;
        StringBuilder axisSql = new StringBuilder("(SELECT ");
        axisSql.append("SUM(").append(ycol.getAD_Column().getColumnName()).append(") FROM  ").append(ycol.getAD_View_Definition().getAD_Table().getTableName()).append(" WHERE ").append(xTableName).append(".").append(fieldKey.getAD_View_Column().getAD_Column().getColumnName()).append("=").append(fieldKey.getAD_View_Column().getColumnSQL());
        for (int id : getAxisRecordIds(tableName, whereClause)) {
            cols++;
            String display = lookup.getDisplay(id).trim();
            display = display.length() > 12 ? display.substring(1, 12) + "_" + cols : display;
            String joinColumn = Msg.translate(m_language, ycol.getAD_Column().getColumnName());
            joinColumn = joinColumn.length() > 15 ? joinColumn.substring(1, 15) : joinColumn;
            String sqlColName = display + "/" + joinColumn;
            String colName = lookup.getDisplay(id).trim() + "/" + Msg.translate(m_language, ycol.getAD_Column().getColumnName());
            StringBuilder axisWhere = new StringBuilder(" ");
            axisWhere.append(getAxisSQLWhere(ycol)).append(" AND ").append(xcol.getAD_View_Definition().getTableAlias()).append(".").append(xcol.getAD_Column().getColumnName());
            StringBuffer select = new StringBuffer();
            select.append(axisSql).append(axisWhere);
            select.append("=").append(id).append(")");
            MViewColumn viewColumn = new MViewColumn(field.getCtx(), 0, field.get_TrxName());
            MViewColumn.copyValues((MViewColumn) ycol, viewColumn);
            viewColumn.setAD_View_Column_ID(ycol.getAD_View_Column_ID());
            viewColumn.setAD_Column_ID(ycol.getAD_Column_ID());
            viewColumn.setColumnSQL(select.toString());
            viewColumn.setColumnName("\"" + sqlColName + "\"");
            MBrowseField browseField = new MBrowseField((MBrowse) field.getAD_Browse(), viewColumn);
            browseField.setAD_Browse_ID(field.getAD_Browse_ID());
            browseField.setAD_Element_ID(field.getAD_Element_ID());
            browseField.setName(colName);
            browseField.setDescription(viewColumn.getDescription());
            browseField.setHelp(viewColumn.getHelp());
            if (viewColumn.get_ID() > 0)
                browseField.setAD_View_Column_ID(viewColumn.getAD_View_Column_ID());
            browseField.setIsActive(true);
            browseField.setIsIdentifier(viewColumn.isIdentifier());
            browseField.setIsRange(false);
            browseField.setIsQueryCriteria(false);
            browseField.setAD_Reference_ID(ycol.getAD_Column().getAD_Reference_ID());
            browseField.setAD_Reference_Value_ID(ycol.getAD_Column().getAD_Reference_Value_ID());
            browseField.setIsKey(false);
            browseField.setIsDisplayed(true);
            browseField.setAxis_Column_ID(field.getAxis_Column_ID());
            browseField.setAxis_Parent_Column_ID(field.getAxis_Parent_Column_ID());
            browseField.setIsReadOnly(field.isReadOnly());
            browseField.setAD_Element_ID(field.getAD_Element_ID());
            list.add(browseField);
            log.finest("Added Column=" + sqlColName + " SQL = " + select);
        }
    } catch (Exception e) {
        throw new AdempiereException(e);
    }
    return list;
}
Also used : MColumn(org.compiere.model.MColumn) MBrowseField(org.adempiere.model.MBrowseField) MLookup(org.compiere.model.MLookup) ArrayList(java.util.ArrayList) I_AD_View_Column(org.adempiere.model.I_AD_View_Column) MBrowse(org.adempiere.model.MBrowse) SQLException(java.sql.SQLException) IOException(java.io.IOException) DBException(org.adempiere.exceptions.DBException) AdempiereException(org.adempiere.exceptions.AdempiereException) MViewColumn(org.adempiere.model.MViewColumn) MTable(org.compiere.model.MTable) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 14 with MColumn

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

the class Browser method getAxisRecordIds.

/**
	 * Get record ID for axis
	 * @param tableName
	 * @param tableWhereClause
	 * @return
	 */
private int[] getAxisRecordIds(String tableName, String tableWhereClause) {
    StringBuilder whereClause = new StringBuilder();
    StringBuilder orderBy = new StringBuilder();
    whereClause.append("EXISTS (SELECT 1 FROM AD_Table t WHERE t.TableName=? AND t.AD_Table_ID=AD_Column.AD_Table_ID) AND ");
    whereClause.append(I_AD_Column.COLUMNNAME_IsIdentifier).append("=?");
    List<MColumn> columns = new Query(Env.getCtx(), I_AD_Column.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).setParameters(tableName, true).setOrderBy(I_AD_Column.COLUMNNAME_SeqNo).list();
    int count = 1;
    for (MColumn column : columns) {
        orderBy.append(column.getColumnName());
        if (count != columns.size())
            orderBy.append(",");
        count++;
    }
    return new Query(Env.getCtx(), tableName, tableWhereClause, null).setOnlyActiveRecords(true).setOrderBy(orderBy.toString()).getIDs();
}
Also used : MColumn(org.compiere.model.MColumn) MQuery(org.compiere.model.MQuery) Query(org.compiere.model.Query)

Example 15 with MColumn

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

the class RecordInfoController method addLine.

/**
	 * 	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);
    //	No for specific column
    if (m_Field == null) {
        line.add(Msg.translate(Env.getCtx(), column.getColumnName()));
    }
    //
    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));
    //	No for specific column
    if (m_Field == null) {
        line.add(column.getColumnName());
    }
    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)

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