feat(expenses): repay utlägg from the bank line (#2333)
* feat(expenses): repay utlägg from the bank line
The transfer that repays a person's registered utlägg is now booked from
the bank inbox (or one click on Hem) instead of ahead of it: the payout RPC
takes the unbooked bank transaction, requires an SEK outflow equal to the
claims' total to the öre, posts liability D / 19xx K, marks the claims paid
and links the row in one locked transaction. The same transfer can no
longer be booked twice (once by "Betala ut", once by categorising the row).
- create_expense_payout_batch(..., p_transaction_id): old signature dropped
so a 6-argument call cannot become ambiguous; refusals TX_NOT_FOUND,
TX_ALREADY_BOOKED, TX_CURRENCY, TX_AMOUNT_MISMATCH
- POST /api/transactions/[id]/match-expense-payout { claim_ids }
- lib/expenses/expense-payout-candidates: pure per-person grouping and
outflow pairing (one person per amount; shared totals are skipped)
- Hem suggested matches gain kind 'expense_payout'; the inbox row gets a
primary "Bokför återbetalning av utlägg till {name}" and a two-leg confirm
- PAYOUT_ERROR_MESSAGES shared by both payout routes
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P8YsvPqjfGxGZUkGeBVUWQ
* feat(expenses): close the utlägg gaps: claim picker, foreign VAT, enskild firma
- "Matcha mot utlägg" in the inbox row menu: pick the person and the
receipts a transfer covers when the exact-amount pairing missed it. The
picked sum must equal the row to the öre; the same RPC books it.
- A foreign receipt defaults VAT to 0 in the Underlag dialog with a note:
foreign VAT is not deductible on 2641.
- Enskild firma: a claim on 2018 is egen insättning, not a debt. Excluded
from Att göra, the attention resource, suggestions and the picker; a
payout for it debits 2013 (eget uttag), never 2018. Copy in the pane and
the dialog says so.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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:
co-authored by
Claude Fable 5.1
Jakob Wennberg
parent
238cbe13f9
commit
b71f2bf425
@@ -3116,15 +3116,20 @@ export function PayerChoiceSelect({
|
||||
accountingMethod: AccountingMethod
|
||||
}) {
|
||||
const t = useTranslations('inbox_workspace')
|
||||
// An enskild firma owner makes an egen insättning, not a loan to the
|
||||
// company: no debt, nothing to pay out, so the help line says so.
|
||||
const isEf = useCompanyOptional()?.company?.entity_type === 'enskild_firma'
|
||||
// Företaget carries no help line: the button under it ("Matcha mot
|
||||
// transaktion") already says what happens. The other answers name the
|
||||
// liability the company takes on, which is the consequence worth reading.
|
||||
const helpKey = (choice: PayerChoice): string | null =>
|
||||
choice === 'company'
|
||||
? null
|
||||
: choice === 'unpaid' && accountingMethod === 'cash'
|
||||
? 'payer_help_unpaid_cash'
|
||||
: `payer_help_${choice}`
|
||||
: choice === 'owner' && isEf
|
||||
? 'payer_help_owner_ef'
|
||||
: choice === 'unpaid' && accountingMethod === 'cash'
|
||||
? 'payer_help_unpaid_cash'
|
||||
: `payer_help_${choice}`
|
||||
const selectedHelp = helpKey(value)
|
||||
return (
|
||||
<div className="space-y-1.5">
|
||||
|
||||
@@ -103,6 +103,11 @@ export default function RegisterExpenseDialog({ open, onOpenChange, item, payer,
|
||||
const [employeesLoaded, setEmployeesLoaded] = useState(false)
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
const currency = (data?.invoice?.currency ?? 'SEK').toUpperCase()
|
||||
// A foreign receipt carries VAT the company cannot deduct on 2641: the whole
|
||||
// amount is cost. The wizard asked for the seller's country; here the
|
||||
// currency is the signal, and the note under the preview says so.
|
||||
const isForeign = currency !== 'SEK'
|
||||
const isEf = entityType === 'enskild_firma'
|
||||
|
||||
// Reset per open so a previous underlag's numbers never carry over.
|
||||
useEffect(() => {
|
||||
@@ -112,10 +117,10 @@ export default function RegisterExpenseDialog({ open, onOpenChange, item, payer,
|
||||
const total = data?.totals?.total
|
||||
const vat = data?.totals?.vatAmount
|
||||
setAmountInput(total != null && total > 0 ? String(roundOre(total)).replace('.', ',') : '')
|
||||
setVatInput(vat != null && vat > 0 ? String(roundOre(vat)).replace('.', ',') : '0')
|
||||
setVatInput(!isForeign && vat != null && vat > 0 ? String(roundOre(vat)).replace('.', ',') : '0')
|
||||
setExpenseAccount('')
|
||||
setEmployeeId('')
|
||||
}, [open, item.id, data])
|
||||
}, [open, item.id, data, isForeign])
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || payer !== 'employee' || employeesLoaded) return
|
||||
@@ -221,7 +226,9 @@ export default function RegisterExpenseDialog({ open, onOpenChange, item, payer,
|
||||
<DialogTitle>{t('expense_dialog_title')}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{payer === 'owner'
|
||||
? t('expense_dialog_help_owner', { account: liabilityAccount })
|
||||
? isEf
|
||||
? t('expense_dialog_help_owner_ef')
|
||||
: t('expense_dialog_help_owner', { account: liabilityAccount })
|
||||
: t('expense_dialog_help_employee')}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
@@ -321,10 +328,12 @@ export default function RegisterExpenseDialog({ open, onOpenChange, item, payer,
|
||||
{vatAmount > 0 ? ` · 2641 D ${formatCurrency(vatAmount, currency)}` : ''}
|
||||
{` · ${liabilityAccount} K ${formatCurrency(amount, currency)}`}
|
||||
</p>
|
||||
{claimantName && (
|
||||
<p>{t('expense_outcome_att_gora', { name: claimantName })}</p>
|
||||
{payer === 'owner' && isEf ? (
|
||||
<p>{t('expense_outcome_ef')}</p>
|
||||
) : (
|
||||
claimantName && <p>{t('expense_outcome_att_gora', { name: claimantName })}</p>
|
||||
)}
|
||||
{currency !== 'SEK' && <p>{t('expense_fx_note')}</p>}
|
||||
{isForeign && <p>{t('expense_fx_note')}</p>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user