protected virtual void refreshDistributionCenters() { PXResultset <KCDistributionCenter> existingDistributionCenters = DistributionCenters.Select(); List <string> existingNames = new List <string>(); List <KCAPIDistributionCenter> newCenters = new List <KCAPIDistributionCenter>(); KCSiteMaster connection = Connection.SelectSingle(); KCARestClient client = new KCARestClient(connection); KCInventoryItemAPIHelper helper = new KCInventoryItemAPIHelper(client); FillDistributionCentersFromCA(helper, newCenters); existingDistributionCenters.RowCast <KCDistributionCenter>().ForEach(x => existingNames.Add(x.DistributionCenterName)); foreach (KCAPIDistributionCenter newCenter in newCenters) { if (!existingNames.Contains(newCenter.Name)) { DistributionCenters.Insert(new KCDistributionCenter() { DistributionCenterID = newCenter.ID, DistributionCenterName = newCenter.Name, Code = newCenter.Code }); } } this.Persist(typeof(KCDistributionCenter), PXDBOperation.Insert); foreach (string existingName in existingNames) { if (!newCenters.Any(x => x.Name == existingName)) { KCDistributionCenter item = DistributionCenterByName.SelectSingle(existingName); DistributionCenters.Delete(item); KCInventoryManagement deletedMapping = Mapping.Select().RowCast <KCInventoryManagement>().FirstOrDefault(x => x.DistributionCenterID == item.DistributionCenterID); if (deletedMapping != null) { Mapping.Delete(deletedMapping); } } } bool defaultDcDeleted = DistributionCenters.Cache.Deleted.RowCast <KCDistributionCenter>().Any(x => x.DistributionCenterID == InventoryTrackingRule.Current.DefaultDistributionCenterID); if (InventoryTrackingRule.Current.InventoryTrackingRule == null) { InventoryTrackingRule.Current.InventoryTrackingRule = KCInventoryTrackingRulesConstants.Consolidate; } if (InventoryTrackingRule.Current.DefaultDistributionCenterID == null || defaultDcDeleted) { InventoryTrackingRule.Current.DefaultDistributionCenterID = GetDefaultDistributionCenter(helper, newCenters); } InventoryTrackingRule.Update(InventoryTrackingRule.Current); InventoryTrackingRule.Cache.SetStatus(InventoryTrackingRule.Current, PXEntryStatus.Updated); Connection.Cache.SetStatus(connection, PXEntryStatus.Notchanged); Actions.PressSave(); }
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 DeleteObsoleteBundleComponents(List <KCAPIBundleComponent> bundleComponents, InventoryItem product) { var caid = BulkGraph.KCInventoryItem.SelectSingle(product.InventoryID)?.UsrKCCAID; if (caid.GetValueOrDefault() < 1) { return; } KCDataExchangeMaint graph = PXGraph.CreateInstance <KCDataExchangeMaint>(); KCSiteMaster connection = graph.Connection.SelectSingle(); KCARestClient client = new KCARestClient(connection); KCInventoryItemAPIHelper helper = new KCInventoryItemAPIHelper(client, LoggerProperties); KCODataWrapper <KCAPIBundleComponent> response = helper.GetBundleComponents(caid); if (response == null) { return; } List <KCAPIBundleComponent> cBundleComponents = helper.GetBundleComponents(caid).Value.ToList(); foreach (KCAPIBundleComponent component in cBundleComponents.Where(x => bundleComponents.All(y => y.ComponentSku != x.ComponentSku))) { helper.DeleteBundleComponent(caid, component.ComponentID, product.InventoryCD, component.ComponentID.ToString()); } }
public KCImportOrderRequest(KCStore store, KCSiteMasterMaint siteMasterMaint) { Store = store; SiteMasterMaint = siteMasterMaint; KCSiteMaster connection = SiteMasterMaint.SiteMaster.Select().RowCast <KCSiteMaster>().Where(x => x.SiteMasterCD.Equals(Store.SiteMasterCD)).First(); KCARestClient client = new KCARestClient(connection); Helper = new KCOrderAPIHelper(client); CustomerClassID = connection.CustomerClassID; BranchID = connection.BranchID; }
private void Export(KCDataExchangeMaint graph, List <KeyValuePair <string, InventoryItem> > products, CancellationToken cancellationToken, Dictionary <string, KCAPIInventoryItem> MSMQPrices = null, Dictionary <string, List <KCAPIQuantity> > MSMQQuantityUpdates = null) { KCBulkProductMaint bulkGraph = PXGraph.CreateInstance <KCBulkProductMaint>(); KCSiteMaster connection = graph.Connection.SelectSingle(); KCARestClient client = new KCARestClient(connection); KCBulkUploader bulkUploader = new KCBulkUploader(bulkGraph, logger.LoggerProperties, cancellationToken) { ApiHelper = new KCInventoryItemAPIHelper(client, logger.LoggerProperties), _strategy = new KCFullSync(bulkGraph) }; List <KCBulkProduct> dtos = bulkUploader.HandleItems(products, MSMQPrices, MSMQQuantityUpdates); if (dtos.Count > 0) { string bulkFile = bulkUploader.PrepareItemBulkFile(dtos); string productFilePath = bulkUploader.GenerateProductUploadPath(connection); bulkUploader.UploadFileToFTP(connection, bulkFile, productFilePath); } }
public virtual void updateAttributes() { KCClassificationsMappingMaint classificationsGraph = PXGraph.CreateInstance <KCClassificationsMappingMaint>(); PXResultset <KCAttribute> existingAttributes = Attributes.Select(); List <string> existingNames = new List <string>(); existingAttributes.RowCast <KCAttribute>().ForEach(x => existingNames.Add(x.AttributeName.Trim().ToUpper())); KCSiteMaster connection = Connection.SelectSingle(); KCARestClient client = new KCARestClient(connection); KCInventoryItemAPIHelper helper = new KCInventoryItemAPIHelper(client); List <string> classificationAttributes = classificationsGraph.GetClassificationAttributes(helper); SaveAttributes(existingNames, classificationAttributes); List <string> skuAttributes = new List <string>(); List <KNSIKCClassificationsMapping> SKUs = GetSKUs(); List <int?> CAIDs = new List <int?>(); foreach (KNSIKCClassificationsMapping classificationsMapping in SKUs) { CAIDs.Add(KCGeneralDataHelper.GetExistingCAProductByInventoryItemCd(helper, classificationsMapping.ChannelAdvisorSKU)?.ID); } foreach (int?CAID in CAIDs) { KCODataWrapper <KCAPIAttribute> CAAttributes = helper.GetAttributes(CAID); if (CAAttributes != null && CAAttributes.Value != null && CAAttributes.Value.Count > 0) { List <string> attributeNames = new List <string>(); CAAttributes.Value.ForEach(x => attributeNames.Add(x.Name)); SaveAttributes(existingNames, attributeNames); CAAttributes.Value.ForEach(x => skuAttributes.Add(x.Name)); } } DeleteExtraAttributes(existingAttributes, classificationAttributes, skuAttributes); Actions.PressSave(); }
public virtual void updateClassifications() { PXResultset <KNSIKCClassification> existingClassifications = Classifications.Select(); List <string> existingNames = new List <string>(); List <string> newNames = new List <string>(); KCSiteMaster connection = Connection.SelectSingle(); KCARestClient client = new KCARestClient(connection); KCInventoryItemAPIHelper helper = new KCInventoryItemAPIHelper(client); FillClassificationsFromCA(helper, newNames); existingClassifications.RowCast <KNSIKCClassification>().ForEach(x => existingNames.Add(x.ClassificationName)); foreach (string newName in newNames) { if (!existingNames.Contains(newName)) { Classifications.Insert(new KNSIKCClassification() { ClassificationName = newName }); } } foreach (string existingName in existingNames) { if (!newNames.Contains(existingName)) { KNSIKCClassification item = Classifications.Select().RowCast <KNSIKCClassification>().Where(x => x.ClassificationName.Equals(existingName)).FirstOrDefault(); Classifications.Delete(item); IEnumerable deletedMapping = ClassificationMapping.Select().RowCast <KNSIKCClassificationsMapping>().Where(x => x.ClassificationID == item.ClassificationID); deletedMapping.RowCast <KNSIKCClassificationsMapping>().ForEach(x => { CleanClassificationMapping(ref x); ClassificationMapping.Update(x); }); } } Actions.PressSave(); }
public void ExportProducts(KCStore store, List <KeyValuePair <string, InventoryItem> > productsForExport = null) { DateTime today = DateTime.Now; _store = store; KCSiteMaster connection = Graph.StoreConfig.Select().RowCast <KCSiteMaster>().First(x => x.SiteMasterCD.Equals(store.SiteMasterCD)); KCARestClient client = new KCARestClient(connection); ApiHelper = new KCInventoryItemAPIHelper(client); if (productsForExport == null) { productsForExport = GetProductsForExport(); } List <KCBulkProduct> dtos = HandleItems(productsForExport); foreach (var item in dtos) { var id = Graph.ItemByCD.SelectSingle(item.Product.Sku).InventoryID; ARSalesPrice rec = Graph.KCSalesPrice.SelectSingle("B", id); if (rec != null) { item.Product.RetailPrice = rec.SalesPrice; } } bool anyProductToExport = dtos.Count > 0; if (anyProductToExport) { string bulkFile = PrepareItemBulkFile(dtos); string productFilePath = GenerateProductUploadPath(connection); UploadFileToFTP(connection, bulkFile, productFilePath); } logger.ClearLoggingIds(); logger.Information(anyProductToExport ? KCMessages.BulkUploadSuccess(store.SiteMasterCD) : KCMessages.NoProductsToExport); }
public KCOrderAPIHelper(KCARestClient client) { this.client = client; request = new KCOrderRequest(client.ApiAccessToken); }
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 KCShipmentAPIHelper(KCARestClient client) { this.client = client; request = new KCShipmentRequest(client.ApiAccessToken); }
public void ProcessMessageAPI(KCPriceAndInventoryMessage message) { KCDataExchangeMaint masterGraph = PXGraph.CreateInstance <KCDataExchangeMaint>(); KCSiteMaster connection = masterGraph.Connection.SelectSingle(); KCARestClient client = new KCARestClient(connection); KCInventoryItemAPIHelper helper = new KCInventoryItemAPIHelper(client, logger.LoggerProperties); KCPriceAndInventoryMaint graph = PXGraph.CreateInstance <KCPriceAndInventoryMaint>(); var syncType = KCMSMQQueueHelper.ParseSyncQueueName(message.Address); var syncName = KCMSMQQueueHelper.GetSyncName(syncType); PushNotificationsHook pnHook = graph.PushNotification.SelectSingle(syncName); if (syncType == SyncType.InventoryQuantity) { KCMSMQueueReader quantity = null; try { quantity = new KCMSMQueueReader(pnHook.Address); if (quantity.TryReceiveMessage(message.MessageID, out var msg)) { foreach (object product in msg.Inserted) { KCMSMQInventoryQuantity quantityProduct = JsonConvert.DeserializeObject <KCMSMQInventoryQuantity>(product.ToString()); UpdateSiteQuantity(masterGraph, quantityProduct, helper); } } } finally { quantity?.Dispose(); } } else if (syncType == SyncType.InventoryPrice) { KCMSMQueueReader price = null; try { price = new KCMSMQueueReader(pnHook.Address); if (price.TryReceiveMessage(message.MessageID, out var msg)) { foreach (object product in msg.Inserted) { KCMSMQInventoryPrice priceProduct = JsonConvert.DeserializeObject <KCMSMQInventoryPrice>(product?.ToString()); UpdatePrice(masterGraph, priceProduct, helper); } } } finally { price?.Dispose(); } } else if (syncType == SyncType.VendorQuantity) { KCMSMQueueReader vendor = null; try { vendor = new KCMSMQueueReader(pnHook.Address); if (vendor.TryReceiveMessage(message.MessageID, out var msg)) { foreach (object product in msg.Inserted) { KCMSMQInventoryQuantity quantityProduct = JsonConvert.DeserializeObject <KCMSMQInventoryQuantity>(product.ToString()); UpdateSiteQuantity(masterGraph, quantityProduct, helper); } } } finally { vendor?.Dispose(); } } }
public KCInventoryItemAPIHelper(KCARestClient client, KCLoggerProperties loggerProperties) { this.client = client; request = new KCProductRequest(client.ApiAccessToken); logger = new KCLoggerProvider(loggerProperties); }
public KCInventoryItemAPIHelper(KCARestClient client) { this.client = client; request = new KCProductRequest(client.ApiAccessToken); }