public JsonResult RemoveLateFeeOption(int id) { LoanOptions options = this.loanOptionsRepository.GetByLoanId(id) ?? LoanOptions.GetDefault(id); options.AutoLateFees = false; options.StopLateFeeFromDate = null; options.StopLateFeeToDate = null; this.loanOptionsRepository.SaveOrUpdate(options); var PropertiesUpdateList = new List <String>() { "StopLateFeeFromDate", "StopLateFeeToDate" }; NL_SaveLoanOptions(options, PropertiesUpdateList); EditLoanDetailsModel model = this._loanModelBuilder.BuildModel(this._loans.Get(id)); model.Options = this.loanOptionsRepository.GetByLoanId(id); RescheduleSetmodel(id, model); return(Json(model)); } // RemoveLateFeeOption
} // ChangeExternalCollectionStatus private void NL_SaveLoanOptions(Customer customer, LoanOptions options) { NL_LoanOptions nlOptions = new NL_LoanOptions() { LoanID = options.LoanId, CaisAccountStatus = options.CaisAccountStatus, EmailSendingAllowed = options.EmailSendingAllowed, LatePaymentNotification = options.LatePaymentNotification, LoanOptionsID = options.Id, MailSendingAllowed = options.MailSendingAllowed, ManualCaisFlag = options.ManualCaisFlag, PartialAutoCharging = options.ReductionFee, SmsSendingAllowed = options.SmsSendingAllowed, StopAutoChargeDate = MiscUtils.NL_GetStopAutoChargeDate(options.AutoPayment, options.StopAutoChargeDate), StopLateFeeFromDate = MiscUtils.NL_GetLateFeeDates(options.AutoLateFees, options.StopLateFeeFromDate, options.StopLateFeeToDate).Item1, StopLateFeeToDate = MiscUtils.NL_GetLateFeeDates(options.AutoLateFees, options.StopLateFeeFromDate, options.StopLateFeeToDate).Item2, UserID = this.context.UserId, InsertDate = DateTime.Now, IsActive = true, Notes = "From Application Info", }; var PropertiesUpdateList = new List <String>() { "StopAutoChargeDate", "StopLateFeeFromDate", "StopLateFeeToDate", }; var nlStrategy = this.serviceClient.Instance.AddLoanOptions(this.context.UserId, customer.Id, nlOptions, options.LoanId, PropertiesUpdateList.ToArray()); }
private void NL_SaveLoanOptions(LoanOptions options, List <String> PropertiesUpdateList) { int customerId = this._loans.Get(options.LoanId).Customer.Id; //NL Loan Options NL_LoanOptions nlOptions = new NL_LoanOptions() { LoanID = options.LoanId, CaisAccountStatus = options.CaisAccountStatus, EmailSendingAllowed = options.EmailSendingAllowed, LatePaymentNotification = options.LatePaymentNotification, LoanOptionsID = options.Id, MailSendingAllowed = options.MailSendingAllowed, ManualCaisFlag = options.ManualCaisFlag, PartialAutoCharging = options.ReductionFee, SmsSendingAllowed = options.SmsSendingAllowed, StopAutoChargeDate = MiscUtils.NL_GetStopAutoChargeDate(options.AutoPayment, options.StopAutoChargeDate), StopLateFeeFromDate = MiscUtils.NL_GetLateFeeDates(options.AutoLateFees, options.StopLateFeeFromDate, options.StopLateFeeToDate).Item1, StopLateFeeToDate = MiscUtils.NL_GetLateFeeDates(options.AutoLateFees, options.StopLateFeeFromDate, options.StopLateFeeToDate).Item2, UserID = this._context.UserId, InsertDate = DateTime.Now, IsActive = true, Notes = "From Loan Editor Controller", }; var nlStrategy = this.serviceClient.Instance.AddLoanOptions(this._context.UserId, customerId, nlOptions, options.LoanId, PropertiesUpdateList.ToArray()); Log.DebugFormat("NL LoanOptions save: LoanOptionsID: {0}, Error: {1}", nlStrategy.Value, nlStrategy.Error); }
public JsonResult Index(int loanId) { var options = this._loanOptionsRepository.GetByLoanId(loanId) ?? LoanOptions.GetDefault(loanId); var loan = this._loanRepository.Get(loanId); var flags = this._caisFlagRepository.GetForStatusType(); var model = new LoanOptionsViewModel(options, loan, flags); return(Json(model, JsonRequestBehavior.AllowGet)); }
/// <exception cref="InvalidCastException"><paramref /> cannot be cast to the element type of the current <see cref="T:System.Array" />.</exception> public override string ToString() { // loan StringBuilder sb = new StringBuilder().Append(PrintHeadersLine(typeof(NL_Loans))).Append(ToStringAsTable()).Append(Environment.NewLine); // freeze interest intervals if (FreezeInterestIntervals.Count > 0) { sb.Append("LoanInterestFreeze:") .Append(Environment.NewLine) .Append(PrintHeadersLine(typeof(NL_LoanInterestFreeze))); FreezeInterestIntervals.ForEach(s => sb.Append(s.ToString())); } //else sb.Append("No LoanInterestFreeze").Append(Environment.NewLine); if (LoanOptions.LoanOptionsID > 0) { sb.Append("LoanOptions:") .Append(Environment.NewLine) .Append(PrintHeadersLine(typeof(NL_LoanOptions))) .Append(LoanOptions.ToStringAsTable()); } //else sb.Append("No Loan options").Append(Environment.NewLine); // rollovers if (AcceptedRollovers.Count > 0) { sb.Append(Environment.NewLine) .Append("AcceptedRollovers:").Append(Environment.NewLine) .Append(PrintHeadersLine(typeof(NL_LoanRollovers))); AcceptedRollovers.ForEach(r => sb.Append(r.ToStringAsTable())); } //else sb.Append("No AcceptedRollovers").Append(Environment.NewLine); // fees if (Fees.Count > 0) { sb.Append(Environment.NewLine) .Append("Fees:").Append(Environment.NewLine) .Append(PrintHeadersLine(typeof(NL_LoanFees))); Fees.ForEach(s => sb.Append(s.ToStringAsTable())); } //else sb.Append("No Fees").Append(Environment.NewLine); // histories if (Histories != null) { sb.Append(Environment.NewLine) .Append("Histories:").Append(Environment.NewLine); Histories.ForEach(h => sb.Append(h.ToString())); } // else sb.Append("No Histories").Append(Environment.NewLine); // payments if (Payments.Count > 0) { sb.Append("Payments:"); Payments.ForEach(p => sb.Append(p.ToString())); } // else sb.Append("No Payments").Append(Environment.NewLine); return(sb.ToString()); }
public JsonResult RemoveFreezeInterval(int id, int intervalid) { Loan loan = this._loans.Get(id); LoanInterestFreeze lif = loan.InterestFreeze.FirstOrDefault(v => v.Id == intervalid); var loan1 = loan; new Transactional(() => { if (lif != null) { lif.DeactivationDate = DateTime.UtcNow; } this._loans.SaveOrUpdate(loan1); }).Execute(); DeactivateLoanInterestFreeze(lif); Log.DebugFormat("remove freeze interest for customer {0}", loan.Customer.Id); loan = this._loans.Get(id); var calc = new LoanRepaymentScheduleCalculator(loan, DateTime.UtcNow, CurrentValues.Instance.AmountToChargeFrom); calc.GetState(); try { long nlLoanId = this.serviceClient.Instance.GetLoanByOldID(id, loan.Customer.Id, this._context.UserId).Value; if (nlLoanId > 0) { var nlModel = this.serviceClient.Instance.GetLoanState(loan.Customer.Id, nlLoanId, DateTime.UtcNow, this._context.UserId, true).Value; Log.InfoFormat("<<< NL_Compare: {0}\n===============loan: {1} >>>", nlModel, loan); } // ReSharper disable once CatchAllClause } catch (Exception ex) { Log.InfoFormat("<<< NL_Compare fail at: {0}, err: {1}", Environment.StackTrace, ex.Message); } EditLoanDetailsModel model = this._loanModelBuilder.BuildModel(loan); model.Options = this.loanOptionsRepository.GetByLoanId(id) ?? LoanOptions.GetDefault(id); RescheduleSetmodel(id, model); return(Json(model)); } // RemoveFreezeInterval
} // CalculateRealAmount private void SendEmails(int loanId, decimal realAmount, Customer customer) { Loan loan = customer.GetLoan(loanId); LoanOptions loanOptions = this.loanOptionsRepository.GetByLoanId(loanId); this.serviceClient.Instance.PayEarly(this.context.User.Id, realAmount, loan.RefNumber); this.serviceClient.Instance.LoanStatusAfterPayment( this.context.UserId, customer.Id, customer.Name, loanId, realAmount, loanOptions == null || loanOptions.EmailSendingAllowed, loan.Balance, loan.Status == LoanStatus.PaidOff ); } // SendEmails
public JsonResult SaveLateFeeOption(int id) { DateTime?lateFeeStartDate = Convert.ToDateTime(HttpContext.Request.QueryString["lateFeeStartDate"]); string lateFeeEndDateStr = HttpContext.Request.QueryString["lateFeeEndDate"]; DateTime?lateFeeEndDate = string.IsNullOrEmpty(lateFeeEndDateStr) ? NoLimitDate : Convert.ToDateTime(lateFeeEndDateStr); LoanOptions options = this.loanOptionsRepository.GetByLoanId(id) ?? LoanOptions.GetDefault(id); EditLoanDetailsModel model = this._loanModelBuilder.BuildModel(this._loans.Get(id)); if (options.StopLateFeeFromDate != null && options.StopLateFeeToDate != null) { // to.Subtract(from) if (options.StopLateFeeToDate.Value.Subtract(options.StopLateFeeFromDate.Value).Days < 0) { model.Errors.Add("'Until date must be greater then From date"); RescheduleSetmodel(id, model); return(Json(model)); } } options.AutoLateFees = true; options.StopLateFeeFromDate = lateFeeStartDate; options.StopLateFeeToDate = lateFeeEndDate; this.loanOptionsRepository.SaveOrUpdate(options); var PropertiesUpdateList = new List <String>() { "StopLateFeeFromDate", "StopLateFeeToDate" }; NL_SaveLoanOptions(options, PropertiesUpdateList); model.Options = this.loanOptionsRepository.GetByLoanId(id); RescheduleSetmodel(id, model); return(Json(model)); } // SaveLateFeeOption
public JsonResult RemoveAutoChargesOption(int id) { LoanOptions options = this.loanOptionsRepository.GetByLoanId(id); options.AutoPayment = true; options.StopAutoChargeDate = null; this.loanOptionsRepository.SaveOrUpdate(options); var PropertiesUpdateList = new List <String>() { "StopAutoChargeDate", }; NL_SaveLoanOptions(options, PropertiesUpdateList); EditLoanDetailsModel model = this._loanModelBuilder.BuildModel(this._loans.Get(id)); model.Options = this.loanOptionsRepository.GetByLoanId(id); RescheduleSetmodel(id, model); return(Json(model)); } // RemoveAutoChargesOption
private void RescheduleSetmodel(int loanID, EditLoanDetailsModel model) { var loan = this._loans.Get(loanID); model.Id = loanID; model.Options = this.loanOptionsRepository.GetByLoanId(model.Id) ?? LoanOptions.GetDefault(model.Id); Log.DebugFormat("RescheduleSetmodel: loanID: {2} model {0}, loan: {1}", model, loan, loanID); ReschedulingArgument renewModel = new ReschedulingArgument(); renewModel.LoanType = loan.GetType().AssemblyQualifiedName; renewModel.LoanID = loanID; renewModel.SaveToDB = false; renewModel.ReschedulingDate = DateTime.UtcNow; renewModel.ReschedulingRepaymentIntervalType = DbConstants.RepaymentIntervalTypes.Month; renewModel.RescheduleIn = true; try { ReschedulingActionResult result = this.serviceClient.Instance.RescheduleLoan(this._context.User.Id, loan.Customer.Id, renewModel); model.ReResultIn = result.Value; //Log.Debug(string.Format("IN=={0}, {1}", renewModel, result.Value)); // ReSharper disable once CatchAllClause } catch (Exception editex) { Log.Error(editex); } renewModel.RescheduleIn = false; renewModel.PaymentPerInterval = 0m; try { ReschedulingActionResult result = this.serviceClient.Instance.RescheduleLoan(this._context.User.Id, loan.Customer.Id, renewModel); model.ReResultOut = result.Value; //Log.Debug(string.Format("OUT=={0}, {1}", renewModel, result.Value)); // ReSharper disable once CatchAllClause } catch (Exception editex) { Log.Error(editex); } }
public JsonResult SaveAutoChargesOption(int id, int schedultItemId) { DateTime now = DateTime.UtcNow; LoanOptions options = this.loanOptionsRepository.GetByLoanId(id) ?? LoanOptions.GetDefault(id); var loan = this._loans.Get(id); options.AutoPayment = false; options.StopAutoChargeDate = null; if (schedultItemId > -1) { var loanScheduleItem = loan.Schedule.Where(x => x.Date > now).FirstOrDefault(x => x.Id == schedultItemId); if (loanScheduleItem != null) { options.StopAutoChargeDate = loanScheduleItem.Date; } else { Log.ErrorFormat("The date selected from DDL is not valid"); } } this.loanOptionsRepository.SaveOrUpdate(options); var PropertiesUpdateList = new List <String>() { "StopAutoChargeDate", }; NL_SaveLoanOptions(options, PropertiesUpdateList); EditLoanDetailsModel model = this._loanModelBuilder.BuildModel(this._loans.Get(id)); model.Options = this.loanOptionsRepository.GetByLoanId(id); RescheduleSetmodel(id, model); return(Json(model)); } // SaveAutoChargesOption
public JsonResult Save(LoanOptions options) { if (options.ManualCaisFlag == "T") { options.ManualCaisFlag = "Calculated value"; } this._loanOptionsRepository.SaveOrUpdate(options); Customer customer = this._loanRepository.Get(options.LoanId).Customer; NL_SaveLoanOptions(customer, options); if (options.CaisAccountStatus == "8") { int minDectForDefault = CurrentValues.Instance.MinDectForDefault; Loan triggeringLoan = null; // Update loan options foreach (Loan loan in customer.Loans) { if (loan.Id == options.LoanId) { triggeringLoan = loan; continue; } if (loan.Status == LoanStatus.PaidOff || loan.Balance < minDectForDefault) { continue; } LoanOptions currentOptions = this._loanOptionsRepository.GetByLoanId(loan.Id) ?? new LoanOptions { LoanId = loan.Id, AutoPayment = true, ReductionFee = true, LatePaymentNotification = true, EmailSendingAllowed = false, MailSendingAllowed = false, SmsSendingAllowed = false, ManualCaisFlag = "Calculated value", AutoLateFees = true }; currentOptions.CaisAccountStatus = "8"; this._loanOptionsRepository.SaveOrUpdate(currentOptions); NL_SaveLoanOptions(customer, options); } // Update customer status CustomerStatuses prevStatus = customer.CollectionStatus; customer.CollectionStatus = this.customerStatusesRepository.Get((int)CollectionStatusNames.Default); customer.CollectionDescription = string.Format("Triggered via loan options:{0}", triggeringLoan != null ? triggeringLoan.RefNumber : "unknown"); // Update status history table var newEntry = new CustomerStatusHistory { Username = User.Identity.Name, Timestamp = DateTime.UtcNow, CustomerId = customer.Id, PreviousStatus = prevStatus, NewStatus = customer.CollectionStatus, }; this.customerStatusHistoryRepository.SaveOrUpdate(newEntry); } return(Json(new { })); }
public LoanOptionsViewModel(LoanOptions loanOptions, Loan loan, IList <CaisFlag> caisFlags) { Options = loanOptions; CalculatedStatus = GetCalculatedStatus(loan); ManualCaisFlags = caisFlags; }
public JsonResult ChangeExternalCollectionStatus(int id, int?externalStatusID) { Customer oCustomer = this.customerRepository.Get(id); if (oCustomer == null) { log.Debug("Customer({0}) not found", id); return(Json(new { error = "Customer not found.", id = id, status = externalStatusID })); } // if var prevExternalCollectionStatus = oCustomer.ExternalCollectionStatus; var newExternalCollectionStatus = (externalStatusID == null) ? null : this.externalCollectionStatusesRepository.Get(externalStatusID); if (newExternalCollectionStatus == null && externalStatusID != null) { log.Debug("Status({0}) not found in the DB repository.", externalStatusID); return(Json(new { error = "Status not found in the DB repository.", id = id, status = externalStatusID })); } // if List <int> addFreeseLoans = new List <int>(); new Transactional(() => { oCustomer.ExternalCollectionStatus = newExternalCollectionStatus; log.Debug("Customer({0}).ExternalCollectionStatus set to {1}", id, externalStatusID); DateTime now = DateTime.UtcNow; if (newExternalCollectionStatus != prevExternalCollectionStatus && (newExternalCollectionStatus == null || prevExternalCollectionStatus == null)) { foreach (Loan loan in oCustomer.Loans.Where(l => l.Status != LoanStatus.PaidOff && l.Balance >= CurrentValues.Instance.MinDectForDefault)) { bool customerInGoodStatus = newExternalCollectionStatus == null && oCustomer.CollectionStatus.IsEnabled; LoanOptions options = this.loanOptionsRepository.GetByLoanId(loan.Id) ?? LoanOptions.GetDefault(loan.Id); options.AutoLateFees = customerInGoodStatus; options.AutoPayment = customerInGoodStatus; options.StopAutoChargeDate = customerInGoodStatus ? (DateTime?)null : now; this.loanOptionsRepository.SaveOrUpdate(options); NL_SaveLoanOptions(oCustomer, options); if (!customerInGoodStatus) { loan.InterestFreeze.Add(new LoanInterestFreeze { Loan = loan, StartDate = now.Date, EndDate = (DateTime?)null, InterestRate = 0, ActivationDate = now, DeactivationDate = null }); addFreeseLoans.Add(loan.Id); } else if (loan.InterestFreeze.Any(f => f.EndDate == null && f.DeactivationDate == null)) { foreach (var interestFreeze in loan.InterestFreeze.Where(f => f.EndDate == null && f.DeactivationDate == null)) { interestFreeze.DeactivationDate = now; DeactivateLoanInterestFreeze(interestFreeze, oCustomer.Id); } } this.loanRepository.SaveOrUpdate(loan); } } }).Execute(); // sync NL freeze foreach (int loanID in addFreeseLoans) { var loan = this.loanRepository.Get(loanID); SaveLoanInterestFreeze(loan.InterestFreeze.Last(), loan.Customer.Id); } this.serviceClient.Instance.SalesForceAddUpdateLeadAccount(this.context.UserId, oCustomer.Name, id, false, false); return(Json(new { error = (string)null, id = id, status = externalStatusID })); } // ChangeExternalCollectionStatus
public JsonResult Save(int customerId, CollectionStatusModel collectionStatus) { var customer = this.customerRepository.Get(customerId); var prevStatus = customer.CollectionStatus; if (prevStatus.Id == collectionStatus.CurrentStatus) { return(Json(new { })); } customer.CollectionStatus = this.customerStatusesRepository.Get(collectionStatus.CurrentStatus); customer.CollectionDescription = collectionStatus.CollectionDescription; List <int> addFreeseLoans = new List <int>(); new Transactional(() => { this.customerRepository.SaveOrUpdate(customer); if (customer.CollectionStatus.IsDefault) { // Update loan options foreach (Loan loan in customer.Loans.Where(l => l.Status != LoanStatus.PaidOff && l.Balance >= CurrentValues.Instance.MinDectForDefault)) { LoanOptions options = this.loanOptionsRepository.GetByLoanId(loan.Id) ?? new LoanOptions { LoanId = loan.Id, AutoPayment = true, ReductionFee = true, LatePaymentNotification = true, EmailSendingAllowed = false, MailSendingAllowed = false, SmsSendingAllowed = false, ManualCaisFlag = "Calculated value", }; options.CaisAccountStatus = "8"; this.loanOptionsRepository.SaveOrUpdate(options); NL_SaveLoanOptions(customer, options); } } DateTime now = DateTime.UtcNow; if (!customer.CollectionStatus.IsEnabled) { // Update loan options add freeze interest foreach (Loan loan in customer.Loans.Where(l => l.Status != LoanStatus.PaidOff && l.Balance >= CurrentValues.Instance.MinDectForDefault)) { LoanOptions options = this.loanOptionsRepository.GetByLoanId(loan.Id) ?? LoanOptions.GetDefault(loan.Id); options.AutoLateFees = false; options.AutoPayment = false; this.loanOptionsRepository.SaveOrUpdate(options); NL_SaveLoanOptions(customer, options); loan.InterestFreeze.Add(new LoanInterestFreeze { Loan = loan, StartDate = now.Date, EndDate = (DateTime?)null, InterestRate = 0, ActivationDate = now, DeactivationDate = null }); this.loanRepository.SaveOrUpdate(loan); addFreeseLoans.Add(loan.Id); } //collection and external status is ok } else if (!prevStatus.IsEnabled && customer.CollectionStatus.IsEnabled && customer.ExternalCollectionStatus == null) { // Update loan options add remove freeze interest foreach (Loan loan in customer.Loans.Where(l => l.Status != LoanStatus.PaidOff && l.Balance >= CurrentValues.Instance.MinDectForDefault)) { LoanOptions options = this.loanOptionsRepository.GetByLoanId(loan.Id) ?? LoanOptions.GetDefault(loan.Id); options.AutoLateFees = true; options.AutoPayment = true; this.loanOptionsRepository.SaveOrUpdate(options); NL_SaveLoanOptions(customer, options); if (loan.InterestFreeze.Any(f => f.EndDate == null && f.DeactivationDate == null)) { foreach (var interestFreeze in loan.InterestFreeze.Where(f => f.EndDate == null && f.DeactivationDate == null)) { interestFreeze.DeactivationDate = now; DeactivateLoanInterestFreeze(interestFreeze, customerId, loan.Id); } this.loanRepository.SaveOrUpdate(loan); } } } this.session.Flush(); DateTime applyForJudgmentDate; bool hasApplyForJudgmentDate = DateTime.TryParseExact(collectionStatus.ApplyForJudgmentDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out applyForJudgmentDate); var newEntry = new CustomerStatusHistory { Username = User.Identity.Name, Timestamp = DateTime.UtcNow, CustomerId = customerId, PreviousStatus = prevStatus, NewStatus = customer.CollectionStatus, Description = collectionStatus.CollectionDescription, Amount = collectionStatus.Amount, ApplyForJudgmentDate = hasApplyForJudgmentDate ? applyForJudgmentDate : (DateTime?)null, Feedback = collectionStatus.Feedback, Type = collectionStatus.Type }; this.customerStatusHistoryRepository.SaveOrUpdate(newEntry); }).Execute(); log.Debug("AaddFreeseLoans {0}", addFreeseLoans); foreach (int loanID in addFreeseLoans) { var loan = this.loanRepository.Get(loanID); SaveLoanInterestFreeze(loan.InterestFreeze.Last(), customerId, loan.Id); } if (customer.CollectionStatus.Name == "Disabled" && (collectionStatus.Unsubscribe || collectionStatus.ChangeEmail)) { this.serviceClient.Instance.UserDisable(this.context.UserId, customer.Id, customer.Name, collectionStatus.Unsubscribe, collectionStatus.ChangeEmail); } this.serviceClient.Instance.SalesForceAddUpdateLeadAccount(this.context.UserId, customer.Name, customerId, false, false); return(Json(new { })); }