diff --git a/.vscode/launch.json b/.vscode/launch.json index 8ad5b14a..d1ace0ad 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -48,7 +48,7 @@ "AYANOVA_DATA_PATH": "c:\\temp\\ravendata", "AYANOVA_USE_URLS": "http://*:7575;", //"AYANOVA_PERMANENTLY_ERASE_DATABASE":"true", - "AYANOVA_SERVER_TEST_MODE": "true", + "AYANOVA_SERVER_TEST_MODE": "false", "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-8", //"AYANOVA_REPORT_RENDERING_TIMEOUT":"1", "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small", diff --git a/server/AyaNova/biz/CustomerServiceRequestBiz.cs b/server/AyaNova/biz/CustomerServiceRequestBiz.cs index c062fc1c..38ac746d 100644 --- a/server/AyaNova/biz/CustomerServiceRequestBiz.cs +++ b/server/AyaNova/biz/CustomerServiceRequestBiz.cs @@ -317,7 +317,7 @@ namespace AyaNova.Biz } vc.Clear(); return ReportData; - } + } private VizCache vc = new VizCache(); //populate viz fields from provided object @@ -512,7 +512,7 @@ namespace AyaNova.Biz } //CSR ACCEPTED - if (!WasAccepted && o.Status == CustomerServiceRequestStatus.Accepted)//TAGS NOT RELEVANT + if (!WasAccepted && o.Status == CustomerServiceRequestStatus.Accepted)//TAGS NOT RELEVANT because customer can't select them { var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.CSRAccepted).ToListAsync(); string SourceName = string.Empty; @@ -539,7 +539,7 @@ namespace AyaNova.Biz } //CSR REJECTED - if (!WasDeclined && o.Status == CustomerServiceRequestStatus.Declined)//TAGS NOT RELEVANT + if (!WasDeclined && o.Status == CustomerServiceRequestStatus.Declined)//TAGS NOT RELEVANT customer can't select them for this { var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.CSRRejected).ToListAsync(); string SourceName = string.Empty; @@ -565,6 +565,74 @@ namespace AyaNova.Biz } } + + if (!WasAccepted && o.Status == CustomerServiceRequestStatus.Accepted) + { + //PROXY CUSTOMER NOTIFICATION SUBSCRIPTION HANDLING + //CSR ACCEPTED + //can this customer even be delivered to? + var custInfo = await ct.Customer.AsNoTracking().Where(x => x.Id == o.CustomerId).Select(x => new { x.Active, x.Tags, x.EmailAddress }).FirstOrDefaultAsync(); + if (custInfo != null && custInfo.Active && !string.IsNullOrWhiteSpace(custInfo.EmailAddress)) + { + var subs = await ct.CustomerNotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.CSRAccepted).OrderBy(z => z.Id).ToListAsync(); + foreach (var sub in subs) + { + //Object tags must match and Customer tags must match + if (NotifyEventHelper.ObjectHasAllSubscriptionTags(o.Tags, sub.Tags) && NotifyEventHelper.ObjectHasAllSubscriptionTags(custInfo.Tags, sub.CustomerTags)) + { + CustomerNotifyEvent n = new CustomerNotifyEvent() + { + EventType = NotifyEventType.CSRAccepted, + CustomerId = o.CustomerId, + AyaType = AyaType.CustomerServiceRequest, + ObjectId = o.Id, + CustomerNotifySubscriptionId = sub.Id, + Name = o.Name + }; + await ct.CustomerNotifyEvent.AddAsync(n); + log.LogDebug($"Adding CustomerNotifyEvent: [{n.ToString()}]"); + await ct.SaveChangesAsync(); + break;//we have a match no need to process any further subs for this event + } + } + } + } + + if (!WasDeclined && o.Status == CustomerServiceRequestStatus.Declined) + { + //PROXY CUSTOMER NOTIFICATION SUBSCRIPTION HANDLING + //CSR DECLINED + //can this customer even be delivered to? + var custInfo = await ct.Customer.AsNoTracking().Where(x => x.Id == o.CustomerId).Select(x => new { x.Active, x.Tags, x.EmailAddress }).FirstOrDefaultAsync(); + if (custInfo != null && custInfo.Active && !string.IsNullOrWhiteSpace(custInfo.EmailAddress)) + { + var subs = await ct.CustomerNotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.CSRRejected).OrderBy(z => z.Id).ToListAsync(); + foreach (var sub in subs) + { + //Object tags must match and Customer tags must match + if (NotifyEventHelper.ObjectHasAllSubscriptionTags(o.Tags, sub.Tags) && NotifyEventHelper.ObjectHasAllSubscriptionTags(custInfo.Tags, sub.CustomerTags)) + { + + CustomerNotifyEvent n = new CustomerNotifyEvent() + { + EventType = NotifyEventType.CSRRejected, + CustomerId = o.CustomerId, + AyaType = AyaType.CustomerServiceRequest, + ObjectId = o.Id, + CustomerNotifySubscriptionId = sub.Id, + Name = o.Name + }; + await ct.CustomerNotifyEvent.AddAsync(n); + log.LogDebug($"Adding CustomerNotifyEvent: [{n.ToString()}]"); + await ct.SaveChangesAsync(); + break;//we have a match no need to process any further subs for this event + } + } + } + } + + + }//end of process notifications diff --git a/server/AyaNova/biz/QuoteBiz.cs b/server/AyaNova/biz/QuoteBiz.cs index 4595f1a0..b37c0787 100644 --- a/server/AyaNova/biz/QuoteBiz.cs +++ b/server/AyaNova/biz/QuoteBiz.cs @@ -1287,9 +1287,6 @@ namespace AyaNova.Biz //delivery is immediate so no need to remove old ones of this kind //note order by id ascending so that only the oldest notification "wins" as per docs in case of overlap to same customer var subs = await ct.CustomerNotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.QuoteStatusChange && z.IdValue == oProposed.QuoteStatusId).OrderBy(z => z.Id).ToListAsync(); - - - foreach (var sub in subs) { //Object tags must match and Customer tags must match @@ -1303,9 +1300,7 @@ namespace AyaNova.Biz AyaType = AyaType.Quote, ObjectId = oProposed.QuoteId, CustomerNotifySubscriptionId = sub.Id, - Name = QuoteInfo.Serial.ToString(), - Subject="TEST SUBJECT", - Message="TEST MESSAGE"//TODO: template processing here + Name = QuoteInfo.Serial.ToString() }; await ct.CustomerNotifyEvent.AddAsync(n); log.LogDebug($"Adding CustomerNotifyEvent: [{n.ToString()}]"); diff --git a/server/AyaNova/generator/CoreJobCustomerNotify.cs b/server/AyaNova/generator/CoreJobCustomerNotify.cs index 6c5ae458..9d3185d0 100644 --- a/server/AyaNova/generator/CoreJobCustomerNotify.cs +++ b/server/AyaNova/generator/CoreJobCustomerNotify.cs @@ -206,7 +206,15 @@ namespace AyaNova.Biz IMailer m = AyaNova.Util.ServiceProviderProvider.Mailer; //generate report if applicable - if (subscription.LinkReportId != null) + bool isReportableEvent = false; + switch (ne.EventType) + { + case NotifyEventType.QuoteStatusChange: + case NotifyEventType.WorkorderCompleted: + isReportableEvent = true; + break; + } + if (isReportableEvent && subscription.LinkReportId != null) { long subTranslationId = (long)subscription.TranslationId; @@ -269,7 +277,7 @@ namespace AyaNova.Biz } } else - await m.SendEmailAsync(deliveryAddress, ne.Subject, ne.Message, ServerGlobalOpsSettingsCache.Notify); + await m.SendEmailAsync(deliveryAddress, Subject, Body, ServerGlobalOpsSettingsCache.Notify); }