public bool Populate(ISaleEventAllocation entity, AmountProcessor amountProcessor) { if (SaleEventId != 0 && SaleEventId != entity.SaleEventId) { return(false); } SaleEventId = entity.SaleEventId; if (string.IsNullOrWhiteSpace(EventName)) { EventName = entity.SaleEvent.Name; SortDt = entity.ReturnDt ?? entity.AllocationDt; Author = entity.AllocationUser?.EMail; } m_blockedAmount = amountProcessor.Add(m_blockedAmount, new Amount(entity.AllocatedQuantity, entity.Unit)); m_returnedAmount = amountProcessor.Add(m_returnedAmount, new Amount(entity.ReturnedQuantity ?? 0m, entity.Unit)); if (m_returnedAmount == null) { m_usedAmount = m_blockedAmount; } m_usedAmount = amountProcessor.Subtract(m_blockedAmount, m_returnedAmount); return(true); }
public static IEnumerable <MaterialBatchViewModel> JoinAutomaticBatches(IEnumerable <MaterialBatchViewModel> source, AmountProcessor processor) { var targetList = new List <MaterialBatchViewModel>(); foreach (var batch in source.OrderBy(i => i.MaterialId)) { if (batch.AutomaticBatches && (targetList.LastOrDefault()?.MaterialId == batch.MaterialId)) { var joined = targetList.Last(); joined.BatchNumber = null; joined.Id = null; var sum = processor.Add(processor.ToAmount(batch.Volume, batch.UnitName), processor.ToAmount(joined.Volume, joined.UnitName)); joined.UnitName = sum.Unit.Symbol; joined.Volume = sum.Value; continue; } targetList.Add(batch); } return(targetList); }
private void PopulateCompositionAmounts(BatchKey componentBatchId, List <BatchReportEntryBase> report) { foreach (var reportRow in report.OfType <BatchReportEntry>()) { var componentBatches = m_batchRepository.GetBatches(componentBatchId).ToList(); if (!componentBatches.Any()) { continue; } Amount theAmount = null; foreach (var compnentBatch in componentBatches) { foreach (var compositionBatch in m_batchRepository.GetBatches(reportRow.BatchKey)) { foreach (var componentEntity in compositionBatch.Components) { var componentBatch = componentEntity.Component; if (componentBatch.MaterialId != componentBatchId.GetMaterialId(m_batchRepository) || (!componentBatch.BatchNumber.Equals(componentBatchId.GetBatchNumber(m_batchRepository), StringComparison.InvariantCultureIgnoreCase))) { continue; } var usedAmount = new Amount(componentEntity.Volume, componentEntity.Unit); theAmount = m_amountProcessor.Add(theAmount, usedAmount); } } } reportRow.CustomField1 = theAmount?.ToString(); } }
public MaterialLevelModel GetMaterialLevel(int materialId) { PreloadBatchAmountCache(); return(m_cache.ReadThrough(GetMaterialLevelCacheKey(materialId), TimeSpan.FromDays(1), () => { var material = m_materialRepository.GetMaterialById(materialId); if (material == null) { return null; } var amount = new Amount(0, material.NominalUnit); var batches = m_batchRepository.GetBatchIds(DateTime.Now.AddYears(-10), DateTime.Now.AddYears(1), materialId: material.Id); foreach (var batchId in batches) { amount = m_amountProcessor.Add(amount, GetAvailableAmount(batchId)); } var threshold = m_materialThresholdRepository.GetThreshold(materialId) ?? CreateFakeThreshold(material, amount); var amountUnitThreshold = m_conversionHelper.ConvertAmount( new Amount(threshold.ThresholdQuantity, m_unitRepository.GetUnit(threshold.UnitId)), amount.Unit.Id); return new MaterialLevelModel { MaterialId = material.Id, MaterialName = material.Name, ActualValue = amount.Value, MaxValue = amountUnitThreshold.Value * 10m, MinValue = amountUnitThreshold.Value, PercentLevel = GetPercentLevel(amountUnitThreshold.Value * 10m, amount.Value), UnitId = amount.Unit.Id, Unit = amount.Unit.Symbol, HasThreshold = threshold.Id > 0 }; })); }
public void Join(StockEventViewModel rawEvent, AmountProcessor amountProcessor) { m_amount = amountProcessor.Add(m_amount, rawEvent.m_amount); }