public void simple_report() { var date = new DateTime(2012, 10, 10); var loan1 = new Loan() { Date = date.AddDays(-10), Balance = 100, Interest = 10 }; loan1.Customer = new Customer() { PersonalInfo = new PersonalInfo() { Fullname = "Test Test Test" } }; var installment1 = new LoanScheduleItem() { Loan = loan1, Date = date.AddDays(-9), AmountDue = 50, Balance = 50, Interest = 1 }; var lh1 = new LoanHistory(loan1, date.AddDays(-10)) { Loan = loan1 }; var lh2 = new LoanHistory(loan1, date.AddDays(-9)) { Loan = loan1, Balance = 51 }; var tran1 = new PaypointTransaction() { Amount = 50, Interest = 1, Balance = 49, Loan = loan1, Fees = 0, PostDate = date.AddDays(-9) }; using (var tx = _session.BeginTransaction()) { _session.Save(loan1); _session.Save(installment1); _session.Save(lh1); _session.Save(lh2); _session.Save(tran1); tx.Commit(); } var builder = new DailyReportBuilder(_loanScheduleRepository, _transactions, _historyRepository); var report = builder.GenerateReport(2012, 10, 1); Assert.That(report.Count, Is.EqualTo(1)); Assert.That(report[0].Before.Balance, Is.EqualTo(100)); Assert.That(report[0].After.Balance, Is.EqualTo(51)); Assert.That(report[0].Paid.Balance, Is.EqualTo(49)); }
public void adding_transaction_to_loan_generates_refnumber() { var loan = new Loan() { RefNumber = "01141490002" }; var tran = new PaypointTransaction(); loan.AddTransaction(tran); Assert.That(tran.RefNumber.Length, Is.EqualTo(14)); Assert.That(tran.RefNumber, Is.EqualTo("01141490002" + "001")); }
private static SchedultItemModel PaypointTransactionModel(PaypointTransaction item) { var model = new SchedultItemModel { Id = item.Id, Date = item.PostDate, Description = item.Description, Status = item.Status.ToString(), Editable = false, Deletable = (item.Amount != 0), Principal = item.LoanRepayment, Interest = item.Interest, Total = item.Amount, Type = "Paypoint" }; return model; }
public void adding_transaction_to_loan_sets_references() { var loan = new Loan() { Id = 1 }; var tran = new PaypointTransaction() { Id = 2 }; loan.AddTransaction(tran); Assert.That(tran.Loan.Id, Is.EqualTo(loan.Id)); Assert.That(loan.Transactions.Count, Is.EqualTo(1)); Assert.That(loan.Transactions.First().Id, Is.EqualTo(tran.Id)); }
private void ProcessPayment(PaypointTransaction payment) { payment.Rollover = 0; var money = payment.Amount; var interestToPay = Math.Max(0, _totalInterestToPay - _paidInterest); var feestToPay = _totalFeesToPay - _paidFees; _lastPaymentDate = payment.PostDate; //Paying Fees var amount = Math.Min(money, Math.Round(feestToPay, 2)); _paidFees += amount; money = money - amount; payment.Fees = amount; RecordFeesPayment(amount); //Paying Interest amount = payment.InterestOnly ? money : Math.Min(money, Math.Round(interestToPay, 2)); _paidInterest += amount; money = money - amount; payment.Interest = amount; RecordInterestPayment(amount); //Paying rollover foreach (var rollover in _rollovers) { money = PayRollover(rollover, payment, money); } //Removing payed rollovers _currentRollover = _currentRollover.Where(r => r.Status != RolloverStatus.Paid).ToList(); //Paying principal amount = Math.Min(money, _principal); _principal = _principal - amount; money = money - amount; _paidPrincipal += amount; payment.LoanRepayment = amount; RecordPrincipalPayment(amount); UpdateInstallmentsState(); }
} //CreatePacnet public static List <ScheduleRowModel> CreatePaypoint(PaypointTransaction p) { var list = new List <ScheduleRowModel>(); if (p.Fees > 0) { list.Add(new ScheduleRowModel { Description = "Fee", Date = p.PostDate, PaymentReceived = null, InterestAndFees = p.Fees, }); } if (p.Interest > 0) { list.Add(new ScheduleRowModel { Description = "Interest", Date = p.PostDate, PaymentReceived = null, InterestAndFees = p.Interest, }); } if (p.Amount > 0) { list.Add(new ScheduleRowModel { Description = "Repayment", Date = p.PostDate, PaymentReceived = p.Amount, InterestAndFees = null, }); } return(list); } //CreatePaypoint
public LoanRepaymentScheduleCalculatorEvent(DateTime date, PaypointTransaction paypointTransaction, int priority = 0) : this(date, priority) { Payment = paypointTransaction; }
} // constructor /// <summary> /// Заплатить за кредит. Платёж может быть произвольный. Early, On time, Late. /// Perform loan payment. Payment can be manual. Early, On time, Late. /// </summary> public virtual decimal PayLoan( Loan loan, string transId, decimal amount, string ip, DateTime?term = null, string description = "payment from customer", bool interestOnly = false, string sManualPaymentMethod = null, NL_Payments nlPayment = null) { int customerID = loan.Customer.Id; var paymentTime = term ?? DateTime.UtcNow; var oldLoan = loan.Clone(); const string Manual = "--- manual ---"; string otherMethod = transId == Manual ? "Manual" : "Auto"; var loanTransactionMethod = this.loanTransactionMethodRepository.FindOrDefault(sManualPaymentMethod, otherMethod); var transaction = this.session.BeginTransaction(); var transactionItem = new PaypointTransaction { Amount = amount, Description = description, PostDate = paymentTime, Status = LoanTransactionStatus.Done, PaypointId = transId, IP = ip, LoanRepayment = oldLoan.Principal - loan.Principal, Interest = loan.InterestPaid - oldLoan.InterestPaid, InterestOnly = interestOnly, LoanTransactionMethod = loanTransactionMethod }; try { loan.AddTransaction(transactionItem); List <InstallmentDelta> deltas = loan.Schedule.Select(inst => new InstallmentDelta(inst)) .ToList(); var calculator = new LoanRepaymentScheduleCalculator(loan, paymentTime, this.amountToChargeFrom); calculator.RecalculateSchedule(); if (this._historyRepository != null) { var historyRecord = new LoanHistory(loan, paymentTime); this._historyRepository.SaveOrUpdate(historyRecord); } // if loan.UpdateStatus(paymentTime); if (loan.Customer != null) { loan.Customer.UpdateCreditResultStatus(); } if (loan.Id > 0) { foreach (InstallmentDelta dlt in deltas) { dlt.SetEndValues(); if (dlt.IsZero) { continue; } loan.ScheduleTransactions.Add(new LoanScheduleTransaction { Date = DateTime.UtcNow, FeesDelta = dlt.Fees.EndValue - dlt.Fees.StartValue, InterestDelta = dlt.Interest.EndValue - dlt.Interest.StartValue, Loan = loan, PrincipalDelta = dlt.Principal.EndValue - dlt.Principal.StartValue, Schedule = dlt.Installment, StatusAfter = dlt.Status.EndValue, StatusBefore = dlt.Status.StartValue, Transaction = transactionItem }); } // for each delta } // if if (nlPayment != null) { Log.InfoFormat("PayLoan: oldLoanID: {0} customer: {1} nlpayment {2}", loan.Id, customerID, nlPayment); // override those for backword compatibility nlPayment.PaymentMethodID = loanTransactionMethod.Id; nlPayment.Notes = description; nlPayment.CreationTime = DateTime.UtcNow; nlPayment.PaymentTime = paymentTime; nlPayment.Amount = amount; nlPayment.PaymentStatusID = (int)NLPaymentStatuses.Active; Log.InfoFormat("PayLoan: overriden nlpayment {0}", nlPayment); long nlLoanId = serviceInstance.GetLoanByOldID(loan.Id, customerID); if (nlLoanId == 0) { Log.InfoFormat("Failed to find nl loan for oldLoanID {0}, customer {1}", loan.Id, customerID); } else { nlPayment.LoanID = nlLoanId; // use argument's nlPayment data: CreatedByUserID if (nlPayment.PaymentSystemType == NLPaymentSystemTypes.Paypoint) { // workaround - from MakeAutomaticPayment sent transactionid with timestamp concated var card = loan.Customer.PayPointCards.FirstOrDefault(x => transId.StartsWith(x.TransactionId)); if (card == null) { Log.InfoFormat("PayPointCard for customer {0}, transId={1}, oldLoanID={2}, nl loanID={3} not found. nl payment\n {4}{5}", customerID, transId, loan.Id, nlPayment.LoanID, AStringable.PrintHeadersLine(typeof(NL_Payments)), nlPayment.ToStringAsTable()); } else { nlPayment.PaypointTransactions.Clear(); nlPayment.PaypointTransactions.Add(new NL_PaypointTransactions() { TransactionTime = paymentTime, Amount = amount, Notes = description, PaypointTransactionStatusID = (int)NLPaypointTransactionStatuses.Done, PaypointUniqueID = transId, PaypointCardID = card.Id, IP = ip }); } } serviceInstance.AddPayment(customerID, nlPayment, nlPayment.CreatedByUserID); } } transaction.Commit(); } catch (Exception ex) { Log.ErrorFormat("Failed to pay {1} pounds for loan {0}, rollbacking \n {2}", loan.Id, amount, ex); transaction.Rollback(); } Log.InfoFormat("LinkPaymentToInvestor {0} {1} {2} {3} {4} begin", transactionItem.Id, loan.Id, loan.Customer.Id, amount, paymentTime); serviceInstance.LinkPaymentToInvestor(1, transactionItem.Id, loan.Id, loan.Customer.Id, amount, paymentTime); // modified by elinar at 9/02/2016 EZ-4678 bugfix return(amount); } // PayLoan