private void CalculateFinalItemsReceipt(IShoppingCart shoppingCart) { //decimal totalInTaxes = 0; foreach (IShoppingCartItem item in shoppingCart.CartItems) { var singleItemtaxes = item.SelectedItem.GetTotalTaxDetail(); decimal totalSingleItemTaxes = item.SelectedItem.GetTotalTaxes(); decimal itemTotalPriceWithTaxes = (item.SelectedItem.Price + totalSingleItemTaxes) * item.Amount; Console.WriteLine($"\n-Item: { item.SelectedItem.ItemName}" + $"\n\t-Qty: { item.Amount}" + $"\n\t-Unit Price: { item.SelectedItem.Price:C2}" + $"\n\t-Total Price with taxes: {Math.Round(itemTotalPriceWithTaxes,2) :C2}"); //Gets the value of the taxes based on the enum y struct foreach (int taxID in singleItemtaxes.Keys) { decimal totalTaxByQuantity = MathRound.MathRoundTwoDecimals(item.Amount * singleItemtaxes[taxID]); Console.WriteLine("\t>>> " + Enum.GetName(typeof(TaxTypes), taxID) + " \t= $ " + totalTaxByQuantity.ToString("C2")); //totalInTaxes += totalTaxByQuantity; } _receipt.FinalPrice += itemTotalPriceWithTaxes; _receipt.TotalTaxes += totalSingleItemTaxes; _receipt.FinalPriceBeforeTaxes += item.SelectedItem.Price * item.Amount; } }
public void CalculateItemTotalTaxes() { var allArticles = dao.GetAllItems(); decimal expected = MathRound.MathRoundTwoDecimals(allArticles[7].Price * (TaxValues.IMPORTED_TAX + TaxValues.SALES_TAX)); decimal actual = allArticles[7].GetTotalTaxes(); Assert.AreEqual(expected, actual); }
public decimal GetTotalTaxes() { decimal total = 0; foreach (var tt in GetTotalTaxDetail()) { total += (decimal)tt.Value; } return(MathRound.MathRoundTwoDecimals(total)); }
public IReceipt CheckOut(IShoppingCart shoppingCart) { Console.WriteLine("\n---------------- RECEIPT ------------------\n"); Console.WriteLine(">> ARTICLES:"); CalculateFinalItemsReceipt(shoppingCart); Console.WriteLine("\n----------------- RESUME -------------------\n"); Console.WriteLine($"Price Before Taxes \t {MathRound.MathRoundTwoDecimals(_receipt.FinalPriceBeforeTaxes):C2}"); Console.WriteLine($"\nTotal Taxes \t\t {_receipt.TotalTaxes:C2}"); Console.WriteLine($"Total \t\t\t {_receipt.FinalPrice:C2}"); Console.WriteLine(""); return(_receipt); }