示例#1
0
        /***
         * Requirements
         * */
        /*
         * /// <summary>
         * /// Creates stock reservation if possible
         * /// </summary>
         * /// <param name="stock"></param>
         * /// <param name="demand"></param>
         * public void TryCreateStockReservation(Stock stock, IDemandToProvider demand)
         * {
         * var stockReservations = GetReserved(demand.ArticleId);
         * var bought = GetAmountBought(demand.ArticleId);
         * //get the current amount of free available articles
         * var current = stock.Current + bought - stockReservations;
         * decimal quantity;
         * //either reserve all that are in stock or the amount needed
         * quantity = demand.Quantity > current ? current : demand.Quantity;
         * if (quantity == 0) return;
         * var demandProviderStock = new DemandProviderStock()
         * {
         *     ArticleId = stock.ArticleForeignKey,
         *     Quantity = quantity,
         *     DemandRequesterId = demand.DemandRequesterId ?? demand.Id,
         *     StockId = stock.Id
         * };
         * Demands.Add(demandProviderStock);
         * SaveChanges();
         * }*/

        public List <ProductionOrder> CreateChildProductionOrders(IDemandToProvider demand, decimal amount, int simulationId)
        {
            ProductionOrderBom bom = null;

            if (demand.GetType() == typeof(DemandProductionOrderBom))
            {
                bom = ProductionOrderBoms.FirstOrDefault(a => a.Id == ((DemandProductionOrderBom)demand).ProductionOrderBomId);
            }

            var lotsize          = SimulationConfigurations.Single(a => a.Id == simulationId).Lotsize;
            var productionOrders = new List <ProductionOrder>();

            /*decimal bomQuantity;
             * if (bom != null)
             *  bomQuantity = ArticleBoms.AsNoTracking().Single(a => a.ArticleChildId == demand.ArticleId &&
             *      a.ArticleParentId == bom.ProductionOrderParent.ArticleId).Quantity * lotsize;
             * else
             *  bomQuantity = ArticleBoms.AsNoTracking().Single(a =>a.ArticleChildId == demand.ArticleId &&
             *      a.ArticleParentId == null).Quantity * lotsize;
             */
            while (amount > 0)// || bomQuantity > 0)
            {
                var productionOrder = CreateProductionOrder(demand, GetDueTimeByOrder(demand), simulationId);
                if (amount > 0)
                {
                    var demandProviderProductionOrder = CreateDemandProviderProductionOrder(demand, productionOrder,
                                                                                            amount > lotsize ? lotsize : amount);

                    //if the article has a parent create a relationship
                    if (bom != null)
                    {
                        demandProviderProductionOrder.DemandRequesterId = demand.Id;
                        Demands.Update(demandProviderProductionOrder);
                    }
                }
                SaveChanges();
                amount -= lotsize;
                //bomQuantity -= lotsize;
                productionOrders.Add(productionOrder);
            }

            return(productionOrders);
        }
        public DbTransactionData(ProductionDomainContext productionDomainContext)
        {
            _productionDomainContext = productionDomainContext;

            // cache tables
            // TODO: This line should be removed
            _articles = _productionDomainContext.Articles.Include(m => m.ArticleBoms)
                        .ThenInclude(m => m.ArticleChild).Include(m => m.ArticleBoms)
                        .ThenInclude(x => x.Operation).ThenInclude(x => x.ResourceCapability)
                        .ThenInclude(s => s.ResourceCapabilityProvider).ThenInclude(r => r.ResourceSetups)
                        .ThenInclude(x => x.Resource)
                        .Include(x => x.ArticleToBusinessPartners).ThenInclude(x => x.BusinessPartner)
                        .ToList();

            _productionOrderBoms =
                new ProductionOrderBoms(_productionDomainContext.ProductionOrderBoms.ToList());

            _stockExchangeDemands =
                new StockExchangeDemands(_productionDomainContext.StockExchanges.ToList());
            _stockExchangeProviders =
                new StockExchangeProviders(_productionDomainContext.StockExchanges.ToList());

            _productionOrders =
                new ProductionOrders(_productionDomainContext.ProductionOrders.ToList());
            _purchaseOrderParts =
                new PurchaseOrderParts(_productionDomainContext.PurchaseOrderParts.ToList());

            _customerOrderParts =
                new CustomerOrderParts(_productionDomainContext.CustomerOrderParts.ToList());
            _customerOrders = new CustomerOrders(_productionDomainContext.CustomerOrders.ToList());

            // others
            _purchaseOrders.PushAll(_productionDomainContext.PurchaseOrders.ToList());
            _productionOrderOperations = new ProductionOrderOperations(
                _productionDomainContext.ProductionOrderOperations.ToList());

            // demandToProvider

            _demandToProviderTable =
                new LinkDemandAndProviderTable(_productionDomainContext.DemandToProviders);
            _providerToDemandTable =
                new LinkDemandAndProviderTable(_productionDomainContext.ProviderToDemand);
        }