Back to top
 
 
 

Customizing Tax Adjusters

Customers can change the way tax rates are applied to a CPBM invoice.
  1. Change the engine to customized implementation:
    1. Implement a new TaxEngine by implementing the interface TaxEngine (com.vmops.service.TaxEngine) and put it inside the citrix.cpbm.custom bundle.
    2. Edit the cloud.properties at /usr/share/vts3/repository/prop to point to the new entry by editing the property tax.engine.implementation. Point it to the new implementation.
    3. Restart the CPBM service.
  2. Adding new engines over and above the existing engine:
    1. Implement a new TaxEngine by implementing the interface TaxEngine (com.vmops.service.TaxEngine) and put it inside the citrix.cpbm.custom bundle.
    2. Add one or more such implementations.
    3. Open the application context file applicationContext-admin-customizations.xml inside the citrix.cpbm.custom bundle.
      Define a bean for each implementation:
      <bean name="taxEngineCustom" class="<New Implementation path>" >   		     	</bean>
    4. Add the above created bean to the list 'taxEngineList':
      <bean id="taxEngineList" class="java.util.ArrayList">  		<constructor-arg>  			<list>  				<ref bean="taxEngine" />  				<ref bean="taxEngineCustom" />  			</list>  		</constructor-arg>  	</bean>

      or

      <bean id="taxEngineList" class="java.util.ArrayList">  		<constructor-arg>  			<list>  				<ref bean="taxEngineCustom" />  			</list>  		</constructor-arg>  	</bean>
    5. Restart the CPBM service.

      Note: You can remove the default implementation and/or add multiple such beans in the list.Beans will be called in the same order as defined in the list.
  3. Example:
    public interface RateAdjuster {        /**     * @param invoice A invoice for the rate adjuster to get info related to this invoice such as tenant, billing period     *          etc.     * @param invoiceItemsToBeProcessed Every RateAdjuster should process the invoiceItemsToBeProcessed and replace them     *          with adjusted items for the next adjusters for further processing. The first adjuster sees the     *          invoiceItems of ChargeType.CHARGE     * @param serviceStart is the billing period start for the moment, it can be any day in the billing period if we     *          decided to support number of days for a promotion (as oppose to number of billing period)     * @param serviceEnd is the billing period end for the moment, it can be any day in the billing period if we decided     *          to support number of days for a promotion (as oppose to number of billing period)     * @param previewMode if true, nothing will be written to db or the billing activity file. Plan to remove this soon.     *          implementation of this interface should create invoice item for discount or tax and add to the invoice     *          items and should adjust the invoice's discount/tax and amount due field.     * @return {@link BigDecimal}     */      public abstract BigDecimal compute(Invoice invoice, List<InvoiceItem> invoiceItemsToBeProcessed, Date serviceStart,        Date serviceEnd, boolean previewMode);    }  
    public interface TaxEngine extends RateAdjuster {        /**     * this method is get called from CPBM catalog UI at the time of subscribing product bundle. and it should return the     * proper tax     * @param amount     * @return {@link BigDecimal}     */    public BigDecimal compute(BigDecimal amount);    }  
    Example Custom Tax Rate Adjuster
    package com.citrix.cpbm.custom.service.impl;    import java.math.BigDecimal;  import java.util.Date;  import java.util.List;    import org.springframework.beans.factory.annotation.Autowired;    import com.vmops.internal.service.ActorService;  import com.vmops.model.Invoice;  import com.vmops.model.InvoiceItem;  import com.vmops.model.InvoiceItem.ChargeType;  import com.vmops.model.User;  import com.vmops.service.TaxEngine;      public class ChannelSpecificTaxPolicy implements TaxEngine {      @Autowired    ActorService actorService;      @Override    public BigDecimal compute(Invoice invoice, List<InvoiceItem> invoiceItemsToBeProcessed, Date serviceStart,        Date serviceEnd, boolean previewMode) {      BigDecimal taxPercent = BigDecimal.TEN;      BigDecimal taxableAmount = invoice.getAmount();      BigDecimal totalTaxOnInvoice = BigDecimal.ZERO;      if (!previewMode) {        if ("usachannel".equalsIgnoreCase(invoice.getTenant().getSourceChannel().getName())) {          taxPercent = BigDecimal.ONE;        }        if ("indiachannel".equalsIgnoreCase(invoice.getTenant().getSourceChannel().getName())) {          taxPercent = BigDecimal.TEN;        }        totalTaxOnInvoice = taxableAmount.multiply(taxPercent).divide(BigDecimal.valueOf(100));        InvoiceItem taxItem = new InvoiceItem(invoice, totalTaxOnInvoice, null, ChargeType.TAX, serviceStart, serviceEnd,            null, null, null, null, "Tax @ " + taxPercent + "%");        invoice.getInvoiceItems().add(taxItem); // adding tax to the invoice items        invoice.setTaxAmount(invoice.getTaxAmount().add(totalTaxOnInvoice));// adjusting total tax amount of the invoice        invoice.setAmount(invoice.getAmount().add(totalTaxOnInvoice));// adjusting total amount of the invoice        invoice.setAmountDue(invoice.getAmountDue().add(totalTaxOnInvoice));// adjusting total amount due of the invoice      }      return totalTaxOnInvoice;    }     // this method is called from CPBM Catalog UI at the time of subscribing the product bundle.     @Override    public BigDecimal compute(BigDecimal amount) {      BigDecimal taxPercent = BigDecimal.TEN;      BigDecimal totalTax = BigDecimal.ZERO;      User effUser = actorService.getDelegateActor();      if (effUser != null && effUser.getTenant().getSourceChannel() != null) {        if ("usachannel".equalsIgnoreCase(effUser.getTenant().getSourceChannel().getName())) {          taxPercent = BigDecimal.ONE;        }        if ("indiachannel".equalsIgnoreCase(effUser.getTenant().getSourceChannel().getName())) {          taxPercent = BigDecimal.TEN;        }        totalTax = amount.multiply(taxPercent).divide(BigDecimal.valueOf(100));      }      return totalTax;    }  }  
 

Comments