Beispiel #1
0
        /// <summary>
        /// Get existing Account or create it
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="AD_Client_ID">client id</param>
        /// <param name="AD_Org_ID"> organisation id</param>
        /// <param name="C_AcctSchema_ID"> account schema id</param>
        /// <param name="Account_ID">account id</param>
        /// <param name="C_SubAcct_ID">sub-Account id</param>
        /// <param name="M_Product_ID">product id</param>
        /// <param name="C_BPartner_ID">Bussness partner id</param>
        /// <param name="AD_OrgTrx_ID"> ordTax id</param>
        /// <param name="C_LocFrom_ID">C_LocFrom_ID</param>
        /// <param name="C_LocTo_ID"></param>
        /// <param name="C_SalesRegion_ID"></param>
        /// <param name="C_Project_ID"></param>
        /// <param name="C_Campaign_ID"></param>
        /// <param name="C_Activity_ID"></param>
        /// <param name="User1_ID"></param>
        /// <param name="User2_ID"></param>
        /// <param name="UserElement1_ID"></param>
        /// <param name="UserElement2_ID"></param>
        /// <returns>account or null</returns>
        public static MAccount Get(Ctx ctx, int AD_Client_ID, int AD_Org_ID, int C_AcctSchema_ID,
                                   int Account_ID, int C_SubAcct_ID, int M_Product_ID, int C_BPartner_ID, int AD_OrgTrx_ID,
                                   int C_LocFrom_ID, int C_LocTo_ID, int C_SalesRegion_ID, int C_Project_ID, int C_Campaign_ID,
                                   int C_Activity_ID, int User1_ID, int User2_ID, int UserElement1_ID, int UserElement2_ID)
        {
            MAccount existingAccount = null;
            //
            StringBuilder info = new StringBuilder();
            StringBuilder sql  = new StringBuilder("SELECT * FROM C_ValidCombination "
                                                                                          //	Mandatory fields
                                                   + "WHERE AD_Client_ID=" + AD_Client_ID //	#1
                                                   + " AND AD_Org_ID=" + AD_Org_ID
                                                   + " AND C_AcctSchema_ID=" + C_AcctSchema_ID
                                                   + " AND Account_ID=" + Account_ID); //	#4

            //	Optional fields
            if (C_SubAcct_ID == 0)
            {
                sql.Append(" AND C_SubAcct_ID IS NULL");
            }
            else
            {
                sql.Append(" AND C_SubAcct_ID=" + C_SubAcct_ID);
            }
            if (M_Product_ID == 0)
            {
                sql.Append(" AND M_Product_ID IS NULL");
            }
            else
            {
                sql.Append(" AND M_Product_ID=" + M_Product_ID);
            }
            if (C_BPartner_ID == 0)
            {
                sql.Append(" AND C_BPartner_ID IS NULL");
            }
            else
            {
                sql.Append(" AND C_BPartner_ID=" + C_BPartner_ID);
            }
            if (AD_OrgTrx_ID == 0)
            {
                sql.Append(" AND AD_OrgTrx_ID IS NULL");
            }
            else
            {
                sql.Append(" AND AD_OrgTrx_ID=" + AD_OrgTrx_ID);
            }
            if (C_LocFrom_ID == 0)
            {
                sql.Append(" AND C_LocFrom_ID IS NULL");
            }
            else
            {
                sql.Append(" AND C_LocFrom_ID=" + C_LocFrom_ID);
            }
            if (C_LocTo_ID == 0)
            {
                sql.Append(" AND C_LocTo_ID IS NULL");
            }
            else
            {
                sql.Append(" AND C_LocTo_ID=" + C_LocTo_ID);
            }
            if (C_SalesRegion_ID == 0)
            {
                sql.Append(" AND C_SalesRegion_ID IS NULL");
            }
            else
            {
                sql.Append(" AND C_SalesRegion_ID=" + C_SalesRegion_ID);
            }
            if (C_Project_ID == 0)
            {
                sql.Append(" AND C_Project_ID IS NULL");
            }
            else
            {
                sql.Append(" AND C_Project_ID=" + C_Project_ID);
            }
            if (C_Campaign_ID == 0)
            {
                sql.Append(" AND C_Campaign_ID IS NULL");
            }
            else
            {
                sql.Append(" AND C_Campaign_ID=" + C_Campaign_ID);
            }
            if (C_Activity_ID == 0)
            {
                sql.Append(" AND C_Activity_ID IS NULL");
            }
            else
            {
                sql.Append(" AND C_Activity_ID=" + C_Activity_ID);
            }
            if (User1_ID == 0)
            {
                sql.Append(" AND User1_ID IS NULL");
            }
            else
            {
                sql.Append(" AND User1_ID=" + User1_ID);
            }
            if (User2_ID == 0)
            {
                sql.Append(" AND User2_ID IS NULL");
            }
            else
            {
                sql.Append(" AND User2_ID=" + User2_ID);
            }
            if (UserElement1_ID == 0)
            {
                sql.Append(" AND UserElement1_ID IS NULL");
            }
            else
            {
                sql.Append(" AND UserElement1_ID=" + UserElement1_ID);
            }
            if (UserElement2_ID == 0)
            {
                sql.Append(" AND UserElement2_ID IS NULL");
            }
            else
            {
                sql.Append(" AND UserElement2_ID=" + UserElement2_ID);
            }
            sql.Append(" AND IsActive='Y'");
            //	sql.Append(" ORDER BY IsFullyQualified DESC");
            try
            {
                DataSet ds = null;
                //IDataReader dr=null;
                ds = DataBase.DB.ExecuteDataset(sql.ToString(), null, null);
                //  --  Mandatory Accounting fields
                info.Append("AD_Client_ID=").Append(AD_Client_ID).Append(",AD_Org_ID=").Append(AD_Org_ID);
                //	Schema
                info.Append(",C_AcctSchema_ID=").Append(C_AcctSchema_ID);
                //	Account
                info.Append(",Account_ID=").Append(Account_ID).Append(" ");

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                //if (dr.Read())
                {
                    DataRow rs = ds.Tables[0].Rows[i];
                    existingAccount = new MAccount(ctx, rs, null);
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, info + "\n" + sql, e);
            }
            //	Existing
            if (existingAccount != null)
            {
                return(existingAccount);
            }
            //	New
            MAccount newAccount = new MAccount(ctx, 0, null);

            newAccount.SetClientOrg(AD_Client_ID, AD_Org_ID);
            newAccount.SetC_AcctSchema_ID(C_AcctSchema_ID);
            newAccount.SetAccount_ID(Account_ID);
            //	--  Optional Accounting fields
            newAccount.SetC_SubAcct_ID(C_SubAcct_ID);
            newAccount.SetM_Product_ID(M_Product_ID);
            newAccount.SetC_BPartner_ID(C_BPartner_ID);
            newAccount.SetAD_OrgTrx_ID(AD_OrgTrx_ID);
            newAccount.SetC_LocFrom_ID(C_LocFrom_ID);
            newAccount.SetC_LocTo_ID(C_LocTo_ID);
            newAccount.SetC_SalesRegion_ID(C_SalesRegion_ID);
            newAccount.SetC_Project_ID(C_Project_ID);
            newAccount.SetC_Campaign_ID(C_Campaign_ID);
            newAccount.SetC_Activity_ID(C_Activity_ID);
            newAccount.SetUser1_ID(User1_ID);
            newAccount.SetUser2_ID(User2_ID);
            newAccount.SetUserElement1_ID(UserElement1_ID);
            newAccount.SetUserElement2_ID(UserElement2_ID);
            //
            if (!newAccount.Save())
            {
                _log.Log(Level.SEVERE, "Could not create new account - " + info);
                return(null);
            }
            _log.Fine("New: " + newAccount);
            return(newAccount);
        }
Beispiel #2
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);
        }