From 6132713ec0195d0965c59813a7a37abae1c85610 Mon Sep 17 00:00:00 2001 From: Jatin Kumar Date: Tue, 14 Jul 2026 01:38:11 +0530 Subject: [PATCH 1/3] [Event Request] codeunit 367 "CheckManagement": add OnFinancialVoidCheckOnBeforePostBalanceAccount IsHandled event; extract balance-account posting into FinancialVoidPostBalanceAccount (AB#640242, ALAppExtensions #30260) --- .../Bank/Check/CheckManagement.Codeunit.al | 70 +++++++++++++------ 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/src/Layers/W1/BaseApp/Bank/Check/CheckManagement.Codeunit.al b/src/Layers/W1/BaseApp/Bank/Check/CheckManagement.Codeunit.al index 9c70c5a73a..ccfc213d71 100644 --- a/src/Layers/W1/BaseApp/Bank/Check/CheckManagement.Codeunit.al +++ b/src/Layers/W1/BaseApp/Bank/Check/CheckManagement.Codeunit.al @@ -253,13 +253,38 @@ codeunit 367 CheckManagement GenJnlLine2.Validate("Currency Code", BankAcc."Currency Code"); GenJnlLine2."Allow Zero-Amount Posting" := true; OnFinancialVoidCheckOnBeforeCheckBalAccountType(GenJnlLine2, CheckLedgEntry, BankAccLedgEntry3); + IsHandled := false; + OnFinancialVoidCheckOnBeforePostBalanceAccount(GenJnlLine2, CheckLedgEntry, BankAccLedgEntry3, IsHandled); + if not IsHandled then + FinancialVoidPostBalanceAccount(CheckLedgEntry, ConfirmFinancialVoid.GetVoidType(), ConfirmFinancialVoid.GetVoidDate(), BalanceAmountLCY); + + if ConfirmFinancialVoid.GetVoidDate() = CheckLedgEntry."Check Date" then begin + BankAccLedgEntry2.Open := false; + BankAccLedgEntry2."Remaining Amount" := 0; + BankAccLedgEntry2."Statement Status" := BankAccLedgEntry2."Statement Status"::Closed; + BankAccLedgEntry2.Modify(); + end; + + // rounding error from currency conversion + if CheckAmountLCY + BalanceAmountLCY <> 0 then + PostRoundingAmount(BankAcc, CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate(), -(CheckAmountLCY + BalanceAmountLCY)); + + MarkCheckEntriesVoid(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()); + Commit(); + UpdateAnalysisView.UpdateAll(0, true); + + OnAfterFinancialVoidCheck(CheckLedgEntry); + end; + + local procedure FinancialVoidPostBalanceAccount(var CheckLedgEntry: Record "Check Ledger Entry"; VoidType: Integer; VoidDate: Date; var BalanceAmountLCY: Decimal) + begin case CheckLedgEntry."Bal. Account Type" of CheckLedgEntry."Bal. Account Type"::"G/L Account": FinancialVoidPostGLAccount(GenJnlLine2, BankAccLedgEntry2, CheckLedgEntry, BalanceAmountLCY); CheckLedgEntry."Bal. Account Type"::Customer: begin - if ConfirmFinancialVoid.GetVoidType() = 0 then // Unapply entry - if UnApplyCustInvoices(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()) then + if VoidType = 0 then // Unapply entry + if UnApplyCustInvoices(CheckLedgEntry, VoidDate) then GenJnlLine2."Applies-to ID" := CheckLedgEntry."Document No."; CustLedgEntry.SetCurrentKey("Transaction No."); CustLedgEntry.SetRange("Transaction No.", BankAccLedgEntry2."Transaction No."); @@ -282,8 +307,8 @@ codeunit 367 CheckManagement end; CheckLedgEntry."Bal. Account Type"::Vendor: begin - if ConfirmFinancialVoid.GetVoidType() = 0 then // Unapply entry - if UnApplyVendInvoices(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()) then + if VoidType = 0 then // Unapply entry + if UnApplyVendInvoices(CheckLedgEntry, VoidDate) then GenJnlLine2."Applies-to ID" := CheckLedgEntry."Document No."; VendorLedgEntry.SetCurrentKey("Transaction No."); VendorLedgEntry.SetRange("Transaction No.", BankAccLedgEntry2."Transaction No."); @@ -352,8 +377,8 @@ codeunit 367 CheckManagement end; CheckLedgEntry."Bal. Account Type"::Employee: begin - if ConfirmFinancialVoid.GetVoidType() = 0 then // Unapply entry - if UnApplyEmpInvoices(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()) then + if VoidType = 0 then // Unapply entry + if UnApplyEmpInvoices(CheckLedgEntry, VoidDate) then GenJnlLine2."Applies-to ID" := CheckLedgEntry."Document No."; EmployeeLedgerEntry.SetCurrentKey("Transaction No."); EmployeeLedgerEntry.SetRange("Transaction No.", BankAccLedgEntry2."Transaction No."); @@ -387,23 +412,6 @@ codeunit 367 CheckManagement OnFinancialVoidCheckOnAfterPostBalAccLine(GenJnlLine2, CheckLedgEntry, GenJnlPostLine); end; end; - - if ConfirmFinancialVoid.GetVoidDate() = CheckLedgEntry."Check Date" then begin - BankAccLedgEntry2.Open := false; - BankAccLedgEntry2."Remaining Amount" := 0; - BankAccLedgEntry2."Statement Status" := BankAccLedgEntry2."Statement Status"::Closed; - BankAccLedgEntry2.Modify(); - end; - - // rounding error from currency conversion - if CheckAmountLCY + BalanceAmountLCY <> 0 then - PostRoundingAmount(BankAcc, CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate(), -(CheckAmountLCY + BalanceAmountLCY)); - - MarkCheckEntriesVoid(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()); - Commit(); - UpdateAnalysisView.UpdateAll(0, true); - - OnAfterFinancialVoidCheck(CheckLedgEntry); end; procedure GenJournalLineGetSystemIdFromRecordId(GenJournalLineRecordId: RecordId): Guid @@ -1150,6 +1158,22 @@ codeunit 367 CheckManagement begin end; + /// + /// Integration event raised before posting the balance account entries during a financial void operation. + /// Enables subscribers to replace the standard balance account type posting. + /// + /// General journal line for the void operation + /// Check ledger entry being voided + /// Bank account ledger entry associated with the check + /// Set to true to skip the standard balance account type posting + /// + /// Raised from FinancialVoidCheck procedure after OnFinancialVoidCheckOnBeforeCheckBalAccountType and before the balance account type posting. + /// + [IntegrationEvent(false, false)] + local procedure OnFinancialVoidCheckOnBeforePostBalanceAccount(var GenJournalLine: Record "Gen. Journal Line"; var CheckLedgerEntry: Record "Check Ledger Entry"; var BankAccountLedgerEntry: Record "Bank Account Ledger Entry"; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised before posting bank account entries during financial void operation. /// Enables custom processing or validation before bank account ledger entries are posted. From ece48145c202a51206fe45a85d66dad285bafbee Mon Sep 17 00:00:00 2001 From: Jatin Kumar Date: Tue, 14 Jul 2026 17:00:15 +0530 Subject: [PATCH 2/3] Expose var BalanceAmountLCY on OnFinancialVoidCheckOnBeforePostBalanceAccount so handled posting flows back for the rounding calc (CI financial-correctness fix) --- src/Layers/W1/BaseApp/Bank/Check/CheckManagement.Codeunit.al | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Layers/W1/BaseApp/Bank/Check/CheckManagement.Codeunit.al b/src/Layers/W1/BaseApp/Bank/Check/CheckManagement.Codeunit.al index ccfc213d71..a278d18c48 100644 --- a/src/Layers/W1/BaseApp/Bank/Check/CheckManagement.Codeunit.al +++ b/src/Layers/W1/BaseApp/Bank/Check/CheckManagement.Codeunit.al @@ -254,7 +254,7 @@ codeunit 367 CheckManagement GenJnlLine2."Allow Zero-Amount Posting" := true; OnFinancialVoidCheckOnBeforeCheckBalAccountType(GenJnlLine2, CheckLedgEntry, BankAccLedgEntry3); IsHandled := false; - OnFinancialVoidCheckOnBeforePostBalanceAccount(GenJnlLine2, CheckLedgEntry, BankAccLedgEntry3, IsHandled); + OnFinancialVoidCheckOnBeforePostBalanceAccount(GenJnlLine2, CheckLedgEntry, BankAccLedgEntry3, BalanceAmountLCY, IsHandled); if not IsHandled then FinancialVoidPostBalanceAccount(CheckLedgEntry, ConfirmFinancialVoid.GetVoidType(), ConfirmFinancialVoid.GetVoidDate(), BalanceAmountLCY); @@ -1165,12 +1165,13 @@ codeunit 367 CheckManagement /// General journal line for the void operation /// Check ledger entry being voided /// Bank account ledger entry associated with the check + /// Running balancing amount in LCY. A subscriber that sets IsHandled must add the LCY amounts it posts so the caller's currency-rounding calculation stays balanced. /// Set to true to skip the standard balance account type posting /// /// Raised from FinancialVoidCheck procedure after OnFinancialVoidCheckOnBeforeCheckBalAccountType and before the balance account type posting. /// [IntegrationEvent(false, false)] - local procedure OnFinancialVoidCheckOnBeforePostBalanceAccount(var GenJournalLine: Record "Gen. Journal Line"; var CheckLedgerEntry: Record "Check Ledger Entry"; var BankAccountLedgerEntry: Record "Bank Account Ledger Entry"; var IsHandled: Boolean) + local procedure OnFinancialVoidCheckOnBeforePostBalanceAccount(var GenJournalLine: Record "Gen. Journal Line"; var CheckLedgerEntry: Record "Check Ledger Entry"; var BankAccountLedgerEntry: Record "Bank Account Ledger Entry"; var BalanceAmountLCY: Decimal; var IsHandled: Boolean) begin end; From acf90107064ab1e2e47b0e25a8060adcc9fe0641 Mon Sep 17 00:00:00 2001 From: Jatin Kumar Date: Tue, 14 Jul 2026 19:49:19 +0530 Subject: [PATCH 3/3] Propagate FinancialVoidCheck balance-account event to NA/APAC/RU layers (Miapp sync) --- .../Bank/Check/CheckManagement.Codeunit.al | 71 +++++++++++++------ .../Bank/Check/CheckManagement.Codeunit.al | 71 +++++++++++++------ .../Bank/Check/CheckManagement.Codeunit.al | 71 +++++++++++++------ 3 files changed, 144 insertions(+), 69 deletions(-) diff --git a/src/Layers/APAC/BaseApp/Bank/Check/CheckManagement.Codeunit.al b/src/Layers/APAC/BaseApp/Bank/Check/CheckManagement.Codeunit.al index b062693707..7c6ca14dd4 100644 --- a/src/Layers/APAC/BaseApp/Bank/Check/CheckManagement.Codeunit.al +++ b/src/Layers/APAC/BaseApp/Bank/Check/CheckManagement.Codeunit.al @@ -284,13 +284,38 @@ codeunit 367 CheckManagement GenJnlLine2.Validate("Currency Code", BankAcc."Currency Code"); GenJnlLine2."Allow Zero-Amount Posting" := true; OnFinancialVoidCheckOnBeforeCheckBalAccountType(GenJnlLine2, CheckLedgEntry, BankAccLedgEntry3); + IsHandled := false; + OnFinancialVoidCheckOnBeforePostBalanceAccount(GenJnlLine2, CheckLedgEntry, BankAccLedgEntry3, BalanceAmountLCY, IsHandled); + if not IsHandled then + FinancialVoidPostBalanceAccount(CheckLedgEntry, ConfirmFinancialVoid.GetVoidType(), ConfirmFinancialVoid.GetVoidDate(), BalanceAmountLCY); + + if ConfirmFinancialVoid.GetVoidDate() = CheckLedgEntry."Check Date" then begin + BankAccLedgEntry2.Open := false; + BankAccLedgEntry2."Remaining Amount" := 0; + BankAccLedgEntry2."Statement Status" := BankAccLedgEntry2."Statement Status"::Closed; + BankAccLedgEntry2.Modify(); + end; + + // rounding error from currency conversion + if CheckAmountLCY + BalanceAmountLCY <> 0 then + PostRoundingAmount(BankAcc, CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate(), -(CheckAmountLCY + BalanceAmountLCY)); + + MarkCheckEntriesVoid(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()); + Commit(); + UpdateAnalysisView.UpdateAll(0, true); + + OnAfterFinancialVoidCheck(CheckLedgEntry); + end; + + local procedure FinancialVoidPostBalanceAccount(var CheckLedgEntry: Record "Check Ledger Entry"; VoidType: Integer; VoidDate: Date; var BalanceAmountLCY: Decimal) + begin case CheckLedgEntry."Bal. Account Type" of CheckLedgEntry."Bal. Account Type"::"G/L Account": FinancialVoidPostGLAccount(GenJnlLine2, BankAccLedgEntry2, CheckLedgEntry, BalanceAmountLCY); CheckLedgEntry."Bal. Account Type"::Customer: begin - if ConfirmFinancialVoid.GetVoidType() = 0 then // Unapply entry - if UnApplyCustInvoices(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()) then + if VoidType = 0 then // Unapply entry + if UnApplyCustInvoices(CheckLedgEntry, VoidDate) then GenJnlLine2."Applies-to ID" := CheckLedgEntry."Document No."; CustLedgEntry.SetCurrentKey("Transaction No."); CustLedgEntry.SetRange("Transaction No.", BankAccLedgEntry2."Transaction No."); @@ -313,8 +338,8 @@ codeunit 367 CheckManagement end; CheckLedgEntry."Bal. Account Type"::Vendor: begin - if ConfirmFinancialVoid.GetVoidType() = 0 then // Unapply entry - if UnApplyVendInvoices(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()) then + if VoidType = 0 then // Unapply entry + if UnApplyVendInvoices(CheckLedgEntry, VoidDate) then GenJnlLine2."Applies-to ID" := CheckLedgEntry."Document No."; VendorLedgEntry.SetCurrentKey("Transaction No."); VendorLedgEntry.SetRange("Transaction No.", BankAccLedgEntry2."Transaction No."); @@ -394,8 +419,8 @@ codeunit 367 CheckManagement end; CheckLedgEntry."Bal. Account Type"::Employee: begin - if ConfirmFinancialVoid.GetVoidType() = 0 then // Unapply entry - if UnApplyEmpInvoices(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()) then + if VoidType = 0 then // Unapply entry + if UnApplyEmpInvoices(CheckLedgEntry, VoidDate) then GenJnlLine2."Applies-to ID" := CheckLedgEntry."Document No."; EmployeeLedgerEntry.SetCurrentKey("Transaction No."); EmployeeLedgerEntry.SetRange("Transaction No.", BankAccLedgEntry2."Transaction No."); @@ -429,23 +454,6 @@ codeunit 367 CheckManagement OnFinancialVoidCheckOnAfterPostBalAccLine(GenJnlLine2, CheckLedgEntry, GenJnlPostLine); end; end; - - if ConfirmFinancialVoid.GetVoidDate() = CheckLedgEntry."Check Date" then begin - BankAccLedgEntry2.Open := false; - BankAccLedgEntry2."Remaining Amount" := 0; - BankAccLedgEntry2."Statement Status" := BankAccLedgEntry2."Statement Status"::Closed; - BankAccLedgEntry2.Modify(); - end; - - // rounding error from currency conversion - if CheckAmountLCY + BalanceAmountLCY <> 0 then - PostRoundingAmount(BankAcc, CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate(), -(CheckAmountLCY + BalanceAmountLCY)); - - MarkCheckEntriesVoid(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()); - Commit(); - UpdateAnalysisView.UpdateAll(0, true); - - OnAfterFinancialVoidCheck(CheckLedgEntry); end; procedure GenJournalLineGetSystemIdFromRecordId(GenJournalLineRecordId: RecordId): Guid @@ -1216,6 +1224,23 @@ codeunit 367 CheckManagement begin end; + /// + /// Integration event raised before posting the balance account entries during a financial void operation. + /// Enables subscribers to replace the standard balance account type posting. + /// + /// General journal line for the void operation + /// Check ledger entry being voided + /// Bank account ledger entry associated with the check + /// Running balancing amount in LCY. A subscriber that sets IsHandled must add the LCY amounts it posts so the caller's currency-rounding calculation stays balanced. + /// Set to true to skip the standard balance account type posting + /// + /// Raised from FinancialVoidCheck procedure after OnFinancialVoidCheckOnBeforeCheckBalAccountType and before the balance account type posting. + /// + [IntegrationEvent(false, false)] + local procedure OnFinancialVoidCheckOnBeforePostBalanceAccount(var GenJournalLine: Record "Gen. Journal Line"; var CheckLedgerEntry: Record "Check Ledger Entry"; var BankAccountLedgerEntry: Record "Bank Account Ledger Entry"; var BalanceAmountLCY: Decimal; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised before posting bank account entries during financial void operation. /// Enables custom processing or validation before bank account ledger entries are posted. diff --git a/src/Layers/NA/BaseApp/Bank/Check/CheckManagement.Codeunit.al b/src/Layers/NA/BaseApp/Bank/Check/CheckManagement.Codeunit.al index 63920f33f0..0eac22b05b 100644 --- a/src/Layers/NA/BaseApp/Bank/Check/CheckManagement.Codeunit.al +++ b/src/Layers/NA/BaseApp/Bank/Check/CheckManagement.Codeunit.al @@ -260,13 +260,38 @@ codeunit 367 CheckManagement GenJnlLine2.Validate("Currency Code", BankAcc."Currency Code"); GenJnlLine2."Allow Zero-Amount Posting" := true; OnFinancialVoidCheckOnBeforeCheckBalAccountType(GenJnlLine2, CheckLedgEntry, BankAccLedgEntry3); + IsHandled := false; + OnFinancialVoidCheckOnBeforePostBalanceAccount(GenJnlLine2, CheckLedgEntry, BankAccLedgEntry3, BalanceAmountLCY, IsHandled); + if not IsHandled then + FinancialVoidPostBalanceAccount(CheckLedgEntry, ConfirmFinancialVoid.GetVoidType(), ConfirmFinancialVoid.GetVoidDate(), BalanceAmountLCY); + + if ConfirmFinancialVoid.GetVoidDate() = CheckLedgEntry."Check Date" then begin + BankAccLedgEntry2.Open := false; + BankAccLedgEntry2."Remaining Amount" := 0; + BankAccLedgEntry2."Statement Status" := BankAccLedgEntry2."Statement Status"::Closed; + BankAccLedgEntry2.Modify(); + end; + + // rounding error from currency conversion + if CheckAmountLCY + BalanceAmountLCY <> 0 then + PostRoundingAmount(BankAcc, CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate(), -(CheckAmountLCY + BalanceAmountLCY)); + + MarkCheckEntriesVoid(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()); + Commit(); + UpdateAnalysisView.UpdateAll(0, true); + + OnAfterFinancialVoidCheck(CheckLedgEntry); + end; + + local procedure FinancialVoidPostBalanceAccount(var CheckLedgEntry: Record "Check Ledger Entry"; VoidType: Integer; VoidDate: Date; var BalanceAmountLCY: Decimal) + begin case CheckLedgEntry."Bal. Account Type" of CheckLedgEntry."Bal. Account Type"::"G/L Account": FinancialVoidPostGLAccount(GenJnlLine2, BankAccLedgEntry2, CheckLedgEntry, BalanceAmountLCY); CheckLedgEntry."Bal. Account Type"::Customer: begin - if ConfirmFinancialVoid.GetVoidType() = 0 then // Unapply entry - if UnApplyCustInvoices(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()) then + if VoidType = 0 then // Unapply entry + if UnApplyCustInvoices(CheckLedgEntry, VoidDate) then GenJnlLine2."Applies-to ID" := CheckLedgEntry."Document No."; CustLedgEntry.SetCurrentKey(CustLedgEntry."Transaction No."); CustLedgEntry.SetRange(CustLedgEntry."Transaction No.", BankAccLedgEntry2."Transaction No."); @@ -295,8 +320,8 @@ codeunit 367 CheckManagement end; CheckLedgEntry."Bal. Account Type"::Vendor: begin - if ConfirmFinancialVoid.GetVoidType() = 0 then // Unapply entry - if UnApplyVendInvoices(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()) then + if VoidType = 0 then // Unapply entry + if UnApplyVendInvoices(CheckLedgEntry, VoidDate) then GenJnlLine2."Applies-to ID" := CheckLedgEntry."Document No."; VendorLedgEntry.SetCurrentKey(VendorLedgEntry."Transaction No."); VendorLedgEntry.SetRange(VendorLedgEntry."Transaction No.", BankAccLedgEntry2."Transaction No."); @@ -371,8 +396,8 @@ codeunit 367 CheckManagement end; CheckLedgEntry."Bal. Account Type"::Employee: begin - if ConfirmFinancialVoid.GetVoidType() = 0 then // Unapply entry - if UnApplyEmpInvoices(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()) then + if VoidType = 0 then // Unapply entry + if UnApplyEmpInvoices(CheckLedgEntry, VoidDate) then GenJnlLine2."Applies-to ID" := CheckLedgEntry."Document No."; EmployeeLedgerEntry.SetCurrentKey("Transaction No."); EmployeeLedgerEntry.SetRange("Transaction No.", BankAccLedgEntry2."Transaction No."); @@ -406,23 +431,6 @@ codeunit 367 CheckManagement OnFinancialVoidCheckOnAfterPostBalAccLine(GenJnlLine2, CheckLedgEntry, GenJnlPostLine); end; end; - - if ConfirmFinancialVoid.GetVoidDate() = CheckLedgEntry."Check Date" then begin - BankAccLedgEntry2.Open := false; - BankAccLedgEntry2."Remaining Amount" := 0; - BankAccLedgEntry2."Statement Status" := BankAccLedgEntry2."Statement Status"::Closed; - BankAccLedgEntry2.Modify(); - end; - - // rounding error from currency conversion - if CheckAmountLCY + BalanceAmountLCY <> 0 then - PostRoundingAmount(BankAcc, CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate(), -(CheckAmountLCY + BalanceAmountLCY)); - - MarkCheckEntriesVoid(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()); - Commit(); - UpdateAnalysisView.UpdateAll(0, true); - - OnAfterFinancialVoidCheck(CheckLedgEntry); end; procedure GenJournalLineGetSystemIdFromRecordId(GenJournalLineRecordId: RecordId): Guid @@ -1189,6 +1197,23 @@ codeunit 367 CheckManagement begin end; + /// + /// Integration event raised before posting the balance account entries during a financial void operation. + /// Enables subscribers to replace the standard balance account type posting. + /// + /// General journal line for the void operation + /// Check ledger entry being voided + /// Bank account ledger entry associated with the check + /// Running balancing amount in LCY. A subscriber that sets IsHandled must add the LCY amounts it posts so the caller's currency-rounding calculation stays balanced. + /// Set to true to skip the standard balance account type posting + /// + /// Raised from FinancialVoidCheck procedure after OnFinancialVoidCheckOnBeforeCheckBalAccountType and before the balance account type posting. + /// + [IntegrationEvent(false, false)] + local procedure OnFinancialVoidCheckOnBeforePostBalanceAccount(var GenJournalLine: Record "Gen. Journal Line"; var CheckLedgerEntry: Record "Check Ledger Entry"; var BankAccountLedgerEntry: Record "Bank Account Ledger Entry"; var BalanceAmountLCY: Decimal; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised before posting bank account entries during financial void operation. /// Enables custom processing or validation before bank account ledger entries are posted. diff --git a/src/Layers/RU/BaseApp/Bank/Check/CheckManagement.Codeunit.al b/src/Layers/RU/BaseApp/Bank/Check/CheckManagement.Codeunit.al index 61c8365317..910a6ecb83 100644 --- a/src/Layers/RU/BaseApp/Bank/Check/CheckManagement.Codeunit.al +++ b/src/Layers/RU/BaseApp/Bank/Check/CheckManagement.Codeunit.al @@ -266,13 +266,38 @@ codeunit 367 CheckManagement GenJnlLine2."Allow Zero-Amount Posting" := true; CheckUnpostedVendor(CheckLedgEntry, GenJnlLine2); OnFinancialVoidCheckOnBeforeCheckBalAccountType(GenJnlLine2, CheckLedgEntry, BankAccLedgEntry3); + IsHandled := false; + OnFinancialVoidCheckOnBeforePostBalanceAccount(GenJnlLine2, CheckLedgEntry, BankAccLedgEntry3, BalanceAmountLCY, IsHandled); + if not IsHandled then + FinancialVoidPostBalanceAccount(CheckLedgEntry, ConfirmFinancialVoid.GetVoidType(), ConfirmFinancialVoid.GetVoidDate(), BalanceAmountLCY); + + if ConfirmFinancialVoid.GetVoidDate() = CheckLedgEntry."Check Date" then begin + BankAccLedgEntry2.Open := false; + BankAccLedgEntry2."Remaining Amount" := 0; + BankAccLedgEntry2."Statement Status" := BankAccLedgEntry2."Statement Status"::Closed; + BankAccLedgEntry2.Modify(); + end; + + // rounding error from currency conversion + if CheckAmountLCY + BalanceAmountLCY <> 0 then + PostRoundingAmount(BankAcc, CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate(), -(CheckAmountLCY + BalanceAmountLCY)); + + MarkCheckEntriesVoid(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()); + Commit(); + UpdateAnalysisView.UpdateAll(0, true); + + OnAfterFinancialVoidCheck(CheckLedgEntry); + end; + + local procedure FinancialVoidPostBalanceAccount(var CheckLedgEntry: Record "Check Ledger Entry"; VoidType: Integer; VoidDate: Date; var BalanceAmountLCY: Decimal) + begin case CheckLedgEntry."Bal. Account Type" of CheckLedgEntry."Bal. Account Type"::"G/L Account": FinancialVoidPostGLAccount(GenJnlLine2, BankAccLedgEntry2, CheckLedgEntry, BalanceAmountLCY); CheckLedgEntry."Bal. Account Type"::Customer: begin - if ConfirmFinancialVoid.GetVoidType() = 0 then // Unapply entry - if UnApplyCustInvoices(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()) then + if VoidType = 0 then // Unapply entry + if UnApplyCustInvoices(CheckLedgEntry, VoidDate) then GenJnlLine2."Applies-to ID" := CheckLedgEntry."Document No."; CustLedgEntry.SetCurrentKey("Transaction No."); CustLedgEntry.SetRange("Transaction No.", BankAccLedgEntry2."Transaction No."); @@ -300,8 +325,8 @@ codeunit 367 CheckManagement end; CheckLedgEntry."Bal. Account Type"::Vendor: begin - if ConfirmFinancialVoid.GetVoidType() = 0 then // Unapply entry - if UnApplyVendInvoices(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()) then + if VoidType = 0 then // Unapply entry + if UnApplyVendInvoices(CheckLedgEntry, VoidDate) then GenJnlLine2."Applies-to ID" := CheckLedgEntry."Document No."; VendorLedgEntry.SetCurrentKey("Transaction No."); VendorLedgEntry.SetRange("Transaction No.", BankAccLedgEntry2."Transaction No."); @@ -379,8 +404,8 @@ codeunit 367 CheckManagement end; CheckLedgEntry."Bal. Account Type"::Employee: begin - if ConfirmFinancialVoid.GetVoidType() = 0 then // Unapply entry - if UnApplyEmpInvoices(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()) then + if VoidType = 0 then // Unapply entry + if UnApplyEmpInvoices(CheckLedgEntry, VoidDate) then GenJnlLine2."Applies-to ID" := CheckLedgEntry."Document No."; EmployeeLedgerEntry.SetCurrentKey("Transaction No."); EmployeeLedgerEntry.SetRange("Transaction No.", BankAccLedgEntry2."Transaction No."); @@ -414,23 +439,6 @@ codeunit 367 CheckManagement OnFinancialVoidCheckOnAfterPostBalAccLine(GenJnlLine2, CheckLedgEntry, GenJnlPostLine); end; end; - - if ConfirmFinancialVoid.GetVoidDate() = CheckLedgEntry."Check Date" then begin - BankAccLedgEntry2.Open := false; - BankAccLedgEntry2."Remaining Amount" := 0; - BankAccLedgEntry2."Statement Status" := BankAccLedgEntry2."Statement Status"::Closed; - BankAccLedgEntry2.Modify(); - end; - - // rounding error from currency conversion - if CheckAmountLCY + BalanceAmountLCY <> 0 then - PostRoundingAmount(BankAcc, CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate(), -(CheckAmountLCY + BalanceAmountLCY)); - - MarkCheckEntriesVoid(CheckLedgEntry, ConfirmFinancialVoid.GetVoidDate()); - Commit(); - UpdateAnalysisView.UpdateAll(0, true); - - OnAfterFinancialVoidCheck(CheckLedgEntry); end; procedure GenJournalLineGetSystemIdFromRecordId(GenJournalLineRecordId: RecordId): Guid @@ -1257,6 +1265,23 @@ codeunit 367 CheckManagement begin end; + /// + /// Integration event raised before posting the balance account entries during a financial void operation. + /// Enables subscribers to replace the standard balance account type posting. + /// + /// General journal line for the void operation + /// Check ledger entry being voided + /// Bank account ledger entry associated with the check + /// Running balancing amount in LCY. A subscriber that sets IsHandled must add the LCY amounts it posts so the caller's currency-rounding calculation stays balanced. + /// Set to true to skip the standard balance account type posting + /// + /// Raised from FinancialVoidCheck procedure after OnFinancialVoidCheckOnBeforeCheckBalAccountType and before the balance account type posting. + /// + [IntegrationEvent(false, false)] + local procedure OnFinancialVoidCheckOnBeforePostBalanceAccount(var GenJournalLine: Record "Gen. Journal Line"; var CheckLedgerEntry: Record "Check Ledger Entry"; var BankAccountLedgerEntry: Record "Bank Account Ledger Entry"; var BalanceAmountLCY: Decimal; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised before posting bank account entries during financial void operation. /// Enables custom processing or validation before bank account ledger entries are posted.