Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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 static int?GetCAIDByInventoryId(KCDataExchangeMaint graph, KCInventoryItemAPIHelper helper, int?id)
        {
            InventoryItem         product      = graph.ProductByInvId.Select(id);
            KCAPIInventoryItemIDs existingItem = GetExistingCAProductByInventoryItemCd(helper, product.InventoryCD);

            return(existingItem?.ID);
        }
Esempio n. 5
0
        public static KCAPIBundleComponent GetAPIGroupedBundleComponent(KCInventoryItemAPIHelper helper, int?productId, KNSIGroupedItems component)
        {
            KCDataExchangeMaint graph = PXGraph.CreateInstance <KCDataExchangeMaint>();

            return(new KCAPIBundleComponent()
            {
                ProductID = productId.GetValueOrDefault(),
                ComponentID = KCGeneralDataHelper.GetCAIDByInventoryId(graph, helper, component.MappedInventoryID).GetValueOrDefault(),
                Quantity = Convert.ToInt32(component.Quantity)
            });
        }
Esempio n. 6
0
        public void FillClassificationsFromCA(KCInventoryItemAPIHelper helper, List <string> newNames)
        {
            APIResultOfArrayOfClassificationConfigurationInformation classifications = helper.GetClassifications();

            try
            {
                classifications.ResultData.ForEach(x => newNames.Add(x.Name));
            }
            catch (System.ArgumentNullException ex)
            {
                throw new PXException(KCMessages.NoClassificationsFound);
            }
        }
        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();
        }
Esempio n. 8
0
        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();
        }
Esempio n. 9
0
        public List <string> GetClassificationAttributes(KCInventoryItemAPIHelper helper)
        {
            List <KNSIKCClassificationsMapping> classificationsMapping = GetMappedClassifications();
            List <string> classificationsAttributes = new List <string>();

            APIResultOfArrayOfClassificationConfigurationInformation classifications = helper.GetClassifications();
            List <ClassificationConfigurationInformationAttribute[]> attributeArrays = new List <ClassificationConfigurationInformationAttribute[]>();

            if (classifications.ResultData == null)
            {
                throw new PXException(KCMessages.NoClassificationsFound);
            }
            foreach (ClassificationConfigurationInformation classification in classifications.ResultData)
            {
                KNSIKCClassification savedClassification = Classifications.Select().RowCast <KNSIKCClassification>().Where(x => x.ClassificationName.Equals(classification.Name)).FirstOrDefault();

                foreach (KNSIKCClassificationsMapping mapping in classificationsMapping)
                {
                    if (savedClassification != null && mapping.IsMapped == true && mapping.ClassificationID == savedClassification.ClassificationID)
                    {
                        attributeArrays.Add(classification.ClassificationConfigurationInformationAttributeArray);
                    }
                }
            }

            foreach (ClassificationConfigurationInformationAttribute[] attributeArray in attributeArrays)
            {
                if (attributeArray != null && attributeArray.Count() > 0)
                {
                    foreach (ClassificationConfigurationInformationAttribute attribute in attributeArray)
                    {
                        classificationsAttributes.Add(attribute.Name.Trim().ToUpper());
                    }
                }
            }

            return(classificationsAttributes);
        }
        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);
        }
        private int?GetDefaultDistributionCenter(KCInventoryItemAPIHelper helper, List <KCAPIDistributionCenter> distributionCenters)
        {
            KCAPIProfile profile = helper.GetProfiles().FirstOrDefault();

            return(profile?.DefaultDistributionCenterID);
        }
 public void FillDistributionCentersFromCA(KCInventoryItemAPIHelper helper, List <KCAPIDistributionCenter> newCenters)
 {
     newCenters.AddRange(helper.GetDistributionCenters());
 }
        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();
                }
            }
        }
        private void UpdateSiteQuantity(KCDataExchangeMaint masterGraph, KCMSMQInventoryQuantity quantityProduct, KCInventoryItemAPIHelper helper)
        {
            InventoryItem inventoryItem = masterGraph.ProductByInvCd.Select(quantityProduct.InventoryID.Trim());

            if (inventoryItem != null)
            {
                KNSIKCInventoryItem kcProduct = masterGraph.KCInventoryItem.SelectSingle(inventoryItem.InventoryID);
                if (kcProduct.UsrKCCAID != null)
                {
                    logger.SetParentAndEntityIds(null, inventoryItem.InventoryCD);

                    try
                    {
                        APIQuantityValue apiQuantity = new APIQuantityValue
                        {
                            Value = new APIUpdates()
                            {
                                UpdateType = "InStock",
                                Updates    = quantityProduct.Updates
                            }
                        };

                        helper.UpdateQuantity(apiQuantity, kcProduct.UsrKCCAID);

                        logger.Information(KCMessages.MSMQSyncAPI);
                    }
                    catch (Exception e)
                    {
                        logger.Information(e.Message);
                    }
                }
            }
        }
        private void UpdatePrice(KCDataExchangeMaint masterGraph, KCMSMQInventoryPrice priceProduct, KCInventoryItemAPIHelper helper)
        {
            InventoryItem inventoryItem = masterGraph.ProductByInvCd.Select(priceProduct.InventoryID.Trim());

            if (inventoryItem != null)
            {
                KNSIKCInventoryItem kcProduct          = masterGraph.KCInventoryItem.SelectSingle(inventoryItem.InventoryID);
                InventoryItemPCExt  inventoryItemPCExt = inventoryItem.GetExtension <InventoryItemPCExt>();
                InventoryItem       parent             = KCGeneralDataHelper.GetInventoryItemByInventoryId(PXGraph.CreateInstance <KCDataExchangeMaint>(), inventoryItemPCExt.UsrKNCompositeID);

                logger.SetParentAndEntityIds(parent?.InventoryCD, inventoryItem.InventoryCD);

                try
                {
                    if (kcProduct.UsrKCCAID != null)
                    {
                        helper.EditProduct(KCMapInventoryItem.GetAPIMSMQInventoryPrice(priceProduct), kcProduct.UsrKCCAID);
                    }

                    logger.Information(KCMessages.MSMQSyncAPI);
                }
                catch (Exception e)
                {
                    logger.Information(e.Message);
                }
            }
        }