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));
        }
コード例 #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));
        }
コード例 #3
0
        /// <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);
            }
        }