public void RetrieveChannelAdvisorIds(KCStore store) { KCDataExchangeMaint graph = PXGraph.CreateInstance <KCDataExchangeMaint>(); KCSiteMaster connection = graph.Connection.Select().RowCast <KCSiteMaster>().First(x => x.SiteMasterCD.Equals(store.SiteMasterCD)); KCARestClient client = new KCARestClient(connection); KCInventoryItemAPIHelper helper = new KCInventoryItemAPIHelper(client); foreach (KCAPIIdSkuJuxtaposion juxtaposion in helper.GetAllIdSkuJuxtaposions()) { InventoryItem item = graph.ItemByCd.SelectSingle(juxtaposion.Sku); if (item == null) { continue; } KNSIKCInventoryItem cItem = graph.KCInventoryItem.SelectSingle(item.InventoryID); if (cItem != null && cItem.UsrKCActiveOnCa.GetValueOrDefault()) { cItem.UsrKCCAID = juxtaposion.ID; cItem.UsrKCCAParentID = juxtaposion.ParentProductID.ToString(); graph.KCInventoryItem.Update(cItem); } } graph.Actions.PressSave(); if (logger != null) { logger.ClearLoggingIds(); logger.Information(KCMessages.ProductIdsRetrievalSuccess); } }
public void ExportShipments(KCStore store) { if (store.DateTo < store.DateFrom) { throw new PXException(KCMessages.DateToBiggerThanDateFrom); } if (store.DateTo.GetValueOrDefault() != default) { store.DateTo = store.DateTo.GetValueOrDefault().AddDays(1); } bool anyExported = false; KCDataExchangeMaint graph = PXGraph.CreateInstance <KCDataExchangeMaint>(); SOOrderShipmentProcess orderShipmentGraph = PXGraph.CreateInstance <SOOrderShipmentProcess>(); KCSiteMaster connection = graph.Connection.Select().RowCast <KCSiteMaster>().Where(x => x.SiteMasterCD.Equals(store.SiteMasterCD)).First(); KCARestClient client = new KCARestClient(connection); KCOrderAPIHelper helperOrder = new KCOrderAPIHelper(client); KCShipmentAPIHelper helperShipment = new KCShipmentAPIHelper(client); List <SOOrder> orders = graph.Orders.Select().RowCast <SOOrder>().Where(x => x.GetExtension <KCSOOrderExt>().UsrKCSiteName?.EndsWith("/Non-FBA") == true).ToList(); foreach (SOOrder order in orders) { IEnumerable <SOOrderShipment> orderShipments = KCGeneralDataHelper.GetOrderShipmentsByOrderNbr(graph, order.OrderNbr); if (orderShipments == null) { continue; } foreach (SOOrderShipment orderShipment in orderShipments) { if (!CheckData(orderShipment, store.DateFrom, store.DateTo)) { continue; } PXResultset <SOLine> lines = graph.OrderLines.Select(orderShipment.ShipmentNbr); SOShipment shipment = KCGeneralDataHelper.GetShipmentByShipmentNbr(orderShipmentGraph, orderShipment.ShipmentNbr); if (!CheckShippingCarrier(helperShipment, shipment)) { logger.Information(KCMessages.ShipViaDoesnotExist(shipment.ShipmentNbr)); continue; } KCSOShipmentExt shipmentKCExt = shipment?.GetExtension <KCSOShipmentExt>(); SOPackageDetail package = KCGeneralDataHelper.GetPackageByShipmentNbr(orderShipmentGraph, orderShipment.ShipmentNbr); KCSOOrderExt orderExt = order.GetExtension <KCSOOrderExt>(); KCMapShipment shipmentMapper = new KCMapShipment(); int?customerOrderNbr = Convert.ToInt32(order.CustomerOrderNbr); if (shipment != null && orderShipment.Confirmed.GetValueOrDefault() && KCGeneralDataHelper.GetExistingCAOrderById(helperOrder, customerOrderNbr) != null && shipmentKCExt?.UsrKCExported != true) { string log; KCErrorResponse response = new KCErrorResponse(); logger.SetParentAndEntityIds(order.OrderNbr, shipment.ShipmentNbr); try { response = helperShipment.MarkTheOrderAsShipped(shipmentMapper.GetAPIShipment(shipment, package, lines), customerOrderNbr); } catch (Exception ex) { log = KCMessages.CorruptedShipment(shipment.ShipmentNbr); logger.Information(log); continue; } if (response != null) { log = KCMessages.ShipmentExportFailure(shipment.ShipmentNbr, response.Error.Message); } else { shipmentKCExt.UsrKCExported = true; orderShipmentGraph.Shipments.Update(shipment); orderShipmentGraph.Save.Press(); anyExported = true; log = KCMessages.ShipmentExported(shipment.ShipmentNbr); } logger.Information(log); } } } logger.ClearLoggingIds(); logger.Information(anyExported ? KCMessages.ShipmentExportSuccess : KCMessages.NoShipmentsToExport); }
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); }