Ejemplo n.º 1
0
        public void check_fees_on_experied_rollover2()
        {
            const int rolloverAmount = 50;

            var calculator = new LoanScheduleCalculator {
                Interest = 0.06M
            };

            calculator.Calculate(1000, _loan, Parse("2012-12-05 00:00:00.000"));

            var rollover = new PaymentRollover
            {
                LoanSchedule = _loan.Schedule[0],
                Created      = Parse("2013-01-08 13:35:59.000"),
                ExpiryDate   = Parse("2013-01-09 00:00:00.000"),
                Payment      = rolloverAmount
            };

            _loan.Schedule[0].Rollovers.Add(rollover);

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, Parse("2013-01-11 10:10:10.000"), 0);             //state for expired rollover
            var state1       = payEarlyCalc.GetState();
            var state        = payEarlyCalc.GetState();

            var model = LoanModel.FromLoan(_loan, payEarlyCalc, payEarlyCalc);

            Assert.That(state.Fees, Is.EqualTo(0));
            Assert.That(state.AmountDue, Is.EqualTo(405.61m));
            Assert.That(state.LateCharges, Is.EqualTo(0));
            Assert.That(state.Interest, Is.EqualTo(405.61m - 334m));

            Assert.That(model.Late, Is.EqualTo(405.61m));
        }
Ejemplo n.º 2
0
        public JsonResult Loan(int id)
        {
            var 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: 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);
            }

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

            RescheduleSetmodel(id, model);

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
        public void check_fees_on_experied_rollover()
        {
            const int rolloverAmount = 50;

            var calculator = new LoanScheduleCalculator {
                Interest = 0.06M
            };

            calculator.Calculate(1000, _loan, Parse("2013-01-15 10:10:10.000"));

            var rollover = new PaymentRollover
            {
                LoanSchedule = _loan.Schedule[1],
                Created      = Parse("2013-01-15 10:10:10.000"),
                ExpiryDate   = Parse("2013-01-25 10:10:10.000"),
                Payment      = rolloverAmount
            };

            _loan.Schedule[1].Rollovers.Add(rollover);

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, Parse("2013-01-26 10:10:10.000"), 0);             //state for expired rollover
            var state        = payEarlyCalc.GetState();

            Assert.That(state.Fees, Is.EqualTo(0));
        }
Ejemplo n.º 4
0
        public void loan_582_Taras()
        {
            var calculator = new LoanScheduleCalculator()
            {
                Interest = 0.06M, Term = 3
            };

            calculator.Calculate(1000, _loan, Parse("2012-10-30 00:00:00.000"));
            _loan.Status = LoanStatus.Live;

            var rollover = new PaymentRollover()
            {
                Created      = Parse("2012-12-28 16:00:31.000"),
                ExpiryDate   = Parse("2012-12-31 00:00:00.000"),
                Status       = RolloverStatus.New,
                LoanSchedule = _loan.Schedule[1],
                Payment      = 50
            };

            _loan.Schedule[1].Rollovers.Add(rollover);

            Console.WriteLine(_loan);

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, Parse("2012-12-28 14:00:53.000"), 0);
            var state        = payEarlyCalc.GetState();

            Assert.That(state.Fees + state.Interest, Is.EqualTo(116m + 50m));
        }
Ejemplo n.º 5
0
        public void loan_517()
        {
            var calculator = new LoanScheduleCalculator()
            {
                Interest = 0.06M, Term = 3
            };

            calculator.Calculate(1000, _loan, Parse("2012-10-26 00:00:00.000"));
            _loan.Status = LoanStatus.Live;

            var rollover = new PaymentRollover()
            {
                Created      = Parse("2012-12-26 18:02:54.000"),
                ExpiryDate   = Parse("2012-12-29 00:00:00.000"),
                Status       = RolloverStatus.New,
                LoanSchedule = _loan.Schedule[0],
                Payment      = 50
            };

            _loan.Schedule[0].Rollovers.Add(rollover);

            Console.WriteLine(_loan);

            MakePayment(170m, Parse("2012-12-26 16:03:42.000"));

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, Parse("2012-12-26 16:03:42.000"), 0);
            var state        = payEarlyCalc.GetState();

            Assert.That(rollover.PaidPaymentAmount, Is.EqualTo(50m));
            Assert.That(_loan.TransactionsWithPaypoint[0].Rollover, Is.EqualTo(50m));
            Assert.That(_loan.TransactionsWithPaypoint[0].Interest, Is.EqualTo(120m));
            Assert.That(_loan.TransactionsWithPaypoint[0].LoanRepayment, Is.EqualTo(0m));
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public JsonResult GetRolloverInfo(int loanId, bool isEdit)
        {
            var loan         = this.loanRepository.Get(loanId);
            var rollover     = this.rolloverRepository.GetByLoanId(loanId).FirstOrDefault(x => x.Status == RolloverStatus.New);
            var payEarlyCalc = new LoanRepaymentScheduleCalculator(loan, DateTime.UtcNow, CurrentValues.Instance.AmountToChargeFrom);
            var state        = payEarlyCalc.GetState();

            var rolloverCharge = CurrentValues.Instance.RolloverCharge;

            var model = new {
                rolloverAmount = state.Fees + state.Interest + (!isEdit ? rolloverCharge : 0),
                interest       = state.Interest,
                lateCharge     = state.Fees - (isEdit && state.Fees != 0 ? rolloverCharge : 0),
                mounthAmount   = rollover != null ? rollover.MounthCount : 1
            };

            try {
                long nlLoanId = this.serviceClient.Instance.GetLoanByOldID(loan.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);
            }

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 8
0
        public void loan_34()
        {
            var calculator = new LoanScheduleCalculator()
            {
                Interest = 0.06M, Term = 3
            };

            calculator.Calculate(400, _loan, Parse("2012-09-12 15:05:27.000"));
            _loan.Status = LoanStatus.Live;

            Console.WriteLine(_loan);

            MakePayment(158.0m, Parse("2012-10-12 10:50:44.000"));
            MakePayment(146.0m, Parse("2012-11-07 12:23:19.000"));
            MakePayment(136.0m, Parse("2012-11-21 16:33:08.000"));
            MakePayment(0.13m, Parse("2013-01-22 20:00:11.000"));

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, Parse("2013-01-23 20:00:11.000"), 0);
            var state        = payEarlyCalc.GetState();

            Assert.That(state.AmountDue, Is.EqualTo(1.08m));

            //Assert.That(state.AmountDue, Is.EqualTo(0.04m));
            //Assert.That(_loan.Status, Is.EqualTo(LoanStatus.PaidOff));
            //Assert.That(_loan.Schedule.All(s => s.Status == LoanScheduleStatus.PaidEarly), Is.True);
        }
Ejemplo n.º 9
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
Ejemplo n.º 10
0
		public void CalculatorState() {
			DateTime calcTime = DateTime.UtcNow;
			const long loanID = 10007;
			const int customerID = 59;
			GetLoanState dbState = new GetLoanState(customerID, loanID, calcTime, 357, false);
			try {
				dbState.Execute();
			} catch (NL_ExceptionInputDataInvalid nlExceptionInputDataInvalid) {
				Console.WriteLine(nlExceptionInputDataInvalid.Message);
				return;
			}
			try {
				ALoanCalculator calc = new LegacyLoanCalculator(dbState.Result, calcTime);
				calc.GetState();
				m_oLog.Debug("----------------------------------{0}", calc.WorkingModel);
			} catch (Exception exception) {
				m_oLog.Error("{0}", exception.Message);
			}

			return;

			// old loan
			LoanRepository loanRep = ObjectFactory.GetInstance<LoanRepository>();
			Loan oldLoan = loanRep.Get(dbState.Result.Loan.OldLoanID);
			// old calc
			LoanRepaymentScheduleCalculator oldCalc = new LoanRepaymentScheduleCalculator(oldLoan, calcTime, 0);
			oldCalc.GetState();

			m_oLog.Debug("++++++++++++++++++++++++++++++old loan: {0}", oldLoan);
			m_oLog.Debug("NextEarlyPayment={0}", oldCalc.NextEarlyPayment());
		}
Ejemplo n.º 11
0
		public void TestLoanInterestRateBetweenDates() {
			LoanRepository loanRep = ObjectFactory.GetInstance<LoanRepository>();
			Loan loan = loanRep.Get(5211);
			DateTime start = new DateTime(2015, 07, 08);
			DateTime end = new DateTime(2015, 10, 21);
			Console.WriteLine(start);
			Console.WriteLine(end);
			var calc = new LoanRepaymentScheduleCalculator(loan, DateTime.UtcNow, CurrentValues.Instance.AmountToChargeFrom);
			calc.GetState();
			//this.m_oLog.Debug("{0}",loan);
			decimal I = 0m;
			decimal P = 57024.55m;
			TimeSpan ts = end.Date.Subtract(start.Date);
			Console.WriteLine(ts);
			int dcounter = 1;
			while (dcounter < ts.Days) {
				DateTime s = start.Date.AddDays(dcounter);
				DateTime e = s.Date.AddDays(1);
				Console.WriteLine("{0}, {1}", s, e);
				decimal r = calc.GetInterestRate(s, e);
				dcounter++;
				Console.WriteLine("{0}, {1}", dcounter, r);
				I += P * r;
			}
			Console.WriteLine(I);
		}
Ejemplo n.º 12
0
        private LoanOffer GetLoanOffer(long id)
        {
            var cr = _cashRequests.Get(id);

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

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

            calc.GetState();

            try {
                ServiceClient service  = new ServiceClient();
                long          nlLoanId = service.Instance.GetLoanByOldID(loan.Id, cr.Customer.Id, 1).Value;
                if (nlLoanId > 0)
                {
                    var nlModel = service.Instance.GetLoanState(loan.Customer.Id, nlLoanId, loan.Date, 1, 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);
            }

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

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

            //TODO calculate offer
            Log.DebugFormat("calculate offer for customer {0}", cr.Customer.Id);

            return(loanOffer);
        }
Ejemplo n.º 13
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));
        }
Ejemplo n.º 14
0
		public void OldCalc() {
			LoanRepository loanRep = ObjectFactory.GetInstance<LoanRepository>();
			Loan loan = loanRep.Get(5);
			var calc = new LoanRepaymentScheduleCalculator(loan, DateTime.UtcNow, CurrentValues.Instance.AmountToChargeFrom);
			calc.GetState();
			Console.WriteLine(loan.ToString());
			Console.WriteLine();
			Console.WriteLine(calc.ToString());
			m_oLog.Debug("---------------------------------------: \n {0}", loan);
		}
Ejemplo n.º 15
0
        public void loan_85()
        {
            var calculator = new LoanScheduleCalculator()
            {
                Interest = 0.05M, Term = 3
            };

            calculator.Calculate(2000, _loan, Parse("2012-10-25 12:56:27.000"));
            _loan.Status = LoanStatus.Live;

            _loan.Charges.Add(new LoanCharge()
            {
                Amount = 20m, Date = Parse("2013-02-01 00:16:32.000")
            });
            _loan.Charges.Add(new LoanCharge()
            {
                Amount = 45m, Date = Parse("2013-02-08 00:16:30.000")
            });

            Console.WriteLine(_loan);

            MakePayment(768.0m, Parse("2012-11-25 09:05:32.000"));
            MakePayment(50.00m, Parse("2013-01-01 12:11:16.000"));
            MakePayment(50.00m, Parse("2013-01-02 13:33:06.000"));
            MakePayment(50.00m, Parse("2013-01-03 14:13:29.000"));
            MakePayment(50.00m, Parse("2013-01-04 11:26:40.000"));
            MakePayment(50.00m, Parse("2013-01-14 09:53:03.000"));
            MakePayment(50.00m, Parse("2013-01-24 16:55:00.000"));
            MakePayment(51.00m, Parse("2013-01-27 11:29:31.000"));
            MakePayment(50.00m, Parse("2013-01-28 09:46:23.000"));
            MakePayment(52.00m, Parse("2013-01-29 09:55:05.000"));
            MakePayment(60.00m, Parse("2013-01-30 09:15:14.000"));
            MakePayment(56.00m, Parse("2013-01-31 09:35:16.000"));
            MakePayment(57.00m, Parse("2013-02-01 08:00:55.000"));
            MakePayment(50.00m, Parse("2013-02-04 08:42:51.000"));
            MakePayment(36.94m, Parse("2013-03-02 00:00:00.000"));
            MakePayment(25.00m, Parse("2013-03-02 00:00:00.000"));
            MakePayment(50.00m, Parse("2013-03-02 00:00:00.000"));
            MakePayment(50.00m, Parse("2013-03-02 00:00:00.000"));
            MakePayment(20.00m, Parse("2013-03-02 00:00:00.000"));
            MakePayment(100.00m, Parse("2013-03-04 00:00:00.000"));
            MakePayment(100.00m, Parse("2013-03-06 00:00:00.000"));
            MakePayment(192.05m, Parse("2013-03-17 00:00:00.000"));

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, Parse("2013-03-19 20:00:11.000"), 0);
            var state        = payEarlyCalc.GetState();

            //Assert.That(state.AmountDue, Is.EqualTo(0m));

            //Assert.That(_loan.Balance, Is.EqualTo(0));
            //Assert.That(_loan.Principal, Is.EqualTo(0));
        }
Ejemplo n.º 16
0
        public void all_loan_late()
        {
            var date  = new DateTime(2012, 9, 25);
            var loan1 = new Loan();

            _calculator.Calculate(1000, loan1, date);
            _customer.Loans.Add(loan1);

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(loan1, new DateTime(2012, 12, 26), 0);
            var state        = payEarlyCalc.GetState();

            Console.Write(state.AmountDue);
        }
Ejemplo n.º 17
0
        public void check_fees_on_delete_rollover()
        {
            var loanDate           = Parse("2013-01-15 10:10:10.000");
            var rolloverCreateDate = Parse("2013-01-15 10:10:10.000");
            var rolloverExpiryDate = Parse("2013-01-25 10:10:10.000");
            var stateDate          = Parse("2013-01-20 10:10:10.000");

            const int rolloverAmount = 50;

            var calculator = new LoanScheduleCalculator {
                Interest = 0.06M
            };

            calculator.Calculate(1000, _loan, loanDate);

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, stateDate, 0);

            var rollover = new PaymentRollover
            {
                LoanSchedule = _loan.Schedule[1],
                Created      = rolloverCreateDate,
                ExpiryDate   = rolloverExpiryDate,
                Payment      = rolloverAmount
            };

            _loan.Schedule[1].Rollovers.Add(rollover);

            var state = payEarlyCalc.GetState();
            var fees  = state.Fees;

            foreach (var r in _loan.Schedule[1].Rollovers)
            {
                r.Status = RolloverStatus.Removed;
            }

            state = payEarlyCalc.GetState();
            Assert.That(state.Fees, Is.EqualTo(fees - rolloverAmount));
        }
Ejemplo n.º 18
0
        public void pay_after_remove_rollover()
        {
            var loanDate           = Parse("2013-01-15 10:10:10.000");
            var rolloverCreateDate = Parse("2013-01-15 10:10:10.000");
            var rolloverExpiryDate = Parse("2013-01-25 10:10:10.000");

            const int rolloverAmount = 50;

            var calculator = new LoanScheduleCalculator {
                Interest = 0.06M
            };

            calculator.Calculate(1000, _loan, loanDate);

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, rolloverCreateDate, 0);
            var state        = payEarlyCalc.GetState();

            var rolloverRemoved = new PaymentRollover
            {
                LoanSchedule = _loan.Schedule[0],
                Created      = rolloverCreateDate,
                ExpiryDate   = rolloverExpiryDate,
                Payment      = rolloverAmount,
                Status       = RolloverStatus.Removed
            };
            var rolloverActive = new PaymentRollover
            {
                LoanSchedule = _loan.Schedule[0],
                Created      = rolloverCreateDate,
                ExpiryDate   = rolloverExpiryDate,
                Payment      = rolloverAmount,
                Status       = RolloverStatus.New
            };

            _loan.Schedule[0].Rollovers.Add(rolloverRemoved);
            _loan.Schedule[0].Rollovers.Add(rolloverActive);

            MakePayment(394 + rolloverAmount, rolloverCreateDate);

            payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, rolloverCreateDate, 0);

            Console.WriteLine(_loan.ToString());

            state = payEarlyCalc.GetState();
            Assert.That(state.Fees, Is.EqualTo(0));
        }
Ejemplo n.º 19
0
		public void TestLoanOldCalculator() {
			int	loanID = 5211;
			LoanRepository loanRep = ObjectFactory.GetInstance<LoanRepository>();
			Loan loan = loanRep.Get(2);
			/*ChangeLoanDetailsModelBuilder loanModelBuilder = new ChangeLoanDetailsModelBuilder();
			EditLoanDetailsModel model = new EditLoanDetailsModel();
			var loaan =  ObjectFactory.GetInstance<LoanRepository>().Get(loanID);
			// 1. build model from DB loan
			model = loanModelBuilder.BuildModel(loaan);
			//m_oLog.Debug("===========================" + model.InterestFreeze.Count);
			// 2. create DB loan from the model
			Loan loan1 = loanModelBuilder.CreateLoan(model);
			//m_oLog.Debug("----------------------" + loan1.InterestFreeze.Count);*/
			var calc = new LoanRepaymentScheduleCalculator(loan, DateTime.UtcNow, CurrentValues.Instance.AmountToChargeFrom);
			calc.GetState();
			m_oLog.Debug("---------------------------------------Loan recalculated: \n {0}", loan);
		}
Ejemplo n.º 20
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
Ejemplo n.º 21
0
        public void loan_533_Taras()
        {
            var calculator = new LoanScheduleCalculator()
            {
                Interest = 0.06M, Term = 3
            };

            calculator.Calculate(1000, _loan, Parse("2012-10-12 00:00:00.000"));
            _loan.Status = LoanStatus.Live;

            var rollover = new PaymentRollover()
            {
                Created      = Parse("2012-12-27 15:18:30.000"),
                ExpiryDate   = Parse("2012-12-30 00:00:00.000"),
                Status       = RolloverStatus.New,
                LoanSchedule = _loan.Schedule[0],
                Payment      = 50
            };

            _loan.Schedule[0].Rollovers.Add(rollover);

            var charge = new LoanCharge()
            {
                Amount = 75, ChargesType = null, Date = Parse("2012-12-27 13:15:29.000"), Loan = _loan
            };

            _loan.Charges.Add(charge);

            Console.WriteLine(_loan);

            var now = Parse("2012-12-27 13:19:00.000");

            MakePayment(274.03m, now);

            //var model = LoanModel.FromLoan(_loan, new LoanRepaymentScheduleCalculator(_loan, now), new LoanRepaymentScheduleCalculator(_loan, now));

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, now, 0);
            var state        = payEarlyCalc.GetState();

            Console.WriteLine(_loan);

            Assert.That(_loan.Schedule[0].Interest, Is.EqualTo(0));
        }
Ejemplo n.º 22
0
        public JsonResult GetPaymentInfo(string date, decimal money, int loanId)
        {
            DateTime paymentDate = FormattingUtils.ParseDateWithoutTime(date);
            Loan     loan        = this.loanRepository.Get(loanId);

            var hasRollover = this.rolloverRepository.GetByLoanId(loanId).Any(x => x.Status == RolloverStatus.New);

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(loan, paymentDate, CurrentValues.Instance.AmountToChargeFrom);
            var state        = payEarlyCalc.GetState();

            try {
                long nlLoanId = this.serviceClient.Instance.GetLoanByOldID(loan.Id, loan.Customer.Id, this.context.UserId).Value;
                if (nlLoanId > 0)
                {
                    var nlModel = this.serviceClient.Instance.GetLoanState(loan.Customer.Id, nlLoanId, paymentDate, 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);
            }

            var model = new LoanPaymentDetails {
                Balance  = payEarlyCalc.TotalEarlyPayment(),
                MinValue = !hasRollover ? 0.01m : state.Fees + state.Interest
            };

            model.Amount = money;

            decimal amount = Math.Min(money, state.Fees);

            model.Fee = amount;
            money     = money - amount;

            amount         = Math.Min(money, state.Interest);
            model.Interest = amount;
            money          = money - amount;

            model.Principal = money;

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 23
0
        public void loan_512()
        {
            var calculator = new LoanScheduleCalculator()
            {
                Interest = 0.06M, Term = 3
            };

            var now = Parse("2012-12-26 15:22:45.000");

            calculator.Calculate(1000, _loan, Parse("2012-10-26 00:00:00.000"));
            _loan.Status = LoanStatus.Live;

            Console.WriteLine(_loan);

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, now, 0);
            var state        = payEarlyCalc.GetState();

            Assert.That(_loan.Schedule[0].Status, Is.EqualTo(LoanScheduleStatus.Late));
            Assert.That(_loan.Schedule[1].Status, Is.EqualTo(LoanScheduleStatus.StillToPay));
            Assert.That(_loan.Schedule[2].Status, Is.EqualTo(LoanScheduleStatus.StillToPay));
        }
Ejemplo n.º 24
0
        public void loan_196()
        {
            var calculator = new LoanScheduleCalculator()
            {
                Interest = 0.06M, Term = 6
            };

            calculator.Calculate(12200, _loan, Parse("2012-12-16 07:47:33.000"));
            _loan.Status = LoanStatus.Live;

            Console.WriteLine(_loan);

            MakePayment(12625.0m, Parse("2013-01-03 09:13:21.000"));

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, Parse("2013-01-23 20:00:04.000"), 0);
            var state        = payEarlyCalc.GetState();

            //Assert.That(state.AmountDue, Is.EqualTo(0.04m));

            //Assert.That(_loan.Status, Is.EqualTo(LoanStatus.PaidOff));
            //Assert.That(_loan.Schedule.All(s => s.Status == LoanScheduleStatus.PaidEarly), Is.True);
        }
Ejemplo n.º 25
0
        }         // GetApr

        private Loan CreateLoan(decimal interestRate, decimal setupFee)
        {
            var loan = new Loan {
                LoanAmount  = Model.LoanAmount,
                Date        = DateTime.UtcNow,
                LoanType    = new StandardLoanType(),
                CashRequest = null,
                SetupFee    = setupFee,
                LoanLegalId = 1
            };

            new LoanScheduleCalculator {
                Interest = interestRate,
                Term     = (int)Model.TenureMonths,
            }.Calculate(Model.LoanAmount, loan, loan.Date, Model.InterestOnlyPeriod);

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

            calc.GetState();

            return(loan);
        }         // CreateLoan
Ejemplo n.º 26
0
        public void loan_187()
        {
            var calculator = new LoanScheduleCalculator()
            {
                Interest = 0.06M, Term = 6
            };

            var now = Parse("2012-12-12 10:23:04.000");

            calculator.Calculate(400, _loan, Parse("2012-12-12 10:23:04.000"));
            _loan.Status = LoanStatus.Live;

            Console.WriteLine(_loan);

            MakePayment(94.0m, Parse("2013-01-14 20:00:04.000"));

            Console.WriteLine(_loan);

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, Parse("2013-01-20 20:00:04.000"), 0);
            var state        = payEarlyCalc.GetState();

            Console.WriteLine(_loan);
        }
Ejemplo n.º 27
0
        public void loan_late_payment_amount()
        {
            var calculator = new LoanScheduleCalculator()
            {
                Interest = 0.06M, Term = 3
            };

            var now = Parse("2012-12-26 15:22:45.000");

            calculator.Calculate(1000, _loan, Parse("2012-10-26 00:00:00.000"));
            _loan.Status = LoanStatus.Live;

            Console.WriteLine(_loan);

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, now, 0);
            var state        = payEarlyCalc.GetState();

            Assert.That(state.Interest, Is.EqualTo(120m));

            MakePayment(120, now);

            Assert.That(_loan.TransactionsWithPaypoint[0].Interest, Is.EqualTo(120));
        }
Ejemplo n.º 28
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));
        }
Ejemplo n.º 29
0
        //https://trello.com/c/x2e8DXJ8
        public void trello_card_244()
        {
            var calculator = new LoanScheduleCalculator()
            {
                Interest = 0.06M, Term = 3
            };

            calculator.Calculate(1000, _loan, Parse("2012-11-08 00:00:00.000"));
            _loan.Status = LoanStatus.Live;

            Console.WriteLine(_loan);

            var payEarlyCalc = new LoanRepaymentScheduleCalculator(_loan, Parse("2013-01-08 16:03:42.000"), 0);
            var state        = payEarlyCalc.GetState();

            var earlyPayment = payEarlyCalc.TotalEarlyPayment();

            var model = LoanModel.FromLoan(_loan, payEarlyCalc, payEarlyCalc);

            Assert.That(state.AmountDue, Is.EqualTo(787));
            Assert.That(earlyPayment, Is.EqualTo(1120m));

            Assert.That(model.Late, Is.EqualTo(454));
        }
Ejemplo n.º 30
0
        }         // BuildQuickOfferModel

        private decimal GetRolloverPayValue(Loan loan)
        {
            var payEarlyCalc = new LoanRepaymentScheduleCalculator(
                loan,
                DateTime.UtcNow,
                CurrentValues.Instance.AmountToChargeFrom
                );
            var state = payEarlyCalc.GetState();

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

            return(state.Fees + state.Interest);
        }         // GetRolloverPayValue