Beispiel #1
0
        public PriceOfProduct(Product product, DateTime targetDate, IPriceService priceService, double amount = 1, double?customFixedPrice = null)
        {
            Name           = $"{product.ToString()}";
            Amount         = amount;
            PriceMainBlock = new PriceOfProductBlock(product.ProductBlock, targetDate, priceService, amount);
            foreach (var dependentProduct in product.DependentProducts)
            {
                PricesOfDependentBlocks.Add(new PriceOfProduct(dependentProduct.Product, targetDate, priceService, dependentProduct.Amount));
            }

            //расстановка нестандартных фиксированных прайсов
            this.SumFixed = customFixedPrice;
        }
Beispiel #2
0
        public Price(IUnit unit, DateTime targetDate, IPriceService priceService, bool checkCalculations)
        {
            Name = unit.Product.ToString();
            IEnumerable <ProductIncluded> productsIncluded = unit.ProductsIncluded;

            //если есть калькул¤ци¤
            var priceCalculationItem = checkCalculations
                ? priceService.GetPriceCalculationItem(unit)
                : null;

            if (priceCalculationItem != null)
            {
                HasCalculation = true;

                //заглушка на прайс основного блока
                PriceMainBlock = new PriceStub(unit.Product.ToString(), 1, laborHours: priceService.GetLaborHoursAmount(unit));

                //заглушки на прайсы зависимых блоков
                PricesOfDependentBlocks =
                    priceCalculationItem.StructureCosts
                    .Where(structureCost => structureCost.UnitPrice.HasValue)
                    .Select(structureCost => new PriceStub($"{structureCost.Comment}", structureCost.Amount, structureCost.UnitPrice.Value, structureCost.Number))
                    .Cast <IPrice>()
                    .ToList();

                //оставл¤ем включенное оборудование только с фиксированной ценой (напр. шеф-монтаж)
                productsIncluded = productsIncluded.Where(productIncluded => productIncluded.CustomFixedPrice.HasValue || productIncluded.Product.HasBlockWithFixedCost);
            }
            //если калькул¤ции нет, нужно инициировать по продукту
            else
            {
                Amount         = 1;
                PriceMainBlock = new PriceOfProduct(unit.Product, targetDate, priceService, Amount);
                foreach (var dependentProduct in unit.Product.DependentProducts)
                {
                    PricesOfDependentBlocks.Add(new PriceOfProduct(dependentProduct.Product, targetDate, priceService, dependentProduct.Amount));
                }
            }

            //включенное оборудование
            foreach (var productIncluded in productsIncluded)
            {
                var price = new PriceOfProduct(productIncluded.Product, targetDate, priceService, productIncluded.AmountOnUnit, productIncluded.CustomFixedPrice);
                PricesProductsIncluded.Add(price);
            }
        }