diff --git a/docs/8.0/ayanova/docs/home-notify-subscriptions.md b/docs/8.0/ayanova/docs/home-notify-subscriptions.md index 2e11a704..bef76d66 100644 --- a/docs/8.0/ayanova/docs/home-notify-subscriptions.md +++ b/docs/8.0/ayanova/docs/home-notify-subscriptions.md @@ -87,13 +87,13 @@ There are no settings adjustable for in app General notifications, however Users | ScheduledOnWorkorder | User is scheduled on (added to) a Work order | | ScheduledOnWorkorderImminent | Scheduled date and time reached for workorder which User is scheduled | | WorkorderCompletedStatusOverdue | Workorder not set to a "Completed" type Status before the selected duration from created date | -| WorkorderCompleted | Service work order is set to any status that is flagged as a "Completed" type of status. (Customer and User notification) | +| WorkorderCompleted | Service work order is set to any status that is flagged as a "Completed" type of status. (Customer / HeadOffice or staff User notification) | | OutsideServiceOverdue | An item sent for 3rd party service is overdue from projected repair time frame | | OutsideServiceReceived | An item sent for 3rd party service has been received back | | PartRequestReceived | An out of stock part requested via a Workorder has been received | | NotifyHealthCheck | Automatic daily "ping" notification to confirm notification and Generator system is active at server | | BackupStatus | Result of last Backup operation at server | -| CustomerServiceImminent | Scheduled service date / time is about to be reached. Intended for Customer type User | +| CustomerServiceReminder | Scheduled service date / time is about to be reached. (Customer or HeadOffice type users only) | | WorkorderTotalExceedsThreshold | The balance of a Work order has exceeded a threshold (the "Andy") | | WorkorderStatusAge | A Workorder has been sitting at the selected status for longer than the selected time frame | | UnitWarrantyExpiry | A Unit's warranty expiration date is reached | @@ -102,6 +102,6 @@ There are no settings adjustable for in app General notifications, however Users | ServerOperationsProblem | Any timely and serious issue related to internal AyaNova Server operations requiring attention | | QuoteStatusAge | A Quote has been sitting at the selected status for longer than the selected time frame | | CopyOfCustomerNotification | Copy of any notification sent to Customer for AyaNova User. Filterable by Customer Tag | -| WorkorderCreatedForCustomer | Customer notification sent when a service type work order is created for them | +| WorkorderCreatedForCustomer | Customer notification sent when a service type work order is created for them (or if HeadOffice Contact user, one of their Customers) | diff --git a/server/AyaNova/biz/WorkOrderBiz.cs b/server/AyaNova/biz/WorkOrderBiz.cs index f8977267..c996eb7a 100644 --- a/server/AyaNova/biz/WorkOrderBiz.cs +++ b/server/AyaNova/biz/WorkOrderBiz.cs @@ -1083,7 +1083,7 @@ namespace AyaNova.Biz #endregion - #region CustomerServiceImminent + #region CustomerServiceImminent "Service Reminder" if (ayaEvent == AyaEvent.Created && oProposed.ServiceDate != null && oProposed.ServiceDate > DateTime.UtcNow) { @@ -1093,8 +1093,36 @@ namespace AyaNova.Biz //not for inactive users if (!await UserBiz.UserIsActive(sub.UserId)) continue; - //No tag match for this one + //Customer User? + var UserInfo = await ct.User.AsNoTracking().Where(x => x.Id == sub.UserId).Select(x => new { x.CustomerId, x.UserType, x.HeadOfficeId }).FirstOrDefaultAsync(); + if (UserInfo.UserType == UserType.Customer || UserInfo.UserType == UserType.HeadOffice) + { + //CUSTOMER USER + //Quick short circuit: if workorder doesn't have a customer id then it's not going to match no matter what + if (oProposed.CustomerId == 0) continue; + + var customerUserRights = await UserBiz.CustomerUserEffectiveRightsAsync(sub.UserId); + + //Are they allowed right now to use this type of notification? + if (!customerUserRights.NotifyWOCreated) continue; + + //is this their related work order? + if (UserInfo.CustomerId != oProposed.CustomerId) + { + //not the same customer but might be a head office user and this is one of their customers so check for that + if (UserInfo.HeadOfficeId == null) continue;//can't match any head office so no need to go further + + //see if workorder customer's head office is the same id as the user's headofficeid (note that a customer user with the same head office as a *different* customer workorder doesn't qualify) + var CustomerInfo = await ct.Customer.AsNoTracking().Where(x => x.Id == oProposed.CustomerId).Select(x => new { x.HeadOfficeId, x.BillHeadOffice }).FirstOrDefaultAsync(); + if (!CustomerInfo.BillHeadOffice) continue;//can't possibly match so no need to go further + if (UserInfo.HeadOfficeId != CustomerInfo.HeadOfficeId) continue; + } + } + else + continue;//only customers can subscribe to this particular notification + + //No tag match for this one NotifyEvent n = new NotifyEvent() { EventType = NotifyEventType.CustomerServiceImminent, @@ -1111,10 +1139,10 @@ namespace AyaNova.Biz } - }//CustomerServiceImminent + }//CustomerServiceImminent "Service Reminder" if (ayaEvent == AyaEvent.Modified) - {// CustomerServiceImminent + {// CustomerServiceImminent "Service Reminder" //differences requiring re-processing of notification if (oProposed.ServiceDate != oCurrent.ServiceDate) @@ -1131,6 +1159,35 @@ namespace AyaNova.Biz //not for inactive users if (!await UserBiz.UserIsActive(sub.UserId)) continue; + //Customer User? + var UserInfo = await ct.User.AsNoTracking().Where(x => x.Id == sub.UserId).Select(x => new { x.CustomerId, x.UserType, x.HeadOfficeId }).FirstOrDefaultAsync(); + if (UserInfo.UserType == UserType.Customer || UserInfo.UserType == UserType.HeadOffice) + { + //CUSTOMER USER + + //Quick short circuit: if workorder doesn't have a customer id then it's not going to match no matter what + if (oProposed.CustomerId == 0) continue; + + var customerUserRights = await UserBiz.CustomerUserEffectiveRightsAsync(sub.UserId); + + //Are they allowed right now to use this type of notification? + if (!customerUserRights.NotifyWOCreated) continue; + + //is this their related work order? + if (UserInfo.CustomerId != oProposed.CustomerId) + { + //not the same customer but might be a head office user and this is one of their customers so check for that + if (UserInfo.HeadOfficeId == null) continue;//can't match any head office so no need to go further + + //see if workorder customer's head office is the same id as the user's headofficeid (note that a customer user with the same head office as a *different* customer workorder doesn't qualify) + var CustomerInfo = await ct.Customer.AsNoTracking().Where(x => x.Id == oProposed.CustomerId).Select(x => new { x.HeadOfficeId, x.BillHeadOffice }).FirstOrDefaultAsync(); + if (!CustomerInfo.BillHeadOffice) continue;//can't possibly match so no need to go further + if (UserInfo.HeadOfficeId != CustomerInfo.HeadOfficeId) continue; + } + } + else + continue;//only customers can subscribe to this particular notification + //No tag match for this one NotifyEvent n = new NotifyEvent() { @@ -1150,7 +1207,7 @@ namespace AyaNova.Biz } } - }//CustomerServiceImminent + }//CustomerServiceImminent "Service Reminder" //# WorkorderCreatedForCustomer - Customer / headoffice notification if (oProposed.CustomerId != 0 && (ayaEvent == AyaEvent.Created