mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-10-05 06:36:55 +01:00
Add source-verified Finance knowledge and review domain (#57)
Some checks failed
Validate knowledge index / validate-index (push) Has been cancelled
Validate AL review fixtures / validate-review-fixtures (push) Has been cancelled
Validate skill index and report schemas / validate-contract (push) Has been cancelled
Validate frontmatter and structure / validate (push) Has been cancelled
Some checks failed
Validate knowledge index / validate-index (push) Has been cancelled
Validate AL review fixtures / validate-review-fixtures (push) Has been cancelled
Validate skill index and report schemas / validate-contract (push) Has been cancelled
Validate frontmatter and structure / validate (push) Has been cancelled
* Add Finance posting domain-knowledge pilot Adds three atomic domain-rule knowledge files under community/knowledge/finance/ as a pilot for Type-A (normative) Business Central domain knowledge: post through the posting engine, treat posted ledger entries as immutable, and treat the Dimension Set ID as the source of truth for dimensions. Includes a good/bad AL sample pair for the posting rule. These encode BC-specific invariants that LLMs reliably get wrong, fitting the existing remedial/atomic knowledge grain with no schema or contract changes. Passes the repo frontmatter validator and is discovered by the knowledge index. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Clarify editable operational fields on posted ledger entries Addresses review feedback from @JeremyVyska on PR #57: the immutability rule applies to financial content, not the whole entry. Reframes the Description around financial content and gives the operational-field exception (payment/application data, on-hold, applies-to, communication fields edited via CustEntry-Edit/VendEntry-Edit and the ledger entry pages) its own paragraph in Best Practice instead of understating it as a narrow set. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Expand Finance pilot into a source-verified review domain Move Finance knowledge to the Microsoft-owned layer, add nine scoped rules with eighteen AL samples, and register bounded Finance review with complete paired evaluation coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Fix Finance review applicability and ownership boundaries Remove application-area gating and later VAT-field dependencies, align dynamic shared conventions, separate SCM ownership, and keep journal examples focused on the intended invariant. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Remove logo branding (#194) Co-authored-by: Jesper Schulz-Wedde <jesper.schulzwedde@microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Add title and description to README * Add foundational AL developer knowledge (#195) Co-authored-by: Jesper Schulz-Wedde <jesper.schulzwedde@microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Clarify locale-safe DateFormula Evaluate inputs (#193) * Clarify locale-safe DateFormula Evaluate inputs Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Normalize DateFormula article sections Keep the analyzer-gap explanation in Description and its scoped probe evidence in References, without a novel Validation section. Normative guidance and fixtures are unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Jesper Schulz-Wedde <jesper.schulzwedde@microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Add SCM functional knowledge domain (#192) * Add SCM functional knowledge domain Introduce nine source-backed rules with original AL sample pairs, bounded SCM review routing, and complete positive/clean evaluation coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Normalize SCM knowledge and review ownership Align article and AL sample conventions, keep BC facts separate from review mechanics, and clarify reciprocal Finance ownership without bespoke shared test assertions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Jesper Schulz-Wedde <jesper.schulzwedde@microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Jesper Schulz-Wedde <jesper.schulzwedde@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
bec8890b7e
commit
07e324ddbc
33 changed files with 1084 additions and 1 deletions
|
|
@ -0,0 +1,33 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50104 "Customer Settlement Actions"
|
||||
{
|
||||
procedure RequestApplication(CustomerEntryNo: Integer)
|
||||
var
|
||||
CustomerEntry: Record "Cust. Ledger Entry";
|
||||
begin
|
||||
RequireInteractiveSession();
|
||||
CustomerEntry.Get(CustomerEntryNo);
|
||||
CustomerEntry.TestField(Open, true);
|
||||
CustomerEntry.Open := false;
|
||||
CustomerEntry.Modify(true);
|
||||
end;
|
||||
|
||||
procedure RequestUnapplication(CustomerEntryNo: Integer)
|
||||
var
|
||||
DetailedCustomerEntry: Record "Detailed Cust. Ledg. Entry";
|
||||
begin
|
||||
RequireInteractiveSession();
|
||||
DetailedCustomerEntry.SetRange("Cust. Ledger Entry No.", CustomerEntryNo);
|
||||
DetailedCustomerEntry.SetRange("Entry Type", DetailedCustomerEntry."Entry Type"::Application);
|
||||
DetailedCustomerEntry.ModifyAll(Unapplied, true);
|
||||
end;
|
||||
|
||||
local procedure RequireInteractiveSession()
|
||||
begin
|
||||
if not GuiAllowed() then
|
||||
Error(InteractiveSessionErr);
|
||||
end;
|
||||
|
||||
var
|
||||
InteractiveSessionErr: Label 'Request settlement from an interactive session.';
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50104 "Customer Settlement Actions"
|
||||
{
|
||||
procedure RequestApplication(CustomerEntryNo: Integer)
|
||||
var
|
||||
CustomerEntry: Record "Cust. Ledger Entry";
|
||||
CustomerApplication: Codeunit "CustEntry-Apply Posted Entries";
|
||||
begin
|
||||
RequireInteractiveSession();
|
||||
CustomerEntry.Get(CustomerEntryNo);
|
||||
CustomerEntry.TestField(Open, true);
|
||||
CustomerApplication.ApplyCustEntryFormEntry(CustomerEntry);
|
||||
end;
|
||||
|
||||
procedure RequestUnapplication(CustomerEntryNo: Integer)
|
||||
var
|
||||
CustomerApplication: Codeunit "CustEntry-Apply Posted Entries";
|
||||
begin
|
||||
RequireInteractiveSession();
|
||||
CustomerApplication.UnApplyCustLedgEntry(CustomerEntryNo);
|
||||
end;
|
||||
|
||||
local procedure RequireInteractiveSession()
|
||||
begin
|
||||
if not GuiAllowed() then
|
||||
Error(InteractiveSessionErr);
|
||||
end;
|
||||
|
||||
var
|
||||
InteractiveSessionErr: Label 'Request settlement from an interactive session.';
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: finance
|
||||
keywords: [cust-ledger-entry, vendor-ledger-entry, detailed-ledger-entry, remaining-amount, application, unapplication, open, closed-by-entry-no]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# Apply and unapply entries through the application workflow, not status flags
|
||||
|
||||
## Description
|
||||
|
||||
Customer/vendor settlement is a posting operation involving detailed ledger entries, not just a change to `Open` on the main entry. Remaining amounts are calculated from detailed entries. Unapplication posts correcting entries and handles application-derived effects such as discounts and currency gains/losses; deleting details or changing `Unapplied` cannot reproduce that history.
|
||||
|
||||
## Best Practice
|
||||
|
||||
Use `"CustEntry-Apply Posted Entries"` / `"VendEntry-Apply Posted Entries"` and the supported application or unapplication workflow. Let it check application dates, entry state, and application ordering. The `ApplyCustEntryFormEntry` / `ApplyVendEntryFormEntry` and `UnApply...LedgEntry` methods are **interactive**: users select and confirm the operation. They are not unattended "mark paid" APIs.
|
||||
|
||||
For programmatic posting, use the target version's public `Apply` / `PostUnApply...` APIs with properly prepared selection and `Apply Unapply Parameters`; handle cancellation and the workflow's transaction/commit behavior. `"Applying Entry"`, `"Applies-to ID"`, and `"Amount to Apply"` are legitimate application-preparation fields. Do not report their writes alone, temporary buffers, supported posting/compression internals, or unrelated operational/extension fields.
|
||||
|
||||
See sample: [`apply-ledger-entries-through-application-codeunits.good.al`](apply-ledger-entries-through-application-codeunits.good.al).
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
Implement customer/vendor payment matching, settlement, or reopening by directly persisting `Open`, `"Closed by Entry No."`, closure amounts/dates, or detailed-entry unapplication flags, or by deleting/rewriting detailed application amounts. Require confirmed writes to existing non-temporary customer/vendor or detailed customer/vendor entries and settlement intent. Item/inventory application records belong to SCM, not this rule. Do not suggest assigning a `Remaining Amount` FlowField as a fix.
|
||||
|
||||
This article owns fabricated application state. Use the [posted-financial-content rule](do-not-modify-or-delete-posted-ledger-entries.md) for original accounting-value corrections, not a second finding prescribing the same application fix.
|
||||
|
||||
See sample: [`apply-ledger-entries-through-application-codeunits.bad.al`](apply-ledger-entries-through-application-codeunits.bad.al).
|
||||
|
||||
## References
|
||||
|
||||
- [Apply and unapply customer transactions](https://learn.microsoft.com/en-us/dynamics365/business-central/receivables-how-apply-sales-transactions-manually).
|
||||
- [Apply and unapply vendor transactions](https://learn.microsoft.com/en-us/dynamics365/business-central/payables-how-apply-purchase-transactions-manually).
|
||||
- [BCApps: customer application workflow](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/BaseApp/Sales/Receivables/CustEntryApplyPostedEntries.Codeunit.al).
|
||||
- [BCApps: vendor application workflow](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/BaseApp/Purchases/Payables/VendEntryApplyPostedEntries.Codeunit.al).
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50105 "Update Ledger Due Dates"
|
||||
{
|
||||
procedure UpdateCustomerDueDate(EntryNo: Integer; NewDueDate: Date)
|
||||
var
|
||||
CustomerEntry: Record "Cust. Ledger Entry";
|
||||
begin
|
||||
CustomerEntry.Get(EntryNo);
|
||||
CustomerEntry.Validate("Due Date", NewDueDate);
|
||||
CustomerEntry.Modify(true);
|
||||
end;
|
||||
|
||||
procedure UpdateVendorDueDate(EntryNo: Integer; NewDueDate: Date)
|
||||
var
|
||||
VendorEntry: Record "Vendor Ledger Entry";
|
||||
begin
|
||||
VendorEntry.Get(EntryNo);
|
||||
VendorEntry.Validate("Due Date", NewDueDate);
|
||||
VendorEntry.Modify(true);
|
||||
end;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50105 "Update Ledger Due Dates"
|
||||
{
|
||||
procedure UpdateCustomerDueDate(EntryNo: Integer; NewDueDate: Date)
|
||||
var
|
||||
CustomerEntry: Record "Cust. Ledger Entry";
|
||||
begin
|
||||
CustomerEntry.Get(EntryNo);
|
||||
CustomerEntry.Validate("Due Date", NewDueDate);
|
||||
Codeunit.Run(Codeunit::"Cust. Entry-Edit", CustomerEntry);
|
||||
end;
|
||||
|
||||
procedure UpdateVendorDueDate(EntryNo: Integer; NewDueDate: Date)
|
||||
var
|
||||
VendorEntry: Record "Vendor Ledger Entry";
|
||||
begin
|
||||
VendorEntry.Get(EntryNo);
|
||||
VendorEntry.Validate("Due Date", NewDueDate);
|
||||
Codeunit.Run(Codeunit::"Vend. Entry-Edit", VendorEntry);
|
||||
end;
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: finance
|
||||
keywords: [due-date, initial-entry-due-date, cust-entry-edit, vend-entry-edit, detailed-ledger-entry, aging]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# Change posted customer/vendor due dates through the entry-edit workflow
|
||||
|
||||
## Description
|
||||
|
||||
A posted customer or vendor due date is supported editable operational data, but it is also represented by `Initial Entry Due Date` on related detailed ledger entries. Validating `Due Date` and calling `Modify(true)` on the main entry does not perform all synchronization done by `"Cust. Entry-Edit"` or `"Vend. Entry-Edit"`. The main entry and due-date-based analysis can otherwise disagree.
|
||||
|
||||
## Best Practice
|
||||
|
||||
Fetch the existing entry, validate the proposed `Due Date`, and pass the changed record to the corresponding entry-edit codeunit, as the standard ledger pages do. Field validation enforces entry-state rules; the editor persists the supported change and synchronizes related detailed entries. Preserve both steps rather than treating table triggers as equivalent to the edit workflow.
|
||||
|
||||
This is a due-date synchronization rule, not a prohibition on all operational edits after posting. Exclude temporary buffers, extension-only fields, supported editor internals, and code that demonstrably performs the equivalent synchronization under the supported workflow. Check the actual table/routine instead of assuming every `*Entry-Edit` accepts the same fields.
|
||||
|
||||
See sample: [`change-ledger-due-dates-through-entry-edit.good.al`](change-ledger-due-dates-through-entry-edit.good.al).
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
Change `Due Date` on an existing non-temporary `Cust. Ledger Entry` or `Vendor Ledger Entry` and persist it with `Modify`, `Modify(true)`, or `ModifyAll` without the edit workflow or equivalent related-entry update. A preceding `Validate("Due Date", ...)` is not sufficient evidence of synchronization.
|
||||
|
||||
See sample: [`change-ledger-due-dates-through-entry-edit.bad.al`](change-ledger-due-dates-through-entry-edit.bad.al).
|
||||
|
||||
## References
|
||||
|
||||
- [Cust. Entry-Edit API](https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/codeunit/microsoft.sales.receivables.cust.-entry-edit).
|
||||
- [Vend. Entry-Edit API](https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/codeunit/microsoft.purchases.payables.vend.-entry-edit).
|
||||
- [BCApps: customer due-date synchronization](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/BaseApp/Sales/Receivables/CustEntryEdit.Codeunit.al).
|
||||
- [BCApps: vendor due-date synchronization](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/BaseApp/Purchases/Payables/VendEntryEdit.Codeunit.al).
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50103 "Change Journal Dimension"
|
||||
{
|
||||
procedure ChangeExistingDimension(TemplateName: Code[10]; BatchName: Code[10]; LineNo: Integer; DimensionCode: Code[20]; NewValue: Code[20])
|
||||
var
|
||||
JournalLine: Record "Gen. Journal Line";
|
||||
DimensionSetEntry: Record "Dimension Set Entry";
|
||||
begin
|
||||
JournalLine.Get(TemplateName, BatchName, LineNo);
|
||||
DimensionSetEntry.Get(JournalLine."Dimension Set ID", DimensionCode);
|
||||
DimensionSetEntry.Validate("Dimension Value Code", NewValue);
|
||||
DimensionSetEntry.Modify();
|
||||
end;
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50103 "Change Journal Dimension"
|
||||
{
|
||||
procedure ChangeExistingDimension(TemplateName: Code[10]; BatchName: Code[10]; LineNo: Integer; DimensionCode: Code[20]; NewValue: Code[20])
|
||||
var
|
||||
JournalLine: Record "Gen. Journal Line";
|
||||
TempDimensionSetEntry: Record "Dimension Set Entry" temporary;
|
||||
DimensionManagement: Codeunit DimensionManagement;
|
||||
begin
|
||||
JournalLine.Get(TemplateName, BatchName, LineNo);
|
||||
DimensionManagement.GetDimensionSet(TempDimensionSetEntry, JournalLine."Dimension Set ID");
|
||||
TempDimensionSetEntry.Get(JournalLine."Dimension Set ID", DimensionCode);
|
||||
TempDimensionSetEntry.Validate("Dimension Value Code", NewValue);
|
||||
TempDimensionSetEntry.Modify();
|
||||
JournalLine.Validate("Dimension Set ID", DimensionManagement.GetDimensionSetID(TempDimensionSetEntry));
|
||||
JournalLine.Modify(true);
|
||||
end;
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: finance
|
||||
keywords: [dimension-set-entry, dimension-value-id, getdimensionset, getdimensionsetid, posted-dimensions, temporary]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# Change a transaction's dimension set reference, not a shared set's membership
|
||||
|
||||
## Description
|
||||
|
||||
The same `Dimension Set ID` can be referenced by an unposted journal line and by many already-posted entries. Editing or deleting the persisted set's dimension/value rows therefore changes the meaning of unrelated transactions, including posting history. The dimension-set search tree also relies on those combinations remaining stable; a set is not a mutable child collection owned by one journal line.
|
||||
|
||||
## Best Practice
|
||||
|
||||
To change an unposted transaction's dimensions, load its set into a **temporary** `Dimension Set Entry` buffer with `DimensionManagement.GetDimensionSet`, change the buffer, and obtain a reusable ID with `GetDimensionSetID`. Validate dimension values in the buffer so `Dimension Value ID` matches the chosen value. Store the resulting ID on the transaction and synchronize its projections through that record's supported dimension validation.
|
||||
|
||||
For already-posted G/L dimensions, use the supported dimension-correction workflow rather than changing shared rows. Read-only access, temporary buffers, and standard maintenance of projection metadata such as `Global Dimension No.` are not membership changes. This rule protects dimension sets reached from general-journal, financial-document, or Finance-ledger flows. It does not own Item, Value, Capacity, Warehouse, or inventory-application record writes, or prescribe custom-table/default-dimension wiring.
|
||||
|
||||
See sample: [`do-not-edit-shared-dimension-sets.good.al`](do-not-edit-shared-dimension-sets.good.al).
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
Follow a general-journal, financial-document, or Finance-ledger `Dimension Set ID` to a **persistent** `Dimension Set Entry` and modify, rename, or delete its dimension/value membership in order to change that one transaction. Inspect `IsTemporary` guards, aliases, and the fields written before reporting: the same operations on a temporary working copy are expected.
|
||||
|
||||
See sample: [`do-not-edit-shared-dimension-sets.bad.al`](do-not-edit-shared-dimension-sets.bad.al).
|
||||
|
||||
## References
|
||||
|
||||
- [Dimension set entries overview](https://learn.microsoft.com/en-us/dynamics365/business-central/design-details-dimension-set-entries-overview).
|
||||
- [Supported G/L dimension correction](https://learn.microsoft.com/en-us/dynamics365/business-central/finance-troubleshooting-correcting-dimensions).
|
||||
- [DimensionManagement API](https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/codeunit/microsoft.finance.dimension.dimensionmanagement).
|
||||
- [BCApps: Dimension Set Entry and its set-ID resolver](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/BaseApp/Finance/Dimension/DimensionSetEntry.Table.al).
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50101 "Correct Posted Transaction"
|
||||
{
|
||||
procedure RequestTransactionReversal(EntryNo: Integer)
|
||||
var
|
||||
GLEntry: Record "G/L Entry";
|
||||
begin
|
||||
if not GuiAllowed() then
|
||||
Error(InteractiveSessionErr);
|
||||
GLEntry.Get(EntryNo);
|
||||
GLEntry.TestField("Transaction No.");
|
||||
GLEntry.Amount := -GLEntry.Amount;
|
||||
GLEntry.Modify(true);
|
||||
end;
|
||||
|
||||
procedure UpdateDescription(EntryNo: Integer; NewDescription: Text[100])
|
||||
var
|
||||
GLEntry: Record "G/L Entry";
|
||||
begin
|
||||
GLEntry.Get(EntryNo);
|
||||
GLEntry.Description := NewDescription;
|
||||
Codeunit.Run(Codeunit::"G/L Entry-Edit", GLEntry);
|
||||
end;
|
||||
|
||||
procedure ClearSimulation(var TempGLEntry: Record "G/L Entry" temporary)
|
||||
begin
|
||||
TempGLEntry.DeleteAll();
|
||||
end;
|
||||
|
||||
var
|
||||
InteractiveSessionErr: Label 'Request the reversal from an interactive session.';
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50101 "Correct Posted Transaction"
|
||||
{
|
||||
procedure RequestTransactionReversal(EntryNo: Integer)
|
||||
var
|
||||
GLEntry: Record "G/L Entry";
|
||||
ReversalEntry: Record "Reversal Entry";
|
||||
begin
|
||||
if not GuiAllowed() then
|
||||
Error(InteractiveSessionErr);
|
||||
GLEntry.Get(EntryNo);
|
||||
GLEntry.TestField("Transaction No.");
|
||||
ReversalEntry.ReverseTransaction(GLEntry."Transaction No.");
|
||||
end;
|
||||
|
||||
procedure UpdateDescription(EntryNo: Integer; NewDescription: Text[100])
|
||||
var
|
||||
GLEntry: Record "G/L Entry";
|
||||
begin
|
||||
GLEntry.Get(EntryNo);
|
||||
GLEntry.Description := NewDescription;
|
||||
Codeunit.Run(Codeunit::"G/L Entry-Edit", GLEntry);
|
||||
end;
|
||||
|
||||
procedure ClearSimulation(var TempGLEntry: Record "G/L Entry" temporary)
|
||||
begin
|
||||
TempGLEntry.DeleteAll();
|
||||
end;
|
||||
|
||||
var
|
||||
InteractiveSessionErr: Label 'Request the reversal from an interactive session.';
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: finance
|
||||
keywords: [g-l-entry, ledger-entry, reversal, audit-trail, correction, financial-content, entry-edit]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# Correct posted financial content through posting workflows, not row surgery
|
||||
|
||||
## Description
|
||||
|
||||
Changing a posted entry's original amount, account, posting date, or tax amounts in place does not correct the related ledger, register, or source document. Deleting one erroneous row has the same problem. Business Central provides reversing and correcting posting workflows that retain the relationship between the original transaction and its correction; this is not a blanket prohibition on every write to a posted table.
|
||||
|
||||
## Best Practice
|
||||
|
||||
Use a supported transaction/register reversal, credit memo, or correcting journal appropriate to the original posting and its current state. Request the standard reversal workflow rather than negating a single row or setting `Reversed` yourself. Let that workflow enforce eligibility; do not change source or application fields to make a rejected reversal pass.
|
||||
|
||||
Supported operational edits are deliberate exceptions: for example, `"G/L Entry-Edit"` supports description changes, and `"Cust. Entry-Edit"` / `"Vend. Entry-Edit"` handle their table-specific editable fields. [Due-date synchronization](change-ledger-due-dates-through-entry-edit.md), [application/unapplication](apply-ledger-entries-through-application-codeunits.md), G/L dimension correction, and supported date compression have their own workflows. Do not flag their standard implementations, temporary simulation buffers, or extension-only metadata updates as financial row surgery. A subscriber is not exempt merely because it runs inside a supported workflow: inspect the fields it actually changes.
|
||||
|
||||
This rule covers G/L, customer/vendor/detailed, VAT, and financial-posting/register records. Item, Value, Capacity, Warehouse, inventory-application, and other inventory-posting records are SCM concerns. The financial-row leg of one inventory-posting bypass is outside this rule when the same inventory correction resolves it; an independently actionable financial defect remains in scope regardless of the containing module's name.
|
||||
|
||||
See sample: [`do-not-modify-or-delete-posted-ledger-entries.good.al`](do-not-modify-or-delete-posted-ledger-entries.good.al).
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
Persist a change to original financial content, delete posted rows, or fabricate reversal flags/links to repair or undo a transaction outside the supported correction/maintenance workflow. Require an existing, non-temporary Finance-owned record and evidence of the fields or rows affected; a `Modify` token or `*Ledger Entry` name alone is insufficient. Settlement-state writes belong to the application article rather than a duplicate finding here.
|
||||
|
||||
See sample: [`do-not-modify-or-delete-posted-ledger-entries.bad.al`](do-not-modify-or-delete-posted-ledger-entries.bad.al).
|
||||
|
||||
## References
|
||||
|
||||
- [Reverse journal postings](https://learn.microsoft.com/en-us/dynamics365/business-central/finance-how-reverse-journal-posting).
|
||||
- [Correct G/L dimensions](https://learn.microsoft.com/en-us/dynamics365/business-central/finance-troubleshooting-correcting-dimensions).
|
||||
- [BCApps: G/L Entry-Edit](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/BaseApp/Finance/GeneralLedger/Ledger/GLEntryEdit.Codeunit.al).
|
||||
- [BCApps: supported customer-ledger date compression](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/BaseApp/Sales/Receivables/DateCompressCustomerLedger.Report.al).
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50108 "Import Purchase Journal Total"
|
||||
{
|
||||
procedure ImportExampleTotal(TemplateName: Code[10]; BatchName: Code[10]; LineNo: Integer)
|
||||
var
|
||||
JournalLine: Record "Gen. Journal Line";
|
||||
VATPostingSetup: Record "VAT Posting Setup";
|
||||
GeneralLedgerSetup: Record "General Ledger Setup";
|
||||
SourceInvoice: JsonObject;
|
||||
NetToken: JsonToken;
|
||||
VATToken: JsonToken;
|
||||
GrossToken: JsonToken;
|
||||
ImportedNet: Decimal;
|
||||
ImportedVAT: Decimal;
|
||||
ImportedGross: Decimal;
|
||||
begin
|
||||
SourceInvoice.ReadFrom('{"netAmount":100,"vatAmount":25,"grossAmount":125}');
|
||||
SourceInvoice.Get('netAmount', NetToken);
|
||||
SourceInvoice.Get('vatAmount', VATToken);
|
||||
SourceInvoice.Get('grossAmount', GrossToken);
|
||||
ImportedNet := NetToken.AsValue().AsDecimal();
|
||||
ImportedVAT := VATToken.AsValue().AsDecimal();
|
||||
ImportedGross := GrossToken.AsValue().AsDecimal();
|
||||
if ImportedGross <> ImportedNet + ImportedVAT then
|
||||
Error(TotalsErr);
|
||||
|
||||
JournalLine.Get(TemplateName, BatchName, LineNo);
|
||||
JournalLine.TestField("Account Type", JournalLine."Account Type"::"G/L Account");
|
||||
JournalLine.TestField("Bal. Account Type", JournalLine."Bal. Account Type"::"G/L Account");
|
||||
JournalLine.TestField("Account No.");
|
||||
JournalLine.TestField("Bal. Account No.");
|
||||
JournalLine.TestField("Currency Code", '');
|
||||
JournalLine.TestField("Gen. Posting Type", JournalLine."Gen. Posting Type"::Purchase);
|
||||
JournalLine.TestField("VAT Posting", JournalLine."VAT Posting"::"Automatic VAT Entry");
|
||||
JournalLine.TestField("VAT Calculation Type", JournalLine."VAT Calculation Type"::"Normal VAT");
|
||||
JournalLine.TestField("VAT %", 25);
|
||||
JournalLine.TestField("VAT Difference", 0);
|
||||
JournalLine.TestField("Bal. Gen. Posting Type", JournalLine."Bal. Gen. Posting Type"::" ");
|
||||
JournalLine.TestField("Bal. VAT %", 0);
|
||||
VATPostingSetup.Get(JournalLine."VAT Bus. Posting Group", JournalLine."VAT Prod. Posting Group");
|
||||
VATPostingSetup.TestField("VAT Calculation Type", VATPostingSetup."VAT Calculation Type"::"Normal VAT");
|
||||
VATPostingSetup.TestField("VAT %", 25);
|
||||
VATPostingSetup.TestField("Unrealized VAT Type", VATPostingSetup."Unrealized VAT Type"::" ");
|
||||
GeneralLedgerSetup.Get();
|
||||
GeneralLedgerSetup.TestField("Additional Reporting Currency", '');
|
||||
GeneralLedgerSetup.TestField("Amount Rounding Precision", 0.01);
|
||||
|
||||
JournalLine.Validate(Amount, ImportedNet);
|
||||
JournalLine.Modify(true);
|
||||
end;
|
||||
|
||||
var
|
||||
TotalsErr: Label 'The invoice total must equal its net amount plus VAT.';
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50108 "Import Purchase Journal Total"
|
||||
{
|
||||
procedure ImportExampleTotal(TemplateName: Code[10]; BatchName: Code[10]; LineNo: Integer)
|
||||
var
|
||||
JournalLine: Record "Gen. Journal Line";
|
||||
VATPostingSetup: Record "VAT Posting Setup";
|
||||
GeneralLedgerSetup: Record "General Ledger Setup";
|
||||
SourceInvoice: JsonObject;
|
||||
NetToken: JsonToken;
|
||||
VATToken: JsonToken;
|
||||
GrossToken: JsonToken;
|
||||
ImportedNet: Decimal;
|
||||
ImportedVAT: Decimal;
|
||||
ImportedGross: Decimal;
|
||||
begin
|
||||
SourceInvoice.ReadFrom('{"netAmount":100,"vatAmount":25,"grossAmount":125}');
|
||||
SourceInvoice.Get('netAmount', NetToken);
|
||||
SourceInvoice.Get('vatAmount', VATToken);
|
||||
SourceInvoice.Get('grossAmount', GrossToken);
|
||||
ImportedNet := NetToken.AsValue().AsDecimal();
|
||||
ImportedVAT := VATToken.AsValue().AsDecimal();
|
||||
ImportedGross := GrossToken.AsValue().AsDecimal();
|
||||
if ImportedGross <> ImportedNet + ImportedVAT then
|
||||
Error(TotalsErr);
|
||||
|
||||
JournalLine.Get(TemplateName, BatchName, LineNo);
|
||||
JournalLine.TestField("Account Type", JournalLine."Account Type"::"G/L Account");
|
||||
JournalLine.TestField("Bal. Account Type", JournalLine."Bal. Account Type"::"G/L Account");
|
||||
JournalLine.TestField("Account No.");
|
||||
JournalLine.TestField("Bal. Account No.");
|
||||
JournalLine.TestField("Currency Code", '');
|
||||
JournalLine.TestField("Gen. Posting Type", JournalLine."Gen. Posting Type"::Purchase);
|
||||
JournalLine.TestField("VAT Posting", JournalLine."VAT Posting"::"Automatic VAT Entry");
|
||||
JournalLine.TestField("VAT Calculation Type", JournalLine."VAT Calculation Type"::"Normal VAT");
|
||||
JournalLine.TestField("VAT %", 25);
|
||||
JournalLine.TestField("VAT Difference", 0);
|
||||
JournalLine.TestField("Bal. Gen. Posting Type", JournalLine."Bal. Gen. Posting Type"::" ");
|
||||
JournalLine.TestField("Bal. VAT %", 0);
|
||||
VATPostingSetup.Get(JournalLine."VAT Bus. Posting Group", JournalLine."VAT Prod. Posting Group");
|
||||
VATPostingSetup.TestField("VAT Calculation Type", VATPostingSetup."VAT Calculation Type"::"Normal VAT");
|
||||
VATPostingSetup.TestField("VAT %", 25);
|
||||
VATPostingSetup.TestField("Unrealized VAT Type", VATPostingSetup."Unrealized VAT Type"::" ");
|
||||
GeneralLedgerSetup.Get();
|
||||
GeneralLedgerSetup.TestField("Additional Reporting Currency", '');
|
||||
GeneralLedgerSetup.TestField("Amount Rounding Precision", 0.01);
|
||||
|
||||
JournalLine.Validate(Amount, ImportedGross);
|
||||
JournalLine.Modify(true);
|
||||
end;
|
||||
|
||||
var
|
||||
TotalsErr: Label 'The invoice total must equal its net amount plus VAT.';
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: finance
|
||||
keywords: [normal-vat, automatic-vat-entry, gross-amount, net-amount, vat-posting-setup, gen-journal-line, purchase]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# Supply a VAT-inclusive journal Amount for automatic Normal VAT
|
||||
|
||||
## Description
|
||||
|
||||
For a general-journal line using **Automatic VAT Entry** and **Normal VAT**, `Amount` includes VAT. The posting engine extracts tax from that total; it does not add tax to a VAT-exclusive expense imported into `Amount`. An LCY invoice with net 100 and VAT 25 therefore needs a journal total of 125, not 100.
|
||||
|
||||
## Best Practice
|
||||
|
||||
Map the source's VAT-inclusive total to journal `Amount` in this posting mode. Establish the intended account and posting-group combination before validating the final amount. Account-derived VAT defaults depend on `Copy VAT Setup to Jnl. Lines`; do not assume account selection always supplies the intended configuration.
|
||||
|
||||
Require the actual input contract and calculation mode, not just a variable named `NetAmount`. The examples encode source net, VAT, and gross values plus a 25% Normal-VAT setup check. They target an LCY G/L purchase with 0.01 amount rounding and without balancing-side VAT, additional reporting currency, VAT differences, or unrealized VAT. Other calculation types, Manual VAT Entry, reverse charge, Full VAT, sales/use tax, unrealized tax, and other currency/rounding contexts need their own analysis; this is not a universal gross-up formula or country-specific tax advice.
|
||||
|
||||
The concern is the supplied transaction total, not its deductible/non-deductible allocation. Non-deductible VAT features can change the allocation of that total, not turn the source's net amount into its gross amount. Do not infer a particular expense or deductible-VAT split from this rule. The samples therefore do not depend on later-version non-deductible-VAT fields.
|
||||
|
||||
See sample: [`normal-vat-journal-amount-includes-vat.good.al`](normal-vat-journal-amount-includes-vat.good.al).
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
In the demonstrated automatic Normal-VAT configuration, put a provably VAT-exclusive source amount into journal `Amount` while expecting posting to add tax. An amount assignment alone, unknown setup, or a suggestive variable name is insufficient. Do not report the correctly supplied gross amount or automatically rewrite tax calculations outside this scope.
|
||||
|
||||
See sample: [`normal-vat-journal-amount-includes-vat.bad.al`](normal-vat-journal-amount-includes-vat.bad.al).
|
||||
|
||||
## References
|
||||
|
||||
- [VAT posting setup combinations](https://learn.microsoft.com/en-us/dynamics365/business-central/finance-setup-vat#combine-vat-posting-groups-in-vat-posting-setups).
|
||||
- [BCApps: journal amount validation](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al).
|
||||
- [BCApps: Normal VAT extraction during posting](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al).
|
||||
- [BCApps: journal VAT amount regression cases](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/Tests/VAT/ERMVATOnGenJournalLine.Codeunit.al).
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50100 "Post Transfer Journal"
|
||||
{
|
||||
procedure PostTransferBatch(TemplateName: Code[10]; BatchName: Code[10])
|
||||
var
|
||||
JournalLine: Record "Gen. Journal Line";
|
||||
LastGLEntry: Record "G/L Entry";
|
||||
NextEntryNo: Integer;
|
||||
begin
|
||||
JournalLine.SetRange("Journal Template Name", TemplateName);
|
||||
JournalLine.SetRange("Journal Batch Name", BatchName);
|
||||
if JournalLine.Count() <> 1 then
|
||||
Error(SingleTransferErr);
|
||||
JournalLine.FindFirst();
|
||||
JournalLine.TestField("Account Type", JournalLine."Account Type"::"G/L Account");
|
||||
JournalLine.TestField("Bal. Account Type", JournalLine."Bal. Account Type"::"G/L Account");
|
||||
JournalLine.TestField("Account No.");
|
||||
JournalLine.TestField("Bal. Account No.");
|
||||
JournalLine.TestField("Posting Date");
|
||||
JournalLine.TestField("Document No.");
|
||||
JournalLine.TestField(Amount);
|
||||
JournalLine.TestField("Currency Code", '');
|
||||
JournalLine.TestField("Gen. Posting Type", JournalLine."Gen. Posting Type"::" ");
|
||||
JournalLine.TestField("Bal. Gen. Posting Type", JournalLine."Bal. Gen. Posting Type"::" ");
|
||||
|
||||
LastGLEntry.LockTable();
|
||||
if LastGLEntry.FindLast() then
|
||||
NextEntryNo := LastGLEntry."Entry No." + 1
|
||||
else
|
||||
NextEntryNo := 1;
|
||||
InsertLedgerRow(JournalLine, NextEntryNo, JournalLine."Account No.", JournalLine.Amount);
|
||||
InsertLedgerRow(JournalLine, NextEntryNo + 1, JournalLine."Bal. Account No.", -JournalLine.Amount);
|
||||
end;
|
||||
|
||||
local procedure InsertLedgerRow(JournalLine: Record "Gen. Journal Line"; EntryNo: Integer; AccountNo: Code[20]; Amount: Decimal)
|
||||
var
|
||||
GLEntry: Record "G/L Entry";
|
||||
begin
|
||||
GLEntry.Init();
|
||||
GLEntry."Entry No." := EntryNo;
|
||||
GLEntry."G/L Account No." := AccountNo;
|
||||
GLEntry."Posting Date" := JournalLine."Posting Date";
|
||||
GLEntry."Document Type" := JournalLine."Document Type";
|
||||
GLEntry."Document No." := JournalLine."Document No.";
|
||||
GLEntry."Source Code" := JournalLine."Source Code";
|
||||
GLEntry."Journal Batch Name" := JournalLine."Journal Batch Name";
|
||||
GLEntry."Dimension Set ID" := JournalLine."Dimension Set ID";
|
||||
GLEntry."Global Dimension 1 Code" := JournalLine."Shortcut Dimension 1 Code";
|
||||
GLEntry."Global Dimension 2 Code" := JournalLine."Shortcut Dimension 2 Code";
|
||||
GLEntry.Amount := Amount;
|
||||
if Amount > 0 then
|
||||
GLEntry."Debit Amount" := Amount
|
||||
else
|
||||
GLEntry."Credit Amount" := -Amount;
|
||||
GLEntry.Insert(true);
|
||||
end;
|
||||
|
||||
var
|
||||
SingleTransferErr: Label 'Use a journal batch containing exactly one self-balancing G/L transfer.';
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50100 "Post Transfer Journal"
|
||||
{
|
||||
procedure PostTransferBatch(TemplateName: Code[10]; BatchName: Code[10])
|
||||
var
|
||||
JournalLine: Record "Gen. Journal Line";
|
||||
PostBatch: Codeunit "Gen. Jnl.-Post Batch";
|
||||
begin
|
||||
JournalLine.SetRange("Journal Template Name", TemplateName);
|
||||
JournalLine.SetRange("Journal Batch Name", BatchName);
|
||||
if JournalLine.Count() <> 1 then
|
||||
Error(SingleTransferErr);
|
||||
JournalLine.FindFirst();
|
||||
JournalLine.TestField("Account Type", JournalLine."Account Type"::"G/L Account");
|
||||
JournalLine.TestField("Bal. Account Type", JournalLine."Bal. Account Type"::"G/L Account");
|
||||
JournalLine.TestField("Account No.");
|
||||
JournalLine.TestField("Bal. Account No.");
|
||||
JournalLine.TestField("Posting Date");
|
||||
JournalLine.TestField("Document No.");
|
||||
JournalLine.TestField(Amount);
|
||||
JournalLine.TestField("Currency Code", '');
|
||||
JournalLine.TestField("Gen. Posting Type", JournalLine."Gen. Posting Type"::" ");
|
||||
JournalLine.TestField("Bal. Gen. Posting Type", JournalLine."Bal. Gen. Posting Type"::" ");
|
||||
PostBatch.Run(JournalLine);
|
||||
end;
|
||||
|
||||
var
|
||||
SingleTransferErr: Label 'Use a journal batch containing exactly one self-balancing G/L transfer.';
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: finance
|
||||
keywords: [g-l-entry, ledger-entry, gen-jnl-post-line, gen-jnl-post-batch, journal-line, register, insert]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# Create financial ledger entries through the owning posting engine
|
||||
|
||||
## Description
|
||||
|
||||
Standard financial ledger entries are outputs of posting, not independent rows an extension manufactures. Even two manually inserted G/L rows with balanced amounts bypass posting checks, register bookkeeping, and transaction/source relationships. `G/L Entry.Insert(true)` runs the table trigger; it does not invoke the posting engine.
|
||||
|
||||
## Best Practice
|
||||
|
||||
Use the owning document or journal posting workflow. For a normal persisted general-journal batch, use `"Gen. Jnl.-Post Batch"`; the example posts an existing batch containing one self-balancing, non-VAT G/L transfer. Let posting allocate entries and maintain the register rather than reconstructing its tables.
|
||||
|
||||
`"Gen. Jnl.-Post Line".RunWithCheck` is appropriate for a complete journal line inside a correctly owned posting lifecycle, but it does not invent a balancing account or document number, allocate numbering merely from `Posting No. Series`, or replace [batch document-balancing policy](preserve-journal-batch-document-balance.md). The line codeunit is stateful; its checked wrapper owns its start/continue/finish work. Normal batch posting owns its numbering and commits by default; do not imply these entry points are transaction-neutral.
|
||||
|
||||
Exclude temporary buffers and the standard engine's own insertion points. A checked parent may legitimately use `RunWithoutCheck`; do not replace it without inspecting that parent. This rule owns `G/L Entry`, `Cust. Ledger Entry`, `Vendor Ledger Entry`, their detailed customer/vendor entries, `VAT Entry`, and financial-posting/register records, not a custom table merely named `Ledger Entry` or a supported, specifically reviewed migration/repair workflow.
|
||||
|
||||
`Item Ledger Entry`, `Value Entry`, Capacity/Warehouse entries, `Item Application Entry`, and other inventory-posting records are SCM concerns, not this rule's financial-ledger scope. That exclusion includes the financial-row leg of a single inventory-posting bypass when restoring the inventory workflow corrects the whole operation. Distinct, independently actionable financial defects remain in scope.
|
||||
|
||||
See sample: [`post-ledger-entries-through-posting-codeunits.good.al`](post-ledger-entries-through-posting-codeunits.good.al).
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
Create posted financial effects by directly inserting the Finance-owned records named above outside their owning posting workflow. Resolve the actual record type, operation, and lifecycle; do not match `*Ledger Entry` as a wildcard. Balanced debit/credit values, copied dimensions, `Insert(true)`, and a lock around entry-number allocation do not turn raw inserts into a complete posting.
|
||||
|
||||
See sample: [`post-ledger-entries-through-posting-codeunits.bad.al`](post-ledger-entries-through-posting-codeunits.bad.al).
|
||||
|
||||
## References
|
||||
|
||||
- [Posting engine structure](https://learn.microsoft.com/en-us/dynamics365/business-central/design-details-posting-engine-structure).
|
||||
- [Gen. Jnl.-Post Line API](https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/codeunit/microsoft.finance.generalledger.posting.gen.-jnl.-post-line).
|
||||
- [BCApps: posting lifecycle and register maintenance](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al).
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50107 "Post Journal Allocation"
|
||||
{
|
||||
procedure PostAllocation(TemplateName: Code[10]; BatchName: Code[10]; DebitAccount: Code[20]; CreditAccount: Code[20]; PostingDate: Date)
|
||||
var
|
||||
JournalTemplate: Record "Gen. Journal Template";
|
||||
JournalBatch: Record "Gen. Journal Batch";
|
||||
JournalLine: Record "Gen. Journal Line";
|
||||
LineToPost: Record "Gen. Journal Line";
|
||||
PostLine: Codeunit "Gen. Jnl.-Post Line";
|
||||
begin
|
||||
JournalTemplate.Get(TemplateName);
|
||||
JournalTemplate.TestField(Recurring, false);
|
||||
JournalTemplate.TestField("Force Doc. Balance", true);
|
||||
JournalTemplate.TestField("Source Code");
|
||||
JournalBatch.Get(TemplateName, BatchName);
|
||||
JournalBatch.TestField("No. Series", '');
|
||||
JournalBatch.TestField("Posting No. Series", '');
|
||||
JournalLine.SetRange("Journal Template Name", TemplateName);
|
||||
JournalLine.SetRange("Journal Batch Name", BatchName);
|
||||
if not JournalLine.IsEmpty() then
|
||||
Error(EmptyBatchErr);
|
||||
|
||||
AddAllocationLine(JournalTemplate, BatchName, 10000, DebitAccount, PostingDate, 'ALLOC-A', 90);
|
||||
AddAllocationLine(JournalTemplate, BatchName, 20000, CreditAccount, PostingDate, 'ALLOC-B', -90);
|
||||
JournalLine.FindSet();
|
||||
repeat
|
||||
LineToPost := JournalLine;
|
||||
PostLine.RunWithCheck(LineToPost);
|
||||
until JournalLine.Next() = 0;
|
||||
end;
|
||||
|
||||
local procedure AddAllocationLine(JournalTemplate: Record "Gen. Journal Template"; BatchName: Code[10]; LineNo: Integer; AccountNo: Code[20]; PostingDate: Date; DocumentNo: Code[20]; LineAmount: Decimal)
|
||||
var
|
||||
JournalLine: Record "Gen. Journal Line";
|
||||
begin
|
||||
JournalLine.Init();
|
||||
JournalLine."Journal Template Name" := JournalTemplate.Name;
|
||||
JournalLine."Journal Batch Name" := BatchName;
|
||||
JournalLine."Line No." := LineNo;
|
||||
JournalLine."Source Code" := JournalTemplate."Source Code";
|
||||
JournalLine.Validate("Posting Date", PostingDate);
|
||||
JournalLine.Validate("Document No.", DocumentNo);
|
||||
JournalLine.Validate("Account Type", JournalLine."Account Type"::"G/L Account");
|
||||
JournalLine.Validate("Account No.", AccountNo);
|
||||
JournalLine.Validate("Gen. Posting Type", JournalLine."Gen. Posting Type"::" ");
|
||||
JournalLine.Validate(Amount, LineAmount);
|
||||
JournalLine.Insert(true);
|
||||
end;
|
||||
|
||||
var
|
||||
EmptyBatchErr: Label 'Use an empty journal batch for this allocation.';
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50107 "Post Journal Allocation"
|
||||
{
|
||||
procedure PostAllocation(TemplateName: Code[10]; BatchName: Code[10]; DebitAccount: Code[20]; CreditAccount: Code[20]; PostingDate: Date)
|
||||
var
|
||||
JournalTemplate: Record "Gen. Journal Template";
|
||||
JournalBatch: Record "Gen. Journal Batch";
|
||||
JournalLine: Record "Gen. Journal Line";
|
||||
PostBatch: Codeunit "Gen. Jnl.-Post Batch";
|
||||
begin
|
||||
JournalTemplate.Get(TemplateName);
|
||||
JournalTemplate.TestField(Recurring, false);
|
||||
JournalTemplate.TestField("Force Doc. Balance", true);
|
||||
JournalTemplate.TestField("Source Code");
|
||||
JournalBatch.Get(TemplateName, BatchName);
|
||||
JournalBatch.TestField("No. Series", '');
|
||||
JournalBatch.TestField("Posting No. Series", '');
|
||||
JournalLine.SetRange("Journal Template Name", TemplateName);
|
||||
JournalLine.SetRange("Journal Batch Name", BatchName);
|
||||
if not JournalLine.IsEmpty() then
|
||||
Error(EmptyBatchErr);
|
||||
|
||||
AddAllocationLine(JournalTemplate, BatchName, 10000, DebitAccount, PostingDate, 'ALLOC-A', 90);
|
||||
AddAllocationLine(JournalTemplate, BatchName, 20000, CreditAccount, PostingDate, 'ALLOC-A', -90);
|
||||
JournalLine.FindFirst();
|
||||
PostBatch.Run(JournalLine);
|
||||
end;
|
||||
|
||||
local procedure AddAllocationLine(JournalTemplate: Record "Gen. Journal Template"; BatchName: Code[10]; LineNo: Integer; AccountNo: Code[20]; PostingDate: Date; DocumentNo: Code[20]; LineAmount: Decimal)
|
||||
var
|
||||
JournalLine: Record "Gen. Journal Line";
|
||||
begin
|
||||
JournalLine.Init();
|
||||
JournalLine."Journal Template Name" := JournalTemplate.Name;
|
||||
JournalLine."Journal Batch Name" := BatchName;
|
||||
JournalLine."Line No." := LineNo;
|
||||
JournalLine."Source Code" := JournalTemplate."Source Code";
|
||||
JournalLine.Validate("Posting Date", PostingDate);
|
||||
JournalLine.Validate("Document No.", DocumentNo);
|
||||
JournalLine.Validate("Account Type", JournalLine."Account Type"::"G/L Account");
|
||||
JournalLine.Validate("Account No.", AccountNo);
|
||||
JournalLine.Validate("Gen. Posting Type", JournalLine."Gen. Posting Type"::" ");
|
||||
JournalLine.Validate(Amount, LineAmount);
|
||||
JournalLine.Insert(true);
|
||||
end;
|
||||
|
||||
var
|
||||
EmptyBatchErr: Label 'Use an empty journal batch for this allocation.';
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: finance
|
||||
keywords: [force-doc-balance, gen-journal-template, gen-jnl-post-batch, runwithcheck, document-no, posting-date, balancing]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# Preserve the journal batch's document-balancing policy
|
||||
|
||||
## Description
|
||||
|
||||
A balanced G/L total does not prove that a general-journal batch satisfies its template's document-balancing policy. `"Gen. Jnl.-Post Batch"` checks balances at posting-date boundaries and, when the **journal template's** `Force Doc. Balance` is enabled, document-type/document-number boundaries. A loop over `"Gen. Jnl.-Post Line".RunWithCheck` does not reproduce these batch-level checks.
|
||||
|
||||
## Best Practice
|
||||
|
||||
Post normal persisted general-journal batches through their owning batch workflow. Keep balancing lines in the appropriate document/date group when the template requires it. The examples use two LCY G/L lines: opposite amounts under different document numbers are not a document-balanced transfer when `Force Doc. Balance` is true; the good example groups them under one document and retains the batch checks.
|
||||
|
||||
Do not claim every document must always balance: when that template option is false, the supported workflow can allow document imbalance while still checking the required aggregate balances. Standalone self-balancing line posting and purpose-built posting engines that demonstrably own equivalent aggregate policies are not prohibited. A `RunWithCheck` call or loop alone is not sufficient evidence of a defect.
|
||||
|
||||
See sample: [`preserve-journal-batch-document-balance.good.al`](preserve-journal-batch-document-balance.good.al).
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
Replace a normal persisted journal batch's posting path with per-line posting or only an aggregate-total check, bypassing a demonstrated template/document/date policy. For the document-imbalance finding, require evidence that `Force Doc. Balance` applies and that separate document groups can be unbalanced; do not infer the setting from its name or a comment alone.
|
||||
|
||||
See sample: [`preserve-journal-batch-document-balance.bad.al`](preserve-journal-batch-document-balance.bad.al).
|
||||
|
||||
## References
|
||||
|
||||
- [Work with general journals](https://learn.microsoft.com/en-us/dynamics365/business-central/ui-work-general-journals).
|
||||
- [Gen. Jnl.-Post Batch API](https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/codeunit/microsoft.finance.generalledger.posting.gen.-jnl.-post-batch).
|
||||
- [BCApps: batch balance checks](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostBatch.Codeunit.al).
|
||||
- [BCApps: document-balance option regression cases](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/Tests/General%20Journal/ERMTestMultipleGenJnlLines.Codeunit.al).
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50106 "Reverse Selected Posting"
|
||||
{
|
||||
procedure RequestReversal(SelectedEntryNo: Integer)
|
||||
var
|
||||
GLEntry: Record "G/L Entry";
|
||||
ReversalEntry: Record "Reversal Entry";
|
||||
begin
|
||||
if not GuiAllowed() then
|
||||
Error(InteractiveSessionErr);
|
||||
GLEntry.Get(SelectedEntryNo);
|
||||
GLEntry.TestField("Transaction No.");
|
||||
ReversalEntry.ReverseTransaction(GLEntry."Entry No.");
|
||||
end;
|
||||
|
||||
var
|
||||
InteractiveSessionErr: Label 'Request the reversal from an interactive session.';
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50106 "Reverse Selected Posting"
|
||||
{
|
||||
procedure RequestReversal(SelectedEntryNo: Integer)
|
||||
var
|
||||
GLEntry: Record "G/L Entry";
|
||||
ReversalEntry: Record "Reversal Entry";
|
||||
begin
|
||||
if not GuiAllowed() then
|
||||
Error(InteractiveSessionErr);
|
||||
GLEntry.Get(SelectedEntryNo);
|
||||
GLEntry.TestField("Transaction No.");
|
||||
ReversalEntry.ReverseTransaction(GLEntry."Transaction No.");
|
||||
end;
|
||||
|
||||
var
|
||||
InteractiveSessionErr: Label 'Request the reversal from an interactive session.';
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: finance
|
||||
keywords: [reversetransaction, reverseregister, transaction-no, entry-no, reversal-entry, g-l-register]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# Pass the transaction number, not a ledger-entry number, to ReverseTransaction
|
||||
|
||||
## Description
|
||||
|
||||
`Reversal Entry.ReverseTransaction` expects a **transaction number**, while `ReverseRegister` expects a **G/L register number**. Neither parameter means a ledger `Entry No.`. All are integers, so the compiler accepts the wrong identity; a coincidentally matching integer can select another transaction instead of the posting the user intended to reverse.
|
||||
|
||||
## Best Practice
|
||||
|
||||
When starting from a `G/L Entry`, fetch that entry and pass **its** `Transaction No.` to `Reversal Entry.ReverseTransaction`, as the sample does. The same identity distinction applies to customer/vendor ledger entries when using their supported transaction-reversal path. If the starting point is a G/L register, use `Reversal Entry.ReverseRegister` with that register's number. The interactive workflow collects the participating entries and validates reversal eligibility before the user posts the reversal.
|
||||
|
||||
Do not infer eligibility from `Open` alone or bypass a rejection by changing origin, application, or reversal fields. The supported path depends on source and state; some postings require unapplication or a correcting document first. A request to reverse is not a guarantee that reversal will be permitted. This rule concerns the two named `Reversal Entry` APIs, not routines such as `UnApplyCustLedgEntry` that legitimately accept a ledger entry number.
|
||||
|
||||
See sample: [`reverse-transactions-by-transaction-number.good.al`](reverse-transactions-by-transaction-number.good.al).
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
Pass a ledger entry's `Entry No.` or a register number into `ReverseTransaction`, or pass a ledger-entry/transaction number into `ReverseRegister`. Require visible value provenance, not merely a suspicious variable name or an arbitrary integer. A correctly sourced transaction number is valid even when the variable is poorly named.
|
||||
|
||||
See sample: [`reverse-transactions-by-transaction-number.bad.al`](reverse-transactions-by-transaction-number.bad.al).
|
||||
|
||||
## References
|
||||
|
||||
- [Reversal Entry API](https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/table/microsoft.finance.generalledger.reversal.reversal-entry).
|
||||
- [Reverse journal postings](https://learn.microsoft.com/en-us/dynamics365/business-central/finance-how-reverse-journal-posting).
|
||||
- [BCApps: reversal entry selection](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/BaseApp/Finance/GeneralLedger/Reversal/ReversalEntry.Table.al).
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50102 "Copy Journal Dimensions"
|
||||
{
|
||||
procedure CopyAllLineDimensions(TemplateName: Code[10]; BatchName: Code[10]; SourceLineNo: Integer; TargetLineNo: Integer)
|
||||
var
|
||||
SourceLine: Record "Gen. Journal Line";
|
||||
TargetLine: Record "Gen. Journal Line";
|
||||
begin
|
||||
SourceLine.Get(TemplateName, BatchName, SourceLineNo);
|
||||
TargetLine.Get(TemplateName, BatchName, TargetLineNo);
|
||||
TargetLine."Shortcut Dimension 1 Code" := SourceLine."Shortcut Dimension 1 Code";
|
||||
TargetLine."Shortcut Dimension 2 Code" := SourceLine."Shortcut Dimension 2 Code";
|
||||
TargetLine.Modify(true);
|
||||
end;
|
||||
|
||||
procedure HasShortcutDimension1(JournalLine: Record "Gen. Journal Line"; DimensionValue: Code[20]): Boolean
|
||||
begin
|
||||
exit(JournalLine."Shortcut Dimension 1 Code" = DimensionValue);
|
||||
end;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// Demonstration only; independently authored, not copied from BaseApp.
|
||||
codeunit 50102 "Copy Journal Dimensions"
|
||||
{
|
||||
procedure CopyAllLineDimensions(TemplateName: Code[10]; BatchName: Code[10]; SourceLineNo: Integer; TargetLineNo: Integer)
|
||||
var
|
||||
SourceLine: Record "Gen. Journal Line";
|
||||
TargetLine: Record "Gen. Journal Line";
|
||||
begin
|
||||
SourceLine.Get(TemplateName, BatchName, SourceLineNo);
|
||||
TargetLine.Get(TemplateName, BatchName, TargetLineNo);
|
||||
TargetLine.Validate("Dimension Set ID", SourceLine."Dimension Set ID");
|
||||
TargetLine.Modify(true);
|
||||
end;
|
||||
|
||||
procedure HasShortcutDimension1(JournalLine: Record "Gen. Journal Line"; DimensionValue: Code[20]): Boolean
|
||||
begin
|
||||
exit(JournalLine."Shortcut Dimension 1 Code" = DimensionValue);
|
||||
end;
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: finance
|
||||
keywords: [dimension-set-id, shortcut-dimension, global-dimension, journal-line, posting, copy-dimensions]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# Copy complete posting dimension sets, not only shortcut projections
|
||||
|
||||
## Description
|
||||
|
||||
When a journal line or posting document inherits dimensions, its `Dimension Set ID` identifies the complete combination of `Dimension Set Entry` rows. Global and shortcut dimensions expose selected dimensions, not the complete set; the eight shortcut dimensions are not a limit on set membership. Copying only these projections can leave the destination's posting dimensions unchanged or silently lose dimensions outside the shortcuts.
|
||||
|
||||
## Best Practice
|
||||
|
||||
For an intentional **complete** dimension transfer, copy the source set ID and synchronize the destination's projections through its supported validation or dimension-management routine. On `Gen. Journal Line`, `Validate("Dimension Set ID", SourceSetID)` updates the two shortcut fields. Do not assume another table has the same validation trigger.
|
||||
|
||||
When line-specific dimensions must survive a header change, use the appropriate set-combination or delta routine instead of blindly replacing the line's entire set. Reading or filtering a known global dimension is legitimate; it is not a claim to enumerate every dimension. This rule owns transfers through general-journal and financial-document posting records, not writes to Item, Value, Capacity, Warehouse, or inventory-application records owned by SCM. Generic custom-table or master `Default Dimension` wiring belongs to data modeling.
|
||||
|
||||
See sample: [`write-dimensions-as-dimension-set-entries.good.al`](write-dimensions-as-dimension-set-entries.good.al).
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
A routine intended to copy **all** posting dimensions copies only global/shortcut codes, or assigns a set ID without synchronizing the destination's stored projections. Require evidence of a complete-transfer intent and inspect surrounding validation; an explicit change to one selected dimension or a read-only filter is not this defect.
|
||||
|
||||
See sample: [`write-dimensions-as-dimension-set-entries.bad.al`](write-dimensions-as-dimension-set-entries.bad.al).
|
||||
|
||||
## References
|
||||
|
||||
- [Dimension set entries overview](https://learn.microsoft.com/en-us/dynamics365/business-central/design-details-dimension-set-entries-overview).
|
||||
- [DimensionManagement API](https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/codeunit/microsoft.finance.dimension.dimensionmanagement).
|
||||
- [BCApps: Gen. Journal Line dimension validation](https://github.com/microsoft/BCApps/blob/8f7a04cb0db8aa96cb97e055c45c61aead49e280/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al).
|
||||
Loading…
Add table
Add a link
Reference in a new issue