public string GetGraphizString(StockExchangeDemand stockExchangeDemand) { // Demand(CustomerOrder);20;Truck string exchangeType = Constants.EnumToString( ((T_StockExchange)stockExchangeDemand.ToIDemand()).ExchangeType, typeof(ExchangeType)); string graphizString = $"D: StockExchangeDemand;{ToGraphizString(stockExchangeDemand)}"; return(graphizString); }
/** * covers parent StockExchangeProvider(and its parent CustomerOrderPart if exist), child PurchaseOrderPart if exist * --> 3 types of subgraphs: Production, Purchase, Customer */ private static List <IDemandOrProvider> GetItemsOfStockExchangeDemandSubGraph( StockExchangeDemand stockExchangeDemand, IDbTransactionData dbTransactionData, IAggregator aggregator, bool includeStockExchangeProviderHavingMultipleChilds) { List <IDemandOrProvider> items = new List <IDemandOrProvider>(); items.Add(stockExchangeDemand); Providers stockExchangeProviders = aggregator.GetAllParentProvidersOf(stockExchangeDemand); foreach (var stockExchangeProvider in stockExchangeProviders) { Demands childsOfStockExchangeProvider = aggregator.GetAllChildDemandsOf(stockExchangeProvider); if (includeStockExchangeProviderHavingMultipleChilds || childsOfStockExchangeProvider.Count() == 1) { items.Add(stockExchangeProvider); Demands customerOrderParts = aggregator.GetAllParentDemandsOf(stockExchangeProvider); if (customerOrderParts.Count() > 1) { throw new MrpRunException( "A stockExchangeProvider can only have one parent."); } foreach (var customerOrderPart in customerOrderParts) { items.Add(customerOrderPart); } } } Providers purchaseOrderParts = aggregator.GetAllChildProvidersOf(stockExchangeDemand); if (purchaseOrderParts.Count() > 1) { throw new MrpRunException("A stockExchangeDemand can only have one child."); } foreach (var purchaseOrderPart in purchaseOrderParts) { items.Add(purchaseOrderPart); } return(items); }
/** * There initial stock levels defined in M_Stock, to avoid modelling stocks, * the initial stock levels are simulated as stockExchangeDemands */ public static void AddInitialStockLevels(IDbTransactionData dbTransactionData) { foreach (var stock in ZppConfiguration.CacheManager.GetMasterDataCache().M_StockGetAll()) { if (stock.Current > 0) { Id articleId = new Id(stock.ArticleForeignKey); Demand stockExchangeDemand = StockExchangeDemand.CreateStockExchangeStockDemand(articleId, new DueTime(0), new Quantity(stock.Current)); stockExchangeDemand.SetReadOnly(); dbTransactionData.DemandsAdd(stockExchangeDemand); } } }
public EntityCollector CreateDependingDemands(Provider provider) { if (provider.GetQuantity().IsNull()) { return(null); } if (provider.GetType() != typeof(StockExchangeProvider)) { throw new MrpRunException("This can only be called for StockExchangeProviders"); } // try to provide by existing demand // collects stockExchangeDemands, providerToDemands EntityCollector entityCollector = _openDemandManager.SatisfyProviderByOpenDemand(provider, provider.GetQuantity()); if (entityCollector == null) { entityCollector = new EntityCollector(); } Quantity remainingQuantity = entityCollector.GetRemainingQuantity(provider); if (remainingQuantity.IsGreaterThan(Quantity.Zero())) { LotSize.Impl.LotSize lotSizes = new LotSize.Impl.LotSize(remainingQuantity, provider.GetArticleId()); bool isLastIteration = false; foreach (var lotSize in lotSizes.GetLotSizes()) { if (isLastIteration || remainingQuantity.IsNegative() || remainingQuantity.IsNull()) { throw new MrpRunException("This is one iteration too many."); } Demand stockExchangeDemand = StockExchangeDemand.CreateStockExchangeStockDemand(provider.GetArticleId(), provider.GetStartTimeBackward(), lotSize); entityCollector.Add(stockExchangeDemand); // 3 cases Quantity quantityOfNewCreatedDemandToReserve; if (remainingQuantity.IsGreaterThan(lotSize)) { quantityOfNewCreatedDemandToReserve = lotSize; } else if (remainingQuantity.Equals(lotSize)) { // last iteration isLastIteration = true; quantityOfNewCreatedDemandToReserve = lotSize; } else { // last iteration, remaining < lotsize isLastIteration = true; quantityOfNewCreatedDemandToReserve = new Quantity(remainingQuantity); // remember created demand as openDemand _openDemandManager.AddDemand(stockExchangeDemand, quantityOfNewCreatedDemandToReserve); } remainingQuantity.DecrementBy(lotSize); if (quantityOfNewCreatedDemandToReserve.IsNegative() || quantityOfNewCreatedDemandToReserve.IsNull()) { throw new MrpRunException( $"quantityOfNewCreatedDemandToReserve cannot be negative or null: " + $"{quantityOfNewCreatedDemandToReserve}"); } T_ProviderToDemand providerToDemand = new T_ProviderToDemand(provider.GetId(), stockExchangeDemand.GetId(), quantityOfNewCreatedDemandToReserve); entityCollector.Add(providerToDemand); } } return(entityCollector); }
public static bool IsOpen(StockExchangeDemand stockExchangeDemand) { Quantity reservedQuantity = CalculateReservedQuantity(stockExchangeDemand); return(stockExchangeDemand.GetQuantity().Minus(reservedQuantity).GetValue() > 0); }