fix(bookkeeping): settle öre differences to 3740 and improve supplier-invoice matching (#699)
Whole-krona Bankgiro/Swish payments of öre-bearing invoices were stranded as partially_paid forever (e.g. 11 231 paid on an 11 231,25 invoice left 0,25 kr open). Book the sub-krona residual to BAS 3740 (Öres- och kronutjämning) and settle the invoice in full, on both the supplier- and customer-invoice match flows. New shared pure helpers buildSupplierPaymentClearingLines + planSupplierPayment mirror the customer-side primitives; routing preview and commit through the same builder also fixes two pre-existing preview↔commit drifts (payment account + line descriptions). Öre absorption is accrual-only — cash entries book the full invoice, so absorbing there would hide a 1930 discrepancy. Also improves supplier-invoice ↔ bank matching: - Pass-3 date window now spans [invoice_date-5, due_date+5] instead of due_date ±5, so early payments auto-match; an ambiguity guard demotes non-unique amount matches to suggestions. - New retroactive matcher (on supplier_invoice.registered/.approved) surfaces the settling bank payment when the invoice is registered after the payment was imported. Matches are written as suggestions for one-click confirm-to-book, never silently auto-booked. Tests: new unit tests for both pure helpers; extended matching, handler, customer öre, and route suites. Full suite green (407 files / 5364 tests). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
4dfd790de5
commit
b38b3d0230
@@ -449,7 +449,14 @@ export default function InvoiceMatchDialog({
|
||||
// built by buildInvoicePaymentClearingLines, which posts the
|
||||
// FX diff to 3960/7960 so the books balance correctly even
|
||||
// when the on-screen numbers can't be naively compared.
|
||||
const amountsMatch = sameCurrency && Math.abs(txAbs - invRemaining) < 0.01
|
||||
const diff = Math.abs(txAbs - invRemaining)
|
||||
const amountsMatch = sameCurrency && diff < 0.01
|
||||
// A sub-krona SEK difference is öresavrundning: the backend books
|
||||
// it to 3740 and settles the invoice in full instead of leaving it
|
||||
// delbetald (see ORE_ROUNDING_SETTLEMENT_MAX). SEK only — keep the
|
||||
// 1 kr band in sync with the server constant.
|
||||
const isOreRounding =
|
||||
sameCurrency && transaction.currency === 'SEK' && diff >= 0.01 && diff < 1.0
|
||||
|
||||
if (amountsMatch) {
|
||||
return (
|
||||
@@ -460,6 +467,19 @@ export default function InvoiceMatchDialog({
|
||||
)
|
||||
}
|
||||
|
||||
if (isOreRounding) {
|
||||
return (
|
||||
<div className="flex items-start gap-2 p-3 rounded-lg bg-success/10 text-success">
|
||||
<CheckCircle2 className="h-4 w-4 flex-shrink-0 mt-0.5" />
|
||||
<p className="text-sm font-medium">
|
||||
{t('ore_rounding_note', {
|
||||
amount: formatCurrency(diff, transaction.currency),
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex items-start gap-2 p-3 rounded-lg bg-warning/10 text-warning-foreground">
|
||||
<AlertTriangle className="h-4 w-4 flex-shrink-0 mt-0.5" />
|
||||
|
||||
Reference in New Issue
Block a user