Skip to main content
Avalara Help Center

TM_00125_AFC .NET Interface

Introduction

Software Requirements

The standard AFC system installed on system is required.

Configuration

Before using the AFC .NET Interface, you must have the standard AFC system installed with the AFC DLL in your path. You also need to add a reference to your .NET project to the EZtax.NET.dll assembly.

Using the AvaTax for Communications (AFC) .NET Interface

The AFC .NET Interface encapsulates the AFC API calls and accompanying structures and constants. The main .NET class, BillSoft.EZtaxNET.EZtax, is the starting point that contains all the API calls.

Sample Code Method Descriptions

Sample Method

Description

RunTaxCalculationExample(session)

Shows the basic steps for performing tax calculations with AFC On-Premise .NET wrapper

RunInvoiceModeExample(session)

Sample of enabling and calculating taxes in invoice mode

RunExemptionExample(session)

Sample of using simple level, tax type and category exemptions in a tax calculation

RunScopeCategoryExemptionExample(session)

Sample of using scoped category exemptions

RunExclusionExample(session)

Sample of using exclusions 

RunTrafficStudyExample(session)

Sample of apply traffic study override to safe harbor rates

RunGetAddressExample(session)

Sample of getting location data for a pcode from the engine

RunOverrideExample(session)

Sample of applying an override to a tax calculation call

RunVATExample(session)

Sample of getting VAT taxes for a foreign location

RunTaxInclusiveExample(session)

Sample for a tax inclusive tax calculation

RunBridgeConferenceExample(session)

Sample of a bridge conference multi-participant calculation

RunWriteToLogExample()

Sample of writing to a tax log file

RunWriteToLogV914Example()

Advanced sample of writing to a v914 tax log file

RunTaxCalculationExampleV914()

Advanced sample of fetching v914 tax data for a tax calculation

RunPrivateLineUsingV914Example()

Private line or P2P sample using v914 tax data

.NET Sample code

using System;
using System.Collections;
using BillSoft.EZTaxNET;
using System.IO;

namespace EZTaxSample
{
   /// <summary>
   /// Provides examples for using C# with the EZTax .NET library
   /// </summary>
   class EZTaxSample
   {
      // TODO: Change the value of this string to the directory where your EZTax database files are stored.
      string databaseDirectory = @"C:\BillSoft\EZTax\Data\";
      string workingDirectory = string.Empty;
      const bool EnableLogging = true;

      /// <summary>
      /// Main entry point for application.
      /// Supports arg[1] as database directory override
      /// </summary>
      /// <param name="args"></param>
      public static void Main(string[] args)
      {
         EZTaxSample sample = new EZTaxSample();

         if (args != null && args.Length > 0)
         {
            sample.databaseDirectory = args[0];
            if (args.Length > 1)
            {
               sample.workingDirectory = args[1];
            }
         }

         // If the InitializeTest method returns false
         //   1. Make sure that the EZTax2.dll is visible to the application.
         //   2. Make sure that the databaseDirectory string has been changed to the directory
         //      where your EZTax database files are stored.
         //   3. Make sure that each entry of the FilePaths object returned by the GetFilePaths method
         //      is correct.
         //   4. Your EZTax database files may have expired.
         //   5. Refer to the status files for error information.
         try
         {
            EZTaxSession session = sample.InitializeTest(sample.workingDirectory);

            if (session != null)
            {
               sample.RunTaxCalculationExample(session);
               sample.RunInvoiceModeExample(session);      // Invoice (Customer) Mode
               sample.RunExemptionExample(session);
               sample.RunScopeCategoryExemptionExample(session);
               sample.RunExclusionExample(session);
               sample.RunTrafficStudyExample(session);
               sample.RunGetAddressExample(session);
               sample.RunOverrideExample(session);
               sample.RunVATExample(session);
               sample.RunTaxInclusiveExample(session);
               sample.RunBridgeConferenceExample(session);
               sample.RunWriteToLogExample();
               sample.RunWriteToLogV914Example();
               sample.RunTaxCalculationExampleV914();
               sample.RunPrivateLineUsingV914Example();
               session.Dispose();
            }
         }
         catch (EZTaxException ex)
         {
            Console.WriteLine("An EZTaxException occurred: " + ex.Message);
         }
      }

      #region EZTax Examples

      /// <summary>
      /// Initialize the test.
      /// </summary>
      /// <returns></returns>
      private EZTaxSession InitializeTest(string workingDir)
      {
         FilePaths paths = GetSampleFilePaths(workingDir);
         EZTaxSession session = null;

         try
         {
            Console.WriteLine("--- EZTax.NET Sample Program ----------------------");
            Console.WriteLine();
            Console.WriteLine("EZTax DLL version:      {0}", EZTax.DllVersion);
            Console.WriteLine("EZTax database version: {0}", EZTax.GetDatabaseVersion(paths.Data));
            Console.WriteLine();

            // Attempt to initialize an EZTax session.
            if ((workingDir == null) || (workingDir == string.Empty))
            {
               //Use default working directory 
               session = new EZTaxSession(EnableLogging, paths);
            }
            else
            {
               //Specify the working directory
               session = new EZTaxSession(EnableLogging, paths, workingDir);
            }
         }
         catch (EZTaxException ex)
         {
            Console.WriteLine("An EZTaxException occurred: {0}", ex.Message);
            return null;
         }
         catch (Exception ex)
         {
            Console.WriteLine(ex.ToString());
            return null;
         }
         finally
         {
         }

         return session;
      }

      /// <summary>
      /// Shows the basic steps for performing tax calculations with EZTax. 
      /// </summary>
      private void RunTaxCalculationExample(EZTaxSession session)
      {
         Console.WriteLine("--- Tax Calculation example ---");
         Console.WriteLine();

         if (session == null)
         {
            Console.WriteLine("ERROR: session pointer is invalid or not open!");
            return;
         }

         try
         {
            ZipAddress address1 = new ZipAddress("USA", "KS", "Johnson", "Overland Park", "66212", null);
            ZipAddress address2 = new ZipAddress("USA", "NY", "New York", "New York", "10242", null);
            uint npanxx = 913859;

            uint pcode1 = session.ZipToPCode(address1);
            uint pcode2 = session.ZipToPCode(address2);

            Transaction trans = session.CreateTransaction();
            FillTransactionData(trans);
            TaxData[] taxes;

            // Calculate taxes
            trans.BillToPCode = pcode1;         // Bill-to jurisdiction must always be specified
            taxes = trans.CalculateTaxes();

            if (taxes == null)
            {
               Console.WriteLine("No taxes were returned for this transaction");
               Console.WriteLine();
            }
            else
            {
               Console.WriteLine("Results for tax calculation ({0} taxes)", taxes.Length);
               DisplayTaxes(taxes, 0.0);
            }

            // Calculate taxes using specific exemptions
            trans.BillToPCode = pcode1;

            // Exempt the Local E911 (Wireless) tax.
            uint exemptJCode = session.PCodeToJCode(pcode1);
            trans.Exemptions.Add(new TaxExemption(exemptJCode, TaxLevel.Local, TaxType.E911_TAX_WIRELESS));
            taxes = trans.CalculateTaxes();

            if (taxes == null)
            {
               Console.WriteLine("No taxes were returned for this transaction");
               Console.WriteLine();
            }
            else
            {
               Console.WriteLine("Results for tax calculation with exemptions ({0} taxes)", taxes.Length);
               DisplayTaxes(taxes, 0.0);
            }

            trans.Exemptions.Clear();           // Remove exemptions from transaction.

            // Calculate adjustments
            trans.ClearJurisdictionInfo();      // Should always call this method before calculating
            // taxes for a different jurisdiction. Use Clear()
            // to clear all the transaction data. You may also set
            // the trans.AutoClear property to true to clear all the
            // transaction data after performing a tax calculation.
            trans.BillToPCode = pcode2;
            trans.OriginationNpaNxx = npanxx;
            trans.TerminationAddress = address1;
            taxes = trans.CalculateAdjustments();

            if (taxes == null)
            {
               Console.WriteLine("No adjustments were returned for this transaction");
               Console.WriteLine();
            }
            else
            {
               Console.WriteLine("Results for tax adjustments ({0} taxes)", taxes.Length);
               DisplayTaxes(taxes, 0.0);
            }

            // Calculate taxes for sales transactions
            SalesTransaction salesTrans = new SalesTransaction();
            FillSalesTransaction(salesTrans);

            salesTrans.Session = session;  // When creating a transaction or sales transaction using the
            // new operator, you must specify the EZTaxSession to use for
            // calculating taxes.

            salesTrans.PointOfAcceptance = address2;
            salesTrans.ShipFrom = address1;
            salesTrans.ShipTo = address2;

            taxes = salesTrans.CalculateTaxes();

            if (taxes == null)
            {
               Console.WriteLine("No taxes were returned for this sales transaction");
               Console.WriteLine();
            }
            else
            {
               Console.WriteLine("Tax calculation results for sales transaction ({0} taxes)", taxes.Length);
               DisplayTaxes(taxes, 0.0);
            }

            // Calculate adjustments for sales transactions
            taxes = salesTrans.CalculateAdjustments();

            if (taxes == null)
            {
               Console.WriteLine("No adjustments were returned for this sales transaction");
               Console.WriteLine();
            }
            else
            {
               Console.WriteLine("Tax adjustments results for sales transaction ({0} taxes)", taxes.Length);
               DisplayTaxes(taxes, 0.0);
            }
         }
         catch (EZTaxException ex)
         {
            Console.WriteLine("An EZTaxException occurred: {0}", ex.Message);
         }
      }

      /// <summary>
      /// Shows the basic steps for calculating taxes using Customer Mode with EZTAx
      /// </summary>
      private void RunInvoiceModeExample(EZTaxSession session)
      {
         Console.WriteLine("--- Invoice Mode example ---");
         Console.WriteLine();

         if (session == null)
         {
            Console.WriteLine("ERROR: session pointer is invalid or not open!");
            return;
         }

         try
         {
            // Set Invoice Mode on for the EZTax session
            session.InvoiceModeOn = true;

            // Get all invoice transactions
            Transaction[] transactions = GetTransactions();

            // Calculate taxes for each transaction
            foreach (Transaction transaction in transactions)
            {
               // Use the same EZTax session to calculate taxes for each transaction.
               transaction.Session = session;
               transaction.CalculateTaxes();
            }

            // Get the invoice totals
            InvoiceTaxData[] taxes = session.GetInvoiceTotals();

            if (taxes == null)
            {
               Console.WriteLine("No taxes were returned for this invoice");
               Console.WriteLine();
            }
            else
            {
               Console.WriteLine("Taxes returned for invoice: ({0} taxes)", taxes.Length);
               DisplayInvoicedTaxes(taxes);
            }
         }
         catch (EZTaxException ex)
         {
            Console.WriteLine("An EZTaxException occurred: " + ex.Message);
         }

         session.InvoiceModeOn = false;
      }

      /// <summary>
      /// Shows how to specify tax exemptions for a transaction.
      /// </summary>
      /// <returns></returns>
      public void RunExemptionExample(EZTaxSession session)
      {

         Console.WriteLine("--- Tax Exemptions example --------------------------");
         Console.WriteLine();

         if (session == null)
         {
            Console.WriteLine("ERROR: session pointer is invalid or not open!");
            return;
         }

         ZipAddress address = new ZipAddress("USA", "KS", "Johnson", "Overland Park", "66212", null);

         try
         {
            Transaction trans = session.CreateTransaction();
            FillTransactionData(trans);
            trans.BillToAddress = address;
            TaxData[] taxes;

            Console.WriteLine("Calculating taxes without exemptions...");
            taxes = trans.CalculateTaxes();

            DisplayTaxes(taxes, 0.0);

            // Exempt all level exemptible taxes for this transaction
            trans.FederalExempt = true;      // Set the exempt flag to true for the Federal level
            trans.StateExempt   = true;      // Set the exempt flag to true for the State level
            trans.CountyExempt  = true;      // Set the exempt flag to true for the County level
            trans.LocalExempt   = true;      // Set the exempt flag to true for the Local level

            Console.WriteLine();
            Console.WriteLine("Calculating taxes after exempting all State taxes and the Local Sales Tax...");
            Console.WriteLine("Note:  Non-level exemptible Federal taxes will still generate taxes");
            taxes = trans.CalculateTaxes();
            DisplayTaxes(taxes, 0.0);

            // Un-exempt all level exemptible taxes for this transaction
            trans.FederalExempt = false;      // Set the exempt flag to true for the Federal level
            trans.StateExempt   = false;      // Set the exempt flag to true for the State level
            trans.CountyExempt  = false;      // Set the exempt flag to true for the County level
            trans.LocalExempt   = false;      // Set the exempt flag to true for the Local level

            // Apply specified exemptions
            // Add a specific exemption. Exempt the Sales Tax Category
            uint jcode = session.ZipToJCode(address);
            TaxExemption exemption = new TaxExemption();
            exemption.JCode = jcode;                      // Specify the jurisdiction for the exemption
            exemption.TaxCategory = TaxCategory.SALES_AND_USE_TAXES;                    // Specify which tax category to exempt
            trans.Exemptions.Add(exemption);

            // Add a specific exemption. Exempt the Federal Telecom Relay Surcharge for Cellular Tax
            // NOTE:  Non-billable taxes will only be returned through the API if configured to do so.
            //  To return non-billable taxes, add [returnnonbillable=true] in the configuration settings for EZTax.cfg 
            exemption = new TaxExemption();
            exemption.JCode = jcode;                      // Specify the jurisdiction for the exemption
            exemption.TaxLevel = TaxLevel.Federal;        // Set the tax level
            exemption.TaxType = TaxType.TELECOMMUNICATIONS_RELAY_SURCHARGE_CELLULAR; // Specify which tax to exempt
            trans.Exemptions.Add(exemption);

            // Add a tax category scope exemption.
            // jcode = jCode;
            // TaxType = category;
            // TaxCatScope = taxCatScope;
            exemption = new TaxExemption();
            exemption.JCode = jcode;                                                                             // Specify the jurisdiction for the exemption
            exemption.TaxType = TaxCategory.SALES_AND_USE_TAXES;                                                 // Set the tax type to the value of the tax category
            exemption.TaxCatScope = TaxCategoryScope.Federal | TaxCategoryScope.County | TaxCategoryScope.Local; // Fed, State, County, Local or some combination of these
            trans.Exemptions.Add(exemption);

            Console.WriteLine();
            Console.WriteLine("Calculating taxes after applying specified exemptions...");
            taxes = trans.CalculateTaxes();
            DisplayTaxes(taxes, 0.0);
         }
         catch (EZTaxException ex)
         {
            Console.WriteLine("An EZTaxException occurred: " + ex.Message);
         }
      }

        /// <summary>
        /// Shows how to specify tax category scope exemptions for a transaction.
        /// </summary>
        /// <returns></returns>
      public void RunScopeCategoryExemptionExample(EZTaxSession session)
      {

          Console.WriteLine("--- Tax Category Scope Exemptions example --------------------------");
          Console.WriteLine();

          if (session == null)
          {
              Console.WriteLine("ERROR: session pointer is invalid or not open!");
              return;
          }

          ZipAddress address = new ZipAddress("USA", "NY", "New York", "New York", "10023", null);

          try
          {
              Transaction trans = session.CreateTransaction();
              FillTransDataForScopeCatExemp(trans);
              trans.BillToAddress = address;
              TaxData[] taxes;

              Console.WriteLine("Calculating taxes without exemptions...");
              taxes = trans.CalculateTaxes();

              DisplayTaxes(taxes, 0.0);

              // Add a tax category scope exemptions.
              // jcode = jCode;
              // TaxType = category;
              // TaxCatScope = taxCatScope;
              uint jcode = session.ZipToJCode(address);
              TaxExemption exemption = new TaxExemption();
              //Exemption 1
              exemption.JCode = jcode;                                                                             // Specify the jurisdiction for the exemption
              exemption.TaxType = TaxCategory.EXCISE_TAXES;                                                 // Set the tax type to the value of the tax category
              exemption.TaxCatScope = TaxCategoryScope.Federal | TaxCategoryScope.State; // Fed, State, County, Local or some combination of these
              trans.Exemptions.Add(exemption);
              //Exemption 2
              exemption = new TaxExemption();
              exemption.JCode = jcode;                                                                             // Specify the jurisdiction for the exemption
              exemption.TaxType = TaxCategory.SALES_AND_USE_TAXES;                                                 // Set the tax type to the value of the tax category
              exemption.TaxCatScope = TaxCategoryScope.Federal | TaxCategoryScope.State; // Fed, State, County, Local or some combination of these
              trans.Exemptions.Add(exemption);
              //Exemption 3
              exemption = new TaxExemption();
              exemption.JCode = jcode;                                                                             // Specify the jurisdiction for the exemption
              exemption.TaxType = TaxCategory.E911_CHARGES;                                                 // Set the tax type to the value of the tax category
              exemption.TaxCatScope = TaxCategoryScope.Federal | TaxCategoryScope.State; // Fed, State, County, Local or some combination of these
              trans.Exemptions.Add(exemption);
              //Exemption 4
              exemption = new TaxExemption();
              exemption.JCode = jcode;                                                                             // Specify the jurisdiction for the exemption
              exemption.TaxType = TaxCategory.REGULATORY_CHARGES;                                                 // Set the tax type to the value of the tax category
              exemption.TaxCatScope = TaxCategoryScope.Federal | TaxCategoryScope.State; // Fed, State, County, Local or some combination of these
              trans.Exemptions.Add(exemption);
              //Exemption 5
              exemption = new TaxExemption();
              exemption.JCode = jcode;                                                                             // Specify the jurisdiction for the exemption
              exemption.TaxType = TaxCategory.CONNECTIVITY_CHARGES;                                                 // Set the tax type to the value of the tax category
              exemption.TaxCatScope = TaxCategoryScope.Federal | TaxCategoryScope.State; // Fed, State, County, Local or some combination of these
              trans.Exemptions.Add(exemption);

              Console.WriteLine();
              Console.WriteLine("Calculating taxes after applying specified exemptions...");
              taxes = trans.CalculateTaxes();
              DisplayTaxes(taxes, 0.0);
          }
          catch (EZTaxException ex)
          {
              Console.WriteLine("An EZTaxException occurred: " + ex.Message);
          }
      }

      /// <summary>
      /// Shows how to specify exclusions for a single transaction.
      /// Note: This approach should not be used in combination with an 
      ///   exclusion file unless used only to add new exclusions for a
      ///   single transaction.
      /// </summary>
      /// <returns></returns>
      public void RunExclusionExample(EZTaxSession session)
      {

         Console.WriteLine("--- Tax Exclusion example --------------------------");
         Console.WriteLine();

         if (session == null)
         {
            Console.WriteLine("ERROR: session pointer is invalid or not open!");
            return;
         }

         ZipAddress address1 = new ZipAddress("USA", "KS", "Johnson", "Overland Park", "66212", null);
         ZipAddress address2 = new ZipAddress("USA", "NY", "New York", "New York", "10242", null);

         try
         {
            Transaction trans = session.CreateTransaction();
            FillTransactionData(trans);
            trans.TransactionType = TransactionType.INTERSTATE;
            trans.ServiceType = ServiceType.TOLL;
            trans.BillToAddress = address1;
            trans.OriginationAddress = address2;
            trans.TerminationAddress = address2;

            TaxData[] taxes;

            Console.WriteLine("Calculating taxes without exclusions...");
            taxes = trans.CalculateTaxes();
            DisplayTaxes(taxes, 0.0);

            Exclusion exc = new Exclusion("USA", "NY", true);

            trans.Exclusions.Add(exc);

            Console.WriteLine();
            Console.WriteLine("Calculating taxes after applying exclusions...");
            taxes = trans.CalculateTaxes();
            DisplayTaxes(taxes, 0.0);

            /////  Sample of Clearing Exclusions  ////
            trans.Exclusions.Clear();
            Console.WriteLine();
            Console.WriteLine("Calculating taxes after clearing exclusions...");
            taxes = trans.CalculateTaxes();
            DisplayTaxes(taxes, 0.0);
         }
         catch (EZTaxException ex)
         {
            Console.WriteLine("An EZTaxException occurred: " + ex.Message);
         }
      }

        /// <summary>
        /// Shows how to specify safe harbor overrides for a single transaction.
        /// Note: This approach should not be used in combination with an 
        ///   override file for safe harbor, since it won't find the safe harbor values to override
        /// </summary>
        /// <returns></returns>
        public void RunTrafficStudyExample(EZTaxSession session)
        {

            Console.WriteLine("--- Traffic Study example --------------------------");
            Console.WriteLine();

            if (session == null)
            {
                Console.WriteLine("ERROR: session pointer is invalid or not open!");
                return;
            }

            ZipAddress address1 = new ZipAddress("USA", "KS", "Johnson", "Overland Park", "66212", null);

            try
            {
                Transaction trans = session.CreateTransaction();
                FillTransactionData(trans);
                trans.TransactionType = TransactionType.VOIP;
                trans.ServiceType = ServiceType.ACCESS_CHARGE;
                trans.BillToAddress = address1;

                TaxData[] taxes;

                Console.WriteLine("Calculating taxes without traffic study...");
                taxes = trans.CalculateTaxes();
                DisplayTaxes(taxes, 0.0);

                session.SetSafeHarborTAMOverride(SafeHarborType.VoIP, 0.649, 0.25);

                Console.WriteLine();
                Console.WriteLine("Calculating taxes after applying traffic study...");
                taxes = trans.CalculateTaxes();
                DisplayTaxes(taxes, 0.0);

                /////  Sample of clearing traffic study  ////
                session.ClearSafeHarborTAMOverride(SafeHarborType.ClearAll);
                Console.WriteLine();
                Console.WriteLine("Calculating taxes after clearing traffic study...");
                taxes = trans.CalculateTaxes();
                DisplayTaxes(taxes, 0.0);
            }
            catch (EZTaxException ex)
            {
                Console.WriteLine("An EZTaxException occurred: " + ex.Message);
            }
        }



        /// <summary>
        /// Example using the GetAddress method.
        /// </summary>
        /// <returns></returns>
        public void RunGetAddressExample(EZTaxSession session)
      {

         Console.WriteLine();
         Console.WriteLine("--- GetAddress example ------------------------------");
         Console.WriteLine();

         if (session == null)
         {
            Console.WriteLine("ERROR: session pointer is invalid or not open!");
            return;
         }

         ZipAddress address = new ZipAddress("USA", "KS", "Johnson", "Overland Park", "66212", null);
         try
         {
            uint jcode = session.ZipToJCode(address);

            Console.WriteLine("Getting address information for JCode " + jcode + "...");

            AddressData[] addressArray = session.GetAddress(jcode);
            AddressData previous = null;

            for (int addressIndex = 0; addressIndex < addressArray.Length; addressIndex++)
            {
               AddressData addressData = addressArray[addressIndex];
               String zipRangeLabel = "             ";
               if (previous == null || previous.Locality.CompareTo(addressData.Locality) != 0)
               {
                  Console.WriteLine();
                  Console.WriteLine("Country ISO: " + addressData.CountryISO);
                  Console.WriteLine("State:       " + addressData.State);
                  Console.WriteLine("County:      " + addressData.County);
                  Console.WriteLine("Locality:    " + addressData.Locality);
                  zipRangeLabel = "Zip Range:   ";
               }

               Console.WriteLine(zipRangeLabel + addressData.ZipBegin + "-" + addressData.ZipP4Begin +
                                  " to " + addressData.ZipEnd + "-" + addressData.ZipP4End);

               previous = addressData;
            }

            Console.WriteLine();
         }
         catch (EZTaxException ex)
         {
            Console.WriteLine("An EZTaxException occurred: " + ex.Message);
         }
      }

      /// <summary>
      /// Shows how to insert an override.
      /// </summary>
      /// <returns></returns>
      public void RunOverrideExample(EZTaxSession session)
      {

         Console.WriteLine("--- Override example --------------------------------");
         Console.WriteLine();

         if (session == null)
         {
            Console.WriteLine("ERROR: session pointer is invalid or not open!");
            return;
         }

         ZipAddress address = new ZipAddress("USA", "KS", "Johnson", "Overland Park", "66212", null);
         try
         {
            Transaction trans = session.CreateTransaction();
            FillTransactionData(trans);
            uint pcode = session.ZipToPCode(address);
            trans.BillToPCode = pcode;

            // Get a list of all taxes for this jurisdiction
            TaxRateInfo[] taxRates = session.GetTaxRates(pcode);
            TaxRateInfo stateSalesTax = null;

            foreach (TaxRateInfo tax in taxRates)
            {
               // Display the information for the State Sales Tax for this jurisdiction
               if (tax.TaxLevel == TaxLevel.State && tax.TaxType == TaxType.SALES_TAX)
               {
                  Console.WriteLine("Tax rate information for " + tax.TaxLevel + " - " +
                        session.GetTaxDescription(tax.TaxType));

                  // Display the history for this tax
                  foreach (TaxRateHistory history in tax.History)
                  {
                     DateTime date = history.EffectiveDate;
                     Console.Write("   Effective date: " + (date.Month + 1) + "/" +
                           date.Day + "/" + date.Year);
                     Console.WriteLine("   Allow level exemptions: " + history.LevelExempt.ToString());

                     // Display each bracket for this history record
                     foreach (TaxBracketInfo bracket in history.Brackets)
                     {
                        Console.WriteLine("      Tax rate: " + bracket.TaxRate.ToString("#.####")
                              + "   Maximum base: " + bracket.MaxBase.ToString());
                     }
                  }

                  stateSalesTax = tax;
               }
            }

            if (stateSalesTax == null)
            {
               Console.WriteLine("This jurisdiction does not have a State Sales Tax.");
               Console.WriteLine();
               return;
            }

            Console.WriteLine();
            Console.WriteLine("Calculating taxes before overriding the tax rate: ");
            TaxData[] taxesBeforeOverride = trans.CalculateTaxes();

            foreach (TaxData tax in taxesBeforeOverride)
            {
               // Display the tax calculation result for the State Sales Tax only
               if (tax.TaxLevel == TaxLevel.State && tax.TaxType == TaxType.SALES_TAX)
               {
                  Console.WriteLine("   Tax: " + tax.TaxLevel + " - " + tax.Description +
                        "   Rate: " + tax.Rate.ToString("#.####") +
                        "   Taxable Measure: " + tax.TaxableMeasure.ToString("#.####") +
                        "   Tax Amount: " + tax.TaxAmount.ToString("#.####"));
               }
            }

            // Override the State Sales Tax
            TaxRateHistory rtHistory = new TaxRateHistory();     // Create a history record 
            rtHistory.EffectiveDate = new DateTime(2013, 8, 15);
            rtHistory.LevelExempt = true;                        // Allow level exemptions on this tax.

            TaxBracketInfo bracket1 = new TaxBracketInfo();    // Create a bracket
            bracket1.TaxRate = 0.0555;                         //   with tax rate of 0.555
            bracket1.MaxBase = 100.00;                         //   and a maximum base of 100.00
            rtHistory.Brackets.Add(bracket1);                  // Add the bracket to the history

            TaxBracketInfo bracket2 = new TaxBracketInfo();    // Create a bracket
            bracket1.TaxRate = 0.0566;                         //   with tax rate of 0.555
            bracket1.MaxBase = TaxBracketInfo.NoLimit;         //   and a maximum base of 100.00
            rtHistory.Brackets.Add(bracket2);                  // Add the bracket to the history

            stateSalesTax.History.Add(rtHistory);              // Add the history to the sales tax information

            session.AddOverrideByPCode(pcode, stateSalesTax);   // Override the tax rate within this session

            // Get the list of all taxes for this jurisdiction again
            taxRates = session.GetTaxRates(pcode);

            foreach (TaxRateInfo tax in taxRates)
            {
               // Display the information for the State Sales Tax for this jurisdiction
               if (tax.TaxLevel == TaxLevel.State && tax.TaxType == TaxType.SALES_TAX)
               {
                  Console.WriteLine("Tax rate information for " + tax.TaxLevel + " - " +
                        session.GetTaxDescription(tax.TaxType));

                  // Display the history for this tax
                  foreach (TaxRateHistory history in tax.History)
                  {
                     DateTime date = history.EffectiveDate;
                     Console.Write("   Effective date: " + (date.Month + 1) + "/" +
                           date.Day + "/" + date.Year);
                     Console.WriteLine("   Allow level exemptions: " + history.LevelExempt.ToString());

                     // Display each bracket for this history record
                     foreach (TaxBracketInfo bracket in history.Brackets)
                     {
                        Console.WriteLine("      Tax rate: " + bracket.TaxRate.ToString("#.####")
                              + "   Maximum base: " + bracket.MaxBase.ToString());
                     }
                  }
               }
            }

            Console.WriteLine();
            Console.WriteLine("Calculating taxes after overriding the tax rate: ");
            TaxData[] taxesAfterOverride = trans.CalculateTaxes();

            foreach (TaxData tax in taxesAfterOverride)
            {
               // Display the tax calculation result for the State Sales Tax only
               if (tax.TaxLevel == TaxLevel.State && tax.TaxType == TaxType.SALES_TAX)
               {
                  Console.WriteLine("   Tax: " + tax.TaxLevel + " - " + tax.Description +
                        "   Rate: " + tax.Rate.ToString("#.####") +
                        "   Taxable Measure: " + tax.TaxableMeasure.ToString("#.####") +
                        "   Tax Amount: " + tax.TaxAmount.ToString("#.####"));
               }
            }

            // Clear the overrides for this session
            session.ClearOverrides();

            Console.WriteLine();
            Console.WriteLine("Calculating taxes after clearing the overrides: ");
            TaxData[] taxesAfterClearOverride = trans.CalculateTaxes();

            foreach (TaxData tax in taxesAfterClearOverride)
            {
               // Display the tax calculation result for the State Sales Tax only
               if (tax.TaxLevel == TaxLevel.State && tax.TaxType == TaxType.SALES_TAX)
               {
                  Console.WriteLine("   Tax: " + tax.TaxLevel + " - " + tax.Description +
                        "   Rate: " + tax.Rate.ToString("#.####") +
                        "   Taxable Measure: " + tax.TaxableMeasure.ToString("#.####") +
                        "   Tax Amount: " + tax.TaxAmount.ToString("#.####"));
               }
            }
         }
         catch (EZTaxException ex)
         {
            Console.WriteLine("An EZTaxException occurred: " + ex.Message);
         }
      }

      /// <summary>
      /// Shows the basic steps for performing tax calculations with EZTax.
      /// </summary>
      /// <returns></returns>
      private void RunVATExample(EZTaxSession session)
      {

         Console.WriteLine("--- VAT Tax Calculation example -------------------------");
         Console.WriteLine();

         if (session == null)
         {
            Console.WriteLine("ERROR: session pointer is invalid or not open!");
            return;
         }

         try
         {
            uint pcode1 = session.CountryToPCode("GBR"); // United Kingdom (GBR - Great Britain)
            ZipAddress address = new ZipAddress("USA", "NY", "New York", "New York", "10242", null);
            //uint pcode3 = eztaxSession.ZipToPCode(address);

            Transaction trans = session.CreateTransaction(); // You may create a Transaction or SalesTransaction
            // that is associated with a specific EZTaxSession
            // by calling the EZTaxSession's CreateTransaction
            // or createSalesTransaction methods.
            FillVATTransactionData(trans);
            TaxData[] taxes;

            // Calculate taxes
            trans.BillToPCode = pcode1;          // You may use different types (JCode, PCode, 
            trans.OriginationPCode = pcode1;     // NPANXX Code, ZipAddress, and FIPS Code) to specify 
            trans.TerminationPCode = pcode1;     // each jurisdiction. However, note that doing so may 
            // result in slower performance.

            Console.WriteLine("Calculating taxes...");
            DisplayTransaction(trans, "runVATExample() - CalculateTaxes", 0.0);
            taxes = trans.CalculateTaxes();
            DisplayTaxes(taxes, 0.0);

            // Determine the taxing jurisdiction for the transaction without calculating any taxes
            Console.WriteLine();
            Console.WriteLine("Calculating taxing jurisdiction for transaction...");
            uint taxingJCode = trans.CalculateJurisdiction();
            AddressData[] addressData = session.GetAddress(taxingJCode);

            Console.WriteLine("Taxing jurisdiction: " + addressData[0].Locality +
                               ", " + addressData[0].County + " County, " +
                               addressData[0].State + ", " + addressData[0].CountryISO);
            Console.WriteLine();

            // Calculate adjustments
            trans.ClearJurisdictionInfo();      // Should always call this method before calculating taxes for a 
            // different jurisdiction. Use Clear() to clear all transaction data. 
            // You may also call the trans.setAutoClear(true) method to true to 
            // clear all the transaction data automatically after performing a 
            // tax calculation or adjustment.

            trans.BillToIso = "FRA";          // You may use different types (JCode, PCode, 
            trans.OriginationPCode = pcode1;     // NPANXX Code, ZipAddress, and FIPS Code) to specify 
            trans.TerminationAddress = address;  // each jurisdiction. However, note that doing so may 
            // result in slower performance.

            Console.WriteLine("Calculating adjustments...");
            taxes = trans.CalculateAdjustments();
            DisplayTaxes(taxes, 0.0);

            // Determine the taxing jurisdiction for the transaction without calculating any taxes
            Console.WriteLine();
            Console.WriteLine("Calculating taxing jurisdiction for transaction...");
            taxingJCode = trans.CalculateJurisdiction();
            addressData = session.GetAddress(taxingJCode);

            Console.WriteLine("Taxing jurisdiction: " + addressData[0].Locality +
                               ", " + addressData[0].County + " County, " +
                               addressData[0].State + ", " + addressData[0].CountryISO);
            Console.WriteLine();
            Console.WriteLine("runVATExample() complete!");
            Console.WriteLine();

         }
         catch (EZTaxException ex)
         {
            Console.WriteLine("An EZTaxException occurred: " + ex.Message);
         }
      }

      /**
       * Shows the basic steps for performing tax calculations with EZTax.
       */
      private void RunTaxInclusiveExample(EZTaxSession session)
      {

         Console.WriteLine("--- Tax Inclusive Calculation example -------------------------");
         Console.WriteLine();

         if (session == null)
         {
            Console.WriteLine("ERROR: session pointer is invalid or not open!");
            return;
         }

         ZipAddress address1 = new ZipAddress("USA", "KS", "Johnson", "Overland Park", "66212", null);
         ZipAddress address2 = new ZipAddress("USA", "NY", "New York", "New York", "10242", null);
         uint npanxx = 913859;
         try
         {
            uint pcode1 = session.ZipToPCode(address1);
            uint pcode2 = session.ZipToPCode(address2);

            Transaction trans = session.CreateTransaction(); // You may create a Transaction or SalesTransaction
            // that is associated with a specific EZTaxSession
            // by calling the EZTaxSession's CreateTransaction
            // or createSalesTransaction methods.
            FillTransactionData(trans);
            TaxData[] taxes;

            // Calculate taxes
            trans.BillToPCode = pcode1;       // Bill-to jurisdiction must always be specified.
            // The origination and termination jurisdictions are
            // optional, but if either one of them is entered, all
            // three jurisdictions must be entered as well.

            // Note: Tax Inclusive (reverse) calculaltions create new sessions and status files. No new 
            //       log files are created. The session is closed after each set of calculations so no 
            //       file collisions occur.
            double desiredTotal = 1000.0;
            Console.WriteLine("Calculating tax inclusive (reverse) taxes...");
            DisplayTransaction(trans, "runTaxInclusiveExample() - CalculateTaxInclusiveTaxes", desiredTotal);
            taxes = trans.CalculateTaxInclusiveTaxes(out desiredTotal);

            DisplayTaxes(taxes, desiredTotal);

            // Calculate adjustments
            trans.ClearJurisdictionInfo();      // Should always call this method before calculating taxes for a 
            // different jurisdiction. Use Clear() to clear all transaction data. 
            // You may also call the trans.setAutoClear(true) method to true to 
            // clear all the transaction data automatically after performing a 
            // tax calculation or adjustment.

            trans.BillToPCode = pcode2;          // You may use different types (JCode, PCode, 
            trans.OriginationNpaNxx = npanxx;    // NPANXX Code, ZipAddress, and FIPS Code) to specify 
            trans.TerminationAddress = address1; // each jurisdiction. However, note that doing so may 
            // result in slower performance.

            desiredTotal = 1000.0;
            Console.WriteLine();
            Console.WriteLine("Calculating tax inclusive (reverse) adjustments...");
            DisplayTransaction(trans, "runTaxInclusiveExample() - CalculateTaxInclusiveAdjustments", desiredTotal);
            taxes = trans.CalculateTaxInclusiveAdjustments(out desiredTotal);
            DisplayTaxes(taxes, desiredTotal);

            // Determine the call type for this transaction
            Console.WriteLine();
            Console.WriteLine("Determining call type for transaction...");
            short callType = trans.GetCallType();

            if (callType == TransactionType.INTERSTATE)
            {
               Console.WriteLine("Call type: Interstate");
            }
            else if (callType == TransactionType.INTRASTATE)
            {
               Console.WriteLine("CallType: Intrastate");
            }

            // Determine the taxing jurisdiction for the transaction without calculating any taxes
            Console.WriteLine();
            Console.WriteLine("Calculating taxing jurisdiction for transaction...");
            uint taxingJCode = trans.CalculateJurisdiction();
            AddressData[] addressData = session.GetAddress(taxingJCode);

            Console.WriteLine("Taxing jurisdiction: " + addressData[0].Locality +
                               ", " + addressData[0].County + " County, " +
                               addressData[0].State + ", " + addressData[0].CountryISO);
            Console.WriteLine();

         }
         catch (EZTaxException ex)
         {
            Console.WriteLine("An EZTaxException occurred: " + ex.Message);
         }
      }

      //************************************************************************
      // CalcAndDisplayBridgeConf demonstrates the following:
      //  - Calculating bridge conferencing taxes and displaying the results
      //************************************************************************
      private void CalcAndDisplayBridgeConf(BridgeConference bc, string desc)
      {
         BridgeConferenceTaxes bcTaxes = bc.CalculateTaxes();

         Console.WriteLine(desc + " - Summarized Taxes");
         DisplayTaxes(bcTaxes.SummarizedTaxes, 0.0);

         Console.WriteLine("Participant Taxes ({0} Participants)", bcTaxes.ParticipantCount);
         for (int idx = 0; idx < bcTaxes.ParticipantCount; idx++)
         {
            int ptcnt = 0;

            BridgeConferenceParticipant bcp = bcTaxes.BCParticipants[idx];
            Console.WriteLine("Taxes for Participant {0} / NPANXX {1}", bcp.ParticipantId + 1, bc.ParticipantNpaNxxList[idx]);
            Console.WriteLine("  T/S Pair:           {0:00}/{1:00}", bcp.TransactionType, bcp.ServiceType);
            if (bcp.ErrorCode != 0)
            {
               if (bcp.ErrorCode == ErrorCode.NPANXX_NOT_FOUND)
               {
                  Console.WriteLine("  Error: Invalid NPANXX for Participant - greatest tax liability used");
               }
               else
               {
                  Console.WriteLine("  Error Code:         {0}", bcp.ErrorCode);
                  Console.WriteLine();
                  continue;
               }
            }

            if (bcp.TaxCount == 0)
            {
               Console.WriteLine("   No taxes returned");
               Console.WriteLine();
               continue;
            }

            Console.WriteLine("  Charge:             {0:0.##}", bcTaxes.BCTaxes[bcp.Offset].TransCharge);
            Console.WriteLine();

            for (; ptcnt < bcp.TaxCount; ptcnt++)
            {
               TaxLogDataV914 tax = bcTaxes.BCTaxes[ptcnt + bcp.Offset];
               Console.WriteLine("    Tax Description:    {0}", tax.Description);
               Console.WriteLine("    Jurisdiction PCode: {0}", tax.PCode);
               Console.WriteLine("    Tax Level:          {0}", tax.TaxLevel);
               Console.WriteLine("    Tax Type:           {0}", tax.TaxType);
               Console.WriteLine("    Tax Rate:           {0:0.####}", tax.TaxRate);
               Console.WriteLine("    Tax Amount:         {0:0.####}", tax.TaxAmount);
               Console.WriteLine("    Billable:           {0}", tax.Billable ? "Yes" : "No");
               Console.WriteLine("");
            }
         }
      }

      //************************************************************************
      // RunBridgeConferenceExample demonstrates the following:
      //  - Setting up a brige conference calculation 
      //************************************************************************
      private void RunBridgeConferenceExample(EZTaxSession session)
      {
         Console.WriteLine("--- Bridge Conference Calculation example ---");
         Console.WriteLine();

         if (session == null)
         {
            Console.WriteLine("ERROR: session pointer is invalid or not open!");
            return;
         }

         try
         {
            BridgeConference bc = session.CreateBridgeConference();
            FillTransactionData(bc);

            bc.ProcessInvalidParticipant = true;
            bc.IsAdjustment = false;
            bc.DiscountType = DiscountType.None;

            bc.BillingAddress = new ZipAddress("USA", "KS", null, "Overland Park", "66212", "3382");
            bc.BridgeAddress = new ZipAddress("USA", "TX", "Fort Bend", "Houston", "77053", null);

            bc.AddParticipantNpanxx(913859);  /* Overland Park, KS - FUSF Applies */
            bc.AddParticipantNpanxx(770485);  /* Atlanta, GA - FUSF Applies */
            bc.AddParticipantNpanxx(937426);  /* Dayton, OH - FUSF Applies */
            bc.AddParticipantNpanxx(617204);  /* Boston, MA - FUSF Applies */
            bc.AddParticipantNpanxx(713210);  /* Houston, TX - NO FUSF */
            bc.AddParticipantNpanxx(800000);  /* Invalid NPANXX - FUSF Applies */

            CalcAndDisplayBridgeConf(bc, "Bridge Conference Interstate");

            /**********************************************/
            /*  Bridge Conference Adjustment or Credit    */
            /**********************************************/
            bc.IsAdjustment = true;
            bc.DiscountType = DiscountType.None;

            CalcAndDisplayBridgeConf(bc, "Bridge Conference Interstate Adjustment");

            Console.WriteLine();
            Console.WriteLine("RunBridgeConferenceExample() complete!");
            Console.WriteLine();

         }
         catch (EZTaxException ex)
         {
            Console.WriteLine("An EZTaxException occurred: {0}", ex.Message);
         }
      }

      /**
      * Shows how to write data to the EZTax log file.
      * Also demonstrates having a different working directory 
      *   - if you pass this sample app a working directory it will not be used here.  
      *     You will get a different log and different status file for this session.
      *
      */
   public void RunWriteToLogExample() {

      Console.WriteLine();
      Console.WriteLine("--- WriteToLog example ------------------------------");
      Console.WriteLine();
      
      EZTaxSession local_session = null;
      FilePaths filePaths = GetWriteToLogFilePaths(workingDirectory);
      ZipAddress address = new ZipAddress("USA", "KS", "Johnson", "Overland Park", "66212", null);
      try {
         // In order to use writeToLog, the session must be initialized with logging enabled.
         local_session = new EZTaxSession(true, filePaths);
         
         Transaction trans = local_session.CreateTransaction();
         FillTransactionData(trans);
         trans.BillToAddress = address;
         
         // Indicate that tax calculations must return the additional log information along with each tax
         local_session.ReturnLogInfo = true;

         // Calculate taxes in order to get some sample data
         // Note: This call will write tax calculation entries into EZTax_DotNet_Sample_WriteToLog.log
         TaxData[] taxes = trans.CalculateTaxes();
         
         // Fill in the information to write to the log file
          
         ArrayList logData = new ArrayList();
         
         foreach (TaxData tax in taxes) 
         {
            TaxLogData log = new TaxLogData();
            
            
            log.PCode            = tax.PCode;
            log.TaxType          = tax.TaxType;
            log.TaxLevel         = tax.TaxLevel;
            log.CalcType         = tax.CalcType;
            log.TaxRate          = tax.Rate;
            log.TaxAmount        = tax.TaxAmount;
            log.SaleAmount       = tax.TaxableMeasure;
            log.ExemptSaleAmount = tax.ExemptSaleAmount;
            log.Billable         = tax.Billable;
            log.Compliance       = tax.Compliance;
            log.Surcharge        = tax.Surcharge;
            
            // The fields listed below are only returned with each tax calculation when the EZTaxSession's
            // returnLogInfo(boolean) method is invoked with a paremeter of true. Otherwise, only the fields 
            // listed above are returned, and the fields listed below will be either null or zero.
            
            log.RefundUncollect     = tax.RefundUncollect;
            // Add 111 to force visible difference in EZTax_DotNet_Sample_WriteToLog.log sample entries.
            log.InvoiceNumber       = tax.InvoiceNumber+111;
            log.ServiceLevelNumber  = tax.ServiceLevelNumber;
            log.Optional            = tax.Optional;
            log.Minutes             = tax.Minutes;
            log.Lines               = tax.Lines;
            log.Locations           = tax.Locations;
            log.CustomerNumber      = tax.CustomerNumber;
            log.CompanyIdentifier   = tax.CompanyIdentifier;
            log.AdjustmentType      = tax.AdjustmentType;
            log.ExemptionType       = tax.ExemptionType;
            log.OptionalAlpha1      = tax.OptionalAlpha1;
            log.Optional4           = tax.Optional4;
            log.Optional5           = tax.Optional5;
            log.Optional6           = tax.Optional6;
            log.Optional7           = tax.Optional7;
            log.Optional8           = tax.Optional8;
            log.Optional9           = tax.Optional9;
            log.Optional10          = tax.Optional10;
            
            logData.Add(log);
         }

         // This call will customized sample tax entries into EZTax_DotNet_Sample_WriteToLog.log
         Console.WriteLine("Writing sample data to the EZTax log file...");
         TaxLogData[] logDataArray = (TaxLogData[])logData.ToArray(typeof(TaxLogData)); //new TaxLogData[logData.L];
         local_session.WriteToLog(logDataArray);
         Console.WriteLine("Write to log successful.");
         Console.WriteLine();
         
         // Calling flushToLog is optional. This method may also be called after performing tax 
         // calculations with a session that has logging enabled to ensure that each transaction
         // processed is logged.
         Console.WriteLine("Calling flushToLog...");
         local_session.FlushToLog();
         Console.WriteLine("flushToLog successful");
         Console.WriteLine();

         // Display the path to the log file
         Console.WriteLine("Displaying name of EZTax log file...");
         Console.WriteLine(local_session.GetLogName());
         Console.WriteLine();
         local_session.Dispose();
      }
      catch (EZTaxException ex) {
         Console.WriteLine("An EZTaxException occurred: " + ex.Message);
         if (local_session != null) local_session.Dispose();
      }
   }

   /**
   * Shows how to write data to the EZTax log file.
   * Also demonstrates having a different working directory 
   *   - if you pass this sample app a working directory it will not be used here.  
   *     You will get a different log and different status file for this session.
   *
   */
   public void RunWriteToLogV914Example()
   {

      Console.WriteLine();
      Console.WriteLine("--- WriteToLogV914 example ------------------------------");
      Console.WriteLine();

      EZTaxSession local_session = null;
      FilePaths filePaths = GetWriteToLogV914FilePaths(workingDirectory);
      ZipAddress address = new ZipAddress("USA", "KS", "Johnson", "Overland Park", "66212", null);
      try
      {
         // In order to use writeToLog, the session must be initialized with logging enabled.
         local_session = new EZTaxSession(true, filePaths);

         Transaction trans = local_session.CreateTransaction();
         FillTransactionData(trans);
         trans.BillToAddress = address;

         // Indicate that tax calculations must return the additional log information along with each tax
         local_session.ReturnLogV914Info = true;

         // Calculate taxes in order to get some sample data
         // Note: This call will write tax calculation entries into EZTax_DotNet_Sample_WriteToLog.log
         TaxData[] taxes = trans.CalculateTaxes();

         // Fill in the information to write to the log file

         ArrayList logData = new ArrayList();

         int log_count = local_session.GetTaxLogV914Count();
         TaxLogDataV914[] logs = local_session.GetTaxLogV914(log_count);
         if (logs == null)
         {
            Console.WriteLine("RunWriteToLogV914Example - no taxes returned");
            if (local_session != null) local_session.Dispose();
            return;
         }

         foreach (TaxLogDataV914 logV914 in logs)
         {
            TaxLogDataV914 log = new TaxLogDataV914();

            log.PCode = logV914.PCode;
            log.TaxType = logV914.TaxType;
            log.TaxLevel = logV914.TaxLevel;
            log.CalcType = logV914.CalcType;
            log.TaxRate = logV914.TaxRate;
            log.TaxAmount = logV914.TaxAmount;
            log.SaleAmount = logV914.SaleAmount;
            log.ExemptSaleAmount = logV914.ExemptSaleAmount;
            log.Billable = logV914.Billable;
            log.Compliance = logV914.Compliance;
            log.Surcharge = logV914.Surcharge;

            // The fields listed below are only returned with each tax calculation when the EZTaxSession's
            // returnLogInfo(boolean) method is invoked with a paremeter of true. Otherwise, only the fields 
            // listed above are returned, and the fields listed below will be either null or zero.

            log.RefundUncollect = logV914.RefundUncollect;
            // Add 111 to force visible difference in EZTax_DotNet_Sample_WriteToLog.log sample entries.
            log.InvoiceNumber = logV914.InvoiceNumber + 111;
            log.ServiceLevelNumber = logV914.ServiceLevelNumber;
            log.Optional = logV914.Optional;
            log.Minutes = logV914.Minutes;
            log.Lines = logV914.Lines;
            log.Locations = logV914.Locations;
            log.CustomerNumber = logV914.CustomerNumber;
            log.CompanyIdentifier = logV914.CompanyIdentifier;
            log.AdjustmentType = logV914.AdjustmentType;
            log.ExemptionType = logV914.ExemptionType;
            log.OptionalAlpha1 = logV914.OptionalAlpha1;
            log.Optional4 = logV914.Optional4;
            log.Optional5 = logV914.Optional5;
            log.Optional6 = logV914.Optional6;
            log.Optional7 = logV914.Optional7;
            log.Optional8 = logV914.Optional8;
            log.Optional9 = logV914.Optional9;
            log.Optional10 = logV914.Optional10;

            // Additional fields added for v914 logging
            log.TransType = logV914.TransType;
            log.SrvType = logV914.SrvType;

            // Extended fields provided for reference but not logged
            log.TransCharge = logV914.TransCharge;
            log.Description = logV914.Description;
            log.CategoryID = logV914.CategoryID;
            log.CategoryDescription = logV914.CategoryDescription;

            logData.Add(log);
         }

         // This call will customized sample tax entries into EZTax_DotNet_Sample_WriteToLog.log
         Console.WriteLine("Writing sample data to the EZTax log file...");
         TaxLogDataV914[] logDataArray = (TaxLogDataV914[])logData.ToArray(typeof(TaxLogDataV914)); //new TaxLogData[logData.L];
         local_session.WriteToLogV914(logDataArray);
         Console.WriteLine("Write to log successful.");
         Console.WriteLine();

         // Calling flushToLog is optional. This method may also be called after performing tax 
         // calculations with a session that has logging enabled to ensure that each transaction
         // processed is logged.
         Console.WriteLine("Calling flushToLog...");
         local_session.FlushToLog();
         Console.WriteLine("flushToLog successful");
         Console.WriteLine();

         // Display the path to the log file
         Console.WriteLine("Displaying name of EZTax log file...");
         Console.WriteLine(local_session.GetLogName());
         Console.WriteLine();
         local_session.Dispose();
      }
      catch (EZTaxException ex)
      {
         Console.WriteLine("An EZTaxException occurred: " + ex.Message);
         if (local_session != null) local_session.Dispose();
      }
   }

   /// <summary>
   /// Shows the basic steps for performing tax calculations with EZTax. 
   /// Uses FilePathsV914 for initialization of session
   /// </summary>
   private void RunTaxCalculationExampleV914()
   {
      Console.WriteLine("--- Tax Calculation example V914 ---");
      Console.WriteLine();

      EZTaxSession v914_session = null;
      FilePathsV914 filePaths = GetV914FilePaths(workingDirectory,
         "EZtaxSample_v914.log", "EZtaxSample_v914.sta", 
         string.Empty, string.Empty, string.Empty, string.Empty);

      try
      {
         // In order to use writeToLog, the session must be initialized with logging enabled.
         v914_session = new EZTaxSession(true, filePaths);

         Console.WriteLine("EZTax session database version: {0}", v914_session.GetDbVersion());

         ZipAddress address1 = new ZipAddress("USA", "KS", "Johnson", "Overland Park", "66212", null);
         ZipAddress address2 = new ZipAddress("USA", "NY", "New York", "New York", "10242", null);
         uint npanxx = 913859;

         uint pcode1 = v914_session.ZipToPCode(address1);
         uint pcode2 = v914_session.ZipToPCode(address2);

         Transaction trans = v914_session.CreateTransaction();
         FillTransactionData(trans);
         TaxData[] taxes;

         // Calculate taxes
         trans.BillToPCode = pcode1;         // Bill-to jurisdiction must always be specified
         taxes = trans.CalculateTaxes();

         if (taxes == null)
         {
            Console.WriteLine("No taxes were returned for this transaction");
            Console.WriteLine();
         }
         else
         {
            Console.WriteLine("Results for tax calculation ({0} taxes)", taxes.Length);
            DisplayTaxes(taxes, 0.0);
         }

         // Calculate taxes using specific exemptions
         trans.BillToPCode = pcode1;

         // Exempt the Local E911 (Wireless) tax.
         uint exemptJCode = v914_session.PCodeToJCode(pcode1);
         trans.Exemptions.Add(new TaxExemption(exemptJCode, TaxLevel.Local, TaxType.E911_TAX_WIRELESS));
         taxes = trans.CalculateTaxes();

         if (taxes == null)
         {
            Console.WriteLine("No taxes were returned for this transaction");
            Console.WriteLine();
         }
         else
         {
            Console.WriteLine("Results for tax calculation with exemptions ({0} taxes)", taxes.Length);
            DisplayTaxes(taxes, 0.0);
         }

         trans.Exemptions.Clear();           // Remove exemptions from transaction.

         // Calculate adjustments
         trans.ClearJurisdictionInfo();      // Should always call this method before calculating
         // taxes for a different jurisdiction. Use Clear()
         // to clear all the transaction data. You may also set
         // the trans.AutoClear property to true to clear all the
         // transaction data after performing a tax calculation.
         trans.BillToPCode = pcode2;
         trans.OriginationNpaNxx = npanxx;
         trans.TerminationAddress = address1;
         taxes = trans.CalculateAdjustments();

         if (taxes == null)
         {
            Console.WriteLine("No adjustments were returned for this transaction");
            Console.WriteLine();
         }
         else
         {
            Console.WriteLine("Results for tax adjustments ({0} taxes)", taxes.Length);
            DisplayTaxes(taxes, 0.0);
         }

         // Calculate taxes for sales transactions
         SalesTransaction salesTrans = new SalesTransaction();
         FillSalesTransaction(salesTrans);

         salesTrans.Session = v914_session;  // When creating a transaction or sales transaction using the
         // new operator, you must specify the EZTaxSession to use for
         // calculating taxes.

         salesTrans.PointOfAcceptance = address2;
         salesTrans.ShipFrom = address1;
         salesTrans.ShipTo = address2;

         taxes = salesTrans.CalculateTaxes();

         if (taxes == null)
         {
            Console.WriteLine("No taxes were returned for this sales transaction");
            Console.WriteLine();
         }
         else
         {
            Console.WriteLine("Tax calculation results for sales transaction ({0} taxes)", taxes.Length);
            DisplayTaxes(taxes, 0.0);
         }

         // Calculate adjustments for sales transactions
         taxes = salesTrans.CalculateAdjustments();

         if (taxes == null)
         {
            Console.WriteLine("No adjustments were returned for this sales transaction");
            Console.WriteLine();
         }
         else
         {
            Console.WriteLine("Tax adjustments results for sales transaction ({0} taxes)", taxes.Length);
            DisplayTaxes(taxes, 0.0);
         }

         // Display the path to the log file
         Console.WriteLine("Displaying name of EZTax log file...");
         Console.WriteLine(v914_session.GetLogName());
         Console.WriteLine();
         v914_session.Dispose();
      }
      catch (EZTaxException ex)
      {
         Console.WriteLine("An EZTaxException occurred: {0}", ex.Message);
      }
   }

   /// <summary>
   /// Shows the basic steps for performing private line tax calculations with AFC. 
   /// Uses FilePathsV914 for initialization of session
   /// </summary>
   public void RunPrivateLineUsingV914Example()
   {

      Console.WriteLine();
      Console.WriteLine("--- PrivateLineUsingV914 example ------------------------------");
      Console.WriteLine();

      EZTaxSession local_session = null;
      FilePaths filePaths = GetWriteToLogV914FilePaths(workingDirectory);
      try
      {
         // In order to use writeToLog, the session must be initialized with logging enabled.
         local_session = new EZTaxSession(true, filePaths);

         Transaction trans = local_session.CreateTransaction();
         FillTransactionData(trans);
         trans.BillToPCode = 0;   //Is not used
         trans.OriginationPCode = 5220006;  // Point A
         trans.TerminationPCode = 2401800;  // Point Z
         trans.TransactionType = (int)TransactionType.INTERSTATE;
         trans.ServiceType = (int)ServiceType.PRIVATE_LINE;
         trans.PrivateLineSplit = 0.5;
         trans.IsPrivateLine = true;
         trans.Lines = 1;

         // Indicate that tax calculations must return the additional log information along with each tax
         local_session.ReturnLogV914Info = true;

         Console.WriteLine("Calculating taxes...");
         TaxData[] taxes = trans.CalculateTaxes();

         DisplayTaxes(taxes, 0.0);
         DisplayV914LogResults(local_session, "PrivateLineUsingV914 - Regular");

         Console.WriteLine("Calculating adjustments...");
         taxes = trans.CalculateAdjustments();

         DisplayTaxes(taxes, 0.0);
         DisplayV914LogResults(local_session, "PrivateLineUsingV914 - Credit");

         Console.WriteLine();
         local_session.Dispose();
      }
      catch (EZTaxException ex)
      {
         Console.WriteLine("An EZTaxException occurred: " + ex.Message);
         if (local_session != null) local_session.Dispose();
      }
   }

      #endregion

      #region Helper Methods

      /// <summary>
      /// Set the transaction data values.
      /// </summary>
      /// <param name="transaction">Transaction object.</param>
      private void FillTransactionData(Transaction transaction)
      {
         transaction.TransactionType = TransactionType.CELLULAR;
         transaction.ServiceType = ServiceType.ACCESS_CHARGE;

         transaction.BusinessClass = BusinessClass.CLEC;
         transaction.Minutes = 45;
         transaction.Charge = 105.50;
         transaction.CompanyIdentifier = "ABCDEFGHIJKLMNOPQRST"; // 20 characters
         transaction.CustomerNumber = "12345678901234567890"; // also 20 characters
         transaction.CustomerType = CustomerType.Residential;
         transaction.Date = new DateTime(2013, 08, 15);
         transaction.DiscountType = DiscountType.AccountLevel;
         transaction.FacilitiesBased = false;
         transaction.Franchise = false;
         transaction.Incorporated = true;
         transaction.InvoiceNumber = 00123;
         transaction.Lifeline = false;
         transaction.Lines = 1;
         transaction.Locations = 1;
         transaction.Optional = 00001;
         transaction.Optional4 = 123;
         transaction.Optional5 = 123;
         transaction.Optional6 = 123;
         transaction.Optional7 = 123;
         transaction.Optional8 = 123;
         transaction.Optional9 = 123;
         transaction.Optional10 = 123;
         transaction.OptionalAlpha1 = "abcdefghijklmnopqrst"; // another 20 characters
         transaction.Regulated = true;
         transaction.Sale = true;
         transaction.ServiceClass = ServiceClass.PrimaryLongDistance;
      }

      /// <summary>
      /// Set the transaction data values.
      /// </summary>
      /// <param name="transaction">Transaction object.</param>
      private void FillTransDataForScopeCatExemp(Transaction transaction)
      {
          transaction.TransactionType = TransactionType.CELLULAR;
          transaction.ServiceType = ServiceType.ACCESS_CHARGE;

          transaction.BusinessClass = BusinessClass.CLEC;
          transaction.Minutes = 0;
          transaction.Charge = 100.00;
          transaction.CompanyIdentifier = "ABCDEFGHIJKLMNOPQRST"; // 20 characters
          transaction.CustomerNumber = "12345678901234567890"; // also 20 characters
          transaction.CustomerType = CustomerType.Business;
          transaction.Date = new DateTime(2018, 01, 15);
          transaction.DiscountType = DiscountType.None;
          transaction.FacilitiesBased = true;
          transaction.Franchise = false;
          transaction.Incorporated = true;
          transaction.InvoiceNumber = 0;
          transaction.Lifeline = false;
          transaction.Lines = 0;
          transaction.Locations = 1;
          transaction.Optional = 00001;
          transaction.Optional4 = 123;
          transaction.Optional5 = 123;
          transaction.Optional6 = 123;
          transaction.Optional7 = 123;
          transaction.Optional8 = 123;
          transaction.Optional9 = 123;
          transaction.Optional10 = 123;
          transaction.OptionalAlpha1 = "NY Exemption"; // another 20 characters
          transaction.Regulated = true;
          transaction.Sale = true;
          transaction.ServiceClass = ServiceClass.PrimaryLocal;
      }

        /// <summary>
        /// Set the transaction data values.
        /// </summary>
        /// <param name="transaction">BridgeConference object.</param>
        private void FillTransactionData(BridgeConference transaction)
      {
         transaction.Clear();

         // Transaction and service type are set during processing of bridge conference
         transaction.TransactionType = TransactionType.NO_TAX;
         transaction.ServiceType = ServiceType.NO_TAX;

         transaction.BusinessClass = BusinessClass.CLEC;
         transaction.Minutes = 45;
         transaction.Charge = 100.00;
         transaction.CompanyIdentifier = "ABCDEFGHIJKLMNOPQRST"; // 20 characters
         transaction.CustomerNumber = "12345678901234567890"; // also 20 characters
         transaction.CustomerType = CustomerType.Residential;
         transaction.Date = new DateTime(2016, 03, 15);
         transaction.DiscountType = DiscountType.AccountLevel;
         transaction.FacilitiesBased = false;
         transaction.Franchise = false;
         transaction.Incorporated = true;
         transaction.InvoiceNumber = 00123;
         transaction.Lifeline = false;
         transaction.Lines = 1;
         transaction.Locations = 1;
         transaction.Optional = 00001;
         transaction.Optional4 = 123;
         transaction.Optional5 = 123;
         transaction.Optional6 = 123;
         transaction.Optional7 = 123;
         transaction.Optional8 = 123;
         transaction.Optional9 = 123;
         transaction.Optional10 = 123;
         transaction.OptionalAlpha1 = "abcdefghijklmnopqrst"; // another 20 characters
         transaction.Regulated = true;
         transaction.Sale = true;
         transaction.ServiceClass = ServiceClass.PrimaryLongDistance;
      }

      /// <summary>
      /// Set the transaction data values.
      /// </summary>
      /// <param name="transaction">Transaction object.</param>
      private void FillVATTransactionData(Transaction transaction)
      {
         transaction.TransactionType = TransactionType.TELEPHONY;  // Telephone/Service (15/7) is for VAT
         transaction.ServiceType = ServiceType.SERVICE;

         transaction.BusinessClass = BusinessClass.CLEC;
         transaction.Minutes = 45;
         transaction.Charge = 1000.00;
         transaction.CompanyIdentifier = "BillSoft";
         transaction.CustomerNumber = "BillSoft Inc.";
         transaction.CustomerType = CustomerType.Residential;
         transaction.Date = new DateTime(2013, 08, 15);
         transaction.DiscountType = DiscountType.AccountLevel;
         transaction.FacilitiesBased = true;
         transaction.Franchise = true;
         transaction.Incorporated = true;
         transaction.InvoiceNumber = 00123;
         transaction.Lifeline = true;
         transaction.Lines = 1;
         transaction.Locations = 1;
         transaction.Optional = 00001;
         transaction.Optional4 = 123;
         transaction.Optional5 = 123;
         transaction.Optional6 = 123;
         transaction.Optional7 = 123;
         transaction.Optional8 = 123;
         transaction.Optional9 = 123;
         transaction.Optional10 = 123;
         transaction.OptionalAlpha1 = "Optional";
         transaction.Regulated = true;
         transaction.Sale = true;
         transaction.ServiceClass = ServiceClass.PrimaryLongDistance;
      }

      /// <summary>
      /// Sets the transaction data values.
      /// </summary>
      /// <param name="transaction">Sales transaction object.</param>
      private void FillSalesTransaction(SalesTransaction transaction)
      {
         transaction.TransactionType = TransactionType.SALES;
         transaction.ServiceType = ServiceType.PRODUCT;

         transaction.Charge = 105.50;
         transaction.CompanyIdentifier = "BillSoft";
         transaction.CustomerNumber = "BillSoft Inc.";
         transaction.CustomerType = CustomerType.Residential;
         transaction.Date = new DateTime(2013, 08, 15);
         transaction.DiscountType = DiscountType.None;
         transaction.ExemptionType = ExemptionType.None;
         transaction.Incorporated = true;
         transaction.InvoiceNumber = 00123;
         transaction.Optional = 00001;
         transaction.Optional4 = 123;
         transaction.Optional5 = 123;
         transaction.Optional6 = 123;
         transaction.Optional7 = 123;
         transaction.Optional8 = 123;
         transaction.Optional9 = 123;
         transaction.Optional10 = 123;
         transaction.OptionalAlpha1 = "Optional";
         transaction.Sale = true;
      }

      /// <summary>
      /// Returns an array of transactions.
      /// </summary>
      /// <returns>Transaction array.</returns>
      public Transaction[] GetTransactions()
      {
         uint pcode = 1248900;
         Transaction[] transactions = new Transaction[3];

         // Transaction 1
         transactions[0] = new Transaction();
         transactions[0].BillToPCode = pcode;
         transactions[0].OriginationPCode = pcode;
         transactions[0].TerminationPCode = pcode;
         transactions[0].TransactionType = TransactionType.CELLULAR;
         transactions[0].ServiceType = ServiceType.ACCESS_CHARGE;

         transactions[0].BusinessClass = BusinessClass.CLEC;
         transactions[0].Minutes = 45;
         transactions[0].Charge = 105.50;
         transactions[0].CompanyIdentifier = "BillSoft";
         transactions[0].CustomerNumber = "BillSoft Inc.";
         transactions[0].CustomerType = CustomerType.Residential;
         transactions[0].Date = new DateTime(2013, 08, 15);
         transactions[0].DiscountType = DiscountType.None;
         transactions[0].ExemptionType = ExemptionType.None;
         transactions[0].FacilitiesBased = true;
         transactions[0].Franchise = true;
         transactions[0].Incorporated = true;
         transactions[0].InvoiceNumber = 00123;
         transactions[0].Lifeline = true;
         transactions[0].Lines = 1;
         transactions[0].Locations = 1;
         transactions[0].Optional = 00001;
         transactions[0].Optional4 = 123;
         transactions[0].Optional5 = 123;
         transactions[0].Optional6 = 123;
         transactions[0].Optional7 = 123;
         transactions[0].Optional8 = 123;
         transactions[0].Optional9 = 123;
         transactions[0].Optional10 = 123;
         transactions[0].OptionalAlpha1 = "Optional";
         transactions[0].Regulated = true;
         transactions[0].Sale = true;
         transactions[0].ServiceClass = ServiceClass.PrimaryLongDistance;

         // Transaction 2
         transactions[1] = new Transaction();
         transactions[1].BillToPCode = pcode;
         transactions[1].OriginationPCode = pcode;
         transactions[1].TerminationPCode = pcode;
         transactions[1].TransactionType = TransactionType.INTERSTATE;
         transactions[1].ServiceType = ServiceType.TOLL;

         transactions[1].BusinessClass = BusinessClass.ILEC;
         transactions[1].Minutes = 45;
         transactions[1].Charge = 105.50;
         transactions[1].CompanyIdentifier = "BillSoft";
         transactions[1].CustomerNumber = "BillSoft Inc.";
         transactions[1].CustomerType = CustomerType.Business;
         transactions[1].Date = new DateTime(2013, 08, 15);
         transactions[1].DiscountType = DiscountType.AccountLevel;
         transactions[1].ExemptionType = ExemptionType.None;
         transactions[1].FacilitiesBased = true;
         transactions[1].Franchise = true;
         transactions[1].Incorporated = true;
         transactions[1].InvoiceNumber = 00124;
         transactions[1].Lifeline = false;
         transactions[1].Lines = 1;
         transactions[1].Locations = 1;
         transactions[1].Optional = 00001;
         transactions[1].Optional4 = 123;
         transactions[1].Optional5 = 123;
         transactions[1].Optional6 = 123;
         transactions[1].Optional7 = 123;
         transactions[1].Optional8 = 123;
         transactions[1].Optional9 = 123;
         transactions[1].Optional10 = 123;
         transactions[1].OptionalAlpha1 = "Optional";
         transactions[1].Regulated = true;
         transactions[1].Sale = true;
         transactions[1].ServiceClass = ServiceClass.PrimaryLocal;

         // Transaction 3
         transactions[2] = new Transaction();
         transactions[2].BillToPCode = pcode;
         transactions[2].OriginationPCode = pcode;
         transactions[2].TerminationPCode = pcode;
         transactions[2].TransactionType = TransactionType.CABLE_TELEVISION;
         transactions[2].ServiceType = ServiceType.ACCESS_CHARGE;

         transactions[2].BusinessClass = BusinessClass.CLEC;
         transactions[2].Minutes = 0;
         transactions[2].Charge = 105.50;
         transactions[2].CompanyIdentifier = "BillSoft";
         transactions[2].CustomerNumber = "BillSoft Inc.";
         transactions[2].CustomerType = CustomerType.Residential;
         transactions[2].Date = new DateTime(2013, 08, 15);
         transactions[2].DiscountType = DiscountType.RetailProduct;
         transactions[2].ExemptionType = ExemptionType.None;
         transactions[2].FacilitiesBased = true;
         transactions[2].Franchise = true;
         transactions[2].Incorporated = true;
         transactions[2].InvoiceNumber = 00125;
         transactions[2].Lifeline = true;
         transactions[2].Lines = 1;
         transactions[2].Locations = 1;
         transactions[2].Optional = 00001;
         transactions[2].Optional4 = 123;
         transactions[2].Optional5 = 123;
         transactions[2].Optional6 = 123;
         transactions[2].Optional7 = 123;
         transactions[2].Optional8 = 123;
         transactions[2].Optional9 = 123;
         transactions[2].Optional10 = 123;
         transactions[2].OptionalAlpha1 = "Optional";
         transactions[2].Regulated = true;
         transactions[2].Sale = true;
         transactions[2].ServiceClass = ServiceClass.PrimaryLongDistance;
         return transactions;
      }

      /// <summary>
      /// Returns a FilePaths object containing the paths to the EZTax database files.
      /// </summary>
      /// <returns>FilePaths object.</returns>
      private FilePaths GetSampleFilePaths(string wrkDir)
      {
         // Create a FilePaths object
         FilePaths paths = new FilePaths();

         paths.Data = Path.Combine(databaseDirectory, "EZTax.dat");
         paths.IDX = Path.Combine(databaseDirectory, "EZTax.idx");
         paths.DLL = Path.Combine(databaseDirectory, "EZTax.dll");
         if ((wrkDir != null) && (wrkDir.Length > 0)) paths.Log = Path.Combine(wrkDir, "EZTax_DotNet_Sample.log");
         else paths.Log = "EZTax_DotNet_Sample.log";
         paths.NpaNxx = Path.Combine(databaseDirectory, "EZTax.npa");
         if ((wrkDir != null) && (wrkDir.Length > 0)) paths.Status = Path.Combine(wrkDir, "EZTax_DotNet_Sample.sta");
         else paths.Status = "EZTax_DotNet_Sample.sta";
         if ((wrkDir != null) && (wrkDir.Length > 0)) paths.Temp = Path.Combine(wrkDir, "EZTax_DotNet_Sample_tmp77777.dat");
         else paths.Temp = "EZTax_DotNet_Sample_tmp77777.dat";
         paths.Location = Path.Combine(databaseDirectory, "EZDesc.dat");
         paths.Zip = Path.Combine(databaseDirectory, "EZZip.dat");
         if ((wrkDir != null) && (wrkDir.Length > 0)) paths.CustomerKey = Path.Combine(wrkDir, "EZTax_DotNet_Sample_cust_key");
         else paths.CustomerKey = "EZTax_DotNet_Sample_cust_key";
         paths.PCode = Path.Combine(databaseDirectory, "EZTax.pcd");
         paths.JCode = Path.Combine(databaseDirectory, "EZTax.jtp");
         paths.Override = "";

         return paths;
      }

      /// <summary>
      /// Returns a FilePathsV914 object containing the paths to the EZTax database files.
      /// </summary>
      /// <returns>FilePathsV914 object.</returns>
      private FilePathsV914 GetV914FilePaths(string wrkDir, string logFile, string staFile,
         string ovrFile, string excFile, string nexFile, string bdlFile)
      {
         // Create a FilePaths object
         FilePathsV914 paths = new FilePathsV914();

         paths.DataDir = databaseDirectory;
         paths.WorkDir = workingDirectory;
         if ((wrkDir != null) && (wrkDir.Length > 0)) paths.Log = Path.Combine(wrkDir, logFile);
         else paths.Log = logFile;
         if ((wrkDir != null) && (wrkDir.Length > 0)) paths.Status = Path.Combine(wrkDir, staFile);
         else paths.Status = staFile;
         paths.Override = ovrFile;
         paths.Exclusion = excFile;
         paths.Nexus = nexFile;
         paths.Bundle = bdlFile;

         return paths;
      }

      /// <summary>
      /// Returns a FilePaths object containing the paths to the EZTax database files.
      /// </summary>
      /// <returns>FilePaths object.</returns>
      private FilePaths GetWriteToLogFilePaths(string wrkDir)
      {
          // Create a FilePaths object
          FilePaths paths = new FilePaths();

          paths.Data = Path.Combine(databaseDirectory, "EZTax.dat");
          paths.IDX = Path.Combine(databaseDirectory, "EZTax.idx");
          paths.DLL = Path.Combine(databaseDirectory, "EZTax.dll");
          if ((wrkDir != null) && (wrkDir.Length > 0)) paths.Log = Path.Combine(wrkDir, "EZTax_DotNet_Sample_WriteToLog.log");
          else paths.Log = "EZTax_DotNet_Sample_WriteToLog.log";
          paths.NpaNxx = Path.Combine(databaseDirectory, "EZTax.npa");
          if ((wrkDir != null) && (wrkDir.Length > 0)) paths.Status = Path.Combine(wrkDir, "EZTax_DotNet_Sample_WriteToLog.sta");
          else paths.Status = "EZTax_DotNet_Sample_WriteToLog.sta";
          if ((wrkDir != null) && (wrkDir.Length > 0)) paths.Temp = Path.Combine(wrkDir, "EZTax_DotNet_Sample_WriteToLog_tmp77777.dat");
          else paths.Temp = "EZTax_DotNet_Sample_WriteToLog_tmp77777.dat";
          paths.Location = Path.Combine(databaseDirectory, "EZDesc.dat");
          paths.Zip = Path.Combine(databaseDirectory, "EZZip.dat");
          if ((wrkDir != null) && (wrkDir.Length > 0)) paths.CustomerKey = Path.Combine(wrkDir, "EZTax_DotNet_Sample_WriteToLog_cust_key");
          else paths.CustomerKey = "EZTax_DotNet_Sample_WriteToLog_cust_key";
          paths.PCode = Path.Combine(databaseDirectory, "EZTax.pcd");
          paths.JCode = Path.Combine(databaseDirectory, "EZTax.jtp");
          paths.Override = "";

          return paths;
      }

      /// <summary>
      /// Returns a FilePaths object containing the paths to the EZTax database files.
      /// </summary>
      /// <returns>FilePaths object.</returns>
      private FilePaths GetWriteToLogV914FilePaths(string wrkDir)
      {
         // Create a FilePaths object
         FilePaths paths = new FilePaths();

         paths.Data = Path.Combine(databaseDirectory, "EZTax.dat");
         paths.IDX = Path.Combine(databaseDirectory, "EZTax.idx");
         paths.DLL = Path.Combine(databaseDirectory, "EZTax.dll");
         if ((wrkDir != null) && (wrkDir.Length > 0)) paths.Log = Path.Combine(wrkDir, "EZTax_DotNet_Sample_WriteToLogV914.log");
         else paths.Log = "EZTax_DotNet_Sample_WriteToLogV914.log";
         paths.NpaNxx = Path.Combine(databaseDirectory, "EZTax.npa");
         if ((wrkDir != null) && (wrkDir.Length > 0)) paths.Status = Path.Combine(wrkDir, "EZTax_DotNet_Sample_WriteToLogV914.sta");
         else paths.Status = "EZTax_DotNet_Sample_WriteToLogV914.sta";
         if ((wrkDir != null) && (wrkDir.Length > 0)) paths.Temp = Path.Combine(wrkDir, "EZTax_DotNet_Sample_WriteToLogV914_tmp77777.dat");
         else paths.Temp = "EZTax_DotNet_Sample_WriteToLogV914_tmp77777.dat";
         paths.Location = Path.Combine(databaseDirectory, "EZDesc.dat");
         paths.Zip = Path.Combine(databaseDirectory, "EZZip.dat");
         if ((wrkDir != null) && (wrkDir.Length > 0)) paths.CustomerKey = Path.Combine(wrkDir, "EZTax_DotNet_Sample_WriteToLogV914_cust_key");
         else paths.CustomerKey = "EZTax_DotNet_Sample_WriteToLogV914_cust_key";
         paths.PCode = Path.Combine(databaseDirectory, "EZTax.pcd");
         paths.JCode = Path.Combine(databaseDirectory, "EZTax.jtp");
         paths.Override = "";

         return paths;
      }

      /// <summary>
      /// Displays the taxes generated on the console screen.
      /// </summary>
      /// <param name="taxes">Array containing tax information to display.</param>
      private void DisplayTaxes(TaxData[] taxes, double desiredTotal)
      {
         if (taxes == null)
         {
            Console.WriteLine("No taxes were returned for this transaction");
            Console.WriteLine();
            return;
         }

         if (desiredTotal > 0.0)
         {
            Console.WriteLine("Results for tax inclusive (reverse) calculation (" + taxes.Length + " taxes)");
            Console.WriteLine("    Desired Total:      {0:0.####}", desiredTotal);
         }
         else
         {
            Console.WriteLine("Results for tax calculation (" + taxes.Length + " taxes)");
         }

         foreach (TaxData tax in taxes)
         {
            Console.WriteLine("    Tax Description:    {0}", tax.Description);
            Console.WriteLine("    Jurisdiction PCode: {0}", tax.PCode);
            Console.WriteLine("    Tax Level:          {0}", tax.TaxLevel);
            Console.WriteLine("    Tax Type:           {0}", tax.TaxType);
            Console.WriteLine("    Tax Rate:           {0:0.####}", tax.Rate);
            Console.WriteLine("    Tax Amount:         {0:0.####}", tax.TaxAmount);
            Console.WriteLine("    Calc Type:          {0}", tax.CalcType);
            Console.WriteLine("    Taxable Measure:    {0:0.####}", tax.TaxableMeasure);
            Console.WriteLine("    Exempt Sale Amount: {0:0.####}", tax.ExemptSaleAmount);
            Console.WriteLine("    Billable:           {0}", tax.Billable ? "Yes" : "No");
            Console.WriteLine("    Compliance:         {0}", tax.Compliance ? "Yes" : "No");
            Console.WriteLine("    Surcharge:          {0}", tax.Surcharge ? "Yes" : "No");
            Console.WriteLine();
         }
      }

      /// <summary>
      /// Displays the taxes generated on the console screen.
      /// </summary>
      /// <param name="taxes">Array containing tax information to display.</param>
      private void DisplayInvoicedTaxes(InvoiceTaxData[] taxes)
      {
         foreach (InvoiceTaxData tax in taxes)
         {
            Console.WriteLine("    Tax Description:    {0}", tax.Description);
            Console.WriteLine("    Jurisdiction PCode: {0}", tax.PCode);
            Console.WriteLine("    Tax Level:          {0}", tax.TaxLevel);
            Console.WriteLine("    Tax Type:           {0}", tax.TaxType);
            Console.WriteLine("    Tax Rate:           {0:0.####}", tax.Rate);
            Console.WriteLine("    Tax Amount:         {0:0.####}", tax.TaxAmount);
            Console.WriteLine("    Calc Type:          {0}", tax.CalcType);
            Console.WriteLine("    Exempt Sale Amount: {0:0.####}", tax.ExemptSaleAmount);
            Console.WriteLine("    Lines:              {0}", tax.Lines);
            Console.WriteLine("    Locations:          {0}", tax.Locations);
            Console.WriteLine("    Minutes:            {0}", tax.Minutes);
            Console.WriteLine("    Minimum Base:       {0:0.####}", tax.MinBase);
            Console.WriteLine("    Maximum Base:       {0:0.####}", tax.MaxBase);
            Console.WriteLine("    Excess Tax:         {0:0.####}", tax.ExcessTax);
            Console.WriteLine("    Total Charge:       {0:0.####}", tax.TotalCharge);
            Console.WriteLine();
         }
      }

      //************************************************************************
      // CalcAndDisplayBridgeConf demonstrates the following:
      //  - Calculating bridge conferencing taxes and displaying the results
      //************************************************************************
      private void DisplayV914LogResults(EZTaxSession session, string desc)
      {
         int log_count = session.GetTaxLogV914Count();
         TaxLogDataV914[] logs = session.GetTaxLogV914(log_count);
         if (logs == null)
         {
            Console.WriteLine("DisplayV914LogResults - no taxes returned");
            return;
         }

         Console.WriteLine(desc + " - V914 Log Results");

         foreach (TaxLogDataV914 logV914 in logs)
         {
            Console.WriteLine("    Tax Description:    {0}", logV914.Description);
            Console.WriteLine("    Jurisdiction PCode: {0}", logV914.PCode);
            Console.WriteLine("    Tax Level:          {0}", logV914.TaxLevel);
            Console.WriteLine("    Tax Type:           {0}", logV914.TaxType);
            Console.WriteLine("    Tax Rate:           {0:0.####}", logV914.TaxRate);
            Console.WriteLine("    Tax Amount:         {0:0.####}", logV914.TaxAmount);
            Console.WriteLine("    Lines:              {0}", logV914.Lines);
            Console.WriteLine("    Billable:           {0}", logV914.Billable ? "Yes" : "No");
            Console.WriteLine("");
         }
      }

      /// <summary>
      /// Displays the transaction on the console screen.
      /// </summary>
      /// <param name="Transaction">Transaction information to display.</param>
      private void DisplayTransaction(Transaction trans, String desc, double desiredTotal)
      {

         Console.WriteLine("Transaction data for " + desc);
         if (trans.BillToPCode != 0) Console.WriteLine("    BillTo PCode:        " + trans.BillToPCode);
         if (trans.BillToNpaNxx != 0) Console.WriteLine("    BillTo NpaNxx:       " + trans.BillToNpaNxx);
         if (trans.BillToFips != null) Console.WriteLine("    BillTo Fips:         " + trans.BillToFips);
         if (trans.BillToAddress != null)
         {
            ZipAddress adr = trans.BillToAddress;
            if (adr.ZipP4 != null)
               Console.WriteLine("    BillTo Address:      " + adr.ZipCode + "-" + adr.ZipP4 + ", " +
                    adr.CountryISO + ", " + adr.State + ", " + adr.County + ", " + adr.Locality);
            else
               Console.WriteLine("    BillTo Address:       " + adr.ZipCode + ", " +
                    adr.CountryISO + ", " + adr.State + ", " + adr.County + ", " + adr.Locality);
         }

         if (trans.OriginationPCode != 0) Console.WriteLine("    Origination PCode:   " + trans.OriginationPCode);
         if (trans.OriginationNpaNxx != 0) Console.WriteLine("    Origination NpaNxx:  " + trans.OriginationNpaNxx);
         if (trans.OriginationFips != null) Console.WriteLine("    Origination Fips:    " + trans.OriginationFips);
         if (trans.OriginationAddress != null)
         {
            ZipAddress adr = trans.OriginationAddress;
            if (adr.ZipP4 != null)
               Console.WriteLine("    Origination Address: " + adr.ZipCode + "-" + adr.ZipP4 + ", " +
                    adr.CountryISO + ", " + adr.State + ", " + adr.County + ", " + adr.Locality);
            else
               Console.WriteLine("    Origination Address: " + adr.ZipCode + ", " +
                    adr.CountryISO + ", " + adr.State + ", " + adr.County + ", " + adr.Locality);
         }

         if (trans.TerminationPCode != 0) Console.WriteLine("    Termination PCode:   " + trans.TerminationPCode);
         if (trans.TerminationNpaNxx != 0) Console.WriteLine("    Termination NpaNxx:  " + trans.TerminationNpaNxx);
         if (trans.TerminationFips != null) Console.WriteLine("    Termination Fips:    " + trans.TerminationFips);
         if (trans.TerminationAddress != null)
         {
            ZipAddress adr = trans.TerminationAddress;
            if (adr.ZipP4 != null)
               Console.WriteLine("    Termination Address: " + adr.ZipCode + "-" + adr.ZipP4 + ", " +
                    adr.CountryISO + ", " + adr.State + ", " + adr.County + ", " + adr.Locality);
            else
               Console.WriteLine("    Termination Address: " + adr.ZipCode + ", " +
                    adr.CountryISO + ", " + adr.State + ", " + adr.County + ", " + adr.Locality);
         }

         if (desiredTotal > 0.0)
         {
            Console.WriteLine("    Desired Total:       " + desiredTotal.ToString("0.00###"));
         }
         else
         {
            Console.WriteLine("    Charge:              " + trans.Charge.ToString("0.00###"));
         }
         Console.WriteLine("    Lines:               " + trans.Lines);
         Console.WriteLine("    Minutes:             " + trans.Minutes.ToString("0.00###"));
         Console.WriteLine("    Debit:               " + trans.Debit);
         Console.WriteLine("    Discount Type:       " + trans.DiscountType);
         Console.WriteLine("    Adjustment Method:   " + trans.AdjustmentMethod);
         Console.WriteLine();
      }
      #endregion
   }
}

Documentation

The AFC .NET Interface includes API documentation for the .NET classes in the form of HTML page. This documentation can be found in the AFC.NET Interface directory. More information on AFC can be found in TM_00101_AFC User Manual_Telecom or TM_00102_AFC User Manual_SAU, which is provided with the standard AFC system.

  • Was this article helpful?