feat(budget): link existing expenses to bookings and places, several per booking

Discussion #2084: a cost bought later (the seat upgrade for a flight) could
not be tied to the booking it belongs to, and a booking held one expense.

- The Costs block of the booking, transport and place forms lists every
  linked expense with edit, unlink (the expense stays in Costs) and delete,
  and offers the expenses that belong nowhere yet under Link existing
  expense. The phone sheets get the same block in their own design, and
  their Files row lists the attached files and links an existing one.
- PUT /budget/:id, update_budget_item (MCP) and costs.update (plugin RPC)
  take reservation_id / place_id; create and update refuse an id from
  another trip on all three paths.
- The booking's mirrored price is the sum of its expenses when they share
  one currency (none counts as the trip's), else the first one, with that
  currency, and follows every change to a linked expense. The booking
  form's price field leaves a booking with several expenses alone.
- Deleting a booking deletes all of its linked expenses and broadcasts each
  one, also from the MCP delete tools.
- Cards show the price with its currency.
- Booking and transport dialogs: Booking Type and Travelers as dropdowns at
  the top, the URL beside Files (transports gain the URL field). The row is
  one shared component; linking and unlinking files go through the store.

Help center pictures and texts for the booking, transport and expense
guides are redone in all 27 languages, five Costs labels that were still
English in 16 languages are translated, and the wiki follows.
This commit is contained in:
Maurice
2026-09-25 15:34:32 +02:00
parent 1f79776070
commit 8864edda18
188 changed files with 4800 additions and 1124 deletions
+30 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import { splitReservationDateTime, resolveDayId, formatMoney, formatMoneySum, currencyDecimals, localizeAmountInput, amountToInputString } from './formatters'
import { splitReservationDateTime, resolveDayId, formatMoney, formatMoneySum, formatPriceText, currencyDecimals, localizeAmountInput, amountToInputString } from './formatters'
import { CURRENCIES, SYMBOLS, currenciesWith } from '../components/Budget/BudgetPanel.constants'
import type { Day } from '../types'
@@ -200,6 +200,35 @@ describe('formatMoneySum (#1561)', () => {
})
})
describe('formatPriceText (#2084)', () => {
it('formats a numeric price as money in its own currency', () => {
expect(formatPriceText(320, 'EUR', 'USD', 'en')).toBe(formatMoney(320, 'EUR', 'en'))
expect(formatPriceText('12.5', 'chf', 'EUR', 'en')).toBe(formatMoney(12.5, 'CHF', 'en'))
})
it("takes the trip's currency when the price names none", () => {
expect(formatPriceText('45', null, 'jpy', 'en')).toBe(formatMoney(45, 'JPY', 'en'))
expect(formatPriceText(45, '', 'CHF', 'en')).toBe(formatMoney(45, 'CHF', 'en'))
})
it('shows nothing for a missing or empty price', () => {
expect(formatPriceText(null, 'EUR', 'EUR', 'en')).toBe('')
expect(formatPriceText(undefined, 'EUR', 'EUR', 'en')).toBe('')
expect(formatPriceText('', 'EUR', 'EUR', 'en')).toBe('')
})
it('passes a price that is not a number through as written, with its own currency', () => {
expect(formatPriceText('on request', 'EUR', 'USD', 'en')).toBe('on request EUR')
expect(formatPriceText('on request', 'eur', 'USD', 'en')).toBe('on request EUR')
expect(formatPriceText('included', null, 'USD', 'en')).toBe('included')
})
it('keeps a bare number bare when neither the price nor the trip names a currency', () => {
expect(formatPriceText('99', null, null, 'en')).toBe('99')
expect(formatPriceText(12.5, undefined, undefined, 'en')).toBe('12.5')
})
})
describe('splitReservationDateTime', () => {
it('parses full ISO datetime', () => {
expect(splitReservationDateTime('2026-06-25T10:00')).toEqual({ date: '2026-06-25', time: '10:00' })
+18
View File
@@ -126,6 +126,24 @@ export function cleanAmountText(value: string | number | null | undefined): stri
return Number.isFinite(n) && String(value).trim() !== '' ? String(cleanAmount(n)) : String(value)
}
/**
* A booking's price for its card: formatted as money when it is a number, in
* its own currency or else the trip's (a price with none is in the trip's
* currency), and passed through as written otherwise.
*/
export function formatPriceText(
price: string | number | null | undefined,
currency: string | null | undefined,
tripCurrency: string | null | undefined,
locale: string,
): string {
if (price == null || price === '') return ''
const n = Number(price)
const code = (currency || tripCurrency || '').toUpperCase()
if (Number.isFinite(n) && String(price).trim() !== '' && code) return formatMoney(n, code, locale)
return `${cleanAmountText(price)}${currency ? ` ${currency.toUpperCase()}` : ''}`
}
/**
* Locale- and currency-correct money formatting via Intl: the symbol position,
* thousands/decimal separators and decimal count all follow the user's locale