public Receipt GenerateReceipt() { var recipt = new Receipt(_taxRate) { Company = Company, InvoiceNumber = new Random().Next(1000, 10000), //Just a randon invoice number, we'd use a primary key or a generated number for the invoice number Date = DateTime.UtcNow //in a real system we would convert this to the correct timezone. }; ProcessLineItems(recipt); recipt.ReconcileTotal(); return recipt; }
/// <summary> /// Creates the receipt for the order /// </summary> /// <param name="type">The type of the receipt to be created</param> /// <returns></returns> public string CreateReceipt(Receipt type) { IReceipt receipt = ReceiptSimpleFactory.CreateReceipt(type); return(receipt.GenerateReceipt(this)); }
private static string CompileTemplate(Receipt model, string resourceName, string templateKey) { var assembly = Assembly.GetExecutingAssembly(); var template = string.Empty; using (var stream = assembly.GetManifestResourceStream(resourceName)) using (var reader = new StreamReader(stream)) { template = reader.ReadToEnd(); } var config = new TemplateServiceConfiguration {EncodedStringFactory = new RawStringFactory()}; Engine.Razor = RazorEngineService.Create(config); return Engine.Razor.RunCompile(template, templateKey, null, model); }
private void ProcessLineItems(Receipt receipt) { foreach (var line in _lines) { var price = line.Item.Price; var qty = line.Quantity; var sub = (decimal) (price*qty); receipt.Items.Add(new ReciptLineItem { Description = line.Name(), Quantity = qty, Total = sub }); var discounts = ApplyDiscounts(line, sub); receipt.Items.AddRange(discounts); } }
/// <summary> /// Creates the receipt for the order /// </summary> /// <param name="type">The type of the receipt to be created</param> /// <returns></returns> public string CreateReceipt(Receipt type) { IReceipt receipt = ReceiptSimpleFactory.CreateReceipt(type); return receipt.GenerateReceipt(this); }