// Only for kedai pasang public RodSetOutput Calculate(RodSetInput input) { RodSetOutput result = new RodSetOutput(); result.Set = input.Set; if (input.ReadyMadeProduct != null && input.ReadyMadeProduct.Count != 0) { result.ReadyMadeProduct = new List <ReadyMadeProduct>(); ReadyMadeProduct product = input.ReadyMadeProduct[0]; if (input.Sequence == 1) { product.Subtotal = Math.Round(product.Quantity * product.Meter * 13, 2); } else if (input.Sequence == 2) { product.Subtotal = Math.Round(product.Quantity * product.Meter * 10, 2); } result.ReadyMadeProduct.Add(product); result.RodQuantity = input.ReadyMadeProduct[0].Quantity; result.RodOnlySubtotal = Math.Round(product.Subtotal, 2); result = HandleEndcapBracket(result, product); result.RodSetTotal = result.RodOnlySubtotal + result.EndCapSubtotal + result.BracketSubtotal; } return(result); }
public void CalculateTest() { Input input = new Input(); input.FormulaCode = "F80"; ReadyMadeProduct p1 = new ReadyMadeProduct(string.Empty, "1 Panel Bunga", "27'' x 84", 125); p1.Quantity = 2; ReadyMadeProduct p2 = new ReadyMadeProduct(string.Empty, "1 Panel Kosong", "27'' x 96", 125); p2.Quantity = 2; ReadyMadeProduct p3 = new ReadyMadeProduct(string.Empty, "2 Panel", "51'' x 84", 175); p3.Quantity = 2; ReadyMadeProduct p4 = new ReadyMadeProduct(string.Empty, "3 Panel", "75'' x 84", 235); p4.Quantity = 2; input.ReadyMadeProduct = new List <ReadyMadeProduct>(); input.ReadyMadeProduct.Add(p1); input.ReadyMadeProduct.Add(p2); input.ReadyMadeProduct.Add(p3); input.ReadyMadeProduct.Add(p4); IFormula formula = new F80(); Output actual = formula.Calculate(input); Assert.AreEqual(actual.Jumlah, 1320); }
public RodSetOutput Calculate(RodSetInput input) { Product p = new Product(null, null, null, true); F93_2ProductCollection products = new F93_2ProductCollection(); p = products.Initialize(p, true); ReadyMadeProduct bracket = p.ReadyMadeProduct.Find(x => x.Name == Constant.Bracket); ReadyMadeProduct endcap = p.ReadyMadeProduct.Find(x => x.Name == Constant.EndCap); RodSetOutput output = CalculateRodWithInstallation(input); output = CalculateEndcapBracket(output, 2, bracket, endcap); return(output); }
private RodSetOutput HandleEndcapBracket(RodSetOutput result, ReadyMadeProduct product) { int option = 0; Product p = new Product(null, null, null, true); switch (product.Name) { case Constant.RodKayuHitam: case Constant.RodKayuCoco: option = 1; F92_1ProductCollection f92_1ProductCollection = new F92_1ProductCollection(); p = f92_1ProductCollection.Initialize(p, true); break; case Constant.RodKayuPutih: option = 2; F93_1ProductCollection f93_1ProductCollection = new F93_1ProductCollection(); p = f93_1ProductCollection.Initialize(p, true); break; case Constant.RodAluminiumMeroon: case Constant.RodAluminiumHitam: case Constant.RodAluminiumKokoGelap: case Constant.RodAluminiumPutih: case Constant.RodAluminiumSilverRose: option = 3; F94_1ProductCollection f94_1ProductCollection = new F94_1ProductCollection(); p = f94_1ProductCollection.Initialize(p, true); break; } ReadyMadeProduct bracket = p.ReadyMadeProduct.Find(x => x.Name == Constant.Bracket); ReadyMadeProduct endcap = p.ReadyMadeProduct.Find(x => x.Name == Constant.EndCap); // A hack to make name become meter for using CalculateEndcapBracket method string tempNameStorage = result.ReadyMadeProduct[0].Name; result.ReadyMadeProduct[0].Name = result.ReadyMadeProduct[0].Meter.ToString(); result = CalculateEndcapBracket(result, option, bracket, endcap); result.ReadyMadeProduct[0].Name = tempNameStorage; return(result); }
public RodSetOutput CalculateEndcapBracket(RodSetOutput output, int option, ReadyMadeProduct bracket, ReadyMadeProduct endcap) { output.EndCapQuantity = output.RodQuantity * 2; // no need multiply by Set here because RodQuantity already calculated with Set foreach (ReadyMadeProduct product in output.ReadyMadeProduct) { double meter; bool isMeter = double.TryParse(product.Name, out meter); if (isMeter) { if (option == 1) { if (meter <= 6.5) { output.BracketQuantity += product.Quantity * 2; } else if (meter <= 12) { output.BracketQuantity += product.Quantity * 3; } else if (meter <= 14) { output.BracketQuantity += product.Quantity * 4; } } else if (option == 2) { if (meter <= 6.5) { output.BracketQuantity += product.Quantity * 2; } else if (meter <= 10) { output.BracketQuantity += product.Quantity * 3; } } else if (option == 3) { if (meter <= 5) { output.BracketQuantity += product.Quantity * 2; } else if (meter <= 12) { output.BracketQuantity += product.Quantity * 3; } else if (meter <= 14) { output.BracketQuantity += product.Quantity * 4; } } } else if (product.Name == Constant.Bracket) { output.BracketQuantity += product.Quantity; } else if (product.Name == Constant.EndCap) { output.EndCapQuantity += product.Quantity; } } //bracket.Subtotal = output.BracketQuantity * bracket.Price; //endcap.Subtotal = output.EndCapQuantity * endcap.Price; //output.ReadyMadeProduct.Add(bracket); //output.ReadyMadeProduct.Add(endcap); //output.BracketSubtotal = bracket.Subtotal; //output.EndCapSubtotal = endcap.Subtotal; output.RodSetTotal = output.RodOnlySubtotal;// + output.BracketSubtotal + output.EndCapSubtotal; return(output); }