ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

Codeunit 57 (Document Totals): Add a new event in procedure PurchaseCalculateTotalsNoRounding

Open avneetwadhwa opened this issue 1 year ago • 4 comments

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;Image

`

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

avneetwadhwa avatar Jan 02 '25 23:01 avneetwadhwa

Hello @avneetwadhwa To confirm, this event would only be added to the NA localization

attilatoury avatar Mar 26 '25 12:03 attilatoury

Hello @avneetwadhwa, is this new event still needed?

attilatoury avatar Aug 15 '25 13:08 attilatoury

@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 avatar Aug 15 '25 22:08 avneetwadhwa

@avneetwadhwa Thank you for the update, I will close the issue.

attilatoury avatar Aug 18 '25 06:08 attilatoury