Skip to content

Instantly share code, notes, and snippets.

@hasokeric
Last active February 28, 2019 17:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hasokeric/8de176aa70df78650d40d5d7987727f2 to your computer and use it in GitHub Desktop.
Save hasokeric/8de176aa70df78650d40d5d7987727f2 to your computer and use it in GitHub Desktop.
Email Template Again - Pulling the Company Settings
// Email Notification
//
// 08/01/17 HK: Initial Implementation, since this is considered a temporary, lets keep it simple
//
// Initialize Actions
Func<string, string> GetCompanyAddressAction = (CompanyID) => {
var Company_Row =
(from sc in Db.SysCompany.With(LockHint.NoLock)
where sc.Company == CompanyID
select new { sc.EmailFromAddr, sc.EmailFromLabel }).FirstOrDefault();
if (Company_Row != null) {
return string.Format(@"""{0}"" <{1}>", Company_Row.EmailFromLabel.Trim(), Company_Row.EmailFromAddr.Trim());
}
return string.Empty;
};
Func<string, string> GetCostPerCode = (CostPerCode) => {
switch (CostPerCode)
{
case "E":
return @"/ 1";
case "C":
return @"/ 100";
case "M":
return @"/ 1000";
}
return string.Empty;
};
// Initialize Variables
string EmailTO = "haso.keric@xyz.com";
string EmailCC = "";
string EmailBCC = "";
string EmailSubject = "";
string EmailBody = "";
// Get POHeader
var ttPOHeader_Row = ttPOHeader.FirstOrDefault();
if (ttPOHeader_Row != null)
{
// Get Vendor ID and Name
var Vendor_Row =
(from v in Db.Vendor.With(LockHint.NoLock)
where
v.Company == ttPOHeader_Row.Company &&
v.VendorNum == ttPOHeader_Row.VendorNum
select new { v.Name, v.VendorID }
).FirstOrDefault();
// Set Subject
EmailSubject = "[ Alert ] PO #: " + ttPOHeader_Row.PONum + " was issued from Company " + ttPOHeader_Row.Company;
// Start Email Body
EmailBody += string.Format("Purchase Order <b>{0}</b> was issued from Company <b>{1}</b> on <b>{2}</b> to Vendor ID {3}, <b>{4}</b>, for:",
ttPOHeader_Row.PONum, ttPOHeader_Row.Company, ttPOHeader_Row.OrderDate.Value.ToShortDateString(), Vendor_Row.VendorID, Vendor_Row.Name );
EmailBody += "<BR><BR>";
EmailBody +=
@"<table width='100%' align='center' border='1' cellspacing='1' cellpadding='1' style='font-family: Arial; font-size: 10pt;' bordercolor='#CCCCCC'>"
+ "<tr>"
+ "<th>Line</th>"
+ "<th>Part</th>"
+ "<th>Our Qty</th>"
+ "<th>Vend Qty</th>"
+ "<th>Unit Cost</th>"
+ "</tr>";
// Get PO Lines
var ttPODtl_Rows =
from pod in Db.PODetail.With(LockHint.NoLock)
where
pod.Company == ttPOHeader_Row.Company &&
pod.PONUM == ttPOHeader_Row.PONum
select new { pod.POLine, pod.PartNum, pod.XOrderQty, pod.OrderQty, pod.IUM, pod.PUM, pod.LineDesc, pod.DocUnitCost, pod.CostPerCode };
foreach (var ttPODtl_Row in ttPODtl_Rows)
{
EmailBody +=
"<tr>"
+ @"<td align='center'>" + ttPODtl_Row.POLine + "</td>"
+ @"<td align='center'><b>" + ttPODtl_Row.PartNum + @"</b><br><span style='font-size: 8pt'>" + ttPODtl_Row.LineDesc + "</span></td>"
+ @"<td align='center'>" + Math.Round(ttPODtl_Row.XOrderQty, 2) + " " + ttPODtl_Row.IUM + "</td>"
+ @"<td align='center'>" + Math.Round(ttPODtl_Row.OrderQty, 2) + " " + ttPODtl_Row.PUM + "</td>"
+ @"<td align='center'>" + Math.Round(ttPODtl_Row.DocUnitCost, 2) + " " + GetCostPerCode(ttPODtl_Row.CostPerCode) + "</td>"
+ "</tr>";
}
EmailBody += "</table>";
// Send Email
var mailer = this.GetMailer(async:true);
var message = new Ice.Mail.SmtpMail();
message.SetFrom( GetCompanyAddressAction(ttPOHeader_Row.Company) );
message.SetTo(EmailTO);
message.SetCC(EmailCC);
message.SetBcc(EmailBCC);
message.SetSubject(EmailSubject);
message.SetBody(EmailBody);
message.IsBodyHtml = true;
mailer.Send(message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment