国际和国家税收课程

时间:2015-12-11 17:09:43

标签: c# class e-commerce kentico tax

我试图实现以下方案,并且不确定如何配置商店的税级,因为任何人都试图实现以下目标:

  • 如果在国家Y,则征收23%的税。
  • 如果不是国家Y和税号,则提供零税,否则提供23%税。

我试图创建两个单独的税级:

  • 正常,国家Y为23%。
  • 国际,所有国家/地区为23%,如果提供税号,则为零税。

但是,我如何确保国际不适用于Y国?它似乎不允许您从列表中删除国家/地区。

1 个答案:

答案 0 :(得分:1)

在Kentico中使用复杂的税务逻辑需要一些自定义开发(至少在第7版中,我认为v8在税收计算方面没有太大变化)。如果您要观看this webinar,那么就会有一个讨论自定义TaxClassInfoProviders的部分。它还包含一些代码示例,您可以下载这些示例以帮助您入门。

这是修改税务计算流程的一种方法。它基于上面链接的网络研讨会中的一个示例文件:

public class CustomTaxClassInfoProvider : TaxClassInfoProvider
{

    #region Properties

    private ShoppingCartInfo Cart
    {
        get 
        {
            return ECommerceContext.CurrentShoppingCart;
        }
    }

    private string CustomerZipCode
    {
        get 
        {
            AddressInfo customerAddress = AddressInfoProvider.GetAddressInfo(Cart.ShoppingCartShippingAddressID);

            if(customerAddress != null)
                return customerAddress.AddressZip;

            return null;
        }
    }

    #endregion

    /// <summary>
    /// Returns DataSet with all the taxes which should be applied to the shopping cart items.
    /// </summary>
    /// <param name="cart">Shopping cart</param>
    protected override DataSet GetTaxesInternal(ShoppingCartInfo cart)
    {
        DataSet taxDataSet = new DataSet();

        // Create an empty taxes table
        DataTable table = GetNewTaxesTable();

        List<TaxRow> taxRows = new List<TaxRow>();

        foreach (ShoppingCartItemInfo item in cart.CartItems)
        {
            TaxRow row = new TaxRow();

            row.SKUID = item.SKU.SKUID;
            row.SKUGUID = item.SKU.SKUGUID;

            taxRows.Add(row);
        }

        foreach (TaxRow row in taxRows)
        {
            double rate = 0;
            string name = "";

            // Add conditions for different tax rates here
            // --------------------------------------------

            // For Example
            if (cart.Customer.CustomerCountryID == countryYouWantToExclude)
            {
                rate = yourTaxRate;
                name = "Name for the tax";
            }
            else
            {
                rate = 0;
                name = "";
            }

            row.TaxRate = rate;
            row.TaxName = name;
        }

        BuildTaxTable(ref table, taxRows);

        // Return our dataset with the taxes
        taxDataSet.Tables.Add(table);
        return taxDataSet;
    }

    private void BuildTaxTable(ref DataTable table, List<TaxRow> taxRows)
    {
        foreach (TaxRow row in taxRows)
        {
            AddTaxRow(table, row.SKUID, row.TaxName, row.TaxRate);
        }
    }

    private DataTable GetNewTaxesTable()
    {
        DataTable table = new DataTable();

        // Add required columns
        table.Columns.Add("SKUID", typeof(int));
        table.Columns.Add("TaxClassDisplayName", typeof(string));
        table.Columns.Add("TaxValue", typeof(double));

        return table;
    }

    private void AddTaxRow(DataTable taxTable, int skuId, string taxName, double taxValue, bool taxIsFlat, bool taxIsGlobal, bool zeroTaxIfIDSupplied)
    {
        DataRow row = taxTable.NewRow();

        // Set required columns
        row["SKUID"] = skuId;
        row["TaxClassDisplayName"] = taxName;
        row["TaxValue"] = taxValue;

        // Set optional columns
        //row["TaxIsFlat"] = taxIsFlat;
        //row["TaxIsGlobal"] = taxIsGlobal;
        //row["TaxClassZeroIfIDSupplied"] = taxIsGlobal;

        taxTable.Rows.Add(row);
    }

    private void AddTaxRow(DataTable taxTable, int skuId, string taxName, double taxValue)
    {
        AddTaxRow(taxTable, skuId, taxName, taxValue, false, false, false);
    }
}

/// <summary>
/// Represents a DataRow to be inserted into the tax calculation data table
/// </summary>
public class TaxRow
{
    public int SKUID { get; set; }
    public Guid SKUGUID { get; set; }
    public string TaxName { get; set; }
    public double TaxRate { get; set; }

    public TaxRow()
    {

    }
}

然后您需要设置CMSModuleLoader类,它也是上述链接中的示例文件之一:

/// <summary>
/// Sample e-commerce module class. Partial class ensures correct registration.
/// </summary>
[SampleECommerceModuleLoader]
public partial class CMSModuleLoader
{
    #region "Macro methods loader attribute"

    /// <summary>
    /// Module registration
    /// </summary>
    private class SampleECommerceModuleLoaderAttribute : CMSLoaderAttribute
    {
        /// <summary>
        /// Constructor
        /// </summary>
        public SampleECommerceModuleLoaderAttribute()
        {
            // Require E-commerce module to load properly
            RequiredModules = new string[] { ModuleEntry.ECOMMERCE };
        }


        /// <summary>
        /// Initializes the module
        /// </summary>
        public override void Init()
        {

            TaxClassInfoProvider.ProviderObject = new CustomTaxClassInfoProvider();
        }
    }

    #endregion
}

将这些文件添加到AppCode中的任何位置,您应该很高兴。如果您有任何问题,请告诉我。