* fix(invoices): guard cash-method partial payments across every payment path
A never-booked kontantmetoden invoice can only be settled by the generated
cash entry (createInvoiceCashEntry / createSupplierInvoiceCashEntry), and
that entry always books the FULL invoice: it takes no payment amount. Three
payment surfaces still let partial payments through to it, corrupting books:
- settleInvoicePayment dropped the fully-paid term entirely, so a partial
payment (Stripe sync, mark-paid) booked the entire invoice: over-recognized
revenue, over-declared output VAT, and a bank debit that did not match the
money received.
- The dashboard and agent match-transaction paths fell back to an
accrual-style clearing entry against an EMPTY 1510: negative receivable,
no revenue, no moms (ML 13 kap 8 § puts each installment's moms in its own
receipt period). The comment claimed the credit "gets resolved on final
payment", but the cash builder never touches 1510 and books the full
total, so the final payment double-debited the bank instead.
- The supplier routes had no full-settlement term at all, so a partial
payment booked the full expense + input VAT.
Fix: one shared predicate (cashPartialBlockReason in booking-mode.ts)
rejects generated cash entries unless the payment settles the invoice in
full from a fully unpaid state, wired into all six POST surfaces, the agent
commit paths, and the three preview routes (so dialogs cannot propose a
verifikat the POST refuses). New bilingual error codes
INVOICE_PAID_CASH_PARTIAL_UNSUPPORTED / SI_CASH_PARTIAL_UNSUPPORTED.
Invoices booked at issue are unaffected: their partial payments keep the
normal 1510/2440 clearing path.
The v1 match-invoice route already had this guard (VALIDATION_ERROR); its
behavior is unchanged. Proper per-installment recognition (proportional
revenue + moms per receipt) is the follow-up feature that would lift this
restriction.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* docs(review): drop stale ML 13 kap 8 § cites for kontantmetoden VAT timing
Compliance-review finding: the section is the old ML 1994:200 numbering; in
ML 2023:200, 13 kap covers input-VAT deduction, not redovisningstidpunkt.
The substantive rule (bokslutsmetoden reports moms at payment, per
installment, except at year-end) is unchanged and stated without a section
cite until the current-law section is verified. Comments and cookbook prose
only; no behavior change. Also fixes the two pre-existing occurrences.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
* feat(invoices): registrera utan att bokföra + explicit Bokför-steg
Companies where one person registers supplier invoices / sends customer
invoices while ekonomi does the actual bookkeeping had no way to split
the two: under faktureringsmetoden every registration/send booked the
journal entry inline.
- New company setting defer_invoice_booking (default off, accrual only):
registering a supplier invoice or sending/marking-sent a customer
invoice creates NO journal entry.
- New explicit booking routes POST /api/supplier-invoices/[id]/book and
POST /api/invoices/[id]/book: create the registration/revenue entry
afterwards, CAS-guarded against concurrent booking (a lost race
cancels the just-posted voucher with a gap explanation), including
periodisering schedules.
- Detail pages show "Ej bokförd ännu" + a Bokför button for unbooked
accrual invoices; the settings toggle lives under Bokföringsmetod.
- mark-paid needs no changes: both payment flows already route on the
journal-entry link, so an invoice still unbooked when paid gets the
full cash-style entry.
- The mark-sent fail-closed rollback now keys on the same gate so
deferred sends are not rolled back as booking failures.
Fixes#967
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(invoices): harden deferred booking after review
CodeRabbit round on #1040:
- CAS link guards also require a still-bookable status (and uncredited,
customer side) so a concurrent mark-paid/credit cannot end up with a
double-posting registration/revenue entry.
- Settings reads fail closed instead of defaulting to accrual rules.
- Detail pages surface the ACCRUAL_SCHEDULE_FAILED warning instead of
showing plain success, and the customer page no longer stringifies
structured errors into "[object Object]".
- The settings form normalizes defer_invoice_booking to false under
kontantmetoden so a stale flag cannot re-activate on method switch.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>