feat(expenses): utlägg as an answer to "Vem betalade?" in Underlag, not a page (#2317)

An out-of-pocket purchase differs from any other receipt only in the
credit account, so the Underlag pane now asks one question for an
unmatched underlag (Företaget / Jag, privat / En anställd / Ingen ännu)
and books a privately paid receipt in place through POST
/api/expense-claims, replacing the "Andra sätt att bokföra" dropdown and
the deep link into the two-step wizard. The verifikat editor stays
reachable below as the escape hatch (BFL 5 kap 6-7 §).

The person owed surfaces in Att göra under a new Betala band, one row per
person (lib/worklist expense_payout, counted in the total and exposed to
agents through the attention resource). The Utlägg nav row is gated on
existing claims, the same hybrid gate as Körjournal, since the entry
point for a new utlägg is now the Underlag pane.


Claude-Session: https://claude.ai/code/session_01P8YsvPqjfGxGZUkGeBVUWQ

Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-09-05 15:57:14 +02:00
committed by GitHub
co-authored by Jakob Wennberg Claude Fable 5.1
parent bff44e5757
commit cbe5580886
17 changed files with 866 additions and 86 deletions
@@ -4,7 +4,7 @@ import {
fetchUnlinkedDocuments,
UNLINKED_DOCUMENT_SCAN_CAP,
} from '@/lib/documents/unlinked-documents'
import { countReconciliationDue } from '@/lib/worklist/categories'
import { countReconciliationDue, listExpensePayoutsDue } from '@/lib/worklist/categories'
import { fetchJunctionLinkedTxIds } from '@/lib/reconciliation/bank-reconciliation'
import { fetchAllRows } from '@/lib/supabase/fetch-all'
@@ -419,6 +419,31 @@ export const attentionResource: McpResource = {
})
}
// ── People owed for unpaid utlägg ───────────────────────────────
// Same predicate as the Att göra Betala band (lib/worklist
// listExpensePayoutsDue): one item per person, not per receipt.
const expensePayouts = await listExpensePayoutsDue(supabase, companyId)
if (expensePayouts.length > 0) {
categories.push({
key: 'expense_payout',
label_sv: 'Personer med utlägg att betala ut',
severity: 'info',
count: expensePayouts.length,
samples: expensePayouts.slice(0, SAMPLE_LIMIT).map((p) => ({
claimant_name: p.claimant_name,
employee_id: p.employee_id,
liability_account: p.liability_account,
claim_count: p.claim_count,
total_sek: p.total_sek,
oldest_expense_date: p.oldest_expense_date,
})),
next: {
description:
'Betala ut från företagskontot och bokför utbetalningen (2893/2820 D mot 19xx K) via /expenses eller POST /api/expense-claims/payouts.',
},
})
}
// ── Period lock approaching ─────────────────────────────────────
const lockDate = companySettingsRow.data?.bookkeeping_locked_through ?? null
if (lockDate && activePeriodRow.data) {