function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tejateja 

Need help for tax estimator

Hi All,

 

I am relatively new to visual force development. Can someone help me with the tax estimator i am trying to develop. Thank you in advance.

 

Controller:
--------------
public class QuickTaxEstimateController {
public string pingResult { get; set; }
public string pingMessages { get; set; }
public string validateResult { get; set; }
public string validateMessages { get; set; }
public string item1TaxCode { get; set; }
public string taxResult { get; set; }
public string taxMessages { get; set; }
public string totalTax { get; set; }
public string totalAmount { get; set; }
public string taxResultText { get; set; }

public EO_TNQT.AddressSvc.AddressSvcSoap getAddressService() {
// EO_TNQT.AddressSvc.AddressSvcSoap addressService = new EO_TNQT.AddressSvc.AddressSvcSoap( 'https://development.avalara.net' );
EO_TNQT.AddressSvc.AddressSvcSoap addressService = new EO_TNQT.AddressSvc.AddressSvcSoap( 'https://rest.avalara.net' );
EO_TNQT.AddressSvc.Security security = new EO_TNQT.AddressSvc.Security();
EO_TNQT.AddressSvc.UsernameToken_element token = new EO_TNQT.AddressSvc.UsernameToken_element();

token.username = 'abc@example.com';
token.password = 'xyz123';
security.UsernameToken = token;
addressService.Security = security;
EO_TNQT.AddressSvc.Profile profile = new EO_TNQT.AddressSvc.Profile();
profile.Client = 'TaxSvcTest,4.0.0.0';
addressService.Profile = profile;
return addressService;
}

public void pingServer() {
EO_TNQT.AddressSvc.AddressSvcSoap addressService = getAddressService();
EO_TNQT.AddressSvc.PingResult result;
result = addressService.Ping( 'Test' );
pingResult = result.ResultCode;
pingMessages = '' + result.Messages;
integer i = 1;
System.debug( 'PING:' + result.Messages );
// for( EO_TNQT.AddressSvc.Message message : result.Messages.Message ) {
// pingMessages = ' ' + i + '-' + message.summary + ':' + message.details;
// }

}

public void validateAddress() {
EO_TNQT.AddressSvc.AddressSvcSoap addressService = getAddressService();
EO_TNQT.AddressSvc.ValidateRequest validateRequest = new EO_TNQT.AddressSvc.ValidateRequest();
EO_TNQT.AddressSvc.BaseAddress address = new EO_TNQT.AddressSvc.BaseAddress();
address.City = 'City';
address.Country = 'USA';
address.Line1 = '123, universal Address';
address.Region = 'Region';
address.PostalCode = '12345';
validateRequest.Address = address;
EO_TNQT.AddressSvc.ValidateResult result = addressService.Validate( validateRequest );
validateResult = result.ResultCode;
validateMessages = '' + result.Messages;
System.debug( 'Validate Result:' + result.ResultCode );
System.debug( 'Validate Result Messages:' + result.Messages );
}

public EO_TNQT.TaxSvc.TaxSvcSoap getTaxService() {
// EO_TNQT.TaxSvc.TaxSvcSoap taxService = new EO_TNQT.TaxSvc.TaxSvcSoap( 'https://development.avalara.net' ); // Dev
EO_TNQT.TaxSvc.TaxSvcSoap taxService = new EO_TNQT.TaxSvc.TaxSvcSoap( 'https://avatax.avalara.net' ); // Production
EO_TNQT.TaxSvc.Security security = new EO_TNQT.TaxSvc.Security();
EO_TNQT.AddressSvc.UsernameToken_element token = new EO_TNQT.AddressSvc.UsernameToken_element();

token.username = 'abc@example.com'; // Production
token.password = 'xyz123';
security.UsernameToken = token;
taxService.Security = security;
EO_TNQT.TaxSvc.Profile profile = new EO_TNQT.TaxSvc.Profile();
profile.Client = 'TaxSvcTest,4.0.0.0';
taxService.Profile = profile;
return taxService;
}

public void getTax() {
EO_TNQT.TaxSvc.GetTaxRequest request = new EO_TNQT.TaxSvc.GetTaxRequest();
Date taxDate = Date.today();
request.DocCode = 'SfQuickTaxTest-' + taxDate;
request.DocType = 'SalesInvoice';
request.DocDate = taxDate;
request.CompanyCode = 'xyz';
request.CustomerCode = 'TaxSvcTest';
request.SalesPersonCode = 'abc';
request.OriginCode = 'Origin';
request.DestinationCode = 'Destination';
request.DetailLevel = 'Line';

// Add the origin and destination addresses referred to by the
// setOriginCode and setDestinationCode properties above.
EO_TNQT.TaxSvc.ArrayOfBaseAddress addresses = new EO_TNQT.TaxSvc.ArrayOfBaseAddress();
EO_TNQT.TaxSvc.BaseAddress origin = new EO_TNQT.TaxSvc.BaseAddress();
origin.AddressCode = 'Origin';
/* origin.Line1 = 'xyz';
origin.Line2 = '321 shgqsl';
origin.Line3 = 'Suite 111';
origin.City = 'City';
origin.Region = 'Region';
origin.PostalCode = '11223';
origin.Country = 'USA'; /**/

addresses.BaseAddress = new List<EO_TNQT.TaxSvc.BaseAddress>();
addresses.BaseAddress.add( origin );

EO_TNQT.TaxSvc.BaseAddress destination = new EO_TNQT.TaxSvc.BaseAddress();
destination.AddressCode = 'Destination';

/* destination.Line1 = '123 galaxy';
destination.City = 'City';
destination.Region = 'Region';
destination.PostalCode = '54321';
destination.Country = 'USA'; /**/

addresses.BaseAddress.add( destination );

request.Addresses = addresses;

EO_TNQT.TaxSvc.ArrayOfLine lines = new EO_TNQT.TaxSvc.ArrayOfLine();
EO_TNQT.TaxSvc.Line line;

/* line = new EO_TNQT.TaxSvc.Line();
line.No = '101';
// line.ItemCode = 'Item001';
line.TaxCode = item1TaxCode;
line.Qty = 1;
// line.Amount = 1000.00;
line.Amount = 890.00;
//added in 4.12 release
// line.CustomerUsageType = 'G'; // I think the usage type is to denote tax exempt status per Anya
// line.CustomerUsageType = 'ST080120';
line.Description = 'Sample Description';
lines.Line = new List<EO_TNQT.TaxSvc.Line>();
lines.Line.add( line );

// line = new EO_TNQT.TaxSvc.Line();
// line.No = '102';
//// line.ItemCode = 'FR'; // Anya also recommended sending freight over with FR as the tax code not the item code
//// line.TaxCode = 'FR';
// line.Qty = 1;
// line.Amount = 10.00;
// lines.Line.add( line );
/**/
lines.Line = new List<EO_TNQT.TaxSvc.Line>();

line = new EO_TNQT.TaxSvc.Line();
line.No = '101';
line.ItemCode = 'IHOME';
line.TaxCode = 'P0000000';
line.Qty = 1;
line.Amount = 595.00;
line.Description = 'IHOME';
lines.Line.add( line );

line = new EO_TNQT.TaxSvc.Line();
line.No = '102';
line.ItemCode = 'OPP';
line.TaxCode = 'P0000000';
line.Qty = 1;
line.Amount = 295.00;
line.Description = 'OPP';
lines.Line.add( line );

request.Lines = lines;

EO_TNQT.TaxSvc.TaxSvcSoap taxService = getTaxService();
EO_TNQT.TaxSvc.GetTaxResult result = taxService.GetTax( request );

EO_TNQT.TaxSvc.ArrayOfTaxLine taxLineArray = result.TaxLines;
taxResultText = '';
taxResult = result.ResultCode;
taxMessages = '' + result.Messages;
if( result.ResultCode.equals( 'Success' ) ) {
for( EO_TNQT.TaxSvc.TaxLine taxLine : taxLineArray.TaxLine ) {
taxResultText = taxResultText + taxLine + '\n\n';
}
System.debug( 'GET TAX Doc Code: ' + result.DocCode );
totalTax = '' + result.TotalTax;
System.debug( 'GET TAX Total Tax: ' + result.TotalTax );
totalAmount = '' + result.TotalAmount;
System.debug( 'GET TAX Total Amount: ' + result.TotalAmount );
} else {
System.debug( 'GET TAX MESSAGES: ' + result.Messages );
}
}
}


VF Page:
--------

<apex:page controller="QuickTaxEstimateController">
<apex:pageBlock >
<apex:form >
<apex:outputText value="Ping Result: {!pingResult}" />
<br />
<apex:outputText value="Ping Messages: {!pingMessages}" />
<br />
<apex:commandButton action="{!pingServer}" value="Ping Server" />
<br />
<apex:outputText value="Validate Result: {!validateResult}" />
<br />
<apex:outputText value="Validate Messages: {!validateMessages}" />
<br />
<apex:commandButton action="{!validateAddress}" value="Validate Address" />
<br />
<apex:inputText label="Item 1 Tax Code" value="{!item1TaxCode}"/>
<br />
<apex:outputText value="Get Tax Result: {!taxResult}" />
<br />
<apex:outputText value="Get Tax Messages: {!taxMessages}" />
<br />
<apex:outputText value="Get Total Tax: {!totalTax}" />
<br />
<apex:outputText value="Get Total Amount: {!totalAmount}" />
<br />
<apex:commandButton action="{!getTax}" value="Get Tax" />
<br />
<apex:inputTextArea label="Result" value="{!taxResultText}" rows="20"/>
</apex:form>
</apex:pageBlock>
</apex:page>

 

Expecting Result :
-------------------------

Taxable Amount : --------------
Non taxable Amount : -------------
Sub : -----------------(sum(Taxable and Non taxable amounts))
Tax :---------------(shld be automatically generated)
Total : -------------(sum of (sub + tax))