Tax computation: encode the loss-offset order between preferred-rate and sort-991 income

Open
#5,104 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
graphql, typescript
Domain
backend, databases

Research direction

Start with packages/server/src/modules/reports/helpers/tax.helper.ts, especially computeCurrentTax, and read the linked follow-up issues #5105 and #5088 for context. The accountant must first decide how losses offset income across rate buckets and what carries forward; then update the helper, its tests, the tax report, and the 6111 line 510 calculation. Done when the decisions are documented and both mixed cases, reporting, and 6111 use the confirmed split.

Written by the indexing model from the issue text.

Description

annual-audit-workflow

Follow-up to #5086, fixed in #5096 (epic #5085). Related: #5105 (loss carry-forward) and #5088 (sort code 931, which also changes calculateTaxAmounts). Links point to main at 4d5ba86.

Background

calculateTaxAmounts builds two taxable-income figures:

  • taxableIncomeAmount (L130-L140): profit before tax plus adjustments, minus sort-code-991 income. It is taxed at taxRate, the company's own and possibly preferred rate (corporate_tax_variables.tax_rate).
  • specialTaxableIncome.amount: the ledger amount on sort code 991. It is taxed at specialTaxRate, the regular corporate rate (L144, corporate_tax_variables.original_tax_rate, default 23, added in this migration).

computeCurrentTax then computes:

annualTaxExpenseAmount = taxableIncomeAmount * taxRate + specialTaxableIncomeAmount * specialTaxRate
currentTaxExpense      = max(0, annualTaxExpenseAmount)
taxableLoss            = max(0, -(taxableIncomeAmount + specialTaxableIncomeAmount))
mixedRateLoss          = the two incomes are non-zero with opposite signs

Problem

When the two incomes have opposite signs, the formula nets a loss against a profit at different rates. A loss should offset income before any rate is applied. Example at 12% / 23%:

Case preferred-rate sort 991 Formula today If the loss offsets the other income first
A −100,000 +300,000 −12,000 + 69,000 = 57,000 (300,000 − 100,000) × 23% = 46,000
B +300,000 −100,000 36,000 − 23,000 = 13,000 (300,000 − 100,000) × 12% = 24,000

The order and the rules (can a 991 loss offset preferred-rate income at all?) must come from the company's accountant. Until they do, #5096 only flags the case:

  • TaxReportYear.mixedRateLoss: schema, resolver.
  • The tax report shows a yellow warning banner: client.
  • The ledger (tax-expenses-ledger-generation.resolver.ts) still books max(0, netted).

To do

  1. Ask the accountant, and write the answers in this issue:
    • Preferred-rate loss with sort-991 profit: does the loss offset the 991 income? At which rate is the rest taxed?
    • Sort-991 loss with preferred-rate profit: the same questions.
    • What carries forward afterwards, and at which "rate bucket"? This feeds #5105.
  2. Change computeCurrentTax to offset first, then apply the rates. Return each rate's taxable amount and tax plus the remaining loss, not just the net. Keep the signature pure: it is the single place both the ledger and the report get the tax from.
  3. Callers (they all read from calculateTaxAmounts):
    • ledger: tax-expenses-ledger-generation.resolver.ts books currentTaxExpense; no change expected;
    • tax report: show the split if useful, and remove the mixedRateLoss warning or downgrade it to an informational note;
    • 6111: buildTaxAdjustmentEntries sets line 510 (income at the special rate) from taxableIncome. Check it against the new split (shaam6111.helper.ts L243-L266).
  4. Tests: extend tax.helper.test.ts. The two "flags a ..." cases already exist; update their expected amounts to the confirmed rules and add cases A and B from the table.

How to run

yarn vitest run --project unit packages/server/src/modules/reports/helpers/__tests__/tax.helper.test.ts

After changing the GraphQL schema, run yarn generate.

Done when

  • The accountant's answer is recorded here and in a doc comment on computeCurrentTax.
  • Both mixed cases produce the confirmed tax and loss, and tests cover them.
  • The tax report no longer flags these cases as unresolved, and 6111 line 510 is consistent.
Dominant language
TypeScript
Stars
30
Forks
10
Avg merge
2d 12h
Merged PRs (30d)
276

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Urigo/accounter-fullstack

All issues in Urigo/accounter-fullstack

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.