예제 #1
0
        private static RepaymentEvent GetRepaymentEvent(Loan loan, Loan repaidLoan)
        {
            var firstUnpaidInstallment = loan.Schedule.Find(x => !x.Repaid);
            var lateDays = (TimeProvider.Today - firstUnpaidInstallment.ExpectedDate.Date).Days;
            lateDays = lateDays < 0 ? 0 : lateDays;

            var repaymentEvent = new RepaymentEvent();
            repaymentEvent.LoanId = loan.Id;
            repaymentEvent.Code = lateDays > 0 ? "RBLE" : "RGLE";
            repaymentEvent.InstallmentNumber = firstUnpaidInstallment.Number;
            repaymentEvent.EventDate = TimeProvider.Now;
            repaymentEvent.UserId = User.CurrentUser.Id;
            repaymentEvent.LateDays = lateDays;

            repaymentEvent.Principal = repaidLoan.Schedule.Sum(x => x.PaidPrincipal) - loan.Schedule.Sum(x => x.PaidPrincipal);
            repaymentEvent.Interest = repaidLoan.Schedule.Sum(x => x.PaidInterest) - loan.Schedule.Sum(x => x.PaidInterest);
            
            return repaymentEvent;
        }
예제 #2
0
 private static CloseEvent GetCloseEvent(Loan loan)
 {
     var closeEvent = new CloseEvent();
     closeEvent.Code = "LOCE";
     closeEvent.LoanId = loan.Id;
     closeEvent.UserId = User.CurrentUser.Id;
     closeEvent.EventDate = TimeProvider.Now;
     return closeEvent;
 }
예제 #3
0
        private static void DistributeTotal(Loan loan, decimal total)
        {
            var installments = loan.Schedule.Where(x => !x.Repaid).ToList();
            var date = TimeProvider.Now;
            foreach (var installment in installments)
            {
                if (installment.UnpaidInterest > total)
                {
                    installment.PaidInterest += total;
                    installment.PaymentDate = date;
                    break;
                }
                total -= installment.UnpaidInterest;
                installment.PaidInterest = installment.Interest;
                installment.PaymentDate = date;

                if (installment.UnpaidPrincipal > total)
                {
                    installment.PaidPrincipal += total;
                    installment.PaymentDate = date;
                    break;
                }
                total -= installment.UnpaidPrincipal;
                installment.PaidPrincipal = installment.Principal;
                installment.PaymentDate = date;

                if (total == 0)
                {
                    break;
                }
            }
        }