Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Request] Codeunit 31269 "Compensation - Post CZC".OnRun #27656

Open
fridrichovsky opened this issue Nov 20, 2024 · 0 comments
Open

[Event Request] Codeunit 31269 "Compensation - Post CZC".OnRun #27656

fridrichovsky opened this issue Nov 20, 2024 · 0 comments
Labels
event-request Request for adding an event Finance GitHub request for Finance area

Comments

@fridrichovsky
Copy link
Contributor

fridrichovsky commented Nov 20, 2024

Describe the request

Please add new event

    trigger OnRun()
    var
        Balance: Decimal;
        TempAmount: Decimal;
        i: Integer;
    begin
        OnBeforePostCompensationCZC(Rec);
        Rec.CheckCompensationPostRestrictions();

        if Rec.Status <> Rec.Status::Released then
            Codeunit.Run(Codeunit::"Release Compens. Document CZC", Rec);

        CompensationsSetupCZC.Get();
        CompensationsSetupCZC.TestField("Compensation Bal. Account No.");

        SourceCodeSetup.Get();
        GeneralLedgerSetup.Get();

        Rec.CalcFields("Compensation Balance (LCY)");
        Balance := Rec."Compensation Balance (LCY)";
        CheckRoundingAccounts(Balance);

        i := 1;
        CompensationLineCZC.Reset();
        CompensationLineCZC.SetRange("Compensation No.", Rec."No.");
        if CompensationLineCZC.Find('-') then begin
            WindowDialog.Open('#1#################################\\' +
              Text008Msg);
            WindowDialog.Update(1, StrSubstNo(Text009Msg, Rec."No."));
            repeat
                WindowDialog.Update(2, i);
                Clear(GenJournalLine);
                GenJournalLine."Compensation CZC" := CompensationLineCZC."Source Entry No." <> 0;
                GenJournalLine.Validate("Posting Date", Rec."Posting Date");
                GenJournalLine.Validate("Document No.", Rec."No.");
                GenJournalLine.Validate("Account Type", CompensationLineCZC."Source Type".AsInteger() + 1);
                GenJournalLine.Validate("Account No.", CompensationLineCZC."Source No.");
                GenJournalLine."Posting Group" := CompensationLineCZC."Posting Group";
                GenJournalLine.Validate("Document Date", Rec."Document Date");
                GenJournalLine.Validate("Currency Code", CompensationLineCZC."Currency Code");
                if CompensationLineCZC."Currency Code" <> '' then
                    GenJournalLine.Validate("Currency Factor", CompensationLineCZC."Currency Factor");
                GenJournalLine.Validate(Description, Rec.Description);
                GenJournalLine.Validate(Amount, -CompensationLineCZC.Amount);
                GenJournalLine.Validate("Bal. Account Type", GenJournalLine."Bal. Account Type"::"G/L Account");
                GenJournalLine.Validate("Bal. Account No.", CompensationsSetupCZC."Compensation Bal. Account No.");
                GenJournalLine.Validate("Applies-to ID", Rec."No.");
                GenJournalLine."Dimension Set ID" := CompensationLineCZC."Dimension Set ID";
                GenJournalLine."Shortcut Dimension 1 Code" := CompensationLineCZC."Shortcut Dimension 1 Code";
                GenJournalLine."Shortcut Dimension 2 Code" := CompensationLineCZC."Shortcut Dimension 2 Code";
                GenJournalLine."Variable Symbol CZL" := CompensationLineCZC."Variable Symbol";

                CompensationManagementCZC.SetAppliesToID(CompensationLineCZC, Rec."No.");

                TempAmount := CompensationLineCZC."Amount (LCY)";
                Clear(CompensationLineCZC."Amount (LCY)");
                CompensationLineCZC.Modify();

                GenJournalLine."Source Code" := SourceCodeSetup."Compensation CZC";
                GenJournalLine."System-Created Entry" := true;
		//------------------------------------------------------------------OnRunOnBeforeGenJnlPostCZC:BEGIN
		OnRunOnBeforeGenJnlPostCZC(GenJournalLine,CompensationLineCZC,TempAmount);
		//------------------------------------------------------------------OnRunOnBeforeGenJnlPostCZC:END
                GenJnlPostLine.RunWithCheck(GenJournalLine);
                CompensationLineCZC."Amount (LCY)" := TempAmount;
                CompensationLineCZC.Modify();

                CompensationManagementCZC.SetAppliesToID(CompensationLineCZC, '');
                i += 1;
            until CompensationLineCZC.Next() = 0;

            if Balance <> 0 then begin
                Clear(GenJournalLine);
                GenJournalLine.Validate("Posting Date", Rec."Posting Date");
                GenJournalLine.Validate("Document No.", Rec."No.");
                GenJournalLine.Validate("Account Type", GenJournalLine."Account Type"::"G/L Account");
                case true of
                    Balance < 0:
                        GenJournalLine.Validate("Account No.", CompensationsSetupCZC."Credit Rounding Account");
                    Balance > 0:
                        GenJournalLine.Validate("Account No.", CompensationsSetupCZC."Debit Rounding Account");
                end;
                GenJournalLine.Validate("Document Date", Rec."Document Date");
                GenJournalLine.Validate(Description, Rec.Description);
                GenJournalLine.Validate(Amount, Balance);
                GenJournalLine.Validate("Bal. Account Type", GenJournalLine."Bal. Account Type"::"G/L Account");
                GenJournalLine.Validate("Bal. Account No.", CompensationsSetupCZC."Compensation Bal. Account No.");
                GenJournalLine."Dimension Set ID" := CompensationLineCZC."Dimension Set ID";
                GenJournalLine."Shortcut Dimension 1 Code" := CompensationLineCZC."Shortcut Dimension 1 Code";
                GenJournalLine."Shortcut Dimension 2 Code" := CompensationLineCZC."Shortcut Dimension 2 Code";
                GenJournalLine."Source Code" := SourceCodeSetup."Compensation CZC";
                GenJournalLine."System-Created Entry" := true;
                GenJnlPostLine.RunWithCheck(GenJournalLine);
            end;

            if PreviewMode then
                GenJnlPostPreview.ThrowError();

            Clear(PostedCompensationHeaderCZC);
            PostedCompensationHeaderCZC.TransferFields(Rec);
            PostedCompensationHeaderCZC.Insert();
            OnAfterPostedCompensationHeaderInsertCZC(Rec, PostedCompensationHeaderCZC);
            RecordLinkManagement.CopyLinks(Rec, PostedCompensationHeaderCZC);

            Clear(CompensationLineCZC);
            CompensationLineCZC.SetRange("Compensation No.", Rec."No.");
            CompensationLineCZC.FindSet();
            repeat
                Clear(PostedCompensationLineCZC);
                PostedCompensationLineCZC.TransferFields(CompensationLineCZC);
                PostedCompensationLineCZC."Compensation No." := PostedCompensationHeaderCZC."No.";
                PostedCompensationLineCZC.Insert();
                OnAfterPostedCompensationLineInsertCZC(CompensationLineCZC, PostedCompensationLineCZC);
            until CompensationLineCZC.Next() = 0;

            UpdateIncomingDocument(Rec."Incoming Document Entry No.", Rec."Posting Date", PostedCompensationHeaderCZC."No.");

            RecordLinkManagement.RemoveLinks(CompensationLineCZC);
            CompensationLineCZC.DeleteAll();
            if Rec.HasLinks() then
                Rec.DeleteLinks();
            Rec.Delete();
            WindowDialog.Close();
        end else
            Error(Text002Err);

        OnAfterPostCompensationCZC(Rec, GenJnlPostLine, PostedCompensationHeaderCZC."No.");
    end;
    //------------------------------------------------------------------OnRunOnBeforeGenJnlPostCZC:BEGIN
    [IntegrationEvent(true, false)]
    local procedure OnRunOnBeforeGenJnlPostCZC(var GenJournalLine: Record "Gen. Journal Line"; var CompensationLineCZC: Record "Compensation Line CZC";var TempAmount: Decimal)
    begin
    end;
    //------------------------------------------------------------------OnRunOnBeforeGenJnlPostCZC:END

Additional context

We need add more values to gen jnl.
Internal work item: AB#558148

@JesperSchulz JesperSchulz added event-request Request for adding an event Finance GitHub request for Finance area labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
event-request Request for adding an event Finance GitHub request for Finance area
Projects
None yet
Development

No branches or pull requests

2 participants