public bool IsAmountChangingAllowed(CashRequest cr) {
			if (cr == null || string.IsNullOrEmpty(cr.LoanTemplate))
				return true;

			var model = EditLoanDetailsModel.Parse(cr.LoanTemplate);

			//compare number of installments/other actions
			if (model.Items.Count(i => i.Type == "Installment") != cr.RepaymentPeriod)
				return false;
			if (model.Items.Count != cr.RepaymentPeriod)
				return false;

			//compare template balances with actual
			var expectedBalances = cr.LoanType.GetBalances(cr.ApprovedSum(), cr.RepaymentPeriod);
			var actualBalances = model.Items.Where(i => i.Type == "Installment").Select(i => i.Balance);
			if (expectedBalances.Except(actualBalances).Any())
				return false;

			return true;
		}
Exemplo n.º 2
0
        public JsonResult GetOffer(GetInstantOfferModel model, CompanyInfo company)
        {
            var context  = ObjectFactory.GetInstance <IWorkplaceContext>();
            var response = this.m_oServiceClient.Instance.BrokerInstantOffer(new BrokerInstantOfferRequest {
                Created                    = DateTime.UtcNow,
                BrokerId                   = context.UserId,
                CompanyNameNumber          = model.CompanyNameNumber,
                AnnualTurnover             = model.AnnualTurnover,
                AnnualProfit               = model.AnnualProfit,
                NumOfEmployees             = model.NumOfEmployees,
                MainApplicantCreditScore   = model.MainApplicantCreditScore,
                IsHomeOwner                = model.IsHomeOwner,
                ExperianRefNum             = company.BusRefNum,
                ExperianCompanyName        = company.BusName,
                ExperianCompanyLegalStatus = company.LegalStatus,
                ExperianCompanyPostcode    = company.PostCode
            });

            var loanTypeRepository   = ObjectFactory.GetInstance <LoanTypeRepository>();
            var loanSourceRepository = ObjectFactory.GetInstance <LoanSourceRepository>();
            var loanBuilder          = ObjectFactory.GetInstance <LoanBuilder>();
            var aprCalc = ObjectFactory.GetInstance <APRCalculator>();

            var cr = new CashRequest {
                ApprovedRepaymentPeriod = response.Response.RepaymentPeriod,
                InterestRate            = response.Response.InterestRate,
                LoanType           = loanTypeRepository.Get(response.Response.LoanTypeId),
                LoanSource         = loanSourceRepository.Get(response.Response.LoanSourceId),
                ManagerApprovedSum = response.Response.ApprovedSum,
                UseBrokerSetupFee  = response.Response.UseBrokerSetupFee,
                UseSetupFee        = response.Response.UseSetupFee,
                RepaymentPeriod    = response.Response.RepaymentPeriod,
                LoanLegals         = new List <LoanLegal>()
            };

            var loan = loanBuilder.CreateNewLoan(cr,
                                                 cr.ApprovedSum(),
                                                 DateTime.UtcNow,
                                                 cr.ApprovedRepaymentPeriod.HasValue ? cr.ApprovedRepaymentPeriod.Value : 12);

            var calc = new LoanRepaymentScheduleCalculator(loan, loan.Date, CurrentValues.Instance.AmountToChargeFrom);

            calc.GetState();

            try {
                long nlLoanId = this.m_oServiceClient.Instance.GetLoanByOldID(loan.Id, loan.Customer.Id, context.UserId).Value;
                if (nlLoanId > 0)
                {
                    var nlModel = this.m_oServiceClient.Instance.GetLoanState(loan.Customer.Id, nlLoanId, loan.Date, context.UserId, true).Value;
                    ms_oLog.Info("<<< NL_Compare: {0}\n===============loan: {1}  >>>", nlModel, loan);
                }
                // ReSharper disable once CatchAllClause
            } catch (Exception ex) {
                ms_oLog.Info("<<< NL_Compare fail at: {0}, err: {1}", Environment.StackTrace, ex.Message);
            }

            var apr = loan.LoanAmount == 0 ? 0 : aprCalc.Calculate(loan.LoanAmount, loan.Schedule, loan.SetupFee, loan.Date);

            var loanOffer = LoanOffer.InitFromLoan(loan, apr, null, cr);

            return(Json(loanOffer, JsonRequestBehavior.AllowGet));
        }         // GetOffer