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_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");
        }
Esempio n. 3
0
        private void CheckForSuspenseAccountsZero()
        {
            if (FledgerInfo.CurrentPeriod == FledgerInfo.NumberOfAccountingPeriods)
            {
                // This means: The last accounting period of the year is running!

                if (getSuspenseAccountInfo == null)
                {
                    getSuspenseAccountInfo =
                        new GetSuspenseAccountInfo(FledgerInfo.LedgerNumber);
                }

                if (getSuspenseAccountInfo.RowCount > 0)
                {
                    ASuspenseAccountRow aSuspenseAccountRow;

                    for (int i = 0; i < getSuspenseAccountInfo.RowCount; ++i)
                    {
                        aSuspenseAccountRow = getSuspenseAccountInfo.Row(i);
                        TGet_GLM_Info get_GLM_Info = new TGet_GLM_Info(FledgerInfo.LedgerNumber,
                            aSuspenseAccountRow.SuspenseAccountCode,
                            FledgerInfo.CurrentFinancialYear);

                        TGlmpInfo get_GLMp_Info = new TGlmpInfo(
                            -1, -1,
                            get_GLM_Info.Sequence,
                            FledgerInfo.CurrentPeriod);

                        if (get_GLMp_Info.RowExists)
                        {
                            TVerificationResult tvr = new TVerificationResult(
                                Catalog.GetString("Non Zero Suspense Account found"),
                                String.Format(Catalog.GetString("Suspense account {0} has the balance value {1}. It is required to be zero."),
                                    getSuspenseAccountInfo.ToString(),
                                    get_GLMp_Info.ActualBase), "",
                                TPeriodEndErrorAndStatusCodes.PEEC_07.ToString(), TResultSeverity.Resv_Critical);
                            FverificationResults.Add(tvr);

                            FHasCriticalErrors = true;
                            FverificationResults.Add(tvr);
                        }
                    }
                }
            }
        }
        public void TestPerformStewardshipCalculation()
        {
            TVerificationResultCollection VerificationResults = new TVerificationResultCollection();

            Int32 PeriodNumber = 5;
            const string CostCentreGIF = "9500";
            const string CostCentreReceivingField = "7300";

            // run possibly empty stewardship calculation, to process all gifts that do not belong to this test
            TStewardshipCalculationWebConnector.PerformStewardshipCalculation(FLedgerNumber,
                PeriodNumber, out VerificationResults);
            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResults,
                "Performing initial Stewardship Calculation Failed!");

            // make sure we have some admin fees
            ImportAdminFees();

            decimal AdminGrantIncomeBefore = new TGet_GLM_Info(FLedgerNumber,
                MFinanceConstants.ADMIN_FEE_INCOME_ACCT,
                (FLedgerNumber * 100).ToString("0000")).YtdActual;
            decimal GIFBefore = new TGet_GLM_Info(FLedgerNumber,
                MFinanceConstants.ICH_ACCT_SETTLEMENT,
                CostCentreGIF).YtdActual;
            decimal RecipientBefore = new TGet_GLM_Info(FLedgerNumber,
                MFinanceConstants.ICH_ACCT_SETTLEMENT,
                CostCentreReceivingField).YtdActual;
            decimal ClearingHouseBefore = new TGet_GLM_Info(FLedgerNumber,
                MFinanceConstants.ICH_ACCT_ICH,
                (FLedgerNumber * 100).ToString("0000")).YtdActual;

            // import new gift batch. use proper period and date effective
            DateTime PeriodStartDate, PeriodEndDate;
            TFinancialYear.GetStartAndEndDateOfPeriod(FLedgerNumber, PeriodNumber, out PeriodStartDate, out PeriodEndDate, null);
            ImportAndPostGiftBatch(PeriodStartDate);

            TStewardshipCalculationWebConnector.PerformStewardshipCalculation(FLedgerNumber,
                PeriodNumber, out VerificationResults);
            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResults,
                "Performing Stewardship Calculation Failed!");

            // Home office keeps 1.40 => 4300/3400 Admin Grant income
            decimal AdminGrantIncomeAfter = new TGet_GLM_Info(FLedgerNumber,
                MFinanceConstants.ADMIN_FEE_INCOME_ACCT,
                (FLedgerNumber * 100).ToString("0000")).YtdActual;
            Assert.AreEqual(20.0m * 7.0m / 100.0m, AdminGrantIncomeAfter - AdminGrantIncomeBefore,
                "Home office keeps 7% of 20 Euro gift");

            // GIF should get 0.20 => 9500/5601
            decimal GIFAfter = new TGet_GLM_Info(FLedgerNumber,
                MFinanceConstants.ICH_ACCT_SETTLEMENT,
                CostCentreGIF).YtdActual;

            Assert.AreEqual(20.0m / 100.0m, GIFAfter - GIFBefore,
                "GIF should get 1% of 20 Euro gift. Before: " + GIFBefore + ", After: " + GIFAfter);

            // Receiving field should get 20-1.60 = 18.40 => 7300/5601
            decimal RecipientAfter = new TGet_GLM_Info(FLedgerNumber,
                MFinanceConstants.ICH_ACCT_SETTLEMENT,
                CostCentreReceivingField).YtdActual;
            Assert.AreEqual(20.0m * (100.0m - 1.0m - 7.0m) / 100.0m, RecipientAfter - RecipientBefore,
                "Receiving field should get 92% of 20 Euro gift");

            // Clearing House (4300/8500) should receive the money for GIF and receiving field
            decimal ClearingHouseAfter = new TGet_GLM_Info(FLedgerNumber,
                MFinanceConstants.ICH_ACCT_ICH,
                (FLedgerNumber * 100).ToString("0000")).YtdActual;
            Assert.AreEqual(20.0m * (100.0m - 7.0m) / 100.0m, ClearingHouseAfter - ClearingHouseBefore,
                "We have to give everything apart from our 7% to ICH");
        }
Esempio n. 5
0
        public void SimpleDocument_ExpectPostingAndPayingWorking()
        {
            //
            // Arrange
            //
            decimal Amount = 399.0m;
            decimal APAccountBalanceBefore;
            decimal ABankAccountBefore;
            decimal AExpAccountBefore;
            TVerificationResultCollection VerificationResult;

            List <int>DocumentIDs;
            int PaymentNumber;
            AAPInfos APInfos;

            CommonNUnitFunctions.ResetDatabase();

            APInfos = PostSimpleAPDocument(Amount, "Test", "Detail Item", out APAccountBalanceBefore, out ABankAccountBefore,
                out AExpAccountBefore, out DocumentIDs);

            //
            // Act: Pay the AP document
            //
            VerificationResult = PayAPDocument(APInfos.ApDS.AApDocument[0].ApDocumentId, Amount,
                APInfos.BankAccount, APInfos.CurrencyCode, APInfos.PeriodEndDate, out PaymentNumber);
            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult);   // Guard Assert

            // Save the current amount on the AP account
            decimal APAccountBalanceAfter = new TGet_GLM_Info(FLedgerNumber,
                APInfos.ApAccountCode, APInfos.CostCentreCode).YtdActual;
            decimal BankAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                APInfos.BankAccount, APInfos.CostCentreCode).YtdActual;

            //
            // Primary Assert: Paying OK?
            //
            // Check the amount on the AP account
            Assert.AreEqual(0.0m, APAccountBalanceAfter - APAccountBalanceBefore, "after paying the invoice, the AP account should be cleared");
            Assert.AreEqual((-1.0m) * Amount, BankAccountAfter - ABankAccountBefore, "after paying the invoice, the bank account should be credited");
        }
Esempio n. 6
0
        private AAPInfos PostAndPayForeignSupplierAPDocument(string ADocumentCode, out int APaymentNumber, out List <int>ADocumentIDs,
            out decimal AAPAccountBalanceBefore, out decimal ABankAccountBefore, out decimal ARevalAccountBefore)
        {
            decimal Amount = 100.0m;
            decimal ExchangeRatePosting = 1.2m;
            decimal ExchangeRatePayment = 1.1m;
            decimal ExpAccountBefore;
            TVerificationResultCollection VerificationResult;
            AAPInfos APInfos;

            APInfos = PostForeignSupplierAPDocument(Amount, ExchangeRatePosting, ADocumentCode, "Detail Item",
                out AAPAccountBalanceBefore, out ABankAccountBefore, out ExpAccountBefore, out ARevalAccountBefore, out ADocumentIDs);

            //
            // Pay the AP document
            //
            VerificationResult = PayAPDocument(APInfos.ApDS.AApDocument[0].ApDocumentId, Amount,
                APInfos.BankAccount, APInfos.CurrencyCode, APInfos.PeriodEndDate, out APaymentNumber, ExchangeRatePayment);
            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult);   // Guard Assert

            // Save the current amount on the AP account and Bank Account
            decimal APAccountBalanceAfter = new TGet_GLM_Info(FLedgerNumber,
                APInfos.ApAccountCode, APInfos.CostCentreCode).YtdActual;
            decimal BankAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                APInfos.BankAccount, APInfos.CostCentreCode).YtdForeign;

            //
            // Guard Assert: Paying OK?
            //
            // Check the amount on the AP account
            Assert.AreEqual(0.0m, APAccountBalanceAfter - AAPAccountBalanceBefore, "after paying the invoice, the AP account should be cleared");
            Assert.AreEqual((-1.0m) * Amount, BankAccountAfter - ABankAccountBefore, "after paying the invoice, the bank account should be credited");

            decimal RevalAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                APInfos.ForexGainsLossesAccount, APInfos.CostCentreCode).YtdActual;

            Assert.AreEqual(
                Math.Round((Amount / ExchangeRatePayment) - (Amount / ExchangeRatePosting), 2),
                Math.Round((RevalAccountAfter - ARevalAccountBefore), 2),
                "after paying the invoice, the revaluation account should be credited with the forex gain");

            return APInfos;
        }
Esempio n. 7
0
        private AAPInfos PostForeignSupplierAPDocument(decimal AAmount, decimal AExchangeRatePosting, string ADocumentCode, string ANarrative,
            out decimal AAPAccountBalanceBefore, out decimal ABankAccountBefore, out decimal AExpAccountBefore,
            out decimal ARevalAccountBefore, out List <int>ADocumentIds)
        {
            TVerificationResultCollection VerificationResult;

            ADocumentIds = new List <int>();

            AAPInfos APInfos = APTestsArrangement(SUPPLIER_FOREIGN_PARTNER_KEY, AAmount, AExchangeRatePosting, ADocumentCode, ANarrative);

            // Save the current amount on the AP account
            AAPAccountBalanceBefore = new TGet_GLM_Info(FLedgerNumber,
                APInfos.ApAccountCode, APInfos.CostCentreCode).YtdActual;
            ABankAccountBefore = new TGet_GLM_Info(FLedgerNumber,
                APInfos.BankAccount, APInfos.CostCentreCode).YtdForeign;

            AExpAccountBefore = new TGet_GLM_Info(FLedgerNumber,
                APInfos.ApDS.AApSupplier[0].DefaultExpAccount,
                APInfos.CostCentreCode).YtdActual;
            ARevalAccountBefore = new TGet_GLM_Info(FLedgerNumber,
                APInfos.ForexGainsLossesAccount,
                APInfos.CostCentreCode).YtdActual;

            VerificationResult = PostAPDocument(APInfos.ApDS, APInfos.PeriodStartDate, ref ADocumentIds);
            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult);   // Guard Assert

            //
            // Guard Assert: Posting OK?
            //
            decimal ExpAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                APInfos.ApDS.AApSupplier[0].DefaultExpAccount,
                APInfos.ApDS.AApSupplier[0].DefaultCostCentre).YtdActual;

            Assert.AreEqual(Math.Round(AAmount / AExchangeRatePosting, 2), Math.Round(ExpAccountAfter - AExpAccountBefore,
                    2), "after posting the invoice, the expense account should be debited the amount in base currency (Exchange Rate is " +
                AExchangeRatePosting + ")");

            return APInfos;
        }
Esempio n. 8
0
        private AAPInfos PostSimpleAPDocument(decimal AAmount, string ADocumentCode, string ANarrative,
            out decimal AAPAccountBalanceBefore, out decimal ABankAccountBefore, out decimal AExpAccountBefore,
            out List <int>ADocumentIds)
        {
            TVerificationResultCollection VerificationResult;

            ADocumentIds = new List <int>();

            AAPInfos APInfos = APTestsArrangement(SUPPLIER_PARTNER_KEY, AAmount, null, ADocumentCode, ANarrative);

            // Save the current amount on the AP account
            AAPAccountBalanceBefore = new TGet_GLM_Info(FLedgerNumber,
                APInfos.ApAccountCode, APInfos.CostCentreCode).YtdActual;
            ABankAccountBefore = new TGet_GLM_Info(FLedgerNumber,
                APInfos.BankAccount, APInfos.CostCentreCode).YtdActual;

            AExpAccountBefore = new TGet_GLM_Info(FLedgerNumber,
                APInfos.ApDS.AApSupplier[0].DefaultExpAccount,
                APInfos.CostCentreCode).YtdActual;

            VerificationResult = PostAPDocument(APInfos.ApDS, APInfos.PeriodStartDate, ref ADocumentIds);
            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult);   // Guard Assert

            //
            // Guard Assert: Posting OK?
            //
            decimal ExpAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                APInfos.ApDS.AApSupplier[0].DefaultExpAccount,
                APInfos.ApDS.AApSupplier[0].DefaultCostCentre).YtdActual;

            Assert.AreEqual(AAmount, ExpAccountAfter - AExpAccountBefore, "after posting the invoice, the expense account should be debited");

            return APInfos;
        }
Esempio n. 9
0
        public void ForeignCurrencySupplier_ExpectDocumentPostingPayingAndReversingWorking()
        {
            //
            // Arrange
            //
            decimal APAccountBalanceBefore;
            decimal BankAccountBefore;
            decimal RevalAccountBefore;
            TVerificationResultCollection VerificationResult;
            int PaymentNumber;

            List <int>DocumentIDs;
            AAPInfos APInfos;

            CommonNUnitFunctions.ResetDatabase();

            // Post and pay a document with a foreign currency supplier
            APInfos = PostAndPayForeignSupplierAPDocument("Test Reverse", out PaymentNumber, out DocumentIDs,
                out APAccountBalanceBefore, out BankAccountBefore, out RevalAccountBefore);


            //
            // Act: Immediately "un-pay" and "un-post" this invoice!
            //
            VerificationResult = ReversePayment(PaymentNumber, APInfos.PeriodEndDate, DocumentIDs, APInfos.ApDS);
            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult);   // Guard Assert

            // Save the current amount on the AP account
            decimal APAccountBalanceAfter = new TGet_GLM_Info(FLedgerNumber,
                APInfos.ApAccountCode, APInfos.CostCentreCode).YtdActual;
            decimal BankAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                APInfos.BankAccount, APInfos.CostCentreCode).YtdForeign;
            decimal RevalAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                APInfos.ForexGainsLossesAccount, APInfos.CostCentreCode).YtdActual;

            //
            // Primary Assert: Reversal OK?
            //
            // Now I can see whether anything is left over by all these
            // various transactions, that should have added up to 0.
            // Check the amount on the AP account
            Assert.AreEqual(APAccountBalanceBefore, APAccountBalanceAfter, "After paying then reversing, the AP account should be as before.");
            Assert.AreEqual(BankAccountBefore, BankAccountAfter, "After paying then reversing, the Bank account should be as before.");
            Assert.AreEqual(
                Math.Round(RevalAccountAfter, 2),
                Math.Round(RevalAccountBefore, 2),
                "After paying then reversing, the Forex Gains/Losses Account account should be as before.");
        }