Example #1
0
        public void SendCancelOrderEmail(int poid, string notes)
        {
            var order = OrderRepository.Single(poid);

            var sb = new StringBuilder();

            sb.AppendLine($"<b>This IOF was canceled on {DateTime.Now:MM/dd/yyyy hh:mm:ss tt} by {Context.CurrentUser.DisplayName}</b>");
            sb.AppendLine($"<br><br>Purchaser Notes:<table style=\"width: 100%;\"><tr><td style=\"border: solid 1px #ccc; background-color: #eee; padding: 5px;\">{notes}</td></tr></table>");

            var args = CreateArgs("IOF.Impl.EmailService.SendCancelOrderEmail", $"IOF #{order.POID} canceled by purchaser", GetBody(order, sb), GetClientEmail(order), GetApproverEmail(order), GetPurchaserEmail(order));

            Provider.Mail.SendMessage(args);
        }
Example #2
0
        public void SendDeleteAttachmentEmail(int poid, string attachmentFileName)
        {
            var order = OrderRepository.Single(poid);

            var sb = new StringBuilder();

            sb.AppendLine($"<b>The following attachment was deleted from your IOF on {DateTime.Now:MM/dd/yyyy hh:mm:ss tt} by {Context.CurrentUser.DisplayName}</b>");
            sb.AppendLine("<ol>");
            sb.AppendLine($"<li>{attachmentFileName}</li>");
            sb.AppendLine("</ol>");

            var args = CreateArgs("IOF.Impl.EmailService.SendDeleteAttachmentEmail", $"IOF #{poid} attachment deleted by purchaser", GetBody(order, sb), GetClientEmail(order), GetApproverEmail(order), GetPurchaserEmail(order));

            Provider.Mail.SendMessage(args);
        }
Example #3
0
        public void SendAddAttachmentsEmail(int poid, IEnumerable <Models.Attachment> attachments)
        {
            var order = OrderRepository.Single(poid);

            var sb = new StringBuilder();

            sb.AppendLine($"<b>The following attachments were added to your IOF on {DateTime.Now:MM/dd/yyyy hh:mm:ss tt} by {Context.CurrentUser.DisplayName}</b>");
            sb.AppendLine("<ol>");
            foreach (var att in attachments)
            {
                sb.AppendLine($"<li><a href=\"{att.Url}\">{att.FileName}</a></li>");
            }
            sb.AppendLine("</ol>");

            var args = CreateArgs("IOF.Impl.EmailService.SendAddAttachmentsEmail", $"IOF #{order.POID} attachment added by purchaser", GetBody(order, sb), GetClientEmail(order), GetApproverEmail(order), GetPurchaserEmail(order));

            Provider.Mail.SendMessage(args);
        }
Example #4
0
        public void SendItemModifiedEmail(int podid, IEnumerable <string> changes)
        {
            var detail = DetailRepository.Single(podid);
            var order  = OrderRepository.Single(detail.POID);

            StringBuilder body = new StringBuilder();

            body.AppendLine($"An item on IOF #{order.POID} was modified by <a href=\"mailto:{Context.CurrentUser.Email}\">{Context.CurrentUser.DisplayName}</a>");
            body.AppendLine($"<br><br><b>{detail.Description}:</b>");
            body.AppendLine("<ul>");
            foreach (var c in changes)
            {
                body.AppendLine($"<li>{c}</li>");
            }
            body.AppendLine("</ul>");

            var args = CreateArgs("IOF.Impl.EmailService.SendItemModifiedEmail", $"IOF #{order.POID} modified by purchaser", GetBody(order, body), GetClientEmail(order), GetApproverEmail(order), GetPurchaserEmail(order));

            Provider.Mail.SendMessage(args);
        }
Example #5
0
        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);
        }
Example #6
0
        public void SendRejectEmail(int poid, string reason)
        {
            var order  = OrderRepository.Single(poid);
            var client = ClientRepository.Single(order.ClientID);

            var name  = client.DisplayName;
            var email = client.Email;

            var sb = new StringBuilder();

            sb.AppendLine($"Hi {name}, <br><br>");
            sb.AppendLine($"Your IOF #{order.POID} has been rejected by {Context.CurrentUser.DisplayName}.<br><br>");

            if (!string.IsNullOrEmpty(reason))
            {
                sb.Append("<hr>");
                sb.AppendLine($"<b>Approver Notes:</b><p>{reason.Replace(((char)13).ToString(), string.Empty).Replace(((char)10).ToString(), "<br>")}</p>");
            }

            var args = CreateArgs("LNF.Impl.EmailService.SendRejectEmail", $"IOF #{order.POID}: Rejected", sb.ToString(), email);

            Provider.Mail.SendMessage(args);
        }
Example #7
0
        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);
        }
Example #8
0
        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}\">&nbsp;</td>");
            sb.AppendLine($"<td style=\"{style1}\">&nbsp;</td>");
            sb.AppendLine($"<td style=\"{style1}\">&nbsp;</td>");
            sb.AppendLine($"<td style=\"{style1}\">&nbsp;</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);
        }