Beispiel #1
0
        }       //	setAccount

        /// <summary>
        ///	Get Account Combination based on Account and Overwrite
        /// </summary>
        /// <returns>account</returns>
        public MAccount GetAccount()
        {
            MAccount acct = MAccount.Get(GetCtx(),
                                         _account.GetAD_Client_ID(),
                                         IsOverwriteOrg() && GetOrg_ID() != 0 ? GetOrg_ID() : _account.GetAD_Org_ID(),
                                         _account.GetC_AcctSchema_ID(),
                                         IsOverwriteAcct() && GetAccount_ID() != 0 ? GetAccount_ID() : _account.GetAccount_ID(),
                                         _account.GetC_SubAcct_ID(),
                                         //
                                         IsOverwriteProduct() ? GetM_Product_ID() : _account.GetM_Product_ID(),
                                         IsOverwriteBPartner() ? GetC_BPartner_ID() : _account.GetC_BPartner_ID(),
                                         IsOverwriteOrgTrx() ? GetAD_OrgTrx_ID() : _account.GetAD_OrgTrx_ID(),
                                         IsOverwriteLocFrom() ? GetC_LocFrom_ID() : _account.GetC_LocFrom_ID(),
                                         IsOverwriteLocTo() ? GetC_LocTo_ID() : _account.GetC_LocTo_ID(),
                                         IsOverwriteSalesRegion() ? GetC_SalesRegion_ID() : _account.GetC_SalesRegion_ID(),
                                         IsOverwriteProject() ? GetC_Project_ID() : _account.GetC_Project_ID(),
                                         IsOverwriteCampaign() ? GetC_Campaign_ID() : _account.GetC_Campaign_ID(),
                                         IsOverwriteActivity() ? GetC_Activity_ID() : _account.GetC_Activity_ID(),
                                         IsOverwriteUser1() ? GetUser1_ID() : _account.GetUser1_ID(),
                                         IsOverwriteUser2() ? GetUser2_ID() : _account.GetUser2_ID(),
                                         _account.GetUserElement1_ID(),
                                         _account.GetUserElement2_ID());

            return(acct);
        }       //	setAccount
        /// <summary>
        /// Get Currency Balancing Account
        /// </summary>
        /// <returns>currency balancing account</returns>
        public MAccount GetCurrencyBalancing_Acct()
        {
            if (_CurrencyBalancing_Acct != null)
            {
                return(_CurrencyBalancing_Acct);
            }
            if (_gl == null)
            {
                GetAcctSchemaGL();
            }
            int C_ValidCombination_ID = _gl.GetCurrencyBalancing_Acct();

            _CurrencyBalancing_Acct = MAccount.Get(GetCtx(), C_ValidCombination_ID);
            return(_CurrencyBalancing_Acct);
        }
        /// <summary>
        /// gain
        /// </summary>
        /// <param name="segment"></param>
        /// <returns></returns>
        public MAccount GetDueFrom_Acct(String segment)
        {
            if (_DueFrom_Acct != null)
            {
                return(_DueFrom_Acct);
            }
            if (_gl == null)
            {
                GetAcctSchemaGL();
            }
            int C_ValidCombination_ID = _gl.GetIntercompanyDueFrom_Acct();

            _DueFrom_Acct = MAccount.Get(GetCtx(), C_ValidCombination_ID);
            return(_DueFrom_Acct);
        }
        /// <summary>
        /// Get Suspense Error Account
        /// </summary>
        /// <returns>suspense error account</returns>
        public MAccount GetSuspenseBalancing_Acct()
        {
            if (_SuspenseError_Acct != null)
            {
                return(_SuspenseError_Acct);
            }
            if (_gl == null)
            {
                GetAcctSchemaGL();
            }
            int C_ValidCombination_ID = _gl.GetSuspenseBalancing_Acct();

            _SuspenseError_Acct = MAccount.Get(GetCtx(), C_ValidCombination_ID);
            return(_SuspenseError_Acct);
        }
Beispiel #5
0
        /**
         *  Derive MAccount from record
         *	@return Valid Account Combination
         */
        public MAccount GetMAccount()
        {
            MAccount acct = MAccount.Get(GetCtx(), GetAD_Client_ID(), GetAD_Org_ID(),
                                         GetC_AcctSchema_ID(), GetAccount_ID(), GetC_SubAcct_ID(),
                                         GetM_Product_ID(), GetC_BPartner_ID(), GetAD_OrgTrx_ID(),
                                         GetC_LocFrom_ID(), GetC_LocTo_ID(), GetC_SalesRegion_ID(),
                                         GetC_Project_ID(), GetC_Campaign_ID(), GetC_Activity_ID(),
                                         GetUser1_ID(), GetUser2_ID(), GetUserElement1_ID(), GetUserElement2_ID());

            if (acct != null && acct.Get_ID() == 0)
            {
                acct.Save();
            }
            return(acct);
        }
        /// <summary>
        /// loass
        /// </summary>
        /// <param name="segment"></param>
        /// <returns></returns>
        public MAccount GetFRPT_RealizedLoss_Acct()
        {
            if (_realizedLoss_Acct != null)
            {
                return(_realizedLoss_Acct);
            }
            if (_gl == null)
            {
                GetAcctSchemaGL();
            }
            int C_ValidCombination_ID = _gl.GetFRPT_RealizedLoss_Acct();

            if (C_ValidCombination_ID > 0)
            {
                _realizedLoss_Acct = MAccount.Get(GetCtx(), C_ValidCombination_ID);
            }
            return(_realizedLoss_Acct);
        }
Beispiel #7
0
        /**
         *  Get Charge Account
         *  @param C_Charge_ID charge
         *  @param as account schema
         *  @param amount amount for expense(+)/revenue(-)
         *  @return Charge Account or null
         */
        public static MAccount GetAccount(int C_Charge_ID, MAcctSchema aSchema, Decimal amount)
        {
            if (C_Charge_ID == 0 || aSchema == null)
            {
                return(null);
            }

            int acct_index = 1;     //  Expense (positive amt)

            if (amount < 0)
            {
                acct_index = 2;     //  Revenue (negative amt)
            }

            String sql        = "SELECT CH_Expense_Acct, CH_Revenue_Acct FROM C_Charge_Acct WHERE C_Charge_ID=" + C_Charge_ID + " AND C_AcctSchema_ID=" + aSchema.GetC_AcctSchema_ID();
            int    Account_ID = 0;

            IDataReader dr = null;

            try
            {
                //	PreparedStatement pstmt = DataBase.prepareStatement(sql, null);
                //	pstmt.setInt (1, C_Charge_ID);
                //	pstmt.setInt (2, aSchema.getC_AcctSchema_ID());
                //	ResultSet dr = pstmt.executeQuery();
                dr = DataBase.DB.ExecuteReader(sql, null, null);

                if (dr.Read())
                {
                    Account_ID = Utility.Util.GetValueOfInt(dr[acct_index - 1].ToString());
                }
                dr.Close();
                //pstmt.close();
            }
            catch (SqlException e)
            {
                if (dr != null)
                {
                    dr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
                return(null);
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
            }

            //	No account
            if (Account_ID == 0)
            {
                _log.Severe("NO account for C_Charge_ID=" + C_Charge_ID);
                return(null);
            }

            //	Return Account
            MAccount acct = MAccount.Get(aSchema.GetCtx(), Account_ID);

            return(acct);
        }   //  getAccount
        }       //	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);
        }
Beispiel #9
0
        /// <summary>
        /// Account from Default Product Category
        /// </summary>
        /// <param name="AcctType"></param>
        /// <param name="as1">accounting schema</param>
        /// <returns> Requested Product Account</returns>
        public MAccount GetAccountDefault(int AcctType, MAcctSchema as1)
        {
            // if (AcctType < 1 || AcctType > 10)
            //Updated By raghu 7,jun,2011
            if (AcctType < 1 || AcctType > 12)
            {
                return(null);
            }

            //String sql = "SELECT P_Revenue_Acct, P_Expense_Acct, P_Asset_Acct, P_Cogs_Acct, "
            //    + "P_PurchasePriceVariance_Acct, P_InvoicePriceVariance_Acct, "
            //    + "P_TradeDiscountRec_Acct, P_TradeDiscountGrant_Acct, "
            //    + "P_CostAdjustment_Acct, P_InventoryClearing_Acct "
            //    + "FROM M_Product_Category pc, M_Product_Category_Acct pca "
            //    + "WHERE pc.M_Product_Category_ID=pca.M_Product_Category_ID"
            //    + " AND pca.C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID()
            //    + "ORDER BY pc.IsDefault DESC, pc.Created";
            //Updated By raghu 7,jun,2011
            /*****************Manfacturing*********************/
            String sql = "SELECT COALESCE(a.P_Revenue_Acct, b.P_Revenue_Acct), "                         //1
                         + " COALESCE(a.P_Expense_Acct, b.P_Expense_Acct), "                             //2
                         + " COALESCE(a.P_Asset_Acct, b.P_Asset_Acct), "                                 //3
                         + " COALESCE(a.P_Cogs_Acct, b.P_Cogs_Acct), "                                   //4
                         + " COALESCE(a.P_PurchasePriceVariance_Acct, b.P_PurchasePriceVariance_Acct), " //5
                         + " COALESCE(a.P_InvoicePriceVariance_Acct, b.P_InvoicePriceVariance_Acct), "   //6
                         + " COALESCE(a.P_TradeDiscountRec_Acct, b.P_TradeDiscountRec_Acct), "           //7
                         + " COALESCE(a.P_TradeDiscountGrant_Acct, b.P_TradeDiscountGrant_Acct), "       //8
                         + " COALESCE(a.P_CostAdjustment_Acct, b.P_CostAdjustment_Acct), "               //9
                         + " COALESCE(a.P_InventoryClearing_Acct, b.P_InventoryClearing_Acct), "         //10
                         + " COALESCE(a.P_Resource_Absorption_Acct, b.P_Resource_Absorption_Acct), "     //11
                         + " COALESCE(a.P_MaterialOverhd_Acct, b.P_MaterialOverhd_Acct) "                //12
                         + " FROM C_AcctSchema_Default b "
                         + " LEFT OUTER JOIN M_Product_Category_Acct a ON (a.C_AcctSchema_ID = b.C_AcctSchema_ID "
                         + " AND a.IsActive = 'Y' ),"
                         + " M_Product_Category pc "
                         + " WHERE pc.M_Product_Category_ID=a.M_Product_Category_ID"
                         + " AND b.C_AcctSchema_ID =" + as1.GetC_AcctSchema_ID()
                         + " ORDER BY pc.IsDefault DESC, pc.Created";
            /*****************Manfacturing*********************/
            int         validCombination_ID = 0;
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, null);
                if (idr.Read())
                {
                    validCombination_ID = Utility.Util.GetValueOfInt(idr[AcctType - 1]);
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                log.Log(Level.SEVERE, sql, e);
            }
            if (validCombination_ID == 0)
            {
                return(null);
            }
            return(MAccount.Get(as1.GetCtx(), validCombination_ID));
        }