/**
  *  AcctSchema Elements
  *  @return ArrayList of AcctSchemaElement
  */
 public MAcctSchemaElement[] GetAcctSchemaElements()
 {
     if (_elements == null)
     {
         _elements = MAcctSchemaElement.GetAcctSchemaElements(this);
     }
     return(_elements);
 }
Пример #2
0
        /// <summary>
        /// Create the key columns in sequence
        /// </summary>
        /// <returns>List of Key Columns</returns>
        private List <String> CreateKeyColumns()
        {
            List <String> columns = new List <String>();

            _leadingColumns = 0;
            //  Sorting Fields
            columns.Add(sortBy1);               //  may add ""
            if (!columns.Contains(sortBy2))
            {
                columns.Add(sortBy2);
            }
            if (!columns.Contains(sortBy3))
            {
                columns.Add(sortBy3);
            }
            if (!columns.Contains(sortBy4))
            {
                columns.Add(sortBy4);
            }

            //  Add Account Segments
            MAcctSchemaElement[] elements = ASchema.GetAcctSchemaElements();
            for (int i = 0; i < elements.Length; i++)
            {
                if (_leadingColumns == 0 && columns.Contains("AD_Org_ID") && columns.Contains("Account_ID"))
                {
                    _leadingColumns = columns.Count;
                }
                //
                MAcctSchemaElement ase        = elements[i];
                String             columnName = ase.GetColumnName();
                if (columnName.StartsWith("UserElement"))
                {
                    if (columnName.IndexOf("1") != -1)
                    {
                        _ref1 = ase.GetDisplayColumnName();
                    }
                    else
                    {
                        _ref2 = ase.GetDisplayColumnName();
                    }
                }
                if (!columns.Contains(columnName))
                {
                    columns.Add(columnName);
                }
            }
            if (_leadingColumns == 0 && columns.Contains("AD_Org_ID") && columns.Contains("Account_ID"))
            {
                _leadingColumns = columns.Count;
            }
            return(columns);
        }
        }       //	get

        /// <summary>
        /// Get AcctSchema Element
        /// </summary>
        /// <param name="elementType">elementType segment type - AcctSchemaElement.ELEMENTTYPE_</param>
        /// <returns>AcctSchemaElement</returns>
        public MAcctSchemaElement GetAcctSchemaElement(String elementType)
        {
            if (_elements == null)
            {
                GetAcctSchemaElements();
            }
            for (int i = 0; i < _elements.Length; i++)
            {
                MAcctSchemaElement ase = _elements[i];
                if (ase.GetElementType().Equals(elementType))
                {
                    return(ase);
                }
            }
            return(null);
        }
        /// <summary>
        /// Factory: Return ArrayList of Account Schema Elements
        /// </summary>
        /// <param name="as1">Accounting Schema</param>
        /// <returns>ArrayList with Elements</returns>
        public static MAcctSchemaElement[] GetAcctSchemaElements(MAcctSchema as1)
        {
            int key = as1.GetC_AcctSchema_ID();

            MAcctSchemaElement[] retValue = (MAcctSchemaElement[])s_cache[key];
            if (retValue != null)
            {
                return(retValue);
            }

            _log.Fine("C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID());
            List <MAcctSchemaElement> list = new List <MAcctSchemaElement>();
            //
            String sql = "SELECT * FROM C_AcctSchema_Element "
                         + "WHERE C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID() + " AND IsActive='Y' ORDER BY SeqNo";

            try
            {
                DataSet ds = DataBase.DB.ExecuteDataset(sql, null, as1.Get_TrxName());
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow            dr  = ds.Tables[0].Rows[i];
                    MAcctSchemaElement ase = new MAcctSchemaElement(as1.GetCtx(), dr, as1.Get_TrxName());
                    _log.Fine(" - " + ase);
                    if (ase.IsMandatory() && ase.GetDefaultValue() == 0)
                    {
                        _log.Log(Level.SEVERE, "No default value for " + ase.GetName());
                    }
                    list.Add(ase);
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }

            retValue = new MAcctSchemaElement[list.Count];
            retValue = list.ToArray();
            s_cache.Add(key, retValue);
            return(retValue);
        }
        }       //	afterDelete

        /** Update combination and optionally **/
        private bool GetOrCreateCombination(Boolean newRecord)
        {
            int Account_ID = 0, C_SubAcct_ID = 0, M_Product_ID = 0, C_BPartner_ID = 0, AD_Org_ID = 0, AD_OrgTrx_ID = 0,
                C_LocFrom_ID = 0, C_LocTo_ID = 0, C_SalesRegion_ID = 0, C_Project_ID = 0, C_Campaign_ID = 0,
                C_Activity_ID = 0, User1_ID = 0, User2_ID = 0;

            if (GetC_ValidCombination_ID() == 0 ||
                (!newRecord && (Is_ValueChanged("Account_ID") ||
                                Is_ValueChanged("M_Product_ID") ||
                                Is_ValueChanged("C_BPartner_ID") ||
                                Is_ValueChanged("AD_Org_ID") ||
                                Is_ValueChanged("C_Project_ID") ||
                                Is_ValueChanged("C_Campaign_ID") ||
                                Is_ValueChanged("C_Activity_ID"))))
            {
                MJournal gl = new MJournal(GetCtx(), GetGL_Journal_ID(), Get_TrxName());

                // Validate all mandatory combinations are set
                MAcctSchema          asc      = MAcctSchema.Get(GetCtx(), gl.GetC_AcctSchema_ID());
                MAcctSchemaElement[] elements = MAcctSchemaElement.GetAcctSchemaElements(asc);
                for (int i = 0; i < elements.Length; i++)
                {
                    MAcctSchemaElement elem = elements[i];
                    String             et   = elem.GetElementType();
                    if (MAcctSchemaElement.ELEMENTTYPE_Account.Equals(et) && Get_ColumnIndex("Account_ID") > 0)
                    {
                        Account_ID = Util.GetValueOfInt(Get_Value("Account_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Account.Equals(et) && Get_ColumnIndex("C_SubAcct_ID") > 0)
                    {
                        C_SubAcct_ID = Util.GetValueOfInt(Get_Value("C_SubAcct_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Activity.Equals(et) && Get_ColumnIndex("C_Activity_ID") > 0)
                    {
                        C_Activity_ID = Util.GetValueOfInt(Get_Value("C_Activity_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_BPartner.Equals(et) && Get_ColumnIndex("C_BPartner_ID") > 0)
                    {
                        C_BPartner_ID = Util.GetValueOfInt(Get_Value("C_BPartner_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Campaign.Equals(et) && Get_ColumnIndex("C_BPartner_ID") > 0)
                    {
                        C_BPartner_ID = Util.GetValueOfInt(Get_Value("C_BPartner_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Organization.Equals(et))
                    {
                        AD_Org_ID = GetAD_Org_ID();
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_OrgTrx.Equals(et) && Get_ColumnIndex("AD_OrgTrx_ID") > 0)
                    {
                        AD_OrgTrx_ID = Util.GetValueOfInt(Get_Value("AD_OrgTrx_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Product.Equals(et) && Get_ColumnIndex("C_LocFrom_ID") > 0)
                    {
                        C_LocFrom_ID = Util.GetValueOfInt(Get_Value("C_LocFrom_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Product.Equals(et) && Get_ColumnIndex("C_LocTo_ID") > 0)
                    {
                        C_LocTo_ID = Util.GetValueOfInt(Get_Value("C_LocTo_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Product.Equals(et) && Get_ColumnIndex("M_Product_ID") > 0)
                    {
                        M_Product_ID = Util.GetValueOfInt(Get_Value("M_Product_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Project.Equals(et) && Get_ColumnIndex("C_Project_ID") > 0)
                    {
                        C_Project_ID = Util.GetValueOfInt(Get_Value("C_Project_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Project.Equals(et) && Get_ColumnIndex("C_Campaign_ID") > 0)
                    {
                        C_Campaign_ID = Util.GetValueOfInt(Get_Value("C_Campaign_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_SalesRegion.Equals(et) && Get_ColumnIndex("C_SalesRegion_ID") > 0)
                    {
                        C_SalesRegion_ID = Util.GetValueOfInt(Get_Value("C_SalesRegion_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_UserList1.Equals(et) && Get_ColumnIndex("User1_ID") > 0)
                    {
                        User1_ID = Util.GetValueOfInt(Get_Value("User1_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_UserList2.Equals(et) && Get_ColumnIndex("User2_ID") > 0)
                    {
                        User2_ID = Util.GetValueOfInt(Get_Value("User2_ID"));
                    }
                }

                MAccount acct = MAccount.Get(GetCtx(), GetAD_Client_ID(), AD_Org_ID, gl.GetC_AcctSchema_ID(), Account_ID,
                                             C_SubAcct_ID, M_Product_ID, C_BPartner_ID, AD_OrgTrx_ID, C_LocFrom_ID, C_LocTo_ID, C_SalesRegion_ID,
                                             C_Project_ID, C_Campaign_ID, C_Activity_ID, User1_ID, User2_ID, 0, 0, 0, 0, 0, 0, 0, 0, 0);

                if (acct != null)
                {
                    acct.Save(Get_TrxName());   // get ID from transaction
                    SetC_ValidCombination_ID(acct.Get_ID());

                    //if (acct.GetAlias() != null && acct.GetAlias().length > 0)
                    //    setAlias_ValidCombination_ID(acct.get_ID());
                    //else
                    //    setAlias_ValidCombination_ID(0);
                }
            }
            else
            {
                fillDimensionsFromCombination();
            }
            return(true);
        }
Пример #6
0
        /// <summary>
        /// Set Value and Description and Fully Qualified Flag for Combination
        /// </summary>
        public void SetValueDescription()
        {
            StringBuilder combi          = new StringBuilder();
            StringBuilder descr          = new StringBuilder();
            bool          fullyQualified = true;
            //
            MAcctSchema as1 = new MAcctSchema(GetCtx(), GetC_AcctSchema_ID(), Get_TrxName());   //	In Trx!

            MAcctSchemaElement[] elements = MAcctSchemaElement.GetAcctSchemaElements(as1);
            for (int i = 0; i < elements.Length; i++)
            {
                if (i > 0)
                {
                    combi.Append(as1.GetSeparator());
                    descr.Append(as1.GetSeparator());
                }
                MAcctSchemaElement element  = elements[i];
                String             combiStr = "_"; //	not defined
                String             descrStr = "_";

                if (MAcctSchemaElement.ELEMENTTYPE_Organization.Equals(element.GetElementType()))
                {
                    if (GetAD_Org_ID() != 0)
                    {
                        MOrg org = new MOrg(GetCtx(), GetAD_Org_ID(), Get_TrxName());   //	in Trx!
                        combiStr = org.GetValue();
                        descrStr = org.GetName();
                    }
                    else
                    {
                        combiStr       = "*";
                        descrStr       = "*";
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_Account.Equals(element.GetElementType()))
                {
                    if (GetAccount_ID() != 0)
                    {
                        if (_accountEV == null)
                        {
                            _accountEV = new MElementValue(GetCtx(), GetAccount_ID(), Get_TrxName());
                        }
                        combiStr = _accountEV.GetValue();
                        descrStr = _accountEV.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Account");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_SubAccount.Equals(element.GetElementType()))
                {
                    if (GetC_SubAcct_ID() != 0)
                    {
                        X_C_SubAcct sa = new X_C_SubAcct(GetCtx(), GetC_SubAcct_ID(), Get_TrxName());
                        combiStr = sa.GetValue();
                        descrStr = sa.GetName();
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_Product.Equals(element.GetElementType()))
                {
                    if (GetM_Product_ID() != 0)
                    {
                        X_M_Product product = new X_M_Product(GetCtx(), GetM_Product_ID(), Get_TrxName());
                        combiStr = product.GetValue();
                        descrStr = product.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Product");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_BPartner.Equals(element.GetElementType()))
                {
                    if (GetC_BPartner_ID() != 0)
                    {
                        X_C_BPartner partner = new X_C_BPartner(GetCtx(), GetC_BPartner_ID(), Get_TrxName());
                        combiStr = partner.GetValue();
                        descrStr = partner.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Business Partner");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_OrgTrx.Equals(element.GetElementType()))
                {
                    if (GetAD_OrgTrx_ID() != 0)
                    {
                        MOrg org = new MOrg(GetCtx(), GetAD_OrgTrx_ID(), Get_TrxName());        // in Trx!
                        combiStr = org.GetValue();
                        descrStr = org.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Trx Org");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_LocationFrom.Equals(element.GetElementType()))
                {
                    if (GetC_LocFrom_ID() != 0)
                    {
                        MLocation loc = new MLocation(GetCtx(), GetC_LocFrom_ID(), Get_TrxName());      //	in Trx!
                        combiStr = loc.GetPostal();
                        descrStr = loc.GetCity();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Location From");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_LocationTo.Equals(element.GetElementType()))
                {
                    if (GetC_LocTo_ID() != 0)
                    {
                        MLocation loc = new MLocation(GetCtx(), GetC_LocFrom_ID(), Get_TrxName());      //	in Trx!
                        combiStr = loc.GetPostal();
                        descrStr = loc.GetCity();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Location To");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_SalesRegion.Equals(element.GetElementType()))
                {
                    if (GetC_SalesRegion_ID() != 0)
                    {
                        MSalesRegion loc = new MSalesRegion(GetCtx(), GetC_SalesRegion_ID(), Get_TrxName());
                        combiStr = loc.GetValue();
                        descrStr = loc.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: SalesRegion");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_Project.Equals(element.GetElementType()))
                {
                    if (GetC_Project_ID() != 0)
                    {
                        X_C_Project project = new X_C_Project(GetCtx(), GetC_Project_ID(), Get_TrxName());
                        combiStr = project.GetValue();
                        descrStr = project.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Project");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_Campaign.Equals(element.GetElementType()))
                {
                    if (GetC_Campaign_ID() != 0)
                    {
                        X_C_Campaign campaign = new X_C_Campaign(GetCtx(), GetC_Campaign_ID(), Get_TrxName());
                        combiStr = campaign.GetValue();
                        descrStr = campaign.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Campaign");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_Activity.Equals(element.GetElementType()))
                {
                    if (GetC_Activity_ID() != 0)
                    {
                        X_C_Activity act = new X_C_Activity(GetCtx(), GetC_Activity_ID(), Get_TrxName());
                        combiStr = act.GetValue();
                        descrStr = act.GetName();
                    }
                    else if (element.IsMandatory())
                    {
                        //log.warning("Mandatory Element missing: Campaign");
                        fullyQualified = false;
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_UserList1.Equals(element.GetElementType()))
                {
                    if (GetUser1_ID() != 0)
                    {
                        MElementValue ev = new MElementValue(GetCtx(), GetUser1_ID(), Get_TrxName());
                        combiStr = ev.GetValue();
                        descrStr = ev.GetName();
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_UserList2.Equals(element.GetElementType()))
                {
                    if (GetUser2_ID() != 0)
                    {
                        MElementValue ev = new MElementValue(GetCtx(), GetUser2_ID(), Get_TrxName());
                        combiStr = ev.GetValue();
                        descrStr = ev.GetName();
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_UserElement1.Equals(element.GetElementType()))
                {
                    if (GetUserElement1_ID() != 0)
                    {
                    }
                }
                else if (MAcctSchemaElement.ELEMENTTYPE_UserElement2.Equals(element.GetElementType()))
                {
                    if (GetUserElement2_ID() != 0)
                    {
                    }
                }
                combi.Append(combiStr);
                descr.Append(descrStr);
            }
            //	Set Values
            base.SetCombination(combi.ToString());
            base.SetDescription(descr.ToString());
            if (fullyQualified != IsFullyQualified())
            {
                SetIsFullyQualified(fullyQualified);
                _log.Fine("Combination=" + GetCombination() + " - " + GetDescription() + " - FullyQualified=" + fullyQualified);
            }
        }
Пример #7
0
        /// <summary>
        /// Factory: default combination
        /// </summary>
        /// <param name="acctSchema">accounting schema</param>
        /// <param name="optionalNull">if true, the optional values are null</param>
        /// <returns>Account</returns>
        public static MAccount GetDefault(MAcctSchema acctSchema, bool optionalNull)
        {
            MAccount vc = new MAccount(acctSchema);

            //  Active Elements
            MAcctSchemaElement[] elements = acctSchema.GetAcctSchemaElements();
            for (int i = 0; i < elements.Length; i++)
            {
                MAcctSchemaElement ase         = elements[i];
                String             elementType = ase.GetElementType();
                int  defaultValue = ase.GetDefaultValue();
                bool setValue     = ase.IsMandatory() || (!ase.IsMandatory() && !optionalNull);
                //
                if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_Organization))
                {
                    vc.SetAD_Org_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_Account))
                {
                    vc.SetAccount_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount) && setValue)
                {
                    vc.SetC_SubAcct_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_BPartner) && setValue)
                {
                    vc.SetC_BPartner_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_Product) && setValue)
                {
                    vc.SetM_Product_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_Activity) && setValue)
                {
                    vc.SetC_Activity_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_LocationFrom) && setValue)
                {
                    vc.SetC_LocFrom_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_LocationTo) && setValue)
                {
                    vc.SetC_LocTo_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_Campaign) && setValue)
                {
                    vc.SetC_Campaign_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_OrgTrx) && setValue)
                {
                    vc.SetAD_OrgTrx_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_Project) && setValue)
                {
                    vc.SetC_Project_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_SalesRegion) && setValue)
                {
                    vc.SetC_SalesRegion_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_UserList1) && setValue)
                {
                    vc.SetUser1_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_UserList2) && setValue)
                {
                    vc.SetUser2_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_UserElement1) && setValue)
                {
                    vc.SetUserElement1_ID(defaultValue);
                }
                else if (elementType.Equals(MAcctSchemaElement.ELEMENTTYPE_UserElement2) && setValue)
                {
                    vc.SetUserElement2_ID(defaultValue);
                }
            }
            _log.Fine("Client_ID=" + vc.GetAD_Client_ID() + ", Org_ID=" + vc.GetAD_Org_ID()
                      + " - AcctSchema_ID=" + vc.GetC_AcctSchema_ID() + ", Account_ID=" + vc.GetAccount_ID());
            return(vc);
        }