ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[Event-Request] Report 1131 Cost Allocation

Open KlausMaxSchwab opened this issue 3 months ago • 4 comments

Why do you need this change?

To further allocate the costs, project details must also be transferred to the journal entry and carried over to the account entries.

Describe the request

local procedure WriteJournalLine(CostTypeCode: Code[20]; CostCenterCode: Code[20]; CostObjectCode: Code[20]; PostAmount: Decimal; Text: Text; AllocKey: Text; AllocID: Code[10]; Allocated2: Boolean) var CostCenter: Record "Cost Center"; begin if PostAmount = 0 then exit;

    if CostCenterCode <> '' then
        if CostCenter.Get(CostCenterCode) then
            CostCenter.TestField(Blocked, false);

    if CostTypeCode = '' then
        Error(Text015, "Cost Allocation Source".ID);

    if ((CostCenterCode = '') and (CostObjectCode = '')) or ((CostCenterCode <> '') and (CostObjectCode <> '')) then
        Error(Text016, "Cost Allocation Source".ID, CostCenterCode, CostObjectCode);

    LastCostJourLineNo := LastCostJourLineNo + 10000;
    TempCostJnlLine."Line No." := LastCostJourLineNo;
    TempCostJnlLine."Posting Date" := AllocDate;
    TempCostJnlLine."Cost Type No." := CostTypeCode;
    TempCostJnlLine."Cost Center Code" := CostCenterCode;
    TempCostJnlLine."Cost Object Code" := CostObjectCode;
    TempCostJnlLine."Document No." := IncStr(CostAccSetup."Last Allocation Doc. No.");
    TempCostJnlLine.Description := CopyStr(Text, 1, MaxStrLen(TempCostJnlLine.Description));
    TempCostJnlLine.Amount := PostAmount;
    TempCostJnlLine."System-Created Entry" := true;
    TempCostJnlLine.Allocated := Allocated2;
    TempCostJnlLine."Allocation Description" := CopyStr(AllocKey, 1, MaxStrLen(TempCostJnlLine."Allocation Description"));
    TempCostJnlLine."Allocation ID" := AllocID;
    TempCostJnlLine."Source Code" := SourceCodeSetup."Cost Allocation";
    TempCostJnlLine."Budget Name" := CostBudgetName.Name;
     OnBeforeInsertTempCostLine(TempCostLine);
    TempCostJnlLine.Insert();

    if TempCostJnlLine.Amount > 0 then
        TotalDebit := TotalDebit + TempCostJnlLine.Amount
    else
        TotalCredit := TotalCredit + TempCostJnlLine.Amount;

    EntriesPerLevel := EntriesPerLevel + 1;
    TotalEntries := TotalEntries + 1;
    Window.Update(4, Format(TotalEntries));
end;

[IntegrationEvent(false, false)] local procedure OnBeforeInsertTempCostLine(var TempCostLine: Record "Cost Journal Line" temporary) begin end;

Internal work item: AB#646934

KlausMaxSchwab avatar Aug 14 '26 13:08 KlausMaxSchwab

This will help us to distribute the project informations to other entries to filter costs to projects.

KlausMaxSchwab avatar Aug 14 '26 13:08 KlausMaxSchwab

✅ Analysis complete - ready for further processing


Implementation:

Add a new integration event in Report 1131 Cost Allocation in the WriteJournalLine() procedure before TempCostJnlLine.Insert() so extensions can populate additional fields, such as project-related information, on the temporary cost journal line.

Location in WriteJournalLine() procedure:

        TempCostJnlLine."System-Created Entry" := true;
        TempCostJnlLine.Allocated := Allocated2;
        TempCostJnlLine."Allocation Description" := CopyStr(AllocKey, 1, MaxStrLen(TempCostJnlLine."Allocation Description"));
        TempCostJnlLine."Allocation ID" := AllocID;
        TempCostJnlLine."Source Code" := SourceCodeSetup."Cost Allocation";
        TempCostJnlLine."Budget Name" := CostBudgetName.Name;
        OnWriteJournalLineOnBeforeInsertTempCostJournalLine(TempCostJnlLine, "Cost Allocation Source");
        TempCostJnlLine.Insert();

        if TempCostJnlLine.Amount > 0 then
            TotalDebit := TotalDebit + TempCostJnlLine.Amount
        else
            TotalCredit := TotalCredit + TempCostJnlLine.Amount;

Event Publisher (add at the end of the codeunit with other events):

    [IntegrationEvent(false, false)]
    local procedure OnWriteJournalLineOnBeforeInsertTempCostJournalLine(var TempCostJournalLine: Record "Cost Journal Line" temporary; CostAllocationSource: Record "Cost Allocation Source")
    begin
    end;

File: CostAllocation.Report.al

[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.

[!TIP] Not accurate? Reply with /not-accurate (optional: add a short explanation). Your feedback improves future responses.

github-actions[bot] avatar Aug 14 '26 19:08 github-actions[bot]

I need this change, too. Do you know when it will be implemented?

Daniamstutz avatar Aug 25 '26 11:08 Daniamstutz

Fixed

AndersLarsenMicrosoft avatar Sep 01 '26 14:09 AndersLarsenMicrosoft