From 07e96f0a7041a51b2c58859fdae7894426e490e5 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 8 Mar 2022 01:23:16 +0000 Subject: [PATCH] --- server/AyaNova/biz/QuoteBiz.cs | 2 + .../generator/CoreJobCustomerNotify.cs | 73 ++++++++++++++++++- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/server/AyaNova/biz/QuoteBiz.cs b/server/AyaNova/biz/QuoteBiz.cs index 9cd1e955..4595f1a0 100644 --- a/server/AyaNova/biz/QuoteBiz.cs +++ b/server/AyaNova/biz/QuoteBiz.cs @@ -1288,6 +1288,8 @@ namespace AyaNova.Biz //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 diff --git a/server/AyaNova/generator/CoreJobCustomerNotify.cs b/server/AyaNova/generator/CoreJobCustomerNotify.cs index c3ee535f..92a7da04 100644 --- a/server/AyaNova/generator/CoreJobCustomerNotify.cs +++ b/server/AyaNova/generator/CoreJobCustomerNotify.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging; using AyaNova.Models; using AyaNova.Util; using Newtonsoft.Json.Linq; +using System.Text.RegularExpressions; namespace AyaNova.Biz { @@ -133,7 +134,7 @@ namespace AyaNova.Biz } else { - IMailer m = AyaNova.Util.ServiceProviderProvider.Mailer; + if (!ServerGlobalOpsSettingsCache.Notify.SmtpDeliveryActive) { await NotifyEventHelper.AddOpsProblemEvent($"Email notifications are set to OFF at server, unable to send Customer email notification for this event:{ne}"); @@ -143,8 +144,76 @@ namespace AyaNova.Biz } else { - //generate report if applicable + //BUILD SUBJECT AND BODY FROM TOKENS IF REQUIRED + var Subject = subscription.Subject; + var Body = subscription.Template; + + if (Subject.Contains("{{") || Body.Contains("{{")) + { + + //fetch the object with viz fields for easy templatization + switch (ne.AyaType) + { + case AyaType.Quote: + { + var qb = QuoteBiz.GetBiz(ct); + await qb.QuoteGetAsync(ne.ObjectId, true, false); + todo figure this regex out, make it a function + MatchCollection matches = Regex.Matches(Subject, @"\{{(.|\n)*?\}}", RegexOptions.IgnorePatternWhitespace + | RegexOptions.Compiled); + foreach (Match KeyMatch in matches) + { + switch (KeyMatch.Value) + { + case "[WorkorderService.Label.ServiceNumber]": + sTemplate = sTemplate.Replace(KeyMatch.Value, wonumber); + break; + case "[O.WorkorderStatus]": + if (statpick.Contains(WorkorderStatusID)) + sTemplate = sTemplate.Replace(KeyMatch.Value, statpick[WorkorderStatusID].Name); + else + sTemplate = sTemplate.Replace(KeyMatch.Value, ""); + break; + case "[Workorder.Label.CustomerContactName]": + sTemplate = sTemplate.Replace(KeyMatch.Value, contact); + break; + case "[Workorder.Label.CustomerReferenceNumber]": + sTemplate = sTemplate.Replace(KeyMatch.Value, cref); + break; + case "[Region.Label.WBIUrl]": + sTemplate = sTemplate.Replace(KeyMatch.Value, r.WBIUrl); + break; + case "[Client.Label.Name]": + sTemplate = sTemplate.Replace(KeyMatch.Value, cl[0].LT_O_Client.Display); + break; + case "[ClientServiceRequest.Label.Details]": + sTemplate = sTemplate.Replace(KeyMatch.Value, csrdetails); + break; + case "[Workorder.Label.Summary]": + sTemplate = sTemplate.Replace(KeyMatch.Value, wosummary); + break; + case "[ClientServiceRequest.Label.Title]": + sTemplate = sTemplate.Replace(KeyMatch.Value, csrtitle); + break; + //case 1499 + case "[WorkorderQuote.Label.QuoteNumber]": + sTemplate = sTemplate.Replace(KeyMatch.Value, wonumber); + break; + } + } + } + break; + case AyaType.WorkOrder: + break; + } + + + } + + + IMailer m = AyaNova.Util.ServiceProviderProvider.Mailer; + //generate report if applicable if (subscription.LinkReportId != null) { long subTranslationId = (long)subscription.TranslationId;