public int SendNotification(SavingEvent savingEvent, OPaymentMethods paymentMethod) { if (person == null) { throw new ArgumentNullException("client"); } var messageTemplate = GetLocalizedActiveMessageTemplate("Client.LoanDisbursementNotification"); if (messageTemplate == null) { return(0); } SavingBookContract savingsContract = (SavingBookContract)SavingsService.GetSaving(savingEvent.ContracId); //tokens var tokens = new List <Token>(); MessageTokenProvider.AddPersonTokens(tokens, person); MessageTokenProvider.AddSavingEventTokens(tokens, savingEvent, savingsContract); tokens.Add(new Token("Messaging.CurrentDate", DateTime.Now.ToShortDateString())); tokens.Add(new Token("Messaging.CurrentTime", DateTime.Now.ToShortTimeString())); //event notification EventPublisher.MessageTokensAdded(messageTemplate, tokens); var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate); var toEmail = person.Email; var toName = person.FullName; return(SendNotification(messageTemplate, emailAccount, tokens, toEmail, toName)); }
public void AddSavingEventTokens(List <Token> tokens, SavingEvent savingEvent, ISavingsContract savingsContract) { string description = savingEvent.Description; string formatedAccountNumber = "******" + savingsContract.Code.Substring(savingsContract.Code.Length - 4); if (description.Contains(savingsContract.Code)) { description.Replace(savingsContract.Code, formatedAccountNumber); } tokens.Add(new Token("SavingEvent.Id", savingEvent.Id.ToString())); tokens.Add(new Token("SavingEvent.Code", savingEvent.Code)); tokens.Add(new Token("SavingEvent.Description", description)); tokens.Add(new Token("SavingEvent.ReferenceNumber", savingEvent.ReferenceNumber)); tokens.Add(new Token("SavingEvent.PaymentsMethod", savingEvent.PaymentsMethod != null ? savingEvent.PaymentsMethod.Name : "")); tokens.Add(new Token("SavingEvent.Date", savingEvent.Date.ToShortDateString())); tokens.Add(new Token("SavingEvent.Currency", savingEvent.Currency != null ? savingEvent.Currency.Name : "NAIRA")); tokens.Add(new Token("SavingEvent.Amount", savingEvent.Amount.GetFormatedValue(true))); tokens.Add(new Token("SavingEvent.Branch", savingEvent.Branch != null ? savingEvent.Branch.Name : "")); tokens.Add(new Token("SavingEvent.Comment", savingEvent.Comment)); tokens.Add(new Token("SavingEvent.IsPending", savingEvent.IsPending.ToString())); tokens.Add(new Token("SavingEvent.SavingProduct.Code", savingEvent.SavingProduct != null ? savingEvent.SavingProduct.Code : "")); tokens.Add(new Token("SavingEvent.SavingsMethod", savingEvent.SavingsMethod != null ? savingEvent.SavingsMethod.Description() : "")); tokens.Add(new Token("SavingEvent.AccountNumber", formatedAccountNumber)); tokens.Add(new Token("SavingEvent.AccountBalance", savingsContract.GetFmtBalance(true))); tokens.Add(new Token("SavingEvent.AccountAvailableBalance", savingsContract.GetFmtAvailBalance(true))); }
public void TestInitialDepositEvent() { Assert.Ignore(); Assert.AreEqual(_savingEventManager.Add(_saving.Events[0], _saving.Id), _saving.Events[0].Id); SavingEvent retrievedSavingEvent = _savingEventManager.SelectEvents(_saving.Id, _saving.Product)[0]; CompareEvent(_saving.Events[0], retrievedSavingEvent); }
private static SavingEvent ReadEvent(OpenCbsReader r, ISavingProduct pProduct) { string code = r.GetString("code"); SavingEvent e = GetSavingsEvent(code); SetSavingsEvent(r, e, pProduct); return(e); }
private DateTime GetLastAgioEventDate() { CreationDate = new DateTime(CreationDate.Year, CreationDate.Month, CreationDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); SavingEvent savingEvent = Events.OrderByDescending(item => item.Date). FirstOrDefault(item => (item is SavingAgioEvent || item is SavingClosureEvent) && !item.Deleted); return((null == savingEvent) ? CreationDate : savingEvent.Date); }
private List <SavingEvent> GenerateAMFeeEvent(SavingEvent savingsEvent) { List <SavingEvent> retval = new List <SavingEvent>(); const string desc = "Account maintenance fee of {0:.00} : {1}"; var fees = Product.AMFeesType == OSavingsFeesType.Flat ? FlatAMFees.GetFormatedValue(true) : Convert.ToString(savingsEvent.Amount * RateAMFees.Value); object[] items = new object[] { fees, Code }; SavingAMFeeEvent sdsfe = new SavingAMFeeEvent { Amount = 0m, Cancelable = true, Date = savingsEvent.Date, Description = string.Format(desc, items), Fee = Product.AMFeesType == OSavingsFeesType.Flat ? FlatAMFees : savingsEvent.Amount * RateAMFees.Value, User = savingsEvent.User, ProductType = Product.GetType(), Branch = Branch, Currency = Product.Currency, ContracId = Id, IsPending = true }; retval.Add(sdsfe); AddSavingEvent(sdsfe); OCurrency balance = GetBalance(CreationDate); if (balance < 0) { if (!InOverdraft) { SavingOverdraftFeeEvent overdraftFeeEvent = new SavingOverdraftFeeEvent { Amount = 0m, Date = CreationDate, Description = "Overdraft fee event : " + Code, User = User, Cancelable = false, Fee = OverdraftFees, ProductType = typeof(SavingsBookProduct), Branch = Branch, Currency = Product.Currency, ContracId = Id }; AddSavingEvent(overdraftFeeEvent); retval.Add(overdraftFeeEvent); InOverdraft = true; } } return(retval); }
private static void SetInsertCommandForSavingEvent(OpenCbsCommand c, SavingEvent pSavingEvent, int pSavingContractId) { c.AddParam("@user_id", pSavingEvent.User.Id); c.AddParam("@contract_id", pSavingContractId); c.AddParam("@code", pSavingEvent.Code); c.AddParam("@amount", pSavingEvent.Amount); c.AddParam("@description", pSavingEvent.Description); c.AddParam("@deleted", pSavingEvent.Deleted); c.AddParam("@creation_date", pSavingEvent.Date); c.AddParam("@cancelable", pSavingEvent.Cancelable); c.AddParam("@is_fired", pSavingEvent.IsFired); c.AddParam("@related_contract_code", pSavingEvent is SavingTransferEvent ? ((SavingTransferEvent)pSavingEvent).RelatedContractCode : null); c.AddParam("@fees", pSavingEvent is ISavingsFees ? ((ISavingsFees)pSavingEvent).Fee : null); if (pSavingEvent.PaymentMethod != null && pSavingEvent.PaymentsMethod.Id != 0) { c.AddParam("@savings_method", pSavingEvent.PaymentsMethod.Id); } else if (pSavingEvent.SavingsMethod.HasValue) { c.AddParam("@savings_method", (int)pSavingEvent.SavingsMethod.Value); } else { c.AddParam("@savings_method", null); } c.AddParam("@pending", pSavingEvent.IsPending); if (pSavingEvent.PendingEventId.HasValue) { c.AddParam("@pending_event_id", pSavingEvent.PendingEventId); } else { c.AddParam("@pending_event_id", null); } if (pSavingEvent.TellerId.HasValue && pSavingEvent.TellerId > 0) { if (pSavingEvent.TellerId != 0) { c.AddParam("@teller_id", pSavingEvent.TellerId); } else { c.AddParam("@teller_id", null); } } else { c.AddParam("@teller_id", null); } c.AddParam("@loan_event_id", pSavingEvent.LoanEventId); c.AddParam("@doc1", pSavingEvent.Doc1); }
public SavingEvent AddSavingEvent(SavingEvent e) { SavingEvent savEvent = EvaluateSavingsEvent(e); if (savEvent != null) { Events.Add(e); } return(savEvent); }
public SavingEvent GetCancelableEvent() { if (0 == Events.Count) { return(null); } SavingEvent evt = Events.OrderBy(item => item.Date).Last(item => !item.Deleted); return(evt.Cancelable ? evt : null); }
public void TestDepositEvent() { List <SavingEvent> savingEventList = _saving.Deposit(100, TimeProvider.Today, "testDepot", _user, false, false, OSavingsMethods.Cash, new PaymentMethod(), null, null); foreach (SavingEvent savingEvent in savingEventList) { savingEvent.Id = _savingEventManager.Add(savingEvent, _saving.Id); SavingEvent retrievedSavingEvent = _savingEventManager.SelectEvents(_saving.Id, _saving.Product).Find(item => item.Id == savingEvent.Id); CompareEvent(savingEvent, retrievedSavingEvent); } }
public void TestWithdrawEvent() { _saving.FlatWithdrawFees = 10; List <SavingEvent> savingEvents = _saving.Withdraw(100, TimeProvider.Today, "testDepot", _user, false, null, new PaymentMethod()); savingEvents[0].Id = 100; _savingEventManager.Add(savingEvents[0], _saving.Id); SavingEvent retrievedSavingEvent = _savingEventManager.SelectEvents(_saving.Id, _saving.Product).Find(item => item.Id == savingEvents[0].Id); CompareEvent(savingEvents[0], retrievedSavingEvent); }
public SavingEvent CancelLastEvent() { SavingEvent retval = GetCancelableEvent(); if (null == retval) { return(null); } CancelEvent(retval); return(retval); }
private List <SavingEvent> GenerateDutyStampFeeEvent(SavingEvent savingsEvent) { List <SavingEvent> retval = new List <SavingEvent>(); const string desc = "Duty stamp fee of {0:.00} : {1}"; object[] items = new object[] { DutyStampFees.GetFormatedValue(true), Code }; SavingDutyStampFeeEvent sdsfe = new SavingDutyStampFeeEvent { Amount = 0m, Cancelable = true, Date = savingsEvent.Date, Description = string.Format(desc, items), Fee = DutyStampFees.HasValue ? DutyStampFees : 0m, User = savingsEvent.User, ProductType = Product.GetType(), Branch = Branch, Currency = Product.Currency, ContracId = Id }; retval.Add(sdsfe); AddSavingEvent(sdsfe); OCurrency balance = GetBalance(CreationDate); if (balance < 0) { if (!InOverdraft) { SavingOverdraftFeeEvent overdraftFeeEvent = new SavingOverdraftFeeEvent { Amount = 0m, Date = CreationDate, Description = "Overdraft fee event : " + Code, User = User, Cancelable = false, Fee = OverdraftFees, ProductType = typeof(SavingsBookProduct), Branch = Branch, Currency = Product.Currency, ContracId = Id }; AddSavingEvent(overdraftFeeEvent); retval.Add(overdraftFeeEvent); InOverdraft = true; } } return(retval); }
public void Transfer_Events() { Assert.Ignore(); List <SavingEvent> events = _saving.Transfer(_savingTarget, 50, 0, DateTime.Today, "Transfer description"); events[0].Id = _savingEventManager.Add(events[0], _saving.Id); events[1].Id = _savingEventManager.Add(events[1], _saving.Id); SavingEvent e1 = _savingEventManager.SelectEvents(_saving.Id, _saving.Product).Find(item => item.Id == events[0].Id); SavingEvent e2 = _savingEventManager.SelectEvents(_saving.Id, _saving.Product).Find(item => item.Id == events[1].Id); CompareEvent(events[0], e1); CompareEvent(events[1], e2); }
public virtual List <SavingEvent> Closure(DateTime date, User user) { SavingEvent evt = GenerateClosureEvent(date); if (evt != null) { Events.Add(evt); return(new List <SavingEvent> { evt }); } return(null); }
public void CancelEvent(SavingEvent pSavingEvent) { pSavingEvent.Deleted = true; pSavingEvent.IsPending = false; pSavingEvent.CancelDate = new DateTime( TimeProvider.Now.Year, TimeProvider.Now.Month, TimeProvider.Now.Day, TimeProvider.Now.Hour, TimeProvider.Now.Minute, TimeProvider.Now.Second ); }
public void TestDeleteEvent() { _saving.FlatWithdrawFees = 0; List <SavingEvent> savingEvents = _saving.Withdraw(100, new DateTime(2009, 02, 01), "testRetrait", _user, false, null, new PaymentMethod()); savingEvents[0].Id = _savingEventManager.Add(savingEvents[0], _saving.Id); savingEvents[0].CancelDate = DateTime.Now; _savingEventManager.DeleteEventInDatabase(savingEvents[0]); SavingEvent retrievedEvent = _savingEventManager.SelectEvents(_saving.Id, _saving.Product).Find(item => item.Id == savingEvents[0].Id); Assert.AreEqual(retrievedEvent.Deleted, true); }
public void TestFireEvent() { //SavingEvent savingEvent = _saving.Deposit(100, new DateTime(2009, 02, 01), "testDepot", _user, false); // List<SavingEvent> savingEventList = _saving.Deposit(100, new DateTime(2009, 02, 01), "testDepot", _user, false, false, OPaymentMethods.Cash, null, null); List <SavingEvent> savingEventList = _saving.Deposit(100, new DateTime(2009, 02, 01), "testDepot", _user, false, false, OSavingsMethods.Cash, new PaymentMethod(), null, null); foreach (var savingEvent in savingEventList) { savingEvent.Id = _savingEventManager.Add(savingEvent, _saving.Id); _savingEventManager.FireEvent(savingEvent.Id); SavingEvent retrievedEvent = _savingEventManager.SelectEvents(_saving.Id, _saving.Product).Find(item => item.Id == savingEvent.Id); Assert.AreEqual(retrievedEvent.IsFired, true); } }
public int Add(SavingEvent pSavingEvent, int pSavingContractId, SqlTransaction sqlTransac) { const string q = @"INSERT INTO [SavingEvents]( [user_id], [contract_id], [code], [amount], [description], [reference_number], [deleted], [creation_date], [cancelable], [is_fired], [related_contract_code], [fees], [savings_method], [pending], [is_local], [pending_event_id], [teller_id], [loan_event_id]) VALUES( @user_id, @contract_id, @code, @amount, @description, @reference_number, @deleted, @creation_date, @cancelable, @is_fired, @related_contract_code, @fees, @savings_method, @pending, @is_local, @pending_event_id, @teller_id, @loan_event_id) SELECT CONVERT(int, SCOPE_IDENTITY())" ; using (OpenCbsCommand c = new OpenCbsCommand(q, sqlTransac.Connection, sqlTransac)) { SetInsertCommandForSavingEvent(c, pSavingEvent, pSavingContractId); pSavingEvent.Id = Convert.ToInt32(c.ExecuteScalar()); return(pSavingEvent.Id); } }
public void TestAccrualEvent() { int i = 10; foreach (SavingEvent savingEvent in _saving.CalculateInterest(new DateTime(2009, 01, 05), _user)) { savingEvent.Id = i; savingEvent.Id = _savingEventManager.Add(savingEvent, _saving.Id); SavingEvent retrievedEvent = _savingEventManager.SelectEvents(_saving.Id, _saving.Product).Find(item => item.Id == savingEvent.Id); CompareEvent(savingEvent, retrievedEvent); i++; } }
public SavingEvent GetCancelableEvent() { if (0 == Events.Count) { return(null); } SavingEvent evt = Events.OrderBy(item => item.Date).Last(item => !item.Deleted && !(item is SavingDutyStampFeeEvent) && !(item is SavingInstrumentFeeEvent) && !(item is SavingSearchFeeEvent) && !(item is SavingAMFeeEvent)); return(evt.Cancelable ? evt : null); }
public List <SavingEvent> GetCancelableFeeEvent(SavingEvent parentEvent) { int parentEventIndex = Events.IndexOf(parentEvent); List <SavingEvent> feeEvents = new List <SavingEvent>(); for (int i = parentEventIndex; i < Events.Count; i++) { if (Events[i].Cancelable) { feeEvents.Add(Events[i]); } } return(feeEvents); }
protected DateTime GetLastManagementFeeEventDate() { CreationDate = new DateTime(CreationDate.Year , CreationDate.Month , CreationDate.Day , DateTime.Now.Hour , DateTime.Now.Minute , DateTime.Now.Second); SavingEvent smfe = Events .FindAll(e => e is SavingManagementFeeEvent && !e.Deleted) .OrderByDescending(e => e.Date) .FirstOrDefault(); return(null == smfe ? CreationDate : smfe.Date); }
public void DeleteEventInDatabase(SavingEvent pSavingEvent) { const string q = @"UPDATE [SavingEvents] SET [deleted] = 1 , is_exported = 0 ,[cancel_date] = @cancel_date WHERE id = @id"; using (SqlConnection conn = GetConnection()) using (OpenCbsCommand c = new OpenCbsCommand(q, conn)) { c.AddParam("@id", pSavingEvent.Id); c.AddParam("@cancel_date", pSavingEvent.CancelDate.Value); c.ExecuteNonQuery(); } }
protected List <SavingEvent> AddSavingEvent(List <SavingInterestsPostingEvent> pEvents) { List <SavingEvent> retval = new List <SavingEvent>(); List <SavingEvent> events = pEvents.ConvertAll <SavingEvent>(delegate(SavingInterestsPostingEvent e) { return(e); }); foreach (SavingEvent e in events) { SavingEvent savEvent = EvaluateSavingsEvent(e); if (savEvent != null) { Events.Add(e); retval.Add(savEvent); } } return(retval); }
private List <SavingEvent> ChargeAMFee(SavingEvent savingsEvent) { List <SavingEvent> retval = new List <SavingEvent>(); List <SavingEvent> list = GenerateAMFeeEvent(savingsEvent); if (list != null) { if (list[0].Fee > 0) { retval.Add(list[0]); } if (list.Count > 1 && list[1].Fee > 0) { retval.Add(list[1]); } } return(retval); }
protected SavingEvent EvaluateSavingsEvent(SavingEvent e) { if (!e.Amount.HasValue) { e.Amount = 0m; } if (!e.Fee.HasValue) { e.Fee = 0m; } if (e is SavingInterestsAccrualEvent || e is SavingInterestsPostingEvent) { if (e.Amount > 0) { e.Amount = Product.Currency.UseCents ? Math.Round(e.Amount.Value, 2, MidpointRounding.AwayFromZero) : Math.Round(e.Amount.Value, 0, MidpointRounding.AwayFromZero); if (e.Amount > 0) { return(e); } } } if (e is SavingAgioEvent || e is SavingManagementFeeEvent || e is SavingInstrumentFeeEvent || e is SavingSearchFeeEvent || e is SavingDutyStampFeeEvent) { if (e.Fee > 0) { e.Fee = Product.Currency.UseCents ? Math.Round(e.Fee.Value, 2, MidpointRounding.AwayFromZero) : Math.Round(e.Fee.Value, 0, MidpointRounding.AwayFromZero); if (e.Fee > 0) { return(e); } } } //return filteredEvents; return(null); }
public void FireEvent(SavingEvent e) { Debug.Assert(e.Target != null, "Saving event's target is null"); e.IsFired = true; using (SqlConnection conn = _savingEventManagement.GetConnection()) using (SqlTransaction t = conn.BeginTransaction()) { try { SavingEventOrigination(e, e.Target, t); t.Commit(); } catch (Exception) { t.Rollback(); throw; } } }
public int Add(SavingEvent pSavingEvent, int pSavingContactId) { using (SqlConnection conn = GetConnection()) { using (SqlTransaction t = conn.BeginTransaction()) { try { int id = Add(pSavingEvent, pSavingContactId, t); t.Commit(); return(id); } catch (Exception) { t.Rollback(); throw; } } } }
public void CompareEvent(SavingEvent originalEvent, SavingEvent retrievedEvent) { Assert.AreEqual(originalEvent.Amount, retrievedEvent.Amount); Assert.AreEqual(originalEvent.User.Id, retrievedEvent.User.Id); Assert.AreEqual(originalEvent.Code, retrievedEvent.Code); Assert.AreEqual(originalEvent.Date, retrievedEvent.Date); Assert.AreEqual(originalEvent.Cancelable, retrievedEvent.Cancelable); Assert.AreEqual(originalEvent.IsFired, retrievedEvent.IsFired); if (originalEvent is SavingTransferEvent) { Assert.AreEqual(((SavingTransferEvent)originalEvent).RelatedContractCode, ((SavingTransferEvent)retrievedEvent).RelatedContractCode); } if (originalEvent is ISavingsFees) { if (((ISavingsFees)originalEvent).Fee.HasValue || ((ISavingsFees)retrievedEvent).Fee.HasValue) { Assert.AreEqual(((ISavingsFees)originalEvent).Fee, ((ISavingsFees)retrievedEvent).Fee); } } }