private void SetupBatchAssignment( PackingOrderItemModel item, IEnumerable <OrderItemBatchAssignmentModel> assignments) { var models = new List <BatchAssignmentViewModel>(); foreach (var assignment in assignments) { var viewModel = models.FirstOrDefault(m => m.BatchNumber.Equals(assignment.BatchNumber, StringComparison.InvariantCultureIgnoreCase)); if (viewModel == null) { viewModel = new BatchAssignmentViewModel(assignment); models.Add(viewModel); } else { viewModel.Add(assignment); } } foreach (var model in models) { model.CanSplit = item.NumericQuantity > 1m; model.IsSplit = models.Count > 1; } item.BatchAssignment.AddRange(models); }
private PackingOrderModel MapOrder(IPurchaseOrder entity, Tuple <long, BatchKey, decimal> orderItemBatchPreference = null) { entity = m_ordersFacade.ResolveSingleItemKitSelection(entity); var batchAssignments = m_batchFacade.TryResolveBatchAssignments(entity, orderItemBatchPreference).ToList(); var orderModel = new PackingOrderModel { OrderId = entity.Id, OrderNumber = entity.OrderNumber, CustomerEmail = entity.CustomerEmail, CustomerName = entity.CustomerName, CustomerNote = entity.CustomerNote, InternalNote = entity.InternalNote, ErpName = entity.Erp?.Description, DiscountsText = entity.DiscountsText, Price = $"{StringUtil.FormatDecimal(entity.PriceWithVat)} {entity.Currency.Symbol}" }; foreach (var sourceItem in entity.Items.OrderBy(i => i.Id)) { var item = new PackingOrderItemModel { ProductName = sourceItem.PlacedName, ItemId = sourceItem.Id, Quantity = StringUtil.FormatDecimal(sourceItem.Quantity), NumericQuantity = sourceItem.Quantity }; var kitItems = new List <KitItemsCollectionModel>(); foreach (var sourceKitItem in m_kitProductRepository.GetKitForOrderItem(entity, sourceItem).OrderBy(ki => ki.KitItemIndex)) { var model = new KitItemsCollectionModel(sourceKitItem); if (sourceKitItem.SelectedItem != null) { var selitem = new PackingOrderItemModel { ProductName = sourceKitItem.SelectedItem.PlacedName, ItemId = sourceKitItem.SelectedItem.Id, Quantity = StringUtil.FormatDecimal(sourceKitItem.SelectedItem.Quantity), NumericQuantity = sourceKitItem.SelectedItem.Quantity }; SetupBatchAssignment(selitem, batchAssignments.Where(a => a.OrderItemId == sourceKitItem.SelectedItem.Id)); model.SelectedItemModel = selitem; } kitItems.Add(model); } item.KitItems.AddRange(kitItems); SetupBatchAssignment(item, batchAssignments.Where(a => a.OrderItemId == sourceItem.Id)); orderModel.Items.Add(item); } return(orderModel); }
private void ValidateItemBatches(PackingOrderItemModel item) { if (item.KitItems.Any()) { foreach (var kitItem in item.KitItems.Where(i => i.SelectedItemModel != null)) { ValidateItemBatches(kitItem.SelectedItemModel); } return; } ValidateItemBatches(item.ProductName, item.NumericQuantity, item.BatchAssignment); }