예제 #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
        protected override string DoIt()
        {
            int To_GL_Journal_ID = GetRecord_ID();

            log.Info("doIt - From GL_JournalBatch_ID=" + _GL_Journal_ID + " to " + To_GL_Journal_ID);
            if (To_GL_Journal_ID == 0)
            {
                throw new ArgumentException("Target GL_JournalBatch_ID == 0");
            }
            if (_GL_Journal_ID == 0)
            {
                throw new ArgumentException("Source GL_JournalBatch_ID == 0");
            }
            VAdvantage.Model.MJournal from = new VAdvantage.Model.MJournal(GetCtx(), _GL_Journal_ID, Get_Trx());
            VAdvantage.Model.MJournal to   = new VAdvantage.Model.MJournal(GetCtx(), To_GL_Journal_ID, Get_Trx());
            //
            int no = to.CopyLines(from, 'x');

            //
            return("@Copied@=" + no);
        }
예제 #3
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));
        }
        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));
        }