Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Codeunit::"Sales Tax Calculate" EventSubscriber?

(0) ShareShare
ReportReport
Posted on by 352

So BC 365 v19.5 on-prem here. Due to being on-prem, as well as being a bit behind in version, I am looking to implement a customized AL solution for Tennessee, USA tiered taxes (https://knowledge.avalara.com/bundle/dqa1657870670369_dqa1657870670369/page/ccf1670396346489.html). Looking at Codeunit::"Sales Tax Calculate", there are various events I can listen out for. For example of a use case, if I am creating a Sales Order, then each new line will first pull the matching Tax Area and Tax Jurisdiction details, stuff those into a temporary Sales Tax Amount Line entry, and then push those tax specifics into a new Sales Line. I am looking to subscribe to the event after the new Sales Tax Amount Line entry is created, modify that with the appropriate taxes, and then take those details to push into the new Sales Line. 

Any suggestions? Here are the events I see available:

    [IntegrationEvent(false, false)]
    local procedure OnBeforeAddSalesLine(var SalesLine: Record "Sales Line"; var IsHandled: Boolean);
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeAddPurchLine(var PurchaseLine: Record "Purchase Line"; var IsHandled: Boolean);
    begin
    end;

#if not CLEAN17
    [Obsolete('Replaced by OnBeforeCalculateTaxProcedure', '17.0')]
    [IntegrationEvent(false, false)]
    procedure OnBeforeCalculateTax(TaxAreaCode: Code[20]; TaxGroupCode: Code[20]; TaxLiable: Boolean)
    begin
    end;
#endif
    [IntegrationEvent(false, false)]
    local procedure OnBeforeCalculateTaxProcedure(TaxAreaCode: Code[20]; TaxGroupCode: Code[20]; TaxLiable: Boolean; Date: Date; Amount: Decimal; Quantity: Decimal; ExchangeRate: Decimal; var TaxAmount: Decimal; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeInitSalesTaxLines(var TaxAreaCode: Code[20]; var TaxGroupCode: Code[20]; TaxLiable: Boolean; Amount: Decimal; Quantity: Decimal; Date: Date; DesiredTaxAmount: Decimal; var TMPTaxDetail: Record "Tax Detail"; var IsHandled: Boolean; var Initialised: Boolean; var FirstLine: Boolean; var TotalForAllocation: Decimal)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeDistTaxOverPurchLines(var PurchaseLine: Record "Purchase Line"; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeDistTaxOverSalesLines(var SalesLine: Record "Sales Line"; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeDistTaxOverServLines(var ServiceLine: Record "Service Line"; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeEndSalesTaxCalculationSales(SalesHeader: Record "Sales Header"; var TempSalesTaxAmountLine: Record "Sales Tax Amount Line" temporary; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeEndSalesTaxCalculationPurchase(PurchaseHeader: Record "Purchase Header"; var TempSalesTaxAmountLine: Record "Sales Tax Amount Line" temporary; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeEndSalesTaxCalculationService(ServiceHeader: Record "Service Header"; var TempSalesTaxAmountLine: Record "Sales Tax Amount Line" temporary; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeGetSummarizedSalesTaxTable(var SalesTaxAmountLine: Record "Sales Tax Amount Line"; SourceType: Integer; SourceSubtype: Integer; SourceID: Code[20]; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeGetPostedSummarizedSalesTaxTable(var SalesTaxAmountLine: Record "Sales Tax Amount Line"; var TempSalesTaxAmountDifference: Record "Sales Tax Amount Difference" temporary; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeApplyTaxDifference(var TempSalesTaxAmountLine: Record "Sales Tax Amount Line"; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnAfterUpdatePurchaseLineVatPct(var PurchLine: Record "Purchase Line"; PurchHeader: Record "Purchase Header")
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnDistTaxOverPurchLinesOnPurchLineLoopOnAfterSetPurchLineVATBaseAmount(var PurchLine: Record "Purchase Line"; PurchHeader: Record "Purchase Header")
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnDistTaxOverPurchLinesOnTempSalesTaxLineLoopOnAfterSetPurchLineVATBaseAmount(var PurchLine: Record "Purchase Line"; PurchHeader: Record "Purchase Header");
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnDistTaxOverPurchLinesOnTempSalesTaxLineLoopOnAfterSetTempSalesTaxLineAmount(var TempSalesTaxLine: Record "Sales Tax Amount Line" temporary; PurchLine: Record "Purchase Line"; PurchHeader: Record "Purchase Header"; var Amount: Decimal)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnAddPurchInvoiceLinesOnAfterCalcPurchLineSalesTaxAmountLine(var TempSalesTaxLine: Record "Sales Tax Amount Line" temporary; PurchInvLine: Record "Purch. Inv. Line"; PurchInvHeader: Record "Purch. Inv. Header"; ExchangeFactor: Decimal)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnAfterAddSalesLine(var TempSalesTaxLine: Record "Sales Tax Amount Line" temporary; SalesLine: Record "Sales Line"; SalesHeader: Record "Sales Header"; ExchangeFactor: Decimal)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnDistTaxOverSalesLinesOnSalesLineLoopOnAfterSetSalesLineVATBaseAmount(var SalesLine: Record "Sales Line"; SalesHeader: Record "Sales Header");
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnDistTaxOverSalesLinesOnTempSalesTaxLineLoopOnAfterSetSalesLineVATBaseAmount(var SalesLine: Record "Sales Line"; SalesHeader: Record "Sales Header")
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnDistTaxOverSalesLinesOnTempSalesTaxLineLoopOnAfterSetTempSalesTaxLineAmount(var TempSalesTaxLine: Record "Sales Tax Amount Line" temporary; SalesLine: Record "Sales Line"; SalesHeader: Record "Sales Header"; var Amount: Decimal)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnEndSalesTaxCalculationOnBeforeSalesTaxAmountLine2Insert(var SalesTaxAmountLine2: Record "Sales Tax Amount Line" temporary; var TempSalesTaxLine: Record "Sales Tax Amount Line" temporary)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnEndSalesTaxCalculationOnBeforeTempSalesTaxLineModify(var TempSalesTaxLine: Record "Sales Tax Amount Line" temporary)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnEndSalesTaxCalculationOnAfterCalculateMaxAmount(var TempSalesTaxLine: Record "Sales Tax Amount Line" temporary; TaxDetail: Record "Tax Detail"; var MaxAmount: Decimal; var AddedTaxAmount: Decimal; TaxBaseAmt: Decimal);
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnAfterAddPurchLine(var TempSalesTaxLine: Record "Sales Tax Amount Line" temporary; PurchLine: Record "Purchase Line"; PurchHeader: Record "Purchase Header"; ExchangeFactor: Decimal)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeStartSalestaxCalculation()
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnAddSalesLineOnAfterTempSalesTaxAmountLineSetFilters(var TempSalesTaxAmountLine: Record "Sales Tax Amount Line" temporary)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnAddPurchLineOnAfterTempSalesTaxAmountLineSetFilters(var TempSalesTaxAmountLine: Record "Sales Tax Amount Line" temporary)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnAfterGetSalesTaxAmountLineTable(var TempSalesTaxAmountLine: Record "Sales Tax Amount Line" temporary)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeCalculateExpenseTax(TaxAreaCode: Code[20]; TaxGroupCode: Code[20]; TaxLiable: Boolean; Date: Date; Amount: Decimal; Quantity: Decimal; ExchangeRate: Decimal; var TaxAmount: Decimal; var TempTaxDetailMaximums: Record "Tax Detail" temporary; var TaxDetail: Record "Tax Detail"; var TaxAreaLine: Record "Tax Area Line"; var IsHandled: Boolean)
    begin
    end;

  • Verified answer
    Greg Kujawa Profile Picture
    352 on at
    RE: Codeunit::"Sales Tax Calculate" EventSubscriber?

    Through a great deal of trial and error I figured out a place to do this.

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales Tax Calculate", 'OnBeforeApplyTaxDifference', '', true, true)]

    This allowed me to modify the tax line as needed, so that the three TN tiers are correctly reflected. Need to refresh the initial document (e.g. - Sales Order), as it's not until the document is released or posted until the sales tax footer appears with the proper tax total. Although behind the scenes the proper taxes are being maintained.

    UPDATE: This mod doesn't work for multiple line items. These taxes are supposed to hit each individual line item. For example, if you have one line item for $3,000 and another line item for $4,000 then local taxes should total $36 for each line item. So the sum total for local taxes should be $72. The way that BC is handling this tax category is forcing things to just reflect $36. That is $1,600 times 2.25% for the entire sale, as opposed to $1,600 times 2.25% for each line item. Based on pulling up the sale in Sales Order --> Order --> Statistics --> View Sales Tax Lines. 

  • Greg Kujawa Profile Picture
    352 on at
    RE: Codeunit::"Sales Tax Calculate" EventSubscriber?

    yzhums Usually you have great insight to the nitty gritty underpinnings, such as this. Any advice? :)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 858

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 1

#3
Mansi Soni Profile Picture

Mansi Soni 569

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans