private List <TaxZoneDet> GetApplicableTaxList(PXGraph aGraph, string aTaxZoneID, string aTaxCategoryID, DateTime aDocDate)
            {
                List <TaxZoneDet> taxList   = new List <TaxZoneDet>();
                HashSet <string>  collected = new HashSet <string>();

                foreach (PXResult <TaxZoneDet, TaxCategory, TaxRev, TaxCategoryDet> r in PXSelectJoin <TaxZoneDet,
                                                                                                       CrossJoin <TaxCategory,
                                                                                                                  InnerJoin <TaxRev, On <TaxRev.taxID, Equal <TaxZoneDet.taxID> >,
                                                                                                                             LeftJoin <TaxCategoryDet, On <TaxCategoryDet.taxID, Equal <TaxZoneDet.taxID>,
                                                                                                                                                           And <TaxCategoryDet.taxCategoryID, Equal <TaxCategory.taxCategoryID> > > > > >,
                                                                                                       Where <TaxZoneDet.taxZoneID, Equal <Required <TaxZoneDet.taxZoneID> >,
                                                                                                              And <TaxCategory.taxCategoryID, Equal <Required <TaxCategory.taxCategoryID> >,
                                                                                                                   And <Required <TaxRev.startDate>, Between <TaxRev.startDate, TaxRev.endDate>, And <TaxRev.outdated, Equal <False>,
                                                                                                                                                                                                      And <Where <TaxCategory.taxCatFlag, Equal <False>, And <TaxCategoryDet.taxCategoryID, IsNotNull,
                                                                                                                                                                                                                                                              Or <TaxCategory.taxCatFlag, Equal <True>, And <TaxCategoryDet.taxCategoryID, IsNull> > > > > > > > > > .Select(aGraph, aTaxZoneID, aTaxCategoryID, aDocDate))
                {
                    TaxZoneDet tzd = r;
                    if (collected.Contains(tzd.TaxID))
                    {
                    }
                    else
                    {
                        collected.Add(tzd.TaxID);
                        taxList.Add(tzd);
                    }
                }
                return(taxList);
            }
Esempio n. 2
0
 protected virtual void TaxZone_RowDeleted(PXCache sender, PXRowDeletedEventArgs e)
 {
     if (!(e.Row is TaxZone row))
     {
         return;
     }
     if (row.TaxZoneID == "Channel")
     {
         TaxZoneDet det = KCTaxItem.SelectSingle(row.TaxZoneID);
         KCTaxItem.Delete(det);
     }
 }
        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();
        }
        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);
                }
            }
        }