示例#1
0
        private BatchReportEntry MapEntry(DbDataReader row)
        {
            #region Column ordinals
            const int batchId               = 0;
            const int inventoryName         = 1;
            const int batchNumber           = 2;
            const int materialName          = 3;
            const int materialId            = 4;
            const int batchVolume           = 5;
            const int unit                  = 6;
            const int batchCreateDt         = 7;
            const int batchCloseDt          = 8;
            const int batchLockDt           = 9;
            const int batchAvailable        = 10;
            const int batchProductionDt     = 11;
            const int numberOfComponents    = 13;
            const int numberOfCompositions  = 14;
            const int numberOfOrders        = 16;
            const int price                 = 17;
            const int invoiceNr             = 18;
            const int numberOfStockEvents   = 19;
            const int numberOfSaleEvents    = 20;
            const int numberOfSegments      = 21;
            const int availableAmountValue  = 22;
            const int availableAmountUnitId = 23;
            #endregion

            var key = BatchKey.Parse(row.GetString(batchId));

            var entry = new BatchReportEntry(key)
            {
                InventoryName        = row.GetString(inventoryName),
                BatchNumber          = row.IsDBNull(batchNumber) ? "?" : row.GetString(batchNumber),
                MaterialName         = row.GetString(materialName),
                MaterialId           = row.GetInt32(materialId),
                CreateDt             = StringUtil.FormatDateTime(row.GetDateTime(batchCreateDt)),
                IsClosed             = !row.IsDBNull(batchCloseDt),
                IsLocked             = !row.IsDBNull(batchLockDt),
                IsAvailable          = row.GetBoolean(batchAvailable),
                NumberOfComponents   = row.GetInt32(numberOfComponents),
                NumberOfCompositions = row.GetInt32(numberOfCompositions),
                NumberOfOrders       = row.GetInt32(numberOfOrders),
                Price                 = row.IsDBNull(price) ? string.Empty : $"{StringUtil.FormatDecimal(row.GetDecimal(price))} CZK",
                InvoiceNumber         = row.IsDBNull(invoiceNr) ? string.Empty : string.Join(", ", row.GetString(invoiceNr).Split(';').Distinct()),
                HasStockEvents        = (!row.IsDBNull(numberOfStockEvents)) && (row.GetInt32(numberOfStockEvents) > 0),
                NumberOfSaleEvents    = row.GetInt32(numberOfSaleEvents),
                NumberOfSegments      = row.GetInt32(numberOfSegments),
                AvailableAmountValue  = row.GetDecimal(availableAmountValue),
                AvailableAmountUnitId = row.GetInt32(availableAmountUnitId),
                TotalAmountValue      = row.GetDecimal(batchVolume),
                TotalAmountUnitName   = row.GetString(unit)
            };

            return(entry);
        }
示例#2
0
        private void PopulateStockEventCounts(BatchReportEntry batchReportEntry)
        {
            foreach (var evt in m_stockEventRepository.GetBatchEvents(batchReportEntry.BatchKey))
            {
                int sum;
                if (!batchReportEntry.StockEventCounts.TryGetValue(evt.Type.TabTitle, out sum))
                {
                    sum = 0;
                }

                batchReportEntry.StockEventCounts[evt.Type.TabTitle] = sum + 1;
            }
        }
示例#3
0
        private void PopulateStockEventSuggestions(BatchReportEntry batchReportEntry)
        {
            if (batchReportEntry.Available?.IsNotPositive ?? true)
            {
                return;
            }

            Func <IStockEventType, Amount, BatchStockEventSuggestion> addSuggestion = (type, amount) =>
            {
                var manipulationAmount = m_amountProcessor.ToSmallestUnit(amount);

                var sug = new BatchStockEventSuggestion()
                {
                    BatchNumber  = batchReportEntry.BatchNumber,
                    Amount       = manipulationAmount.Value,
                    EventTypeId  = type.Id,
                    MaterialId   = batchReportEntry.MaterialId,
                    MaterialName = batchReportEntry.MaterialName,
                    UnitSymbol   = manipulationAmount.Unit.Symbol,
                    Title        = $"{type.Name} {StringUtil.FormatDecimal(amount.Value)} {amount.Unit.Symbol}"
                };

                batchReportEntry.EventSuggestions.Add(sug);

                return(sug);
            };

            foreach (var eventType in m_stockEventRepository.GetAllEventTypes())
            {
                if (batchReportEntry.Available.Unit.IntegerOnly)
                {
                    addSuggestion(eventType, new Amount(1m, batchReportEntry.Available.Unit));
                }

                addSuggestion(eventType, batchReportEntry.Available);
            }
        }
示例#4
0
        private List <BatchReportEntryBase> PopulateRelativeToOrder(IPurchaseOrder order, List <BatchReportEntryBase> batches)
        {
            var concreteItems = m_ordersFacade.GetAllConcreteOrderItems(order).ToList();
            var result        = new List <BatchReportEntryBase>(concreteItems.Count * 2);

            foreach (var orderItem in concreteItems)
            {
                var itemName = orderItem.KitParent?.PlacedName ?? orderItem.PlacedName;

                var assignedBatches = orderItem.AssignedBatches.ToList();
                if (!assignedBatches.Any())
                {
                    assignedBatches.Add(null);
                }

                foreach (var assignment in assignedBatches)
                {
                    var assignmentBatchKey = new BatchKey(assignment.MaterialBatchId);

                    var assignmentBatchMaterialId = assignmentBatchKey.GetMaterialId(m_batchFacade);
                    var assignmentBatchNumber     = assignmentBatchKey.GetBatchNumber(m_batchFacade);

                    var sourceRecord = batches.OfType <BatchReportEntry>().FirstOrDefault(b => b.MaterialId == assignmentBatchMaterialId && b.BatchNumber.Equals(assignmentBatchNumber, StringComparison.InvariantCultureIgnoreCase));

                    var user = assignment == null ? string.Empty : m_userRepository.GetUserNick(assignment.UserId);

                    var reportRow = new BatchReportEntry(BatchKey.Parse(sourceRecord.BatchId))
                    {
                        CustomField1         = StringUtil.FormatDecimal(assignment?.Quantity ?? orderItem.Quantity),
                        CustomField2         = user,
                        CustomField3         = itemName,
                        InventoryName        = sourceRecord?.InventoryName,
                        BatchNumber          = sourceRecord?.BatchNumber ?? string.Empty,
                        MaterialName         = sourceRecord?.MaterialName ?? string.Empty,
                        MaterialId           = sourceRecord?.MaterialId ?? -1,
                        BatchVolume          = sourceRecord?.BatchVolume ?? string.Empty,
                        AvailableAmount      = sourceRecord?.AvailableAmount ?? string.Empty,
                        CreateDt             = sourceRecord?.CreateDt ?? string.Empty,
                        IsClosed             = sourceRecord?.IsClosed ?? false,
                        IsLocked             = sourceRecord?.IsLocked ?? false,
                        IsAvailable          = sourceRecord?.IsAvailable ?? false,
                        NumberOfComponents   = sourceRecord?.NumberOfComponents ?? 0,
                        NumberOfCompositions = sourceRecord?.NumberOfCompositions ?? 0,
                        NumberOfOrders       = sourceRecord?.NumberOfOrders ?? 0,
                        Price              = sourceRecord?.Price ?? string.Empty,
                        InvoiceNumber      = sourceRecord?.InvoiceNumber ?? string.Empty,
                        NumberOfSaleEvents = sourceRecord?.NumberOfSaleEvents ?? 0,
                        NumberOfSegments   = sourceRecord?.NumberOfSegments ?? 0
                    };

                    result.Add(reportRow);
                }
            }

            result.Sort(
                new GenericComparer <BatchReportEntryBase>(
                    (a, b) =>
                    string.Compare((a as BatchReportEntry)?.CustomField2,
                                   (b as BatchReportEntry)?.CustomField2,
                                   StringComparison.Ordinal)));

            return(result);
        }