public LoanHistoryController( CustomerRepository customersRepository, PaymentRolloverRepository rolloverRepository, LoanScheduleRepository loanScheduleRepository, IEzbobWorkplaceContext context, LoanRepository loanRepository, PayPointApi paypoint, ServiceClient serviceClient) { this.customerRepository = customersRepository; this.rolloverRepository = rolloverRepository; this.loanScheduleRepository = loanScheduleRepository; this.context = context; this.loanRepository = loanRepository; this.paypoint = paypoint; this.serviceClient = serviceClient; }
public UnitOfWork(INavyAccountDbContext context) { this.context = context; Users = new UserRepository(context); Menus = new MenuRepository(context); RoleMenus = new RoleMenuRepository(context); MenuGroups = new MenuGroupRepository(context); UserRoles = new UserRoleRepository(context); FundType = new FundTypeRepo(context); actType = new AccountTypeRepository(context); balSheet = new BalanceSheetRepository(context); mainAccount = new MainAccountRepository(context); accountChart = new ChartRepository(context); subtype = new SubTypeRepository(context); fundTypeCode = new FundTypeRepository(context); loanType = new LoanTypeRepo(context); rank = new RankRepo(context); person = new PersonRepo(context); beneficiary = new BeneficiaryRepo(context); bank = new BankRepository(context); pfundrate = new PfFundRateRepository(context); contribution = new NPFContributionRepository(context); loanRegisterRepository = new LoanRegisterRepository(context); register = new InvestmentRegisterRepository(context); loanStatus = new LoanStatusRepository(context); schedule = new LoanScheduleRepository(context); balance = new TrialBalanceRepository(context); accountHistory = new AccountHistoryRepository(context); npf_Ledgers = new LedgerRepositoy(context); report = new TrialBalanceReportRepository(context); history = new TrialBalanceHistoryRepository(context); pf_loandisc = new LoandiscRepo(context); loanPerRank = new LoanPerRankRepository(context); claimregister = new ClaimRepository(context); npfHistories = new FinancialDocRepo(context); trail = new AuditRailRepository(context); npf_contrdisc = new ContrRepo(context); surplus = new SurplusRepository(context); cam = new ClaimTypeRepository(context); navip = new NavipRepository(context); loantypereview = new LoanTypeReviewRepo(context); }
//----------------------------------------------------------------------------------- /// <summary> /// Make automatic payment for given installment /// Called from PaypointCharger job /// </summary> /// <param name="customerId"></param> /// <param name="loanId"></param> /// <param name="loanScheduleId">Installment Id</param> /// <param name="amount">Amount to pay</param> /// <returns>PayPointReturnData as a result of call to paypoint API</returns> public PayPointReturnData MakeAutomaticPayment( int customerId, int loanId, int loanScheduleId, decimal amount ) { LoanScheduleRepository installments = (LoanScheduleRepository)ObjectFactory.GetInstance <ILoanScheduleRepository>(); var loanPaymentFacade = new LoanPaymentFacade(); PayPointReturnData payPointReturnData = null; installments.BeginTransaction(); try { var installment = installments.Get(loanScheduleId); var loan = installment.Loan; var customer = loan.Customer; var now = DateTime.UtcNow; NL_Payments nlPayment = new NL_Payments() { Amount = amount, PaymentMethodID = (int)NLLoanTransactionMethods.Auto, PaymentStatusID = (int)NLPaymentStatuses.Active, PaymentSystemType = NLPaymentSystemTypes.Paypoint, CreationTime = now, CreatedByUserID = 1, Notes = "autocharger" }; Log.InfoFormat("Making automatic repayment for customer {0}(#{1}) for amount {2} for loan# {3}({4})", customer.PersonalInfo.Fullname, customer.RefNumber, amount, loan.RefNumber, loan.Id); PayPointCard defaultCard = customer.PayPointCards.FirstOrDefault(x => x.IsDefaultCard); if (defaultCard == null && customer.PayPointCards.Any()) { defaultCard = customer.PayPointCards.First(); } if (defaultCard == null) { // ReSharper disable once ThrowingSystemException throw new Exception("Debit card not found"); } var payPointTransactionId = defaultCard.TransactionId; try { payPointReturnData = RepeatTransactionEx(defaultCard.PayPointAccount, payPointTransactionId, amount); // set real charged amount nlPayment.Amount = amount; } catch (PayPointException ex) { loan.Transactions.Add(new PaypointTransaction { Amount = amount, Description = ex.PaypointData.Message ?? "Exception:" + ex.Message, PostDate = now, Status = LoanTransactionStatus.Error, PaypointId = payPointTransactionId, IP = "", Balance = loan.Balance, Principal = loan.Principal, Loan = loan, LoanTransactionMethod = ObjectFactory.GetInstance <DatabaseDataHelper>().LoanTransactionMethodRepository.FindOrDefault("Auto") }); installments.CommitTransaction(); // save failed NL payment + PP transaction long nlLoanId = ObjectFactory.GetInstance <IEzServiceAccessor>().GetLoanByOldID(loanId, customerId); if (nlLoanId > 0) { nlPayment.Amount = 0; nlPayment.PaymentStatusID = (int)NLPaymentStatuses.Error; nlPayment.PaypointTransactions.Clear(); nlPayment.PaypointTransactions.Add(new NL_PaypointTransactions() { TransactionTime = now, Amount = amount, // in the case of Exception amount should be 0 ???? Notes = ex.PaypointData.Message ?? "Exception:" + ex.Message, PaypointTransactionStatusID = (int)NLPaypointTransactionStatuses.Error, IP = string.Empty, PaypointUniqueID = payPointTransactionId, PaypointCardID = defaultCard.Id }); Log.InfoFormat("Failed Paypoint transaction: customerId={0} loanID = {1}, loanScheduleId={2} amount={3}; nlPayment={4}", customerId, loanId, loanScheduleId, amount, nlPayment); ObjectFactory.GetInstance <IEzServiceAccessor>().AddPayment(loan.Customer.Id, nlPayment); } return(ex.PaypointData); } installments.CommitTransaction(); loanPaymentFacade.PayLoan(loan, payPointReturnData.NewTransId, amount, null, now, "auto-charge", false, null, nlPayment); } catch (Exception e) { if (!(e is PayPointException)) { Log.Error(e); } if (payPointReturnData == null) { payPointReturnData = new PayPointReturnData { Error = e.Message } } ; installments.RollbackTransaction(); } return(payPointReturnData); }