Codeunit 57 (Document Totals): Add a new event in procedure PurchaseCalculateTotalsNoRounding
Describe the request
I would like to request Microsoft Dynamics Business Central AL team to publish a new event with the need of controlling if condition of the procedure PurchaseCalculateTotalsNoRounding in Codeunit 57 as shown in the below code snippet which is requested as a new event in the tags // NEW EVENT BEGIN ----- // NEW EVENT END and also attaching the further details for the requirement at end of this request.
Thank you!
procedure PurchaseCalculateTotalsNoRounding(var TempCurrentPurchaseLine: Record "Purchase Line"; var VATAmount: Decimal; var TempTotalPurchaseLine: Record "Purchase Line"; var TaxAreaCode: Code[20])
var
PurchaseLine: Record "Purchase Line";
begin
Clear(TempTotalPurchaseLine);
PurchaseLine.SetRange("Document Type", TempCurrentPurchaseLine."Document Type");
PurchaseLine.SetRange("Document No.", TempCurrentPurchaseLine."Document No.");
if PurchaseLine.FindSet() then
repeat
if ((PurchaseLine."Tax Group Code" = '') or
((PurchaseLine."Tax Area Code" = '') and (TaxAreaCode <> '')))
then begin
TempTotalPurchaseLine.Amount += (PurchaseLine."Line Amount" - PurchaseLine."Inv. Discount Amount");
TempTotalPurchaseLine."Inv. Discount Amount" += PurchaseLine."Inv. Discount Amount";
TempTotalPurchaseLine."Amount Including VAT" += (PurchaseLine."Line Amount" - PurchaseLine."Inv. Discount Amount");
end else begin
TempTotalPurchaseLine.Amount += PurchaseLine.Amount;
TempTotalPurchaseLine."Inv. Discount Amount" += PurchaseLine."Inv. Discount Amount";
TempTotalPurchaseLine."Amount Including VAT" += PurchaseLine."Amount Including VAT";
end
until PurchaseLine.Next() = 0;
VATAmount := TempTotalPurchaseLine."Amount Including VAT" - TempTotalPurchaseLine.Amount;
//NEW EVENT BEGIN
OnAfterPurchaseCalculateTotalsNoRounding(TempCurrentPurchaseLine: Record "Purchase Line", VATAmount: Decimal, TempTotalPurchaseLine: Record "Purchase Line", TaxAreaCode)
//NEW EVENT END
end;
----------
----------
----------
`
[IntegrationEvent(false, false)]
local procedure OnAfterPurchaseCalculateTotalsNoRounding(var CurrentPurchaseLine: Record "Purchase Line"; var VATAmount: Decimal; TotalPurchaseLine: Record "Purchase Line"; TaxAreaCode: Code[20])
begin
end;
`
Additional context
The need arose due to necessary to control over the VATAmount variable value. as shown in the code snippet below:
`
begin Clear(TotalPurchaseLine); PurchaseLine.SetRange("Document Type", CurrentPurchaseLine."Document Type"); PurchaseLine.SetRange("Document No.", CurrentPurchaseLine."Document No."); if PurchaseLine.FindSet() then repeat if ((PurchaseLine."Tax Group Code" = '') or ((PurchaseLine."Tax Area Code" = '') and (TaxAreaCode <> ''))) then begin TotalPurchaseLine.Amount += (PurchaseLine."Line Amount" - PurchaseLine."Inv. Discount Amount"); TotalPurchaseLine."Inv. Discount Amount" += PurchaseLine."Inv. Discount Amount"; TotalPurchaseLine."Amount Including VAT" += (PurchaseLine."Line Amount" - PurchaseLine."Inv. Discount Amount"); end else begin TotalPurchaseLine.Amount += PurchaseLine.Amount; TotalPurchaseLine."Inv. Discount Amount" += PurchaseLine."Inv. Discount Amount"; TotalPurchaseLine."Amount Including VAT" += PurchaseLine."Amount Including VAT"; end; TotalPurchaseLine."Gross Weight" += PurchaseLine.Quantity * PurchaseLine."Gross Weight"; // NEW LINE until PurchaseLine.Next() = 0; VATAmount := TotalPurchaseLine."Amount Including VAT" - TotalPurchaseLine.Amount; end;
` Internal work item: AB#561533
Hello @avneetwadhwa To confirm, this event would only be added to the NA localization
Hello @avneetwadhwa, is this new event still needed?
@attilatoury I can see a new even has been added already at the start of this procedure. So we are good now. This ticket can be closed now. Thank you so much!
@avneetwadhwa Thank you for the update, I will close the issue.