Esempio n. 1
0
        public void InitManager()
        {
            TechnicalSettings.CheckSettings();

            LoanProductManager loanProductManager = new LoanProductManager(DataUtil.TESTDB);
            AccountingTransactionManager accountingTransactionManager = new AccountingTransactionManager(DataUtil.TESTDB);
            EventManager eventManager = new EventManager(DataUtil.TESTDB);
            ExchangeRateManager exchangeRateManager = new ExchangeRateManager(DataUtil.TESTDB);
            ProvisioningRuleManager provisioningRuleManager = new ProvisioningRuleManager(DataUtil.TESTDB);
            AccountManager accountManager = new AccountManager(DataUtil.TESTDB);
            InstallmentTypeManager installmentTypeManager = new InstallmentTypeManager(DataUtil.TESTDB);
            UserManager userManager = new UserManager(DataUtil.TESTDB);
            EconomicActivityManager economicActivityManager = new EconomicActivityManager(DataUtil.TESTDB);
            InstallmentManager installmentManager = new InstallmentManager(DataUtil.TESTDB);
            FundingLineManager fundingLineManager = new FundingLineManager(DataUtil.TESTDB);
            ClientManager clientManager = new ClientManager(DataUtil.TESTDB);
            LocationsManager locationsManager = new LocationsManager(DataUtil.TESTDB);
            LoanManager loanManager = new LoanManager(DataUtil.TESTDB);
            ProjectManager projectManager = new ProjectManager(DataUtil.TESTDB);
            MFIManager mfiManager = new MFIManager(DataUtil.TESTDB);
            SavingManager savingManager = new SavingManager(DataUtil.TESTDB);
            SavingProductManager savingProductManager = new SavingProductManager(DataUtil.TESTDB);
            SavingEventManager savingEventManager = new SavingEventManager(DataUtil.TESTDB);
            CurrencyManager currencyManager = new CurrencyManager(DataUtil.TESTDB);
            AccountingRuleManager accountingRuleManager = new AccountingRuleManager(DataUtil.TESTDB);
            FundingLineServices fundingLineServices = new FundingLineServices(DataUtil.TESTDB);

            container = new Hashtable
                            {
                                {"LoanProductManager", loanProductManager},
                                {"AccountingTransactionManager", accountingTransactionManager},
                                {"EventManager", eventManager},
                                {"ExchangeRateManager", exchangeRateManager},
                                {"ProvisioningRuleManager", provisioningRuleManager},
                                {"AccountManager", accountManager},
                                {"InstallmentTypeManager", installmentTypeManager},
                                {"UserManager", userManager},
                                {"FundingLineManager", fundingLineManager},
                                {"LoanManager", loanManager},
                                {"ClientManager", clientManager},
                                {"LocationsManager", locationsManager},
                                {"ProjectManager", projectManager},
                                {"EconomicActivityManager", economicActivityManager},
                                {"InstallmentManager", installmentManager},
                                {"MFIManager", mfiManager},
                                {"SavingManager", savingManager},
                                {"SavingProductManager", savingProductManager},
                                {"SavingEventManager", savingEventManager},
                                {"CurrencyManager", currencyManager},
                                {"FundingLineServices", fundingLineServices},
                                {"AccountingRuleManager", accountingRuleManager}
                            };
        }
Esempio n. 2
0
        public EventProcessorServices(User pUser,string testDB)
        {
            _user = pUser;

            _eventManagement = new EventManager(testDB);
            _savingEventManagement = new SavingEventManager(testDB);
            _movementSetManagement = new AccountingTransactionManager(testDB);
            _loanManager = new LoanManager(testDB);
            _packageManager = new LoanProductManager(testDB);
            _clientManagement = new ClientManager(testDB);
            _accountingServices = new Accounting.AccountingServices(testDB);

            _InitializeEventProcessor();
        }
Esempio n. 3
0
 public EventProcessorServices(EventManager eventManagement)
 {
     _eventManagement = eventManagement;
     _InitializeEventProcessor();
 }
Esempio n. 4
0
 public EventProcessorServices(EventManager eventManagement,AccountingTransactionManager movementSetManagement,LoanManager loanManager,
     AccountManager accountManagement)
 {
     _eventManagement = eventManagement;
     _movementSetManagement = movementSetManagement;
     _loanManager = loanManager;
     _InitializeEventProcessor();
 }
Esempio n. 5
0
 public void LoanPenaltyAccrual()
 {
     var launchDate = DateTime.Today;
     var listOfLoans = _loanManager.GetListOfLoansToAccruePenalty(launchDate);
     var em = new EventManager(User.CurrentUser);
     using (var connection=_loanManager.GetConnection())
         foreach (var item in listOfLoans)
         {
             var date = item.Value;
             while (date < launchDate)
             {
                 date = date.AddDays(1);
                 var penaltyEvent = new LoanPenaltyAccrualEvent
                     {
                         Penalty = _loanManager.GetDailyPenaltyForLoan(item.Key, date),
                         Date = date,
                         User = User.CurrentUser,
                         ContracId = item.Key
                     };
                 using (var transaction = connection.BeginTransaction())
                     try
                     {
                         em.AddLoanEvent(penaltyEvent, penaltyEvent.ContracId, transaction);
                         transaction.Commit();
                     }
                     catch (Exception)
                     {
                         transaction.Rollback();
                         //throw;
                     }
             }
         }
 }
Esempio n. 6
0
 public void LoanInterestAccrual(DateTime launchDate)
 {
     var listOfLoans = _loanManager.GetListOfLoansToAccrueInterest(launchDate);
     var em = new EventManager(User.CurrentUser);
     using (var connection = _loanManager.GetConnection())
         foreach (var item in listOfLoans)
         {
             var date = item.Value;
             var loan = SelectLoan(item.Key, true, false, false);
             while (date < launchDate)
             {
                 date = date.AddDays(1);
                 var interest = GetDailyInterestForLoan(loan, date);
                 if (interest <= 0) continue;
                 var interestEvent = new LoanInterestAccrualEvent
                 {
                     Interest = interest,
                     Date = date,
                     User = User.CurrentUser,
                     ContracId = item.Key
                 };
                 using (var transaction = connection.BeginTransaction())
                     try
                     {
                         _ePs.FireEvent(interestEvent, loan, transaction);
                         CallInterceptor(new Dictionary<string, object>
                         {
                             {"Loan", loan},
                             {"Event", interestEvent},
                             {"SqlTransaction", transaction}
                         });
                         transaction.Commit();
                     }
                     catch (Exception)
                     {
                         transaction.Rollback();
                         //throw;
                     }
             }
         }
 }
Esempio n. 7
0
        public void GenerateLoanTransitionEvent()
        {
            var em = new EventManager(User.CurrentUser);
            var date = _loanManager.LastLoanTransitionEventDate();

            while (date.Date < DateTime.Now.Date)
            {
                date = date.AddDays(1);
                using (var connection = _loanManager.GetConnection())
                using (var transaction = connection.BeginTransaction())
                    try
                    {
                        var glll = _loanManager.GetListOfTransitionToLateLoan(date);
                        var transitionEventList = glll.Select(item => new LoanTransitionEvent
                            {
                                Code = "GLLL",
                                Date = date,
                                User = User.CurrentUser,
                                Amount = item.Value,
                                ContracId = item.Key
                            }).ToList();

                        //var llgl = _loanManager.GetListOfTransitionToGoodLoan(date);
                        //transitionEventList.AddRange(llgl.Select(item => new LoanTransitionEvent
                        //    {
                        //        Code = "LLGL",
                        //        Date = date,
                        //        User = User.CurrentUser,
                        //        Amount = item.Value,
                        //        ContracId = item.Key
                        //    }));

                        foreach (var transitionEvent in transitionEventList)
                            em.AddLoanEvent(transitionEvent, transitionEvent.ContracId, transaction);

                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
            }
        }
Esempio n. 8
0
 public LoanManager(string pTestDb)
     : base(pTestDb)
 {
     _user = User.CurrentUser;
     _userManager = new UserManager(pTestDb);
     _packageManager = new LoanProductManager(pTestDb);
     _installmentTypeManagement = new InstallmentTypeManager(pTestDb);
     _installmentManagement = new InstallmentManager(pTestDb);
     _eventManagement = new EventManager(pTestDb);
     _fundingLineManager = new FundingLineManager(pTestDb);
     _collateralProductManager = new CollateralProductManager(pTestDb);
     _paymentMethodManager = new PaymentMethodManager(pTestDb);
     _economicActivityManager = new EconomicActivityManager(pTestDb);
 }
Esempio n. 9
0
 public LoanManager(User pUser)
     : base(pUser)
 {
     _user = pUser;
     _userManager = new UserManager(pUser);
     _paymentMethodManager = new PaymentMethodManager(pUser);
     _packageManager = new LoanProductManager(pUser);
     _installmentTypeManagement = new InstallmentTypeManager(pUser);
     _installmentManagement = new InstallmentManager(pUser);
     _eventManagement = new EventManager(pUser);
     _fundingLineManager = new FundingLineManager(pUser);
     _projectManager = new ProjectManager(pUser, false);
     _clientManager = new ClientManager(pUser, false, false);
     _collateralProductManager = new CollateralProductManager(pUser);
     _economicActivityManager = new EconomicActivityManager(pUser);
 }
Esempio n. 10
0
 public LoanManager(string pTestDb, User pUser)
     : base(pTestDb)
 {
     _user = pUser;
     _userManager = new UserManager(pTestDb, _user);
     _packageManager = new LoanProductManager(pTestDb);
     _installmentTypeManagement = new InstallmentTypeManager(pTestDb);
     _installmentManagement = new InstallmentManager(pTestDb);
     _eventManagement = new EventManager(pTestDb);
     _fundingLineManager = new FundingLineManager(pTestDb);
     _clientManager = new ClientManager(pTestDb);
     _collateralProductManager = new CollateralProductManager(pTestDb);
     _paymentMethodManager = new PaymentMethodManager(pTestDb, pUser);
 }
Esempio n. 11
0
        protected override void SetUp()
        {
            base.SetUp();

            _accountingRuleManager = (AccountingRuleManager)container["AccountingRuleManager"];
            _accountManager = (AccountManager)container["AccountManager"];
            _loanProductManager = (LoanProductManager)container["LoanProductManager"];
            _savingProductManager = (SavingProductManager)container["SavingProductManager"];
            _economicActivityManager = (EconomicActivityManager)container["EconomicActivityManager"];
            _fundingLineManager = (FundingLineManager)container["FundingLineManager"];
            _eventManager = (EventManager)container["EventManager"];

            Assert.IsNotNull(_accountingRuleManager);
            Assert.IsNotNull(_accountManager);
            Assert.IsNotNull(_loanProductManager);
            Assert.IsNotNull(_savingProductManager);
            Assert.IsNotNull(_economicActivityManager);
            Assert.IsNotNull(_fundingLineManager);
            Assert.IsNotNull(_eventManager);
        }
Esempio n. 12
0
        public void GenerateLoanTransitionEvent()
        {
            const string glll = @"SELECT id, olb, late_days
                            FROM dbo.ActiveLoans(@date, 0)
                            WHERE late_days = 1";
            const string llgl = @"SELECT a1.id,a1.olb,a1.late_days
                            FROM dbo.ActiveLoans(@date, 0) a1
                            INNER JOIN dbo.ActiveLoans(DATEADD(dd,-1,@date), 0) a2 ON a2.id = a1.id
                            WHERE a1.late_days = 0 and a2.late_days>0";
            var user = ServicesProvider.GetInstance().GetUserServices().Find(1);
            var em = new EventManager(user);
            var date = LastLoanTransitionEventDate();

            while (date.Date < DateTime.Now.Date)
            {
                date = date.AddDays(1);
                using (var connection = _loanManager.GetConnection())
                using (var transaction = connection.BeginTransaction())
                    try
                    {
                        var transitionEventList = new List<LoanTransitionEvent>();
                        using (var c = new OpenCbsCommand(glll, connection, transaction))
                        {
                            c.AddParam("@date", date);

                            using (var r = c.ExecuteReader())
                            {
                                while (r.Read())
                                {
                                    var loanId = r.GetInt("id");
                                    var amount = r.GetDecimal("olb");

                                    var transitionEvent = new LoanTransitionEvent
                                    {
                                        Code = "GLLL",
                                        Date = date,
                                        User = user,
                                        Amount = amount,
                                        ContracId = loanId
                                    };
                                    transitionEventList.Add(transitionEvent);
                                }
                            }
                        }
                        using (var c = new OpenCbsCommand(llgl, connection, transaction))
                        {
                            c.AddParam("@date", date);

                            using (var r = c.ExecuteReader())
                            {
                                while (r.Read())
                                {
                                    var loanId = r.GetInt("id");
                                    var amount = r.GetDecimal("olb");

                                    var transitionEvent = new LoanTransitionEvent
                                    {
                                        Code = "LLGL",
                                        Date = date,
                                        User = user,
                                        Amount = amount,
                                        ContracId = loanId
                                    };
                                    transitionEventList.Add(transitionEvent);
                                }
                            }
                        }
                        foreach (var transitionEvent in transitionEventList)
                            em.AddLoanEvent(transitionEvent, transitionEvent.ContracId, transaction);

                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
            }
        }
Esempio n. 13
0
        public void LoanPenaltyAccrual()
        {
            const string q = @"SELECT al.id AS id,
                                    al.amount * cr.non_repayment_penalties_based_on_initial_amount +
                                    al.olb * cr.non_repayment_penalties_based_on_olb +
                                    al.principal_due * cr.non_repayment_penalties_based_on_overdue_principal +
                                    al.interest_due * cr.non_repayment_penalties_based_on_overdue_interest AS penalty,
                                    al.late_days
                                    FROM dbo.ActiveLoans(@date, 0) AS al
                                    LEFT JOIN dbo.Credit AS cr ON cr.id=al.id
                                    WHERE al.late_days > 0";
            var user = ServicesProvider.GetInstance().GetUserServices().Find(1);
            var em = new EventManager(user);
            var date = LastPenaltyAccrualEventDate();

            while (date.Date < DateTime.Now.Date)
            {
                date = date.AddDays(1);
                using (var connection = _loanManager.GetConnection())
                    using (var transaction = connection.BeginTransaction())
                        try
                        {
                            var penaltyEventList = new List<LoanPenaltyAccrualEvent>();
                            using (var c = new OpenCbsCommand(q, connection, transaction))
                            {
                                c.AddParam("@date", date);

                                using (var r = c.ExecuteReader())
                                {
                                    while (r.Read())
                                    {
                                        var loanId = r.GetInt("id");
                                        var penalty = r.GetDouble("penalty");

                                        var penaltyEvent = new LoanPenaltyAccrualEvent
                                            {
                                                Date = date,
                                                User = user,
                                                Penalty = Convert.ToDecimal(penalty),
                                                ContracId = loanId
                                            };
                                        penaltyEventList.Add(penaltyEvent);
                                    }
                                }
                                foreach (var penaltyEvent in penaltyEventList)
                                    em.AddLoanEvent(penaltyEvent, penaltyEvent.ContracId, transaction);
                            }
                            transaction.Commit();
                        }
                        catch (Exception)
                        {
                            transaction.Rollback();
                            throw;
                        }
            }
        }
Esempio n. 14
0
        public void LoanInterestAccrual()
        {
            const string q = @"WITH summary AS (SELECT al.id
                                                    ,inst.interest
                                                    ,inst.expected_date
                                                    ,ROW_NUMBER() OVER(PARTITION BY al.id
                                                                                 ORDER BY al.id) AS rk
                                                    FROM Activeloans(@date,0) AS al
                                                        LEFT JOIN InstallmentSnapshot(@date) AS inst ON inst.contract_id=al.id
                                                        WHERE @date < inst.expected_date)
                                SELECT s.id, s.interest, s.expected_date
                                FROM summary s
                                WHERE s.rk = 1";
            const string q1 = @"SELECT TOP 1 date FROM (
                                            SELECT MAX(inst.expected_date) AS date
                                                FROM Activeloans(@date, 0) AS al
                                                LEFT JOIN InstallmentSnapshot(@date) AS inst ON inst.contract_id=al.id
                                                WHERE @date >= inst.expected_date AND al.id=@contractId
                                                group by al.id
                                            UNION ALL
                                            SELECT start_date
                                                FROM Contracts
                                                WHERE id=@contractId) t ORDER by date desc";
            var user = ServicesProvider.GetInstance().GetUserServices().Find(1);
            var em = new EventManager(user);
            var date = LastInterestAccrualEventDate();
            while (date.Date < DateTime.Now.Date)
            {
                date = date.AddDays(1);
                using (var connection = _loanManager.GetConnection())
                using (var transaction = connection.BeginTransaction())
                    try
                    {
                        var interestEventList = new List<LoanInterestAccrualEvent>();
                        using (var c = new OpenCbsCommand(q, connection, transaction))
                        {
                            c.AddParam("@date", date);

                            using (var r = c.ExecuteReader())
                            {
                                while (r.Read())
                                {
                                    var loanId = r.GetInt("id");
                                    var interest = r.GetDecimal("interest");
                                    var expectedDate = r.GetDateTime("expected_date");

                                    var interestEvent = new LoanInterestAccrualEvent
                                        {
                                            Date = date,
                                            User = user,
                                            Interest = interest,
                                            InstallmentExpectedDate = expectedDate,
                                            ContracId = loanId
                                        };
                                    interestEventList.Add(interestEvent);
                                }
                            }
                        }
                        foreach (var interestEvent in interestEventList)
                        {
                            var previousInstallmentDate = new DateTime();
                            using (var c = new OpenCbsCommand(q1, connection, transaction))
                            {
                                c.AddParam("@date", date);
                                c.AddParam("@contractId", interestEvent.ContracId);
                                using (var r = c.ExecuteReader())
                                {
                                    r.Read();
                                    previousInstallmentDate = r.GetDateTime("date");
                                }
                            }
                            var passedPeriod = interestEvent.Date - previousInstallmentDate;
                            if (passedPeriod.Days > 30)
                                interestEvent.Interest = 0;
                            else if (interestEvent.Date == interestEvent.InstallmentExpectedDate)
                                interestEvent.Interest -= GetSumOfAccruedInterests(interestEvent.Date,
                                                                                   previousInstallmentDate,
                                                                                   interestEvent.ContracId);
                            else
                                interestEvent.Interest = interestEvent.Interest.Value/30;

                            em.AddLoanEvent(interestEvent, interestEvent.ContracId, transaction);
                        }
                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
            }
        }