[WHT]-Withholding Tax is not deducted from Expense Report lines based on the Expense Category during posting - #9973
Conversation
… on the Expense Category during posting
|
Could not find linked issues in the pull request description. Please make sure the pull request description contains a line that contains 'Fixes #' followed by the issue number being fixed. Use that pattern for every issue you want to link. |
|
Copilot resolve the merge conflicts in this pull request |
…ne' of https://github.com/ViditGupta1277/BCApps into bugs/Bug-645160-WHT-not-deducted-from-Expense-Report-Line
|
The new Suggested fix (apply manually — could not be anchored as a one-click suggestion): if CheckWithholdingTaxDisabled() then
exit;
if Rec."Expense Category" = '' then begin
Rec."Wthldg. Tax Prod. Post. Group" := '';
exit;
end;
if ExpenseCategory.Get(Rec."Expense Category") then
Rec."Wthldg. Tax Prod. Post. Group" := ExpenseCategory."Wthldg. Tax Prod. Post. Group"
else
Rec."Wthldg. Tax Prod. Post. Group" := '';Knowledge: Line mapping was unavailable, so this was posted as an issue comment. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.32.4 |
d4e3b32
…rom-Expense-Report-Line
| GLEntry: Record "G/L Entry"; | ||
| WHTEmployeeCalc: Codeunit "WHT Employee Calculation"; | ||
| begin | ||
| if not WHTPostingSetup.Get(GenJnlLine."Wthldg. Tax Bus. Post. Group", GenJnlLine."Wthldg. Tax Prod. Post. Group") then begin |
There was a problem hiding this comment.
Two independently-flagged issues compound: the buffer table is directly writable (RIMD) by any user holding only the new permission set, and PostWHTSingle/PostWHTGroup post whatever amounts are found in that buffer without validating that a posting setup exists before trusting the amount. Together, a user (or a bug) that seeds/edits buffer rows can drive incorrect G/L postings with no configuration error surfaced anywhere in the flow. Closing either gap alone still leaves the other; both the permission model and the setup validation should be hardened together.
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.32.4
| Assignable = true; | ||
| Caption = 'Expense Withholding Tax'; | ||
|
|
||
| Permissions = |
There was a problem hiding this comment.
The new assignable permission set "Exp. Withholding Tax" grants only the buffer table and two internal codeunits, but the app's setup and normal usage paths also depend on the Expense Category Card, Withholding Tax Posting Setup, and the extended General Journal page/fields. Without execute/tabledata coverage for those objects (or an equivalent included permission set), an assigned user cannot configure or use this feature without SUPER.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.32.4
|
|
||
| using Microsoft.WithholdingTax; | ||
|
|
||
| table 7059 "WHT Exp. Report Buffer" |
There was a problem hiding this comment.
Table 7059 is modeled as a normal persisted table even though it is used only as a per-document staging buffer between posting events and is explicitly deleted again after posting. Keeping transient posting state in tabledata adds unnecessary schema and permission surface, and any path that misses cleanup leaves stale rows behind. Model this buffer as temporary, or document and constrain why durable storage is required.
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.32.4
| ParentSetup.Get(GenJnlLine."Wthldg. Tax Bus. Post. Group", WHTGroupLine."Wthldg. Tax Prod. Post. Group"); | ||
| ComponentWHT := Round(WHTEmployeeCalc.CalcComponentWHT(WHTGroupLine, CompoundBase, GenJnlLine)); | ||
| if ComponentWHT <> 0 then begin | ||
| if (WHTGroupLine."Wthldg. Tax Prod. Post. Group" <> '') and |
There was a problem hiding this comment.
In PostWHTGroup, a missing component posting setup only skips G/L entry creation, but InsertEmployeeWHTComponentEntry still runs. Posting continues with withholding tax component history but no balancing payable entry, and the user never sees a configuration error. Fail the posting when the component setup row is absent before inserting the component tax entry.
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.32.4
| [EventSubscriber(ObjectType::Codeunit, Codeunit::"WHT Employee Calculation", OnAfterIsEmployeeWHTApplicable, '', false, false)] | ||
| local procedure OnAfterIsEmployeeWHTApplicable(GenJnlLine: Record "Gen. Journal Line"; var IsApplicable: Boolean) | ||
| begin | ||
| if (GenJnlLine."Wthldg. Tax Prod. Post. Group" = '') and IsExpenseCategorySingleTax(GenJnlLine) then |
There was a problem hiding this comment.
The OnAfterIsEmployeeWHTApplicable subscriber overwrites IsApplicable with true in its else branch, so it can undo another subscriber's decision to set it false, depending on execution order. Only narrow the result when this subscriber needs to block withholding tax, and otherwise leave the incoming value unchanged.
Suggested fix (apply manually — could not be anchored as a one-click suggestion):
if (GenJnlLine."Wthldg. Tax Prod. Post. Group" = '') and IsExpenseCategorySingleTax(GenJnlLine) then
IsApplicable := false;👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.32.4
| end; | ||
|
|
||
| [EventSubscriber(ObjectType::Codeunit, Codeunit::"WHT Employee Calculation", OnAfterIsEmployeeWHTApplicable, '', false, false)] | ||
| local procedure OnAfterIsEmployeeWHTApplicable(GenJnlLine: Record "Gen. Journal Line"; var IsApplicable: Boolean) |
There was a problem hiding this comment.
New event subscriber OnAfterIsEmployeeWHTApplicable declares (GenJnlLine, var IsApplicable) but the publisher in WHT Employee Calculation raises the event as (GenJnlLine, Employee, var IsApplicable). AL subscriber parameter lists must be a positional prefix of the publisher's list — you may drop trailing parameters but not a middle one. Here the subscriber's second parameter (var IsApplicable: Boolean) lines up against the publisher's second parameter (Employee: Record Employee), a type mismatch that will fail compilation of this app. Add the missing Employee: Record Employee parameter between GenJnlLine and var IsApplicable.
Suggested fix (apply manually — could not be anchored as a one-click suggestion):
local procedure OnAfterIsEmployeeWHTApplicable(GenJnlLine: Record "Gen. Journal Line"; Employee: Record Employee; var IsApplicable: Boolean)Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.32.4
…ne' of https://github.com/ViditGupta1277/BCApps into bugs/Bug-645160-WHT-not-deducted-from-Expense-Report-Line # Conflicts: # build/projects/Apps CA/.AL-Go/settings.json # build/projects/Apps CZ/.AL-Go/settings.json # build/projects/Apps DK/.AL-Go/settings.json # build/projects/Apps ES/.AL-Go/settings.json # build/projects/Apps FR/.AL-Go/settings.json # build/projects/Apps GB/.AL-Go/settings.json # build/projects/Apps NO/.AL-Go/settings.json # build/projects/Apps US/.AL-Go/settings.json
|
This PR introduces a second, parallel implementation of single/group withholding-tax GL posting logic. Posting this finding as an issue comment because inline comment placement failed. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.32.4 |
|
Behavioral change to the shipped, non-local procedure Line mapping was unavailable, so this was posted as an issue comment. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.32.4 |
Fixes AB#645160