private bool GetAffectedCuts(int productId, ProductNode node, Dictionary <int, ProductNode> cuts) { if (node.ProductId == productId) { if (!cuts.ContainsKey(productId)) { cuts.Add(productId, node); } return(true); } else { if (node.Childs.Any()) { foreach (var child in node.Childs) { var result = GetAffectedCuts(productId, child, cuts); if (result) { if (!cuts.ContainsKey(node.ProductId)) { cuts.Add(node.ProductId, node); } return(true); } } } } return(false); }
private void AddBlankRecipes() { foreach (Product p in _products.Where(p => p.ProductTypeId == ProductType.Dish)) { var product = _products_dict[p.ProductId]; ProductNode node = new ProductNode(product.ProductId, product.UnitId, product.Quantity, product.ProductTypeId); if (product.ProductTypeId == ProductType.Dish) { node.RecipeKind = product.RecipeTypeId; } if (!_forest.ContainsKey(node.ProductId)) { _forest.Add(node.ProductId, node); } } }
private void AddRecipeChild(ProductNode parent, Dictionary <int, List <ProductPart> > allParts, List <ProductPart> childParts) { foreach (var part in childParts) { ProductNode node = new ProductNode(part.SubProductId, part.UnitId.HasValue ? part.UnitId.Value: 0, part.Quantity.HasValue ? part.Quantity.Value : 0, part.ProductTypeId, part.Ratio, part.PortionTypeId); if (!part.Quantity.HasValue || !part.UnitId.HasValue) { node.IsBroken = true; } if (part.ProductTypeId == ProductType.Dish) { node.RecipeKind = _products_dict[part.SubProductId].RecipeTypeId; } node.IsChoise = part.IsChoise; parent.Childs.Add(node); if (part.ProductTypeId != ProductType.Ingredient) { if (_forest.ContainsKey(node.ProductId)) { var existingItemStructure = _forest[node.ProductId]; //add existings node.Childs.AddRange(existingItemStructure.Childs); } else { List <ProductPart> childs = new List <ProductPart>(); if (allParts.ContainsKey(node.ProductId)) { childs = allParts[node.ProductId]; } var product = _products_dict[node.ProductId]; ProductNode fNode = new ProductNode(product.ProductId, product.UnitId, product.Quantity, product.ProductTypeId); //build non existing chain AddRecipeChild(fNode, allParts, childs); node.Childs.AddRange(fNode.Childs); //build child structure _forest.Add(fNode.ProductId, node); } } } }
private void AddNonBlankRecipes() { Dictionary <int, List <ProductPart> > product_parts_dict = _parts.GroupBy(g => g.ProductId).ToDictionary(key => key.Key, value => value.ToList()); foreach (int productId in product_parts_dict.Keys) { var childs = product_parts_dict[productId]; var product = _products_dict[productId]; ProductNode node = new ProductNode(productId, product.UnitId, product.Quantity, product.ProductTypeId); if (product.ProductTypeId == ProductType.Dish) { node.RecipeKind = product.RecipeTypeId; } if (!_forest.ContainsKey(productId)) { AddRecipeChild(node, product_parts_dict, childs); _forest.Add(node.ProductId, node); } } }
protected virtual decimal?GetRecipePrice(Dictionary <int, decimal> priceStorage, Dictionary <int, Product> products, HashSet <int> accessList, bool checkAlternates, IEnumerable <IngredientAlternate> alternates, StringBuilder errors, ProductNode child, decimal productConvertion) { decimal?price = null; var recipePrice = child.GetPrice(priceStorage, products, accessList, checkAlternates, alternates, errors); if (recipePrice.HasValue && (RecipeKind != RecipeType.Choice || child.IsChoise)) { var apPrice = recipePrice.Value * child.Quantity; price = apPrice / productConvertion; //add non ingredient price } return(price); }
protected virtual decimal GetIngredientPrice(Dictionary <int, decimal> priceStorage, StringBuilder errors, ProductNode child, int workChildProductId, Product product, decimal productConvertion) { //need to check if child is ingredient is any of its alternates listed in price storage //this case is used when feature Restrict by Supplier access is enable if (!priceStorage.ContainsKey(workChildProductId)) { string msg = $"ProductId {workChildProductId} not found in list with priceStorage. Calculated productId {ProductId}, childProductId {child.ProductId}, workChildProductId {workChildProductId}"; if (errors != null) { errors.AppendLine(msg); } throw new KeyNotFoundException(msg); } var baseIngredientPrice = priceStorage[workChildProductId]; decimal ingredientEpPrice = baseIngredientPrice; if (child.Portion == PortionType.EP && product.Wastage.HasValue && product.Wastage <= 100 && product.Wastage > 0) { ingredientEpPrice = baseIngredientPrice * 100.0m / (100.0m - product.Wastage.Value); } var apPrice = ingredientEpPrice * child.Quantity; decimal price = apPrice / productConvertion; return(price); }