Esempio n. 1
0
        private void ProcessResolutions(ProductionRequest request, IRecipeComponent recipeComponent, ProductionComponent requestComponent, decimal multiplier, DateTime sourceBatchesMadeBefore)
        {
            if (TryProcessTransformationInput(request, recipeComponent, requestComponent) && (!requestComponent.IsValid))
            {
                return;
            }

            var requiredAmount = new Amount(recipeComponent.Amount * multiplier, m_unitRepository.GetUnit(recipeComponent.UnitId));

            ClearUserAllocationsIfQuantityChanged(requestComponent, requiredAmount);

            var requiredBatchNr = recipeComponent.IsTransformationInput ? request.ProducingBatchNumber : null;
            var resolutions     = m_batchFacade.ResolveMaterialDemand(
                recipeComponent.MaterialId,
                requiredAmount,
                requiredBatchNr,
                false,
                true,
                sourceBatchesMadeBefore,
                request.SourceSegmentId);

            RemoveComponentsNotProposedBySystem(requestComponent, resolutions, requiredAmount);
            AddMissingComponents(requestComponent, resolutions, requiredAmount, request.SourceSegmentId != null && request.IsFirstRound);

            var userAllocatedAmount =
                m_amountProcessor.Sum(requestComponent.Resolutions.Where(r => r.GetAmount(m_unitRepository) != null)
                                      .Select(r => r.GetAmount(m_unitRepository))) ?? new Amount(0, requiredAmount.Unit);

            var remaining = m_amountProcessor.Subtract(requiredAmount, userAllocatedAmount);

            if (!resolutions.CompletelyAllocated)
            {
                requestComponent.Invalidate("Potřebné množství není dostupné");
            }

            if (remaining.IsPositive)
            {
                //seems we allocated the requested amount
                requestComponent.Invalidate($"Zbývá vložit {remaining}");
            }
            else if (remaining.IsNegative)
            {
                requestComponent.Invalidate($"Přebývá {m_amountProcessor.Neg(remaining)}");
            }
        }
Esempio n. 2
0
        private static bool TryProcessTransformationInput(ProductionRequest request, IRecipeComponent recipeComponent,
                                                          ProductionComponent requestComponent)
        {
            if (recipeComponent.IsTransformationInput)
            {
                for (var i = requestComponent.Resolutions.Count - 1; i >= 0; i--)
                {
                    if (requestComponent.Resolutions[i].BatchNumber
                        ?.Equals(request.ProducingBatchNumber ?? string.Empty) != true)
                    {
                        requestComponent.Resolutions.RemoveAt(i);
                    }
                }

                if (string.IsNullOrWhiteSpace(request.ProducingBatchNumber))
                {
                    requestComponent.Invalidate("Receptura vyžaduje shodné číslo šarže");
                }

                return(true);
            }

            return(false);
        }