From 9a11e4bfb42a3cb0d1451c1904e087b346db3444 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 9 Mar 2021 00:01:09 +0000 Subject: [PATCH] --- server/AyaNova/biz/CustomerBiz.cs | 48 +++++++++++++++++++++++++ server/AyaNova/biz/HeadOfficeBiz.cs | 50 +++++++++++++++++++++++++- server/AyaNova/biz/UnitBiz.cs | 55 ++++++++++++++++++++--------- server/AyaNova/biz/WorkOrderBiz.cs | 2 ++ 4 files changed, 137 insertions(+), 18 deletions(-) diff --git a/server/AyaNova/biz/CustomerBiz.cs b/server/AyaNova/biz/CustomerBiz.cs index ce6daba5..af164ae9 100644 --- a/server/AyaNova/biz/CustomerBiz.cs +++ b/server/AyaNova/biz/CustomerBiz.cs @@ -531,6 +531,54 @@ namespace AyaNova.Biz await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct); //SPECIFIC EVENTS FOR THIS OBJECT + Customer o = (Customer)proposedObj; + + //## DELETED EVENTS + //any event added below needs to be removed, so + //just blanket remove any event for this object of eventtype that would be added below here + //do it regardless any time there's an update and then + //let this code below handle the refreshing addition that could have changes + await NotifyEventHelper.ClearPriorEventsForObject(ct, AyaType.Customer, o.Id, NotifyEventType.ContractExpiring); + + + //## CREATED / MODIFIED EVENTS + if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified) + { + + //# CONTRACT EXPIRY + { + if (o.ContractId != null && o.ContractExpires != null) + { + var ContractExpirydate = (DateTime)o.ContractExpires; + //notify users about contract expiry (time delayed) + var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ContractExpiring).ToListAsync(); + foreach (var sub in subs) + { + //not for inactive users + if (!await UserBiz.UserIsActive(sub.UserId)) continue; + + //Tag match? (will be true if no sub tags so always safe to call this) + if (NotifyEventHelper.TagsMatch(o.Tags, sub.Tags)) + { + NotifyEvent n = new NotifyEvent() + { + EventType = NotifyEventType.ContractExpiring, + UserId = sub.UserId, + AyaType = o.AyaType, + ObjectId = o.Id, + NotifySubscriptionId = sub.Id, + Name = o.Name, + EventDate = ContractExpirydate + }; + await ct.NotifyEvent.AddAsync(n); + log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]"); + await ct.SaveChangesAsync(); + } + } + } + }//Contract expiry event + + } }//end of process notifications diff --git a/server/AyaNova/biz/HeadOfficeBiz.cs b/server/AyaNova/biz/HeadOfficeBiz.cs index 83d7567d..43d0fbd8 100644 --- a/server/AyaNova/biz/HeadOfficeBiz.cs +++ b/server/AyaNova/biz/HeadOfficeBiz.cs @@ -489,7 +489,55 @@ namespace AyaNova.Biz //STANDARD EVENTS FOR ALL OBJECTS await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct); - //SPECIFIC EVENTS FOR THIS OBJECT + //SPECIFIC EVENTS FOR THIS OBJECT + HeadOffice o = (HeadOffice)proposedObj; + + //## DELETED EVENTS + //any event added below needs to be removed, so + //just blanket remove any event for this object of eventtype that would be added below here + //do it regardless any time there's an update and then + //let this code below handle the refreshing addition that could have changes + await NotifyEventHelper.ClearPriorEventsForObject(ct, AyaType.HeadOffice, o.Id, NotifyEventType.ContractExpiring); + + + //## CREATED / MODIFIED EVENTS + if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified) + { + + //# CONTRACT EXPIRY + { + if (o.ContractId != null && o.ContractExpires != null) + { + var ContractExpirydate = (DateTime)o.ContractExpires; + //notify users about contract expiry (time delayed) + var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ContractExpiring).ToListAsync(); + foreach (var sub in subs) + { + //not for inactive users + if (!await UserBiz.UserIsActive(sub.UserId)) continue; + + //Tag match? (will be true if no sub tags so always safe to call this) + if (NotifyEventHelper.TagsMatch(o.Tags, sub.Tags)) + { + NotifyEvent n = new NotifyEvent() + { + EventType = NotifyEventType.ContractExpiring, + UserId = sub.UserId, + AyaType = o.AyaType, + ObjectId = o.Id, + NotifySubscriptionId = sub.Id, + Name = o.Name, + EventDate = ContractExpirydate + }; + await ct.NotifyEvent.AddAsync(n); + log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]"); + await ct.SaveChangesAsync(); + } + } + } + }//Contract expiry event + + } }//end of process notifications diff --git a/server/AyaNova/biz/UnitBiz.cs b/server/AyaNova/biz/UnitBiz.cs index 0968f1d5..c341f33a 100644 --- a/server/AyaNova/biz/UnitBiz.cs +++ b/server/AyaNova/biz/UnitBiz.cs @@ -256,7 +256,7 @@ namespace AyaNova.Biz AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Serial", "no two units can have the same serial and same unitmodel"); } } - + if (proposedObj.ContractId != null) if (proposedObj.ContractExpires == null) AddError(ApiErrorCode.VALIDATION_REQUIRED, "ContractExpires"); @@ -484,30 +484,22 @@ namespace AyaNova.Biz await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct); //SPECIFIC EVENTS FOR THIS OBJECT - /* - UnitWarrantyExpiry = 25,//* Unit object created, advance notice can be used, tag conditional + Unit o = (Unit)proposedObj; - - */ //## DELETED EVENTS - //TODO: there are no specific deleted events - //but any event added below needs to be removed, so + //any event added below needs to be removed, so //just blanket remove any event for this object of eventtype that would be added below here //do it regardless any time there's an update and then //let this code below handle the refreshing addition that could have changes + await NotifyEventHelper.ClearPriorEventsForObject(ct, AyaType.Unit, o.Id, NotifyEventType.UnitWarrantyExpiry); + await NotifyEventHelper.ClearPriorEventsForObject(ct, AyaType.Unit, o.Id, NotifyEventType.ContractExpiring); //## CREATED / MODIFIED EVENTS if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified) { - Unit o = (Unit)proposedObj; - //# UNIT WARRANTY EXPIRY { - //first remove any existing, potentially stale notifyevents for this exact object and notifyeventtype - //NOTE: this is only required for notify events that have an AgeValue where the eventdate is relevant - await NotifyEventHelper.ClearPriorEventsForObject(ct, AyaType.Unit, o.Id, NotifyEventType.UnitWarrantyExpiry); - //does the unit even have a model or warranty? int effectiveWarrantyMonths = 0; //unit has own warranty terms @@ -560,6 +552,39 @@ namespace AyaNova.Biz } }//warranty expiry event + //# CONTRACT EXPIRY + { + if (o.ContractId != null && o.ContractExpires != null) + { + var ContractExpirydate = (DateTime)o.ContractExpires; + //notify users about contract expiry (time delayed) + var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ContractExpiring).ToListAsync(); + foreach (var sub in subs) + { + //not for inactive users + if (!await UserBiz.UserIsActive(sub.UserId)) continue; + + //Tag match? (will be true if no sub tags so always safe to call this) + if (NotifyEventHelper.TagsMatch(o.Tags, sub.Tags)) + { + NotifyEvent n = new NotifyEvent() + { + EventType = NotifyEventType.ContractExpiring, + UserId = sub.UserId, + AyaType = o.AyaType, + ObjectId = o.Id, + NotifySubscriptionId = sub.Id, + Name = o.Serial, + EventDate = ContractExpirydate + }; + await ct.NotifyEvent.AddAsync(n); + log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]"); + await ct.SaveChangesAsync(); + } + } + } + }//Contract expiry event + //#todo: METER READING EVENT //MIGRATE_OUTSTANDING need meter reading object to complete unit notification for UnitMeterReadingMultipleExceeded @@ -570,11 +595,7 @@ namespace AyaNova.Biz //then check if unit is still metered etc etc and do the rest once the unit meter reading is coded - - //} - - } diff --git a/server/AyaNova/biz/WorkOrderBiz.cs b/server/AyaNova/biz/WorkOrderBiz.cs index bdaa5ac1..b37b2ac2 100644 --- a/server/AyaNova/biz/WorkOrderBiz.cs +++ b/server/AyaNova/biz/WorkOrderBiz.cs @@ -2638,6 +2638,8 @@ namespace AyaNova.Biz //SPECIFIC EVENTS FOR THIS OBJECT + //todo: contract response time notification + }//end of process notifications