private static IResult <SetSalesOrderItemParameters> ToParsedParameters(this ISalesOrderItem orderItem) { if (orderItem == null) { throw new ArgumentNullException("orderItem"); } IContractItemKey contractItemKey = null; if (!string.IsNullOrWhiteSpace(orderItem.ContractItemKey)) { var contractItemKeyResult = KeyParserHelper.ParseResult <IContractItemKey>(orderItem.ContractItemKey); if (!contractItemKeyResult.Success) { return(contractItemKeyResult.ConvertTo <SetSalesOrderItemParameters>()); } contractItemKey = contractItemKeyResult.ResultingObject; } var productKeyResult = KeyParserHelper.ParseResult <IProductKey>(orderItem.ProductKey); if (!productKeyResult.Success) { return(productKeyResult.ConvertTo <SetSalesOrderItemParameters>()); } var packagingProductKeyResult = KeyParserHelper.ParseResult <IPackagingProductKey>(orderItem.PackagingKey); if (!packagingProductKeyResult.Success) { return(packagingProductKeyResult.ConvertTo <SetSalesOrderItemParameters>()); } var treatmentKeyResult = KeyParserHelper.ParseResult <IInventoryTreatmentKey>(orderItem.TreatmentKey); if (!treatmentKeyResult.Success) { return(treatmentKeyResult.ConvertTo <SetSalesOrderItemParameters>()); } return(new SuccessResult <SetSalesOrderItemParameters>(new SetSalesOrderItemParameters { SalesOrderItem = orderItem, ContractItemKey = contractItemKey == null ? null : contractItemKey.ToContractItemKey(), ProductKey = productKeyResult.ResultingObject.ToProductKey(), PackagingProductKey = packagingProductKeyResult.ResultingObject.ToPackagingProductKey(), InventoryTreatmentKey = treatmentKeyResult.ResultingObject.ToInventoryTreatmentKey() })); }
public static ContractItemKey ToContractItemKey(this IContractItemKey k) { return(new ContractItemKey(k)); }
internal static SalesOrderItem ConstrainByKeys(this SalesOrderItem item, ISalesOrderKey order = null, IContractItemKey contractItem = null, IChileProductKey chileProduct = null, IPackagingProductKey packagingProduct = null, IInventoryTreatmentKey treatment = null) { if (item == null) { throw new ArgumentNullException("item"); } if (order != null) { item.Order = null; item.DateCreated = order.SalesOrderKey_DateCreated; item.Sequence = order.SalesOrderKey_Sequence; if (item.InventoryPickOrderItem != null) { item.InventoryPickOrderItem.InventoryPickOrder = null; } } if (contractItem != null) { item.ContractItem = null; item.ContractYear = contractItem.ContractKey_Year; item.ContractSequence = contractItem.ContractKey_Sequence; item.ContractItemSequence = contractItem.ContractItemKey_Sequence; } if (chileProduct != null) { item.InventoryPickOrderItem.Product = null; item.InventoryPickOrderItem.ProductId = chileProduct.ChileProductKey_ProductId; } if (packagingProduct != null) { item.InventoryPickOrderItem.PackagingProduct = null; item.InventoryPickOrderItem.PackagingProductId = packagingProduct.PackagingProductKey_ProductId; } if (treatment != null) { item.InventoryPickOrderItem.InventoryTreatment = null; item.InventoryPickOrderItem.TreatmentId = treatment.InventoryTreatmentKey_Id; } return(item); }
private SalesOrderLoad SetItems(SalesOrderLoad order, tblOrderDTO oldOrder) { var orderItemSequence = 0; var pickedItemSequence = 0; order.SalesOrderItems = new List <SalesOrderItem>(); order.SalesOrderPickedItems = new List <SalesOrderPickedItem>(); var latestStaged = oldOrder.tblOrderDetails.SelectMany(d => d.tblStagedFGs) .OrderByDescending(s => s.EntryDate) .FirstOrDefault(); if (latestStaged != null) { order.InventoryShipmentOrder.PickedInventory.TimeStamp = latestStaged.EntryDate.ConvertLocalToUTC(); if (latestStaged.EmployeeID != null) { order.InventoryShipmentOrder.PickedInventory.EmployeeId = latestStaged.EmployeeID.Value; } } foreach (var detail in oldOrder.tblOrderDetails) { LoadCount.AddRead(EntityType.SalesOrderItem); var product = _newContextHelper.GetProduct(detail.ProdID); if (product == null) { Log(new CallbackParameters(CallbackReason.DetailProductNotFound) { Order = oldOrder, Detail = detail }); continue; } var packaging = _newContextHelper.GetPackagingProduct(detail.PkgID); if (packaging == null) { Log(new CallbackParameters(CallbackReason.DetailPackagingNotFound) { Order = oldOrder, Detail = detail }); continue; } var treatment = _newContextHelper.NoTreatment; if (detail.TrtmtID != null) { treatment = _newContextHelper.GetInventoryTreatment(detail.TrtmtID.Value); if (treatment == null) { Log(new CallbackParameters(CallbackReason.DetailTreatmentNotFound) { Order = oldOrder, Detail = detail }); continue; } } IContractItemKey contractItemKey = null; if (detail.KDetailID != null) { contractItemKey = _newContextHelper.GetContractItemKey(detail.KDetailID); if (contractItemKey == null) { Log(new CallbackParameters(CallbackReason.ContractItemNotFound) { Order = oldOrder, Detail = detail }); continue; } } order.SalesOrderItems.Add(new SalesOrderItem { ItemSequence = orderItemSequence, ContractYear = contractItemKey == null ? (int?)null : contractItemKey.ContractKey_Year, ContractSequence = contractItemKey == null ? (int?)null : contractItemKey.ContractKey_Sequence, ContractItemSequence = contractItemKey == null ? (int?)null : contractItemKey.ContractItemKey_Sequence, PriceBase = (double)(detail.Price ?? 0), PriceFreight = (double)(detail.FreightP ?? 0), PriceTreatment = (double)(detail.TrtnmntP ?? 0), PriceWarehouse = (double)(detail.WHCostP ?? 0), PriceRebate = (double)(detail.Rebate ?? 0), ODetail = detail.ODetail, InventoryPickOrderItem = new InventoryPickOrderItem { ItemSequence = orderItemSequence, ProductId = product.ProductKey.ProductKey_ProductId, PackagingProductId = packaging.Id, TreatmentId = treatment.Id, Quantity = (int)(detail.Quantity ?? 0), CustomerLotCode = detail.CustLot, CustomerProductCode = detail.CustProductCode, } }); foreach (var staged in detail.tblStagedFGs) { LoadCount.AddRead(EntityType.SalesOrderPickedItem); LotKey lotKey; if (!LotNumberParser.ParseLotNumber(staged.Lot, out lotKey)) { Log(new CallbackParameters(CallbackReason.StagedInvalidLotNumber) { Order = oldOrder, Staged = staged }); continue; } packaging = _newContextHelper.GetPackagingProduct(staged.PkgID); if (packaging == null) { Log(new CallbackParameters(CallbackReason.StagedPackagingNotFound) { Order = oldOrder, Staged = staged }); continue; } var currentLocation = _newContextHelper.GetLocation(staged.LocID); if (currentLocation == null) { Log(new CallbackParameters(CallbackReason.StagedLocationNotFound) { Order = oldOrder, Staged = staged }); continue; } var fromLocation = detail.tblOutgoing.Any() ? DeterminePickedFromLocation(detail, staged) : currentLocation; if (fromLocation == null) { Log(new CallbackParameters(CallbackReason.UndeterminedPickedFromLocation) { Order = oldOrder, Staged = staged }); continue; } treatment = _newContextHelper.GetInventoryTreatment(staged.TrtmtID); if (treatment == null) { Log(new CallbackParameters(CallbackReason.StagedTreatmentNotFound) { Order = oldOrder, Staged = staged }); continue; } order.SalesOrderPickedItems.Add(new SalesOrderPickedItem { ItemSequence = pickedItemSequence, OrderItemSequence = orderItemSequence, PickedInventoryItem = new PickedInventoryItem { DetailID = staged.EntryDate, ItemSequence = pickedItemSequence, LotDateCreated = lotKey.LotKey_DateCreated, LotDateSequence = lotKey.LotKey_DateSequence, LotTypeId = lotKey.LotKey_LotTypeId, Quantity = (int)(staged.Quantity ?? 0), PackagingProductId = packaging.Id, FromLocationId = fromLocation.Id, CurrentLocationId = currentLocation.Id, TreatmentId = treatment.Id, ToteKey = "", CustomerLotCode = staged.CustLot, CustomerProductCode = staged.CustProductCode } }); pickedItemSequence++; } orderItemSequence++; } return(order); }