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 225 "Gen. Jnl.-Apply".ApplyCustomerLedgerEntry #27932

Open
fridrichovsky opened this issue Jan 13, 2025 · 0 comments
Open
Labels
event-request Request for adding an event SCM GitHub request for SCM area

Comments

@fridrichovsky
Copy link
Contributor

fridrichovsky commented Jan 13, 2025

Describe the request

Please add new parameter to event

local procedure ApplyCustomerLedgerEntry(var GenJnlLine: Record "Gen. Journal Line")
    var
        CustLedgEntry: Record "Cust. Ledger Entry";
        TempCustLedgEntry: Record "Cust. Ledger Entry" temporary;
        AppliedAmount: Decimal;
        CustomAppliesToId: Code[50];
        IsHandled: Boolean;
    begin
        GetAppliedCustomerEntries(TempCustLedgEntry, GenJnlLine);
        EntrySelected := SelectCustLedgEntry(GenJnlLine, CustomAppliesToId);
        if not EntrySelected then
            exit;

        CustLedgEntry.Reset();
        CustLedgEntry.SetCurrentKey("Customer No.", Open, Positive);
        CustLedgEntry.SetRange("Customer No.", AccNo);
        CustLedgEntry.SetRange(Open, true);
        CustLedgEntry.SetRange("Applies-to ID", GenJnlLine."Applies-to ID");
        OnAfterCustLedgEntrySetFilters(CustLedgEntry, GenJnlLine, AccNo);
        if CustLedgEntry.Find('-') then begin
            CurrencyCode2 := CustLedgEntry."Currency Code";
            if GenJnlLine.Amount = 0 then begin
                repeat
                    if not TempCustLedgEntry.Get(CustLedgEntry."Entry No.") then begin
                        PaymentToleranceMgt.DelPmtTolApllnDocNo(GenJnlLine, CustLedgEntry."Document No.");
                        OnApplyCustomerLedgerEntryOnBeforeCheckAgainstApplnCurrency(GenJnlLine, CustLedgEntry);
                        CheckAgainstApplnCurrency(CurrencyCode2, CustLedgEntry."Currency Code", AccType::Customer, true);
                        UpdateCustLedgEntry(CustLedgEntry);
                        IsHandled := false;
                        OnBeforeFindCustApply(GenJnlLine, CustLedgEntry, GenJnlLine.Amount, IsHandled);
                        if not IsHandled then
                            if PaymentToleranceMgt.CheckCalcPmtDiscGenJnlCust(GenJnlLine, CustLedgEntry, 0, false) and
                               (Abs(CustLedgEntry."Amount to Apply") >=
                                Abs(CustLedgEntry."Remaining Amount" - CustLedgEntry.GetRemainingPmtDiscPossible(GenJnlLine."Posting Date")))
                            then
                                GenJnlLine.Amount := GenJnlLine.Amount - (CustLedgEntry."Amount to Apply" - CustLedgEntry.GetRemainingPmtDiscPossible(GenJnlLine."Posting Date"))
                            else
                                GenJnlLine.Amount := GenJnlLine.Amount - CustLedgEntry."Amount to Apply";
                    end else
                        GetAppliedAmountOnCustLedgerEntry(TempCustLedgEntry, AppliedAmount);
                until CustLedgEntry.Next() = 0;
                TempCustLedgEntry.DeleteAll();

                if AppliedAmount <> 0 then
                    GenJnlLine.Amount += AppliedAmount;

                if (GenJnlLine."Bal. Account Type" = GenJnlLine."Bal. Account Type"::Customer) or (GenJnlLine."Bal. Account Type" = GenJnlLine."Bal. Account Type"::Vendor) then
                    GenJnlLine.Amount := -GenJnlLine.Amount;
                GenJnlLine.Validate(Amount);
                //-----------------------------------------------OnApplyCustomerLedgerEntryOnAfterValidateAmount:BEGIN
                OnApplyCustomerLedgerEntryOnAfterValidateAmount(GenJnlLine, CustLedgEntry);
                //-----------------------------------------------OnApplyCustomerLedgerEntryOnAfterValidateAmount:END
            end else
                repeat
                    OnApplyCustomerLedgerEntryOnBeforeCheckAgainstApplnCurrencyCustomerAmountNotZero(GenJnlLine, CustLedgEntry);
                    CheckAgainstApplnCurrency(CurrencyCode2, CustLedgEntry."Currency Code", AccType::Customer, true);
                until CustLedgEntry.Next() = 0;
            if GenJnlLine."Currency Code" <> CurrencyCode2 then
                if GenJnlLine.Amount = 0 then begin
                    IsHandled := false;
                    OnApplyCustomerLedgerEntryOnBeforeConfirmUpdateCurrency(GenJnlLine, CustLedgEntry."Currency Code", IsHandled);
                    if not IsHandled then begin
                        ConfirmCurrencyUpdate(GenJnlLine, CustLedgEntry."Currency Code");
                        GenJnlLine."Currency Code" := CustLedgEntry."Currency Code";
                    end;
                end else begin
                    OnApplyCustomerLedgerEntryOnBeforeCheckAgainstApplnCurrencyCustomer(GenJnlLine, CustLedgEntry);
                    CheckAgainstApplnCurrency(GenJnlLine."Currency Code", CustLedgEntry."Currency Code", AccType::Customer, true);
                end;
            GenJnlLine."Applies-to Doc. Type" := GenJnlLine."Applies-to Doc. Type"::" ";
            GenJnlLine."Applies-to Doc. No." := '';
            OnApplyCustomerLedgerEntryOnAfterSetCustomerAppliesToDocNo(GenJnlLine, CustLedgEntry);
        end else
            GenJnlLine."Applies-to ID" := '';

        if (GenJnlLine."Applies-to ID" = '') and (CustomAppliesToId <> '') then
            GenJnlLine."Applies-to ID" := CustomAppliesToId;

        GenJnlLine.SetJournalLineFieldsFromApplication();

        OnApplyCustomerLedgerEntryOnBeforeModify(GenJnlLine, CustLedgEntry);

        if GenJnlLine.Modify() then;
        if GenJnlLine.Amount <> 0 then
            if not PaymentToleranceMgt.PmtTolGenJnl(GenJnlLine) then
                exit;
    end;

    //-----------------------------------------------OnApplyCustomerLedgerEntryOnAfterValidateAmount:BEGIN
    [IntegrationEvent(true, false)]
    local procedure OnApplyCustomerLedgerEntryOnAfterValidateAmount(var GenJnlLine: Record "Gen. Journal Line"; var CustLedgEntry: Record "Cust. Ledger Entry")
    begin
    end;
    //-----------------------------------------------OnApplyCustomerLedgerEntryOnAfterValidateAmount:END

Additional context

We need work with Customer Ledger Entry and Gen. Journal Line after apply.
Internal work item: AB#562609

@JesperSchulz JesperSchulz added event-request Request for adding an event SCM GitHub request for SCM area labels Jan 16, 2025
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 SCM GitHub request for SCM area
Projects
None yet
Development

No branches or pull requests

2 participants