fix(bokforing): account search results in the booking dialog search field (#1877) (#1889)

* fix(bokforing): account search results in the booking dialog search field (#1877)

The search field in the "Bokfor transaktion" dialog only matched template
metadata, so typing an account number or name (e.g. active 5460
Forbrukningsmaterial) gave zero hits and no path to booking; the real
account search was only reachable via the discreet "Bokfor manuellt" link.

- TemplatePicker now also searches the company's active chart of accounts
  (reusing lib/bookkeeping/account-search.ts) and shows hits as a "Konton"
  result group; picking one routes into the same manual booking flow as
  "Bokfor manuellt" with the account prefilled on the counter line.
- New buildActiveAccountIndex helper indexes chart rows active-only, so
  deactivated accounts never surface as bookable results.
- searchTemplates additionally prefix-matches all-digit tokens against a
  template's business account (debit for expense, credit for income, both
  legs for transfers, AB variants included); the settlement leg is
  deliberately excluded so "1930" does not light up every template.
- Library template search prefix-matches line accounts on all-digit queries.
- Empty search results show a hint pointing at "Bokfor manuellt" for
  accounts outside the active chart; placeholder now says "Sok mall eller
  konto...". New strings in both messages/sv.json and messages/en.json.

Fixes #1877

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(bokforing): match only business lines when digit-searching library templates (#1877)

CodeRabbit review on PR #1889: the all-digit library-template match also hit
settlement and VAT lines, so searching "1930" lit up every user template with
a bank settlement leg. Restrict the predicate to business lines, mirroring
the static catalog's settlement-leg exclusion.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Mattsson
2026-08-25 13:30:03 +02:00
committed by GitHub
co-authored by Claude Fable 5
parent e92365b86e
commit cd46d936f3
9 changed files with 290 additions and 37 deletions
+23 -1
View File
@@ -326,6 +326,9 @@ export default function TransactionsPage() {
const [bookingDialogOpen, setBookingDialogOpen] = useState(false)
const [bookingDialogTransaction, setBookingDialogTransaction] = useState<TransactionWithInvoice | null>(null)
const [bookingDialogTemplate, setBookingDialogTemplate] = useState<BookingTemplateLibrary | null>(null)
// Account picked from the template picker's "Konton" search results:
// prefills the counter line when the manual booking dialog opens.
const [bookingDialogAccount, setBookingDialogAccount] = useState<string | null>(null)
// Attach-underlag dialog (tx→doc mirror of the Documents view's matcher)
const [attachDocTx, setAttachDocTx] = useState<TransactionWithInvoice | null>(null)
@@ -3389,10 +3392,23 @@ export default function TransactionsPage() {
if (templatePickerTransaction) {
setBookingDialogTransaction(templatePickerTransaction)
setBookingDialogTemplate(null)
setBookingDialogAccount(null)
setBookingDialogOpen(true)
}
}
// Account picked from the template picker's "Konton" search group
// (issue #1877): same route as "Bokför manuellt", with the picked account
// prefilled on the counter line of the journal entry form.
function handlePickAccount(accountNumber: string) {
if (!templatePickerTransaction) return
setBookingDialogTransaction(templatePickerTransaction)
setBookingDialogTemplate(null)
setBookingDialogAccount(accountNumber)
setTemplatePickerOpen(false)
setBookingDialogOpen(true)
}
// Complex (multi-leg or otherwise non-convertible) library template picked
// from the transaction modal: route into the manual booking dialog with
// the template pre-applied against the transaction's amount.
@@ -3400,6 +3416,7 @@ export default function TransactionsPage() {
if (!templatePickerTransaction) return
setBookingDialogTransaction(templatePickerTransaction)
setBookingDialogTemplate(raw)
setBookingDialogAccount(null)
setTemplatePickerOpen(false)
setBookingDialogOpen(true)
}
@@ -3964,10 +3981,14 @@ export default function TransactionsPage() {
open
onOpenChange={(o) => {
setBookingDialogOpen(o)
if (!o) setBookingDialogTemplate(null)
if (!o) {
setBookingDialogTemplate(null)
setBookingDialogAccount(null)
}
}}
transaction={bookingDialogTransaction}
preselectedTemplate={bookingDialogTemplate}
preselectedAccount={bookingDialogAccount}
onBooked={handleTransactionBooked}
/>
)}
@@ -4037,6 +4058,7 @@ export default function TransactionsPage() {
handleOpenTemplateReview(templatePickerTransaction, templateId)
}}
onPickLibraryTemplate={handlePickLibraryTemplate}
onSelectAccount={handlePickAccount}
/>
</DialogContent>
</Dialog>}