Exemplo n.º 1
0
        private MaterialBatchComponent MapToModel(IMaterialBatch entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new MaterialBatchComponent(new MaterialBatchAdapter(entity, m_serviceLocator), this);

            return(model);
        }
Exemplo n.º 2
0
        public void ApplyComponents(MaterialBatchComponent sourceSegment, ProductionRequestContext context)
        {
            var recipeComponents = m_recipeRepository.GetRecipe(sourceSegment.Batch.RecipeId.Ensure("Segment nevznikl z existující receptury, nelze změnit")).Components.OrderBy(c => c.SortOrder);

            var requestComponents = context.Request.Components;

            foreach (var recipeComponent in recipeComponents)
            {
                var compo = new ProductionComponent
                {
                    MaterialId   = recipeComponent.MaterialId,
                    MaterialName = m_materialRepository.GetMaterialById(recipeComponent.MaterialId).Ensure().Name,
                    SortOrder    = recipeComponent.SortOrder
                };
                requestComponents.Add(compo);

                var resolutions = sourceSegment.Components.Where(c => c.Batch.MaterialId == recipeComponent.MaterialId);

                var resIndex      = new Dictionary <string, ProductionComponentResolution>();
                var componentUnit = m_unitRepository.GetUnit(recipeComponent.UnitId);

                foreach (var r in resolutions)
                {
                    var resolutionAmount  = m_amountProcessor.Convert(new Amount(r.ComponentAmount, r.ComponentUnit), componentUnit);
                    var batchAvailability = m_amountProcessor.Convert(m_batchFacade.GetAvailableAmount(r.Batch.Id), componentUnit);

                    if (!resIndex.TryGetValue(r.Batch.BatchNumber, out var resolution))
                    {
                        resolution = new ProductionComponentResolution
                        {
                            Amount = resolutionAmount.Value,
                            BatchAvailableAmount     = batchAvailability.Value,
                            BatchAvailableAmountText = batchAvailability.ToString(),
                            BatchCreationDt          = StringUtil.FormatDate(r.Batch.Created),
                            BatchNumber = r.Batch.BatchNumber,
                            Key         = Guid.NewGuid().ToString(),
                            Sorter      = r.Batch.Created.Ticks,
                            UnitSymbol  = componentUnit.Symbol
                        };
                        compo.Resolutions.Add(resolution);
                        resIndex.Add(r.Batch.BatchNumber, resolution);
                    }
                    else
                    {
                        resolution.Amount += resolutionAmount.Value;
                    }
                }

                compo.LastClientAmount = m_amountProcessor
                                         .Sum(compo.Resolutions.Select(r => r.GetAmount(m_unitRepository)))?.ToString();
            }
        }