Example #1
0
        public void TestLifeTime()
        {
            var ei = new EarnedInterest(
                m_oDB,
                EarnedInterest.WorkingMode.ForPeriod,
                false,
                new DateTime(2012, 9, 1, 0, 0, 0, DateTimeKind.Utc),
                DateTime.UtcNow,
                m_oLog
                );

            ei.VerboseLogging = true;

            ei.Run();
        }         // TestLifeTime
Example #2
0
        public void TestOneDay()
        {
            var ei = new EarnedInterest(
                m_oDB,
                EarnedInterest.WorkingMode.ForPeriod,
                false,
                new DateTime(2014, 8, 23, 0, 0, 0, DateTimeKind.Utc),
                new DateTime(2014, 8, 24, 0, 0, 0, DateTimeKind.Utc),
                m_oLog
                );

            ei.VerboseLogging = true;

            ei.Run();
        } // TestOneDay
Example #3
0
        private static void TestEarnedInterest(AConnection oDB, ASafeLog log)
        {
            var ea = new EarnedInterest(
                oDB,
                EarnedInterest.WorkingMode.ByIssuedLoans,
                false,
                new DateTime(2012, 9, 1),
                new DateTime(2018, 3, 8),
                log
                )
            {
                VerboseLogging = true
            };

            ea.Run();
        }
        }         // Name

        public override void Execute()
        {
            Log.Debug(
                "Update started for date '{0}' keeping {1} history...",
                this.todayStr,
                this.daysToKeep == 0 ? "entire" : Grammar.Number(this.daysToKeep, "day") + " of"
                );

            SortedDictionary <int, decimal> earnedInterestByPeriodsList = new EarnedInterest(
                DB,
                EarnedInterest.WorkingMode.ForPeriod,
                false,
                this.today,
                this.today.AddDays(1),
                Log
                ).Run();

            SortedDictionary <int, decimal> earnedInterestBySomeDateList = new EarnedInterest(
                DB,
                EarnedInterest.WorkingMode.ForPeriod,
                true,
                this.today,
                this.today.AddDays(1),
                Log
                ).Run();

            decimal totalEarnedInterestByPeriods  = 0;
            decimal totalEarnedInterestBySomeDate = 0;

            List <int> union = earnedInterestByPeriodsList.Keys.Union(earnedInterestBySomeDateList.Keys).ToList();

            var updatePkg = new List <UpdatePkgRow>();

            foreach (int loanID in union)
            {
                decimal byPeriods = earnedInterestByPeriodsList.ContainsKey(loanID)
                                        ? earnedInterestByPeriodsList[loanID]
                                        : 0;

                decimal bySomeDate = earnedInterestBySomeDateList.ContainsKey(loanID)
                                        ? earnedInterestBySomeDateList[loanID]
                                        : 0;

                totalEarnedInterestByPeriods  += byPeriods;
                totalEarnedInterestBySomeDate += bySomeDate;

                Log.Debug(
                    "On {0} for loan ID {1} earned interest is: by periods {2}, by some date {3}.",
                    this.todayStr,
                    loanID,
                    byPeriods.ToString("C2", Library.Instance.Culture),
                    bySomeDate.ToString("C2", Library.Instance.Culture)
                    );

                updatePkg.Add(new UpdatePkgRow {
                    LoanID  = loanID,
                    TheDate = this.today,
                    EarnedInterestByPeriods  = byPeriods,
                    EarnedInterestBySomeDate = bySomeDate,
                });
            }             // for each

            Log.Debug(
                "On {0} for {1} total earned interest is: by periods {2}, by some date {3}.",
                this.todayStr,
                Grammar.Number(union.Count, "loan"),
                totalEarnedInterestByPeriods.ToString("C2", Library.Instance.Culture),
                totalEarnedInterestBySomeDate.ToString("C2", Library.Instance.Culture)
                );

            if (updatePkg.Count > 0)
            {
                DB.ExecuteNonQuery(
                    "UpdateDailyLoanStats",
                    CommandSpecies.StoredProcedure,
                    new QueryParameter("DaysToKeep", this.daysToKeep),
                    new QueryParameter("Now", this.today),
                    DB.CreateTableParameter <UpdatePkgRow>("UpdatePkg", updatePkg)
                    );
            }
            else
            {
                Log.Debug("Not updating: nothing to update.");
            }

            Log.Debug(
                "Update complete for date '{0}' keeping {1} history...",
                this.todayStr,
                this.daysToKeep == 0 ? "entire" : Grammar.Number(this.daysToKeep, "day") + " of"
                );
        }         // Execute