atg.commerce.pricing
Class TaxProcessorTaxCalculator

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.commerce.pricing.TaxProcessorTaxCalculator
All Implemented Interfaces:
TaxPricingCalculator, atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener
Direct Known Subclasses:
AddressVerificationTaxProcessorTaxCalculator

public class TaxProcessorTaxCalculator
extends GenericService
implements TaxPricingCalculator

Uses the atg.payment.tax package to calculate tax for an order. This class is configured with an atg.payment.tax.TaxProcessor which is passed all of the information it needs to compute tax, e.g. the Amount, Shipping Address, Currency Code, etc. Note: This calc looks at the averagePriceRoundingDecimalPlaces property of PricingTools. As of this writing, DCS does not keep track of which units of a CommerceItem are being shipped to what addresses. Also, the ItemPricingEngine is capable of pricing different units of a CommerceItem differently because of various promotions. These two facts mean that we can't be perfectly sure about the exact amount that is to be taxed. Instead, this calculator takes an average CommerceItem unit price and multiplies it by the number of units in a particular shipping group. All this dividing may potentially leave us with a price that has an infinitely repeating number of decimals. The averagePriceRoundingDecimalPlaces property dictates how to truncate these prices before sending them to the TaxProcessor implementation. This calculator keeps track of any missing money and adds it to one of the totals.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
static java.lang.String DETAILED_ITEM_PRICE_TAX_PROPERTY
           
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
TaxProcessorTaxCalculator()
           
 
Method Summary
protected  void assignItemTaxAmounts(Order pOrder, TaxPriceInfo pOrderTax, TaxStatus pStatus)
          Assign each detail's tax for the given order.
protected  void assignItemTaxAmounts(ShippingGroup pShippingGroup, TaxPriceInfo pTaxPriceInfo, OrderPriceInfo pOrderPrice, OrderPriceInfo pShippingSubtotal, TaxStatus pStatus)
          Assign each detail's tax for the given order.
protected  void calculateTax(TaxRequestInfo pTRI, TaxPriceInfo pPriceQuote, Order pOrder, RepositoryItem pPricingModel, java.util.Locale pLocale, RepositoryItem pProfile, java.util.Map pExtraParameters)
          Given the input TaxRequestInfo object, modify the input pPriceQuote object to reflect the current tax.
protected  void calculateTaxByShipping(TaxRequestInfo pTRI, TaxPriceInfo pPriceQuote, Order pOrder, RepositoryItem pPricingModel, java.util.Locale pLocale, RepositoryItem pProfile, java.util.Map pExtraParameters)
          Given the input TaxRequestInfo object, modify the input pPriceQuote object to reflect the current tax.
protected  TaxableItem createTaxableItemForRelationship(CommerceItemRelationship pRelationship, TaxRequestInfo pTaxRequestInfo)
          create a TaxableItem for the input relationship and TaxRequestInfo.
protected  TaxableItem createTaxableItemForRelationship(CommerceItemRelationship pRelationship, TaxRequestInfo pTaxRequestInfo, Order pOrder, java.util.Locale pLocale, RepositoryItem pProfile, java.util.Map pExtraParameters)
          create a TaxableItem for the input relationship and TaxRequestInfo.
protected  TaxableItem createTaxableItemForRelationshipByAverage(CommerceItemRelationship pRelationship, TaxRequestInfo pTaxRequestInfo)
          create a TaxableItem for the input relationship and TaxRequestInfo.
protected  TaxableItem createTaxableItemForRelationshipByAverage(CommerceItemRelationship pRelationship, TaxRequestInfo pTaxRequestInfo, Order pOrder, java.util.Locale pLocale, RepositoryItem pProfile, java.util.Map pExtraParameters)
          create a TaxableItem for the input relationship and TaxRequestInfo.
protected  Address determineShippingAddress(ShippingGroup pGroup)
          Determines a shipping address based on a ShippingGroup
 void doStartService()
          This is called after a Service has been created, placed into the naming hierarchy, and initialized with its configured property values.
 java.lang.String getBillingAddressPropertyName()
          Returns the billingAddressPropertyName
 boolean getCalculateTaxByShipping()
          flag that determines whether this calculator should calculate tax on a per-shippingGroup basis.
 OrderManager getOrderManager()
          Get property OrderManager
 PricingTools getPricingTools()
          the PricingTools object which helps this calculator calculate tax'
 java.util.List getRelationshipsToAssignTaxTo(ShippingGroup pShippingGroup)
          Returns the list of ShippingGroupCommerceItemRelationships that should be assigned tax.
 TaxProcessor getTaxProcessor()
          Get property TaxProcessor
 java.lang.String getTaxStatusProperty()
          Returns property TaxStatusProperty
 boolean isVerifyAddresses()
          Test property VerifyAddresses
 void priceTax(TaxPriceInfo pPriceQuote, Order pOrder, RepositoryItem pPricingModel, java.util.Locale pLocale, RepositoryItem pProfile, java.util.Map pExtraParameters)
          Tax an order within a context.
 void setBillingAddressPropertyName(java.lang.String pBillingAddressPropertyName)
          Sets the billingAddressPropertyName
 void setCalculateTaxByShipping(boolean pCalculateTaxByShipping)
          flag that determines whether this calculator should calculate tax on a per-shippingGroup basis.
 void setOrderManager(OrderManager pOrderManager)
          Set property OrderManager
 void setPricingTools(PricingTools pPricingTools)
          the PricingTools object which helps this calculator calculate tax
 void setTaxProcessor(TaxProcessor pTaxProcessor)
          Set property TaxProcessor
 void setTaxStatusProperty(java.lang.String pTaxStatusProperty)
          Sets property TaxStatusProperty
 void setVerifyAddresses(boolean pVerifyAddresses)
          flag that determines whether this calculator will attempt to verify addresses
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static final java.lang.String CLASS_VERSION
Class version string

See Also:
Constant Field Values

DETAILED_ITEM_PRICE_TAX_PROPERTY

public static final java.lang.String DETAILED_ITEM_PRICE_TAX_PROPERTY
See Also:
Constant Field Values
Constructor Detail

TaxProcessorTaxCalculator

public TaxProcessorTaxCalculator()
Method Detail

setTaxStatusProperty

public void setTaxStatusProperty(java.lang.String pTaxStatusProperty)
Sets property TaxStatusProperty


getTaxStatusProperty

public java.lang.String getTaxStatusProperty()
Returns property TaxStatusProperty


setTaxProcessor

public void setTaxProcessor(TaxProcessor pTaxProcessor)
Set property TaxProcessor

Parameters:
pTaxProcessor - new value to set

getTaxProcessor

public TaxProcessor getTaxProcessor()
Get property TaxProcessor

Returns:
TaxProcessor

setOrderManager

public void setOrderManager(OrderManager pOrderManager)
Set property OrderManager

Parameters:
pOrderManager - new value to set

getOrderManager

public OrderManager getOrderManager()
Get property OrderManager

Returns:
OrderManager

setPricingTools

public void setPricingTools(PricingTools pPricingTools)
the PricingTools object which helps this calculator calculate tax

Parameters:
pPricingTools - new value to set

getPricingTools

public PricingTools getPricingTools()
the PricingTools object which helps this calculator calculate tax'

Returns:
property PricingTools

setVerifyAddresses

public void setVerifyAddresses(boolean pVerifyAddresses)
flag that determines whether this calculator will attempt to verify addresses

Parameters:
pVerifyAddresses - new value to set

isVerifyAddresses

public boolean isVerifyAddresses()
Test property VerifyAddresses

Returns:
VerifyAddresses

setCalculateTaxByShipping

public void setCalculateTaxByShipping(boolean pCalculateTaxByShipping)
flag that determines whether this calculator should calculate tax on a per-shippingGroup basis.

Parameters:
pCalculateTaxByShipping - new value to set

getCalculateTaxByShipping

public boolean getCalculateTaxByShipping()
flag that determines whether this calculator should calculate tax on a per-shippingGroup basis.

Returns:
property CalculateTaxByShipping

getBillingAddressPropertyName

public java.lang.String getBillingAddressPropertyName()
Returns the billingAddressPropertyName


setBillingAddressPropertyName

public void setBillingAddressPropertyName(java.lang.String pBillingAddressPropertyName)
Sets the billingAddressPropertyName


priceTax

public void priceTax(TaxPriceInfo pPriceQuote,
                     Order pOrder,
                     RepositoryItem pPricingModel,
                     java.util.Locale pLocale,
                     RepositoryItem pProfile,
                     java.util.Map pExtraParameters)
              throws PricingException
Tax an order within a context. This implementation consults the configured TaxProcessor for the tax. The steps taken here are: NOTE: The algorithm used by this method to determine the tax of the order finds an average price for each item and uses that price in determining the tax on every unit of that item. The reason for this is that there is currently no way to specify which individual units of a CommerceItem belong in which shipping relationship. Additionally, units as small as one of a CommerceItem can be priced differently from other units in the same CommerceItem. These two situations mean that when taxing a CommerceItem, there is no way to know explicitly what the total price of a shipping relationship is. Therefore, an average price is computed for all items, and that price is multiplied by the quantity of the CommerceItem that reside in the current relationship to find the total price of the relationship.

Ideally, we should change a shipping relationship to include an exact specification of which units of a CommerceItem belong to that relationship.

Specified by:
priceTax in interface TaxPricingCalculator
Parameters:
pPriceQuote - TaxPriceInfo representing the tax quote for the order
pOrder - The order to tax
pPricingModels - A Collection of RepositoryItems representing PricingModels
pProfile - The user's profile
pExtraParameters - A Map of extra parameters to be used in the pricing, may be null
Throws:
PricingException

calculateTaxByShipping

protected void calculateTaxByShipping(TaxRequestInfo pTRI,
                                      TaxPriceInfo pPriceQuote,
                                      Order pOrder,
                                      RepositoryItem pPricingModel,
                                      java.util.Locale pLocale,
                                      RepositoryItem pProfile,
                                      java.util.Map pExtraParameters)
                               throws PricingException
Given the input TaxRequestInfo object, modify the input pPriceQuote object to reflect the current tax. This method differs from calculateTax in that it calls through to the 'calculateTaxByShipping' tax API call.

Parameters:
pTRI - the TaxRequestInfo object which represents a request from a TaxProcessor for a tax calculation. Required.
pPriceQuote - the TaxPriceInfo to modify to reflect the calculated tax. Required.
pOrder - the order for which tax is being calculated. Optional.
pPricingModel - the pricing model which is modifying the tax total. Optional. Not used in DCS at this time.
pLocale - the local in which the tax should be calculated. Optional.
pProfile - the person for whom the tax is being calculated. Optional.
pExtraParameters - any extra information needed to calculate tax. Optional.
Throws:
PricingException

calculateTax

protected void calculateTax(TaxRequestInfo pTRI,
                            TaxPriceInfo pPriceQuote,
                            Order pOrder,
                            RepositoryItem pPricingModel,
                            java.util.Locale pLocale,
                            RepositoryItem pProfile,
                            java.util.Map pExtraParameters)
                     throws PricingException
Given the input TaxRequestInfo object, modify the input pPriceQuote object to reflect the current tax.

Parameters:
pTRI - the TaxRequestInfo object which represents a request from a TaxProcessor for a tax calculation. Required.
pPriceQuote - the TaxPriceInfo to modify to reflect the calculated tax. Required.
pOrder - the order for which tax is being calculated. Optional.
pPricingModel - the pricing model which is modifying the tax total. Optional. Not used in DCS at this time.
pLocale - the local in which the tax should be calculated. Optional.
pProfile - the person for whom the tax is being calculated. Optional.
pExtraParameters - any extra information needed to calculate tax. Optional.
Throws:
PricingException

determineShippingAddress

protected Address determineShippingAddress(ShippingGroup pGroup)
Determines a shipping address based on a ShippingGroup


createTaxableItemForRelationshipByAverage

protected TaxableItem createTaxableItemForRelationshipByAverage(CommerceItemRelationship pRelationship,
                                                                TaxRequestInfo pTaxRequestInfo,
                                                                Order pOrder,
                                                                java.util.Locale pLocale,
                                                                RepositoryItem pProfile,
                                                                java.util.Map pExtraParameters)
                                                         throws PricingException
create a TaxableItem for the input relationship and TaxRequestInfo. This implementation finds the average price of a single unit of the relationship's CommerceItem and uses that price as a basis for determining the total cost of the relationship. This in turn affects the amount of tax on this relationship. Extending classes can override this method to gain finer control over the manner in which units of a CommerceItem are assigned to a CommerceItemRelationship.

Parameters:
pRelationship - the relationship for which a TaxableItem is needed.
pTaxRequestInfo - the TaxRequestInfo object into which the returned TaxableItem will be inserted.
Throws:
PricingException

createTaxableItemForRelationshipByAverage

protected TaxableItem createTaxableItemForRelationshipByAverage(CommerceItemRelationship pRelationship,
                                                                TaxRequestInfo pTaxRequestInfo)
                                                         throws PricingException
create a TaxableItem for the input relationship and TaxRequestInfo. This implementation finds the average price of a single unit of the relationship's CommerceItem and uses that price as a basis for determining the total cost of the relationship. This in turn affects the amount of tax on this relationship. Extending classes can override this method to gain finer control over the manner in which units of a CommerceItem are assigned to a CommerceItemRelationship.

Parameters:
pRelationship - the relationship for which a TaxableItem is needed.
pTaxRequestInfo - the TaxRequestInfo object into which the returned TaxableItem will be inserted.
Throws:
PricingException

createTaxableItemForRelationship

protected TaxableItem createTaxableItemForRelationship(CommerceItemRelationship pRelationship,
                                                       TaxRequestInfo pTaxRequestInfo)
                                                throws PricingException
create a TaxableItem for the input relationship and TaxRequestInfo. This implementation finds the average price of a single unit of the relationship's CommerceItem and uses that price as a basis for determining the total cost of the relationship.

Parameters:
pRelationship - the relationship for which a TaxableItem is needed.
pTaxRequestInfo - the TaxRequestInfo object into which the returned TaxableItem will be inserted.
Throws:
PricingException

createTaxableItemForRelationship

protected TaxableItem createTaxableItemForRelationship(CommerceItemRelationship pRelationship,
                                                       TaxRequestInfo pTaxRequestInfo,
                                                       Order pOrder,
                                                       java.util.Locale pLocale,
                                                       RepositoryItem pProfile,
                                                       java.util.Map pExtraParameters)
                                                throws PricingException
create a TaxableItem for the input relationship and TaxRequestInfo. This implementation finds the sum of the amounts for each DetailedItemPriceInfo that apply to a Range that is inside the Range for this Relationship Extending classes can override this method to gain finer control over the manner in which units of a CommerceItem are assigned to a CommerceItemRelationship.

Parameters:
pRelationship - the relationship for which a TaxableItem is needed.
pTaxRequestInfo - the TaxRequestInfo object into which the returned TaxableItem will be inserted.
Throws:
PricingException

assignItemTaxAmounts

protected void assignItemTaxAmounts(Order pOrder,
                                    TaxPriceInfo pOrderTax,
                                    TaxStatus pStatus)
                             throws PricingException
Assign each detail's tax for the given order. This method will assign a tax value for the detail proportional to the details cost compared to the order cost. The calculation also takes into consideration the discount share that the item has received, as well as any manual adjustments (always a negative number as it's an adjustment as opposed to a discount). For example, in its simplest form, if the order is $100, the detail is $20, and the tax is $10: the detail's tax will be $2. This method is used if calculateTaxByShipping is false.

Parameters:
pOrder - The order that was just taxed.
pOrderTax - The orders tax.
pStatus - This is the tax status that was returned from the TaxProcessor. This is currently ignored. If the status were to include the item level tax breakdown, this method could be extended to use that information.
Throws:
PricingException

assignItemTaxAmounts

protected void assignItemTaxAmounts(ShippingGroup pShippingGroup,
                                    TaxPriceInfo pTaxPriceInfo,
                                    OrderPriceInfo pOrderPrice,
                                    OrderPriceInfo pShippingSubtotal,
                                    TaxStatus pStatus)
                             throws PricingException
Assign each detail's tax for the given order. This method will assign a tax value for the detail proportional to the details cost compared to the shipping group subtotal. For example, if the shipping subtotal is $100, the detail is $20, and the tax is $10: the detail's tax will be $2. This method is used if calculateTaxByShipping is true.

Parameters:
pShippingGroup - The shipping group whose details will be update
pTaxPriceInfo - The TaxPriceInfo for the shipping group
pOrderPrice - The TaxPriceInfo for the entire order
pShippingSubtotal - The price info containing the subtotal information for the shipping group
pStatus - This is the tax status that was returned from the TaxProcessor. This is currently ignored. If the status were to include the item level tax breakdown, this method could be extended to use that information.
Throws:
PricingException

getRelationshipsToAssignTaxTo

public java.util.List getRelationshipsToAssignTaxTo(ShippingGroup pShippingGroup)
Returns the list of ShippingGroupCommerceItemRelationships that should be assigned tax. By default, this returns all ShippingGroupCommerceItemRelationships within the given shipping group.

Parameters:
pShippingGroup - the shipping group being taxed
Returns:
List of ShippingGroupCommerceItemRelationships that should be assigned tax.

doStartService

public void doStartService()
                    throws ServiceException
Description copied from class: GenericService
This is called after a Service has been created, placed into the naming hierarchy, and initialized with its configured property values. The Service should override this method to start any processes it requires.

Overrides:
doStartService in class GenericService
Throws:
ServiceException - if the Service had a problem starting up