taxengine:integration:code_samples:c_concise_sample
C# concise sample using TBIC
Please see Getting Started for help with using the KampData TaxEngine.
using System;
using System.Runtime.InteropServices;
using System.Collections;
//Add the KDTaxEngine.dll as a reference.
using KampData.TaxEngine.API;
using KampData.TaxEngine.API.Enums;
namespace TaxEngineConsoleApp
{
/// <summary>
/// This sample uses hardcoded values to illustrate what is required
/// to retrieve the tax schedule and tax option for a line item
/// using the DynamicZip Tax by Item Category settings.
/// </summary>
/// <remarks>To use the KampData TaxEngine in this sample, or in any other
/// project, you must first setup the SOP module from the KDControlCenter.exe's
/// Transaction Source Module Setup window. Please see "Getting Started"in the
/// KDTaxEngine.chm help file for more information.</remarks>
class CSharpClient
{
[STAThread]
static void Main(string[] args)
{
bool abort = false;
ArrayList cities = new ArrayList();
ArrayList counties = new ArrayList();
ArrayList states = new ArrayList();
string server = @"Microsoft SQL Server";
string userId = "User";
string password = "p@ssw0rd";
string companyDatabase = "TWO";
string systemDatabase = "DYNAMICS";
Int16 timeOutSeconds = 60;
bool displayProgessBar = true;
string loginMessage = "";
string message = "";
/// KampData.Portal object must be instantiated.
Portal txEngn = new Portal();
try
{
try
{
/// The Portal.Login method makes the connection to SQL Server and
/// prepares the TaxEngine for use.
loginMessage = txEngn.Login(server, userId, password, systemDatabase, companyDatabase, timeOutSeconds, displayProgessBar);
}
catch (Exception e)
{
loginMessage = e.Message;
}
if (loginMessage != "")
{
abort = true;
Console.WriteLine(loginMessage);
Console.WriteLine("Press enter to continue");
Console.ReadLine(); // to hold window open displaying error message
}
if (!abort)
{
/// Set the docType and module using the values you have setup
/// in the KDWindowClient.exe's Transaction Source Module Setup
/// and Document Type Setup windows. In the SOP module, invoices are
/// docType 3.
/// (The SOP module can be setup automatically using
/// File > Create SOP in the TE Transaction Source Modules window.)
Int16 docType = 3;
string module = "SOP";
/// You must assign a document number at this point. You can use a
/// document number generated by your order entry software
/// that will call the TaxEngine, or you can use the following code
/// to generate a document number.
string docNumber = txEngn.NextDocumentNumber(module);
/// Initialize the document.
txEngn.Document(docNumber, docType, module);
/// DocSaleOrPurchase defaults to Sales, so the following line
/// is unnecessary. However, you can set it to Purchases if desired.
txEngn.DocSaleOrPurchase = SalesOrPurchases.Sales;
/// A customer ID is required to check customer taxable status
/// to see if the customer is taxable or exempt. If no
/// customer ID is provided, the customer is assumed taxable.
txEngn.DocCustomerID = "ADAMPARK0001";
/// We now add a line to the order. The addressing and taxation
/// features occur on the line level. This step is required to
/// instantiate a line object to work with.
int lineNumber = 1;
txEngn.LineAdd(lineNumber);
// Set the values necessary to retrieve the item category taxability.
string itemCategory = "FREIGHT";
txEngn.LineItemCategory = itemCategory;
string zip = "84101";
txEngn.LineZip = zip;
string state = "UT";
txEngn.LineState = state;
string city = "Salt Lake City";
txEngn.LineCity = city;
string county = "Salt Lake"; // leave blank if unknown.
if (county != "")
txEngn.LineCounty = county;
txEngn.LineTaxScheduleSelect();
// The item tax schedule and item tax option should now be available.
Console.WriteLine("Line-item or document tax schedule [{0}] {1}",
txEngn.LineTaxScheduleID, txEngn.LineTaxScheduleDescription);
Console.WriteLine("Tax Option: {0}", txEngn.LineItemTaxOption);
if (txEngn.LineItemTaxScheduleID != "")
Console.WriteLine("Item tax schedule [{0}]",
txEngn.LineItemTaxScheduleID);
// The following is informational only - to show more results.
txEngn.LineItemUnitPrice = 100;
txEngn.LineItemQuantity = 1;
txEngn.DocCalculateTax();
Console.WriteLine();
message = "ID";
message = message.PadRight(80);
message = message.Insert(17, "Description");
message = message.Insert(48, "Total");
message = message.Insert(58, "Taxable");
message = message.Insert(68, "Tax");
message = message.Trim();
Console.WriteLine(message);
// This code displays the Microsoft Dynamics GP tax details
// that were used.
foreach (TrxTaxDetail trxDtl in txEngn.DocTaxDetails(TaxDetails.Transaction))
{
message = trxDtl.ID;
message = message.PadRight(80);
message = message.Insert(17, trxDtl.Description);
message = message.Insert(48, trxDtl.TotalAmount.ToString());
message = message.Insert(58, trxDtl.TaxedAmount.ToString());
message = message.Insert(68, trxDtl.TaxAmount.ToString());
message = message.Trim();
Console.WriteLine(message);
}
Console.WriteLine();
}
}
catch (Exception exc)
{
Console.WriteLine(exc.Message);
Console.WriteLine("Press enter to continue");
Console.ReadLine(); // to hold window open displaying error message
}
}
}
}
taxengine/integration/code_samples/c_concise_sample.txt · Last modified: 2015/08/06 20:53 by chuck