public CalculateAprMethod(ALoanCalculator calculator, DateTime?aprDate) : base(calculator, false) { MaxIterationLimit = DefaultMaxIterationsLimit; CalculationAccuracy = DefaultCalculationAccuracy; AprDate = (aprDate ?? DateTime.UtcNow).Date; } // constructor
public void CreateCalcInstance() { NL_Model m = new NL_Model(56); try { Type myType = Type.GetType(CurrentValues.Instance.DefaultLoanCalculator.Value); // "Ezbob.Backend.CalculateLoan.LoanCalculator.LegacyLoanCalculator, Ezbob.Backend.CalculateLoan.LoanCalculator, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null"); if (myType != null) { ALoanCalculator calc = (ALoanCalculator)Activator.CreateInstance(myType, m); Console.WriteLine(calc); calc.CreateSchedule(); } } catch (Exception e) { Console.WriteLine(e); } }
public CreateScheduleMethod(ALoanCalculator calculator) : base(calculator, false) { } // constructor
public RolloverReschedulingMethod(ALoanCalculator calculator) : base(calculator, false) { } // constructor
} // CalculateTotal /// <exception cref="OverflowException">The number of elements in is larger than <see cref="F:System.Int32.MaxValue" />.</exception> /// <exception cref="NullReferenceException"><paramref /> is null. </exception> /// <exception cref="NoScheduleException">Condition. </exception> public AgreementModel NL_BuildAgreementModel(Customer customer, NL_Model nlModel) { // fill in loan+history with offer data nlModel = this.serviceClient.Instance.BuildLoanFromOffer(this.context != null ? this.context.UserId : customer.Id, nlModel.CustomerID, nlModel).Value; ALoanCalculator nlCalculator = null; // 2. get Schedule and Fees try { // init calculator nlCalculator = new LegacyLoanCalculator(nlModel); // model should contain Schedule and Fees after this invocation nlCalculator.CreateSchedule(); // create primary dates/p/r/f distribution of schedules (P/n) and setup/servicing fees. 7 September - fully completed schedule + fee + amounts due, without payments. } catch (NoInitialDataException noDataException) { this.log.Alert("CreateSchedule failed: {0}", noDataException.Message); } catch (InvalidInitialAmountException amountException) { this.log.Alert("CreateSchedule failed: {0}", amountException.Message); } catch (InvalidInitialInterestRateException interestRateException) { this.log.Alert("CreateSchedule failed: {0}", interestRateException.Message); } catch (InvalidInitialRepaymentCountException paymentsException) { this.log.Alert("CreateSchedule failed: {0}", paymentsException.Message); } catch (Exception ex) { this.log.Alert("Failed to create Schedule for customer {0}, err: {1}", nlModel.CustomerID, ex); } finally { if (nlCalculator == null) { this.log.Alert("failed to get nlCalculator for customer: {0}", nlModel.CustomerID); } // if } // try var history = nlModel.Loan.LastHistory(); // no Schedule if (history.Schedule.Count == 0) { this.log.Alert("No Schedule. Customer: {0}", nlModel.CustomerID); return null; } var model = new AgreementModel() { Schedule = new List<LoanScheduleItemModel>() }; // fill in AgreementModel schedules list foreach (NL_LoanSchedules s in history.Schedule) { var item = new LoanScheduleItemModel { Id = s.LoanScheduleID, AmountDue = s.AmountDue, Date = s.PlannedDate, Interest = s.Interest, Status = Enum.GetName(typeof(NLScheduleStatuses), s.LoanScheduleStatusID).DescriptionAttr(), LoanRepayment = s.Principal, Balance = s.Balance, Fees = s.Fees, InterestRate = s.InterestRate }; item.StatusDescription = item.Status; model.Schedule.Add(item); } // for each model.CustomerEmail = customer.Name; model.FullName = customer.PersonalInfo.Fullname; model.TypeOfBusinessName = customer.PersonalInfo.TypeOfBusinessName; var businessType = customer.PersonalInfo.TypeOfBusiness; var company = customer.Company; CustomerAddress companyAddress = null; if (company != null) { switch (businessType.Reduce()) { case TypeOfBusinessReduced.Limited: model.CompanyNumber = company.ExperianRefNum ?? company.CompanyNumber; goto case TypeOfBusinessReduced.NonLimited; case TypeOfBusinessReduced.NonLimited: model.CompanyName = company.ExperianCompanyName ?? company.CompanyName; companyAddress = company.ExperianCompanyAddress.LastOrDefault() ?? company.CompanyAddress.LastOrDefault(); break; } // switch } // if model.CompanyAdress = companyAddress.GetFormatted(); model.PersonAddress = customer.AddressInfo.PersonalAddress.FirstOrDefault().GetFormatted(); // collect all setup/servicing "spreaded" fees List<NL_LoanFees> loanSetupFees = nlModel.Loan.Fees.Where(f => f.LoanFeeTypeID == (int)NLFeeTypes.SetupFee || f.LoanFeeTypeID == (int)NLFeeTypes.ServicingFee).ToList(); // get fees sum decimal totalFees = 0m; loanSetupFees.ForEach(f => totalFees += f.Amount); decimal totalPrincipal = model.Schedule.Sum(a => a.LoanRepayment); // formatted totals model.TotalAmount = FormattingUtils.NumericFormats(model.Schedule.Sum(a => a.AmountDue)); model.TotalPrincipal = FormattingUtils.NumericFormats(totalPrincipal); model.TotalInterest = FormattingUtils.NumericFormats(model.Schedule.Sum(a => a.Interest)); model.TotalAmoutOfCredit = model.TotalPrincipal; //FormattingUtils.NumericFormats(model.Schedule.Sum(a => a.LoanRepayment)); model.TotalFees = FormattingUtils.NumericFormats(totalFees); decimal currencyRate = GetUSDCurrencyRate(); model.TotalPrincipalUsd = "$ " + (CurrentValues.Instance.AlibabaCurrencyConversionCoefficient * currencyRate * totalPrincipal).ToString("N", CultureInfo.CreateSpecificCulture("en-gb")); model.CurentDate = FormattingUtils.FormatDateTimeToString(DateTime.UtcNow); model.CurrentDate = DateTime.UtcNow; model.FormattedSchedules = model.Schedule.Select((installment, i) => new FormattedSchedule { AmountDue = FormattingUtils.NumericFormats(installment.AmountDue), Principal = FormattingUtils.NumericFormats(installment.LoanRepayment), Interest = FormattingUtils.NumericFormats(installment.Interest), Fees = FormattingUtils.NumericFormats(installment.Fees), Date = FormattingUtils.FormatDateToString(installment.Date), StringNumber = FormattingUtils.ConvertingNumberToWords(i + 1), InterestRate = string.Format("{0:0.00}", installment.InterestRate * 100), Iterration = i + 1, }).ToList(); // TODO update from history? model.InterestRate = history.InterestRate * 100; model.SetupFee = FormattingUtils.NumericFormats(totalFees); model.SetupFeeAmount = FormattingUtils.NumericFormats((int)CurrentValues.Instance.SetupFeeFixed); model.SetupFeePercent = CurrentValues.Instance.SetupFeePercent; //// FEES TODO ////According to new logic the setup fee is always percent and min setup fee is amount SetupFeeFixed ???? if ((totalFees > 0) || (nlModel.Offer.BrokerSetupFeePercent.HasValue && nlModel.Offer.BrokerSetupFeePercent.Value > 0)) { decimal setupFeePercent = totalFees + nlModel.Offer.BrokerSetupFeePercent ?? 0M; model.SetupFeePercent = (setupFeePercent * 100).ToString(CultureInfo.InvariantCulture); } // if // TODO was is das? model.IsBrokerFee = false; model.IsManualSetupFee = false; if (nlCalculator != null) model.APR = nlCalculator.CalculateApr(history.EventTime); model.InterestRatePerDay = model.Schedule[1].InterestRate / 30; // For first month model.InterestRatePerDayFormatted = string.Format("{0:0.00}", model.InterestRatePerDay); model.InterestRatePerYearFormatted = string.Format("{0:0.00}", model.InterestRate * 12); model.LoanType = Enum.GetName(typeof(NLLoanTypes), nlModel.Loan.LoanTypeID); model.TermOnlyInterest = model.Schedule.Count(s => s.LoanRepayment == 0); model.TermOnlyInterestWords = FormattingUtils.ConvertToWord(model.TermOnlyInterest).ToLower(); model.TermInterestAndPrincipal = model.Schedule.Count(s => s.LoanRepayment != 0 && s.Interest != 0); model.TermInterestAndPrincipalWords = FormattingUtils.ConvertToWord(model.TermInterestAndPrincipal).ToLower(); model.isHalwayLoan = Enum.GetName(typeof(NLLoanTypes), nlModel.Loan.LoanTypeID) == NLLoanTypes.HalfWayLoanType.ToString(); model.CountRepayment = model.Schedule.Count; model.Term = model.Schedule.Count; model.TotalPrincipalWithSetupFee = FormattingUtils.NumericFormats(totalPrincipal - totalFees); return model; } // NL_BuildAgreementModel
protected AMethod(ALoanCalculator calculator, bool writeToLog) { Calculator = calculator; WriteToLog = writeToLog; } // constructor
} // constructor protected AMethod(ALoanCalculator calculator) { Calculator = calculator; } // constructor