예제 #1
0
        private BatchReportModel LoadSaleEvents(BatchKey key, int pageNumber)
        {
            var events = m_saleEventRepository.GetAllocationsByBatch(key).ToList();

            var aggregatedAllocations = new List <SaleEventAllocationModel>(events.Count);

            foreach (var evt in events)
            {
                if (aggregatedAllocations.Any(ag => ag.Populate(evt, m_amountProcessor)))
                {
                    continue;
                }

                var newRecord = new SaleEventAllocationModel();
                newRecord.Populate(evt, m_amountProcessor);
                aggregatedAllocations.Add(newRecord);
            }

            var entry = new BatchSaleEventsReportEntry(key);

            entry.SaleEvents.AddRange(aggregatedAllocations.OrderByDescending(a => a.SortDt));

            var result = new BatchReportModel();

            result.Report.Add(entry);

            return(result);
        }
예제 #2
0
        public SaleEventModel ExportEvent(int eventId)
        {
            var saleEvent = m_saleEventRepository.GetEventById(eventId).Ensure();

            var model = GetSaleEventModelTemplate();

            model.Id   = saleEvent.Id;
            model.Name = saleEvent.Name;

            if (saleEvent.Allocations.Any())
            {
                model.AllocDate = saleEvent.Allocations.Min(a => a.AllocationDt);
            }

            var allocations = saleEvent.Allocations.ToList();

            if (allocations.Any(a => a.ReturnDt != null))
            {
                model.ReturnDate = allocations.Where(a => a.ReturnDt != null).Min(e => e.ReturnDt.Value);
            }

            model.Items.Clear();

            var itemIndex = new Dictionary <string, SaleEventAllocationModel>();

            foreach (var alo in saleEvent.Allocations.OrderBy(a => a.Id))
            {
                var key = $"{alo.Batch.MaterialId}:{alo.Batch.BatchNumber}";

                if (itemIndex.TryGetValue(key, out var item))
                {
                    item.AllocatedQuantity += alo.AllocatedQuantity;

                    if (alo.ReturnedQuantity != null)
                    {
                        item.ReturnQuantity = (item.ReturnQuantity ?? 0m) + alo.ReturnedQuantity.Value;
                    }

                    continue;
                }

                item = new SaleEventAllocationModel
                {
                    AllocatedQuantity    = alo.AllocatedQuantity,
                    AllocationUnitSymbol = alo.Unit.Symbol,
                    BatchNumber          = alo.Batch.BatchNumber,
                    MaterialName         = alo.Batch.Material.Name,
                    ReturnQuantity       = alo.ReturnedQuantity
                };

                itemIndex.Add(key, item);

                model.Items.Add(item);
            }

            return(model);
        }