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 KCAPIInventoryItem GetAPIInventoryItem(InventoryItem product) { DAC.KNSIKCInventoryItem kcProduct = BulkGraph.KCInventoryItem.SelectSingle(product.InventoryID); InventoryItemPCExt productPcExt = product.GetExtension <InventoryItemPCExt>(); string classificationName = KCGeneralDataHelper.GetClassificationByInventoryId(ClassificationsGraph, product); KCAPIInventoryItem apiProduct = new KCAPIInventoryItem() { Classification = classificationName }; if (IsConfigurableParentOrChild(product, productPcExt)) { PropagateConfigurable(product, apiProduct, productPcExt.UsrKNCompositeType == null); } if (productPcExt.UsrKNCompositeType == KCConstants.GroupedProduct) { PropagateBundle(product, apiProduct); } if (product.KitItem.GetValueOrDefault()) { PropagateKit(product, apiProduct); } KCDynamicProductMapper mapper = new KCDynamicProductMapper(KCMappingEntitiesConstants.Product); mapper.Mapping.MappingValues = ConversionGraph.GetEntity(product.InventoryCD); apiProduct = mapper.MapApiInventoryItem(apiProduct, product, kcProduct); apiProduct = KCGeneralDataHelper.FillReservedAttributes(product, apiProduct); return(apiProduct); }
public bool CheckBranches(KCSiteMasterMaint sitemaster, List <KCAPIOrderItem> orderItems, KCAPIOrder order) { BAccount customer = KCGeneralDataHelper.GetCustomerByCAOrder(sitemaster, order); if (customer == null) { logger.SetNonChildEntityId(order.ID.ToString()); logger.Information(KCMessages.CustomerNotFound(order.ID, order.BuyerEmailAddress)); return(false); } bool workflowPublished = new KCNamespaceReview().Test(KCConstants.NamespaceTesterPackage); if (workflowPublished) { bool validItem; foreach (KCAPIOrderItem item in orderItems) { DAC.KNSIKCInventoryItem stockItem = sitemaster.ExistingProducts.SelectSingle(item.ProductID); InventoryItem product = sitemaster.ProductByInvId.SelectSingle(stockItem.InventoryID); KCInventoryItemExt productKCExt = product.GetExtension <KCInventoryItemExt>(); validItem = false; if (product.GetExtension <InventoryItemPCExt>().UsrKNCompositeType == null) { if (productKCExt.UsrKNCPBranch != null && customer.GetExtension <KCCustomerExt>()?.UsrKNCPBranchID != null) { List <string> productBranches = productKCExt.UsrKNCPBranch.Split(',').ToList(); foreach (string branch in productBranches) { if (customer.GetExtension <KCCustomerExt>()?.UsrKNCPBranchID?.Split(',').Select(x => x.Trim()).ToList().Contains(branch) == true) { validItem = true; } } } else { validItem = true; } } else { validItem = true; } if (!validItem) { logger.SetNonChildEntityId(order.ID.ToString()); logger.Information(KCMessages.WebsitesAreNotAssociated(order.ID, product.InventoryCD, customer.AcctName)); return(false); } } } return(true); }
public bool CheckFulfillmentItems(KCSOShipmentEntryExt graph, List <KCAPIFulfillmentItem> productsFromAllFulfillments, Dictionary <int?, List <int?> > compositeItems, KCAPIFulfillment currentFulfillment, List <KCAPIOrderItem> orderItems) { foreach (KCAPIFulfillmentItem item in currentFulfillment.Items) { double?orderedCountOfBundles = 0; KCAPIOrderItem orderItem = orderItems.Where(x => x.ID == item.OrderItemID).FirstOrDefault(); if (orderItem.ProductID == item.ProductID) { continue; } foreach (int productID in compositeItems[item.OrderItemID]) { int?itemQuantity = 0; productsFromAllFulfillments.Where(x => x.ProductID == productID && x.OrderItemID == item.OrderItemID).ToList().ForEach(x => itemQuantity += x.Quantity); double?qtyPerBundle = itemQuantity / orderItem.Quantity; DAC.KNSIKCInventoryItem KCItem = graph.KCInventoryItem.SelectSingle(productID); if (KCItem != null) { if (orderedCountOfBundles == 0) { orderedCountOfBundles = itemQuantity / qtyPerBundle; } if (currentFulfillment.Items.Any(x => x.ProductID == productID && x.OrderItemID == item.OrderItemID && x.Quantity / qtyPerBundle == orderedCountOfBundles) && (!productsFromAllFulfillments.Any(x => x.ProductID == productID && x.OrderItemID == item.OrderItemID && x.FulfillmentID != item.FulfillmentID) || (orderedCountOfBundles % 1 == 0 && itemQuantity / qtyPerBundle == orderedCountOfBundles))) { continue; } else { return(false); } } } } return(true); }
public bool CheckOrderItems(List <KCAPIOrderItem> orderItems, KCSiteMasterMaint exchangeMaint) { bool result = false; if (orderItems != null) { foreach (KCAPIOrderItem orderItem in orderItems) { DAC.KNSIKCInventoryItem stockItem = exchangeMaint.ExistingProducts.SelectSingle(orderItem.ProductID); if (stockItem == null) { logger.SetNonChildEntityId(orderItem.OrderID.ToString()); logger.Information(KCMessages.ProductDoesntExist(orderItem.OrderID, orderItem.ProductID)); return(false); } result = true; } } return(result); }
public bool CheckSalesAccountID(KCSiteMasterMaint sitemaster, InventoryItem product, int orderID, int CAProductId) { if (product != null && !product.StkItem.GetValueOrDefault() && (product.SalesAcctID == null || product.SalesSubID == null)) { DAC.KNSIKCInventoryItem KCChild = sitemaster.KCInventoryItem.SelectSingle(product.InventoryID); if (KCChild != null) { logger.SetNonChildEntityId(orderID.ToString()); logger.Information(KCMessages.SalesAcctIDCannotBeEmpty(orderID, KCChild.UsrKCCAID.GetValueOrDefault())); } else { logger.SetNonChildEntityId(orderID.ToString()); logger.Information(KCMessages.SalesAcctIDCannotBeEmpty(orderID, CAProductId)); } return(false); } return(true); }
public bool CheckProductStatus(KCSiteMasterMaint sitemaster, InventoryItem product, int orderID, int CAProductId) { if (product != null && product.ItemStatus != KCConstants.Active) { DAC.KNSIKCInventoryItem KCChild = sitemaster.KCInventoryItem.SelectSingle(product.InventoryID); if (KCChild != null) { logger.SetNonChildEntityId(orderID.ToString()); logger.Information(KCMessages.ProductDoesntActive(orderID, KCChild.UsrKCCAID.GetValueOrDefault())); } else { logger.SetNonChildEntityId(orderID.ToString()); logger.Information(KCMessages.ProductDoesntActive(orderID, CAProductId)); } return(false); } return(true); }
public bool ValidateItems <T>(List <T> items, Validation method, KCSiteMasterMaint sitemaster) { bool result = false; List <KCAPIOrderItem> orderItems; List <KCAPIFulfillmentItem> filfillmentItems; if (items as List <KCAPIOrderItem> != null) { orderItems = items as List <KCAPIOrderItem>; } if (items as List <KCAPIFulfillmentItem> != null) { filfillmentItems = items as List <KCAPIFulfillmentItem>; } if (items != null) { foreach (T item in items) { KCAPIOrderItem orderItem = null; KCAPIFulfillmentItem fulfillmetItem = null; if (item as KCAPIOrderItem != null) { orderItem = item as KCAPIOrderItem; } if (item as KCAPIFulfillmentItem != null) { fulfillmetItem = item as KCAPIFulfillmentItem; } int productID = 0; int orderID = 0; if (orderItem == null) { productID = fulfillmetItem.ProductID; orderID = fulfillmetItem.OrderID; } else { productID = orderItem.ProductID; orderID = orderItem.OrderID; } DAC.KNSIKCInventoryItem stockItem = sitemaster.ExistingProducts.SelectSingle(productID); InventoryItem inventoryItem = sitemaster.ProductByInvId.SelectSingle(stockItem.InventoryID); if (inventoryItem != null) { if (!method(sitemaster, inventoryItem, orderID, productID)) { return(false); } else if (inventoryItem.GetExtension <InventoryItemPCExt>().UsrKNCompositeType == KCConstants.ConfigurableProduct) { PXResultset <InventoryItem> childItems = sitemaster.ConfigChildItems.Select(inventoryItem.InventoryID); foreach (InventoryItem child in childItems) { if (!method(sitemaster, child, orderID, productID)) { return(false); } } } else if (inventoryItem.GetExtension <InventoryItemPCExt>().UsrKNCompositeType == KCConstants.GroupedProduct) { PXResultset <KNSIGroupedItems> childItems = sitemaster.GroupedChildItems.Select(inventoryItem.InventoryID); foreach (KNSIGroupedItems child in childItems) { InventoryItem product = sitemaster.ProductByInvId.SelectSingle(child.MappedInventoryID); if (!method(sitemaster, product, orderID, productID)) { return(false); } } } else if (inventoryItem.KitItem.GetValueOrDefault()) { string revisionId = sitemaster.KitProduct.SelectSingle(inventoryItem.InventoryID)?.RevisionID; IEnumerable <INKitSpecNonStkDet> nonStockKitComponents = sitemaster.NonStockKitComponents.Select(inventoryItem.InventoryID, revisionId)?.RowCast <INKitSpecNonStkDet>(); foreach (INKitSpecNonStkDet child in nonStockKitComponents) { InventoryItem product = sitemaster.ProductByInvId.SelectSingle(child.CompInventoryID); if (!method(sitemaster, product, orderID, productID)) { return(false); } } } } result = true; } } return(result); }