Example #1
0
 internal SaveLoanStateToDB(NL_Model nlmodel, bool loanClose = false, bool loanStatusChange = false)
 {
     model             = nlmodel;
     runClose          = loanClose;
     runStatusChenge   = loanStatusChange;
     this.strategyArgs = new object[] { model };
 }         // ctor
Example #2
0
        public void TestCreateScheduleSetupFeeBrokerSetupFee()
        {
            var nlModel = new NL_Model(1);

            DecorateNL_LoanNL_LoanHistory(nlModel);
            DecorateNL_Offers(nlModel, NLFeeTypes.ServicingFee, true);

            var legacyLoanCalculator = new LegacyLoanCalculator(nlModel, DateTime.UtcNow);

            legacyLoanCalculator.CreateSchedule();

            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(nlModel.Loan.LastHistory().Schedule.Count == 3);

            var nlLoanSchedule = nlModel.Loan.LastHistory().Schedule.FirstOrDefault(x => x.Position == 1);

            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(nlLoanSchedule != null &&
                                                                       nlLoanSchedule.Principal == 333 &&
                                                                       nlLoanSchedule.Balance == 999 &&
                                                                       nlLoanSchedule.InterestRate == 2 &&
                                                                       nlLoanSchedule.PlannedDate == new DateTime(2015, 2, 15));

            nlLoanSchedule = nlModel.Loan.LastHistory().Schedule.FirstOrDefault(x => x.Position == 2);
            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(nlLoanSchedule != null &&
                                                                       nlLoanSchedule.Principal == 333 &&
                                                                       nlLoanSchedule.Balance == 666 &&
                                                                       nlLoanSchedule.InterestRate == 2 &&
                                                                       nlLoanSchedule.PlannedDate == new DateTime(2015, 3, 15));

            nlLoanSchedule = nlModel.Loan.LastHistory().Schedule.FirstOrDefault(x => x.Position == 3);
            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(nlLoanSchedule != null &&
                                                                       nlLoanSchedule.Principal == 333 &&
                                                                       nlLoanSchedule.Balance == 333 &&
                                                                       nlLoanSchedule.InterestRate == 2 &&
                                                                       nlLoanSchedule.PlannedDate == new DateTime(2015, 4, 15));
        }
Example #3
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));
        }
Example #4
0
        //[Transactional]
        public void NL_SyncFees(int id)
        {
            Log.DebugFormat("sync NL fees for old loan {0}", id);

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

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

                    // new/edit fee
                    foreach (LoanCharge ch in loan.Charges.OrderBy(ff => ff.Date))
                    {
                        NL_LoanFees f = nlModel.Loan.Fees.FirstOrDefault(ff => ff.OldFeeID == ch.Id);
                        if (f == null)
                        {
                            f = new NL_LoanFees()
                            {
                                AssignedByUserID = this._context.UserId,
                                LoanFeeTypeID    = (int)NL_Model.ConfVarToNLFeeType(ch.ChargesType),
                                LoanID           = nlLoanId,
                                OldFeeID         = ch.Id,                         // update in strategy after this [Transactional]
                                Amount           = ch.Amount,
                                AssignTime       = ch.Date.Date,
                                Notes            = !string.IsNullOrEmpty(ch.Description) ? ch.Description : "add fee from edit loan"
                            };
                            this.serviceClient.Instance.SaveFee(this._context.UserId, loan.Customer.Id, f);

                            // fee type is editable + modified (amount/assign date/notes)
                        }
                        else if (Array.Exists <NLFeeTypes>(NL_Model.NLFeeTypesEditable, element => element == (NLFeeTypes)f.LoanFeeTypeID) && (f.Amount != ch.Amount || f.AssignTime.Date != ch.Date.Date || f.Notes != ch.Description))
                        {
                            f.UpdatedByUserID = this._context.UserId;
                            f.Amount          = ch.Amount;
                            f.AssignTime      = ch.Date.Date;
                            f.Notes           = !string.IsNullOrEmpty(ch.Description) ? ch.Description : "add fee from edit loan";
                            this.serviceClient.Instance.SaveFee(this._context.UserId, loan.Customer.Id, f);
                        }
                    }

                    //	removed fee
                    foreach (NL_LoanFees f in nlModel.Loan.Fees.OrderBy(ff => ff.AssignTime))
                    {
                        var charge = loan.Charges.FirstOrDefault(c => c.Id == f.LoanFeeID);
                        if (charge == null)
                        {
                            f.DeletedByUserID = this._context.UserId;
                            this.serviceClient.Instance.CancelFee(this._context.UserId, loan.Customer.Id, f);
                        }
                    }
                }
                // ReSharper disable once CatchAllClause
            } catch (Exception ex) {
                Log.InfoFormat("Fail to sync NL loan fees. {0}, err: {1}", Environment.StackTrace, ex.Message);
            }
        }
Example #5
0
        public void GetStateHistoriesEvents()
        {
            var nlModel = new NL_Model(1);

            DecorateNL_LoanNL_LoanHistory(nlModel);
            DecorateHistory(nlModel);

            var legacyLoanCalculator = new LegacyLoanCalculator(nlModel, DateTime.UtcNow);

            legacyLoanCalculator.GetState();
        }
Example #6
0
        public void GetStateAcceptedRolloverEvents()
        {
            var nlModel = new NL_Model(1);

            DecorateNL_LoanNL_LoanHistory(nlModel);
            DecorateNL_Offers(nlModel, NLFeeTypes.ServicingFee);
            DecoratePayment(nlModel);

            var legacyLoanCalculator = new LegacyLoanCalculator(nlModel, DateTime.UtcNow);
            //legacyLoanCalculator.
            //legacyLoanCalculator.GetState();
        }
Example #7
0
        public ExcelCalculator(NL_Model nlModel)
        {
            NL_Model = nlModel;


            using (ExcelPackage = new ExcelPackage(new FileInfo("D:\\Excel\\Calculator.xlsx"))) {
                Worksheet = ExcelPackage.Workbook.Worksheets[1];

                //Loan Amount:
                Worksheet.Cells["D5"].Value = nlModel.Loan.FirstHistory()
                                              .Amount.ToString(CultureInfo.InvariantCulture);

                //Annual Interest Rate:
                Worksheet.Cells["D6"].Value = nlModel.Loan.LastHistory()
                                              .InterestRate.ToString(CultureInfo.InvariantCulture);

                //Loan Length in Years
                Worksheet.Cells["D7"].Value = 1;

                //Number of Payments per Year:
                Worksheet.Cells["D8"].Value = 12;

                //Start Date of Loan:
                Worksheet.Cells["D9"].Value = "01-02-2016";

                //Optional Extra Per Month Payment:
                Worksheet.Cells["D10"].Value = "10";

                //var calcOptions = new ExcelCalculationOption() {
                //    AllowCirculareReferences = true
                //};

                //Worksheet.Calculate(calcOptions);


                var calcOptions = new ExcelCalculationOption()
                {
                    AllowCirculareReferences = true
                };

                Worksheet.Cells[5, 9].Formula = "=IF(IF(D5*D6*D7*D9>0,1,0),-PMT(D6/D8,D7*D8,D5),\"\")";

                Worksheet.Cells[5, 9].Calculate();

                ExcelPackage.Save();
            }

            ExcelPackage.Dispose();
            Worksheet.Dispose();

            ExcelPackage = new ExcelPackage(new FileInfo("D:\\Excel\\Calculator.xlsx"));
            Worksheet    = ExcelPackage.Workbook.Worksheets[1];
        }
Example #8
0
 private void DecorateHistory(NL_Model nlModel)
 {
     nlModel.Loan.Histories.Add(new NL_LoanHistory()
     {
         LoanID         = 1,
         LoanHistoryID  = 2,
         EventTime      = new DateTime(2015, 2, 15),
         InterestRate   = 3,
         Amount         = 400,
         RepaymentCount = 4
     });
 }
Example #9
0
        public void AddFeeNotes(NL_Model model)
        {
            if (model == null)
            {
                return;
            }

            foreach (NL_LoanFees fee in model.Loan.Fees)
            {
                AddNote(fee.AssignTime, "Fee assigned: " + fee.Amount.ToString("C2", Library.Instance.Culture));
            }
        }
Example #10
0
        private void DecoratePayment(NL_Model nlModel)
        {
            NL_Payments nlPayments = new NL_Payments()
            {
                LoanID       = 1,
                Amount       = 333,
                CreationTime = new DateTime(2015, 2, 15),
                PaymentTime  = new DateTime(2015, 2, 15),
                PaymentID    = 1
            };

            nlModel.Loan.Payments.Add(nlPayments);
        }
Example #11
0
        public JsonResult Now(int cardId, decimal amount)
        {
            var      cus  = this.context.Customer;
            var      card = cus.PayPointCards.First(c => c.Id == cardId);
            DateTime now  = DateTime.UtcNow;

            NL_Model nlModel = new NL_Model(cus.Id);
            var      loan    = this.loanCreator.CreateLoan(cus, amount, card, now, nlModel);

            var url = Url.Action("Index", "PacnetStatus", new { Area = "Customer" }, "https");

            return(Json(new { url = url }));
        }
Example #12
0
		public void DiscountPlan() {
			var discounts = this.m_oDB.Fill<NL_DiscountPlanEntries>(
						"NL_DiscountPlanEntriesGet",
						CommandSpecies.StoredProcedure,
						new QueryParameter("@DiscountPlanID", 2)
						);
			if (discounts != null) {
				discounts.ForEach(d => m_oLog.Debug(d));
				NL_Model model = new NL_Model(374);
				foreach (NL_DiscountPlanEntries dpe in discounts) {
					model.Offer.DiscountPlan.Add(Decimal.Parse(dpe.InterestDiscount.ToString(CultureInfo.InvariantCulture)));
				}
				model.Offer.DiscountPlan.ForEach(d => Console.WriteLine(d));
			}
		}
Example #13
0
        public void AddPaymentNotes(NL_Model model)
        {
            if (model == null)
            {
                return;
            }

            //for(int i = 0; i < workingModel.Repayments.Count; i++) {
            //	var rp = workingModel.Repayments[i];

            //	AddNote(
            //		rp.Date,
            //		"Repaid: " + rp.Amount.ToString("C2", Library.Instance.Culture)
            //	);
            //} // for each
        }
Example #14
0
        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);
            }
        }
Example #15
0
 private void DecorateNL_LoanNL_LoanHistory(NL_Model nlModel)
 {
     nlModel.Loan = new NL_Loans()
     {
         LoanID    = 1,
         Histories = new List <NL_LoanHistory>()
     };
     nlModel.Loan.Histories.Add(new NL_LoanHistory()
     {
         LoanID         = 1,
         LoanHistoryID  = 1,
         EventTime      = new DateTime(2015, 1, 15),
         InterestRate   = 2,
         Amount         = 999,
         RepaymentCount = 3
     });
 }
Example #16
0
		public GetLoanState(int customerID, long loanID, DateTime? stateDate, int? userID = null, bool getCalculatorState = true) {

			//this.strategyArgs = new object[] { customerID, loanID, stateDate, userID, getCalculatorState };

			this.StateDate = stateDate ?? DateTime.UtcNow;

			Result = new NL_Model(customerID);

			Result.Loan = new NL_Loans() { LoanID = loanID };
			Result.UserID = userID;
			GetCalculatorState = getCalculatorState;

			LoanDAL = new LoanDAL();

			this.strategyArgs = new object[] { Result.CustomerID, Result.Loan.LoanID, this.StateDate, Result.UserID, GetCalculatorState };

		} // constructor
Example #17
0
        /// <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 void RenderAgreements(Loan loan, bool isRebuld, NL_Model nlModel = null)
        {
            var model = !isRebuld
                                ? this._builder.Build(loan.Customer, loan.LoanAmount, loan)
                                : this._builder.ReBuild(loan.Customer, loan);

            // NL - AgreementModel in json
            if (nlModel != null)
            {
                nlModel.Loan.LastHistory().AgreementModel = JsonConvert.SerializeObject(this._builder.NL_BuildAgreementModel(loan.Customer, nlModel));
            }

            var productSubTypeID = loan.CashRequest.ProductSubTypeID;
            var isRegulated      = loan.Customer.PersonalInfo.TypeOfBusiness.IsRegulated();
            var originId         = loan.Customer.CustomerOrigin.CustomerOriginID;

            LoanAgreementTemplate[] loanAgreementTemplates = this.serviceClient.Instance.GetLegalDocs(loan.Customer.Id, 1, originId, isRegulated, productSubTypeID ?? 0).LoanAgreementTemplates;
            foreach (var loanAgreementTemplate in loanAgreementTemplates)
            {
                var agreement = new LoanAgreement(loanAgreementTemplate.Name, loan, loanAgreementTemplate.Id);
                loan.Agreements.Add(agreement);
                string        path1         = Path.Combine(CurrentValues.Instance.AgreementPdfLoanPath1, agreement.FilePath);
                string        path2         = Path.Combine(CurrentValues.Instance.AgreementPdfLoanPath2, agreement.FilePath);
                TemplateModel templateModel = new TemplateModel {
                    Template = loanAgreementTemplate.Template
                };
                this.serviceClient.Instance.SaveAgreement(loan.Customer.Id, model, loan.RefNumber, Enum.GetName(typeof(LegalDocsEnums.LoanAgreementTemplateType), agreement.Id), templateModel, path1, path2);

                string nlpath1 = Path.Combine(CurrentValues.Instance.NL_AgreementPdfLoanPath1, agreement.FilePath);
                string nlpath2 = Path.Combine(CurrentValues.Instance.NL_AgreementPdfLoanPath2, agreement.FilePath);
                this.serviceClient.Instance.SaveAgreement(loan.Customer.Id, model, loan.RefNumber, Enum.GetName(typeof(LegalDocsEnums.LoanAgreementTemplateType), agreement.Id), templateModel, nlpath1, nlpath2);


                if (nlModel != null)
                {
                    nlModel.Loan.LastHistory()
                    .Agreements.Add(new NL_LoanAgreements()
                    {
                        LoanAgreementTemplateID = agreement.TemplateID,
                        FilePath = agreement.FilePath
                    });
                }
            }
            loan.AgreementModel = JsonConvert.SerializeObject(model);
        }
Example #18
0
        }         // RescheduleLoan

        public NLModelActionResult BuildLoanFromOffer(int?userID, int?customerID, NL_Model model)
        {
            ActionMetaData     amd      = null;
            BuildLoanFromOffer strategy = new BuildLoanFromOffer(model);

            try {
                amd = ExecuteSync(out strategy, customerID, userID, model);
                // ReSharper disable once CatchAllClause
            } catch (Exception e) {
                Log.Alert("BuildLoanFromOffer failed: {0}", e);
                strategy.Result.Error = "InternalServerError";
            }
            return(new NLModelActionResult()
            {
                MetaData = amd,
                Value = strategy.Result
            });
        }
Example #19
0
 public void DecorateNL_Offers(NL_Model nlModel, NLFeeTypes feeType, bool isBrokerSetUpFee = false)
 {
     nlModel.Offer = new NL_Offers()
     {
         OfferFees = new List <NL_OfferFees>()
         {
             new NL_OfferFees()
             {
                 Percent       = (decimal?)0.02,
                 LoanFeeTypeID = (int)feeType
             }
         }
     };
     if (isBrokerSetUpFee)
     {
         nlModel.Offer.BrokerSetupFeePercent = (decimal?)0.5;
     }
 }
Example #20
0
        public void AddScheduleNotes(NL_Model model)
        {
            if (model == null)
            {
                return;
            }

            List <NL_LoanSchedules> activeSchedule = new List <NL_LoanSchedules>();

            model.Loan.Histories.ForEach(h => activeSchedule.AddRange(h.ActiveSchedule()));
            int activeScheduleCount = activeSchedule.Count;
            int i = 0;

            foreach (NL_LoanSchedules s in activeSchedule)
            {
                AddNote(s.PlannedDate, i == activeScheduleCount - 1 ? "Last schedule." : "Schedule.");
                i++;
            }
        }
Example #21
0
		public void BuildLoanFromOffer() {
			NL_Model model = new NL_Model(1394) {
				UserID = 357,
				Loan = new NL_Loans()
			};
			model.Loan.Histories.Add(new NL_LoanHistory() { EventTime = DateTime.UtcNow });
			BuildLoanFromOffer strategy = new BuildLoanFromOffer(model);
			strategy.Context.UserID = model.UserID;
			try {
				strategy.Execute();
				//if (string.IsNullOrEmpty(strategy.Result.Error)) {
				//	this.m_oLog.Debug(strategy.Result.Offer);
				m_oLog.Debug(strategy.Result.Loan);
				//} else
				m_oLog.Debug("error: {0}", strategy.Result.Error);
			} catch (Exception ex) {
				Console.WriteLine(ex);
			}
		}
Example #22
0
        public void CreateSchedule()
        {
            NL_Model model = new NL_Model(56)
            {
                UserID = 357,
                Loan   = new NL_Loans()
            };

            model.Loan.Histories.Add(new NL_LoanHistory()
            {
                EventTime      = new DateTime(2015, 10, 15),            //DateTime.UtcNow,
                Amount         = 1000,
                RepaymentCount = 4,
                InterestRate   = 0.0225m,
            });
            var discounts = DB.Fill <NL_DiscountPlanEntries>("NL_DiscountPlanEntriesGet", CommandSpecies.StoredProcedure, new QueryParameter("@DiscountPlanID", 2));

            foreach (NL_DiscountPlanEntries dpe in discounts)
            {
                model.Offer.DiscountPlan.Add(Decimal.Parse(dpe.InterestDiscount.ToString(CultureInfo.InvariantCulture)));
            }
            //model.Offer.DiscountPlan.ForEach(d => Log.Info("discount entry: {0}", d));
            model.Offer.OfferFees = DB.Fill <NL_OfferFees>("NL_OfferFeesGet", CommandSpecies.StoredProcedure, new QueryParameter("@OfferID", 3));
            model.Offer.OfferFees.ForEach(f => Log.Info("fee: {0}", f));

            try {
                ALoanCalculator calc = new LegacyLoanCalculator(model);
                calc.CreateSchedule();
            } catch (NoInitialDataException noInitialDataException) {
                Log.Debug(noInitialDataException);
            } catch (InvalidInitialRepaymentCountException invalidInitialRepaymentCountException) {
                Log.Debug(invalidInitialRepaymentCountException);
            } catch (InvalidInitialInterestRateException invalidInitialInterestRateException) {
                Log.Debug(invalidInitialInterestRateException);
            } catch (InvalidInitialAmountException invalidInitialAmountException) {
                Log.Debug(invalidInitialAmountException);
            } catch (Exception exception) {
                Log.Error("No calculator instance {0}", exception);
            }

            Log.Info(model.Loan);
            //model.Loan.LastHistory().Schedule.ForEach(s => Log.Info(s.ToString()));
        }
Example #23
0
		public void AddLoan() {
			const int userID = 357;
			const int oldLoanID = 7152;
			LoanRepository loanRep = ObjectFactory.GetInstance<LoanRepository>();
			Loan oldLoan = loanRep.Get(oldLoanID);
			if (oldLoan == null)
				return;
			DateTime now = DateTime.UtcNow; // oldLoan.Date;
			NL_Model model = new NL_Model(oldLoan.Customer.Id) {
				UserID = userID,
				Loan = new NL_Loans() { OldLoanID = oldLoan.Id, Refnum = oldLoan.RefNumber },
				FundTransfer = new NL_FundTransfers() {
					Amount = oldLoan.LoanAmount,
					FundTransferStatusID = (int)NLFundTransferStatuses.Pending, // (int)NLPacnetTransactionStatuses.Done,
					LoanTransactionMethodID = (int)NLLoanTransactionMethods.Pacnet,
					TransferTime = now,
					PacnetTransactions = new List<NL_PacnetTransactions>()
				}
			};
			model.Loan.Histories.Add(new NL_LoanHistory() {
				EventTime = now,
				AgreementModel = JsonConvert.SerializeObject(oldLoan.AgreementModel)
			});
			model.Loan.LastHistory().Agreements.Add(new NL_LoanAgreements() {
				LoanAgreementTemplateID = 2065, //(int)NLLoanAgreementTemplateTypes.PreContractAgreement,
				FilePath = "2016/2/21/PAD64J14012/Guaranty Agreement_Deka_Dance_1394_21-02-2016_10-18-25.pdf", // "preContract/cc/dd" + oldLoan.RefNumber + ".pdf"
			});
			model.Loan.LastHistory().Agreements.Add(new NL_LoanAgreements() {
				LoanAgreementTemplateID = 2067, //(int)NLLoanAgreementTemplateTypes.GuarantyAgreement,
				FilePath = "2016/2/21/PAD64J14012/Private Company Loan Agreement_Deka_Dance_1394_21-02-2016_10-18-25.pdf", //"guarantyAgreement/aa/bb" + oldLoan.RefNumber + ".pdf"
			});
			AddLoan strategy = new AddLoan(model);
			strategy.Context.UserID = model.UserID;
			try {
				strategy.Execute();
				m_oLog.Debug(strategy.Error);
				m_oLog.Debug(strategy.LoanID);
				Console.WriteLine("LoanID: {0}, Error: {1}", strategy.LoanID, strategy.Error);
			} catch (Exception ex) {
				Console.WriteLine(ex);
			}
		}
Example #24
0
		public void CreateSchedule() {
			DateTime issueDate = DateTime.UtcNow; // new DateTime(2015, 12, 8, 19, 12, 00);
			NL_Model model = new NL_Model(1394) { UserID = 357, Loan = new NL_Loans() };
			model.Loan.Histories.Add(new NL_LoanHistory() { EventTime = issueDate });
			BuildLoanFromOffer strategy = new BuildLoanFromOffer(model);
			strategy.Execute();
			if (!string.IsNullOrEmpty(strategy.Error)) {
				m_oLog.Debug("error: {0}", strategy.Error);
				return;
			}
			model = strategy.Result;
			m_oLog.Debug("=================================={0}\n", model.Loan);
			try {
				ALoanCalculator calc = new LegacyLoanCalculator(model);
				calc.CreateSchedule();
				m_oLog.Debug("=================Calculator end================={0}\n", model.Loan);
			} catch (Exception exception) {
				m_oLog.Error("{0}", exception.Message);
			}
		}
Example #25
0
		public void TestDateInterval() {
			const long loanID = 17;
			GetLoanState strategy = new GetLoanState(56, loanID, DateTime.UtcNow, 357);
			strategy.Execute();
			NL_Model model = strategy.Result;
			model.Loan.Payments.Clear();
			try {
				DateTime calcDate = new DateTime(2015, 10, 25);
				ALoanCalculator calc = new LegacyLoanCalculator(model);
				DateTime start = calcDate;
				DateTime end = new DateTime(2016, 02, 25);
				int days = end.Subtract(start).Days;
				m_oLog.Debug("total days: {0}", days);
				var schedule = model.Loan.LastHistory().Schedule;
				for (int i=0; i <= days; i++) {
					DateTime theDate = start.AddDays(i);
					var scheduleItem = schedule.FirstOrDefault(s => theDate.Date >= calc.PreviousScheduleDate(s.PlannedDate.Date, RepaymentIntervalTypes.Month) && theDate.Date <= s.PlannedDate.Date);
					m_oLog.Debug("theDate: {0}, {1}", theDate, scheduleItem.PlannedDate);
				}
			} catch (Exception exception) {
				m_oLog.Error("{0}", exception.Message);
			}
		}
Example #26
0
        public JsonResult CreateLoanHidden(int nCustomerID, decimal nAmount, string sDate)
        {
            try {
                var lc = new LoanCreatorNoChecks(
                    ObjectFactory.GetInstance <IPacnetService>(),
                    ObjectFactory.GetInstance <IAgreementsGenerator>(),
                    ObjectFactory.GetInstance <IEzbobWorkplaceContext>(),
                    ObjectFactory.GetInstance <LoanBuilder>(),
                    ObjectFactory.GetInstance <ISession>()
                    );

                Customer oCustomer = this.customerRepository.Get(nCustomerID);

                DateTime oDate   = DateTime.ParseExact(sDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                NL_Model nlModel = new NL_Model(nCustomerID);
                lc.CreateLoan(oCustomer, nAmount, null, oDate, nlModel);

                return(Json(new { success = true, error = false, }));
            } catch (Exception e) {
                log.Warn(e, "Could not create a hidden loan.");
                return(Json(new { success = false, error = e.Message, }));
            }             // try
        }
Example #27
0
        public decimal GetAmountToPay(int customerID, long loandID, long loanScheduleID)
        {
            NL_Model nlModel = new NL_Model(customerID)
            {
                Loan = new NL_Loans()
            };
            GetLoanState state = new GetLoanState(customerID, loandID, DateTime.UtcNow);

            try {
                state.Execute();
                nlModel = state.Result;
            } catch (NL_ExceptionInputDataInvalid nlExceptionInputDataInvalid) {
                Error = nlExceptionInputDataInvalid.Message;
                Log.Error(Error);
                NL_AddLog(LogType.Error, "Failed to GetLoanState for NL loan", new object[] { customerID, loandID, loanScheduleID }, Error, nlExceptionInputDataInvalid.ToString(), nlExceptionInputDataInvalid.StackTrace);
            }

            if (!string.IsNullOrEmpty(state.Error))
            {
                Error = state.Error;
                Log.Error(Error);
                NL_AddLog(LogType.Error, "Failed to GetLoanState for NL loan", new object[] { customerID, loandID, loanScheduleID }, Error, Error, null);
            }

            var item = nlModel.Loan.LastHistory().Schedule.FirstOrDefault(s => s.LoanScheduleID == loanScheduleID);

            if (item != null)
            {
                return(item.AmountDue);
            }

            Error = string.Format("Failed to get AmountDue for nlloanID {0}, schedule={1}", loandID, loanScheduleID);
            Log.Error(Error);
            NL_AddLog(LogType.Error, "Failed to get AmountDue", new object[] { customerID, loandID, loanScheduleID }, Error, Error, null);

            return(0);
        }
Example #28
0
		public void APR() {
			const int userID = 357;
			const int oldLoanID = 3091;
			LoanRepository loanRep = ObjectFactory.GetInstance<LoanRepository>();
			Loan oldLoan = loanRep.Get(oldLoanID);
			DateTime now = oldLoan.Date;
			NL_Model model = new NL_Model(oldLoan.Customer.Id) {
				UserID = userID,
				Loan = new NL_Loans() { OldLoanID = oldLoan.Id, Refnum = oldLoan.RefNumber }
			};
			model.Loan.Histories.Add(new NL_LoanHistory() {
				EventTime = now,
				InterestRate = oldLoan.InterestRate,
				RepaymentCount = oldLoan.Schedule.Count,
				Amount = oldLoan.LoanAmount
			});
			try {
				ALoanCalculator calc = new LegacyLoanCalculator(model);
				double apr = calc.CalculateApr();
				m_oLog.Debug("CalculationDate: {0}, apr: {1}", calc.CalculationDate, apr);
			} catch (Exception exception) {
				m_oLog.Error("{0}", exception.Message);
			}
		}
Example #29
0
		/// <summary>
		/// Create new loan
		/// Expected input:
		///		NL_Model with:
		///			- CustomerID
		///			- Loan.OldLoanID
		///			- Loan.Refnum
		///			- Histories => history: EventTime (former IssuedTime)
		///			- Agreements
		///			- AgreementModel (JSON)
		///		Expected result:
		///			- int LoanID newly created
		///			- optional string Error
		/// 
		/// Creation of loan from underwriter not supported 
		/// Mail notifications sent on success/on error
		/// </summary>
		/// <param name="nlModel"></param>
		public AddLoan(NL_Model nlModel) {
			model = nlModel;
			nowTime = DateTime.UtcNow;
			this.strategyArgs = new object[] { model };
		}
Example #30
0
		public BuildLoanFromOffer(NL_Model model) {
			Result = model;
			this.strategyArgs = new object[] { Result };
		} // constructor