Skip to main content
Avalara Help Center

Microsoft Dynamics NAV - Avalara AvaTax extended codeunits to help Third-party integrations

Overview

As part of this release, Avalara has exposed new codeunits to help Third-party integration.

Environment

Microsoft Dynamics 2009 R2 / NAV 2013RTM / 2013R2 / 2015RTM / 2016RTM

Resolution

  • [type here]

Release Avalara AvaTax NAV (Details)

As part of this release, Avalara has exposed new codeunits to help Third-party integrations

  • Third-party integration can call codeunit 14073350 to update Tax which is calculated by Avalara Tax

service with single parameter based call for Specific Sales Header

  •  Third-party integration can call codeunit 14073351 to get value of “Amount Incl. VAT” which is calculated

by Avalara Tax service with single parameter based call for Specific Sales line

  •  Code to avoid multiple GetTax call on already uncommitted document for Tax calculation operation

 

Steps to Implement Avalara AvaTax generic hook    

  •     Step 1: Import below objects from Development environment from File                    

File Name: AvalaraForThirdPartyIntegration.txt

  •  Step 2: Compile above object (if error see page 4)
  •  Step 3: use new codeunits and respective functions in your integration as per below mentioned
    details

New codeunit introduced by Avalara

Codeunit 14073349 Avalara Integration Check

  •  Third-party integration can check whether AvaTax is installed / configured for company with global

function added in this codeunit.

  •  You can directly import this codeunit into your database.

Codeunit 14073350 AVA Sales Integration

  •  Third-party integration can call this codeunit to update Tax which is calculated by Avalara Tax service

with single parameter based call for Specific Sales Header

                 e.g. CODEUNIT.RUN(14073350,SalesHeader);

  •  As objects are generic for all Avalara NAV version, you can use below steps to avoid compilation error
Based on NAV version developer needs to comment / un-comment code line

e.g. for 2009 R2
        AVAValidateCall.AvaStatisticsActionSales(Rec,FALSE);

e.g. for 2013RTM / 2013R2 / 2015RTM / 2016RTM
        AVAValidateCall.AvaStatisticsActionSales(Rec,FALSE,FALSE,FORMAT(Rec."Document Type"));

Codeunit 14073351 AVA Sales Order Quantity

  •  Third-party integration can call this codeunit to get value of “Amount Incl. VAT” which is calculated by

Avalara Tax service with single parameter based call for Specific Sales line
             e.g. CODEUNIT.RUN(14073351,SalesLine);

  •  You can directly import this codeunit into your database

Codeunit 14073301 AVA Tax Engine

  •  To avoid multiple GetTax call on already uncommitted document (optional)

Steps 1 : go to function  fnCalcTax

Search for below line and replace marked code with old code lines fnCalcTax

Search for below line and replace marked code with old code lines
AvaDocumentNo := SalesHead."No.";

AVAAddrLatLongFlag:=FALSE;


AvaCallGetTax := FALSE;
IF DocTypeSetToInv THEN AvaCallGetTax := TRUE;
IF (AvaCallGetTax = FALSE) THEN BEGIN
    AvaHead.RESET;
    AvaHead.SETRANGE(Module,AvaHead.Module::Sales);
    AvaHead.SETFILTER("Document No.",'%1','*'+SalesHead."No."+'*');
    AvaHead.SETRANGE("Document Type",SalesHead."Document Type");
    AvaHead.SETFILTER("Status Code",'<>OK');
    IF AvaHead.FINDFIRST AND (AvaHead."Company ID" <> '') THEN BEGIN
        IF (AvaCallGetTax = FALSE) AND (AvaHead."Customer No." <> SalesHead."Sell-to Customer No.") THEN AvaCallGetTax := TRUE;
        IF (AvaCallGetTax = FALSE) AND (AvaHead."Document Date" <>SalesHead."Document Date") THEN AvaCallGetTax := TRUE;
        IF (AvaCallGetTax = FALSE) AND (AvaHead."Exemption No." <> ExemptionNo) THEN AvaCallGetTax := TRUE;
        IF (AvaCallGetTax = FALSE) AND (AvaHead."Original Address" <> FromAddress) THEN AvaCallGetTax := TRUE;
        IF (AvaCallGetTax = FALSE) AND (AvaHead."Destination Address" <> ToAddress) THEN AvaCallGetTax := TRUE;
        IF (AvaCallGetTax = FALSE) AND (iDocType = 1) AND (AvaHead."Document Status" = 0) THEN AvaCallGetTax := TRUE;
        IF (AvaCallGetTax = FALSE) THEN BEGIN
            SalesLine.SETRANGE("Document Type",SalesHead."Document Type") ;
            SalesLine.SETRANGE("Document No.",SalesHead."No.");
            SalesLine.SETFILTER(Type,'<>%1',SalesLine.Type::" ");
            IF SalesLine.FINDFIRST THEN BEGIN
                REPEAT
                    AvaLine.RESET;
                    AvaLine.SETRANGE(Module,AvaHead.Module);
                    AvaLine.SETRANGE("Document Type",AvaHead."Document Type");
                    AvaLine.SETRANGE("Document No.",AvaHead."Document No.");
                    AvaLine.SETRANGE("Document Line No.",FORMAT(SalesLine."Line No."));
                    AvaLine.SETRANGE("Item No.",FORMAT(SalesLine."No."));
                    IF AvaLine.FINDFIRST THEN BEGIN
                        IF (AvaCallGetTax = FALSE) AND (AvaLine."Entity No." <> EntityUseCode) THEN AvaCallGetTax:= TRUE;
                        IF (AvaCallGetTax = FALSE) AND (AvaLine."Tax Area" <> SalesLine."Tax Area Code") THEN AvaCallGetTax := TRUE;
                        IF (AvaCallGetTax = FALSE) AND (SalesLine.Quantity <> AvaLine.Quantity) THEN AvaCallGetTax := TRUE;
                        IF (AvaCallGetTax = FALSE) AND (SalesLine."Quantity (Base)" <> AvaLine."Quantity (Base)") THEN AvaCallGetTax := TRUE;
                        IF (AvaCallGetTax = FALSE) AND (SalesLine."Unit of Measure Code" <> AvaLine."Unit of Measure Code") THEN AvaCallGetTax := TRUE;
                        IF (AvaCallGetTax = FALSE) AND (SalesLine."Unit Price" <> AvaLine."Unit Price") THEN AvaCallGetTax := TRUE;
fnGetItemDetails(SalesLine.Type,SalesLine."No.",SalesLine."Tax Group Code",Ref1,Ref2,"G\LAccNo.",TaxibilityCode,UnitPrice);
                            IF (AvaCallGetTax = FALSE) AND (AvaLine."Tax Code" <> TaxibilityCode) THEN AvaCallGetTax := TRUE;
//SalesLine.CALCSUMS("Inv. Discount Amount");
//IF (AvaCallGetTax = FALSE) THEN
// IF ((SalesLine."Inv. Discount Amount"*SalesLine."Qty. to Invoice")/SalesLine.Quantity) <> AvaLine."Tax Discount Amount" THEN
// AvaCallGetTax := TRUE;
                            IF (AvaCallGetTax = FALSE) THEN BEGIN
                                RecCurrency.InitRoundingPrecision;
                                IF ((AvaLine."Tax Tax Amount" + AvaLine."Total Taxable Amount" + AvaLine."Tax Exempt Amount") <> 0) THEN BEGIN

    SalesLine."Amount Including VAT" := ROUND(AvaLine."Tax Tax Amount" + AvaLine."Total Taxable Amount" + AvaLine."Tax Exempt Amount",RecCurrency."Amount Rounding Precision");

    SalesLine."Outstanding Amount" := ROUND(AvaLine."Tax Tax Amount" + AvaLine."Total Taxable Amount" + AvaLine."Tax Exempt Amount",RecCurrency."Amount Rounding Precision");

END;

IF AvaLine."Tax Tax Amount" <> 0 THEN

    SalesLine."VAT %" := (AvaLine."Tax Tax Amount" / AvaLine."Total Taxable Amount")*100;
SalesLine."Prepmt. Line Amount" := ROUND((SalesLine."Prepayment %" * SalesLine."Line Amount") / 100,RecCurrency."Amount Rounding Precision");

PrepLineAmt := (AvaLine."Total Taxable Amount" + AvaLine."Tax Discount Amount" + AvaLine."Tax Exempt Amount");
PrepLineAmt += (AvaLine."Total Taxable Amount" + AvaLine."Tax Discount Amount" + AvaLine."Tax Exempt Amount")* AvaLine."Tax Rate" ;

IF SalesOrderHdr."Prepmt. Include Tax" THEN
        SalesLine."Prepmt. Amt. Incl. VAT" := ROUND((SalesLine."Prepayment %" * PrepLineAmt) /                 100,RecCurrency."Amount Rounding Precision")
ELSE
        SalesLine."Prepmt. Amt. Incl. VAT" := SalesLine."Prepmt. Line Amount";
        SalesLine."Prepayment Amount" := SalesLine."Prepmt. Amt. Incl. VAT";
        SalesLine.MODIFY;
END

END
ELSE AvaCallGetTax := TRUE;

UNTIL (SalesLine.NEXT = 0) OR (AvaCallGetTax = TRUE);

END;

END;

END
ELSE

AvaCallGetTax := TRUE;

END;

 

IF AvaCallGetTax = FALSE THEN
EXIT(TRUE);

AvaHead.RESET;
AvaHead.SETRANGE(Module,AvaHead.Module::Sales);
AvaHead.SETRANGE("Document Type",SalesHeaderType);
AvaHead.SETRANGE("Document No.",SalesHeaderNo);
AvaHead.SETRANGE("Document Id",SalesHeaderNo);
IF AvaHead.FINDFIRST THEN
fnRemoveRecord(AvaHead);
AvaWindowOpen(StrMessage+Text14073221);

 

Steps 2 : go to function  fnCalcTax

Search for below line and replace marked code with old code lines fnCalcTax

IF NOT AvaReleaseStatisticsBln THEN BEGIN
    IF SalesLine."Document Type" = SalesLine."Document Type" ::Quote THEN BEGIN

QtyPerLine:=SalesLine.Quantity;

    END
ELSE BEGIN

IF Avaconfig."Statistics Quantity" = '1' THEN BEGIN

QtyPerLine:=SalesLine.Quantity;

END;

IF Avaconfig."Statistics Quantity" = '2' THEN BEGIN

IF (SalesLine."Document Type" = SalesLine."Document Type" :: "Return Order") OR (SalesLine."Document Type" = SalesLine."Document Type" :: "Credit Memo") THEN BEGIN

QtyPerLine:=SalesLine."Return Qty. to Receive";

END ELSE BEGIN

QtyPerLine:=SalesLine."Qty. to Ship";

END;

END;

IF Avaconfig."Statistics Quantity" = '3' THEN BEGIN

QtyPerLine:=SalesLine."Qty. to Invoice";

END;

END;

END ELSE BEGIN

// IF Avaconfig."Release Quantity" = '1' THEN BEGIN

// QtyPerLine:=SalesLine.Quantity;
// END ELSE IF Avaconfig."Release Quantity" = '2' THEN BEGIN
// IF (SalesLine."Document Type" = SalesLine."Document Type" :: "Credit Memo") OR (SalesLine."Document Type" = SalesLine."Document Type" :: "Return Order") THEN BEGIN
// QtyPerLine:=SalesLine."Return Qty. to Receive";
// END ELSE BEGIN
// QtyPerLine:=SalesLine."Qty. to Ship";
// END;
// END ELSE IF Avaconfig."Release Quantity" = '3' THEN BEGIN
// QtyPerLine:=SalesLine."Qty. to Invoice";
// END;

QtyPerLine:=SalesLine.Quantity;

END;

END
ELSE BEGIN
    InvoiceFlag := Avaconfig.Invoice;

 

Codeunit 14073310 AVA Validate Call

 

  •  To avoid multiple GetTax call on already uncommitted document (optional)

Steps 1 : go to function  AvaGetTaxOrder

Search for below line and Add marked

IF NOT(AvaCheckInstStatus(0)) THEN
    EXIT(FALSE);

IF NOT OpStatistics THEN BEGIN
    AvaDocTypeTax := 0;
    CASE DocType OF
        0,4: BEGIN AvaDocTypeTax := 0; TDocType := 1; END;
        1,2: BEGIN AvaDocTypeTax := 98; TDocType := 1; END;
        3,5: BEGIN AvaDocTypeTax := 99; TDocType := 5; END;
    END;
END;

IF ((NOT(SalesHead.Status = SalesHead.Status::Released) )OR OpStatistics) THEN BEGIN
    IF NOT(SALES_TO_POST) THEN BEGIN
        AvaTaxEngine.AvaSetReleaseFlag(TRUE);
        Result:=AvaTaxEngine.fnCalcTax(DocNum,DocType,AvaDocTypeTax,FALSE,GetTaxSource);
END ELSE
    Result:=TRUE;
END ELSE BEGIN