Search in sources :

Example 1 with MAcctSchema

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

the class WAccountDialog 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_adTabPanel.init(null, m_WindowNo, m_mTab, null);
    //  Prepare Parameter
    parameterLayout.makeNoStrip();
    parameterLayout.setOddRowSclass("even");
    parameterLayout.setParent(parameterPanel);
    parameterLayout.setStyle("background-color: transparent;");
    m_rows = new Rows();
    m_rows.setParent(parameterLayout);
    int TabNo = 0;
    //	Alias
    if (s_AcctSchema.isHasAlias()) {
        GridField alias = m_mTab.getField("Alias");
        f_Alias = WebEditorFactory.getEditor(alias, false);
        addLine(alias, f_Alias, false);
    }
    //	Alias
    //	Combination
    GridField combination = m_mTab.getField("Combination");
    f_Combination = WebEditorFactory.getEditor(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 = WebEditorFactory.getEditor(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 = WebEditorFactory.getEditor(field, false);
            //	((VLookup)f_Account_ID).setWidth(400);
            addLine(field, f_Account_ID, isMandatory);
            f_Account_ID.addValueChangeListener(this);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount)) {
            GridField field = m_mTab.getField("C_SubAcct_ID");
            f_SubAcct_ID = WebEditorFactory.getEditor(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 = WebEditorFactory.getEditor(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 = WebEditorFactory.getEditor(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 = WebEditorFactory.getEditor(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 = WebEditorFactory.getEditor(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 = WebEditorFactory.getEditor(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 = WebEditorFactory.getEditor(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 = WebEditorFactory.getEditor(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 = WebEditorFactory.getEditor(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 = WebEditorFactory.getEditor(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 = WebEditorFactory.getEditor(field, false);
            // Change the label from the default to the user defined name
            //f_User1_ID.setLabel(ase.getName());				
            addLine(field, f_User1_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList2)) {
            GridField field = m_mTab.getField("User2_ID");
            f_User2_ID = WebEditorFactory.getEditor(field, false);
            // Change the label from the default to the user defined name
            //f_User2_ID.setLabel(ase.getName());				
            addLine(field, f_User2_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList3)) {
            GridField field = m_mTab.getField("User3_ID");
            f_User3_ID = WebEditorFactory.getEditor(field, false);
            // Change the label from the default to the user defined name
            //f_User3_ID.setLabel(ase.getName());
            addLine(field, f_User3_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList4)) {
            GridField field = m_mTab.getField("User4_ID");
            f_User4_ID = WebEditorFactory.getEditor(field, false);
            // Change the label from the default to the user defined name
            //f_User4_ID.setLabel(ase.getName());
            addLine(field, f_User4_ID, isMandatory);
        }
    }
    //	Create Fields in Element Order
    //	Add description
    m_newRow = true;
    Row row = new Row();
    f_Description.setStyle("font-decoration: italic;");
    row.appendChild(f_Description);
    row.setSpans("4");
    row.setStyle("background-color: transparent;");
    m_rows.appendChild(row);
    //	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_adTabPanel.getGridTab().addDataStatusListener(this);
    m_adTabPanel.activate(true);
    if (!m_adTabPanel.isGridView())
        m_adTabPanel.switchRowPresentation();
    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 : MAcctSchema(org.compiere.model.MAcctSchema) GridWindow(org.compiere.model.GridWindow) GridWindowVO(org.compiere.model.GridWindowVO) MQuery(org.compiere.model.MQuery) GridField(org.compiere.model.GridField) Row(org.adempiere.webui.component.Row) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement) Rows(org.adempiere.webui.component.Rows)

Example 2 with MAcctSchema

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

the class ImportAccount method updateCharge.

//	doIt
private void updateCharge(X_I_ElementValue impEV, MElementValue ev) {
    MCharge charge = (MCharge) impEV.getC_Charge();
    if (charge.get_ID() == 0 && !Util.isEmpty(impEV.getChargeName())) {
        charge.setName(impEV.getChargeName());
        charge.setAD_Org_ID(0);
        if (impEV.getC_TaxCategory_ID() == 0) {
            String sql = "SELECT C_TaxCategory_ID FROM C_TaxCategory WHERE AD_Client_ID = ? ORDER BY IsDefault DESC ";
            int taxc = DB.getSQLValue(get_TrxName(), sql, m_AD_Client_ID);
            charge.setC_TaxCategory_ID(taxc);
        } else {
            charge.setC_TaxCategory_ID(impEV.getC_TaxCategory_ID());
        }
        charge.saveEx();
        impEV.setC_Charge_ID(charge.getC_Charge_ID());
    }
    // add/update charge accounting 
    if (ev != null && !charge.is_new()) {
        // for accounting schemas
        for (MAcctSchema schema : MAcctSchema.getClientAcctSchema(getCtx(), m_AD_Client_ID)) {
            // with the same Account Element as the import
            if (schema.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Account).getC_Element_ID() == ev.getC_Element_ID()) {
                MChargeAcct chargeacct = MChargeAcct.get(schema, charge.getC_Charge_ID(), get_TrxName());
                if (chargeacct == null) {
                    chargeacct = new MChargeAcct(getCtx(), 0, get_TrxName());
                    chargeacct.setAD_Org_ID(charge.getAD_Org_ID());
                    chargeacct.setC_AcctSchema_ID(schema.getC_AcctSchema_ID());
                    chargeacct.setC_Charge_ID(charge.getC_Charge_ID());
                }
                MAccount expenseAccount = (MAccount) chargeacct.getCh_Expense_A();
                if (expenseAccount == null) {
                    //  optional null
                    expenseAccount = MAccount.getDefault(schema, true);
                }
                if (expenseAccount.getAccount_ID() != ev.getC_ElementValue_ID()) {
                    MAccount account = MAccount.get(Env.getCtx(), charge.getAD_Client_ID(), charge.getAD_Org_ID(), schema.getC_AcctSchema_ID(), ev.getC_ElementValue_ID(), expenseAccount.getC_SubAcct_ID(), expenseAccount.getM_Product_ID(), expenseAccount.getC_BPartner_ID(), expenseAccount.getAD_OrgTrx_ID(), expenseAccount.getC_LocFrom_ID(), expenseAccount.getC_LocTo_ID(), expenseAccount.getC_SalesRegion_ID(), expenseAccount.getC_Project_ID(), expenseAccount.getC_Campaign_ID(), expenseAccount.getC_Activity_ID(), expenseAccount.getUser1_ID(), expenseAccount.getUser2_ID(), expenseAccount.getUser3_ID(), expenseAccount.getUser4_ID(), expenseAccount.getUserElement1_ID(), expenseAccount.getUserElement2_ID(), get_TrxName());
                    chargeacct.setCh_Expense_Acct(account.getC_ValidCombination_ID());
                }
                MAccount revenueAccount = (MAccount) chargeacct.getCh_Revenue_A();
                if (revenueAccount == null) {
                    //  optional null
                    revenueAccount = MAccount.getDefault(schema, true);
                }
                if (revenueAccount.getAccount_ID() != ev.getC_ElementValue_ID()) {
                    MAccount account = MAccount.get(Env.getCtx(), charge.getAD_Client_ID(), charge.getAD_Org_ID(), schema.getC_AcctSchema_ID(), ev.getC_ElementValue_ID(), revenueAccount.getC_SubAcct_ID(), revenueAccount.getM_Product_ID(), revenueAccount.getC_BPartner_ID(), revenueAccount.getAD_OrgTrx_ID(), revenueAccount.getC_LocFrom_ID(), revenueAccount.getC_LocTo_ID(), revenueAccount.getC_SalesRegion_ID(), revenueAccount.getC_Project_ID(), revenueAccount.getC_Campaign_ID(), revenueAccount.getC_Activity_ID(), revenueAccount.getUser1_ID(), revenueAccount.getUser2_ID(), revenueAccount.getUser3_ID(), revenueAccount.getUser4_ID(), revenueAccount.getUserElement1_ID(), revenueAccount.getUserElement2_ID(), get_TrxName());
                    chargeacct.setCh_Revenue_Acct(account.getC_ValidCombination_ID());
                }
                chargeacct.saveEx();
            }
        }
    }
}
Also used : MAcctSchema(org.compiere.model.MAcctSchema) MAccount(org.compiere.model.MAccount) MCharge(org.compiere.model.MCharge) MChargeAcct(org.compiere.model.MChargeAcct)

Example 3 with MAcctSchema

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

the class DocumentEngine method postImmediate.

/**
	 *  Post Immediate
	 *
	 *	@param	ctx Client Context
	 *  @param  AD_Client_ID    Client ID of Document
	 *  @param  AD_Table_ID     Table ID of Document
	 *  @param  Record_ID       Record ID of this document
	 *  @param  force           force posting
	 *  @param  trxName			ignore, retained for backward compatibility
	 *  @return null, if success or error message
	 */
public static String postImmediate(Properties ctx, int AD_Client_ID, int AD_Table_ID, int Record_ID, boolean force, String trxName) {
    // Ensure the table has Posted column / i.e. GL_JournalBatch can be completed but not posted
    if (MColumn.getColumn_ID(MTable.getTableName(ctx, AD_Table_ID), "Posted") <= 0)
        return null;
    String error = null;
    if (MClient.isClientAccounting()) {
        log.info("Table=" + AD_Table_ID + ", Record=" + Record_ID);
        MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(ctx, AD_Client_ID);
        error = Doc.postImmediate(ass, AD_Table_ID, Record_ID, force, trxName);
        return error;
    }
    //  try to get from Server when enabled
    if (CConnection.get().isAppsServerOK(true)) {
        log.config("trying server");
        try {
            Server server = CConnection.get().getServer();
            if (server != null) {
                Properties p = Env.getRemoteCallCtx(Env.getCtx());
                error = server.postImmediate(p, AD_Client_ID, AD_Table_ID, Record_ID, force, // don't pass transaction to server
                null);
                log.config("from Server: " + error == null ? "OK" : error);
            } else {
                error = "NoAppsServer";
            }
        } catch (Exception e) {
            log.log(Level.WARNING, "(RE)", e);
            error = e.getMessage();
        }
    }
    return error;
}
Also used : MAcctSchema(org.compiere.model.MAcctSchema) Server(org.compiere.interfaces.Server) Properties(java.util.Properties) SQLException(java.sql.SQLException) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 4 with MAcctSchema

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

the class FactAcctReset method delete.

//	reset
/**
	 * 	Delete Accounting Table where period status is open and update count.
	 * 	@param TableName table name
	 *	@param AD_Table_ID table
	 */
private void delete(String TableName, int AD_Table_ID) {
    Timestamp today = TimeUtil.trunc(new Timestamp(System.currentTimeMillis()), TimeUtil.TRUNC_DAY);
    MAcctSchema as = MClient.get(getCtx(), getAD_Client_ID()).getAcctSchema();
    boolean autoPeriod = as != null && as.isAutoPeriodControl();
    if (autoPeriod) {
        Timestamp temp = TimeUtil.addDays(today, -as.getPeriod_OpenHistory());
        if (p_DateAcct_From == null || p_DateAcct_From.before(temp)) {
            p_DateAcct_From = temp;
            log.info("DateAcct From set to: " + p_DateAcct_From);
        }
        temp = TimeUtil.addDays(today, as.getPeriod_OpenFuture());
        if (p_DateAcct_To == null || p_DateAcct_To.after(temp)) {
            p_DateAcct_To = temp;
            log.info("DateAcct To set to: " + p_DateAcct_To);
        }
    }
    reset(TableName, AD_Table_ID);
    m_countReset = 0;
    //
    String docBaseType = getDocumentBaseType(AD_Table_ID, TableName);
    if (docBaseType == null) {
        String s = TableName + ": Unknown DocBaseType";
        log.severe(s);
        addLog(s);
        docBaseType = "";
        return;
    } else
        docBaseType = " AND pc.DocBaseType " + docBaseType;
    //	Doc
    String sql1 = "UPDATE " + TableName + " SET Posted='N', Processing='N' " + "WHERE AD_Client_ID=" + p_AD_Client_ID + " AND (Posted<>'N' OR Posted IS NULL OR Processing<>'N' OR Processing IS NULL)" + " AND EXISTS (SELECT 1 FROM C_PeriodControl pc" + " INNER JOIN Fact_Acct fact ON (fact.C_Period_ID=pc.C_Period_ID) " + " WHERE fact.AD_Table_ID=" + AD_Table_ID + " AND fact.Record_ID=" + TableName + "." + TableName + "_ID";
    if (!autoPeriod)
        sql1 += " AND pc.PeriodStatus = 'O'" + docBaseType;
    if (p_DateAcct_From != null)
        sql1 += " AND TRUNC(fact.DateAcct, 'DD') >= " + DB.TO_DATE(p_DateAcct_From);
    if (p_DateAcct_To != null)
        sql1 += " AND TRUNC(fact.DateAcct, 'DD') <= " + DB.TO_DATE(p_DateAcct_To);
    sql1 += ")";
    log.log(Level.FINE, sql1);
    int reset = DB.executeUpdate(sql1, get_TrxName());
    //	Fact
    String sql2 = "DELETE Fact_Acct " + "WHERE AD_Client_ID=" + p_AD_Client_ID + " AND AD_Table_ID=" + AD_Table_ID;
    if (!autoPeriod)
        sql2 += " AND EXISTS (SELECT 1 FROM C_PeriodControl pc " + "WHERE pc.PeriodStatus = 'O'" + docBaseType + " AND Fact_Acct.C_Period_ID=pc.C_Period_ID)";
    else
        sql2 += " AND EXISTS (SELECT 1 FROM C_PeriodControl pc " + "WHERE Fact_Acct.C_Period_ID=pc.C_Period_ID)";
    if (p_DateAcct_From != null)
        sql2 += " AND TRUNC(Fact_Acct.DateAcct, 'DD') >= " + DB.TO_DATE(p_DateAcct_From);
    if (p_DateAcct_To != null)
        sql2 += " AND TRUNC(Fact_Acct.DateAcct, 'DD') <= " + DB.TO_DATE(p_DateAcct_To);
    log.log(Level.FINE, sql2);
    int deleted = DB.executeUpdate(sql2, get_TrxName());
    //
    log.info(TableName + "(" + AD_Table_ID + ") - Reset=" + reset + " - Deleted=" + deleted);
    String s = TableName + " - Reset=" + reset + " - Deleted=" + deleted;
    addLog(s);
    //
    m_countReset += reset;
    m_countDelete += deleted;
}
Also used : MAcctSchema(org.compiere.model.MAcctSchema) Timestamp(java.sql.Timestamp)

Example 5 with MAcctSchema

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

Aggregations

MAcctSchema (org.compiere.model.MAcctSchema)45 BigDecimal (java.math.BigDecimal)20 MCostElement (org.compiere.model.MCostElement)18 MProduct (org.compiere.model.MProduct)15 ArrayList (java.util.ArrayList)14 MCostType (org.compiere.model.MCostType)14 List (java.util.List)12 MCost (org.compiere.model.MCost)12 Arrays (java.util.Arrays)11 Query (org.compiere.model.Query)11 Trx (org.compiere.util.Trx)9 AdempiereException (org.adempiere.exceptions.AdempiereException)8 Env (org.compiere.util.Env)8 CostDimension (org.adempiere.engine.CostDimension)7 SQLException (java.sql.SQLException)6 MAcctSchemaElement (org.compiere.model.MAcctSchemaElement)6 Msg (org.compiere.util.Msg)6 Timestamp (java.sql.Timestamp)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 AdempiereSystemError (org.compiere.util.AdempiereSystemError)5