示例#1
0
        public async Task ShouldInsert_LoanAgreementAndLoanPymt_UsingLoanAgreementAggregate()
        {
            LoanAgreement agreement = new LoanAgreement
                                      (
                new EconomicEvent(Guid.NewGuid(), EventType.CashReceiptFromLoanAgreement),
                FinancierId.Create(new Guid("b49471a0-5c1e-4a4d-97e7-288fb0f6338a")),
                LoanAmount.Create(175000),
                InterestRate.Create(.0675),
                LoanDate.Create(new DateTime(2021, 11, 5)),
                MaturityDate.Create(new DateTime(2022, 11, 5)),
                PaymentsPerYear.Create(12),
                UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))
                                      );

            LoanPayment loanPayment = new LoanPayment
                                      (
                new EconomicEvent(Guid.NewGuid(), EventType.CashDisbursementForLoanPayment),
                agreement,
                PaymentNumber.Create(1),
                PaymentDueDate.Create(new DateTime(2021, 12, 5)),
                LoanPrincipalAmount.Create(14135),
                LoanInterestAmount.Create(984),
                LoanPrincipalRemaining.Create(160862),
                UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))
                                      );

            agreement.AddLoanPayment(loanPayment);
            await _loanAgreementRepo.AddAsync(agreement);

            await _unitOfWork.Commit();

            var result = await _loanAgreementRepo.Exists(agreement.Id);

            Assert.True(result);    //TODO Test navigation to LoanPayment
        }
        private static decimal TryPayLoanPayment(decimal amount, LoanPayment loanPayment)
        {
            amount = PayRequiredPaymentAmount(amount, loanPayment.Fine, newAmount => loanPayment.Fine = newAmount);
            amount = PayRequiredPaymentAmount(amount, loanPayment.Amount, newAmount => loanPayment.Amount = newAmount);

            return(amount);
        }
示例#3
0
        public IActionResult App(Loan loan)
        {
            var LoanHelpers      = new LoanUtils();
            var RemainingBalance = loan.Amount;


            var MonthlyPayment  = LoanHelpers.CalcPayment(loan.Amount, loan.Rate, loan.Term);
            var TotalInterest   = 0.00m;
            var MonthlyInterest = 0.00m;


            for (int i = 1; i <= loan.Term; i++)
            {
                var loanPayment = new LoanPayment();

                loanPayment.Month            = i;
                MonthlyInterest              = LoanHelpers.CalcMonthlyInterest(RemainingBalance, loan.Rate);
                loanPayment.Payment          = MonthlyPayment;
                loanPayment.MonthlyInterest  = MonthlyInterest;
                loanPayment.MonthlyPrinciapl = MonthlyPayment - MonthlyInterest;
                var MonthlyPrincipal = MonthlyPayment - MonthlyInterest;
                TotalInterest             = MonthlyInterest + TotalInterest;
                loanPayment.TotalInterest = TotalInterest;
                RemainingBalance          = RemainingBalance - MonthlyPrincipal;
                loanPayment.Balance       = RemainingBalance;


                loan.Payments.Add(loanPayment);
            }

            return(View(loan));
        }
 private void ReCalculatePayment(LoanPayment payment, DateTime date, LoanProduct product)
 {
     if (payment.Date < date)
     {
         payment.Fine += product.FineDayPercentage * payment.Amount;
     }
 }
示例#5
0
        public async Task ShouldInsert_LoanPymt_UsingLoanAgreementAggregate()
        {
            LoanAgreement agreement = await _loanAgreementRepo.GetByIdAsync(new Guid("0a7181c0-3ce9-4981-9559-157fd8e09cfb"));

            EconomicEvent economicEvent = new EconomicEvent(Guid.NewGuid(), EventType.CashDisbursementForLoanPayment);
            await _loanAgreementRepo.AddEconomicEventAsync(economicEvent);

            LoanPayment loanPayment = new LoanPayment
                                      (
                economicEvent,
                agreement,
                PaymentNumber.Create(1),
                PaymentDueDate.Create(new DateTime(2021, 12, 5)),
                LoanPrincipalAmount.Create(14135.13M),
                LoanInterestAmount.Create(984),
                LoanPrincipalRemaining.Create(160862.13M),
                UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))
                                      );

            agreement.AddLoanPayment(loanPayment);
            _loanAgreementRepo.Update(agreement);
            await _unitOfWork.Commit();

            LoanPayment result = agreement.LoanPayments.FirstOrDefault(p => p.Id == loanPayment.EconomicEvent.Id);

            Assert.NotNull(result);
        }
        public async Task <LoanPayment> Create(LoanPayment loanPayment)
        {
            _context.LoanPayments.Add(loanPayment);
            await _context.SaveChangesAsync();

            return(loanPayment);
        }
示例#7
0
 private void SendDelinquentPaymentNotification(LoanPayment payment, Client client)
 {
     mailService.SendMessage(
         SendDelinquentPaymentNotificationSubject,
         String.Format(SendDelinquentPaymentNotificationBody, client.FirstName, payment.Amount),
         client.Email);
 }
示例#8
0
        public ActionResult AddPayment(int?id)
        {
            ViewBag.Action    = "Add Payment";
            ViewBag.Calculate = false;
            Loan loan = GetLoan(id);

            if (loan == null || loan.User.Id != user.Id)
            {
                return(HttpNotFound());
            }

            LoanPayment payment = new LoanPayment()
            {
                DatePaid   = loan.NextPayment.Date,
                Base       = loan.NextPayment.Base,
                Additional = loan.NextPayment.Additional,
                Escrow     = loan.NextPayment.Escrow,
                Interest   = loan.NextPayment.Interest,
                Loan       = loan
            };

            ViewBag.Users            = GetAvailableUsers(loan);
            ViewBag.SharedPercentage = Enum.GetValues(typeof(SharedPercentage));
            return(View("Payment", payment));
        }
示例#9
0
        public ActionResult EditPayment(int?id, string[] payeeId, string[] sharedPercent, [Bind(Include = "DatePaid,Base,Additional,Escrow,Interest")] LoanPayment loanPayment)
        {
            ViewBag.Action    = "Edit Payment";
            ViewBag.Calculate = false;

            LoanPayment lp = db.LoanPayments.Find(id);

            if (ModelState.IsValid)
            {
                lp.DatePaid   = loanPayment.DatePaid;
                lp.Base       = loanPayment.Base;
                lp.Additional = loanPayment.Additional;
                lp.Escrow     = loanPayment.Escrow;
                lp.Interest   = loanPayment.Interest;
                IEnumerable <LoanPayment> payments = db.LoanPayments.Where(x => x.Loan.ID == lp.Loan.ID && x.DatePaid < lp.DatePaid).OrderBy(x => x.DatePaid);
                if (payments != null && payments.Any())
                {
                    lp.Principal = payments.LastOrDefault().Principal - loanPayment.Base - loanPayment.Additional;
                }
                else
                {
                    lp.Principal = loanPayment.Loan.LoanAmount - loanPayment.Base - loanPayment.Additional;
                }
                db.Entry(lp).State = EntityState.Modified;
                UpdateLoanPaymentShared(lp, payeeId, sharedPercent);
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = lp.Loan.ID }));
            }
            ViewBag.Users            = GetAvailableUsers(loanPayment.Loan);
            ViewBag.SharedPercentage = Enum.GetValues(typeof(SharedPercentage));
            return(View("Payment", lp));
        }
示例#10
0
        public List <LoanPayment> GetAmortizationSchedule(int periods, double balance, double monthlyRate = (double)3 / 100 / 12)
        {
            var loanPayments = new List <LoanPayment>()
            {
                new LoanPayment
                {
                    Balance = balance
                }
            };

            double monthyPayment = (monthlyRate / (1 - (Math.Pow((1 + monthlyRate), -(periods))))) * balance;


            for (var i = 0; i < periods; i++)
            {
                var loanPayment = new LoanPayment()
                {
                    MonthyPayment    = monthyPayment,
                    InterestForMonth = balance * monthlyRate,
                    Index            = i + 1
                };
                loanPayment.PrincipalForMonth = monthyPayment - loanPayment.InterestForMonth;
                balance            -= loanPayment.PrincipalForMonth;
                loanPayment.Balance = balance;

                loanPayments.Add(loanPayment);
            }

            return(loanPayments);
        }
示例#11
0
        public ActionResult DeleteConfirmed(int id)
        {
            LoanPayment loanPayment = db.LoanPayments.Find(id);

            db.LoanPayments.Remove(loanPayment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#12
0
        void BeginCalculate()
        {
            double monthlyPayment;

            this.calculatedPayments       = LoanPayment.Calculate((double)LoanAmount, (double)(InterestRate / 12M), (double)(TermOfLoan * 12), StartMonth, out monthlyPayment);
            this.calculatedMonthlyPayment = (decimal)monthlyPayment;
            this.calculatedYearPayments   = YearPayment.Calculate(this.calculatedPayments);
        }
示例#13
0
        public IActionResult App(Loan loan)
        {
            //var loanPayments = new Loan();

            var totalInterest    = 0.00m;
            var interestPayment  = 0.00m;
            var principalPayment = 0.00m;
            var totalCost        = 0.00m;
            var totalPrincipal   = 0.00m;

            //var loanTerm = loan.Term * 12;
            var loanHelper = new LoanHelper.LoanUtils();

            totalPrincipal = loan.Amount;

            var monthlyPayment   = loanHelper.CalcPayment(loan.Amount, loan.Rate, loan.Term);
            var remainingBalance = loan.Amount;


            for (int i = 1; i <= loan.Term; i++)
            {
                interestPayment = loanHelper.CalcMonthyInterest(remainingBalance, loan.Rate);

                principalPayment = monthlyPayment - interestPayment;
                totalPrincipal  += monthlyPayment - interestPayment;

                var loanPayment = new LoanPayment();

                loanPayment.Month = i;

                loanPayment.MonthlyInterest = interestPayment;

                loanPayment.Payment = monthlyPayment;

                loanPayment.MonthlyPrincipal = principalPayment;

                totalInterest = totalInterest + interestPayment;

                loanPayment.TotalInterest = totalInterest;

                remainingBalance -= principalPayment;

                loanPayment.Balance = remainingBalance;



                loan.Payments.Add(loanPayment);
            }

            loan.Payment = monthlyPayment;


            loan.TotalInterest  = totalInterest;
            loan.TotalPrincipal = totalPrincipal;
            loan.TotalCost      = totalPrincipal + totalInterest;

            return(View(loan));
        }
示例#14
0
        private void AddLoanPaymentToReport(PaymentTransaction paymentTransaction, LoanPayment loanPayment)
        {
            var row = new PaymentDetailsReport(
                paymentTransaction.TransNo, paymentTransaction.MemberCode, loanPayment.AmountPaid,
                loanPayment.Loan.Description,
                loanPayment.Loan.Remarks, paymentTransaction.FamilyMember.Sex);

            _uiReportList.Add(row);
        }
 private static void CheckLoanPaymentStatus(LoanPayment loanPayment)
 {
     if (loanPayment.Fine == 0 && loanPayment.Amount == 0)
     {
         loanPayment.Status = loanPayment.Date.Date < DateTime.Now.Date
                                  ? LoanPaymentStatus.PaidWithDelay
                                  : LoanPaymentStatus.Paid;
     }
 }
示例#16
0
        public ActionResult DeletePayment(int?id)
        {
            LoanPayment loanPayment = GetLoanPayment(id);
            Loan        loan        = loanPayment.Loan;

            db.SharedLoanPayment.RemoveRange(loanPayment.SharedWith);
            db.LoanPayments.Remove(loanPayment);
            db.SaveChanges();
            return(RedirectToAction("Details", new { id = loan.ID }));
        }
示例#17
0
 public ActionResult Edit([Bind(Include = "ID,DateOfPayment,AmountOfPayment,Remarks")] LoanPayment loanPayment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(loanPayment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(loanPayment));
 }
示例#18
0
        public void FillLoanPayement(LoanPayment data)
        {
            this.SelectByText(this.PayoutMethod, data.PayoutMethod);
            this.Type(this.Iban, data.Iban);

            if (data.IbanOnotherPerson == "yes")
            {
                this.IbanOnotherPerson.Click();
            }
        }
示例#19
0
 public List <DBResponse> InsertLoanPaymentHistory(LoanPayment loan)
 {
     using (var _context = new AccountsEntities())
     {
         string dataList = "[Loan_InsertLoanPayment_History] '" + loan.Id + "','" + loan.LoanBaseId + "','" + loan.CashIn +
                           "','" + loan.CashOut + "','" + loan.TransactionDate + "'";
         var list = _context.Database.SqlQuery <DBResponse>(dataList).ToList <DBResponse>();
         return(list);
     }
 }
        public void TryPayLoanPayment(LoanPayment loanPayment)
        {
            Contract.Requires <ArgumentNullException>(loanPayment.IsNotNull());
            Account account = loanPayment.TakenLoan.Client.PrimaryAccount;

            account.Amount = TryPayLoanPayment(account.Amount, loanPayment);
            CheckLoanPaymentStatus(loanPayment);
            CheckTakenLoanStatus(loanPayment.TakenLoan);
            this.gangsterBankUnitOfWork.ClientsRepository.CreateOrUpdate(loanPayment.TakenLoan.Client);
        }
示例#21
0
        protected LoanPayment GetLoanPayment(int?id)
        {
            LoanPayment loanPayment = db.LoanPayments.Find(id);

            if (loanPayment == null || loanPayment.User.Id != user.Id)
            {
                return(null);
            }
            loanPayment.Loan = loanPayment.Loan.Populate(loanPayment.User);
            return(loanPayment);
        }
示例#22
0
        public ActionResult Create([Bind(Include = "ID,DateOfPayment,AmountOfPayment,Remarks")] LoanPayment loanPayment)
        {
            if (ModelState.IsValid)
            {
                db.LoanPayments.Add(loanPayment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(loanPayment));
        }
示例#23
0
        private void UpdateLoanStatus(Loan loan, LoanPayment loanPayment)
        {
            decimal previousLoanPayments =
                _unitOfWork.LoanPayments.Where(x => x.LoanNo == loan.LoanNo).Sum(s => (decimal?)s.AmountPaid) ?? 0;
            decimal totalAmountPaidSoFar = previousLoanPayments + loanPayment.AmountPaid;

            if (loan.Amount == totalAmountPaidSoFar)
            {
                //Remark: this will update entity in unitOfWork, Make sure to save changes on the same unitOfWork in order for change to be reflected in database.
                loan.Status = LoanStatus.Paid;
            }
        }
示例#24
0
        public async Task ShouldDelete_LoanPayment_UsingLoanAgreementAggregate()
        {
            LoanAgreement agreement = await _loanAgreementRepo.GetByIdAsync(new Guid("1511c20b-6df0-4313-98a5-7c3561757dc2"));

            LoanPayment payment = agreement.LoanPayments.FirstOrDefault(p => p.Id == new Guid("409e60dc-bbe6-4ca9-95c2-ebf6886e8c4c"));

            agreement.DeleteLoanPayment(payment.Id);
            await _unitOfWork.Commit();

            LoanPayment result = agreement.LoanPayments.FirstOrDefault(p => p.Id == new Guid("409e60dc-bbe6-4ca9-95c2-ebf6886e8c4c"));

            Assert.Null(result);
        }
示例#25
0
        public ActionResult EditPayment(int?id)
        {
            ViewBag.Action    = "Edit Payment";
            ViewBag.Calculate = false;
            LoanPayment loanPayment = GetLoanPayment(id);

            if (loanPayment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Users            = GetAvailableUsers(loanPayment.Loan);
            ViewBag.SharedPercentage = Enum.GetValues(typeof(SharedPercentage));
            return(View("Payment", loanPayment));
        }
示例#26
0
        // GET: LoanPayments/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LoanPayment loanPayment = db.LoanPayments.Find(id);

            if (loanPayment == null)
            {
                return(HttpNotFound());
            }
            return(View(loanPayment));
        }
示例#27
0
        /// <summary>
        /// Function to add current payment of loan to database
        /// </summary>
        /// <param name="loanPayment"></param>
        public void AddLoanPayment(LoanPayment loanPayment)
        {
            moneyManagerContext.LoanPayment.Add(loanPayment);
            var loan = moneyManagerContext.Loan.Find(loanPayment.LoanId);
            //total amount payed or recieved for loan
            var totalPayed = moneyManagerContext.LoanPayment.Where(entry => entry.LoanId == loanPayment.LoanId).Sum(entry => entry.LoanPaymentAmount);

            if (totalPayed >= loan.LoanAmount)
            {
                //set payed =true is whole amount is payed or received
                loan.IsLoanPayed = true;
            }
            moneyManagerContext.Entry(loan).State = EntityState.Modified;
            moneyManagerContext.SaveChanges();
        }
示例#28
0
        public async Task <bool> Pay(Loan loan, decimal amount)
        {
            loanBL.Payment(loan, amount);
            _context.Update(loan);
            LoanPayment lPayment = new LoanPayment
            {
                Amount      = amount,
                LoanID      = loan.Id,
                PaymentTime = DateTime.Now,
                Details     = $"Payment of {amount}, {loan.Balance} remaining"
            };

            _context.Add(lPayment);
            await _context.SaveChangesAsync();

            return(true);
        }
示例#29
0
        private void ProceedPayment(LoanPayment payment, DateTime date, Client client)
        {
            var paymentDate = payment.Date;

            if (paymentDate < date)
            {
                this.SendDelinquentPaymentNotification(payment, client);
            }
            else if (paymentDate == date)
            {
                this.SendTodayPaymentNotification(payment, client);
            }
            else if (paymentDate < date.AddDays(3))
            {
                this.Send3DayPaymentNotification(payment, client);
            }
        }
示例#30
0
        public async Task ShouldUpdate_LoanPayment_UsingLoanAgreementAggregate()
        {
            LoanAgreement agreement = await _loanAgreementRepo.GetByIdAsync(new Guid("1511c20b-6df0-4313-98a5-7c3561757dc2"));

            LoanPayment payment = agreement.LoanPayments.FirstOrDefault(p => p.Id == new Guid("2205ebde-58dc-4af7-958b-9124d9645b38"));

            payment.UpdatePaymentDueDate(PaymentDueDate.Create(new DateTime(2021, 1, 10)));
            payment.UpdateLoanInterestAmount(LoanInterestAmount.Create(360.07M));

            agreement.UpdateLoanPayment(payment);
            await _unitOfWork.Commit();

            LoanPayment result = agreement.LoanPayments.FirstOrDefault(p => p.Id == new Guid("2205ebde-58dc-4af7-958b-9124d9645b38"));

            Assert.Equal(new DateTime(2021, 1, 10), result.PaymentDueDate);
            Assert.Equal(360.07M, result.LoanInterestAmount);
        }
示例#31
0
        public static LoanPayment CreateLoanPayment(Payment payment, PartyRole customerPartyRole)
        {
            decimal OwnerLoanBalance = 0;
            decimal OwnerInterest = 0;
            decimal CoOwnerBalance = 0;
            decimal CoOwnerInterest = 0;

            var ownerLoans = from farc in Context.FinancialAccountRoles
                               join pr in Context.PartyRoles on farc.PartyRoleId equals pr.Id
                               join ls in Context.LoanAccountStatus on farc.FinancialAccountId equals ls.FinancialAccountId
                               where pr.PartyId == customerPartyRole.PartyId
                               && pr.EndDate == null
                               && (pr.RoleTypeId == RoleType.OwnerFinancialType.Id)
                               && ls.IsActive == true && (ls.StatusTypeId != LoanAccountStatusType.RestructuredType.Id
                               && ls.StatusTypeId != LoanAccountStatusType.PaidOffType.Id)
                               select ls.LoanAccount;
            if (ownerLoans.Count() != 0)
                OwnerLoanBalance = ownerLoans.Sum(entity => entity.LoanBalance);

            var coOwnerLoans = from farc in Context.FinancialAccountRoles
                               join pr in Context.PartyRoles on farc.PartyRoleId equals pr.Id
                               join ls in Context.LoanAccountStatus on farc.FinancialAccountId equals ls.FinancialAccountId
                               where pr.PartyId == customerPartyRole.PartyId
                               && pr.EndDate == null
                               && (pr.RoleTypeId == RoleType.CoOwnerFinancialType.Id
                               || pr.RoleTypeId == RoleType.GuarantorFinancialType.Id)
                               && ls.IsActive == true && (ls.StatusTypeId != LoanAccountStatusType.RestructuredType.Id
                               && ls.StatusTypeId != LoanAccountStatusType.PaidOffType.Id)
                               select ls.LoanAccount;

            if (coOwnerLoans.Count() != 0)
                CoOwnerBalance = coOwnerLoans.Sum(entity => entity.LoanBalance);

            var ownerReceivables = from l in ownerLoans
                              join r in Context.Receivables on l.FinancialAccountId equals r.FinancialAccountId
                              join rs in Context.ReceivableStatus on r.Id equals rs.ReceivableId
                              where rs.IsActive == true && r.Balance > 0 && (rs.StatusTypeId == ReceivableStatusType.OpenType.Id
                              || rs.StatusTypeId == ReceivableStatusType.PartiallyPaidType.Id)
                              select r;

            if (ownerReceivables.Count() != 0)
                OwnerInterest = ownerReceivables.Sum(entity => entity.Balance);

            var coOwnerReceivables = from l in coOwnerLoans
                                   join r in Context.Receivables on l.FinancialAccountId equals r.FinancialAccountId
                                   join rs in Context.ReceivableStatus on r.Id equals rs.ReceivableId
                                   where rs.IsActive == true && r.Balance > 0 && (rs.StatusTypeId == ReceivableStatusType.OpenType.Id
                                   || rs.StatusTypeId == ReceivableStatusType.PartiallyPaidType.Id)
                                   select r;

            if (coOwnerReceivables.Count() != 0)
                CoOwnerInterest = coOwnerReceivables.Sum(entity => entity.Balance);

            LoanPayment loanpayment = new LoanPayment();
            loanpayment.Payment = payment;
            loanpayment.OwnerOutstandingLoan = OwnerLoanBalance;
            loanpayment.OwnerOutstandingInterest = OwnerInterest;
            loanpayment.CoOwnerOutstandingLoan = CoOwnerBalance;
            loanpayment.CoOwnerOutstandingInterest = CoOwnerInterest;
            return loanpayment;
        }