This commit is contained in:
@@ -1478,16 +1478,10 @@ namespace AyaNova.Biz
|
||||
}//"The Andy" for Dynamic Dental corp. notification
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//# WorkorderCompleted - Customer AND User but customer only notifies if it's their workorder
|
||||
{
|
||||
if (wos.Completed)
|
||||
{
|
||||
|
||||
//look for potential subscribers
|
||||
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.WorkorderCompleted).ToListAsync();
|
||||
foreach (var sub in subs)
|
||||
@@ -1495,14 +1489,15 @@ namespace AyaNova.Biz
|
||||
//not for inactive users
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||
|
||||
//Ok, is this a customer user and if so do they have rights to subscribe to this and if so is it their related workorder
|
||||
//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 (WorkorderInfo.CustomerId == 0) continue;
|
||||
|
||||
//CUSTOMER USER
|
||||
var customerUserRights = await UserBiz.CustomerUserEffectiveRightsAsync(sub.UserId);
|
||||
|
||||
//Are they allowed right now to use this type of notification?
|
||||
@@ -1511,65 +1506,39 @@ namespace AyaNova.Biz
|
||||
//is this their related work order?
|
||||
if (UserInfo.CustomerId != WorkorderInfo.CustomerId)
|
||||
{
|
||||
//not the same customer but might be the same head office which is kosher here
|
||||
if (UserInfo.HeadOfficeId == null) continue;//can't match so no need to go further
|
||||
//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 == WorkorderInfo.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;
|
||||
}
|
||||
|
||||
//Ok, we're here so it must be a related workorder so notify away
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//INSIDE USER
|
||||
|
||||
//Tag match? (will be true if no sub tags so always safe to call this)
|
||||
//check early to avoid cost of fetching and calculating total if unnecessary
|
||||
if (!NotifyEventHelper.ObjectHasAllSubscriptionTags(WorkorderInfo.Tags, sub.Tags)) continue;
|
||||
|
||||
//get the total because we have at least one subscriber and matching tags
|
||||
if (haveTotal == false)
|
||||
{
|
||||
GrandTotal = await WorkorderGrandTotalAsync(oProposed.WorkOrderId, ct);
|
||||
haveTotal = true;
|
||||
|
||||
//Note: not a time delayed notification, however user could be flipping states quickly triggering multiple notifications that are in queue temporarily
|
||||
//so this will prevent that:
|
||||
await NotifyEventHelper.ClearPriorEventsForObject(ct, AyaType.WorkOrder, oProposed.WorkOrderId, NotifyEventType.WorkorderTotalExceedsThreshold);
|
||||
}
|
||||
//Ok, we're here because there is a subscriber who is active and tags match so only check left is total against decvalue
|
||||
if (sub.DecValue < GrandTotal)
|
||||
{
|
||||
//notification is a go
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
EventType = NotifyEventType.WorkorderTotalExceedsThreshold,
|
||||
UserId = sub.UserId,
|
||||
AyaType = AyaType.WorkOrder,
|
||||
ObjectId = oProposed.WorkOrderId,
|
||||
NotifySubscriptionId = sub.Id,
|
||||
Name = $"{WorkorderInfo.Serial.ToString()}",
|
||||
DecValue = GrandTotal
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
//Ok, we're here so it must be ok to notify user
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
EventType = NotifyEventType.WorkorderCompleted,
|
||||
UserId = sub.UserId,
|
||||
AyaType = AyaType.WorkOrder,
|
||||
ObjectId = oProposed.WorkOrderId,
|
||||
NotifySubscriptionId = sub.Id,
|
||||
Name = $"{WorkorderInfo.Serial.ToString()}"
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}//WorkorderCompleted
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}//end of process notifications
|
||||
|
||||
Reference in New Issue
Block a user