示例#1
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);
        }
示例#2
0
        public void ForeignCurrencySupplier_ExpectDocumentPostingPayingAndReversingWorking()
        {
            //
            // Arrange
            //
            decimal APAccountBalanceBefore;
            decimal BankAccountBefore;
            decimal RevalAccountBefore;
            TVerificationResultCollection VerificationResult;
            int PaymentNumber;

            List <int> DocumentIDs;
            AAPInfos   APInfos;

            CommonNUnitFunctions.ResetDatabase();
            TPetraServerConnector.Connect();

            TDataBase      db          = DBAccess.Connect("ForeignCurrencySupplier_ExpectDocumentPostingPayingAndReversingWorking");
            TDBTransaction transaction = db.BeginTransaction(IsolationLevel.Serializable);

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

            transaction.Commit();
            transaction = db.BeginTransaction(IsolationLevel.Serializable);

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

            transaction.Commit();
            transaction = db.BeginTransaction(IsolationLevel.Serializable);

            // Save the current amount on the AP account
            decimal APAccountBalanceAfter = new TGet_GLM_Info(FLedgerNumber,
                                                              APInfos.ApAccountCode, APInfos.CostCentreCode, db).YtdActual;
            decimal BankAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                                                         APInfos.BankAccount, APInfos.CostCentreCode, db).YtdForeign;
            decimal RevalAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                                                          APInfos.ForexGainsLossesAccount, APInfos.CostCentreCode, db).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.");

            transaction.Commit();
        }
示例#3
0
        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

            // ** NOTE! Both of these initially return empty data because the GLMInfo line doesn't exist.
            //          When they are later used in a comparison, 0 is returned for the non-existant rows.
            //          And the test succeeds by a fortunate accident!

            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");
        }
示例#4
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();
            TPetraServerConnector.Connect();

            TDataBase      db          = DBAccess.Connect("SimpleDocument_ExpectPostingAndPayingWorking");
            TDBTransaction transaction = db.BeginTransaction(IsolationLevel.Serializable);

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

            transaction.Commit();
            transaction = db.BeginTransaction(IsolationLevel.Serializable);

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

            transaction.Commit();

            // Save the current amount on the AP account
            decimal APAccountBalanceAfter = new TGet_GLM_Info(FLedgerNumber,
                                                              APInfos.ApAccountCode, APInfos.CostCentreCode, db).YtdActual;
            decimal BankAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                                                         APInfos.BankAccount, APInfos.CostCentreCode, db).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");
        }
示例#5
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);

                        if (get_GLM_Info.GLMExists)
                        {
                            TGlmpInfo get_GLMp_Info = new TGlmpInfo(FledgerInfo.LedgerNumber);
                            get_GLMp_Info.LoadBySequence(get_GLM_Info.Sequence, FledgerInfo.CurrentPeriod);

                            if (get_GLMp_Info.RowExists && (get_GLMp_Info.ActualBase != 0))
                            {
                                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);
                            }
                        }
                    }
                }
            }
        } // CheckFor SuspenseAccountsZero
示例#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);
        }
示例#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);
        }
        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");
        }
示例#9
0
        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

            // ** NOTE! Both of these initially return empty data because the GLMInfo line doesn't exist.
            //          When they are later used in a comparison, 0 is returned for the non-existant rows,
            //          And the test succeeds by a fortunate accident!
            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 TestAdjustGiftBatch()
        {
            int GiftBatchNumber = ImportAndPostGiftBatch();

            TGet_GLM_Info getGLM_InfoBeforeTest73 = new TGet_GLM_Info(FLedgerNumber, "0200", "7300");
            TGet_GLM_Info getGLM_InfoBeforeTest35 = new TGet_GLM_Info(FLedgerNumber, "0200", "3500");

            string formletterTemplateFile = TAppSettingsManager.GetValue("ReceiptTemplate.file",
                                                                         "../../csharp/ICT/Testing/lib/MFinance/SampleData/AnnualReceiptTemplate.html");
            Encoding     encodingOfHTMLfile = TTextFile.GetFileEncoding(formletterTemplateFile);
            StreamReader sr          = new StreamReader(formletterTemplateFile, encodingOfHTMLfile, false);
            string       FileContent = sr.ReadToEnd();

            sr.Close();

            string receiptsBefore;
            string receiptsPDF;

            TReceiptingWebConnector.CreateAnnualGiftReceipts(FLedgerNumber, "Annual",
                                                             new DateTime(DateTime.Today.Year, 1, 1), new DateTime(DateTime.Today.Year, 12, 31),
                                                             FileContent, null, String.Empty, null, String.Empty, "de-DE",
                                                             out receiptsPDF, out receiptsBefore);
            Assert.AreNotEqual(0, receiptsBefore.Trim().Length, "old receipt must not be empty");

            int AdjustBatchNumber;

            TAdjustmentWebConnector.GiftRevertAdjust(FLedgerNumber,
                                                     GiftBatchNumber, -1, false, -1,
                                                     DateTime.Today, GiftAdjustmentFunctionEnum.AdjustGift,
                                                     false, -1.0m, out AdjustBatchNumber);

            bool         BatchIsUnposted;
            string       CurrencyCode;
            GiftBatchTDS BatchTDS = TGiftTransactionWebConnector.LoadGiftTransactionsForBatch(
                FLedgerNumber, AdjustBatchNumber, out BatchIsUnposted, out CurrencyCode);

            // find the transaction to modify
            Int32 ToModify = (BatchTDS.AGiftDetail[1].GiftTransactionNumber == 2)?1:0;

            // change the amount from 20 to 25
            BatchTDS.AGiftDetail[ToModify].GiftTransactionAmount = 25;
            // the money should go to field 35 instead of field 73
            BatchTDS.AGiftDetail[ToModify].RecipientKey = 35000000;
            // TODO change of donor
            // BatchTDS.Gift[1].DonorKey =

            TVerificationResultCollection VerificationResult;

            if (TGiftTransactionWebConnector.SaveGiftBatchTDS(ref BatchTDS, out VerificationResult) != TSubmitChangesResult.scrOK)
            {
                Assert.Fail("Adjustment Gift Batch was not saved: " + VerificationResult.BuildVerificationResultString());
            }

            int generatedGlBatchNumber;

            if (!TGiftTransactionWebConnector.PostGiftBatch(FLedgerNumber, AdjustBatchNumber, out generatedGlBatchNumber, out VerificationResult))
            {
                Assert.Fail("Adjustment Gift Batch was not posted: " + VerificationResult.BuildVerificationResultString());
            }

            TGet_GLM_Info getGLM_InfoAfterTest73 = new TGet_GLM_Info(FLedgerNumber, "0200", "7300");
            TGet_GLM_Info getGLM_InfoAfterTest35 = new TGet_GLM_Info(FLedgerNumber, "0200", "3500");

            // Test balance on the related account/Costcentre
            Assert.AreEqual(getGLM_InfoBeforeTest73.YtdActual - 20, getGLM_InfoAfterTest73.YtdActual, "The amount of 20 should be derived from the 73 costcentre");
            Assert.AreEqual(getGLM_InfoBeforeTest35.YtdActual + 25, getGLM_InfoAfterTest35.YtdActual, "The amount of 25 should be added to the 35 costcentre");

            // Test the number of rows on the gift receipt.
            // the difference should be 3 lines removed, 3 lines added. no double donations.
            string receiptsAfter;

            TReceiptingWebConnector.CreateAnnualGiftReceipts(FLedgerNumber, "Annual",
                                                             new DateTime(DateTime.Today.Year, 1, 1), new DateTime(DateTime.Today.Year, 12, 31),
                                                             FileContent, null, String.Empty, null, String.Empty, "de-DE",
                                                             out receiptsPDF, out receiptsAfter);
            receiptsBefore = THttpBinarySerializer.DeserializeFromBase64(receiptsBefore);
            receiptsAfter  = THttpBinarySerializer.DeserializeFromBase64(receiptsAfter);

            TLogging.Log("TestAdjustGiftBatch Diff:");
            TLogging.Log(TTextFile.Diff(receiptsBefore, receiptsAfter));
            string[] diff = TTextFile.Diff(receiptsBefore, receiptsAfter).Trim().Split(Environment.NewLine);
            Assert.AreEqual(6, diff.Length, "difference on receipts are 6 lines");
        }