Пример #1
0
        /// <summary>
        /// Populate ledger with gifts and invoices, post batches, close periods and years, according to FNumberOfClosedPeriods
        /// </summary>
        /// <param name="datadirectory"></param>
        public static void PopulateData(string datadirectory)
        {
            int periodOverall = 0;
            int yearCounter   = 0;
            int period        = 1;
            int YearAD        = DateTime.Today.Year - (FNumberOfClosedPeriods / 12);

            SampleDataGiftBatches.LoadBatches(Path.Combine(datadirectory, "donations.csv"));
            SampleDataAccountsPayable.GenerateInvoices(Path.Combine(datadirectory, "invoices.csv"), YearAD);

            while (periodOverall <= FNumberOfClosedPeriods)
            {
                SampleDataGiftBatches.CreateGiftBatches(period);
                SampleDataGiftBatches.PostBatches(yearCounter, period, periodOverall == FNumberOfClosedPeriods ? 1 : 0);
                SampleDataAccountsPayable.PostAndPayInvoices(yearCounter, period, periodOverall == FNumberOfClosedPeriods ? 1 : 0);
                TLedgerInfo LedgerInfo = new TLedgerInfo(FLedgerNumber);

                if (periodOverall < FNumberOfClosedPeriods)
                {
                    TAccountPeriodInfo AccountingPeriodInfo =
                        new TAccountPeriodInfo(FLedgerNumber, period);
                    TLogging.Log("closing period at " + AccountingPeriodInfo.PeriodEndDate.ToShortDateString());

                    // run month end
                    TMonthEnd MonthEndOperator = new TMonthEnd(LedgerInfo);
                    MonthEndOperator.SetNextPeriod();

                    if (period == 12)
                    {
                        TYearEnd YearEndOperator = new TYearEnd(LedgerInfo);
                        // run year end
                        TVerificationResultCollection verificationResult = new TVerificationResultCollection();
                        TReallocation reallocation = new TReallocation(LedgerInfo);
                        reallocation.VerificationResultCollection = verificationResult;
                        reallocation.IsInInfoMode = false;
                        reallocation.RunOperation();

                        TGlmNewYearInit glmNewYearInit = new TGlmNewYearInit(LedgerInfo, yearCounter, YearEndOperator);
                        glmNewYearInit.VerificationResultCollection = verificationResult;
                        glmNewYearInit.IsInInfoMode = false;
                        glmNewYearInit.RunOperation();

                        YearAD++;
                        yearCounter++;
                        SampleDataAccountsPayable.GenerateInvoices(Path.Combine(datadirectory, "invoices.csv"), YearAD);
                        period = 0;
                    }
                }

                period++;
                periodOverall++;
            }
        }
Пример #2
0
        public static bool TPeriodYearEnd(
            int ALedgerNum,
            bool AIsInInfoMode,
            out TVerificationResultCollection AVerificationResult)
        {
            bool NewTransaction;

            DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, out NewTransaction);

            try
            {
                TLedgerInfo LedgerInfo = new TLedgerInfo(ALedgerNum);
                bool res = new TYearEnd(LedgerInfo).RunYearEnd(AIsInInfoMode, out AVerificationResult);

                if (!res)
                {
                    String SuccessMsg = AIsInInfoMode ? "YearEnd check: No problems found." : "Success.";
                    AVerificationResult.Add(new TVerificationResult("Year End", SuccessMsg, "Success", TResultSeverity.Resv_Status));
                }

                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                }

                return res;
            }
            catch (Exception e)
            {
                TLogging.Log("TPeriodIntervalConnector.TPeriodYearEnd() throws " + e.ToString());
                AVerificationResult = new TVerificationResultCollection();
                AVerificationResult.Add(
                    new TVerificationResult(
                        Catalog.GetString("Year End"),
                        Catalog.GetString("Uncaught Exception: ") + e.Message,
                        TResultSeverity.Resv_Critical));

                DBAccess.GDBAccessObj.RollbackTransaction();

                return false;
            }
        }
Пример #3
0
        public void Test_2YearEnds()
        {
            intLedgerNumber = CommonNUnitFunctions.CreateNewLedger();
            CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\server\\GL\\test-sql\\gl-test-year-end.sql", intLedgerNumber);
            TLedgerInfo LedgerInfo = new TLedgerInfo(intLedgerNumber);

            for (int countYear = 0; countYear < 2; countYear++)
            {
                TLogging.Log("preparing year number " + countYear.ToString());

                // accounting one gift
                string strAccountGift = "0200";
                string strAccountBank = "6200";
                TCommonAccountingTool commonAccountingTool =
                    new TCommonAccountingTool(intLedgerNumber, "NUNIT");
                commonAccountingTool.AddBaseCurrencyJournal();
                commonAccountingTool.JournalDescription = "Test Data accounts";
                commonAccountingTool.AddBaseCurrencyTransaction(
                    strAccountBank, "4301", "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 100);
                commonAccountingTool.AddBaseCurrencyTransaction(
                    strAccountGift, "4301", "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 100);
                Boolean PostedOk = commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work
                Assert.AreEqual(true, PostedOk, "Test batch can't be posted");

                bool blnLoop = true;

                while (blnLoop)
                {
                    //                  System.Windows.Forms.MessageBox.Show(LedgerInfo.CurrentPeriod.ToString(), "MonthEnd Period");

                    if (LedgerInfo.ProvisionalYearEndFlag)
                    {
                        blnLoop = false;
                    }
                    else
                    {
                        List <Int32> glBatchNumbers;
                        Boolean      stewardshipBatch;
                        TVerificationResultCollection VerificationResult;

                        TPeriodIntervalConnector.PeriodMonthEnd(
                            intLedgerNumber,
                            false,
                            out glBatchNumbers,
                            out stewardshipBatch,
                            out VerificationResult);
                        CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult,
                                                                                            "MonthEnd gave critical error at Period" + LedgerInfo.CurrentPeriod + ":\r\n");
                    }
                }

                TDBTransaction transaction  = null;
                bool           SubmissionOK = false;

                DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(
                    IsolationLevel.Serializable,
                    TEnforceIsolationLevel.eilMinimum,
                    ref transaction,
                    ref SubmissionOK,
                    delegate
                {
                    TLogging.Log("Closing year number " + countYear.ToString());
                    List <Int32> glBatches     = new List <int>();
                    TReallocation reallocation = new TReallocation(LedgerInfo, glBatches, transaction);
                    TVerificationResultCollection verificationResult = new TVerificationResultCollection();
                    reallocation.VerificationResultCollection        = verificationResult;
                    reallocation.IsInInfoMode = false;
                    //                Assert.AreEqual(1, reallocation.GetJobSize(), "Check 1 reallocation job is required"); // No job size is published by Reallocation
                    reallocation.RunOperation();

                    TYearEnd YearEndOperator       = new TYearEnd(LedgerInfo);
                    TGlmNewYearInit glmNewYearInit = new TGlmNewYearInit(LedgerInfo, countYear, YearEndOperator, transaction);
                    glmNewYearInit.VerificationResultCollection = verificationResult;
                    glmNewYearInit.IsInInfoMode = false;
                    //              Assert.Greater(glmNewYearInit.GetJobSize(), 0, "Check that NewYearInit has work to do"); // in this version, GetJobSize returns 0
                    glmNewYearInit.RunOperation();
                    YearEndOperator.SetNextPeriod(transaction);
                    SubmissionOK = true;
                });
            }

            Assert.AreEqual(2, LedgerInfo.CurrentFinancialYear, "After YearEnd, Ledger is in year 2");

            TAccountPeriodInfo periodInfo = new TAccountPeriodInfo(intLedgerNumber, 1);

            Assert.AreEqual(new DateTime(DateTime.Now.Year + 2,
                                         1,
                                         1), periodInfo.PeriodStartDate, "new Calendar should start with January 1st of next year");
        } // Test_2YearEnds
Пример #4
0
        /// <summary>
        /// Populate ledger with gifts and invoices, post batches, close periods and years, according to FNumberOfClosedPeriods
        /// </summary>
        public static void PopulateData(string datadirectory, bool smallNumber = false)
        {
            int periodOverall = 0;
            int yearCounter   = 0;
            int period        = 1;
            int YearAD        = DateTime.Today.Year - (FNumberOfClosedPeriods / 12);

            SampleDataGiftBatches.FLedgerNumber     = FLedgerNumber;
            SampleDataAccountsPayable.FLedgerNumber = FLedgerNumber;
            SampleDataGiftBatches.LoadBatches(Path.Combine(datadirectory, "donations.csv"), smallNumber);
            SampleDataAccountsPayable.GenerateInvoices(Path.Combine(datadirectory, "invoices.csv"), YearAD, smallNumber);

            while (periodOverall <= FNumberOfClosedPeriods)
            {
                TLogging.LogAtLevel(1, "working on year " + yearCounter.ToString() + " / period " + period.ToString());

                SampleDataGiftBatches.CreateGiftBatches(period);

                if (!SampleDataGiftBatches.PostBatches(yearCounter, period, (periodOverall == FNumberOfClosedPeriods) ? 1 : 0))
                {
                    throw new Exception("could not post gift batches");
                }

                if (!SampleDataAccountsPayable.PostAndPayInvoices(yearCounter, period, (periodOverall == FNumberOfClosedPeriods) ? 1 : 0))
                {
                    throw new Exception("could not post invoices");
                }

                TLedgerInfo LedgerInfo = new TLedgerInfo(FLedgerNumber);

                if (periodOverall < FNumberOfClosedPeriods)
                {
                    TAccountPeriodInfo AccountingPeriodInfo =
                        new TAccountPeriodInfo(FLedgerNumber, period);
                    TLogging.Log("closing period at " + AccountingPeriodInfo.PeriodEndDate.ToShortDateString());

                    // run month end
                    TMonthEnd MonthEndOperator = new TMonthEnd(LedgerInfo);
                    MonthEndOperator.SetNextPeriod(null);


                    if (period == 12)
                    {
                        TDBTransaction transaction  = null;
                        bool           SubmissionOK = false;

                        DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(
                            IsolationLevel.Serializable,
                            TEnforceIsolationLevel.eilMinimum,
                            ref transaction,
                            ref SubmissionOK,
                            delegate
                        {
                            TYearEnd YearEndOperator = new TYearEnd(LedgerInfo);
                            // run year end
                            TVerificationResultCollection verificationResult = new TVerificationResultCollection();
                            List <Int32> glBatches     = new List <int>();
                            TReallocation reallocation = new TReallocation(LedgerInfo, glBatches, transaction);
                            reallocation.VerificationResultCollection = verificationResult;
                            reallocation.IsInInfoMode = false;
                            reallocation.RunOperation();

                            TGlmNewYearInit glmNewYearInit = new TGlmNewYearInit(LedgerInfo, yearCounter, YearEndOperator, transaction);
                            glmNewYearInit.VerificationResultCollection = verificationResult;
                            glmNewYearInit.IsInInfoMode = false;
                            glmNewYearInit.RunOperation();
                            YearEndOperator.SetNextPeriod(transaction);

                            SampleDataLedger.InitExchangeRate();

                            YearAD++;
                            yearCounter++;
                            SampleDataAccountsPayable.GenerateInvoices(Path.Combine(datadirectory, "invoices.csv"), YearAD, smallNumber);
                            period       = 0;
                            SubmissionOK = true;
                        });
                    }
                }

                period++;
                periodOverall++;
            }
        }