示例#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);
            }
        }
示例#2
0
        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;
        }
        public static void ProcessStore(KCStore store, CancellationToken token)
        {
            KCBulkProductMaint      graph        = CreateInstance <KCBulkProductMaint>();
            KCBulkUploader          bulkUploader = new KCBulkUploader(graph, logger.LoggerProperties, token);
            KCBulkProductSyncConfig config       = new KCBulkProductSyncConfig {
                SyncType = store.SyncType ?? KCBulkProductSyncTypesConstants.Delta, DateFrom = store.DateFrom, DateTo = store.DateTo
            };

            bulkUploader.SetStrategy(config);
            bulkUploader.ExportProducts(store);
        }
示例#4
0
 public KCMapInventoryItem(KCRelationshipSetupMaint relationshipGraph,
                           KCClassificationsMappingMaint classificationsGraph,
                           KCBulkProductMaint bulkGraph,
                           KCIItemConversionDataMaint conversionGraph,
                           KCStore store,
                           KCLoggerProperties loggerProperties)
 {
     RelationshipGraph    = relationshipGraph;
     ClassificationsGraph = classificationsGraph;
     BulkGraph            = bulkGraph;
     ConversionGraph      = conversionGraph;
     Store            = store;
     LoggerProperties = loggerProperties;
 }
        public virtual IEnumerable Stores()
        {
            KCProcessingEntry filter = ProcessingEntry.Current;
            PXSelectReadonly <KCSiteMaster> existingStores = new PXSelectReadonly <KCSiteMaster>(this);

            if (filter == null)
            {
                yield break;
            }

            bool found = false;

            foreach (KCStore item in stores.Cache.Inserted)
            {
                found         = true;
                item.Entity   = filter.Entity;
                item.DateFrom = filter.DateFrom;
                item.DateTo   = filter.DateTo;
                yield return(item);
            }

            if (found)
            {
                yield break;
            }

            foreach (KCSiteMaster result in existingStores.Select())
            {
                KCStore store = new KCStore
                {
                    SiteMasterCD = result.SiteMasterCD,
                    AccountId    = result.AccountId,
                    Descr        = result.Descr,
                    Entity       = filter.Entity,
                    DateFrom     = filter.DateFrom,
                    DateTo       = filter.DateTo
                };

                yield return(stores.Insert(store));
            }

            stores.Cache.IsDirty = false;
        }
        private static void ProcessStore(KCStore store)
        {
            (string Entity, string Action)actionAndEntity = GetActionAndEntity(store.Entity);
            LoggerProperties.EntityType = actionAndEntity.Entity;
            LoggerProperties.ActionName = actionAndEntity.Action;

            switch (store.Entity)
            {
            case KCEntities.Order:
                new KCOrderDataHelper(LoggerProperties).ImportOrders(store);
                break;

            case KCEntities.Shipment:
                new KCShipmentDataHelper(LoggerProperties).ExportShipments(store);
                break;

            case KCEntities.RetrieveIds:
                new KCInventoryItemDataHelper(LoggerProperties).RetrieveChannelAdvisorIds(store);
                break;
            }
        }
        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 IEnumerable stores()
        {
            KCBulkProductSyncConfig filter = Config.Current;

            if (filter == null)
            {
                yield break;
            }

            bool found = false;

            foreach (KCStore item in Stores.Cache.Inserted)
            {
                found       = true;
                item.Entity = KCConstants.Product;
                yield return(item);
            }

            if (found)
            {
                yield break;
            }

            foreach (KCSiteMaster result in StoreConfig.Select())
            {
                KCStore store = new KCStore
                {
                    SiteMasterCD = result.SiteMasterCD,
                    AccountId    = result.AccountId,
                    Descr        = result.Descr,
                    Entity       = KCConstants.Product
                };

                yield return(Stores.Insert(store));
            }
            Stores.Cache.IsDirty = false;
        }
示例#9
0
        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);
        }