public ODataShipment GetAPIShipment(SOShipment shipment, SOPackageDetail package, PXResultset <SOLine> lines) { var wrapper = new ODataShipment(); var apiShipment = new KCAPIShipment() { ShippedDateUtc = shipment.ShipDate, TrackingNumber = package?.TrackNumber, ShippingCarrier = shipment.ShipVia, ShippingClass = shipment.ShipVia, DeliveryStatus = "Complete" }; var apiItems = new List <KCAPIShipmentItem>(); foreach (PXResult <SOLine> line in lines) { SOLine soLine = line.GetItem <SOLine>(); SOShipLine shipLine = line.GetItem <SOShipLine>(); DAC.KNSIKCInventoryItem kcInventoryItem = line.GetItem <DAC.KNSIKCInventoryItem>(); InventoryItem inventoryItem = line.GetItem <InventoryItem>(); InventoryItemPCExt inventoryItemPcExt = inventoryItem.GetExtension <InventoryItemPCExt>(); SOLinePCExt soLinePcExt = soLine.GetExtension <SOLinePCExt>(); int quantity = Convert.ToInt32(shipLine.ShippedQty.GetValueOrDefault()); if ((soLine.LineNbr != soLinePcExt?.UsrKNMasterLineNbr && ParentIsGrouped(lines, soLinePcExt)) || (inventoryItemPcExt?.UsrKNCompositeType == KCConstants.ConfigurableProduct && soLine.LineNbr == soLinePcExt?.UsrKNMasterLineNbr)) { continue; } if (inventoryItemPcExt?.UsrKNCompositeType == KCConstants.GroupedProduct && quantity == 0) { SOShipLine childItem = lines.Where(x => x.GetItem <SOLine>().GetExtension <SOLinePCExt>().UsrKNMasterLineNbr == soLine.LineNbr && x.GetItem <SOLine>().LineNbr != soLine.LineNbr).RowCast <SOShipLine>().FirstOrDefault(); if (childItem != null) { KCDataExchangeMaint graph = PXGraph.CreateInstance <KCDataExchangeMaint>(); List <KNSIGroupedItems> origChildItems = graph.GroupedChildItems.Select(inventoryItem.InventoryID).RowCast <KNSIGroupedItems>().ToList(); quantity = Convert.ToInt32(childItem.ShippedQty / origChildItems.Where(x => x.MappedInventoryID == childItem.InventoryID).FirstOrDefault().Quantity); } else { throw new KCCorruptedShipmentException(); } } apiItems.Add(new KCAPIShipmentItem { ProductID = kcInventoryItem?.UsrKCCAID.ToString(), OrderItemID = soLine?.GetExtension <KCSOLineExt>()?.UsrKCOrderItemID.ToString(), Quantity = shipLine == null ? 0 : Convert.ToInt32(quantity) }); } apiShipment.Items = apiItems; wrapper.Value = apiShipment; return(wrapper); }
public KCErrorResponse MarkTheOrderAsShipped(ODataShipment shipment, int?orderId) { return(client.Post <KCErrorResponse>(request.AddShipment(shipment, orderId))); }