This commit is contained in:
2022-03-08 01:51:29 +00:00
parent 07e96f0a70
commit c6ee47bb62

View File

@@ -151,57 +151,21 @@ namespace AyaNova.Biz
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)
var qt = await ct.Quote.AsNoTracking().FirstOrDefaultAsync(z => z.Id == ne.ObjectId);
if (qt == null)
{
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;
}
//maybe deleted, this can't proceed
throw new ApplicationException($"Unable to make delivery for customer notify event as Quote {ne.Name} was not found during delivery, deleted?");
}
var CustomerName = await ct.Customer.AsNoTracking().Where(x => x.Id == qt.CustomerId).Select(x => x.Name).FirstOrDefaultAsync();
Subject = SetQuoteTokens(Subject, qt, CustomerName);
Body = SetQuoteTokens(Body, qt, CustomerName);
}
break;
case AyaType.WorkOrder:
@@ -262,7 +226,7 @@ namespace AyaNova.Biz
var path = (string)lastLogJ["reportfilename"];
var FilePath = FileUtil.GetFullPathForTemporaryFile(path);
var FileName = FileUtil.StringToSafeFileName(await TranslationBiz.GetTranslationStaticAsync(ne.AyaType.ToString(), subTranslationId, ct) + $"-{ne.Name}.pdf").ToLowerInvariant();
await m.SendEmailAsync(deliveryAddress, ne.Subject, ne.Message, ServerGlobalOpsSettingsCache.Notify, FilePath, FileName);
await m.SendEmailAsync(deliveryAddress, Subject, Body, ServerGlobalOpsSettingsCache.Notify, FilePath, FileName);
break;
}
case JobStatus.Failed:
@@ -300,6 +264,39 @@ namespace AyaNova.Biz
await ct.SaveChangesAsync();
}
}
private static string SetQuoteTokens(string TheField, Quote qt, string CustomerName)
{
MatchCollection matches = Regex.Matches(TheField, @"\{{(.|\n)*?\}}", RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
//{{.*?}}
foreach (Match KeyMatch in matches)
{
switch (KeyMatch.Value)
{
case "{{Customer}}":
TheField = TheField.Replace(KeyMatch.Value, CustomerName);
break;
case "{{QuoteIntroduction}}":
TheField = TheField.Replace(KeyMatch.Value, qt.Introduction);
break;
case "{{WorkOrderCustomerContactName}}":
TheField = TheField.Replace(KeyMatch.Value, qt.CustomerContactName);
break;
case "{{WorkOrderCustomerReferenceNumber}}":
TheField = TheField.Replace(KeyMatch.Value, qt.CustomerReferenceNumber);
break;
case "{{WorkOrderSummary}}":
TheField = TheField.Replace(KeyMatch.Value, qt.Notes);
break;
case "{{QuoteSerialNumber}}":
TheField = TheField.Replace(KeyMatch.Value, qt.Serial.ToString());
break;
}
}
return TheField;
}
//===