示例#1
0
        /// <summary>
        /// Revenue Recognition.
        /// Called from FactLine.save
        /// <p>
        /// Create Revenue recognition plan and return Unearned Revenue account
        /// to be used instead of Revenue Account. If not found, it returns
        /// the revenue account.
        /// </summary>
        /// <param name="C_RevenueRecognition_ID">revenue recognition</param>
        /// <param name="C_InvoiceLine_ID">invoice line</param>
        /// <param name="AD_Client_ID">client</param>
        /// <param name="AD_Org_ID">Org</param>
        /// <param name="AD_User_ID">user</param>
        /// <param name="Account_ID">of Revenue Account</param>
        /// <param name="C_SubAcct_ID"> sub account</param>
        /// <param name="M_Product_ID">product</param>
        /// <param name="C_BPartner_ID">bpartner</param>
        /// <param name="AD_OrgTrx_ID"> trx org</param>
        /// <param name="C_LocFrom_ID">loc from</param>
        /// <param name="C_LocTo_ID">loc to</param>
        /// <param name="C_SRegion_ID">sales region</param>
        /// <param name="C_Project_ID">project</param>
        /// <param name="C_Campaign_ID">campaign</param>
        /// <param name="C_Activity_ID">activity</param>
        /// <param name="User1_ID"></param>
        /// <param name="User2_ID"></param>
        /// <param name="UserElement1_ID">user element 1</param>
        /// <param name="UserElement2_ID">user element 2</param>
        /// <returns></returns>
        private int CreateRevenueRecognition(
            int C_RevenueRecognition_ID, int C_InvoiceLine_ID,
            int AD_Client_ID, int AD_Org_ID, int AD_User_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_SRegion_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)
        {
            log.Fine("From Accout_ID=" + Account_ID);
            //  get VC for P_Revenue (from Product)
            MAccount revenue = MAccount.Get(GetCtx(),
                                            AD_Client_ID, AD_Org_ID, GetC_AcctSchema_ID(), Account_ID, C_SubAcct_ID,
                                            M_Product_ID, C_BPartner_ID, AD_OrgTrx_ID, C_LocFrom_ID, C_LocTo_ID, C_SRegion_ID,
                                            C_Project_ID, C_Campaign_ID, C_Activity_ID,
                                            User1_ID, User2_ID, UserElement1_ID, UserElement2_ID);

            if (revenue != null && revenue.Get_ID() == 0)
            {
                revenue.Save();
            }
            if (revenue == null || revenue.Get_ID() == 0)
            {
                log.Severe("Revenue_Acct not found");
                return(Account_ID);
            }
            int P_Revenue_Acct = revenue.Get_ID();

            //  get Unearned Revenue Acct from BPartner Group
            int unearnedRevenue_Acct = 0;
            int new_Account_ID       = 0;

            String sql = "SELECT ga.UnearnedRevenue_Acct, vc.Account_ID "
                         + "FROM C_BP_Group_Acct ga, C_BPartner p, C_ValidCombination vc "
                         + "WHERE ga.C_BP_Group_ID=p.C_BP_Group_ID"
                         + " AND ga.UnearnedRevenue_Acct=vc.C_ValidCombination_ID"
                         + " AND ga.C_AcctSchema_ID=" + GetC_AcctSchema_ID() + " AND p.C_BPartner_ID=" + C_BPartner_ID;
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, Get_TrxName());
                if (idr.Read())
                {
                    unearnedRevenue_Acct = Utility.Util.GetValueOfInt(idr[0]); ///.getInt(1);
                    new_Account_ID       = Utility.Util.GetValueOfInt(idr[1]); //.getInt(2);
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, sql, e);
            }
            if (new_Account_ID == 0)
            {
                log.Severe("UnearnedRevenue_Acct not found");
                return(Account_ID);
            }

            MRevenueRecognitionPlan plan = new MRevenueRecognitionPlan(GetCtx(), 0, null);

            plan.SetC_RevenueRecognition_ID(C_RevenueRecognition_ID);
            plan.SetC_AcctSchema_ID(GetC_AcctSchema_ID());
            plan.SetC_InvoiceLine_ID(C_InvoiceLine_ID);
            plan.SetUnEarnedRevenue_Acct(unearnedRevenue_Acct);
            plan.SetP_Revenue_Acct(P_Revenue_Acct);
            plan.SetC_Currency_ID(GetC_Currency_ID());
            plan.SetTotalAmt(GetAcctBalance());
            if (!plan.Save(Get_TrxName()))
            {
                log.Severe("Plan NOT created");
                return(Account_ID);
            }
            log.Fine("From Acctount_ID=" + Account_ID + " to " + new_Account_ID
                     + " - Plan from UnearnedRevenue_Acct=" + unearnedRevenue_Acct + " to Revenue_Acct=" + P_Revenue_Acct);
            return(new_Account_ID);
        }