Use this component for calculating taxes in pipelines using the multiple shipment features of Commerce Server 2002.
- The SampleRegionalTax component is not a complete solution to tax calculation. It is provided as an example of a tax component that takes full advantage of the multiple shipment features of Commerce Server 2002. Microsoft strongly recommends that you purchase a third-party tax component.
Intended use: Order Processing pipeline, Tax stage.
The SampleRegionalTax component reads the following values from the indicated dictionaries.
||Order||A SimpleList object of shipments.|
||Order||The total price of all the items, after all the discounts have been applied.|
||Context||A reference to a dictionary containing tax information.|
In addition, the SampleRegionalTax component reads the following keys from the Addresses dictionary in the OrderForm object.
||The ship to country/region for the address ID retrieved for the shipment.|
||Optional. The ship to region for the address ID retrieved for the shipment.|
The SampleRegionalTax component writes the following values to the Order dictionary.
||The total tax for the item.|
||The total tax for the item included in the cost. You must set this key to zero (0).|
||The total tax for the shipment.|
||The total tax for the shipment included in the cost. You must set this key to zero (0).|
||The total tax for the order.|
||The total tax for the order included in the cost. You must set this key to zero (0).|
The SampleRegionalTax component computes tax for the Commerce Server 2002 shipping architecture that handles multiple shipments. For more information about how Commerce Server processes shipments, see Multiple-shipment Shipping Architecture.
For each shipment in the order, the component first gets the tax rate from the database using the CacheManager object and stores it in the SampleRegionalTaxCache component.
The SampleRegionalTax component then goes through each item in the shipment and calculates its tax based on the rate retrieved from the tax rate table. Rates are retrieved based on the country/region codes in the dictionary of addresses in the Order dictionary. For more information about the dictionary of addresses, see Multiple-shipment Shipping Architecture.
As it goes through the items and shipments in the order, the SampleRegionalTax component accumulates totals for the items, shipments, and, finally, for the entire order.
The tax rate data stored in the SampleRegionalTaxCache component is a snapshot of the RegionalTax database table. The RegionalTax table contains three columns.
||String, 255 characters.||The country code.|
||String, 255 characters.||The region code.|
||Float, 8 bytes.||The tax rate.|
You may include a wildcard entry (@) for a region code. This will match regions that would not otherwise match. If no entry is found in the RegionalTax table, the rate is zero (0).
Using a pipeline containing the SampleRegionalTax component is very similar to using a Content Selection pipeline. First, you configure the CacheManager object to use the SampleRegionalTaxCache loader in the Application_OnStart section of the Global.asa file. Then, in the Active Server Pages (ASP) page, you add an entry for the CacheManager object to the Context dictionary and invoke the pipeline.
Setup code in the Application_OnStart method:
' Create a Dictionary to hold configuration information. Set dConfig = CreateObject("Commerce.Dictionary") ' Add configuration information to the dictionary. SampleRegtionalTax ' only uses a connection string. dConfig("ConnectionString") = "DSN=adsamples;UID=username;PWD=******" ' Create a CacheManager object. Set CacheManager = Server.CreateObject("Commerce.CacheManager") ' Set the ProgID of the Loader component for the ' "SampleRegionalTaxCache" cache. CacheManager.LoaderProgId("SampleRegionalTaxCache") = _ "Commerce.SampleRegionalTaxCache" ' Set the Loader component config Dictionary for the cache. Set CacheManager.LoaderConfig("SampleRegionalTaxCache") = dConfig ' ' Other CacheManager configuration code would appear here. ' ' Store a reference to the CacheManager in the Application object. Set Application("CacheManager") = CacheManager
Code to run the pipeline containing the SampleRegionalTax component:
' Place a reference to the CacheManager in the context dictionary. Set dContext = Server.CreateObject("Commerce.Dictionary") dContext.CacheManager = Application("CacheManager") ' ' Set other values and create the Order dictionary (dOrder) here. ' ' Load and run the pipeline containing the tax component. Set pPooledPipe = Server.CreateObject("Commerce.PooledPipeline") pPooledPipe.LoadPipe("OrderAndTax.pcf") iErrVal = pPooledPipe.Execute(0, dOrder, dContext, 1)
Code to query the SampleRegionalTax cache for a specific tax rate:
' Initialize the TaxRates dictionary as Dictionary object. ' Retrieve the tax rate for a specific country_code and region_code. Dim TaxRates As CDictionary Set TaxRates = _ objContext("CacheManager").GetCache("SampleRegionalTaxCache").Cache_("US")("WA")