Files
accounted/scripts/checks/antipatterns-baseline.json
T
Jakob Wennberg 5777f51940 Reject overpayment on all invoice-match paths (audit C3) (#647)
* fix(invoices): reject overpayment on all invoice-match paths (audit C3)

The paid/remaining math was copy-pasted across three sites; the dashboard match-invoice route guarded against overpayment but the v1 public API route and the agent/MCP commitMatchTransactionInvoice had drifted WITHOUT it — silently accepting payment > remaining (recording paid_amount > total, over-crediting AR; cleanup needs storno, not edit).

- New lib/invoices/apply-invoice-payment.ts planInvoicePayment(): single source of the paid/remaining/status math + overpayment guard, via canonical roundOre (@/lib/money, guard rail #9). FX-agnostic — caller passes the invoice-currency amount.
- All three sites delegate; the guard runs BEFORE journal-entry creation so a rejected match never burns a voucher number. Dashboard behaviour unchanged (faithful extraction — its existing overpayment test still passes, the equivalence anchor). v1 returns MATCH_AMOUNT_EXCEEDS_REMAINING; commit returns the same registry message at 400.
- Removes 7 hand-rolled Math.round(x*100)/100 sites; antipattern guard ratchets 668 -> 661.
- Unit tests for the helper (overpayment rejection, half-öre tolerance, remaining_amount fallback).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* review: run overpayment guard before the storno (PR #647)

greptile: in commit.ts and the v1 route the conflicting-JE storno ran BEFORE the new guard, so a rejected overpayment would still reverse the transaction's prior JE and null its journal_entry_id — a side effect on a rejected match. Move planInvoicePayment above the storno so a rejection leaves the transaction fully untouched. (The dashboard route's pre-existing storno-before-guard ordering is FX-entangled and unchanged here; noted as a follow-up.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 17:00:22 +02:00

183 lines
9.0 KiB
JSON

{
"_comment": "Ratchet baseline for scripts/checks/no-new-antipatterns.mjs. These counts may only decrease. Re-run with --update after a migration lowers them. Goal: both reach 0 (A1 route-auth campaign, D1 rounding codemod).",
"rawRouteAuth": {
"count": 171,
"files": [
"app/api/account/delete/route.ts",
"app/api/account/password/route.ts",
"app/api/agent/composer/route.ts",
"app/api/agent/conversations/[id]/route.ts",
"app/api/agent/conversations/route.ts",
"app/api/agent/invoke/route.ts",
"app/api/agent/memory/[id]/route.ts",
"app/api/agent/memory/route.ts",
"app/api/agent/onboarding/stream/route.ts",
"app/api/agent/profile/route.ts",
"app/api/agent/profile/verify/route.ts",
"app/api/agent/skills/route.ts",
"app/api/audit-trail/route.ts",
"app/api/bookkeeping/account-balances/route.ts",
"app/api/bookkeeping/account-totals/route.ts",
"app/api/bookkeeping/accounts/[number]/route.ts",
"app/api/bookkeeping/accounts/activate/route.ts",
"app/api/bookkeeping/accounts/bas-lookup/route.ts",
"app/api/bookkeeping/accounts/reference/route.ts",
"app/api/bookkeeping/accounts/route.ts",
"app/api/bookkeeping/fiscal-periods/[id]/close/route.ts",
"app/api/bookkeeping/fiscal-periods/[id]/entry-count/route.ts",
"app/api/bookkeeping/fiscal-periods/[id]/route.ts",
"app/api/bookkeeping/fiscal-periods/period-status/route.ts",
"app/api/bookkeeping/fiscal-periods/route.ts",
"app/api/bookkeeping/journal-entries/[id]/chain/route.ts",
"app/api/bookkeeping/journal-entries/[id]/no-document-required/route.ts",
"app/api/bookkeeping/journal-entries/[id]/notes/route.ts",
"app/api/bookkeeping/journal-entries/[id]/route.ts",
"app/api/bookkeeping/journal-entries/route.ts",
"app/api/bookkeeping/mapping-rules/evaluate/route.ts",
"app/api/bookkeeping/mapping-rules/route.ts",
"app/api/bookkeeping/no-doc-required/route.ts",
"app/api/bookkeeping/voucher-gaps/route.ts",
"app/api/calendar/feed/route.ts",
"app/api/cash-accounts/route.ts",
"app/api/company/check-org-number/route.ts",
"app/api/company/current/route.ts",
"app/api/company/members/[id]/route.ts",
"app/api/company/members/invite/[id]/route.ts",
"app/api/company/members/invite/route.ts",
"app/api/company/members/route.ts",
"app/api/company/route.ts",
"app/api/currency/rate/route.ts",
"app/api/deadlines/[id]/complete/route.ts",
"app/api/deadlines/[id]/route.ts",
"app/api/deadlines/[id]/status/route.ts",
"app/api/deadlines/route.ts",
"app/api/documents/[id]/extraction-status/route.ts",
"app/api/documents/[id]/route.ts",
"app/api/documents/[id]/verify/route.ts",
"app/api/documents/[id]/versions/route.ts",
"app/api/documents/counts/route.ts",
"app/api/events/route.ts",
"app/api/extensions/[sector]/[slug]/data/route.ts",
"app/api/extensions/[sector]/[slug]/settings/route.ts",
"app/api/extensions/ext/[...path]/route.ts",
"app/api/extensions/skatteverket/skattekonto/drift/route.ts",
"app/api/import/sie/[id]/route.ts",
"app/api/import/sie/create-accounts/route.ts",
"app/api/import/sie/mappings/route.ts",
"app/api/import/sie/route.ts",
"app/api/invoices/[id]/convert/route.ts",
"app/api/invoices/[id]/mark-sent/route.ts",
"app/api/invoices/[id]/pdf/route.ts",
"app/api/invoices/[id]/route.ts",
"app/api/invoices/preview-pdf/route.ts",
"app/api/kpi/preferences/route.ts",
"app/api/mcp-oauth/authorize/route.ts",
"app/api/pending-operations/[id]/commit/route.ts",
"app/api/pending-operations/[id]/reject/route.ts",
"app/api/pending-operations/[id]/route.ts",
"app/api/pending-operations/bulk-commit/route.ts",
"app/api/pending-operations/route.ts",
"app/api/reconciliation/bank/link/route.ts",
"app/api/reconciliation/bank/mark-opening-balance/route.ts",
"app/api/reconciliation/bank/run/route.ts",
"app/api/reconciliation/bank/status/route.ts",
"app/api/reconciliation/bank/unlink/route.ts",
"app/api/reconciliation/bank/unmatched-entries/route.ts",
"app/api/reports/ar-ledger/customer/[customerId]/invoices/route.ts",
"app/api/reports/ar-ledger/route.ts",
"app/api/reports/ar-ledger/xlsx/route.ts",
"app/api/reports/audit-trail/route.ts",
"app/api/reports/avgifter-basis/route.ts",
"app/api/reports/balance-sheet/pdf/route.ts",
"app/api/reports/balance-sheet/xlsx/route.ts",
"app/api/reports/balansrapport/pdf/route.ts",
"app/api/reports/balansrapport/route.ts",
"app/api/reports/balansrapport/xlsx/route.ts",
"app/api/reports/continuity-check/route.ts",
"app/api/reports/full-archive/route.ts",
"app/api/reports/general-ledger/xlsx/route.ts",
"app/api/reports/income-statement/pdf/route.ts",
"app/api/reports/income-statement/xlsx/route.ts",
"app/api/reports/journal-register/route.ts",
"app/api/reports/journal-register/xlsx/route.ts",
"app/api/reports/kassaflodesanalys/pdf/route.ts",
"app/api/reports/kassaflodesanalys/route.ts",
"app/api/reports/kpi/route.ts",
"app/api/reports/kpi/xlsx/route.ts",
"app/api/reports/monthly-breakdown/route.ts",
"app/api/reports/monthly-breakdown/xlsx/route.ts",
"app/api/reports/resultatrapport/pdf/route.ts",
"app/api/reports/resultatrapport/route.ts",
"app/api/reports/resultatrapport/xlsx/route.ts",
"app/api/reports/salary-journal/route.ts",
"app/api/reports/salary-journal/xlsx/route.ts",
"app/api/reports/supplier-ledger/route.ts",
"app/api/reports/supplier-ledger/supplier/[supplierId]/invoices/route.ts",
"app/api/reports/supplier-ledger/xlsx/route.ts",
"app/api/reports/trial-balance/account/[accountNumber]/sources/route.ts",
"app/api/reports/trial-balance/route.ts",
"app/api/reports/trial-balance/xlsx/route.ts",
"app/api/reports/vacation-liability/route.ts",
"app/api/reports/vat-declaration/ruta/[ruta]/sources/route.ts",
"app/api/reports/vat-declaration/xlsx/route.ts",
"app/api/salary/employees/[id]/absence/route.ts",
"app/api/salary/employees/[id]/benefits/[benefitId]/route.ts",
"app/api/salary/employees/[id]/benefits/route.ts",
"app/api/salary/employees/[id]/route.ts",
"app/api/salary/employees/[id]/worked-hours/batch/route.ts",
"app/api/salary/employees/[id]/worked-hours/route.ts",
"app/api/salary/employees/route.ts",
"app/api/salary/ku/[year]/route.ts",
"app/api/salary/payroll-config/[year]/route.ts",
"app/api/salary/runs/[id]/agi/submit/route.ts",
"app/api/salary/runs/[id]/agi/xml/route.ts",
"app/api/salary/runs/[id]/correct/route.ts",
"app/api/salary/runs/[id]/employees/[employeeId]/route.ts",
"app/api/salary/runs/[id]/employees/route.ts",
"app/api/salary/runs/[id]/lines/[lineId]/route.ts",
"app/api/salary/runs/[id]/lines/route.ts",
"app/api/salary/runs/[id]/payment/bg-lb/route.ts",
"app/api/salary/runs/[id]/payment/pain001/route.ts",
"app/api/salary/runs/[id]/payslips/[employeeId]/pdf/route.ts",
"app/api/salary/runs/[id]/payslips/send/route.ts",
"app/api/salary/runs/[id]/preview/route.ts",
"app/api/salary/runs/[id]/review/route.ts",
"app/api/salary/runs/[id]/route.ts",
"app/api/salary/tax-tables/lookup/route.ts",
"app/api/salary/tax-tables/status/route.ts",
"app/api/settings/api-keys/[id]/route.ts",
"app/api/settings/booking-templates/[id]/route.ts",
"app/api/settings/booking-templates/[id]/touch/route.ts",
"app/api/settings/booking-templates/export/route.ts",
"app/api/settings/booking-templates/import/route.ts",
"app/api/settings/booking-templates/route.ts",
"app/api/settings/counterparty-templates/route.ts",
"app/api/settings/logo/route.ts",
"app/api/settings/oauth-clients/[id]/route.ts",
"app/api/settings/oauth-clients/route.ts",
"app/api/settings/route.ts",
"app/api/skatteverket/tax-payments/[period]/mark-paid/route.ts",
"app/api/skatteverket/tax-payments/[period]/payment-file/route.ts",
"app/api/skatteverket/tax-payments/[period]/route.ts",
"app/api/supplier-invoices/[id]/route.ts",
"app/api/supplier-invoices/[id]/uncredit/route.ts",
"app/api/support/contact/route.ts",
"app/api/tax-deadlines/generate/route.ts",
"app/api/team/accept/route.ts",
"app/api/team/members/route.ts",
"app/api/transactions/[id]/attach-document/route.ts",
"app/api/transactions/[id]/book/route.ts",
"app/api/transactions/[id]/ignore/route.ts",
"app/api/transactions/[id]/uncategorize/route.ts",
"app/api/transactions/batch-match-invoices/route.ts",
"app/api/transactions/create-from-document/route.ts",
"app/api/transactions/route.ts",
"app/api/transactions/suggest-categories/route.ts",
"app/api/vat/validate/route.ts"
]
},
"naiveOreRound": {
"count": 661
}
}