コード例 #1
0
        public BatchReportModel Get(BatchReportQuery query)
        {
            if (query == null)
            {
                query = new BatchReportQuery
                {
                    PageNumber = 0
                };
            }

            return(m_reportingFacade.QueryBatches(query));
        }
コード例 #2
0
        public BatchReportModel QueryBatches(BatchReportQuery query)
        {
            if (query.LoadOrdersPage != null)
            {
                return(LoadOrders(query.ToKey(), query.LoadOrdersPage.Value));
            }
            else if (query.LoadSaleEventsPage != null)
            {
                return(LoadSaleEvents(query.ToKey(), query.LoadSaleEventsPage.Value));
            }
            else if (query.LoadSegmentsPage != null)
            {
                return(LoadSegments(query.ToKey(), query.LoadSegmentsPage.Value));
            }
            else if (query.LoadPriceComponentsPage != null)
            {
                return(LoadPriceComponents(query.ToKey(), query.LoadPriceComponentsPage.Value));
            }

            var pageSize   = query.HasKey ? 1 : c_pageSize;
            var pageNumber = query.HasKey ? 0 : query.PageNumber;

            IPurchaseOrder order = null;

            if (query.RelativeToOrderId != null)
            {
                order = m_orderRepository.GetOrder(query.RelativeToOrderId.Value);

                if (order == null)
                {
                    throw new InvalidOperationException("Invalid entity reference");
                }

                pageSize   = 1000;
                pageNumber = 0;
            }

            var sql = m_database.Sql().Call("LoadBatchesReport")
                      .WithParam("@projectId", m_session.Project.Id)
                      .WithParam("@pageSize", pageSize)
                      .WithParam("@pageNumber", pageNumber)
                      .WithParam("@batchId", query.HasKey ? query.ToKey().UnsafeToString() : null)
                      .WithParam("@materialId", query.MaterialId)
                      .WithParam("@orderNumber", ToProperNull(query.OrderNumber))
                      .WithParam("@batchNumber", ToProperNull(query.BatchNumberQuery?.Replace("*", "%")))
                      .WithParam("@dtFrom", query.From)
                      .WithParam("@dtTo", query.To)
                      .WithParam("@closed", query.ClosedBatches)
                      .WithParam("@locked", query.LockedBatches)
                      .WithParam("@inventoryTypeId", query.InventoryTypeId)
                      .WithParam("@onlyProduced", query.ProducedOnly)
                      .WithParam("@onlyBought", query.PurchasedOnly)
                      .WithParam("@compositionId", query.CompositionId)
                      .WithParam("@componentId", query.ComponentId)
                      .WithParam("@orderId", query.RelativeToOrderId)
                      .WithParam("@onlyBlocking", query.BlockedBatchesOnly)
                      .WithParam("@segmentId", query.SegmentId)
                      .WithParam("@invoiceNr", ToProperNull(query.InvoiceNr));

            var result = new BatchReportModel {
                Query = query
            };

            var rawEntries = sql.MapRows(MapEntry);

            result.Report.AddRange(rawEntries);
            result.CanLoadMore = (result.Report.Count == c_pageSize);

            foreach (var b in result.Report.OfType <BatchReportEntry>())
            {
                var material = m_materialRepository.GetMaterialById(b.MaterialId);

                if (b.IsClosed)
                {
                    b.AvailableAmount = "0";
                }
                else
                {
                    /*
                     * var available = m_batchFacade.GetAvailableAmount(b.BatchKey);
                     * b.AvailableAmount = $"{StringUtil.FormatDecimal(available.Value)} {available.Unit.Symbol}";
                     * b.Available = available;
                     */
                    var available = new Amount(b.AvailableAmountValue, m_unitRepository.GetUnit(b.AvailableAmountUnitId));

                    available         = m_amountProcessor.Convert(available, material.NominalUnit);
                    b.AvailableAmount = $"{StringUtil.FormatDecimal(available.Value)} {available.Unit.Symbol}";
                    b.Available       = available;
                }

                var totalUnit   = m_unitRepository.GetUnitBySymbol(b.TotalAmountUnitName);
                var totalAmount = new Amount(b.TotalAmountValue, totalUnit);
                totalAmount = m_amountProcessor.Convert(totalAmount, material.NominalUnit);

                b.BatchVolume = $"{StringUtil.FormatDecimal(totalAmount.Value)} {totalAmount.Unit.Symbol}";

                //b.NoDelReason = m_batchFacade.GetDeletionBlockReasons(b.BatchId).FirstOrDefault();
                b.CanDelete = !(b.HasStockEvents || b.NumberOfCompositions > 0 || b.NumberOfOrders > 0 || b.NumberOfSaleEvents > 0);

                if (b.HasStockEvents)
                {
                    PopulateStockEventCounts(b);
                }

                PopulateStockEventSuggestions(b);
            }

            if ((query.HasKey) && (result.Report.Count == 0))
            {
                result.Report.Add(new DeletedBatchReportEntry(query.ToKey()));
                return(result);
            }

            if (query.CompositionId != null)
            {
                PopulateComponentAmounts(BatchKey.Parse(query.CompositionId), result.Report);
                result.CustomField1Name = "Použito";
            }
            else if (query.ComponentId != null)
            {
                PopulateCompositionAmounts(BatchKey.Parse(query.ComponentId), result.Report);
                result.CustomField1Name = "Použito";
            }
            else if (query.RelativeToOrderId != null)
            {
                result.Report           = PopulateRelativeToOrder(order, result.Report);
                result.CustomField1Name = "Množství";
                result.CustomField3Name = "Položka";
                result.CustomField2Name = "Balil";
            }

            return(result);
        }