public ComplexRecipe(ComplexProduction production)
            : this()
        {
            locationId      = production.LocationId;
            location        = production.Location;
            location2       = production.Location2;
            partnerId       = production.PartnerId;
            partnerName     = production.PartnerName;
            partnerName2    = production.PartnerName2;
            userId          = production.UserId;
            userName        = production.UserName;
            userName2       = production.UserName2;
            loggedUserId    = production.LoggedUserId;
            loggedUserName  = production.LoggedUserName;
            loggedUserName2 = production.LoggedUserName2;

            foreach (ComplexProductionDetail detail in production.DetailsMat)
            {
                detailsMat.Add(new ComplexRecipeDetail(detail));
            }

            detailsMat = GetCombinedDetails(false, true, detailsMat);

            foreach (ComplexProductionDetail detail in production.DetailsProd)
            {
                detailsProd.Add(new ComplexRecipeDetail(detail));
            }

            detailsProd = GetCombinedDetails(false, true, detailsProd);
        }
        public void QuantityEvaluate(double value, ComplexProduction parent)
        {
            Quantity = value;

            if (SourceRecipe != null)
            {
                ComplexRecipeDetail recDetail = GetMatchingRecipeDetail(this);
                if (recDetail != null)
                {
                    double coef = value / recDetail.Quantity;

                    foreach (ComplexProductionDetail detail in parent.DetailsMat)
                    {
                        if (!ReferenceEquals(detail.SourceRecipe, SourceRecipe))
                        {
                            continue;
                        }

                        if (detail.ItemId == itemId)
                        {
                            continue;
                        }

                        recDetail = GetMatchingRecipeDetail(detail);
                        if (recDetail == null)
                        {
                            continue;
                        }

                        detail.Quantity = recDetail.Quantity * coef;
                    }

                    foreach (ComplexProductionDetail detail in parent.DetailsProd)
                    {
                        if (!ReferenceEquals(detail.SourceRecipe, SourceRecipe))
                        {
                            continue;
                        }

                        if (detail.ItemId == itemId)
                        {
                            continue;
                        }

                        recDetail = GetMatchingRecipeDetail(detail);
                        if (recDetail == null)
                        {
                            continue;
                        }

                        detail.Quantity = recDetail.Quantity * coef;
                    }
                }
            }

            parent.RecalculatePrices();
        }
        public bool ItemEvaluate(Item item, PriceGroup priceGroup, bool updatePrice, ComplexProduction parent)
        {
            bool ret = ItemEvaluate(item, priceGroup, updatePrice);

            if (ret)
            {
                parent.RecalculatePrices();
            }

            return(ret);
        }
        public static ComplexProduction GetPending(long pId, long lId)
        {
            ComplexProduction production = BusinessDomain.DataAccessProvider.GetPendingOperation <ComplexProduction> (OperationType.ComplexProductionMaterial, pId, lId);

            if (production != null)
            {
                production.LoadDetails();
                production.IsDirty = false;
            }

            return(production);
        }
        public static ComplexProduction GetById(long id)
        {
            ComplexProduction production = BusinessDomain.DataAccessProvider.GetOperationById <ComplexProduction> (OperationType.ComplexProductionMaterial, id);

            if (production != null)
            {
                production.LoadDetails();
                production.IsDirty = false;
            }

            return(production);
        }