ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[EventRequest] Codeunit 1255 "Match Bank Payments" - OnBeforeDocumentMatching()

Open MatjazSega opened this issue 7 years ago • 1 comments

Hello,

We want to add matching by Recepient Reference to standard matching code (CU 1255 "Match Bank Payments") with as little changes as possible. To achieve this, we need new event in mentioned codeunit, and an ability to skip the rest of document matching if match was found:

    local procedure FindMatchingEntry(TempLedgerEntryMatchingBuffer: Record "Ledger Entry Matching Buffer" temporary; var BankAccReconciliationLine: Record "Bank Acc. Reconciliation Line"; AccountType: Option; var BankPmtApplRule: Record "Bank Pmt. Appl. Rule")
    var
        Score: Integer;
        RemainingAmount: Decimal;
        // NEW VARIABLES >>>
        DocumentMatchingHandled: Boolean;
        // NEW VARIABLES <<< 
    begin
        if CanEntriesMatch(
             BankAccReconciliationLine, TempLedgerEntryMatchingBuffer."Remaining Amount", TempLedgerEntryMatchingBuffer."Posting Date")
        then begin
            if AccountType = TempBankStatementMatchingBuffer."Account Type"::Customer then
                DirectDebitCollectionMatching(BankPmtApplRule, BankAccReconciliationLine, TempLedgerEntryMatchingBuffer);

            RelatedPartyMatching(BankPmtApplRule, TempLedgerEntryMatchingBuffer, BankAccReconciliationLine, AccountType);

            // NEW CODE >>>
            OnBeforeDocumentMatching(BankPmtApplRule, BankAccReconciliationLine, TempLedgerEntryMatchingBuffer, DocumentMatchingHandled);
            if not DocumentMatchingHandled then
            // NEW CODE <<<
                if AccountType <> TempBankStatementMatchingBuffer."Account Type"::"Bank Account" then
                    DocumentMatching(BankPmtApplRule, BankAccReconciliationLine,
                      TempLedgerEntryMatchingBuffer."Document No.", TempLedgerEntryMatchingBuffer."External Document No.")
                else
                    DocumentMatchingForBankLedgerEntry(BankPmtApplRule, BankAccReconciliationLine, TempLedgerEntryMatchingBuffer);

            RemainingAmount := TempLedgerEntryMatchingBuffer.GetApplicableRemainingAmount(BankAccReconciliationLine, UsePaymentDiscounts);
            AmountInclToleranceMatching(
              BankPmtApplRule, BankAccReconciliationLine, AccountType, RemainingAmount);

            Score := TempBankPmtApplRule.GetBestMatchScore(BankPmtApplRule);

            if Score >= MinimumMatchScore then
                TempBankStatementMatchingBuffer.AddMatchCandidate(
                  BankAccReconciliationLine."Statement Line No.", TempLedgerEntryMatchingBuffer."Entry No.",
                  Score, AccountType,
                  TempLedgerEntryMatchingBuffer."Account No.");

            if BankPmtApplRule."Doc. No./Ext. Doc. No. Matched" = BankPmtApplRule."Doc. No./Ext. Doc. No. Matched"::Yes then begin
                TempBankStatementMatchingBuffer.InsertOrUpdateOneToManyRule(
                  TempLedgerEntryMatchingBuffer,
                  BankAccReconciliationLine."Statement Line No.",
                  BankPmtApplRule."Related Party Matched", AccountType,
                  RemainingAmount);

                TempBankStmtMultipleMatchLine.InsertLine(
                  TempLedgerEntryMatchingBuffer,
                  BankAccReconciliationLine."Statement Line No.", AccountType);
            end;
        end;
    end;

And new event would look something like this:

    [IntegrationEvent(false, false)]
    local procedure OnBeforeDocumentMatching(var BankPmtApplRule: Record "Bank Pmt. Appl. Rule"; BankAccReconciliationLine: Record "Bank Acc. Reconciliation Line"; TempLedgerEntryMatchingBuffer: Record "Ledger Entry Matching Buffer" temporary; var DocumentMatchingHandled: Boolean)
    begin
    end;

Best regards, Matjaz

MatjazSega avatar Nov 08 '19 13:11 MatjazSega

Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. We will update this issue with information about availability.

bc-ghost avatar Nov 27 '19 10:11 bc-ghost