public static SOOrder GetSOOrder(SOOrderEntry orderGraph, KCAPIOrder order, SOOrder acumaticaOrder, int?branchID, bool FBA)
        {
            KCSiteMasterMaint graph = PXGraph.CreateInstance <KCSiteMasterMaint>();
            var customer            = KCGeneralDataHelper.GetCustomerByCAOrder(graph, order);
            var paymentmethod       = KCGeneralDataHelper.GetPaymenthMethodId(graph, order);
            var mapper          = new KCDynamicOrderMapper(KCMappingEntitiesConstants.Order);
            var conversionGraph = PXGraph.CreateInstance <KCOrderConversionDataMaint>();

            mapper.Mapping.MappingValues = conversionGraph.GetEntity();
            mapper.MapOrder(acumaticaOrder, order);
            if (paymentmethod == null)
            {
                KCPaymentMethodsMappingMaint paymentMethodMappingGraph = PXGraph.CreateInstance <KCPaymentMethodsMappingMaint>();
                CustomerPaymentMethodMaint   paymentMethodGraph        = PXGraph.CreateInstance <CustomerPaymentMethodMaint>();
                try
                {
                    KCGeneralDataHelper.CreatePaymentMethod(paymentMethodGraph, paymentMethodMappingGraph, customer.BAccountID, order);
                    paymentmethod = KCGeneralDataHelper.GetPaymenthMethodId(graph, order);
                }
                catch { }
            }
            acumaticaOrder.CustomerID       = customer.BAccountID;
            acumaticaOrder.PMInstanceID     = paymentmethod?.PMInstanceID;
            acumaticaOrder.Status           = SOOrderStatus.Open;
            acumaticaOrder.CreatePMInstance = true;
            KCSOOrderEntryExt orderext  = orderGraph.GetExtension <KCSOOrderEntryExt>();
            string            orderType = new KCMarketplaceHelper().GetOrderType(order, orderGraph);

            acumaticaOrder.OrderType = orderType ?? acumaticaOrder.OrderType;

            if (order.EstimatedShipDateUtc == null)
            {
                acumaticaOrder.RequestDate = acumaticaOrder.OrderDate;
            }
            orderGraph.CurrentDocument.Current = acumaticaOrder;

            PXNoteAttribute.SetNote(orderGraph.CurrentDocument.Cache, orderGraph.CurrentDocument.Current, order.PrivateNotes);
            string       firstName      = orderext.AccountCD.SelectSingle(acumaticaOrder.CustomerID).AcctName;
            bool         isFBAFirstName = firstName.Contains("FBA");
            KCSOOrderExt orderExt       = acumaticaOrder.GetExtension <KCSOOrderExt>();

            orderExt = mapper.MapOrderCaExt(orderExt, order);
            orderExt.UsrKCSyncDate  = DateTime.Now;
            orderExt.UsrKCSiteName += FBA ? "/FBA" : "/Non-FBA";
            if ((FBA && orderExt.UsrKCSiteName.Contains("Amazon")) || isFBAFirstName)
            {
                acumaticaOrder.Status = KCCheckoutStatus.CCompleted;
            }

            return(acumaticaOrder);
        }
        public string GetOrderType(KCAPIOrder order, SOOrderEntry orderEntry)
        {
            //string marketplaceName = order.SiteName;
            string marketplaceName = order.BillingFirstName.Split()[0];
            var    orderExt        = orderEntry.GetExtension <KCSOOrderEntryExt>();
            int?   marketplaceId   = orderExt.KCMarketplaceEntity.SelectSingle(marketplaceName)?.MarketplaceId;

            if (marketplaceId == null)
            {
                marketplaceName = order.SiteName;
                marketplaceId   = orderExt.KCMarketplaceEntity.SelectSingle(marketplaceName)?.MarketplaceId;
            }
            var marketplace = orderExt.KCMarketplaceManagement.SelectSingle(marketplaceId.ToString());

            if (marketplace != null)
            {
                return(marketplace.SOOrderType);
            }
            else
            {
                return(orderExt.KCConnection.SelectSingle().SOOrderType);
            }
        }
Beispiel #3
0
        public bool CheckAddress(KCSiteMasterMaint graph, KCAPIOrder order)
        {
            Country billingCountry  = graph.Countries.Select().RowCast <Country>().Where(x => x.CountryID.Equals(order.BillingCountry)).FirstOrDefault();
            Country shippingCountry = graph.Countries.Select().RowCast <Country>().Where(x => x.CountryID.Equals(order.ShippingCountry)).FirstOrDefault();

            if (billingCountry == null)
            {
                logger.SetNonChildEntityId(order.ID.ToString());
                logger.Information(KCMessages.InvalidCountryInBillingAddress(order.ID, order.BillingCountry));
                return(false);
            }

            if (shippingCountry == null)
            {
                logger.SetNonChildEntityId(order.ID.ToString());
                logger.Information(KCMessages.InvalidCountryInShippingAddress(order.ID, order.ShippingCountry));
                return(false);
            }

            State billingState  = graph.State.SelectSingle(billingCountry.CountryID, order.BillingStateOrProvince);
            State shippingState = graph.State.SelectSingle(shippingCountry.CountryID, order.ShippingStateOrProvince);

            if (billingState == null)
            {
                logger.SetNonChildEntityId(order.ID.ToString());
                logger.Information(KCMessages.InvalidStateInBillingAddress(order.ID, order.BillingStateOrProvinceName));
                return(false);
            }

            if (shippingState == null)
            {
                logger.SetNonChildEntityId(order.ID.ToString());
                logger.Information(KCMessages.InvalidStateInShippingAddress(order.ID, order.ShippingStateOrProvinceName));
                return(false);
            }

            bool billingZip = false;

            if (order.BillingPostalCode != null)
            {
                billingZip = billingCountry.ZipCodeRegexp == null || Regex.IsMatch(order.BillingPostalCode, billingCountry.ZipCodeRegexp);
            }
            bool shippingZip = false;

            if (order.ShippingPostalCode != null)
            {
                shippingZip = shippingCountry.ZipCodeRegexp == null || Regex.IsMatch(order.ShippingPostalCode, shippingCountry.ZipCodeRegexp);
            }

            if (!shippingZip)
            {
                logger.SetNonChildEntityId(order.ID.ToString());
                logger.Information(KCMessages.InvalidZipInShippingAddress(order.ID, order.ShippingPostalCode));
                return(false);
            }

            if (!billingZip)
            {
                logger.SetNonChildEntityId(order.ID.ToString());
                logger.Information(KCMessages.InvalidZipInBillingAddress(order.ID, order.BillingPostalCode));
                return(false);
            }

            return(true);
        }
Beispiel #4
0
        public bool CheckBranches(KCSiteMasterMaint sitemaster, List <KCAPIOrderItem> orderItems, KCAPIOrder order)
        {
            BAccount customer = KCGeneralDataHelper.GetCustomerByCAOrder(sitemaster, order);

            if (customer == null)
            {
                logger.SetNonChildEntityId(order.ID.ToString());
                logger.Information(KCMessages.CustomerNotFound(order.ID, order.BuyerEmailAddress));
                return(false);
            }

            bool workflowPublished = new KCNamespaceReview().Test(KCConstants.NamespaceTesterPackage);

            if (workflowPublished)
            {
                bool validItem;
                foreach (KCAPIOrderItem item in orderItems)
                {
                    DAC.KNSIKCInventoryItem stockItem    = sitemaster.ExistingProducts.SelectSingle(item.ProductID);
                    InventoryItem           product      = sitemaster.ProductByInvId.SelectSingle(stockItem.InventoryID);
                    KCInventoryItemExt      productKCExt = product.GetExtension <KCInventoryItemExt>();
                    validItem = false;

                    if (product.GetExtension <InventoryItemPCExt>().UsrKNCompositeType == null)
                    {
                        if (productKCExt.UsrKNCPBranch != null && customer.GetExtension <KCCustomerExt>()?.UsrKNCPBranchID != null)
                        {
                            List <string> productBranches = productKCExt.UsrKNCPBranch.Split(',').ToList();

                            foreach (string branch in productBranches)
                            {
                                if (customer.GetExtension <KCCustomerExt>()?.UsrKNCPBranchID?.Split(',').Select(x => x.Trim()).ToList().Contains(branch) == true)
                                {
                                    validItem = true;
                                }
                            }
                        }
                        else
                        {
                            validItem = true;
                        }
                    }
                    else
                    {
                        validItem = true;
                    }

                    if (!validItem)
                    {
                        logger.SetNonChildEntityId(order.ID.ToString());
                        logger.Information(KCMessages.WebsitesAreNotAssociated(order.ID, product.InventoryCD, customer.AcctName));
                        return(false);
                    }
                }
            }
            return(true);
        }
        public string GetTaxSettings(KCAPIOrder order, SOOrderEntry orderEntry)
        {
            //string marketplaceName = order.SiteName;
            string marketplaceName = order.BillingFirstName.Split()[0];
            var    orderExt        = orderEntry.GetExtension <KCSOOrderEntryExt>();
            PXResultset <KCTaxManagement> taxManagement = null;
            KCTaxManagement taxrecord     = null;
            int?            marketplaceId = orderExt.KCMarketplaceEntity.SelectSingle(marketplaceName)?.MarketplaceId;

            if (marketplaceId == null)
            {
                marketplaceName = order.SiteName;
                marketplaceId   = orderExt.KCMarketplaceEntity.SelectSingle(marketplaceName)?.MarketplaceId;
            }
            var marketplace      = orderExt.KCMarketplaceManagement.SelectSingle(marketplaceId.ToString());
            var isCATaxZoneExist = orderExt.KCTaxZoneId.SelectSingle(KCConstants.Channel);

            Boolean.TryParse(orderExt.KCXSiteMaster.SelectSingle().IsImportTax, out bool IsImport);
            if (marketplace != null)
            {
                taxManagement = orderExt.KCTaxManagementView.Select(marketplace.MarketplaceId);
                var taxrecordlist = taxManagement.RowCast <KCTaxManagement>().ToList().Where
                                        (x => x.CountryId == order.BillingCountry);
                foreach (var taxman in taxrecordlist)
                {
                    var byState = taxrecordlist.Where(x => (x?.StateId == order.BillingStateOrProvince) || x?.StateId?.Contains(order.BillingStateOrProvince) == true);
                    if (byState.Count() == 0 && taxrecordlist.Where(x => x.CountryId == order.BillingCountry && x?.StateId == null).Count() != 0)
                    {
                        taxrecord = taxrecordlist.Where(x => x.CountryId == order.BillingCountry && x?.StateId == null).FirstOrDefault();
                    }
                    else
                    {
                        taxrecord = byState.FirstOrDefault();
                    }
                }
            }
            if (marketplace != null) // If marketplace exist on Marketplace grid settings
            {
                if (taxManagement != null && taxrecord != null)
                {
                    if (!taxrecord.UseDefTaxZone.GetValueOrDefault()) // if this row has UseDefTaxZone on true
                    {
                        string defTaxZone = taxrecord.TaxZoneId;
                        return(defTaxZone);
                    }
                    else
                    {
                        //if (orderExt.KCXSiteMaster.SelectSingle().IsImportTax == "0") // if UseDefTaxZone is true--use General settings
                        {
                            if (isCATaxZoneExist == null)
                            {
                                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();
                                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();
                                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, tax.TaxID);
                                CAtaxzone.Persist();
                                string defTaxZone = newTaxZone.TaxZoneID;
                                return(defTaxZone);
                            }
                            else
                            {
                                string defTaxZone = isCATaxZoneExist.TaxZoneID;
                                return(defTaxZone);
                            }
                        }
                        //else
                        //{
                        //    string defTaxZone = orderExt.KCXSiteMaster.SelectSingle().TaxZone;
                        //    return defTaxZone;
                        //}
                    }
                }
                else
                {
                    if (!marketplace.UseDefTaxZone.GetValueOrDefault()) // if this row has UseDefTaxZone on true
                    {
                        string defTaxZone = marketplace.TaxZone;
                        return(defTaxZone);
                    }
                    else
                    {
                        //if (orderExt.KCXSiteMaster.SelectSingle().IsImportTax == "0") // if UseDefTaxZone is true--use General settings
                        {
                            if (isCATaxZoneExist == null)
                            {
                                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();
                                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();
                                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, tax.TaxID);
                                CAtaxzone.Persist();
                                string defTaxZone = newTaxZone.TaxZoneID;
                                return(defTaxZone);
                            }
                            else
                            {
                                string defTaxZone = isCATaxZoneExist.TaxZoneID;
                                return(defTaxZone);
                            }
                        }
                        //else
                        //{
                        //    string defTaxZone = orderExt.KCXSiteMaster.SelectSingle().TaxZone;
                        //    return defTaxZone;
                        //}
                    }
                }
            }
            else
            {
                if (orderExt.KCXSiteMaster.SelectSingle().IsImportTax == "0") // if UseDefTaxZone is true--use General settings
                {
                    if (isCATaxZoneExist == null)
                    {
                        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();
                        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();
                        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, tax.TaxID);
                        CAtaxzone.Persist();

                        string defTaxZone = newTaxZone.TaxZoneID;
                        return(defTaxZone);
                    }
                    else
                    {
                        string defTaxZone = isCATaxZoneExist.TaxZoneID;
                        return(defTaxZone);
                    }
                }
                else
                {
                    string defTaxZone = orderExt.KCXSiteMaster.SelectSingle().TaxZone;
                    return(defTaxZone);
                }
            }
        }