Exemplo n.º 1
0
		} // BuildLoan

		/// <summary>
		/// Looks like this method is not used any more (after removing edit loan button from underwriter's
		/// approval dialogue. The button was located in _ProfileTemplateMain.cshtml.
		/// </summary>
		/// <param name="cr"></param>
		/// <param name="amount"></param>
		/// <param name="now"></param>
		/// <returns></returns>
		private Loan CreateLoanFromTemplate(CashRequest cr, decimal amount, DateTime now) {
			var model = EditLoanDetailsModel.Parse(cr.LoanTemplate);
			var loan = _builder.CreateLoan(model);
			loan.LoanType = cr.LoanType;
			loan.CashRequest = cr;

			AdjustDates(now, loan);
			AdjustBalances(amount, loan);

			var c = new LoanRepaymentScheduleCalculator(loan, now, CurrentValues.Instance.AmountToChargeFrom);
			c.GetState();

			if (loan.Id > 0) {
				try {
					ServiceClient serviceClient = new ServiceClient();
					long nlLoanId = serviceClient.Instance.GetLoanByOldID(loan.Id, cr.Customer.Id, 1)
						.Value;
					if (nlLoanId > 0) {
						var nlModel = serviceClient.Instance.GetLoanState(loan.Customer.Id, nlLoanId, DateTime.UtcNow, 1, true).Value;
						log.Msg("<<< NL_Compare: {0}\n===============loan: {1}  >>>", nlModel, loan);
					}
					// ReSharper disable once CatchAllClause
				} catch (Exception ex) {
					log.Msg("<<< NL_Compare fail at: {0}, err: {1}", Environment.StackTrace, ex.Message);
				} // try
			} // if

			loan.LoanSource = cr.LoanSource;
			return loan;
		} // CreateLoanFromTemplate
Exemplo n.º 2
0
        public JsonResult Loan(EditLoanDetailsModel model)
        {
            var loan = this._loans.Get(model.Id);

            var historyItem = new LoanChangesHistory {
                Data = this._loanModelBuilder.BuildModel(loan).ToJSON(),
                Date = DateTime.UtcNow,
                Loan = loan,
                User = this._context.User
            };

            this._history.Save(historyItem);

            //  remove/add fees/installment/pp transaction

            // model - from UI (modified), loan - from DB
            this._loanModelBuilder.UpdateLoan(model, loan);

            Log.DebugFormat("model {0} =================== loan {1} ", model, loan);

            //TODO update loan (apply all modifications)
            Log.DebugFormat("apply loan modifications for customer {0}", loan.Customer.Id);

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

            calc.GetState();

            // NL cancel payment
            try {
                long nlLoanId = this.serviceClient.Instance.GetLoanByOldID(model.Id, loan.Customer.Id, this._context.UserId).Value;
                if (nlLoanId > 0)
                {
                    NL_Model nlModel = this.serviceClient.Instance.GetLoanState(loan.Customer.Id, nlLoanId, DateTime.UtcNow, this._context.UserId, false).Value;
                    Log.InfoFormat("nlModel : {0} loan: {1}  >>>", nlModel, loan);
                    foreach (PaypointTransaction t in loan.TransactionsWithPaypointSuccesefull.Where(t => t.Cancelled))
                    {
                        foreach (NL_Payments zz in nlModel.Loan.Payments)
                        {
                            if (zz.Amount == t.CancelledAmount && zz.PaymentTime.Date.Equals(t.PostDate.Date))                              //&& (zz.PaypointTransactions.FirstOrDefault(x => x.PaypointUniqueID == t.PaypointId && x.IP == t.IP) != null))
                            {
                                zz.DeletedByUserID = this._context.UserId;
                                zz.DeletionTime    = DateTime.UtcNow;
                                zz.Notes           = t.Description;
                                zz.PaymentStatusID = (int)NLPaymentStatuses.WrongPayment;
                                Log.InfoFormat("cancelling NL payment {0}", zz);
                                this.serviceClient.Instance.CancelPayment(this._context.UserId, zz, loan.Customer.Id);
                            }
                        }
                    }
                }

                // ReSharper disable once CatchAllClause
            } catch (Exception fex) {
                Log.InfoFormat("Fail to cancel NL payment(s). {0}, err: {1}", Environment.StackTrace, fex.Message);
            }

            RescheduleSetmodel(loan.Id, model);

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        private bool CheckValidateLoanState(LoanRepaymentScheduleCalculator calc)
        {
            try {
                calc.GetState();
                // ReSharper disable once CatchAllClause
            } catch (Exception e) {
                this.Result.Error = e.Message;
                Log.Alert("LoanRepaymentScheduleCalculator STATE EXCEPTION: {0}", e);
                return(false);
            }

            // additional validating - via "edit loan" GUI model
            ChangeLoanDetailsModelBuilder changeLoanModelBuilder = new ChangeLoanDetailsModelBuilder();
            EditLoanDetailsModel          model = changeLoanModelBuilder.BuildModel(this.tLoan);

            model.Validate();
            if (model.HasErrors)
            {
                this.Result.Error = string.Join("<br/>", model.Errors.ToArray());
                Log.Alert(this.Result.Error);
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        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
Exemplo n.º 5
0
        public JsonResult LoanCR(EditLoanDetailsModel model)
        {
            var cr = this._cashRequests.Get(model.CashRequestId);

            model = RecalculateModel(model, cr, model.Date);

            cr.LoanTemplate = model.ToJSON();

            RescheduleSetmodel(model.Id, model);

            return(Json(model));
        }
Exemplo n.º 6
0
        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
Exemplo n.º 7
0
        public JsonResult SaveFreezeInterval(int id)
        {
            DateTime?freezeStartDate = Convert.ToDateTime(HttpContext.Request.QueryString["startdate"]);

            string   freezeEndDateStr = HttpContext.Request.QueryString["enddate"];
            DateTime?freezeEndDate    = string.IsNullOrEmpty(freezeEndDateStr) ? NoLimitDate : Convert.ToDateTime(freezeEndDateStr);

            EditLoanDetailsModel model = this._loanModelBuilder.BuildModel(this._loans.Get(id));

            if (freezeStartDate > freezeEndDate)
            {
                model.Errors.Add("Until date must be greater then From date");
                RescheduleSetmodel(id, model);
                return(Json(model));
            }

            Loan loan  = this._loans.Get(id);
            var  loan1 = loan;

            new Transactional(() => {
                loan1.InterestFreeze.Add(new LoanInterestFreeze {
                    Loan             = loan1,
                    StartDate        = freezeStartDate,
                    EndDate          = freezeEndDate,
                    InterestRate     = 0,
                    ActivationDate   = DateTime.UtcNow,
                    DeactivationDate = null
                });

                this._loans.SaveOrUpdate(loan1);
            }).Execute();

            SaveLoanInterestFreeze(loan.InterestFreeze.Last(), id);

            loan          = this._loans.Get(id);
            model         = this._loanModelBuilder.BuildModel(loan);
            model.Options = this.loanOptionsRepository.GetByLoanId(id);

            RescheduleSetmodel(loan.Id, model);

            return(Json(model));
        }         //SaveFreezeInterval
Exemplo n.º 8
0
        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
Exemplo n.º 9
0
        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
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 11
0
        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
Exemplo n.º 12
0
        private EditLoanDetailsModel RecalculateModel(EditLoanDetailsModel model, CashRequest cr, DateTime now)
        {
            model.Validate();

            if (model.HasErrors)
            {
                return(model);
            }

            var loan = this._loanModelBuilder.CreateLoan(model);

            loan.LoanType    = cr.LoanType;
            loan.CashRequest = cr;

            RescheduleSetmodel(model.Id, model);

            try {
                var calc = new LoanRepaymentScheduleCalculator(loan, now, CurrentValues.Instance.AmountToChargeFrom);
                calc.GetState();

                //try {
                //	long nlLoanId = this.serviceClient.Instance.GetLoanByOldID(loan.Id, cr.Customer.Id, this._context.UserId).Value;
                //	if (nlLoanId > 0) {
                //		var nlModel = this.serviceClient.Instance.GetLoanState(loan.Customer.Id, nlLoanId, now, this._context.UserId, true).Value;
                //		Log.InfoFormat("<<< NL_Compare: nlModel : {0} loan: {1}  >>>", nlModel, loan);
                //	}
                //	// ReSharper disable once CatchAllClause
                //} catch (Exception ex) {
                //	Log.InfoFormat("<<< NL_Compare Fail at: {0}, err: {1}", Environment.StackTrace, ex.Message);
                //}
            } catch (Exception e) {
                model.Errors.Add(e.Message);
                return(model);
            }

            return(this._loanModelBuilder.BuildModel(loan));
        }
Exemplo n.º 13
0
        public JsonResult RecalculateCR(EditLoanDetailsModel model)
        {
            var cr = this._cashRequests.Get(model.CashRequestId);

            return(Json(RecalculateModel(model, cr, model.Date)));
        }
Exemplo n.º 14
0
        public JsonResult Recalculate(int id, EditLoanDetailsModel model)
        {
            var cr = this._loans.Get(id).CashRequest;

            return(Json(RecalculateModel(model, cr, DateTime.UtcNow)));
        }