protected void Page_Load(object sender, EventArgs e) { loggedInAdmin = Helpers.GetLoggedInAdmin(); homeCompany = Helpers.GetCurrentCompany(); currentInvoice = Helpers.GetRequestedInvoice(); permission = AllowedStore.GetAllowedStoreByCustomerSupplier(homeCompany.company_id, currentInvoice.supplier_id); if (!(Helpers.IsAuthorizedAdmin(loggedInAdmin, homeCompany))) { Response.Redirect("/status.aspx?error=notadmin"); } else if (!(currentInvoice.customer_id == homeCompany.company_id || currentInvoice.supplier_id == homeCompany.company_id)) { Response.Redirect("/status.aspx?error=genericerror"); } if (!IsPostBack) { PopulateDetails(); PopulateInvoiceItems(); } }
public static void SendInvoice(Invoice newInvoice) { // create mail message object MailMessage mail = new MailMessage(); mail.From = new MailAddress(sender); // put the from address here mail.To.Add(new MailAddress(newInvoice.customer_.transactions_email)); // put to address here //mail.Bcc.Add(new MailAddress(backupAddress)); mail.Subject = "Invoice # " + newInvoice.invoice_id.ToString() + " available."; // put subject here string serverPath = HttpContext.Current.Server.MapPath("/email/"); string body = File.ReadAllText(serverPath + "InvoiceEmail.txt"); body = body.Replace("$invoiceID", newInvoice.invoice_id.ToString()); body = body.Replace("$supplierName", newInvoice.supplierName); body = body.Replace("$local_code", newInvoice.local_code); body = body.Replace("$purchaseorder_code", newInvoice.purchaseorder_.local_code); body = body.Replace("$freight", newInvoice.freight.ToString("#0.00")); body = body.Replace("$tax", newInvoice.tax.ToString("#0.00")); body = body.Replace("$total", newInvoice.total.ToString("#0.00")); string invoiceItemHeader = "Barcode\t\tGST?\tRRP\tQty\tCostEx\tDescription"; body = body.Replace("$invoiceItemHeader", invoiceItemHeader); string invoiceItems = ""; foreach (var item in newInvoice.InvoiceItemsByinvoice_) { string gst = item.is_GST ? "GST" : "FRE"; invoiceItems += item.barcode + "\t" + gst + "\t" + item.RRP.ToString("#0.00") + "\t" + item.quantity + "\t" + item.cost_price.ToString("#0.00") + "\t" + item.description + "\r\n"; } body = body.Replace("$invoiceItems", invoiceItems); mail.Body = body; SmtpClient client = new SmtpClient(); try { client.Send(mail); } catch (Exception ex) { throw ex; } }