private static void PrintCalculations(InvoiceHeader header, IList <InvoiceLine> lines) { decimal subtotal, gst, pst, total; subtotal = gst = pst = total = 0.0m; foreach (var line in lines) { subtotal += line.LineTotal; gst += GetTax(line.LineTotal, false); if (line.IsTaxable) { pst += GetTax(line.LineTotal, true); } } WriteLine($"{"",18}{"Subtotal:"}{subtotal,37:N}"); WriteLine($"{"",18}{"GST:"}{gst,42:N2}"); if (pst > 0) { WriteLine($"{"",18}{"PST:"}{pst,42:N2}"); } PrintDottedLine(); total = subtotal + gst + pst; WriteLine($"{"",18}{"Total:"}{total,40:N2}"); WriteLine(); WriteLine($"{"",18}{"Discount:"}{GetDiscount(total, header.ParseTerm()[0]),37:N2}"); }
private static InvoiceHeader GetHeader(string fileHeader, IList <InvoiceLine> lines) { var header = fileHeader.Split(':'); var invHeader = new InvoiceHeader { InvoiceNumber = int.Parse(header[0]), InvoiceDate = DateTime.Parse(header[1]), Term = int.Parse(header[2]), InvoiceLines = (List <InvoiceLine>)lines }; return(invHeader); }