/// <summary> /// Replace Invoice Items /// </summary> /// <param name="document">Document</param> /// <param name="cartItems">List of invoice items</param> /// <param name="invoicePaid">Invoice Paid</param> private static void ReplaceInvoiceItems(DocX document, List <spGetCartItems_Result> cartItems, bool invoicePaid) { var invoiceItems = cartItems.Select(cart => new { cart.Supplement_Description, cart.Item_Quantity, Price = cart.Item_Price.AddCurrency(), Quantity = cart.Item_Quantity.ToString(), SubTotal = (cart.SubTotal ?? 0M).AddCurrency() }).ToList(); document.ReplaceText("{Description}", string.Join(Environment.NewLine, invoiceItems.Select(p => p.Supplement_Description).ToList())); document.ReplaceText("{Quantity}", string.Join(Environment.NewLine, invoiceItems.Select(p => p.Quantity).ToList())); document.ReplaceText("{Price}", string.Join(Environment.NewLine, invoiceItems.Select(p => p.Price).ToList())); document.ReplaceText("{Amount}", string.Join(Environment.NewLine, invoiceItems.Select(p => p.SubTotal).ToList())); decimal subTotal = cartItems.Sum(p => p.SubTotal) ?? 0M; decimal vat = subTotal * (decimal.Parse(ConfigurationManager.AppSettings["VAT"]) / 100M); document.ReplaceText("{SubTotal}", (subTotal - vat).AddCurrency()); document.ReplaceText("{Balance}", invoicePaid ? "Total" : "Balance Due"); document.ReplaceText("{Vat}", vat.AddCurrency()); document.ReplaceText("{Total}", subTotal.AddCurrency()); }