Esempio n. 1
0
        public void Process(ProductionRequestContext context)
        {
            if ((context.Request.ProducingAmount ?? 0m) < 0.00001m)
            {
                context.Request.ProducingAmount = 0;
                context.InvalidateRequest("Je třeba zadat množství");
            }
            else
            {
                if (context.Request.PriceCalcAmount != (context.Request.ProducingAmount ?? 0m))
                {
                    if (context.Recipe.ProductionPricePerUnit != null)
                    {
                        context.Request.ProducingPrice =
                            context.Recipe.ProductionPricePerUnit * (context.Request.ProducingAmount ?? 0);
                    }

                    context.Request.PriceCalcAmount = (context.Request.ProducingAmount ?? 0m);
                }
            }

            if ((context.Request.ProducingPrice ?? 0m) < 0.001m)
            {
                if (context.TargetMaterial.RequiresProductionPrice != true)
                {
                    context.Request.ProducingPrice = 0m;
                }
                else
                {
                    context.InvalidateRequest("Je třeba zadat cenu práce");
                }
            }
        }
Esempio n. 2
0
        public void Process(ProductionRequestContext context)
        {
            var material = m_materialFacade.GetMaterialInfo(context.Recipe.ProducedMaterialId);

            context.Request.MaterialName = material.MaterialName;

            // Batch number
            if (string.IsNullOrWhiteSpace(context.Request.ProducingBatchNumber))
            {
                if (material.AutomaticBatches)
                {
                    context.Request.ProducingBatchNumber = material.AutoBatchNr;
                }
                else
                {
                    context.InvalidateRequest("Nutno vyplnit číslo šarže");
                }
            }

            // Unit
            while (true)
            {
                if (string.IsNullOrWhiteSpace(context.Request.ProducingUnitSymbol))
                {
                    context.Request.ProducingUnitSymbol = material.PreferredUnitSymbol;
                    break;
                }

                if (!context.Request.ProducingUnitSymbol.Equals(material.PreferredUnitSymbol, StringComparison.InvariantCultureIgnoreCase))
                {
                    var usedUnit = m_unitRepository.GetUnitBySymbol(context.Request.ProducingUnitSymbol.Trim());
                    if (usedUnit == null)
                    {
                        context.Request.ProducingUnitSymbol = null;
                        continue;
                    }

                    var mainUnit = m_unitRepository.GetUnitBySymbol(material.PreferredUnitSymbol);
                    if (!m_conversionHelper.AreCompatible(usedUnit.Id, mainUnit.Id))
                    {
                        context.Request.ProducingUnitSymbol = null;
                        continue;
                    }
                }

                break;
            }

            context.RequestedAmount     = new Amount(context.Request.ProducingAmount ?? 0m, m_unitRepository.GetUnitBySymbol(context.Request.ProducingUnitSymbol));
            context.NominalRecipeAmount = new Amount(context.Recipe.RecipeProducedAmount, m_unitRepository.GetUnit(context.Recipe.ProducedAmountUnitId));

            var commonUnit = m_conversionHelper.GetSmallestCompatibleUnit(context.RequestedAmount.Unit);

            var convertedRequestedAmount = m_conversionHelper.ConvertAmount(context.RequestedAmount, commonUnit.Id);
            var convertedNominalAmount   = m_conversionHelper.ConvertAmount(context.NominalRecipeAmount, commonUnit.Id);

            context.ComponentMultiplier = convertedRequestedAmount.Value / convertedNominalAmount.Value;

            if (context.MinimalAmount != null && m_amountProcessor.GreaterThan(context.MinimalAmount, context.RequestedAmount))
            {
                context.InvalidateRequest($"Nové množství nesmí být méně než {context.MinimalAmount}, protože tolik již bylo spotřebováno");
            }
        }