/// <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); } }
/// <exception cref="NL_ExceptionInputDataInvalid">Condition. </exception> public override void Execute() { if (!CurrentValues.Instance.NewLoanRun) { NL_AddLog(LogType.Info, "NL disabled by configuration", null, null, null, null); return; } // invalid input if (!string.IsNullOrEmpty(Error)) { throw new NL_ExceptionInputDataInvalid(Error); } NL_AddLog(LogType.Info, "Started", this.strategyArgs, null, Error, null); // load loan NL_Loans loan = LoanDAL.GetLoan(Payment.LoanID); if (loan.LoanStatusID == (int)NLLoanStatuses.Pending) { // loan pending - can't to add payment Error = string.Format("Loan {0} in status 'Pending' yet, payment registering not allowed.", loan.LoanID); Log.Debug(Error); NL_AddLog(LogType.Info, "End", this.strategyArgs, null, Error, null); return; } if ((loan.LoanStatusID == (int)NLLoanStatuses.PaidOff || loan.LoanStatusID == (int)NLLoanStatuses.WriteOff) && loan.DateClosed!=null) { // loan closed - can't to add payment Error = string.Format("Loan {0} in status {1} since {2:d}, payment registering not allowed.", loan.LoanID, loan.LoanStatusID, loan.DateClosed); Log.Debug(Error); NL_AddLog(LogType.Info, "End", this.strategyArgs, null, Error, null); return; } ConnectionWrapper pconn = DB.GetPersistent(); try { pconn.BeginTransaction(); // RESET PAID PRINCIPAL, INTEREST (SCHEDULE), FEES PAID on retroactive payment - in SP NL_ResetPaymentsPaidAmounts, called from NL_PaymentsSave. PaymentID = DB.ExecuteScalar<long>("NL_PaymentsSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter<NL_Payments>("Tbl", Payment)); Payment.PaymentID = PaymentID; if (Payment.PaypointTransactions.Count > 0) { NL_PaypointTransactions ppTransaction = Payment.PaypointTransactions.FirstOrDefault(); if (ppTransaction == null) { Log.Info("Paypoint transaction not found. Payment \n{0}{1}", AStringable.PrintHeadersLine(typeof(NL_Payments)), Payment.ToStringAsTable()); NL_AddLog(LogType.Info, "Paypoint transaction not found", this.strategyArgs, null, Error, null); } else { ppTransaction.PaymentID = Payment.PaymentID; ppTransaction.PaypointTransactionID = DB.ExecuteScalar<long>("NL_PaypointTransactionsSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter<NL_PaypointTransactions>("Tbl", ppTransaction)); } } pconn.Commit(); NL_AddLog(LogType.Info, "End", this.strategyArgs, Payment, Error, null); // ReSharper disable once CatchAllClause } catch (Exception ex) { pconn.Rollback(); Error = ex.Message; Log.Error("Failed to add new payment: {0}", Error); NL_AddLog(LogType.Error, "Strategy Faild - Rollback", Payment, Error, ex.ToString(), ex.StackTrace); return; } // recalculate state by calculator + save new state to DB UpdateLoanDBState reloadLoanDBState = new UpdateLoanDBState(CustomerID, Payment.LoanID, UserID); try { reloadLoanDBState.Execute(); // ReSharper disable once CatchAllClause } catch (Exception ex) { Error = ex.Message; Log.Error("Failed on UpdateLoanDBState {0}", Error); NL_AddLog(LogType.Error, "Failed on UpdateLoanDBState", Payment, reloadLoanDBState.Error + "\n" + Error, ex.ToString(), ex.StackTrace); } }
/// <exception cref="NL_ExceptionInputDataInvalid">Condition. </exception> /// <exception cref="NL_ExceptionLoanNotFound">Condition. </exception> /// <exception cref="NL_ExceptionCustomerNotFound">Condition. </exception> public override void Execute() { if (!CurrentValues.Instance.NewLoanRun) { NL_AddLog(LogType.Info, "NL disabled by configuration", null, null, null, null); return; } NL_AddLog(LogType.Info, "Started", this.strategyArgs, Error, null, null); if (CustomerID == 0) { Error = NL_ExceptionCustomerNotFound.DefaultMessage; NL_AddLog(LogType.Error, NL_ExceptionCustomerNotFound.DefaultMessage, this.strategyArgs, null, Error, null); throw new NL_ExceptionCustomerNotFound(Error); } if (Payment == null || Payment.LoanID == 0) { Error = NL_ExceptionLoanNotFound.DefaultMessage; NL_AddLog(LogType.Error, NL_ExceptionLoanNotFound.DefaultMessage, this.strategyArgs, null, Error, null); throw new NL_ExceptionLoanNotFound(Error); } if (Payment.PaymentID == 0) { Error = NL_ExceptionInputDataInvalid.DefaultMessage; NL_AddLog(LogType.Error, NL_ExceptionInputDataInvalid.DefaultMessage, this.strategyArgs, null, Error, null); throw new NL_ExceptionInputDataInvalid(Error); } if (Payment.PaymentStatusID != (int)NLPaymentStatuses.ChargeBack && Payment.PaymentStatusID != (int)NLPaymentStatuses.WrongPayment) { Error = "PaymentStatusID not ChargeBack and not WrongPayment"; NL_AddLog(LogType.Error, NL_ExceptionInputDataInvalid.DefaultMessage, this.strategyArgs, Error, null, null); throw new NL_ExceptionInputDataInvalid(Error); } if (Payment.DeletionTime.Equals(DateTime.MinValue) || Payment.DeletionTime == null) { Error = "DeletionTime not set"; NL_AddLog(LogType.Error, NL_ExceptionInputDataInvalid.DefaultMessage, this.strategyArgs, Error, null, null); throw new NL_ExceptionInputDataInvalid(Error); } if (Payment.DeletedByUserID == null || Payment.DeletedByUserID == 0) { Error = "DeletedByUserID not set"; NL_AddLog(LogType.Error, NL_ExceptionInputDataInvalid.DefaultMessage, this.strategyArgs, Error, null, null); throw new NL_ExceptionInputDataInvalid(Error); } ConnectionWrapper pconn = DB.GetPersistent(); try { pconn.BeginTransaction(); Log.Debug("==============================={0}", new QueryParameter("PaymentStatusID", Payment.PaymentStatusID)); // RESET PAID PRINCIPAL, INTEREST (SCHEDULE), FEES PAID AFTER [DeletionTime] on delete payment - in SP NL_ResetPaymentsPaidAmounts, called from NL_PaymentCancel DB.ExecuteNonQuery(pconn, "NL_PaymentCancel", CommandSpecies.StoredProcedure, new QueryParameter("PaymentID", Payment.PaymentID), new QueryParameter("LoanID", Payment.LoanID), new QueryParameter("PaymentStatusID", Payment.PaymentStatusID), new QueryParameter("DeletionTime", Payment.DeletionTime), new QueryParameter("DeletedByUserID", Payment.DeletedByUserID), new QueryParameter("Notes", Payment.Notes) ); pconn.Commit(); // ReSharper disable once CatchAllClause } catch (Exception ex) { pconn.Rollback(); Error = ex.Message; Log.Error("Failed to cancel payment: {0}", Error); NL_AddLog(LogType.Error, "Failed - Rollback", Payment, Error, ex.ToString(), ex.StackTrace); return; } NL_AddLog(LogType.Info, "End", this.strategyArgs, Payment, null, null); // recalculate state with calculator + save new state to DB UpdateLoanDBState reloadLoanDBState = new UpdateLoanDBState(CustomerID, Payment.LoanID, UserID); try { reloadLoanDBState.Execute(); } catch (Exception ex) { Error = ex.Message; NL_AddLog(LogType.Error, "Failed on UpdateLoanDBState", Payment, reloadLoanDBState.Error + "\n" + Error, ex.ToString(), ex.StackTrace); } }