Ejemplo n.º 1
0
 private void LoanPenaltyAccrualOrigination(LoanPenaltyAccrualEvent loanPenaltyAccrualEvent,
                                              Loan loanContract, SqlTransaction sqlTransac)
 {
     _eventManagement.AddLoanEvent(loanPenaltyAccrualEvent, loanContract.Id, sqlTransac);
 }
Ejemplo n.º 2
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;
                        }
            }
        }
Ejemplo n.º 3
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;
                     }
             }
         }
 }
Ejemplo n.º 4
0
        public void AddLoanEvent(LoanPenaltyAccrualEvent pEvent, int contractId, SqlTransaction transaction)
        {
            pEvent.Id = AddLoanEventHead(pEvent, contractId, transaction);
            const string q = @"INSERT INTO [LoanPenaltyAccrualEvents](
                                        [id],
                                        [penalty])
                                     VALUES(@id,
                                        @penalty)";

            using (var c = new OpenCbsCommand(q, transaction.Connection, transaction))
            {
                SetLoanPenaltyAccrualEvent(c, pEvent, pEvent.Penalty);
                c.ExecuteNonQuery();
            }
        }