public void SendPurchaserEmail(int poid, string attachmentFilePath) { var po = OrderRepository.Single(poid); // Send Email to Purchaser, Approver and IOF Owner var client = ClientRepository.Single(po.ClientID); var approver = ClientRepository.GetApprover(po); double totalWarningMin = GetTotalWarningMinimum(); int over = Convert.ToInt32(totalWarningMin / 1000); string subject = $"IOF #{po.POID}: Approved" + (po.TotalPrice > totalWarningMin ? $" (over ${over}k)" : string.Empty) + (po.Attention.GetValueOrDefault() ? " (URGENT)" : string.Empty); string body = $"IOF #{po.POID} has been approved. Please see the attachment."; var args = CreateArgs("IOF.Impl.EmailService.SendPurchaserEmail", subject, body, approver.Email, GetPurchasingAgentEmails(), client.Email); args.Bcc = GetBccEmails(new[] { "*****@*****.**" }); args.Attachments = new[] { attachmentFilePath }; Provider.Mail.SendMessage(args); }
public string CreatePDF(int poid) { var po = OrderRepository.Single(poid); if (po == null) { throw new ItemNotFoundException <Ordering.PurchaseOrder>(x => x.POID, poid); } var basePath = ConfigurationManager.AppSettings["PdfBasePath"]; if (string.IsNullOrEmpty(basePath)) { throw new InvalidOperationException("Missing required appSetting: PdfBasePath"); } if (!Directory.Exists(basePath)) { throw new InvalidOperationException($"Directory not found: {basePath}"); } string tempPath = Path.Combine(basePath, "temp"); if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } string imagePath = Path.Combine(basePath, "images"); if (!Directory.Exists(imagePath)) { Directory.CreateDirectory(imagePath); } string template = Path.Combine(basePath, "IOFTemplate.pdf"); if (!File.Exists(template)) { throw new InvalidOperationException($"Missing template file: {template}"); } string templatePage2 = Path.Combine(basePath, "IOFTemplatePage2.pdf"); if (!File.Exists(templatePage2)) { throw new InvalidOperationException($"Missing template page 2 file: {templatePage2}"); } var c = ClientRepository.Single(po.ClientID); string pdfName = $"IOF_{po.POID}_{c.LName}{c.FName}_{DateTime.Now:yyMmddHHmmss}.pdf"; string pdfPath = Path.Combine(tempPath, pdfName); if (File.Exists(pdfPath)) { File.Delete(pdfPath); } using (var fs = new FileStream(pdfPath, FileMode.Create, FileAccess.Write)) { PdfReader pr = new PdfReader(template); PdfStamper ps = new PdfStamper(pr, fs); AcroFields af = ps.AcroFields; var info = pr.Info; info["Title"] = $"IOF #{po.POID} : {po.VendorName} : {c.FName} {c.LName}"; ps.MoreInfo = info; using (var ms = new MemoryStream()) { var xmp = new XmpWriter(ms, info); ps.XmpMetadata = ms.ToArray(); xmp.Close(); } af.SetField("poID", $"IOF # {po.POID}"); af.SetField("RequestedBy", c.DisplayName); af.SetField("Email", c.Email); af.SetField("Phone", c.Phone); var approver = ClientRepository.GetApprover(po); if (po.IsApproved()) { string imageFile = Path.Combine(imagePath, $"{approver.LName}.tif"); if (File.Exists(imageFile)) { var sig = Image.GetInstance(imageFile); ps.GetOverContent(1).AddImage(sig, 50, 0, 0, 24, 231, 539); } af.SetField("ApprovedBy", approver.DisplayName); } // fill in shipping info af.SetField("Date", po.CreatedDate.ToShortDateString()); af.SetField("DateNeeded", po.NeededDate.ToShortDateString()); af.SetField("Advisor", approver.DisplayName); af.SetField("Shipping", po.ShippingMethodName); var acct = AccountRepository.Single(po.ClientID, po.AccountID); if (acct == null) { af.SetField("Account", string.Empty); } else { af.SetField("Account", acct.ShortCode); } if (po.Oversized) { af.SetField("chkOverSized", "Yes"); } af.SetField("PurchaseTotal", po.TotalPrice.ToString("#,##0.00")); // fill in vendor info var vendor = VendorRepository.Single(po.VendorID); af.SetField("Vendor", vendor.VendorName); af.SetField("VendAddr1", vendor.Address1); af.SetField("VendAddr2", vendor.Address2); af.SetField("VendAddr3", vendor.Address3); af.SetField("Contact", vendor.Contact); af.SetField("ContactPhone", vendor.Phone); af.SetField("ContactFax", vendor.Fax); af.SetField("VendorWWW", vendor.URL); af.SetField("ContactEmail", vendor.Email); // in the 'office use only' box af.SetField("VendorOffice", vendor.VendorName); // notes var items = GetItems(po.POID).ToList(); if (!string.IsNullOrEmpty(po.Notes)) { items.Add(new PdfItem() { Description = po.Notes, IsNotes = true }); } // items int x = 0; float y = 410F; //page 1 starting position int pageNumber = 1; float width = pr.GetPageSize(pageNumber).Width - x; //DrawLine(ps.GetOverContent(page), 280) foreach (var item in items.OrderByDescending(i => i.PODID)) { var tbl = CreateTable(item, width); if (pageNumber < 2) { if (y + tbl.TotalHeight < 280) { pageNumber = 2; y = 580; //page 2 starting position ps.InsertPage(pageNumber, pr.GetPageSize(1)); var p2reader = new PdfReader(templatePage2); ps.ReplacePage(p2reader, 1, 2); ps.Writer.FreeReader(p2reader); p2reader.Close(); //DrawLine(ps.GetOverContent(page), 60) } } else { if (y + tbl.TotalHeight < 60) { pageNumber += 1; y = 580; //page n starting position ps.InsertPage(pageNumber, pr.GetPageSize(1)); var p2reader = new PdfReader(templatePage2); ps.ReplacePage(p2reader, 1, pageNumber); ps.Writer.FreeReader(p2reader); p2reader.Close(); //DrawLine(ps.GetOverContent(page), 60) } } var ct = new ColumnText(ps.GetOverContent(pageNumber)) { Alignment = Element.ALIGN_LEFT }; ct.SetSimpleColumn(x, y, width, y + 100); ct.AddElement(tbl); ct.Go(); y -= tbl.TotalHeight; } AddPageNumberFooter(ps, pr.NumberOfPages, width); ps.FormFlattening = true; ps.Close(); } return(pdfPath); }
private string GetApproverEmail(Order order) { var approver = ClientRepository.GetApprover(order); return(approver.Email); }
public void SendApproverEmail(int poid) { var order = OrderRepository.Single(poid); var acct = AccountRepository.Single(order.ClientID, order.AccountID); if (acct == null) { throw new Exception("The IOF must have an account before sending for approval."); } var client = ClientRepository.Single(order.ClientID); var approver = ClientRepository.GetApprover(order); StringBuilder sb = new StringBuilder(); sb.AppendLine("<div style=\"margin-top: 20px;\">"); sb.AppendLine($"<h3>Approver: {approver.DisplayName}</h3>"); sb.AppendLine("<hr/>"); string style1 = "text-align: right; padding: 6px 6px 6px 24px;"; string style2 = "padding: 6px 6px 6px 12px"; sb.AppendLine("<div style=\"padding: 10px;\">"); sb.AppendLine("<div style=\"padding-bottom: 10px;\"><b>IOF Info</b></div>"); sb.AppendLine("<table style=\"border-collapse: collapse;\">"); sb.AppendLine($"<tr><td style=\"{style1}\"><b>IOF #</b></td><td style=\"{style2}\">{order.POID}</td></tr>"); sb.AppendLine($"<tr><td style=\"{style1}\"><b>Vendor</b></td><td style=\"{style2}\">{order.VendorName}</td></tr>"); sb.AppendLine($"<tr><td style=\"{style1}\"><b>Account</b></td><td style=\"{style2}\">{acct.AccountDisplayName}</td></tr>"); sb.AppendLine($"<tr><td style=\"{style1}\"><b>Date Needed</b></td><td style=\"{style2}\">{order.NeededDate:M/d/yyyy}</td></tr>"); sb.AppendLine($"<tr><td style=\"{style1}\"><b>Notes</b></td><td style=\"{style2};\">{order.Notes}</td></tr>"); sb.AppendLine("</table>"); sb.AppendLine("</div>"); style1 = "border: solid 1px #444444; padding: 6px; background-color: #5078b3; color: #ffffff;"; sb.AppendLine("<hr/>"); sb.AppendLine("<div style=\"padding: 10px;\">"); sb.AppendLine("<div style=\"padding-bottom: 10px;\"><b>IOF Items</b></div>"); sb.AppendLine($"<table style=\"border-collapse: collapse; width: 100%;\">"); sb.AppendLine("<tr>"); sb.AppendLine($"<th style=\"{style1} width: 150px; text-align: left;\">Part #</th>"); sb.AppendLine($"<th style=\"{style1} text-align: left;\">Description</th>"); sb.AppendLine($"<th style=\"{style1} width: 150px; text-align: left;\">Category</th>"); sb.AppendLine($"<th style=\"{style1} width: 60px; text-align: right;\">Qty</th>"); sb.AppendLine($"<th style=\"{style1} width: 90px; text-align: right;\">Unit Price</th>"); sb.AppendLine($"<th style=\"{style1} width: 90px; text-align: right;\">Ext Price</th>"); sb.AppendLine("</tr>"); style1 = "border: solid 1px #808080; padding: 6px;"; double total = 0; foreach (var pod in DetailRepository.GetOrderDetails(order.POID)) { sb.AppendLine("<tr>"); sb.AppendLine($"<td style=\"{style1}\">{pod.PartNum}</td>"); sb.AppendLine($"<td style=\"{style1}\">{pod.Description}</td>"); sb.AppendLine($"<td style=\"{style1}\">{pod.CategoryNumber} - {pod.CategoryName}</td>"); sb.AppendLine($"<td style=\"{style1} text-align: right;\">{$"{pod.Quantity} {pod.Unit}".Trim()}</td>"); sb.AppendLine($"<td style=\"{style1} text-align: right;\">{pod.UnitPrice:C}</td>"); sb.AppendLine($"<td style=\"{style1} text-align: right;\">{pod.ExtPrice:C}</td>"); sb.AppendLine("</tr>"); total += pod.ExtPrice; } style1 = "border: solid 1px #808080; padding: 6px; background-color: #ccff99;"; sb.AppendLine("<tr>"); sb.AppendLine($"<td style=\"{style1}\"> </td>"); sb.AppendLine($"<td style=\"{style1}\"> </td>"); sb.AppendLine($"<td style=\"{style1}\"> </td>"); sb.AppendLine($"<td style=\"{style1}\"> </td>"); sb.AppendLine($"<td style=\"{style1} text-align: right;\"><b>Total:</b></td>"); sb.AppendLine($"<td style=\"{style1} text-align: right;\"><b>{total:C}</b></td>"); sb.AppendLine("</tr>"); sb.AppendLine("</table>"); sb.AppendLine("</div>"); sb.AppendLine("<hr/>"); sb.AppendLine("<div style=\"padding: 10px;\">"); sb.AppendLine("<div style=\"padding-bottom: 10px;\"><b>Attachments</b></div>"); var attachments = AttachmentService.GetAttachments(order.POID); if (attachments.Count() > 0) { sb.AppendLine("<ol>"); foreach (var a in attachments) { sb.AppendLine($"<li><a href=\"{a.Url}\">{a.FileName}</a></li>"); } sb.AppendLine("</ol>"); } else { sb.AppendLine("<div><i style=\"color: #808080;\">No attachments found.</i></div>"); } sb.AppendLine("</div>"); sb.AppendLine("<hr/>"); bool useApproveOrReject = GetUseApproveOrRejectSetting(); sb.AppendLine("<div style=\"padding: 10px;\">"); if (useApproveOrReject) { sb.AppendLine($"<div style=\"margin-bottom: 20px;\"><b><a href=\"{GetApproveOrRejectUrl(order)}\">Approve or Reject this IOF</a></b></div>"); } else { sb.AppendLine($"<div style=\"margin-bottom: 20px;\"><b><a href=\"{GetApproveUrl(order)}\">Approve this IOF</a></b></div>"); sb.AppendLine($"<div style=\"margin-bottom: 20px;\"><b><a href=\"{GetRejectUrl(order)}\">Reject this IOF</a></b></div>"); } sb.AppendLine("</div>"); sb.AppendLine("</div>"); var args = CreateArgs("IOF.Impl.EmailService.SendApproverEmail", $"IOF #{order.POID}: Request By {client.DisplayName}", sb.ToString(), approver.Email); Provider.Mail.SendMessage(args); }