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()); } }
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 virtual void VerifyApiAccessPermission() { KCSiteMaster row = SiteMaster.Current; if (row == null) { return; } if (row.ApplicationId != "" && row.SharedSecret != "") { PXLongOperation.StartOperation(this, delegate() { KCInternalReponse response = new KCSiteMasterHelper().VerifyApiAccess(row); if (response != null) { if (!response.IsSuccess && !string.IsNullOrEmpty(response.Message)) { throw new PXException(response.Message); } else if (!string.IsNullOrEmpty(response.Message)) { PXTrace.WriteInformation(response.Message); } } else { string exceptionmsg = string.Format(KCConstants.DualParameters, KCConstants.VerifyApiAccess, KCMessages.NullException); throw new PXException(exceptionmsg); } }); } }
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 virtual void VerifyFtpAccess() { KCSiteMaster row = SiteMaster.Current; if (row == null) { return; } PXLongOperation.StartOperation(this, delegate() { try { using (WebClient client = new WebClient()) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; FtpWebRequest ftpWebRequest = (FtpWebRequest)WebRequest.Create("ftp://" + row.FTPHostname); ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory; ftpWebRequest.EnableSsl = true; ftpWebRequest.Credentials = new NetworkCredential(row.FTPUsername, row.FTPPassword); client.Encoding = Encoding.UTF8; ftpWebRequest.GetResponse(); } } catch (Exception e) { throw new PXException(e.Message); } }); }
public KCARestClient(KCSiteMaster xSiteMaster) { this._xSiteMaster = xSiteMaster; BASE_URL = xSiteMaster?.BaseUrl; _restClient = new KCRestApiClient(KCSinglet.JsonSerializer, "https://api.channeladvisor.com"); GetAccessToken(); }
protected virtual void KCSiteMaster_RowUpdating(PXCache sender, PXRowUpdatingEventArgs e) { if (e.Row == null) { return; } KCSiteMaster row = (KCSiteMaster)e.Row; }
protected KCBasicBulkStrategy(KCBulkProductMaint graph) { Graph = graph; ProductsForUpdate = new PXSelectJoin <InventoryItem, LeftJoin <KNSIKCInventoryItem, On <InventoryItem.inventoryID, Equal <KNSIKCInventoryItem.inventoryID> > >, Where <KNSIKCInventoryItem.usrKCActiveOnCa, Equal <True> > >(graph); SiteMaster = Graph.SiteMaster.SelectSingle(); }
protected virtual void KCSiteMaster_DefaultShippingMethod_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e) { if (e.Row == null) { return; } KCSiteMaster row = (KCSiteMaster)e.Row; row.DefaultBox = null; }
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 static int?GetThresholdValue() { KCSiteMasterMaint graph = PXGraph.CreateInstance <KCSiteMasterMaint>(); KCSiteMaster siteMaster = PXSelect <KCSiteMaster> .Select(graph).FirstOrDefault(); if (siteMaster == null) { throw new Exception(); } return(siteMaster.MessageQueueThresholdValue); }
public override void Persist() { if (SiteMaster.Current != null) { object devConfirmPassword = SiteMaster.Current.DevConfirmPassword; SiteMaster.Cache.RaiseFieldVerifying <KCSiteMaster.devConfirmPassword>(SiteMaster.Current, ref devConfirmPassword); object ftpConfirmPassword = SiteMaster.Current.FTPConfirmPassword; SiteMaster.Cache.RaiseFieldVerifying <KCSiteMaster.fTPConfirmPassword>(SiteMaster.Current, ref ftpConfirmPassword); KCSiteMaster siteExists = PXSelectReadonly <KCSiteMaster, Where <KCSiteMaster.accountId, Equal <Required <KCSiteMaster.accountId> >, And <KCSiteMaster.siteMasterCD, NotEqual <Required <KCSiteMaster.siteMasterCD> > > > > .Select(this, SiteMaster.Current.AccountId, SiteMaster.Current.SiteMasterCD); if (siteExists != null) { string msg = KCMessages.AlreadyExistAccountId; SiteMaster.Cache.RaiseExceptionHandling <KCSiteMaster.accountId>(SiteMaster.Current, SiteMaster.Current.AccountId, new PXSetPropertyException <KCSiteMaster.accountId>(msg)); throw new PXSetPropertyException <KCSiteMaster.accountId>(msg); } } var isCATaxZoneExist = TaxZoneId.SelectSingle(KCConstants.Channel); var isCATaxExist = TaxId.SelectSingle(KCConstants.ChannelAdvisor); SalesTaxMaint stax = PXGraph.CreateInstance <SalesTaxMaint>(); TaxZoneMaint CAtaxzone = PXGraph.CreateInstance <TaxZoneMaint>(); Tax tax = stax.Tax.Insert(); TaxZone newTaxZone = CAtaxzone.TxZone.Insert(); TaxZoneDet taxZoneDet = CAtaxzone.TxZoneDet.Insert(); if (isCATaxExist == null) { stax.Tax.Cache.SetValue <Tax.taxID>(tax, KCConstants.ChannelAdvisor); stax.Tax.Cache.SetValue <Tax.descr>(tax, KCConstants.ChannelAdvisor); stax.Tax.Cache.SetValue <Tax.salesTaxAcctID>(tax, KCConstants.salesTaxAcctID); stax.Tax.Cache.SetValue <Tax.salesTaxSubID>(tax, KCConstants.salesTaxSubID); stax.Tax.Cache.SetValue <Tax.taxCalcType>(tax, KCConstants.taxCalcType); stax.Tax.Cache.SetValue <Tax.taxCalcLevel>(tax, KCConstants.taxCalcLevel); stax.Persist(); } if (isCATaxZoneExist == null) { CAtaxzone.TxZone.Cache.SetValue <TaxZone.taxZoneID>(newTaxZone, KCConstants.Channel); CAtaxzone.TxZone.Cache.SetValue <TaxZone.descr>(newTaxZone, KCConstants.Channel); CAtaxzone.TxZone.Cache.SetValue <TaxZone.dfltTaxCategoryID>(newTaxZone, KCConstants.Taxable); CAtaxzone.TxZoneDet.Cache.SetValue <TaxZoneDet.taxZoneID>(taxZoneDet, newTaxZone.TaxZoneID); CAtaxzone.TxZoneDet.Cache.SetValue <TaxZoneDet.taxID>(taxZoneDet, KCConstants.ChannelAdvisor); CAtaxzone.Persist(); } base.Persist(); }
protected virtual void _(Events.FieldSelecting <KCSiteMaster, KCSiteMaster.apiResponse> e) { KCSiteMaster row = (KCSiteMaster)e.Row; if (row == null) { return; } if (row != null) { if (row.BaseUrl == null || row.BaseUrl == "") { e.ReturnValue = "https://api.channeladvisor.com/ChannelAdvisorAPI/v7/AdminService.asmx"; } } }
protected virtual void _(Events.FieldSelecting <KCSiteMaster, KCSiteMaster.endpointAddressValueShipment> e) { KCSiteMaster row = (KCSiteMaster)e.Row; if (row == null) { return; } if (row != null) { if (row.EndpointAddressValueShipment == null || row.EndpointAddressValueShipment == "") { e.ReturnValue = "https://api.channeladvisor.com/ChannelAdvisorAPI/v7/ShippingService.asmx"; } } }
protected virtual void _(Events.FieldSelecting <KCSiteMaster, KCSiteMaster.soapCaptionHeader> e) { KCSiteMaster row = (KCSiteMaster)e.Row; if (row == null) { return; } if (row != null) { if (row.BaseUrl == null || row.BaseUrl == "") { e.ReturnValue = "\"http://api.channeladvisor.com/webservices/RequestAccess\""; } } }
protected virtual void _(Events.FieldSelecting <KCSiteMaster, KCSiteMaster.envelop> e) { KCSiteMaster row = (KCSiteMaster)e.Row; if (row == null) { return; } if (row != null) { if (row.BaseUrl == null || row.BaseUrl == "") { e.ReturnValue = "http://schemas.xmlsoap.org/soap/envelope/"; } } }
protected virtual void _(Events.FieldSelecting <KCSiteMaster, KCSiteMaster.chacheControlHeader> e) { KCSiteMaster row = (KCSiteMaster)e.Row; if (row == null) { return; } if (row != null) { if (row.BaseUrl == null || row.BaseUrl == "") { e.ReturnValue = "no-cache"; } } }
protected virtual void _(Events.RowSelected <KCSiteMaster> e) { if (e.Row == null) { return; } KCSiteMaster row = (KCSiteMaster)e.Row; if (row != null) { PXRSACryptStringAttribute.SetDecrypted <KCSiteMaster.devPassword>(e.Cache, row, true); PXRSACryptStringAttribute.SetDecrypted <KCSiteMaster.devConfirmPassword>(e.Cache, row, true); PXRSACryptStringAttribute.SetDecrypted <KCSiteMaster.fTPPassword>(e.Cache, row, true); PXRSACryptStringAttribute.SetDecrypted <KCSiteMaster.fTPConfirmPassword>(e.Cache, row, true); } }
protected virtual void _(Events.FieldSelecting <KCSiteMaster, KCSiteMaster.webservices> e) { KCSiteMaster row = (KCSiteMaster)e.Row; if (row == null) { return; } if (row != null) { if (row.BaseUrl == null || row.BaseUrl == "") { e.ReturnValue = "http://api.channeladvisor.com/webservices/"; } } }
public void KCInventoryTrackingRule_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { if (e.Row == null) { return; } KCInventoryTrackingRule row = (KCInventoryTrackingRule)e.Row; KCSiteMaster siteMaster = Connection.SelectSingle(); if (siteMaster != null) { siteMaster.IncludeVendorInventory = row.IncludeVendorInventory; siteMaster.InventoryTrackingRule = row.InventoryTrackingRule; siteMaster.DefaultDistributionCenterID = row.DefaultDistributionCenterID; Connection.Update(siteMaster); } }
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 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 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(); }
protected virtual void _(Events.FieldVerifying <KCSiteMaster, KCSiteMaster.devConfirmPassword> e) { KCSiteMaster row = (KCSiteMaster)e.Row; if (row == null) { return; } if (row != null) { string NewValue = e.NewValue != null?e.NewValue.ToString().Trim() : ""; string DevPassword = !string.IsNullOrEmpty(row.DevPassword) ? row.DevPassword.Trim() : ""; if (!DevPassword.Equals(NewValue) && !string.IsNullOrEmpty(DevPassword)) { string msg = KCMessages.DevConfirmPassword; SiteMaster.Cache.RaiseExceptionHandling <KCSiteMaster.devConfirmPassword>(e.Row, row.DevConfirmPassword, new PXSetPropertyException <KCSiteMaster.devConfirmPassword>(msg)); throw new PXSetPropertyException <KCSiteMaster.devConfirmPassword>(msg); } } }
public KCInternalReponse VerifyApiAccess(KCSiteMaster xSiteMaster) { try { KCInternalReponse response = new KCInternalReponse(); if (xSiteMaster != null) { xSiteMaster.ApplicationId = !string.IsNullOrEmpty(xSiteMaster.ApplicationId) ? xSiteMaster.ApplicationId.Trim() : ""; xSiteMaster.SharedSecret = !string.IsNullOrEmpty(xSiteMaster.SharedSecret) ? xSiteMaster.SharedSecret.Trim() : ""; xSiteMaster.RefreshToken = !string.IsNullOrEmpty(xSiteMaster.RefreshToken) ? xSiteMaster.RefreshToken.Trim() : ""; } byte[] bytes = Encoding.UTF8.GetBytes(string.Format("{0}:{1}", xSiteMaster.ApplicationId, xSiteMaster.SharedSecret)); WebHeaderCollection headers = new WebHeaderCollection(); headers["Authorization"] = "Basic " + Convert.ToBase64String(bytes); headers["Cache-Control"] = "no-cache"; string reqbody = "grant_type=refresh_token&refresh_token=" + xSiteMaster.RefreshToken; var apiresponse = KCApiHelper.CallWebAPI("https://api.channeladvisor.com/oauth2/token", reqbody, "POST", headers); if (apiresponse == null) { PXTrace.WriteError(KCConstants.VerifyApiAccess + " - " + KCMessages.NullException); response.IsSuccess = false; response.Message = KCMessages.VerifyApiAccessFailed; } if (apiresponse.IsSuccess) { var rootthread = JsonConvert.DeserializeObject <KCAPIAccessToken>(apiresponse.response); if (rootthread != null) { response.IsSuccess = true; response.Message = KCMessages.VerifyApiAccessSuccess; response.Data = apiresponse.response; } else { string errormsg = string.Format(KCConstants.DualParameters, KCConstants.VerifyApiAccess, apiresponse.Message); PXTrace.WriteError(errormsg); response.IsSuccess = false; response.Message = KCMessages.VerifyApiAccessFailed; } } else { string errormsg = string.Format(KCConstants.DualParameters, KCConstants.VerifyApiAccess, apiresponse.Message); PXTrace.WriteError(errormsg); response.IsSuccess = false; response.Message = KCMessages.VerifyApiAccessFailed; } return(response); } catch (Exception ex) { string errormsg = string.Format(KCConstants.DualParameters, KCMessages.VerifyApiAccessFailed, ex.Message); PXTrace.WriteError(errormsg); KCInternalReponse response = new KCInternalReponse(); response.IsSuccess = false; response.Message = errormsg; return(response); } }
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 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 KCInternalReponse RequestAPIAccess(KCSiteMaster xSiteMaster) { KCInternalReponse response = new KCInternalReponse(); try { WebHeaderCollection headers = new WebHeaderCollection(); headers["Cache-Control"] = xSiteMaster.ChacheControlHeader; headers["soapaction"] = xSiteMaster.SoapCaptionHeader; string reqbody = "<soapenv:Envelope xmlns:soapenv=\"" + xSiteMaster.Envelop + "\" xmlns:web=\"" + xSiteMaster.Webservices + "\">\r\n <soapenv:Header>\r\n <web:APICredentials>\r\n <web:DeveloperKey>" + xSiteMaster.DevKey + "</web:DeveloperKey>\r\n <web:Password>" + xSiteMaster.DevPassword + "</web:Password>\r\n </web:APICredentials>\r\n </soapenv:Header>\r\n <soapenv:Body>\r\n <web:RequestAccess>\r\n <web:localID>" + xSiteMaster.ProfileId + "</web:localID>\r\n </web:RequestAccess>\r\n </soapenv:Body>\r\n</soapenv:Envelope>"; var apiresponse = KCApiHelper.CallWebAPI(xSiteMaster.ApiResponse, reqbody, "POST", headers, "text/xml; charset=utf-8"); if (apiresponse == null) { PXTrace.WriteError(KCConstants.RequestApiAccess + " - " + KCMessages.NullException); response.IsSuccess = false; response.Message = string.Format(KCMessages.RequestApiAccessFailed, ""); } if (apiresponse.IsSuccess) { XmlDocument doc = new XmlDocument(); doc.LoadXml(apiresponse.response); string json = JsonConvert.SerializeXmlNode(doc); if (json != null) { JObject obj = JsonConvert.DeserializeObject <JObject>(json); JObject innerObj = obj["soap:Envelope"] as JObject; JObject lolSummorLvl = innerObj["soap:Body"] as JObject; JObject lolSummorLvl2 = lolSummorLvl["RequestAccessResponse"] as JObject; JObject lolSummorLvl3 = lolSummorLvl2["RequestAccessResult"] as JObject; string status = (string)lolSummorLvl3["Status"]; string MessageCode = (string)lolSummorLvl3["MessageCode"]; string Message = ""; if (status == KCConstants.Failure) { Message = (string)lolSummorLvl3["Message"]; } string ResultData = (string)lolSummorLvl3["ResultData"]; if (status != KCConstants.Failure) { response.IsSuccess = true; response.Message = KCMessages.RequestApiAccessSuccess; } else { string errormsg = string.Format(KCConstants.DualParameters, KCConstants.RequestApiAccess, Message); PXTrace.WriteError(errormsg); response.IsSuccess = false; response.Message = string.Format(KCMessages.RequestApiAccessFailed, Message); } } else { string errormsg = string.Format(KCConstants.DualParameters, KCConstants.RequestApiAccess, KCMessages.XmlNullException); PXTrace.WriteError(errormsg); PXTrace.WriteError(KCConstants.RequestApiAccess + " - " + KCMessages.XmlNullException); response.IsSuccess = false; response.Message = string.Format(KCMessages.RequestApiAccessFailed, ""); } } else { string errormsg = string.Format(KCConstants.DualParameters, KCConstants.RequestApiAccess, apiresponse.Message); PXTrace.WriteError(errormsg); response.IsSuccess = false; response.Message = string.Format(KCMessages.RequestApiAccessFailed, ""); } return(response); } catch (Exception ex) { string errormsg = string.Format(KCConstants.DualParameters, KCConstants.RequestApiAccess, ex.Message); PXTrace.WriteError(errormsg); response.IsSuccess = false; response.Message = string.Format(KCMessages.RequestApiAccessFailed, ex.Message); return(response); } }
protected virtual void KCSiteMaster_SiteMasterCD_FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e) { KCSiteMaster row = (KCSiteMaster)e.Row; }