コード例 #1
0
ファイル: TestNewLoan.cs プロジェクト: vijayamazon/ezbob
		public void UpdateRolloverTest() {
			const int oldID = 5116;
			const int customerID = 385;
			DateTime now = DateTime.UtcNow;
			PaymentRolloverRepository rep = ObjectFactory.GetInstance<PaymentRolloverRepository>();
			var rollovers = rep.GetByLoanId(oldID);
			var paymentRollovers = rollovers as IList<PaymentRollover> ?? rollovers.ToList();
			//paymentRollovers.ForEach(rr => this.m_oLog.Debug(rr));
			var r = paymentRollovers.FirstOrDefault(rr => rr.ExpiryDate > now);
			m_oLog.Debug(r);
			if (r == null) {
				return;
			}

			var s = new GetLoanIDByOldID(oldID);
			s.Execute();
			GetLoanState state = new GetLoanState(customerID, s.LoanID, now, 1, false);
			state.Execute();

			NL_LoanRollovers nlr = state.Result.Loan.Rollovers.FirstOrDefault(nr => nr.CreationTime.Date == r.Created.Date && nr.ExpirationTime.Date == r.ExpiryDate);

			if (nlr == null)
				return;

			nlr.ExpirationTime = nlr.ExpirationTime.AddDays(4);

			m_oLog.Debug(nlr);

			SaveRollover saver = new SaveRollover(nlr, state.Result.Loan.LoanID);
			saver.Execute();
			m_oLog.Debug(saver.Error);
		}
コード例 #2
0
        }         // AddPayment

        public StringActionResult SaveRollover(int userID, int customerID, NL_LoanRollovers rollover, long loanID)
        {
            SaveRollover s = new SaveRollover(rollover, loanID);

            s.Context.UserID     = userID;
            s.Context.CustomerID = customerID;
            var amd = ExecuteSync(out s, customerID, userID, rollover, loanID);

            return(new StringActionResult {
                Value = s.Error
            });
        }         // SaveRollover
コード例 #3
0
        public void RemoveRollover(int rolloverId, long nlRolloverID = 0)
        {
            var rollover = this.rolloverRepository.GetById(rolloverId);

            rollover.Status = RolloverStatus.Removed;
            this.rolloverRepository.Update(rollover);

            try {
                int loanID     = rollover.LoanSchedule.Loan.Id;
                int customerID = rollover.LoanSchedule.Loan.Customer.Id;

                long nlLoanId = this.serviceClient.Instance.GetLoanByOldID(loanID, customerID, this.context.UserId).Value;

                if (nlLoanId > 0)
                {
                    var nlModel = this.serviceClient.Instance.GetLoanState(customerID, nlLoanId, DateTime.UtcNow, this.context.UserId, false).Value;

                    NL_LoanRollovers nlRollover = null;

                    if (nlRolloverID > 0)
                    {
                        nlRollover = nlModel.Loan.Rollovers.FirstOrDefault(r => r.LoanRolloverID == nlRolloverID);
                    }

                    // TEMPORARY UNTILL "old" WILL BE RAPLACED BY NL rollover
                    DateTime oexpireTime = rollover.ExpiryDate.HasValue ? rollover.ExpiryDate.Value : DateTime.MinValue;
                    nlRollover = nlModel.Loan.Rollovers.FirstOrDefault(r => r.CreationTime.Date == rollover.Created.Date && r.ExpirationTime.Date == oexpireTime.Date);

                    if (nlRollover == null)
                    {
                        string message = string.Format("remove rollover: rollover record for loan {0}/nl {1} not found", loanID, nlModel.Loan.LoanID);
                        Log.InfoFormat(message);
                        return;
                    }

                    nlRollover.DeletedByUserID = this.context.UserId;
                    nlRollover.DeletionTime    = DateTime.UtcNow;

                    this.serviceClient.Instance.SaveRollover(this.context.UserId, customerID, nlRollover, nlLoanId);
                }

                // ReSharper disable once CatchAllClause
            } catch (Exception ex) {
                Log.InfoFormat("<<< NL_Compare Fail at: {0}, err: {1}", Environment.StackTrace, ex.Message);
            }
        }
コード例 #4
0
ファイル: AcceptRollover.cs プロジェクト: vijayamazon/ezbob
		/// <exception cref="ArgumentNullException"><paramref /> is null. </exception>
		/// <exception cref="FormatException"><paramref /> is not in the correct format. </exception>
		public override void Execute() {

			if (!CurrentValues.Instance.NewLoanRun) {
				NL_AddLog(LogType.Info, "NL disabled by configuration", null, null, null, null);
				return;
			}

			this.strategyArgs = new object[] { CustomerID, LoanID };

			if (CustomerID == 0) {
				Error = NL_ExceptionCustomerNotFound.DefaultMessage;
				NL_AddLog(LogType.DataExsistense, "Strategy failed", this.strategyArgs, null, Error, null);
				return;
			}

			if (LoanID == 0) {
				Error = NL_ExceptionLoanNotFound.DefaultMessage;
				NL_AddLog(LogType.DataExsistense, "Strategy failed", this.strategyArgs, null, Error, null);
				return;
			}

			// TODO EZ-4330
			/* RolloverPayment = open interest till accept day included + rollover fees assigned
			1. records NL_Payments (+NL_PaypointTransactions) for rollover () - via AddPayment strategy from outside - via customer dashboard before this strategy
			2. record rollover fee for into NL_LoanFees
			3. update existing rollover record: [CustomerActionTime], [IsAccepted] in [dbo].[NL_LoanRollovers] table
			5. make rollover using calculator - add to NL model new history, rearrange schedules, statuses
			 *  - run calc.GetState to get outstanding balance
			 *  - create new history
			 *  - mark non relevant schedules as CancelledOnRollover
			 *  - create schedule for new history
			6. update DB: records new history, new schedule items; update previous schedule with appropriate statuses
			*/

			DateTime nowTime = DateTime.Now;
			bool rolloverAccepted = false;

			NL_AddLog(LogType.Info, "Strategy Start", this.strategyArgs, null, Error, null);

			// fetch loan's rollovers and check rollover exists, valid and not accepted yet
			NL_LoanRollovers rollover=DB.Fill<NL_LoanRollovers>("NL_RolloversGet", CommandSpecies.StoredProcedure, new QueryParameter("LoanID", LoanID))
				.FirstOrDefault(r => r.DeletedByUserID == null && r.DeletionTime == null && r.IsAccepted == false && (r.CreationTime <= nowTime && nowTime <= r.ExpirationTime));

			if (rollover == null) {
				Error = string.Format("Rollover opportunity for loan {0} not found, or expired, or accepted", LoanID);
				Log.Info(Error);
				NL_AddLog(LogType.DataExsistense, "Strategy end", this.strategyArgs, null, Error, null);
				rolloverAccepted = true;
			}

			if (!rolloverAccepted) {
				// set rollover data for future update
				rollover.IsAccepted = true;
				rollover.CustomerActionTime = nowTime;

				ConnectionWrapper pconn = DB.GetPersistent();

				try {

					// insert rollover fee
					NL_LoanFees rolloverFee = new NL_LoanFees() {
						LoanID = LoanID,
						Amount = Decimal.Parse(CurrentValues.Instance.RolloverCharge.Value),
						AssignedByUserID = rollover.CreatedByUserID,
						AssignTime = rollover.CustomerActionTime.Value,
						CreatedTime = rollover.CustomerActionTime.Value, //DateTime.UtcNow,
						LoanFeeTypeID = (int)NLFeeTypes.RolloverFee,
						Notes = string.Format("rolloverID {2} {0:d}-{1:d}", rollover.CreationTime, rollover.ExpirationTime, rollover.LoanRolloverID)
					};

					rollover.LoanFeeID = DB.ExecuteScalar<long>("NL_LoanFeesSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter<NL_LoanFees>("Tbl", rolloverFee));

					Log.Info("NL rollover fee {0} added", rollover.LoanFeeID);
					NL_AddLog(LogType.Info, "Rollover fee added", this.strategyArgs, rollover.LoanFeeID, Error, null);

					// set newly created history ID for rollover row
					//rollover.LoanHistoryID = loanState.Result.Loan.LastHistory().LoanHistoryID;

					// update rollover
					DB.ExecuteNonQuery("NL_LoanRolloverUpdate", CommandSpecies.StoredProcedure, DB.CreateTableParameter<NL_LoanRollovers>("Tbl", rollover), new QueryParameter("RolloverID", rollover.LoanRolloverID));

					pconn.Commit();

					//ReSharper disable once CatchAllClause
				} catch (Exception ex) {

					pconn.Rollback();

					Error = ex.Message;
					Log.Error("Failed to 'accept rollover': {0}", Error);
					NL_AddLog(LogType.Error, "Strategy failed", this.strategyArgs, Error, ex.ToString(), ex.StackTrace);

					return;
				}
			}

			// update "old" schedules, add new history + new schedules + new distributed fees to DB
			UpdateLoanDBState updateState = new UpdateLoanDBState(CustomerID, LoanID, 1);
			try {
				updateState.Execute();
				// ReSharper disable once CatchAllClause
			} catch (Exception ex) {
				Error = ex.Message;
				Log.Alert(Error);
				NL_AddLog(LogType.Error, "Strategy failed", this.strategyArgs, null, Error, null);
			}

			// reassign payments and save
			try {
				updateState.Execute();
				// ReSharper disable once CatchAllClause
			} catch (Exception ex) {
				Error = ex.Message;
				Log.Alert(Error);
				NL_AddLog(LogType.Error, "Strategy failed", this.strategyArgs, null, Error, null);
			}

		}
コード例 #5
0
ファイル: SaveRollover.cs プロジェクト: vijayamazon/ezbob
 public SaveRollover(NL_LoanRollovers r, long loanID)
 {
     rollover          = r;
     LoanID            = loanID;
     this.strategyArgs = new object[] { LoanID, rollover };
 }
コード例 #6
0
        public void AddRollover(int scheduleId, string experiedDate, bool isEditCurrent, decimal payment, int?rolloverId, int mounthCount, long nlRolloverID = 0)
        {
            var expDate             = FormattingUtils.ParseDateWithoutTime(experiedDate);
            var currentLoanSchedule = this.loanScheduleRepository.GetById(scheduleId);
            var rolloverModel       = isEditCurrent && rolloverId.HasValue ? this.rolloverRepository.GetById((int)rolloverId) : new PaymentRollover();
            var customer            = currentLoanSchedule.Loan.Customer;

            if (expDate <= DateTime.UtcNow)
            {
                throw new Exception("Incorrect date");
            }
            if (mounthCount < 1)
            {
                throw new Exception("Month count must be at least 1");
            }

            if (isEditCurrent)
            {
                if (rolloverModel == null)
                {
                    throw new Exception("Loan schedule #{0} not found for editing");
                }
            }
            else
            {
                var rollovers = this.rolloverRepository.GetByLoanId(currentLoanSchedule.Loan.Id);
                if (rollovers.Any(rollover => rollover.Status == RolloverStatus.New && rollover.ExpiryDate > DateTime.UtcNow))
                {
                    throw new Exception("The loan has an unpaid rollover. Please close unpaid rollover and try again");
                }
            }


            DateTime ocreateTime = rolloverModel.Created.Date;
            DateTime oexpireTime = rolloverModel.ExpiryDate.HasValue ? rolloverModel.ExpiryDate.Value : DateTime.MinValue;

            rolloverModel.MounthCount  = mounthCount;
            rolloverModel.ExpiryDate   = expDate;
            rolloverModel.LoanSchedule = currentLoanSchedule;
            rolloverModel.CreatorName  = this.context.User.Name;
            rolloverModel.Created      = DateTime.Now;
            rolloverModel.Payment      = CurrentValues.Instance.RolloverCharge;
            rolloverModel.Status       = RolloverStatus.New;
            this.rolloverRepository.SaveOrUpdate(rolloverModel);

            try {
                long nlLoanId = this.serviceClient.Instance.GetLoanByOldID(currentLoanSchedule.Loan.Id, customer.Id, this.context.UserId).Value;

                if (nlLoanId > 0)
                {
                    var nlModel = this.serviceClient.Instance.GetLoanState(customer.Id, nlLoanId, rolloverModel.Created, this.context.UserId, false).Value;

                    NL_LoanRollovers nlRollover = null;

                    if (nlRolloverID > 0)
                    {
                        nlRollover = nlModel.Loan.Rollovers.FirstOrDefault(r => r.LoanRolloverID == nlRolloverID);
                    }

                    // TEMPORARY UNTILL "old" WILL BE RAPLACED BY NL rollover
                    if (isEditCurrent && rolloverId > 0)
                    {
                        nlRollover = nlModel.Loan.Rollovers.FirstOrDefault(r => r.CreationTime.Date == ocreateTime && r.ExpirationTime.Date == oexpireTime.Date);
                    }

                    if (nlRollover == null)
                    {
                        nlRollover = new NL_LoanRollovers();
                        nlRollover.LoanHistoryID = nlModel.Loan.LastHistory().LoanHistoryID;
                    }

                    nlRollover.CreatedByUserID = this.context.UserId;
                    nlRollover.CreationTime    = rolloverModel.Created;
                    nlRollover.ExpirationTime  = (DateTime)rolloverModel.ExpiryDate;

                    this.serviceClient.Instance.SaveRollover(this.context.UserId, customer.Id, nlRollover, nlLoanId);
                }

                // ReSharper disable once CatchAllClause
            } catch (Exception ex) {
                Log.InfoFormat("<<< NL_Compare Fail at: {0}, err: {1}", Environment.StackTrace, ex.Message);
            }

            this.serviceClient.Instance.EmailRolloverAdded(this.context.UserId, customer.Id, payment);
        }
コード例 #7
0
ファイル: LoanEvent.cs プロジェクト: vijayamazon/ezbob
 // rollover
 public LoanEvent(DateTime date, NL_LoanRollovers rollover) : this(date) {
     Rollover = rollover;
 }