Skip to main content
Avalara Help Center

AvaTax for Communications Java Interface

Introduction

Software Requirements

  • The standard AFC system.
  • The Java Runtime Environment, version 1.4.1 or higher. The JRE can be obtained from http://www.javasoft.com.

Configuration

Before using the AFC Java Interface, you must have the standard AFC system installed with the EZtax DLL or shared object in your path. You may also wish to set an environment variable to the Java Interface codebase directory. The codebase directory, found at <Java Interface Home>\codebase, contains both the Java Interface jar file and the JNI bridge to AFC. When running with the Java Interface, you will need to set your classpath to point to the AFC Java Interface jar file and you will need to run with java.library.path set to the codebase directory.

For example, if I set the environment variable EZTAXJAVA to C:\BillSoft\EZtax\JavaInt\codebase, I can then run my Java application by calling

java –classpath %EZTAXJAVA%\EZtax.jar –Djava.library.path=%EZTAXJAVA% MyApplication

Using the Java Interface

The AFC Java Interface encapsulates the AFC API calls and accompanying structures and constants. The main Java class, billsoft.EZtax.EZtax, is the starting point that contains all the API calls. Following is a sample that uses the Java interface to calculate taxes based on a pcode:

import billsoft.EZtax.*;
import java.text.DecimalFormat;

public class EZJavaTest
{
    private EZtax EZtax; 
    private long handle;

    public static void main(String[] args)
    {
        EZJavaTest theTest = new EZJavaTest(); 
        theTest.run();
    }

    public void run()
    {
        EZtax = new EZtax();

        try
        {
            // Initialize EZtax 
            EZtax.EZtaxStart();

            FilePaths paths = new FilePaths();
            paths.EZtax_data = "e:\\Testing\\dbfiles\\EZtax.dat"; 
            paths.EZtax_IDX = "e:\\Testing\\dbfiles\\EZtax.idx"; 
            paths.EZtax_DLL = "e:\\Testing\\dbfiles\\EZtax.dll"; 
            paths.EZtax_log = "EZtax.log";
            paths.EZtax_npanxx = "e:\\Testing\\dbfiles\\EZtax.npa"; 
            paths.EZtax_status = "EZtax.sta";
            paths.EZtax_temp_file = "e:\\Testing\\dbfiles\\tmp77777.dat"; 
            paths.EZtax_location = "e:\\Testing\\dbfiles\\EZDesc.dat"; 
            paths.EZtax_zip = "e:\\Testing\\dbfiles\\EZZIP.dat"; 
            paths.EZtax_customer_key = "e:\\Testing\\dbfiles\\cust_key"; 
            paths.EZtax_pcode = "e:\\Testing\\dbfiles\\EZtax.pcd"; 
            paths.EZtax_jcode = "e:\\Testing\\dbfiles\\EZtax.jtp"; 
            paths.EZtax_over = "";

            handle = EZtax.EZtaxInit(true, paths);

            // Open the pcode database 
            EZtax.EZtaxOpen(handle, EZtaxConst.PCODE);

            doEZtaxPCode();

            // Close the pcode database 
            EZtax.EZtaxClose(handle, EZtaxConst.PCODE);

            // Exit the system 
            EZtax.EZtaxExit();
        }
        catch (Exception e)
        {
            System.out.println("EXCEPTION: " + e.getMessage());

            EZtax.EZtaxExit();
        }
    }
    
    private void doEZtaxPCode() throws Exception
    {
        PCode objPCode = new PCode();

        objPCode.BTN_P_Code = 1248800;
        objPCode.orig_P_Code = 1248800;
        objPCode.term_P_Code = 1898500; 
        objPCode.tax_data.business = false; 
        objPCode.tax_data.sale = true; 
        objPCode.tax_data.regulated = true; 
        objPCode.tax_data.trans_type = EZtaxConst.INTERSTATE; 
        objPCode.tax_data.srv_type = EZtaxConst.TOLL; 
        objPCode.tax_data.date = 20030415; 
        objPCode.tax_data.charge = 1.0F; 
        objPCode.tax_data.minutes = 15.33F; 
        objPCode.tax_data.lines = 3;
        objPCode.tax_data.locations = 1; 
        objPCode.tax_data.incorp = true; 
        objPCode.tax_data.FED_exempt = false; 
        objPCode.tax_data.st_exempt = false; 
        objPCode.tax_data.co_exempt = false; 
        objPCode.tax_data.loc_exempt = false; 
        objPCode.tax_data.FED_J_Code = 0;
        objPCode.tax_data.st_J_Code = 0;
        objPCode.tax_data.co_J_Code = 0;
        objPCode.tax_data.loc_J_Code = 0;
        objPCode.tax_data.inv_no = 3;
        objPCode.tax_data.srv_lvl_no = 4;
        objPCode.tax_data.optional = 5; 
        objPCode.tax_data.cust_no = "This is a test";
        
        objPCode.tax_data.s_exempt = new TaxExempt[2]; 
        
        TaxExempt tex = new TaxExempt();
        tex.tax_level = 1;
        tex.tax_type = 10;
        tex.exempt_J_Code = 1234567890; 
        objPCode.tax_data.s_exempt[0] = tex;

        tex = new TaxExempt(); 
        tex.tax_level = 2;
        tex.tax_type = 11;
        tex.exempt_J_Code = 1234567891; 
        objPCode.tax_data.s_exempt[1] = tex;
        
        TaxesTbl[] taxes = EZtax.EZtaxPCode(handle, objPCode); 
        
        printTaxesTbl(taxes);
    }

    private void printTaxesTbl(TaxesTbl[] taxes)
    {
        if (taxes.length == 0) 
            System.out.println("No taxes returned");

        DecimalFormat df = new DecimalFormat("0.######"); 
        
        for (int i=0; i<taxes.length; i++)
        {
            System.out.println("JCode: " + taxes[i].j_code); 
            System.out.println("Tax Type: " + taxes[i].tax_type); 
            System.out.println("Tax Level: " + getTaxLevelStr(taxes[i].tax_level)); 
            System.out.println("Calc Type: " + getCalcTypeStr(taxes[i].calc_type)); 
            System.out.println("Rate: " + df.format(taxes[i].rate)); 
            System.out.println("Tax Amount: " + df.format(taxes[i].tax_amount)); 
            System.out.println("Description: " + taxes[i].desc);

            System.out.println("");
        }
    }
}

Documentation 

The AFC Java Interface includes API documentation for the Java classes in the form of HTML pages. This documentation can be found in the <Java Interface Home>\docs directory. More information on AFC can be found in TM_00101_AFC User Manual_Telecom, which is provided with the standard AFC system.

  • Was this article helpful?