/** * SE:I --> satisfy by orders PuOP */ public EntityCollector Satisfy(Demand demand, Quantity demandedQuantity) { EntityCollector entityCollector = new EntityCollector(); M_Article article = demand.GetArticle(); DueTime dueTime = demand.GetStartTimeBackward(); if (article.ToBuild) { throw new MrpRunException( "You try to create a purchaseOrderPart for a articleToBuild."); } // currently only one businessPartner per article TODO: This could be changing M_ArticleToBusinessPartner articleToBusinessPartner = _dbMasterDataCache.M_ArticleToBusinessPartnerGetAllByArticleId(article.GetId())[0]; M_BusinessPartner businessPartner = _dbMasterDataCache.M_BusinessPartnerGetById(new Id(articleToBusinessPartner .BusinessPartnerId)); T_PurchaseOrder purchaseOrder = new T_PurchaseOrder(); // [Name],[DueTime],[BusinessPartnerId] purchaseOrder.DueTime = dueTime.GetValue(); purchaseOrder.BusinessPartner = businessPartner; purchaseOrder.Name = $"PurchaseOrder{article.Name} for " + $"businessPartner {purchaseOrder.BusinessPartner.Id}"; // init a new purchaseOderPart T_PurchaseOrderPart tPurchaseOrderPart = new T_PurchaseOrderPart(); // [PurchaseOrderId],[ArticleId],[Quantity],[State],[ProviderId] tPurchaseOrderPart.PurchaseOrder = purchaseOrder; tPurchaseOrderPart.PurchaseOrderId = purchaseOrder.Id; tPurchaseOrderPart.Article = article; tPurchaseOrderPart.ArticleId = article.Id; tPurchaseOrderPart.Quantity = CalculateQuantity(articleToBusinessPartner, demandedQuantity) * articleToBusinessPartner .PackSize; if (tPurchaseOrderPart.Quantity < demandedQuantity.GetValue()) { throw new MrpRunException("You cannot purchase less than you need!"); } tPurchaseOrderPart.State = State.Created; PurchaseOrderPart purchaseOrderPart = new PurchaseOrderPart(tPurchaseOrderPart, null); T_DemandToProvider demandToProvider = new T_DemandToProvider() { DemandId = demand.GetId().GetValue(), ProviderId = purchaseOrderPart.GetId().GetValue(), Quantity = demandedQuantity.GetValue() }; entityCollector.Add(purchaseOrderPart); entityCollector.Add(demandToProvider); return(entityCollector); }
/** * COP or PrOB --> satisfy by SE:W */ public EntityCollector Satisfy(Demand demand, Quantity demandedQuantity) { EntityCollector entityCollector = new EntityCollector(); Provider stockProvider = CreateStockExchangeProvider(demand.GetArticle(), demand.GetStartTimeBackward(), demandedQuantity); entityCollector.Add(stockProvider); T_DemandToProvider demandToProvider = new T_DemandToProvider(demand.GetId(), stockProvider.GetId(), demandedQuantity); entityCollector.Add(demandToProvider); return(entityCollector); }
public EntityCollector CreateDependingDemands(Provider provider) { EntityCollector entityCollector = new EntityCollector(); Demands dependingDemands = CreateProductionOrderBoms(provider.GetArticle(), provider, provider.GetQuantity()); entityCollector.AddAll(dependingDemands); foreach (var dependingDemand in dependingDemands) { T_ProviderToDemand providerToDemand = new T_ProviderToDemand(provider.GetId(), dependingDemand.GetId(), dependingDemand.GetQuantity()); entityCollector.Add(providerToDemand); } return(entityCollector); }
/** * SE:I --> satisfy by orders PrOBom */ public EntityCollector Satisfy(Demand demand, Quantity demandedQuantity) { if (demand.GetArticle().ToBuild == false) { throw new MrpRunException("Must be a build article."); } EntityCollector entityCollector = CreateProductionOrder(demand, demandedQuantity); foreach (var provider in entityCollector.GetProviders()) { T_DemandToProvider demandToProvider = new T_DemandToProvider() { DemandId = demand.GetId().GetValue(), ProviderId = provider.GetId().GetValue(), Quantity = provider.GetQuantity().GetValue() }; entityCollector.Add(demandToProvider); } return(entityCollector); }
public EntityCollector CreateProductionOrder(Demand demand, Quantity quantity) { if (quantity == null || quantity.GetValue() == null) { throw new MrpRunException("Quantity is not set."); } T_ProductionOrder tProductionOrder = new T_ProductionOrder(); // [ArticleId],[Quantity],[Name],[DueTime],[ProviderId] tProductionOrder.DueTime = demand.GetStartTimeBackward().GetValue(); tProductionOrder.Article = demand.GetArticle(); tProductionOrder.ArticleId = demand.GetArticle().Id; tProductionOrder.Name = $"ProductionOrder for Demand {demand.GetArticle()}"; tProductionOrder.Quantity = quantity.GetValue().GetValueOrDefault(); ProductionOrder productionOrder = new ProductionOrder(tProductionOrder); EntityCollector entityCollector = new EntityCollector(); entityCollector.Add(productionOrder); return(entityCollector); }
/** * aka ReserveQuantityOfExistingDemand or satisfyByAlreadyExistingDemand */ public EntityCollector SatisfyProviderByOpenDemand(Provider provider, Quantity demandedQuantity) { if (_openDemands.AnyOpenProvider(provider.GetArticle())) { EntityCollector entityCollector = new EntityCollector(); // ths is needed, because openDemands will be removed once they are consumed List <OpenNode <Demand> > copyOfOpenDemands = new List <OpenNode <Demand> >(); copyOfOpenDemands.AddRange(_openDemands.GetOpenProvider(provider.GetArticle())); Quantity remainingQuantity = new Quantity(demandedQuantity); bool isLastIteration = false; foreach (var openDemand in copyOfOpenDemands) { if (isLastIteration || remainingQuantity.IsNegative() || remainingQuantity.IsNull()) { throw new MrpRunException("This is one iteration too many."); } if (openDemand != null && provider.GetStartTimeBackward() .IsGreaterThanOrEqualTo(openDemand.GetOpenNode().GetStartTimeBackward())) { // 3 cases Quantity quantityOfOpenDemandToReserve; if (remainingQuantity.IsGreaterThan(openDemand.GetOpenQuantity())) { quantityOfOpenDemandToReserve = openDemand.GetOpenQuantity(); _openDemands.Remove(openDemand); } else if (remainingQuantity.Equals(openDemand.GetOpenQuantity())) { // last iteration isLastIteration = true; quantityOfOpenDemandToReserve = openDemand.GetOpenQuantity(); _openDemands.Remove(openDemand); } else { // last iteration, remaining < openQuantity isLastIteration = true; quantityOfOpenDemandToReserve = new Quantity(remainingQuantity); // adapt openDemand openDemand.GetOpenQuantity().DecrementBy(remainingQuantity); } remainingQuantity.DecrementBy(quantityOfOpenDemandToReserve); T_ProviderToDemand providerToDemand = new T_ProviderToDemand() { ProviderId = provider.GetId().GetValue(), DemandId = openDemand.GetOpenNode().GetId().GetValue(), Quantity = quantityOfOpenDemandToReserve.GetValue() }; entityCollector.Add(providerToDemand); if (remainingQuantity.IsNull() || remainingQuantity.IsNegative()) { break; } } } return(entityCollector); } else { return(null); } }