Beispiel #1
0
        public ProductionOrder CreateProductionOrder(IDemandToProvider demand, int duetime, int simulationId)
        {
            var productionOrder = new ProductionOrder()
            {
                ArticleId = demand.Article.Id,
                Quantity  = SimulationConfigurations.Single(a => a.Id == simulationId).Lotsize,
                Duetime   = duetime
            };

            ProductionOrders.Add(productionOrder);
            SaveChanges();
            return(productionOrder);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public ProductionOrderBom TryCreateProductionOrderBoms(IDemandToProvider demand, ProductionOrder parentProductionOrder, int simulationId)
        {
            if (parentProductionOrder == null)
            {
                return(null);
            }
            var lotsize  = SimulationConfigurations.Single(a => a.Id == simulationId).Lotsize;
            var quantity = demand.Quantity > lotsize ? lotsize : demand.Quantity;
            var pob      = new ProductionOrderBom()
            {
                Quantity = quantity,
                ProductionOrderParentId = parentProductionOrder.Id
            };

            Add(pob);
            SaveChanges();
            if (demand.GetType() == typeof(DemandProductionOrderBom))
            {
                AssignDemandProviderToProductionOrderBom((DemandProductionOrderBom)demand, pob);
            }
            return(pob);
        }