public void Add_LoanInterestAccruingEvent() { EventManager eventManager = (EventManager)container["EventManager"]; AccruedInterestEvent loanInterestAccruingEvent = new AccruedInterestEvent { Id = 15, User = new User { Id = 1 }, Date = new DateTime(2006, 7, 21), Interest = 99, AccruedInterest = 3, Rescheduled = true, InstallmentNumber = 4 }; eventManager.AddLoanEvent(loanInterestAccruingEvent, 1); Assert.AreNotEqual(0, loanInterestAccruingEvent.Id); }
private void LoanInterestAccruingOrigination(AccruedInterestEvent loanInterestAccruingEvent, Loan loanContract, SqlTransaction sqlTransac) { _eventManagement.AddLoanEvent(loanInterestAccruingEvent, loanContract.Id, sqlTransac); }
public Loan AddAccruedInterestEvent(Loan loan, AccruedInterestEvent accruedInterestEvent, SqlTransaction sqlTransaction) { try { _ePs.FireEvent(accruedInterestEvent, loan, sqlTransaction); return loan; } catch (Exception ex) { sqlTransaction.Rollback(); throw ex; } }
public Loan AddAccruedInterestEvent(Loan loan, AccruedInterestEvent accruedInterestEvent) { using (SqlConnection conn = _savingEventManager.GetConnection()) using (SqlTransaction sqlTransaction = conn.BeginTransaction()) { try { _ePs.FireEvent(accruedInterestEvent, loan, sqlTransaction); //loan.Events.Add(accruedInterestEvent); sqlTransaction.Commit(); sqlTransaction.Dispose(); return loan; } catch (Exception ex) { sqlTransaction.Rollback(); throw ex; } } }
public void Select_Added_LoanInterestAccruingEvent() { EventManager eventManager = (EventManager)container["EventManager"]; AccruedInterestEvent loanInterestAccruingEvent = new AccruedInterestEvent { Id = 15, User = new User { Id = 1 }, Date = new DateTime(2006, 7, 21), Interest = 99, AccruedInterest = 3, Rescheduled = true, InstallmentNumber = 4 }; eventManager.AddLoanEvent(loanInterestAccruingEvent, 1); EventStock eventStock = eventManager.SelectEvents(2); foreach (Event e in eventStock.GetEvents()) { if (e is AccruedInterestEvent) _AssertLoanInterestAccruingEvent(e as AccruedInterestEvent, new DateTime(2006, 7, 21), 99, 3, true, 4,false); } }
private static void _AssertLoanInterestAccruingEvent(AccruedInterestEvent pEvent, DateTime pDate, OCurrency pInterestPrepayment, OCurrency pAccruedInterest, bool pRescheduled, int pInstallmentNumber, bool pDeleted) { Assert.AreEqual("LIAE", pEvent.Code); Assert.AreEqual(pDate, pEvent.Date); Assert.AreEqual(pInterestPrepayment.Value, pEvent.Interest.Value); Assert.AreEqual(pAccruedInterest.Value, pEvent.AccruedInterest.Value); Assert.AreEqual(pRescheduled, pEvent.Rescheduled); Assert.AreEqual(pInstallmentNumber, pEvent.InstallmentNumber); Assert.AreEqual(pDeleted, pEvent.Deleted); }
public AccruedInterestEvent GetAccruedInterestEvent(DateTime currentDate) { AccruedInterestEvent accruedInterestEvent = new AccruedInterestEvent { User = User.CurrentUser, Date = TimeProvider.Now, Description = Code, ContracId = Id }; OCurrency accruedAmount = 0; DateTime ceaseLateDate = InstallmentList[0].ExpectedDate; foreach (Installment installment in InstallmentList) { if (!installment.IsRepaid) { ceaseLateDate = installment.ExpectedDate; break; } } ceaseLateDate = ceaseLateDate.AddDays(_generalSettings.CeaseLateDays); foreach (Installment installment in InstallmentList) { if (installment.ExpectedDate <= currentDate) { accruedAmount += installment.InterestsRepayment; } DateTime date = installment.Number == 1 ? StartDate : GetInstallment(installment.Number - 2).ExpectedDate; //!installment.IsRepaid && if (installment.ExpectedDate > currentDate && date <= currentDate) { // do not calculate more then cease Late Days if (ceaseLateDate < currentDate) currentDate = ceaseLateDate; int days = (currentDate - date).Days; int daysInInstallment = installment.Number == 1 ? (installment.ExpectedDate - StartDate).Days : (installment.ExpectedDate - GetInstallment(installment.Number - 2).ExpectedDate) .Days; accruedAmount += days >= DateTime.DaysInMonth(date.Year, date.Month) ? installment.InterestsRepayment : installment.InterestsRepayment* (double) days / (double) daysInInstallment; accruedInterestEvent.InstallmentNumber = installment.Number - 1; } } foreach (AccruedInterestEvent accruedEvent in Events.GetAccruedInterestEvents()) { if (!accruedEvent.Deleted) accruedAmount -= accruedEvent.AccruedInterest; } accruedInterestEvent.Interest = accruedAmount < 0 ? -1.0m * accruedAmount : 0; accruedAmount = accruedAmount < 0 ? 0 : accruedAmount; accruedAmount = UseCents ? Math.Round(accruedAmount.Value, 2) : Math.Round(accruedAmount.Value, 0); accruedInterestEvent.AccruedInterest = accruedAmount; accruedInterestEvent.Date = currentDate; accruedInterestEvent.Cancelable = true; if (accruedInterestEvent.AccruedInterest > 0) { Events.Add(accruedInterestEvent); return accruedInterestEvent; } return null; }
public void Delete_Event() { EventManager eventManager = (EventManager)container["EventManager"]; //I choose LoanInterestAccruingEvent, but delete work with any event AccruedInterestEvent loanInterestAccruingEvent = new AccruedInterestEvent { Id = 15, User = new User { Id = 1 }, Date = new DateTime(2006, 7, 21), Interest = 99, AccruedInterest = 3, Rescheduled = true, InstallmentNumber = 4 }; eventManager.AddLoanEvent(loanInterestAccruingEvent, 3); loanInterestAccruingEvent.CancelDate = DateTime.Now; eventManager.DeleteLoanEvent(loanInterestAccruingEvent); EventStock eventStock = eventManager.SelectEvents(3); foreach (Event e in eventStock.GetEvents()) { if (e is AccruedInterestEvent) _AssertLoanInterestAccruingEvent(e as AccruedInterestEvent, new DateTime(2006, 7, 21), 99, 3, true, 4,true); } }
public AccruedInterestEvent CreateLoanInterestAccruingEvent(DateTime today) { OCurrency accruedAmount = 0; AccruedInterestEvent accruedInterestEvent = new AccruedInterestEvent {ClientType = _clientType}; foreach (Installment installment in _installmentList) { if (installment.IsRepaid) { accruedAmount += installment.InterestsRepayment; } else { DateTime date = installment.Number == 1 ? _startDate : GetInstallment(installment.Number - 2).ExpectedDate; int days = (today - date).Days; accruedAmount += days >= DateTime.DaysInMonth(date.Year, date.Month) ? installment.InterestsRepayment : installment.InterestsRepayment * (double)days / (double)DateTime.DaysInMonth(date.Year, date.Month); accruedAmount = UseCents ? Math.Round(accruedAmount.Value, 2) : Math.Round(accruedAmount.Value, 0); break; } } OCurrency alreadyAccrued = 0; foreach (AccruedInterestEvent loanInterestAccruingEvent in Events.GetEventsByType(typeof(AccruedInterestEvent))) { alreadyAccrued += loanInterestAccruingEvent.AccruedInterest + loanInterestAccruingEvent.Interest; } accruedAmount -= alreadyAccrued; accruedInterestEvent.Interest = accruedAmount; accruedInterestEvent.AccruedInterest = accruedAmount; accruedInterestEvent.Rescheduled = _rescheduled; accruedInterestEvent.Date = today; return accruedInterestEvent; }
public void AddLoanEvent(AccruedInterestEvent pEvent, int contractId, SqlTransaction transac) { pEvent.Id = AddLoanEventHead(pEvent, contractId, transac); const string q = @"INSERT INTO [LoanInterestAccruingEvents]( [id], [interest_prepayment], [accrued_interest], [rescheduled], [installment_number]) VALUES(@id, @interestPrepayment, @accruedInterest, @rescheduled, @installmentNumber)"; using (OpenCbsCommand c = new OpenCbsCommand(q, transac.Connection, transac)) { SetLoanInterestAccruingEvent(pEvent, c); c.ExecuteNonQuery(); } }
public void AddLoanEvent(AccruedInterestEvent pEvent, int contractId) { using (SqlConnection connection = GetConnection()) using (SqlTransaction transaction = connection.BeginTransaction()) { try { AddLoanEvent(pEvent, contractId, transaction); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } }
private static void SetLoanInterestAccruingEvent(AccruedInterestEvent pEvent, OpenCbsCommand c) { c.AddParam("@id", pEvent.Id); c.AddParam("@interestPrepayment", pEvent.Interest.Value); c.AddParam("@accruedInterest", pEvent.AccruedInterest.Value); c.AddParam("@rescheduled", pEvent.Rescheduled); c.AddParam("@installmentNumber", pEvent.InstallmentNumber); }
private static OCurrency GetValue(AccruedInterestEvent eventItem, ContractAccountingRule rule) { OCurrency amount = 0; if (rule.EventAttribute.Name.ToLower() == "accrued_interest") { amount = eventItem.AccruedInterest; } return amount; }