public PackingOrderModel SetItemBatchAllocation(BatchAllocationChangeRequest request) { WebSession.EnsureUserRight(OrdersPackingUserRights.OrderBatchAssignment); PackingOrderModel result; using (var tx = m_database.OpenTransaction()) { var order = m_orderRepository.GetOrder(request.OrderId); if (order == null) { throw new InvalidOperationException("Objednávka nebyla v systému nalezena"); } if (!string.IsNullOrWhiteSpace(request.OriginalBatchNumber)) { m_batchFacade.ChangeOrderItemBatchAssignment( order, request.OrderItemId, request.OriginalBatchNumber, request.NewAmount); order = m_orderRepository.GetOrder(order.Id); if (request.NewAmount > 0m) { request.NewBatchSearchQuery = request.NewBatchSearchQuery ?? request.OriginalBatchNumber; } } var item = m_ordersFacade.GetAllConcreteOrderItems(order).FirstOrDefault(i => i.Id == request.OrderItemId).Ensure(); if (!string.IsNullOrWhiteSpace(request.NewBatchSearchQuery) && ((request.NewAmount ?? item.Quantity) > 0m)) { var material = m_virtualProductFacade.GetOrderItemMaterialForSingleUnit(order, item); var batch = m_batchFacade.FindBatchBySearchQuery(material.MaterialId, request.NewBatchSearchQuery); result = MapOrder( order, new Tuple <long, BatchKey, decimal>(item.Id, batch, request.NewAmount ?? item.Quantity)); } else { result = MapOrder(order); } tx.Commit(); return(result); } }
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); }