public void calcul_facture() { Order commande = new Order(); commande.Prices = new[] {4.1m, 8.03m, 86.83m, 65.62m, 44.82m}; commande.Quantities = new[] {10, 3, 5, 4, 5}; commande.Country = "AT"; commande.Reduction = "STANDARD"; Bill facture = ConstructBill.CalculerBill(commande); Assert.That(facture.total, Is.EqualTo(1166.62m)); }
public void calcul_facture_1_article() { Order commande = new Order(); commande.Prices = new[] { 15.99m }; commande.Quantities = new[] {1}; commande.Country = "ES"; commande.Reduction = "STANDARD"; Bill facture = ConstructBill.CalculerBill(commande); Assert.That(facture.total,Is.EqualTo(19.03m)); }
public static Bill CalculerPrice(Order order) { // Variable Bill billFacture = new Bill(); decimal sumArticle = 0; decimal totalSum = 0; decimal totalSumTX = 0; // parcour d'une facture for (int i = 0; i < order.Prices.Length; i++) { sumArticle = order.Prices[i] * order.Quantities[i]; totalSum += sumArticle; switch (order.Country) { case "DE": totalSumTX = Math.Round(totalSum * (1.2m), 2); break; case "FR": totalSumTX = Math.Round(totalSum * (1.2m), 2); break; case "RO": totalSumTX = Math.Round(totalSum * (1.2m), 2); break; case "NL": totalSumTX = Math.Round(totalSum * (1.2m), 2); break; case "EL": totalSumTX = Math.Round(totalSum * (1.2m), 2); break; case "LV": totalSumTX = Math.Round(totalSum * (1.2m), 2); break; case "UK": totalSumTX = Math.Round(totalSum * (1.21m), 2); break; case "PL": totalSumTX = Math.Round(totalSum * (1.21m), 2); break; case "BG": totalSumTX = Math.Round(totalSum * (1.21m), 2); break; case "IE": totalSumTX = Math.Round(totalSum * (1.21m), 2); break; case "CI": totalSumTX = Math.Round(totalSum * (1.21m), 2); break; case "DK": totalSumTX = Math.Round(totalSum * (1.21m), 2); break; case "IT": totalSumTX = Math.Round(totalSum * (1.25m), 2); break; case "LU": totalSumTX = Math.Round(totalSum * (1.25m), 2); break; case "ES": totalSumTX = Math.Round(totalSum * (1.19m), 2); break; case "PT": totalSumTX = Math.Round(totalSum * (1.23m), 2); break; case "SE": totalSumTX = Math.Round(totalSum * (1.23m), 2); break; case "HR": totalSumTX = Math.Round(totalSum * (1.23m), 2); break; case "LT": totalSumTX = Math.Round(totalSum * (1.23m), 2); break; } } // Ajout de la Reduction if (order.Reduction != "PAY THE PRICE") { if (totalSumTX >= 1000) { totalSumTX = totalSumTX - (totalSumTX*(0.03m)); } if (totalSumTX >= 5000) { totalSumTX = totalSumTX - (totalSumTX*(0.05m)); } if (totalSumTX >= 7000) { totalSumTX = totalSumTX - (totalSumTX*(0.07m)); } if (totalSumTX >= 10000) { totalSumTX = totalSumTX - (totalSumTX*(0.10m)); } if (totalSumTX >= 50000) { totalSumTX = totalSumTX - (totalSumTX*(0.15m)); } } billFacture.total = totalSumTX; return billFacture; }
private Bill HandlerOrder(Order order) { // TODO HERE. Return null if you do not what to return a total return null; }
public static Bill CalculerBill(Order commande) { Bill facture = new Bill(); //if (commande.Reduction!="STANDARD") // return null; decimal[] totalPrices = new decimal[commande.Prices.Length]; for (int i = 0; i < commande.Prices.Length; i++) { //Calcul des taxes relatives au pays switch (commande.Country) { case "ES": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.19m; break; case "AT": totalPrices[i] = (commande.Prices[i] * commande.Quantities[i]) * 1.22m; break; case "DE": totalPrices[i] = (commande.Prices[i] * commande.Quantities[i]) * 1.20m; break; case "UK": totalPrices[i] = (commande.Prices[i] * commande.Quantities[i]) * 1.21m; break; case "FR": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.20m; break; case "IT": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.25m; break; case "PL": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.21m; break; case "RO": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.20m; break; case "NL": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.20m; break; case "BE": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.24m; break; case "EL": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.20m; break; case "CZ": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.19m; break; case "PT": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.23m; break; case "HU": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.27m; break; case "SE": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.23m; break; case "BG": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.21m; break; case "DK": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.21m; break; case "FI": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.17m; break; case "SK": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.18m; break; case "IE": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.21m; break; case "HR": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.23m; break; case "LT": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.23m; break; case "SI": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.24m; break; case "LV": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.20m; break; case "EE": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.22m; break; case "CY": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.21m; break; case "LU": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.25m; break; case "MT": totalPrices[i] = (commande.Prices[i]*commande.Quantities[i])*1.20m; break; default: return null; }; } decimal total = totalPrices.Sum(); //Applcation des réductions Bill bill = new Bill(); if (commande.Reduction == "PAY THE PRICE") bill.total = Math.Round(total,2); else if (commande.Reduction == "STANDARD") { if (total >= 1000) { decimal reduction = total*0.03m; total = total - reduction; } else if (total >= 5000) { decimal reduction = total*0.05m; total = total - reduction; } else if (total >= 7000) { decimal reduction = total*0.07m; total = total - reduction; } else if (total >= 10000) { decimal reduction = total*0.10m; total = total - reduction; } else if (total >= 50000) { decimal reduction = total*0.15m; total = total - reduction; } total = Math.Round(total, 2); bill.total = total; } else { bill = null; } return bill; }