private void AddToOldDueLoansInstructions(Payment currentPayment, IList <Loan> oldDepitLoans) { foreach (var oldLoan in oldDepitLoans) { var instruction = new PaymentInstruction { EarnPercent = 0, LoanType = oldLoan.LoanType, Payment = currentPayment, PeriodYear = oldLoan.PeriodYear, OldLoan = true }; AddToOldDueLoansInstructions(instruction); } }
private void AddToCurrentPaymentLoansInstructions(Payment currentPayment, IEnumerable <Loan> currentPaymentLoans) { foreach (var loan in currentPaymentLoans) { var instruction = new PaymentInstruction { EarnPercent = 0, LoanType = loan.LoanType, Payment = currentPayment, PeriodYear = loan.PeriodYear, OldLoan = false }; AddToCurrentPaymentLoansInstructions(instruction); } }
private decimal PayLoan(Loan loan, PaymentTransaction detail) { RepositoryBase <LoanStatus> statusRepos = _unitOfWork.LoanStatuses; PaymentInstruction order = GetLoanOrder(detail.Payment, loan); if (order == null) { throw new InvalidOperationException("You must register payment orders for all types of loans"); } decimal amountToPaid = (loan.Amount * order.EarnPercent) / 100; //In case if the amountToPaid is greater than the actual balance //adjust the amountToPaid to be just the acutal balance. //This behvior is accour due to loans that is INPAYING status //and the payment order earn percent will exceed the remaining balance. if (amountToPaid > loan.Balance) { amountToPaid = loan.Balance; } var history = new LoanPayment { Id = Guid.NewGuid(), Loan = loan, FamilyMember = detail.FamilyMember, PaymentTransaction = detail, AmountPaid = amountToPaid }; loan.Paid = (loan.Paid + amountToPaid); loan.Balance = loan.Amount - loan.Paid; if (loan.Balance == 0.0M) { loan.LoanStatus = statusRepos.GetById(3); } else { loan.LoanStatus = statusRepos.GetById(2); } _historyRepository.Add(history); _uiLoansHistory.Add(history); return(amountToPaid); }
public IActionResult Create(PaymentInstructionViewModel viewModel) { PaymentInstruction paymentInstruction = null; switch (viewModel.SelectedPaymentMethod) { case "Cash": paymentInstruction = new Cash(); break; case "Cheque": paymentInstruction = new Cheque(); break; } paymentInstruction.Id = idGenerator.GetId(); paymentInstruction.Amount = viewModel.Amount; paymentInstruction.Status = StatusType.Draft; repository.Add(paymentInstruction); return(View("Index", repository.GetAll())); }
private PaymentInstruction GetLoanOrder(Payment payment, Loan loan) { PaymentInstruction order = null; RepositoryBase <PaymentInstruction> ordersRepos = _unitOfWork.PaymentInstructions; //First check that this loans is belong to the current payment period and sequence. bool currentPaymentLoan = loan.PeriodSetting.Id == payment.PeriodSetting.Id && loan.PaymentSequence.Id == payment.PaymentSequence.Id; //If so if (!currentPaymentLoan) { //Get the order of this loan type which is not belong to this payment sequnce order = ordersRepos.Query( x => x.Payment.PaymentNo == payment.PaymentNo && x.LoanType.Code == loan.LoanType.Code && x.PeriodSetting.Id == loan.PeriodSetting.Id && x.OldLoan ).Single(); } else { order = ordersRepos.Query( x => x.Payment.PaymentNo == payment.PaymentNo && x.LoanType.Code == loan.LoanType.Code && x.PeriodSetting.Id == loan.PeriodSetting.Id && x.OldLoan == false ).Single(); } return(order); }
public void Add(PaymentInstruction item) { items.Add(item); }
private void AddToOldDueLoansInstructions(PaymentInstruction instruction) { OldDueLoansInstructions.Add(instruction); }
private void AddToCurrentPaymentLoansInstructions(PaymentInstruction instruction) { CurrentPaymentLoansInstructions.Add(instruction); }