public void TestExportGifts()
        {
            int       LedgerNumber    = FLedgerNumber;
            string    CostCentre      = "7300";
            string    AcctCode        = "0200";
            string    MonthName       = "January";
            int       PeriodNumber    = 1;
            DateTime  PeriodStartDate = new DateTime(DateTime.Today.Year, 1, 1);
            DateTime  PeriodEndDate   = new DateTime(DateTime.Today.Year, 1, 31);
            string    Base            = MFinanceConstants.CURRENCY_BASE;
            int       IchNumber       = 0;
            DataTable TableForExport  = new DataTable();

            bool NewTransaction = false;

            // otherwise period 1 might have been closed already
            CommonNUnitFunctions.ResetDatabase();

            // need to create gifts first
            TStewardshipCalculationTest.ImportAndPostGiftBatch(PeriodEndDate);

            //Perform stewardship calculation
            TVerificationResultCollection VerificationResults;

            TStewardshipCalculationWebConnector.PerformStewardshipCalculation(FLedgerNumber,
                                                                              PeriodNumber, out VerificationResults);

            VerificationResults = new TVerificationResultCollection();

            //Create DataTable to receive exported transactions
            TableForExport.Columns.Add("CostCentre", typeof(string));
            TableForExport.Columns.Add("Account", typeof(string));
            TableForExport.Columns.Add("LedgerMonth", typeof(string));
            TableForExport.Columns.Add("ICHPeriod", typeof(string));
            TableForExport.Columns.Add("Date", typeof(DateTime));
            TableForExport.Columns.Add("IndividualDebitTotal", typeof(decimal));
            TableForExport.Columns.Add("IndividualCreditTotal", typeof(decimal));

            TGenHOSAFilesReportsWebConnector.ExportGifts(LedgerNumber,
                                                         CostCentre,
                                                         AcctCode,
                                                         MonthName,
                                                         PeriodNumber,
                                                         PeriodStartDate,
                                                         PeriodEndDate,
                                                         Base,
                                                         IchNumber,
                                                         TableForExport,
                                                         VerificationResults);

            TableForExport.AcceptChanges();

            DataRow[] DR = TableForExport.Select();

            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResults,
                                                                                "HOSA - Performing Export of gifts Failed!");

            Assert.IsTrue((DR.Length > 0),
                          "HOSA - Performing Export of gifts Failed to return any rows!");

            if (NewTransaction)
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }
        }
        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");
        }