/// <summary>
        /// setup a ledger with simple test data
        /// </summary>
        public static int SetupTestLedgerWithPostedBatches()
        {
            // create a new ledger
            int LedgerNumber = CommonNUnitFunctions.CreateNewLedger();

            // post a sample batch
            TCommonAccountingTool commonAccountingTool =
                new TCommonAccountingTool(LedgerNumber, "NUNIT");

            commonAccountingTool.AddBaseCurrencyJournal();
            commonAccountingTool.JournalDescription = "Test Data accounts";
            string strAccountBank = "6000";
            string StandardCostCentre = TGLTransactionWebConnector.GetStandardCostCentre(LedgerNumber);

            // Accounting of a start balance
            commonAccountingTool.AddBaseCurrencyTransaction(
                "6200", StandardCostCentre, "Start Balance", "Debit", MFinanceConstants.IS_DEBIT, 40);
            commonAccountingTool.AddBaseCurrencyTransaction(
                "9700", StandardCostCentre, "Start Balance", "Credit", MFinanceConstants.IS_CREDIT, 40);
            // Accounting of some gifts ...
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountBank, StandardCostCentre, "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 100);
            commonAccountingTool.AddBaseCurrencyTransaction(
                "0100", StandardCostCentre, "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 100);
            // Accounting of some expense ...
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountBank, StandardCostCentre, "Expense Example", "Credit", MFinanceConstants.IS_CREDIT, 20);
            commonAccountingTool.AddBaseCurrencyTransaction(
                "4200", StandardCostCentre, "Expense Example", "Debit", MFinanceConstants.IS_DEBIT, 20);
            commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work

            return LedgerNumber;
        }
        public void Test_PEMM_05_Revaluation()
        {
            FLedgerNumber = CommonNUnitFunctions.CreateNewLedger();
            // load foreign currency account 6001
            CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\GL\\" +
                "test-sql\\gl-test-account-data.sql", FLedgerNumber);

            // post a batch for foreign currency account 6001
            TCommonAccountingTool commonAccountingTool =
                new TCommonAccountingTool(FLedgerNumber, "NUNIT");
            commonAccountingTool.AddForeignCurrencyJournal("GBP", 1.1m);
            commonAccountingTool.JournalDescription = "Test foreign currency account";
            string strAccountGift = "0200";
            string strAccountBank = "6001";

            // Accounting of some gifts ...
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountBank, (FLedgerNumber * 100).ToString(), "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 100);

            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountGift, (FLedgerNumber * 100).ToString(), "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 100);

            Boolean PostedOk = commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work
            Assert.IsTrue(PostedOk, "Post foreign gift batch");


            TVerificationResultCollection verificationResult;

/*
 * This error is no longer critical - it's OK to run month end even if a reval is required. (Mantis# 03905)
 *
 *          bool blnHasErrors = TPeriodIntervalConnector.TPeriodMonthEnd(
 *              FLedgerNumber, true, out verificationResult);
 *
 *          for (int i = 0; i < verificationResult.Count; ++i)
 *          {
 *              if (verificationResult[i].ResultCode.Equals(
 *                      TPeriodEndErrorAndStatusCodes.PEEC_05.ToString()))
 *              {
 *                  blnStatusArrived = true;
 *                  Assert.IsTrue(verificationResult[i].ResultSeverity == TResultSeverity.Resv_Critical,
 *                      "A critical error is required: need to run revaluation first ...");
 *              }
 *          }
 */

            // run revaluation
            Boolean blnHasErrors = TRevaluationWebConnector.Revaluate(FLedgerNumber, new string[] { "GBP" }, new decimal[] { 1.2m },
                TLedgerInfo.GetStandardCostCentre(FLedgerNumber),
                out verificationResult);

            if (blnHasErrors)
            {
                TLogging.Log("\n\n\nTRevaluationWebConnector.Revaluate returned false, VerificationResult follows:");
                TLogging.Log(verificationResult.BuildVerificationResultString());
            }

            Assert.IsFalse(blnHasErrors, "Problem running the revaluation");

            blnHasErrors = TPeriodIntervalConnector.PeriodMonthEnd(
                FLedgerNumber, true, out verificationResult);

            if (blnHasErrors)
            {
                TLogging.Log("\n\n\nTPeriodMonthEnd returned true, VerificationResult follows:");
                TLogging.Log(verificationResult.BuildVerificationResultString());
            }

            Assert.IsFalse(blnHasErrors, "should now be able to close the month now that the revaluation has been run");
        }
        public void Test_PEMM_03_SuspensedAccounts()
        {
            TCommonAccountingTool commonAccountingTool =
                new TCommonAccountingTool(FLedgerNumber, "NUNIT");

            commonAccountingTool.AddBaseCurrencyJournal();
            commonAccountingTool.JournalDescription = "Test Data accounts";
            string strAccountBank = "6000";
            // Accounting of some gifts ...
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountBank, "7300", "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 100);
            commonAccountingTool.AddBaseCurrencyTransaction(
                "0100", "7300", "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 100);
            commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work

            new ChangeSuspenseAccount(FLedgerNumber, strAccountBank).Suspense();

            TVerificationResultCollection verificationResult;
            bool blnHasErrors = TPeriodIntervalConnector.PeriodMonthEnd(    // Changed to InfoMode because
                FLedgerNumber, true, out verificationResult);               // the suspense accounts warning is now shown only in InfoMode.
            bool blnStatusArrived = false;

            for (int i = 0; i < verificationResult.Count; ++i)
            {
                if (verificationResult[i].ResultCode.Equals(
                        TPeriodEndErrorAndStatusCodes.PEEC_07.ToString()))
                {
                    blnStatusArrived = true;
                    Assert.AreEqual(TResultSeverity.Resv_Status, verificationResult[i].ResultSeverity,
                        "MonthEnd verificationResult should be status only ...");
                }
            }

            Assert.IsTrue(blnStatusArrived, "MonthEnd status message PEEC_07 has been shown");
            Assert.IsFalse(blnHasErrors, "there should not be an error for closing the first period");

            int periodCounter = 1;

            //TODO: Calendar vs Financial Date Handling - Check if this should not assume 12 but rather use number of financial periods in ledger
            while (!blnHasErrors && periodCounter < 12)
            {
                blnHasErrors = TPeriodIntervalConnector.PeriodMonthEnd(
                    FLedgerNumber, false, out verificationResult);

                Assert.IsFalse(blnHasErrors, "there was an error closing period " + periodCounter.ToString());
                periodCounter++;
                Assert.AreEqual(periodCounter, new TLedgerInfo(FLedgerNumber).CurrentPeriod, "should be in new period");
            }

            blnHasErrors = TPeriodIntervalConnector.PeriodMonthEnd(
                FLedgerNumber, false, out verificationResult);

            blnStatusArrived = false;

            for (int i = 0; i < verificationResult.Count; ++i)
            {
                if (verificationResult[i].ResultCode.Equals(
                        TPeriodEndErrorAndStatusCodes.PEEC_07.ToString())
                    && (TResultSeverity.Resv_Critical == verificationResult[i].ResultSeverity))
                {
                    blnStatusArrived = true;
                }
            }

            Assert.IsTrue(blnStatusArrived, "there should be  a critical error PEEC_07 for the suspense account");
            Assert.IsTrue(blnHasErrors, "there should be an error because we cannot close the last period due to suspense account with a balance");

            new ChangeSuspenseAccount(FLedgerNumber, strAccountBank).Unsuspense();
        }
        public void Test_YearEnd()
        {
            intLedgerNumber = CommonNUnitFunctions.CreateNewLedger();

            TLedgerInfo LedgerInfo = new TLedgerInfo(intLedgerNumber);
            Assert.AreEqual(0, LedgerInfo.CurrentFinancialYear, "Before YearEnd, we should be in year 0");

            TAccountPeriodInfo periodInfo = new TAccountPeriodInfo(intLedgerNumber, 1);
            Assert.AreEqual(new DateTime(DateTime.Now.Year,
                    1,
                    1), periodInfo.PeriodStartDate, "Calendar from base database should start with January 1st of this year");

            CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\GL\\test-sql\\gl-test-year-end.sql", intLedgerNumber);

            TCommonAccountingTool commonAccountingTool =
                new TCommonAccountingTool(intLedgerNumber, "NUNIT");
            commonAccountingTool.AddBaseCurrencyJournal();
            commonAccountingTool.JournalDescription = "Test Data accounts";
            string strAccountGift = "0200";
            string strAccountBank = "6200";
            string strAccountExpense = "4100";

            // Accounting of some gifts ...
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountBank, "4301", "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 100);
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountBank, "4302", "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 200);
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountBank, "4303", "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 300);

            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountGift, "4301", "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 100);
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountGift, "4302", "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 200);
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountGift, "4303", "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 300);


            // Accounting of some expenses ...

            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountExpense, "4301", "Expense Example", "Debit", MFinanceConstants.IS_DEBIT, 150);
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountExpense, "4302", "Expense Example", "Debit", MFinanceConstants.IS_DEBIT, 150);
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountExpense, "4303", "Expense Example", "Debit", MFinanceConstants.IS_DEBIT, 200);

            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountBank, "4301", "Expense Example", "Credit", MFinanceConstants.IS_CREDIT, 150);
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountBank, "4302", "Expense Example", "Credit", MFinanceConstants.IS_CREDIT, 150);
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountBank, "4303", "Expense Example", "Credit", MFinanceConstants.IS_CREDIT, 200);

            commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work


            TVerificationResultCollection verificationResult = new TVerificationResultCollection();

            bool blnLoop = true;

            while (blnLoop)
            {
                if (LedgerInfo.ProvisionalYearEndFlag)
                {
                    blnLoop = false;
                }
                else
                {
                    TVerificationResultCollection VerificationResult;
                    TPeriodIntervalConnector.PeriodMonthEnd(intLedgerNumber, false, out VerificationResult);
                    CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult,
                        "Running MonthEnd gave critical error");
                }
            }

            // check before year end that income and expense accounts are not 0
            int intYear = 0;
            CheckGLMEntry(intLedgerNumber, intYear, strAccountBank,
                -50, 0, 50, 0, 100, 0);
            CheckGLMEntry(intLedgerNumber, intYear, strAccountExpense,
                150, 0, 150, 0, 200, 0);
            CheckGLMEntry(intLedgerNumber, intYear, strAccountGift,
                100, 0, 200, 0, 300, 0);

            // test that we cannot post to period 12 anymore, all periods are closed?
            LedgerInfo = new TLedgerInfo(intLedgerNumber);
            Assert.AreEqual(true, LedgerInfo.ProvisionalYearEndFlag, "Provisional YearEnd flag should be set");
            Assert.AreEqual(TYearEndProcessStatus.RESET_STATUS,
                (TYearEndProcessStatus)LedgerInfo.YearEndProcessStatus,
                "YearEnd process status should be still on RESET");

            //
            // Reallocation is never called explicitly like this - it's not really appropriate
            // because I'm about to call it again as part of YearEnd, below.
            // But a tweak in the reallocation code means that it should now cope with being called twice.

            TReallocation reallocation = new TReallocation(LedgerInfo);
            reallocation.VerificationResultCollection = verificationResult;
            reallocation.IsInInfoMode = false;
            reallocation.RunOperation();

            // check amounts after reallocation
            CheckGLMEntry(intLedgerNumber, intYear, strAccountBank,
                -50, 0, 50, 0, 100, 0);
            CheckGLMEntry(intLedgerNumber, intYear, strAccountExpense,
                0, -150, 0, -150, 0, -200);
            CheckGLMEntry(intLedgerNumber, intYear, strAccountGift,
                0, -100, 0, -200, 0, -300);

            // first run in info mode
            TPeriodIntervalConnector.PeriodYearEnd(intLedgerNumber, true, out verificationResult);
            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(verificationResult,
                "YearEnd test should not have critical errors");

            // now run for real
            TPeriodIntervalConnector.PeriodYearEnd(intLedgerNumber, false, out verificationResult);
            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(verificationResult,
                "YearEnd should not have critical errors");

            ++intYear;
            // check after year end that income and expense accounts are 0, bank account remains
            CheckGLMEntry(intLedgerNumber, intYear, strAccountBank,
                -50, 0, 50, 0, 100, 0);
            CheckGLMEntry(intLedgerNumber, intYear, strAccountExpense,
                0, 0, 0, 0, 0, 0);
            CheckGLMEntry(intLedgerNumber, intYear, strAccountGift,
                0, 0, 0, 0, 0, 0);

            // also check the glm period records
            CheckGLMPeriodEntry(intLedgerNumber, intYear, 1, strAccountBank,
                -50, 50, 100);
            CheckGLMPeriodEntry(intLedgerNumber, intYear, 1, strAccountExpense,
                0, 0, 0);
            CheckGLMPeriodEntry(intLedgerNumber, intYear, 1, strAccountGift,
                0, 0, 0);

            // 9700 is the account that the expenses and income from last year is moved to
            TGlmInfo glmInfo = new TGlmInfo(intLedgerNumber, intYear, "9700");
            glmInfo.Reset();
            Assert.IsTrue(glmInfo.MoveNext(), "9700 account not found");

            Assert.AreEqual(100, glmInfo.YtdActualBase);
            Assert.AreEqual(0, glmInfo.ClosingPeriodActualBase);

            LedgerInfo = new TLedgerInfo(intLedgerNumber);
            Assert.AreEqual(1, LedgerInfo.CurrentFinancialYear, "After YearEnd, we are in a new financial year");
            Assert.AreEqual(1, LedgerInfo.CurrentPeriod, "After YearEnd, we are in Period 1");
            Assert.AreEqual(false, LedgerInfo.ProvisionalYearEndFlag, "After YearEnd, ProvisionalYearEnd flag should not be set");
            Assert.AreEqual(TYearEndProcessStatus.RESET_STATUS,
                (TYearEndProcessStatus)LedgerInfo.YearEndProcessStatus,
                "after year end, year end process status should be RESET");

            periodInfo = new TAccountPeriodInfo(intLedgerNumber, 1);
            Assert.AreEqual(new DateTime(DateTime.Now.Year + 1,
                    1,
                    1), periodInfo.PeriodStartDate, "new Calendar should start with January 1st of next year");
        }
        public void Test_2YearEnds()
        {
            intLedgerNumber = CommonNUnitFunctions.CreateNewLedger();
            CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\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
                    {
                        TVerificationResultCollection VerificationResult;
                        TPeriodIntervalConnector.PeriodMonthEnd(intLedgerNumber, false, out VerificationResult);
                        CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult,
                            "MonthEnd gave critical error at Period" + LedgerInfo.CurrentPeriod + ":\r\n");
                    }
                }

                TLogging.Log("Closing year number " + countYear.ToString());
                TReallocation reallocation = new TReallocation(LedgerInfo);
                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);
                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();
            }

            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");
        }
        public void Test_01_BaseCurrencyAccounting()
        {
            // <summary>
            // 6000 is defined as debit Account and so an accounting in "debit direction" is
            // added as a positive value to GLM.
            // 9800 is defined as credit Account and so an accounting in "credit direction" is
            // added as a positive value to GLM.
            // </summary>

            string strAccountStart = "6000";
            string strAccountEnd = "9800";
            string strCostCentre = "4300";

            // Get the glm-values before and after the test and taking the differences enables
            // to run the test several times
            TGet_GLM_Info getGLM_InfoBeforeStart = new TGet_GLM_Info(LedgerNumber, strAccountStart, strCostCentre);
            TGet_GLM_Info getGLM_InfoBeforeEnd = new TGet_GLM_Info(LedgerNumber, strAccountEnd, strCostCentre);

            TCommonAccountingTool commonAccountingTool =
                new TCommonAccountingTool(LedgerNumber, "NUNIT");

            commonAccountingTool.AddBaseCurrencyJournal();

            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountStart, strCostCentre, "Debit-Test-10", "NUNIT",
                MFinanceConstants.IS_DEBIT, 10);
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountEnd, strCostCentre, "Credit-Test 10", "NUNIT",
                MFinanceConstants.IS_CREDIT, 10);
            commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work

            TGet_GLM_Info getGLM_InfoAfterStart = new TGet_GLM_Info(LedgerNumber, strAccountStart, strCostCentre);
            TGet_GLM_Info getGLM_InfoAfterEnd = new TGet_GLM_Info(LedgerNumber, strAccountEnd, strCostCentre);

            // strAccountStart is a debit account -> in this case "+"
            Assert.AreEqual(getGLM_InfoBeforeStart.YtdActual + 10, getGLM_InfoAfterStart.YtdActual,
                "Check if 10 has been accounted to " + strAccountStart);
            // strAccountEnd is a credit acount -> in this case "+" too!
            Assert.AreEqual(getGLM_InfoBeforeEnd.YtdActual + 10, getGLM_InfoAfterEnd.YtdActual,
                "Check if 10 has been accounted to " + strAccountEnd);

            commonAccountingTool =
                new TCommonAccountingTool(LedgerNumber, "NUNIT");

            commonAccountingTool.AddBaseCurrencyJournal();

            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountStart, strCostCentre, "Debit-Test-5", "NUNIT",
                MFinanceConstants.IS_CREDIT, 5);
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountEnd, strCostCentre, "Credit-Test 5", "NUNIT",
                MFinanceConstants.IS_DEBIT, 5);
            commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work

            getGLM_InfoAfterStart = new TGet_GLM_Info(LedgerNumber, strAccountStart, strCostCentre);
            getGLM_InfoAfterEnd = new TGet_GLM_Info(LedgerNumber, strAccountEnd, strCostCentre);
            // now both directions are "-" and so the difference is reduced to 5
            Assert.AreEqual(getGLM_InfoBeforeStart.YtdActual + 5, getGLM_InfoAfterStart.YtdActual,
                "Check if 10 has been accounted");
            // strAccountEnd is a credit acount -> in this case "+" too!
            Assert.AreEqual(getGLM_InfoBeforeEnd.YtdActual + 5, getGLM_InfoAfterEnd.YtdActual,
                "Check if 10 has been accounted");
        }
        public void Test_03_ForeignCurrencyAccountingWithWrongForeignValue()
        {
            string strAccountStart = "6001";      // Use an foreign currency account in GBP only
            string strAccountEnd = "9800";        // Use a base currency account only
            string strCostCentre = "4300";

            PrepareTestCaseData();

            TCommonAccountingTool commonAccountingTool =
                new TCommonAccountingTool(LedgerNumber, "NUNIT");
            try
            {
                commonAccountingTool.AddForeignCurrencyJournal("JPY", 0.3m);
                commonAccountingTool.AddForeignCurrencyTransaction(
                    strAccountStart, strCostCentre, "Credit GBP 100", "NUNIT",
                    MFinanceConstants.IS_DEBIT, 100, 333.33m);
                commonAccountingTool.AddForeignCurrencyTransaction(
                    strAccountEnd, strCostCentre, "Debit GBP 100", "NUNIT",
                    MFinanceConstants.IS_CREDIT, 100, 333.33m);
                Assert.Fail("Exception does not appear!");
            }
            catch (EVerificationException)
            {
                // Exception was thrown, which is expected
                // Assert.Pass will throw an exception NUnit.Framework.SuccessException and fail the test???
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.ToString());
                Assert.Fail("Wrong exception thrown");
            }
        }
        public void Test_02_ForeignCurrencyAccounting()
        {
            string strAccountStart = "6001";      // Use an foreign currency account in GBP only
            string strAccountEnd = "9800";        // Use a base currency account only
            string strCostCentre = "4300";

            PrepareTestCaseData();

            // Get the glm-values before and after the test and taking the differences enables
            // to run the test several times
            TGet_GLM_Info getGLM_InfoBeforeStart = new TGet_GLM_Info(LedgerNumber, strAccountStart, strCostCentre);
            TGet_GLM_Info getGLM_InfoBeforeEnd = new TGet_GLM_Info(LedgerNumber, strAccountEnd, strCostCentre);

            TCommonAccountingTool commonAccountingTool =
                new TCommonAccountingTool(LedgerNumber, "NUNIT");

            decimal ExchangeRateEurToGBP = 0.85m;
            decimal AmountInGBP = 100.0m;
            decimal AmountInEUR = (1.0m / ExchangeRateEurToGBP) * AmountInGBP;
            commonAccountingTool.AddForeignCurrencyJournal("GBP", ExchangeRateEurToGBP);

            commonAccountingTool.AddForeignCurrencyTransaction(
                strAccountStart, strCostCentre, "Debit GBP 100", "NUNIT",
                MFinanceConstants.IS_DEBIT, AmountInEUR, AmountInGBP);
            commonAccountingTool.AddForeignCurrencyTransaction(
                strAccountEnd, strCostCentre, "Credit GBP 100", "NUNIT",
                MFinanceConstants.IS_CREDIT, AmountInEUR, AmountInGBP);

            commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work

            TGet_GLM_Info getGLM_InfoAfterStart = new TGet_GLM_Info(LedgerNumber, strAccountStart, strCostCentre);
            TGet_GLM_Info getGLM_InfoAfterEnd = new TGet_GLM_Info(LedgerNumber, strAccountEnd, strCostCentre);

            Assert.AreEqual(Math.Round(getGLM_InfoBeforeStart.YtdActual + AmountInEUR, 2), Math.Round(getGLM_InfoAfterStart.YtdActual, 2),
                "Check if base currency has been accounted to " + strAccountStart);
            Assert.AreEqual(Math.Round(getGLM_InfoBeforeEnd.YtdActual + AmountInEUR, 2), Math.Round(getGLM_InfoAfterEnd.YtdActual, 2),
                "Check if base currency has been accounted to " + strAccountEnd);

            Assert.AreEqual(getGLM_InfoBeforeStart.YtdForeign + AmountInGBP, getGLM_InfoAfterStart.YtdForeign,
                "Check if foreign currency has been accounted");
            Assert.AreEqual(getGLM_InfoBeforeEnd.YtdForeign, getGLM_InfoAfterEnd.YtdForeign,
                "Check if nothing foreign has been accounted on the non foreign currency account");
        }
        public void Test_PEMM_05_Revaluation()
        {
            FLedgerNumber = CommonNUnitFunctions.CreateNewLedger();
            // load foreign currency account 6001
            CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\GL\\" +
                "test-sql\\gl-test-account-data.sql", FLedgerNumber);

            // post a batch for foreign currency account 6001
            TCommonAccountingTool commonAccountingTool =
                new TCommonAccountingTool(FLedgerNumber, "NUNIT");
            commonAccountingTool.AddForeignCurrencyJournal("GBP", 1.1m);
            commonAccountingTool.JournalDescription = "Test foreign currency account";
            string strAccountGift = "0200";
            string strAccountBank = "6001";

            // Accounting of some gifts ...
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountBank, (FLedgerNumber * 100).ToString(), "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 100);

            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountGift, (FLedgerNumber * 100).ToString(), "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 100);

            commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work


            TVerificationResultCollection verificationResult;
            bool blnHasErrors = TPeriodIntervalConnector.TPeriodMonthEnd(
                FLedgerNumber, true, out verificationResult);
            bool blnStatusArrived = false;

            for (int i = 0; i < verificationResult.Count; ++i)
            {
                if (verificationResult[i].ResultCode.Equals(
                        TPeriodEndErrorAndStatusCodes.PEEC_05.ToString()))
                {
                    blnStatusArrived = true;
                    Assert.IsTrue(verificationResult[i].ResultSeverity == TResultSeverity.Resv_Critical,
                        "we need a critical error: need to run revaluation first ...");
                }
            }

            Assert.IsTrue(blnStatusArrived, "Status message has been shown");
            Assert.IsTrue(blnHasErrors, "should fail because revaluation needs to be run first");

            // run revaluation
            blnHasErrors = TRevaluationWebConnector.Revaluate(FLedgerNumber, new TLedgerInfo(
                    FLedgerNumber).CurrentPeriod, new string[] { "GBP" }, new decimal[] { 1.2m }, out verificationResult);

            TLogging.Log(verificationResult.BuildVerificationResultString());
            Assert.IsFalse(blnHasErrors, "Problem running the revaluation");

            blnHasErrors = TPeriodIntervalConnector.TPeriodMonthEnd(
                FLedgerNumber, true, out verificationResult);
            Assert.IsFalse(blnHasErrors, "should now be able to close the month now that the revaluation has been run");
        }
Example #10
0
        private void ReallocationLoop(TGlmpInfo AGlmpInfo, TCommonAccountingTool YearEndBatch, String AAccountFrom, String ACostCentreFrom)
        {
            string strCostCentreTo = TLedgerInfo.GetStandardCostCentre(FledgerInfo.LedgerNumber);
            string strAccountTo;

            FaccountInfo.AccountCode = AAccountFrom;
            Boolean blnDebitCredit = FaccountInfo.DebitCreditIndicator;
            String narrativeMessage = FstrNarrativeToMessage;

            string strCCAccoutCode = FaccountInfo.SetCarryForwardAccount(); // Move FaccountInfo to the Carry Forward Account - if there is one.

            if (FaccountInfo.IsValid) // The CarryForward account exists..
            {
                strAccountTo = FaccountInfo.AccountCode;

                if (strCCAccoutCode == "SAMECC")
                {
                    strCostCentreTo = ACostCentreFrom;
                    narrativeMessage = FstrNarrativeFromToMessage;
                }
            }
            else // If there's no Carry Forward account, use EARNINGS_BF_ACCT
            {
                FaccountInfo.SetSpecialAccountCode(TAccountPropertyEnum.EARNINGS_BF_ACCT);
                strAccountTo = FaccountInfo.AccountCode;
            }

            if (FledgerInfo.IltAccountFlag) // In either case, change that if ICH_ACCT is set
            {
                FaccountInfo.SetSpecialAccountCode(TAccountPropertyEnum.ICH_ACCT);
                strAccountTo = FaccountInfo.AccountCode;
            }

            if (FledgerInfo.BranchProcessing) // Keep the original Cost Centres - don't roll up
            {
                strCostCentreTo = ACostCentreFrom;
                narrativeMessage = FstrNarrativeFromToMessage;
            }

            if (FglmInfo.YtdActualBase < 0)
            {
                blnDebitCredit = !blnDebitCredit;
            }

            Decimal TransactionAmount = Math.Abs(AGlmpInfo.ActualBase);

            YearEndBatch.AddBaseCurrencyTransaction(
                AAccountFrom, ACostCentreFrom,
                String.Format(narrativeMessage, ACostCentreFrom, AAccountFrom, strCostCentreTo, strAccountTo),
                FstrYearEnd, !blnDebitCredit, TransactionAmount);

            YearEndBatch.AddBaseCurrencyTransaction(
                strAccountTo, strCostCentreTo,
                String.Format(narrativeMessage, ACostCentreFrom, AAccountFrom, strCostCentreTo, strAccountTo),
                FstrYearEnd, blnDebitCredit, TransactionAmount);
        }
Example #11
0
        /// <summary>
        /// TReallocation.RunOperation
        /// </summary>
        public override Int32 RunOperation()
        {
            Int32 CountJobs = 0;

            if (FAccountList == null)
            {
                CalculateAccountInfo();
            }

            TCommonAccountingTool YearEndBatch = null;

            if (DoExecuteableCode)
            {
                YearEndBatch = new TCommonAccountingTool(FledgerInfo,
                    Catalog.GetString("Financial year end processing"));
                YearEndBatch.AddBaseCurrencyJournal();
                YearEndBatch.JournalDescription = Catalog.GetString("YearEnd revaluations");
                YearEndBatch.SubSystemCode = CommonAccountingSubSystemsEnum.GL;
            }

            // tCommonAccountingTool.DateEffective =""; Default is "End of actual period ..."
            // Loop with all account codes
            foreach (string strAccountCode in FAccountList)
            {
                FglmInfo = new TGlmInfo(FledgerInfo.LedgerNumber,
                    FledgerInfo.CurrentFinancialYear,
                    strAccountCode);

                while (FglmInfo.MoveNext())
                {
                    Int32 CostCentreRowIdx = FCostCentreTbl.DefaultView.Find(FglmInfo.CostCentreCode);
                    ACostCentreRow currentCostCentre = (ACostCentreRow)FCostCentreTbl.DefaultView[CostCentreRowIdx].Row;

                    if (currentCostCentre.PostingCostCentreFlag)
                    {
                        TGlmpInfo glmpInfo = new TGlmpInfo(-1, -1, FglmInfo.GlmSequence, FledgerInfo.NumberOfAccountingPeriods);

                        if (glmpInfo.ActualBase + FglmInfo.ClosingPeriodActualBase != 0)
                        {
                            if (DoExecuteableCode)
                            {
                                ReallocationLoop(glmpInfo, YearEndBatch, strAccountCode, FglmInfo.CostCentreCode);
                            }

                            CountJobs++;
                        }
                    }
                }
            }

            if (DoExecuteableCode)
            {
                YearEndBatch.CloseSaveAndPost(FverificationResults);
            }

            return CountJobs;
        }