示例#1
0
        public VAdvantage.Model.MJournalLine GenerateJounalLine(VAdvantage.Model.MJournal journal, MInvoice invoice, VAdvantage.Model.MInvoiceLine invoiceLine,
                                                                MRevenueRecognitionPlan revenueRecognitionPlan, MRevenueRecognitionRun revenueRecognitionRun, string recognitionType, int k)
        {
            try
            {
                int combination_ID = 0;
                if (k == 0)
                {
                    if (recognitionType == "R")
                    {
                        combination_ID = revenueRecognitionPlan.GetUnEarnedRevenue_Acct();
                        //journalLine.SetC_ValidCombination_ID(combination_ID);
                    }
                    else
                    {
                        combination_ID = revenueRecognitionPlan.GetINT15_ProductExpense();
                        //journalLine.SetC_ValidCombination_ID(combination_ID);
                    }
                    journalLine.SetAmtAcctDr(revenueRecognitionRun.GetRecognizedAmt());
                    journalLine.SetAmtSourceDr(revenueRecognitionRun.GetRecognizedAmt());
                    journalLine.SetAmtSourceCr(0);
                    journalLine.SetAmtAcctCr(0);
                }
                else
                {
                    if (recognitionType == "R")
                    {
                        combination_ID = revenueRecognitionPlan.GetP_Revenue_Acct();
                        //journalLine.SetC_ValidCombination_ID(combination_ID);
                    }
                    else
                    {
                        combination_ID = revenueRecognitionPlan.GetINT15_PrepaidExpense();
                        //journalLine.SetC_ValidCombination_ID(combination_ID);
                    }
                    journalLine.SetAmtAcctDr(0);
                    journalLine.SetAmtSourceDr(0);
                    journalLine.SetAmtSourceCr(revenueRecognitionRun.GetRecognizedAmt());
                    journalLine.SetAmtAcctCr(revenueRecognitionRun.GetRecognizedAmt());
                }
                int account_ID = Util.GetValueOfInt(DB.ExecuteScalar("Select Account_ID From C_ValidCombination Where C_ValidCombination_ID=" + combination_ID));
                //VAdvantage.Model.MElementValue elementValue = new VAdvantage.Model.MElementValue(GetCtx(), account_ID, Get_Trx());

                journalLine.Set_ValueNoCheck("Account_ID", account_ID);
                journalLine.Set_ValueNoCheck("C_BPartner_ID", invoice.GetC_BPartner_ID());
                journalLine.Set_ValueNoCheck("M_Product_ID", invoiceLine.GetM_Product_ID());
            }
            catch (Exception ex)
            {
                log.SaveError(null, ex);
            }
            return(journalLine);
        }
示例#2
0
        public string createJournals(MRevenueRecognition mRevenueRecognition)
        {
            try
            {
                MRevenueRecognitionPlan[] revenueRecognitionPlans = MRevenueRecognitionPlan.GetRecognitionPlans(mRevenueRecognition, 0);
                MRevenueRecognitionRun[]  mRevenueRecognitionRuns = null;
                for (int i = 0; i < revenueRecognitionPlans.Length; i++)
                {
                    MRevenueRecognitionPlan       revenueRecognitionPlan = revenueRecognitionPlans[i];
                    VAdvantage.Model.MInvoiceLine invoiceLine            = new VAdvantage.Model.MInvoiceLine(GetCtx(), revenueRecognitionPlan.GetC_InvoiceLine_ID(), Get_Trx());
                    MInvoice invoice = new MInvoice(GetCtx(), invoiceLine.GetC_Invoice_ID(), Get_Trx());

                    mRevenueRecognitionRuns = MRevenueRecognitionRun.GetRecognitionRuns(revenueRecognitionPlan, _RecognitionDate, true);

                    if (mRevenueRecognitionRuns.Length > 0)
                    {
                        for (int j = 0; j < mRevenueRecognitionRuns.Length; j++)
                        {
                            MRevenueRecognitionRun revenueRecognitionRun = mRevenueRecognitionRuns[j];
                            if (_DocType == "GL")
                            {
                                if (revenueRecognitionPlan.GetC_AcctSchema_ID() != _AcctSchema_ID || revenueRecognitionPlan.GetC_Currency_ID() != _Currency_ID || revenueRecognitionRun.GetINT15_RecognitionDate() != _RecognizeDate)
                                {
                                    if (journal != null && journal.CompleteIt() == "CO")
                                    {
                                        journal.SetProcessed(true);
                                        journal.SetDocStatus("CO");
                                        journal.SetDocAction("CL");
                                        journal.Save(Get_Trx());
                                        if (DocNo == null)
                                        {
                                            DocNo = journal.GetDocumentNo();
                                        }
                                        else
                                        {
                                            DocNo += "," + journal.GetDocumentNo();
                                        }
                                    }
                                    journal = new VAdvantage.Model.MJournal(GetCtx(), 0, Get_Trx());
                                    journal = CreateJournalHDR(revenueRecognitionPlan, revenueRecognitionRun);

                                    #region Commented Code for Journal Batch
                                    //else if (_DocType == "GB")
                                    //{
                                    //    VAdvantage.Model.MJournalBatch journalBatch = new VAdvantage.Model.MJournalBatch(GetCtx(), 0, Get_Trx());
                                    //    journalBatch.SetClientOrg(revenueRecognitionPlan);
                                    //    journalBatch.SetDescription("Revenue Recognition Run");
                                    //    journalBatch.SetPostingType("A");
                                    //    journalBatch.SetDateDoc(_RecognitionDate);
                                    //    journalBatch.SetDateAcct(_RecognitionDate);
                                    //    journalBatch.SetC_Period_ID(C_Period_ID);
                                    //    int C_Doctype_ID = Util.GetValueOfInt(DB.ExecuteScalar("Select C_Doctype_ID From C_Doctype Where DocBaseType='GLJ'"));
                                    //    journalBatch.SetC_DocType_ID(C_Doctype_ID);
                                    //    journalBatch.SetC_Currency_ID(revenueRecognitionPlan.GetC_Currency_ID());
                                    //    journalBatch.SetTotalCr(revenueRecognitionPlan.GetTotalAmt());
                                    //    journalBatch.SetTotalDr(revenueRecognitionPlan.GetTotalAmt());
                                    //    journalBatch.SetDocStatus("DR");
                                    //    journalBatch.SetDocAction("CO");
                                    //    if (journalBatch.Save())
                                    //    {
                                    //        if (revenueRecognitionPlan.GetC_AcctSchema_ID() != _AcctSchema_ID || revenueRecognitionPlan.GetC_Currency_ID() != _Currency_ID)
                                    //        {
                                    //            journal = new VAdvantage.Model.MJournal(journalBatch);
                                    //            journal = CreateJournalHDR(mRevenueRecognition, revenueRecognitionPlan);
                                    //        }
                                    //    }
                                    //}
                                    #endregion

                                    if (journal.Save())
                                    {
                                        _AcctSchema_ID = journal.GetC_AcctSchema_ID();
                                        _Currency_ID   = journal.GetC_Currency_ID();
                                        _RecognizeDate = revenueRecognitionRun.GetINT15_RecognitionDate();
                                    }
                                }
                                for (int k = 0; k < 2; k++)
                                {
                                    journalLine = new VAdvantage.Model.MJournalLine(journal);
                                    journalLine = GenerateJounalLine(journal, invoice, invoiceLine, revenueRecognitionPlan, revenueRecognitionRun, mRevenueRecognition.GetINT15_RecognizeType(), k);
                                    if (journalLine.Save())
                                    {
                                        revenueRecognitionRun.SetGL_Journal_ID(journal.GetGL_Journal_ID());
                                        revenueRecognitionRun.Save();
                                    }
                                }
                                revenueRecognitionPlan.SetRecognizedAmt(revenueRecognitionRun.GetRecognizedAmt() + revenueRecognitionPlan.GetRecognizedAmt());
                                revenueRecognitionPlan.Save();
                            }
                        }
                    }
                }
                if (journal != null && journal.GetDocStatus() != "CO")
                {
                    journal.CompleteIt();
                    journal.SetProcessed(true);
                    journal.SetDocStatus("CO");
                    journal.SetDocAction("CL");
                    journal.Save(Get_Trx());
                    if (DocNo == null)
                    {
                        DocNo = journal.GetDocumentNo();
                    }
                    else
                    {
                        DocNo += "," + journal.GetDocumentNo();
                    }
                }
            }
            catch (Exception ex)
            {
                log.Log(Level.SEVERE, "GL Journal not allocated due to " + ex);
                return(ex.ToString());
            }
            if (DocNo == null)
            {
                DocNo = "0";
            }
            return(Msg.GetMsg(GetCtx(), "INT15_GLJournalCreated = " + DocNo));
        }
        /// <summary>
        /// Create journal line
        /// </summary>
        /// <param name="journal">GL_Journal</param>
        /// <param name="invoice">Invoice</param>
        /// <param name="invoiceLine">Invoice Line</param>
        /// <param name="revenueRecognitionPlan">Revenue Recognition Plan</param>
        /// <param name="revenueRecognitionRun">Revenue Recognition run</param>
        /// <param name="recognitionType">Recognition type</param>
        /// <param name="k">loop variable</param>
        /// <returns>Journal line object</returns>
        public MJournalLine GenerateJounalLine(MJournal journal, MInvoice invoice, MInvoiceLine invoiceLine,
                                               MRevenueRecognitionPlan revenueRecognitionPlan, MRevenueRecognitionRun revenueRecognitionRun, string recognitionType, int k)
        {
            int combination_ID = 0;

            if (k == 0)
            {
                combination_ID = GetCombinationID(invoiceLine.GetM_Product_ID(), invoiceLine.GetC_Charge_ID(), journal.GetC_AcctSchema_ID(), invoice.IsSOTrx(), invoice.IsReturnTrx(), revenueRecognitionRun.GetRecognizedAmt(), revenueRecognitionPlan.GetC_RevenueRecognition_ID());
                journalLine.SetLine(lineno);
                if (recognitionType.Equals("E") && revenueRecognitionRun.GetRecognizedAmt() > 0)
                {
                    journalLine.SetAmtAcctDr(revenueRecognitionRun.GetRecognizedAmt());
                    journalLine.SetAmtSourceDr(revenueRecognitionRun.GetRecognizedAmt());
                    journalLine.SetAmtSourceCr(0);
                    journalLine.SetAmtAcctCr(0);
                }
                else if (recognitionType.Equals("E") && revenueRecognitionRun.GetRecognizedAmt() < 0)
                {
                    journalLine.SetAmtAcctCr(Decimal.Negate(revenueRecognitionRun.GetRecognizedAmt()));
                    journalLine.SetAmtSourceCr(Decimal.Negate(revenueRecognitionRun.GetRecognizedAmt()));
                    journalLine.SetAmtSourceDr(0);
                    journalLine.SetAmtAcctDr(0);
                }
                else if (recognitionType.Equals("R") && revenueRecognitionRun.GetRecognizedAmt() > 0)
                {
                    journalLine.SetAmtAcctCr(revenueRecognitionRun.GetRecognizedAmt());
                    journalLine.SetAmtSourceCr(revenueRecognitionRun.GetRecognizedAmt());
                    journalLine.SetAmtSourceDr(0);
                    journalLine.SetAmtAcctDr(0);
                }
                else if (recognitionType.Equals("R") && revenueRecognitionRun.GetRecognizedAmt() < 0)
                {
                    journalLine.SetAmtAcctDr(Decimal.Negate(revenueRecognitionRun.GetRecognizedAmt()));
                    journalLine.SetAmtSourceDr(Decimal.Negate(revenueRecognitionRun.GetRecognizedAmt()));
                    journalLine.SetAmtSourceCr(0);
                    journalLine.SetAmtAcctCr(0);
                }
                int account_ID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT Account_ID From C_ValidCombination Where C_ValidCombination_ID=" + combination_ID));
                journalLine.Set_ValueNoCheck("Account_ID", account_ID);
                journalLine.Set_ValueNoCheck("C_BPartner_ID", invoice.GetC_BPartner_ID());
                journalLine.SetAD_OrgTrx_ID(invoiceLine.Get_ColumnIndex("AD_OrgTrx_ID") > 0 ? invoiceLine.GetAD_OrgTrx_ID() : invoice.GetAD_OrgTrx_ID());
                journalLine.Set_ValueNoCheck("C_Project_ID", invoiceLine.GetC_Project_ID() > 0 ? invoiceLine.GetC_Project_ID() : invoice.Get_Value("C_ProjectRef_ID"));
                journalLine.Set_ValueNoCheck("C_Campaign_ID", invoiceLine.Get_ColumnIndex("C_Campaign_ID") > 0 ? invoiceLine.GetC_Campaign_ID() : invoice.GetC_Campaign_ID());
                journalLine.Set_ValueNoCheck("C_Activity_ID", invoiceLine.Get_ColumnIndex("C_Activity_ID") > 0 ? invoiceLine.GetC_Activity_ID() : invoice.GetC_Activity_ID());
                journalLine.Set_ValueNoCheck("M_Product_ID", invoiceLine.GetM_Product_ID());
            }
            else
            {
                combination_ID = GetCombinationID(0, 0, revenueRecognitionPlan.GetC_AcctSchema_ID(), invoice.IsSOTrx(), invoice.IsReturnTrx(), revenueRecognitionRun.GetRecognizedAmt(), revenueRecognitionPlan.GetC_RevenueRecognition_ID());
                int account_ID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT Account_ID From C_ValidCombination Where C_ValidCombination_ID=" + combination_ID));

                journalLine = GetOrCreate(journal, journalLine, invoiceLine.GetM_Product_ID(), invoiceLine.GetC_Charge_ID(),
                                          invoiceLine.Get_ColumnIndex("C_Campaign_ID") > 0 ? invoiceLine.GetC_Campaign_ID() : invoice.GetC_Campaign_ID(),
                                          account_ID, invoiceLine.GetC_Project_ID() > 0 ? invoiceLine.GetC_Project_ID() : Util.GetValueOfInt(invoice.Get_Value("C_ProjectRef_ID")),
                                          invoiceLine.Get_ColumnIndex("C_Activity_ID") > 0 ? invoiceLine.GetC_Activity_ID() : invoice.GetC_Activity_ID(), invoice.GetC_BPartner_ID(),
                                          invoice.GetAD_Org_ID(), invoiceLine.Get_ColumnIndex("AD_OrgTrx_ID") > 0 ? invoiceLine.GetAD_OrgTrx_ID() : invoice.GetAD_OrgTrx_ID());


                if (recognitionType.Equals("E") && revenueRecognitionRun.GetRecognizedAmt() > 0)
                {
                    journalLine.SetAmtAcctCr(journalLine.GetAmtAcctCr() + revenueRecognitionRun.GetRecognizedAmt());
                    journalLine.SetAmtSourceCr(journalLine.GetAmtSourceCr() + revenueRecognitionRun.GetRecognizedAmt());
                    journalLine.SetAmtSourceDr(0);
                    journalLine.SetAmtAcctDr(0);
                }
                else if (recognitionType.Equals("E") && revenueRecognitionRun.GetRecognizedAmt() < 0)
                {
                    journalLine.SetAmtAcctDr(journalLine.GetAmtAcctDr() + Decimal.Negate(revenueRecognitionRun.GetRecognizedAmt()));
                    journalLine.SetAmtSourceDr(journalLine.GetAmtSourceDr() + Decimal.Negate(revenueRecognitionRun.GetRecognizedAmt()));
                    journalLine.SetAmtSourceCr(0);
                    journalLine.SetAmtAcctCr(0);
                }
                else if (recognitionType.Equals("R") && revenueRecognitionRun.GetRecognizedAmt() > 0)
                {
                    journalLine.SetAmtAcctDr(journalLine.GetAmtAcctDr() + revenueRecognitionRun.GetRecognizedAmt());
                    journalLine.SetAmtSourceDr(journalLine.GetAmtSourceDr() + revenueRecognitionRun.GetRecognizedAmt());
                    journalLine.SetAmtSourceCr(0);
                    journalLine.SetAmtAcctCr(0);
                }
                else if (recognitionType.Equals("R") && revenueRecognitionRun.GetRecognizedAmt() < 0)
                {
                    journalLine.SetAmtAcctCr(journalLine.GetAmtAcctCr() + Decimal.Negate(revenueRecognitionRun.GetRecognizedAmt()));
                    journalLine.SetAmtSourceCr(journalLine.GetAmtSourceCr() + Decimal.Negate(revenueRecognitionRun.GetRecognizedAmt()));
                    journalLine.SetAmtSourceDr(0);
                    journalLine.SetAmtAcctDr(0);
                }
            }
            return(journalLine);

            return(journalLine);
        }
        protected override string DoIt()
        {
            try
            {
                MRevenueRecognition       mRevenueRecognition     = new MRevenueRecognition(GetCtx(), _RevenueRecognition_ID, Get_Trx());
                MRevenueRecognitionPlan[] revenueRecognitionPlans = MRevenueRecognitionPlan.GetRecognitionPlans(mRevenueRecognition, C_InvoiceLine_ID);
                for (int i = 0; i < revenueRecognitionPlans.Length; i++)
                {
                    MRevenueRecognitionPlan       revenueRecognitionPlan = revenueRecognitionPlans[i];
                    VAdvantage.Model.MInvoiceLine invoiceLine            = new VAdvantage.Model.MInvoiceLine(GetCtx(), revenueRecognitionPlan.GetC_InvoiceLine_ID(), Get_Trx());
                    MInvoice invoice = new MInvoice(GetCtx(), invoiceLine.GetC_Invoice_ID(), Get_Trx());
                    MRevenueRecognitionRun[] mRevenueRecognitionRuns = MRevenueRecognitionRun.GetRecognitionRuns(revenueRecognitionPlan, _RecognitionDate, false);
                    if (mRevenueRecognitionRuns.Length > 0)
                    {
                        if (_DocType == "GL")
                        {
                            if (revenueRecognitionPlan.GetC_AcctSchema_ID() != _AcctSchema_ID || revenueRecognitionPlan.GetC_Currency_ID() != _Currency_ID)
                            {
                                if (journal != null && journal.CompleteIt() == "CO")
                                {
                                    journal.SetProcessed(true);
                                    journal.SetDocStatus("CO");
                                    journal.SetDocAction("CL");
                                    journal.Save(Get_Trx());
                                    if (DocNo == null)
                                    {
                                        DocNo = journal.GetDocumentNo();
                                    }
                                    else
                                    {
                                        DocNo += "," + journal.GetDocumentNo();
                                    }
                                }
                                journal = new VAdvantage.Model.MJournal(GetCtx(), 0, Get_Trx());
                                journal = CreateJournalHDR(mRevenueRecognition, revenueRecognitionPlan);
                                journal.Save();
                                _AcctSchema_ID = journal.GetC_AcctSchema_ID();
                                _Currency_ID   = journal.GetC_Currency_ID();

                                decimal totalAmt = 0;
                                for (int j = 0; j < mRevenueRecognitionRuns.Length; j++)
                                {
                                    MRevenueRecognitionRun revenueRecognitionRun = mRevenueRecognitionRuns[j];
                                    totalAmt += revenueRecognitionRun.GetRecognizedAmt();
                                    revenueRecognitionRun.SetGL_Journal_ID(journal.GetGL_Journal_ID());
                                    revenueRecognitionRun.Save();
                                }

                                revenueRecognitionPlan.SetRecognizedAmt(totalAmt + revenueRecognitionPlan.GetRecognizedAmt());
                                revenueRecognitionPlan.Save();

                                for (int k = 0; k < 2; k++)
                                {
                                    journalLine = new VAdvantage.Model.MJournalLine(journal);
                                    int combination_ID = 0;
                                    if (k == 0)
                                    {
                                        if (mRevenueRecognition.GetINT15_RecognizeType() == "R")
                                        {
                                            combination_ID = revenueRecognitionPlan.GetUnEarnedRevenue_Acct();
                                            //journalLine.SetC_ValidCombination_ID(combination_ID);
                                        }
                                        else
                                        {
                                            combination_ID = revenueRecognitionPlan.GetINT15_ProductExpense();
                                            //journalLine.SetC_ValidCombination_ID(combination_ID);
                                        }
                                        journalLine.SetAmtAcctDr(totalAmt);
                                        journalLine.SetAmtSourceDr(totalAmt);
                                        journalLine.SetAmtSourceCr(0);
                                        journalLine.SetAmtAcctCr(0);
                                    }
                                    else
                                    {
                                        if (mRevenueRecognition.GetINT15_RecognizeType() == "R")
                                        {
                                            combination_ID = revenueRecognitionPlan.GetP_Revenue_Acct();
                                            //journalLine.SetC_ValidCombination_ID(combination_ID);
                                        }
                                        else
                                        {
                                            combination_ID = revenueRecognitionPlan.GetINT15_PrepaidExpense();
                                            //journalLine.SetC_ValidCombination_ID(combination_ID);
                                        }
                                        journalLine.SetAmtAcctDr(0);
                                        journalLine.SetAmtSourceDr(0);
                                        journalLine.SetAmtSourceCr(totalAmt);
                                        journalLine.SetAmtAcctCr(totalAmt);
                                    }
                                    int account_ID = Util.GetValueOfInt(DB.ExecuteScalar("Select Account_ID From C_ValidCombination Where C_ValidCombination_ID=" + combination_ID));
                                    VAdvantage.Model.MElementValue elementValue = new VAdvantage.Model.MElementValue(GetCtx(), account_ID, Get_Trx());
                                    try
                                    {
                                        journalLine.Set_ValueNoCheck("Account_ID", account_ID);
                                        journalLine.Set_ValueNoCheck("C_BPartner_ID", invoice.GetC_BPartner_ID());
                                        journalLine.Set_ValueNoCheck("M_Product_ID", invoiceLine.GetM_Product_ID());
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                    journalLine.Save();
                                }
                            }
                        }
                    }
                }
                if (journal != null && journal.GetDocStatus() != "CO")
                {
                    if (journal.CompleteIt() == "CO")
                    {
                        journal.SetProcessed(true);
                        journal.SetDocStatus("CO");
                        journal.SetDocAction("CL");
                        journal.Save(Get_Trx());
                        if (DocNo == null)
                        {
                            DocNo = journal.GetDocumentNo();
                        }
                        else
                        {
                            DocNo += "," + journal.GetDocumentNo();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Log(Level.SEVERE, "GL Journal not allocated due to " + ex);
                return(ex.ToString());
            }
            return(Msg.GetMsg(GetCtx(), "INT15_GLJournalCreated = " + DocNo));
        }
        /// <summary>
        /// Create GL Journal
        /// </summary>
        /// <param name="mRevenueRecognition">Revenue Recognition</param>
        /// <returns>Message</returns>
        public string CreateJournals(MRevenueRecognition mRevenueRecognition)
        {
            try
            {
                MRevenueRecognitionRun[] mRevenueRecognitionRuns = null;

                MRevenueRecognitionPlan revenueRecognitionPlan = null;
                MInvoiceLine            invoiceLine            = null;
                MInvoice invoice = null;


                mRevenueRecognitionRuns = MRevenueRecognitionRun.GetRecognitionRuns(mRevenueRecognition, _RecognitionDate, _orgId, false);
                journal_ID = new int[mRevenueRecognitionRuns.Length];
                if (mRevenueRecognitionRuns.Length > 0)
                {
                    for (int j = 0; j < mRevenueRecognitionRuns.Length; j++)
                    {
                        MRevenueRecognitionRun revenueRecognitionRun = mRevenueRecognitionRuns[j];
                        revenueRecognitionPlan = new MRevenueRecognitionPlan(GetCtx(), revenueRecognitionRun.GetC_RevenueRecognition_Plan_ID(), Get_TrxName());
                        invoiceLine            = new MInvoiceLine(GetCtx(), revenueRecognitionPlan.GetC_InvoiceLine_ID(), Get_TrxName());
                        invoice = new MInvoice(GetCtx(), invoiceLine.GetC_Invoice_ID(), Get_TrxName());

                        if (revenueRecognitionPlan.GetC_AcctSchema_ID() != _AcctSchema_ID || revenueRecognitionPlan.GetC_Currency_ID() != _Currency_ID || revenueRecognitionRun.GetRecognitionDate() != _RecognizeDate)
                        {
                            if (journal != null)
                            {
                                if (DocNo == null)
                                {
                                    DocNo = journal.GetDocumentNo();
                                }
                                else
                                {
                                    DocNo += ", " + journal.GetDocumentNo();
                                }
                                journal_ID[j - 1] = journal.GetGL_Journal_ID();
                            }
                            journal = new MJournal(GetCtx(), 0, Get_TrxName());

                            journal.SetC_DocType_ID(_DocType);
                            journal = CreateJournalHDR(revenueRecognitionPlan, revenueRecognitionRun, mRevenueRecognition.GetRecognitionFrequency());


                            if (journal.Save())
                            {
                                _AcctSchema_ID = journal.GetC_AcctSchema_ID();
                                _Currency_ID   = journal.GetC_Currency_ID();
                                _RecognizeDate = revenueRecognitionRun.GetRecognitionDate();
                                lineno         = Util.GetValueOfInt(DB.ExecuteScalar("SELECT NVL(MAX(Line), 0)+10  AS DefaultValue FROM GL_JournalLine WHERE GL_Journal_ID=" + journal.GetGL_Journal_ID(), null, invoice.Get_Trx()));
                            }
                            else
                            {
                                pp = VLogger.RetrieveError();
                                if (pp != null)
                                {
                                    errorMsg = pp.GetName();
                                    if (errorMsg == "")
                                    {
                                        errorMsg = pp.GetValue();
                                    }
                                }
                                if (errorMsg == "")
                                {
                                    errorMsg = Msg.GetMsg(GetCtx(), "GLJournalNotCreated");
                                }
                                Get_TrxName().Rollback();
                                return(errorMsg);
                            }
                        }
                        for (int k = 0; k < 2; k++)
                        {
                            journalLine = new MJournalLine(journal);
                            journalLine = GenerateJounalLine(journal, invoice, invoiceLine, revenueRecognitionPlan, revenueRecognitionRun, mRevenueRecognition.GetRecognitionType(), k);
                            if (journalLine.Save())
                            {
                                revenueRecognitionRun.SetGL_Journal_ID(journal.GetGL_Journal_ID());
                                revenueRecognitionRun.Save();
                                lineno += 10;
                            }
                            else
                            {
                                pp = VLogger.RetrieveError();
                                if (pp != null)
                                {
                                    errorMsg = pp.GetName();
                                    if (errorMsg == "")
                                    {
                                        errorMsg = pp.GetValue();
                                    }
                                }
                                if (errorMsg == "")
                                {
                                    errorMsg = Msg.GetMsg(GetCtx(), "GLJournalNotCreated");
                                }
                                Get_TrxName().Rollback();
                                return(errorMsg);
                            }
                        }
                        revenueRecognitionPlan.SetRecognizedAmt(revenueRecognitionRun.GetRecognizedAmt() + revenueRecognitionPlan.GetRecognizedAmt());
                        if (!revenueRecognitionPlan.Save())
                        {
                            pp = VLogger.RetrieveError();
                            if (pp != null)
                            {
                                errorMsg = pp.GetName();
                                if (errorMsg == "")
                                {
                                    errorMsg = pp.GetValue();
                                }
                            }
                            if (errorMsg == "")
                            {
                                errorMsg = Msg.GetMsg(GetCtx(), "GLJournalNotCreated");
                            }
                            Get_TrxName().Rollback();
                            return(errorMsg);
                        }
                    }
                    if (journal != null)
                    {
                        if (DocNo == null)
                        {
                            DocNo = journal.GetDocumentNo();
                        }
                        else
                        {
                            DocNo += ", " + journal.GetDocumentNo();
                        }

                        journal_ID[journal_ID.Length - 1] = journal.GetGL_Journal_ID();
                    }
                }
            }
            catch (Exception ex)
            {
                log.Log(Level.SEVERE, Msg.GetMsg(GetCtx(), "GLJournalnotallocateddueto") + ex.Message);
                Get_TrxName().Rollback();
                return(ex.Message);
            }
            if (DocNo == null)
            {
                return(Msg.GetMsg(GetCtx(), "FoundNoRevenueRecognitionPlan"));
            }

            Get_TrxName().Commit();
            if (journal_ID != null)
            {
                for (int i = 0; i < journal_ID.Length; i++)
                {
                    if (journal_ID[i] > 0)
                    {
                        string result = CompleteOrReverse(GetCtx(), journal_ID[i], 169, "CO");
                        if (!String.IsNullOrEmpty(result))
                        {
                            journalIDS += ", " + journal_ID[i] + " " + result;
                        }
                    }
                }
            }
            if (!String.IsNullOrEmpty(journalIDS))
            {
                return(Msg.GetMsg(GetCtx(), "GLJournalCreated") + DocNo + " " + Msg.GetMsg(GetCtx(), "GLJournalNotCompleted") + journalIDS);
            }
            else
            {
                return(Msg.GetMsg(GetCtx(), "GLJournalCreated") + DocNo);
            }
        }