public string Create(Cart cart)
        {
            StringBuilder receipt  = new StringBuilder();
            decimal       totalTax = 0;

            foreach (var product in cart.Products)
            {
                decimal tax = Taxes.ComputeSalesTax(product);
                totalTax += tax;
                decimal price = product.Price + tax;
                receipt.Append("1 ");

                if (product.IsImported)
                {
                    receipt.Append("imported ");
                }

                receipt.Append(product.Name + ": " + Taxes.RoundingRule(price) + Environment.NewLine);
            }

            decimal total = Taxes.RoundingRule(cart.Products.Sum(p => p.Price) + totalTax);

            receipt.Append("Sales Taxes: " + Taxes.RoundingRule(totalTax).ToString("0.00") + Environment.NewLine);
            receipt.Append("Total: " + total.ToString());

            return(receipt.ToString());
        }
Ejemplo n.º 2
0
        public string Create(Cart cart)
        {
            StringBuilder receipt  = new StringBuilder();
            decimal       totalTax = 0;
            int           sno      = 1;
            int           count    = 1;
            TableBuilder  tb       = new TableBuilder();

            tb.AddRow("S.No.", "Product Name", "Count", "Price", "Sales Tax");
            tb.AddRow("-----", "------------", "-----", "-----", "---------");

            foreach (var product in cart.Products)
            {
                decimal tax = Taxes.ComputeSalesTax(product);
                totalTax += tax;
                decimal price = product.Price;
                string  name  = String.Format("{0} {1}", product.IsImported ? "Imported " : "", product.Name);
                tb.AddRow(sno++, name, count, price, tax);
            }
            receipt.Append(tb.Output());
            decimal total = Taxes.RoundingRule(cart.Products.Sum(p => p.Price) + totalTax);

            receipt.Append("-------------------------------------------------------------------\n");
            receipt.Append("Total Sales Taxes: " + Taxes.RoundingRule(totalTax).ToString("0.00") + Environment.NewLine);
            receipt.Append("Total: " + total.ToString());

            return(receipt.ToString());
        }