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

Aperta
#5,104 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
graphql, typescript
Ambito
backend, databases

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
TypeScript
Stelle
30
Fork
10
Merge medio
2g 12h
PR unite (30g)
276

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Urigo/accounter-fullstack

Tutte le issue di Urigo/accounter-fullstack

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.