private void SelectAccount(object sender, RoutedEventArgs e) { List <Account> accounts = Account.GetList(); // create list of search items List <SearchItem> searchItems = accounts.Select( account => new SearchItem(account.ID, account.AccountTitle) { ItemCode = account.AccountCode }).ToList(); var searchByCodeWindow = new SearchByCodeWindow(searchItems); searchByCodeWindow.ShowDialog(); if (searchByCodeWindow.DialogResult != true) { return; } var accountSelect = new Account(); accountSelect.Find(searchByCodeWindow.SelectedItem.ItemId); _currentLoanCharges.AccountCode = accountSelect.AccountCode; _currentLoanCharges.AccountTitle = accountSelect.AccountTitle; DataContext = new LoanCharge(); DataContext = _currentLoanCharges; }
public void ApplayLateCharge() { int loanid = 5103; ILoanRepository loanRep = ObjectFactory.GetInstance<LoanRepository>(); var loan = loanRep.Get(loanid); DateTime now = DateTime.UtcNow; ILoanOptionsRepository optRep = ObjectFactory.GetInstance<LoanOptionsRepository>(); var loanOptions = optRep.GetByLoanId(loanid); // m_oLog.Debug("loanOption={0}", loanOptions.ToString()); if (loanOptions != null && loanOptions.AutoLateFees == false) { if (((loanOptions.StopLateFeeFromDate.HasValue && now >= loanOptions.StopLateFeeFromDate.Value) && (loanOptions.StopLateFeeToDate.HasValue && now <= loanOptions.StopLateFeeToDate.Value)) || (!loanOptions.StopLateFeeFromDate.HasValue && !loanOptions.StopLateFeeToDate.HasValue)) { m_oLog.Debug("not applying late fee for loan {0} - auto late fee is disabled", loanid); return; } } var charge = new LoanCharge { Amount = 20, ChargesType = new ConfigurationVariable(CurrentValues.Instance.GetByID(CurrentValues.Instance.LatePaymentCharge.ID)), Date = now, Loan = loan }; m_oLog.Debug("charge={0}", charge); var res = loan.TryAddCharge(charge); m_oLog.Debug("result={0}", res); }
public void paying_loan_early__without_fees() { var loanAmount = 10000; var loan1 = new Loan(); _calculator.Calculate(loanAmount, loan1, Parse("2013-02-28 14:27:14.000")); loan1.Status = LoanStatus.Live; var charge = new LoanCharge() { Loan = loan1, Amount = 20, Date = Parse("2013-04-10 01:11:12.000") }; loan1.Charges.Add(charge); var now = Parse("2013-02-28 16:40:13.000"); var c1 = new LoanRepaymentScheduleCalculator(loan1, now, 0); _facade.PayLoan(loan1, "", 10000, "ip", now); c1.RecalculateSchedule(); Console.WriteLine(loan1); Assert.That(loan1.Status, Is.EqualTo(LoanStatus.PaidOff)); Assert.That(charge.State, Is.EqualTo("Expired")); }
/// <summary> /// el: 1. cumulate _totalFeesToPay; 2. add fee amount to first unpaid schedule item all non paid fees; 2. cumulate _chargesToPay list /// </summary> /// <param name="charge"></param> private void ProcessCharge(LoanCharge charge) { // el: if loan PaidOff, mark the charge as Expired if (_loan.Status == LoanStatus.PaidOff) { charge.State = "Expired"; return; } // el: attach fee amount to the first unpaid schedule item. will be last item from processed schedules list var lastInstallment = _processed.Where(i => i.Status == LoanScheduleStatus.Late || i.Status == LoanScheduleStatus.StillToPay).LastOrDefault(); if (lastInstallment != null) { if (lastInstallment.Status == LoanScheduleStatus.Late || (lastInstallment.Status == LoanScheduleStatus.StillToPay && _schedule.Count == _processed.Count)) { lastInstallment.AmountDue += charge.Amount; lastInstallment.Fees += charge.Amount; } } // el: add amount to totalFees _totalFeesToPay += charge.Amount; // el: reset AmountPaid of the charge charge.AmountPaid = 0; // el: add to list of _chargesToPay - handles in RecordFeesPayment _chargesToPay.Add(charge); }
public void charge_can_be_added() { var loan = new Loan(); var calculator = new LoanScheduleCalculator() { Interest = 0.06M }; calculator.Calculate(1000, loan, new DateTime(2012, 10, 10)); var charge = new LoanCharge { Amount = 100, ChargesType = new ConfigurationVariable() { Id = 1, Name = "Charge1", Value = "100" }, Date = new DateTime(2012, 10, 11), Loan = loan }; loan.TryAddCharge(charge); Assert.That(loan.Charges.Count, Is.EqualTo(1)); }
public void Update(object sender, RoutedEventArgs e) { int loanProductId = _currentLoanCharges.LoanProductId; if (string.IsNullOrEmpty(_currentLoanCharges.AccountCode)) { MessageWindow.ShowAlertMessage("Loan Charges of Operation must not be empty!"); return; } if (_currentLoanCharges.ID == 0) { _currentLoanCharges.Create(); _currentLoanCharges.ID = 0; } else { _currentLoanCharges.Update(); } DataContext = _currentLoanCharges = new LoanCharge(); _currentLoanCharges.LoanProductId = loanProductId; MessageWindow.ShowNotifyMessage("Loan Charges information saved!"); CloseWindow(sender, e); }
public EditLoanProductView(string newLoanProductName) : this() { _loanProduct = new LoanProduct { Name = newLoanProductName }; _loanCharge1 = new LoanCharge(); _loanCharge2 = new LoanCharge(); _loanCharge3 = new LoanCharge(); _loanCharge4 = new LoanCharge(); _loanCharge5 = new LoanCharge(); _loanCharge6 = new LoanCharge(); _loanDeduction1 = new LoanDeduction(); _loanDeduction2 = new LoanDeduction(); _loanDeduction3 = new LoanDeduction(); DataContext = _loanProduct; grdDetails.DataContext = _loanProduct; grdCharge1.DataContext = _loanCharge1; grdCharge2.DataContext = _loanCharge2; grdCharge3.DataContext = _loanCharge3; grdCharge4.DataContext = _loanCharge4; grdCharge5.DataContext = _loanCharge5; grdCharge6.DataContext = _loanCharge6; grdDeduction1.DataContext = _loanDeduction1; grdDeduction2.DataContext = _loanDeduction2; grdDeduction3.DataContext = _loanDeduction3; }
public void fees_are_added_to_payments() { var loanAmount = 10000; var loan1 = new Loan(); _calculator.Calculate(loanAmount, loan1, Parse("2013-02-28 14:27:14.000")); loan1.Status = LoanStatus.Live; var charge = new LoanCharge() { Loan = loan1, Amount = 20, Date = Parse("2013-04-10 01:11:12.000") }; loan1.Charges.Add(charge); var now = Parse("2013-02-28 16:40:13.000"); var c1 = new LoanRepaymentScheduleCalculator(loan1, now, 0); var lm1 = LoanModel.FromLoan(loan1, c1, c1); Console.WriteLine(loan1); Assert.That(lm1.TotalEarlyPayment, Is.EqualTo(loanAmount)); }
public LoanChargesMaintenanceWindow(Int32 loanProductId) { InitializeComponent(); _currentLoanCharges = new LoanCharge(); _currentLoanCharges.LoanProductId = loanProductId; DataContext = _currentLoanCharges; }
public void simple_late_charge() { var calculator = new LoanScheduleCalculator() { Interest = 0.06M }; calculator.Calculate(5000, _loan, Parse("2012-09-23 23:29:35.000")); var charge = new LoanCharge() { Amount = 60, Loan = _loan, Date = new DateTime(2012, 10, 25) }; _loan.Charges.Add(charge); Console.WriteLine(_loan); MakePayment(1968, Parse("2012-10-28 10:03:01.000")); MakePayment(1865.92m, Parse("2012-11-23 10:44:22.000")); MakePayment(1765.96m, Parse("2012-12-23 13:30:18.000")); Assert.That(_loan.TransactionsWithPaypointSuccesefull[0].Fees, Is.EqualTo(60)); Assert.That(charge.AmountPaid, Is.EqualTo(60)); }
public void state_after_missed_payment_is_correct() { var calculator = new LoanScheduleCalculator() { Interest = 0.06M }; calculator.Calculate(5000, _loan, Parse("2012-09-23 23:29:35.000")); Console.WriteLine(_loan); var fee = 60m; var charge = new LoanCharge() { Amount = fee, Loan = _loan, Date = new DateTime(2012, 10, 25) }; _loan.Charges.Add(charge); var state = _facade.GetStateAt(_loan, new DateTime(2012, 10, 26)); Console.WriteLine(_loan); var percents = 29.03m; // проценты, которые набежали с момента последнего instllment var oldInstallmentAmountDue = 1968m; Assert.That(state.AmountDue, Is.EqualTo(oldInstallmentAmountDue + fee + percents)); //Assert.That(state.LoanRepayment, Is.EqualTo(0)); //Assert.That(state.Interest, Is.EqualTo(0)); }
public void state_at_begining_of_the_loan_with_late_charge() { var calculator = new LoanScheduleCalculator() { Interest = 0.06M }; calculator.Calculate(5000, _loan, Parse("2012-09-23 23:29:35.000")); Console.WriteLine(_loan); var charge = new LoanCharge() { Amount = 60, Loan = _loan, Date = new DateTime(2012, 10, 25) }; _loan.Charges.Add(charge); var state = _facade.GetStateAt(_loan, new DateTime(2012, 9, 23)); Console.WriteLine(_loan); Assert.That(state.AmountDue, Is.EqualTo(0)); Assert.That(state.LoanRepayment, Is.EqualTo(0)); Assert.That(state.Interest, Is.EqualTo(0)); }
public void Read(object sender, RoutedEventArgs e) { List <LoanCharge> loanChargesList = LoanCharge.GetList(); List <SearchItem> searchItems = loanChargesList.Select(charges => new SearchItem(charges.ID, charges.AccountCode)).ToList(); var searchWindow = new SearchWindow(searchItems); searchWindow.ShowDialog(); }
public void state_at_installment_dates() { var calculator = new LoanScheduleCalculator() { Interest = 0.06M }; calculator.Calculate(5000, _loan, Parse("2012-09-23 23:29:35.000")); var charge = new LoanCharge() { Amount = 60, Loan = _loan, Date = new DateTime(2012, 10, 25) }; _loan.Charges.Add(charge); Console.WriteLine(_loan); LoanScheduleItem state; //loan start state = _facade.GetStateAt(_loan, new DateTime(2012, 9, 23)); Console.WriteLine(_loan); Assert.That(state.AmountDue, Is.EqualTo(0)); Assert.That(state.LoanRepayment, Is.EqualTo(0)); Assert.That(state.Interest, Is.EqualTo(0)); Assert.That(state.Fees, Is.EqualTo(0)); Console.WriteLine(_loan); // installment #1 state = _facade.GetStateAt(_loan, new DateTime(2012, 10, 23)); Console.WriteLine(_loan); Assert.That(state.AmountDue, Is.EqualTo(1968.00m)); Assert.That(state.LoanRepayment, Is.EqualTo(1668)); Assert.That(state.Interest, Is.EqualTo(300.00m)); Assert.That(state.Fees, Is.EqualTo(0)); // installment #2 state = _facade.GetStateAt(_loan, new DateTime(2012, 11, 23)); Console.WriteLine(_loan); //Assert.That(state.AmountDue, Is.EqualTo(1865.92m)); Assert.That(state.LoanRepayment, Is.EqualTo(1666 + 1668)); Assert.That(state.Fees, Is.EqualTo(60)); //Assert.That(state.Interest, Is.EqualTo(199.92m)); // installment #3 state = _facade.GetStateAt(_loan, new DateTime(2012, 12, 23)); Console.WriteLine(_loan); //Assert.That(state.AmountDue, Is.EqualTo(1765.96m)); Assert.That(state.LoanRepayment, Is.EqualTo(1666 + 1666 + 1668)); Assert.That(state.Fees, Is.EqualTo(60)); //Assert.That(state.Interest, Is.EqualTo(99.96m)); }
public void Delete(object sender, RoutedEventArgs e) { if ( MessageWindow.ShowConfirmMessage( "You are about to delete current Area information. Do you want to proceed?") == MessageBoxResult.Yes) { _currentLoanCharges.Destroy(); MessageWindow.ShowNotifyMessage("Loan Charges information deleted!"); DataContext = _currentLoanCharges = new LoanCharge(); } }
private static SchedultItemModel FeeModel(LoanCharge item) { var model = new SchedultItemModel { Id = item.Id, Fees = item.Amount, Total = item.Amount, Date = item.Date, Status = item.State ?? "Active", Description = item.Description, Editable = true, Deletable = true, Type = "Fee", Editor = "Fee" }; return model; }
} // ShiftPayments public virtual bool TryAddCharge(LoanCharge charge) { if (charge.Date < Date) { throw new ArgumentException("Charge date is before loan start date"); } var charges = Charges.Where(c => { var name1 = c.ChargesType.Name; var name2 = charge.ChargesType.Name; if (name1 == name2) { return(true); } if (name1 == "PartialPaymentCharge" && name2 == "AdministrationCharge") { return(true); } if (name2 == "PartialPaymentCharge" && name1 == "AdministrationCharge") { return(true); } return(false); }).ToList(); if (charge.Date > Schedule.First().Date) { var dateFrom = Schedule.Last(s => s.Date < charge.Date).Date; charges = charges.Where(c => c.Date >= dateFrom).ToList(); } if (charge.Date < Schedule.Last().Date) { var dateUpTo = Schedule.First(s => s.Date >= charge.Date).Date; charges = charges.Where(c => c.Date < dateUpTo).ToList(); } if (charges.Any()) { return(false); } Charges.Add(charge); return(true); } // TryAddCharge
} // constructor public static LoanChargesModel FromCharges(LoanCharge loanCharge) { if (loanCharge == null) { return(null); } return(new LoanChargesModel { Amount = loanCharge.Amount, ChargesType = ConfigurationVariableModel.FromConfigurationVariable(loanCharge.ChargesType), Date = loanCharge.Date, Id = loanCharge.Id, State = loanCharge.State ?? "Active", AmountPaid = loanCharge.AmountPaid, Description = loanCharge.GetDescription(), IsServiceFee = loanCharge.ChargesType.Name == spreadSetupFee.Name ? "yes" : "no", }); } // FromCharges
public void loan_533_Taras() { var calculator = new LoanScheduleCalculator() { Interest = 0.06M, Term = 3 }; calculator.Calculate(1000, _loan, Parse("2012-10-12 00:00:00.000")); _loan.Status = LoanStatus.Live; var rollover = new PaymentRollover() { Created = Parse("2012-12-27 15:18:30.000"), ExpiryDate = Parse("2012-12-30 00:00:00.000"), Status = RolloverStatus.New, LoanSchedule = _loan.Schedule[0], Payment = 50 }; _loan.Schedule[0].Rollovers.Add(rollover); var charge = new LoanCharge() { Amount = 75, ChargesType = null, Date = Parse("2012-12-27 13:15:29.000"), Loan = _loan }; _loan.Charges.Add(charge); Console.WriteLine(_loan); var now = Parse("2012-12-27 13:19:00.000"); MakePayment(274.03m, now); //var model = LoanModel.FromLoan(_loan, new LoanRepaymentScheduleCalculator(_loan, now), new LoanRepaymentScheduleCalculator(_loan, now)); var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, now, 0); var state = payEarlyCalc.GetState(); Console.WriteLine(_loan); Assert.That(_loan.Schedule[0].Interest, Is.EqualTo(0)); }
public EditLoanProductView(int id) : this() { _loanProduct.Find(id); List <LoanCharge> loanCharges = LoanCharge.GetListByLoanProductId(_loanProduct.ID); int countCharges = loanCharges.Count; _loanCharge1 = countCharges >= 1 ? loanCharges[0] : new LoanCharge(); _loanCharge2 = countCharges >= 2 ? loanCharges[1] : new LoanCharge(); _loanCharge3 = countCharges >= 3 ? loanCharges[2] : new LoanCharge(); _loanCharge4 = countCharges >= 4 ? loanCharges[3] : new LoanCharge(); _loanCharge5 = countCharges >= 5 ? loanCharges[4] : new LoanCharge(); _loanCharge6 = countCharges >= 6 ? loanCharges[5] : new LoanCharge(); List <LoanDeduction> loanDeductions = LoanDeduction.GetListByLoanProductId(_loanProduct.ID); int countDeductions = loanDeductions.Count; _loanDeduction1 = countDeductions >= 1 ? loanDeductions[0] : new LoanDeduction(); _loanDeduction2 = countDeductions >= 2 ? loanDeductions[1] : new LoanDeduction(); _loanDeduction3 = countDeductions >= 3 ? loanDeductions[2] : new LoanDeduction(); DataContext = _loanProduct; grdDetails.DataContext = _loanProduct; grdCharge1.DataContext = _loanCharge1; grdCharge2.DataContext = _loanCharge2; grdCharge3.DataContext = _loanCharge3; grdCharge4.DataContext = _loanCharge4; grdCharge5.DataContext = _loanCharge5; grdCharge6.DataContext = _loanCharge6; grdDeduction1.DataContext = _loanDeduction1; grdDeduction2.DataContext = _loanDeduction2; grdDeduction3.DataContext = _loanDeduction3; }
public bool ApplyLateCharge(Loan loan, decimal amount, int loanChargesTypeId, DateTime date) { var charge = new LoanCharge { Amount = amount, ChargesType = new ConfigurationVariable(CurrentValues.Instance.GetByID(loanChargesTypeId)), Date = date, Loan = loan }; var res = loan.TryAddCharge(charge); var facade = new LoanPaymentFacade(); facade.Recalculate(loan, date); _loans.Update(loan); //Log.Debug(string.Format("updated loan: {0}", loan)); return(res); }
public void late_charge_before_first_installment() { var calculator = new LoanScheduleCalculator() { Interest = 0.06M }; calculator.Calculate(5000, _loan, Parse("2012-09-23 23:29:35.000")); var charge = new LoanCharge() { Amount = 60, Loan = _loan, Date = new DateTime(2012, 09, 30) }; _loan.Charges.Add(charge); var payment = _loan.TotalEarlyPayment(_loan.Date); Console.WriteLine(_loan); Assert.That(_loan.Schedule[0].Fees, Is.EqualTo(60)); }
public void cannot_add_charge_of_the_same_type_to_one_installment() { var loan = new Loan(); var calculator = new LoanScheduleCalculator() { Interest = 0.06M }; calculator.Calculate(1000, loan, new DateTime(2012, 10, 10)); var charge1 = new LoanCharge { Amount = 100, ChargesType = new ConfigurationVariable() { Id = 1, Name = "LatePaymentCharge", Value = "100" }, Date = new DateTime(2012, 11, 11), Loan = loan }; var charge2 = new LoanCharge { Amount = 200, ChargesType = new ConfigurationVariable() { Id = 1, Name = "LatePaymentCharge", Value = "100" }, Date = new DateTime(2012, 11, 11), Loan = loan }; loan.TryAddCharge(charge1); loan.TryAddCharge(charge2); Assert.That(loan.Charges.Count, Is.EqualTo(1)); }
public void admin_fee_is_partial_fee() { var loan = new Loan(); var calculator = new LoanScheduleCalculator() { Interest = 0.06M }; calculator.Calculate(1000, loan, new DateTime(2012, 10, 10)); var charge1 = new LoanCharge { Amount = 100, ChargesType = new ConfigurationVariable() { Id = 1, Name = "PartialPaymentCharge", Value = "100" }, Date = new DateTime(2012, 11, 11), Loan = loan }; var charge2 = new LoanCharge { Amount = 200, ChargesType = new ConfigurationVariable() { Id = 1, Name = "AdministrationCharge", Value = "100" }, Date = new DateTime(2012, 11, 11), Loan = loan }; loan.TryAddCharge(charge1); loan.TryAddCharge(charge2); Assert.That(loan.Charges.Count, Is.EqualTo(1)); }
public void add_or_not_charge_after_installment() { var calculator = new LoanScheduleCalculator() { Interest = 0.06M }; calculator.Calculate(5000, _loan, Parse("2012-09-23 23:29:35.000")); var charge = new LoanCharge() { Amount = 60, Loan = _loan, Date = new DateTime(2012, 11, 30) }; _loan.Charges.Add(charge); _facade.Recalculate(_loan, Parse("2012-10-23 23:29:35.000")); Console.WriteLine(_loan); Assert.That(_loan.Schedule.Sum(x => x.Fees), Is.EqualTo(60)); Assert.That(_loan.Schedule[2].Fees, Is.EqualTo(60)); }
public void late_charge_after_first_installment_that_is_paid() { var calculator = new LoanScheduleCalculator() { Interest = 0.06M }; calculator.Calculate(5000, _loan, Parse("2012-09-23 23:29:35.000")); var charge = new LoanCharge() { Amount = 60, Loan = _loan, Date = new DateTime(2012, 10, 30) }; _loan.Charges.Add(charge); _facade.PayLoan(_loan, "", 3000, "", new DateTime(2012, 10, 23)); Console.WriteLine(_loan); Assert.That(_loan.Schedule[0].Fees, Is.EqualTo(0)); Assert.That(_loan.Schedule[1].Fees, Is.EqualTo(60)); }
public void early_payment_with_late_charge() { var calculator = new LoanScheduleCalculator() { Interest = 0.06M }; calculator.Calculate(5000, _loan, Parse("2012-09-23 23:29:35.000")); Console.WriteLine(_loan); var charge = new LoanCharge() { Amount = 60, Loan = _loan, Date = new DateTime(2012, 10, 25) }; _loan.Charges.Add(charge); var payment = _loan.TotalEarlyPayment(_loan.Date); Console.WriteLine(_loan); Assert.That(payment, Is.EqualTo(_loan.LoanAmount)); }
public LoanRepaymentScheduleCalculatorEvent(DateTime date, LoanCharge loanCharge) : this(date) { Charge = loanCharge; }
public LoanChargesMaintenanceWindow(LoanCharge loanCharges, Int32 loanProductId) { InitializeComponent(); _currentLoanCharges = loanCharges; DataContext = _currentLoanCharges; }
public void Create(object sender, RoutedEventArgs e) { DataContext = new LoanCharge(); }