fix(costs): amounts follow their currency's decimals and format, and payments count on the local day

Several small things in the costs views, on desktop and phone alike:

- The outstanding card no longer says "You're all settled up" while a
  payment is still open in Settle up.
- The custom split shows its suggested shares as a faint placeholder in
  the currency's own form (30000 for won, not 30000.00), so it no longer
  reads like an amount already typed.
- Amount fields take only the decimals the currency has: won and yen take
  none, KWD and the other three-decimal currencies three. A switch of
  currency cuts what was already typed. 1000.555 won was saved as typed,
  listed as 1,001 and reopened as 1001.
- The expense sheet on the phone prints shares and sums with the same
  formatter as the list, with grouping and the currency's decimals.
- A payment recorded with Settle or Settle all is dated on the viewer's
  own day, and one without a date of its own is grouped by its UTC record
  time read on the local calendar. In Seoul before 09:00 it landed on the
  day before.
- "1 expenses need a payer" now uses the plural forms of each language.

Refs #2604
This commit is contained in:
Maurice
2026-10-12 15:04:32 +02:00
parent 9064dbb2f0
commit dbbbd07b1c
37 changed files with 424 additions and 74 deletions
@@ -8,7 +8,7 @@ import { Eyebrow, FIELD_AREA_CLS, FIELD_CLS, FormSheetFooter, FormSheetHeader }
import { useTranslation } from '../../../../i18n'
import { useToast } from '../../../../components/shared/Toast'
import { useTripStore } from '../../../../store/tripStore'
import { formatMoney, localizeAmountInput } from '../../../../utils/formatters'
import { amountToInputString, formatMoney, localizeAmountInput, zeroAmountInput } from '../../../../utils/formatters'
import { openFile } from '../../../../utils/fileDownload'
import { splitShareLabel } from '../../../../components/Budget/expenseFx'
import { SPLIT_COLORS } from '../../../../components/Budget/BudgetPanel.constants'
@@ -150,11 +150,11 @@ export default function MCostSheet({ tripId, base, people, me, editing, prefill,
<NumericInput
mode="signed-decimal"
signToggleLabel={t('costs.toggleSign')}
placeholder={localizeAmountInput('0.00', currency)}
value={localizeAmountInput(isTicketMode ? ticketInfo.total.toFixed(2) : total, currency)}
placeholder={zeroAmountInput(currency)}
value={localizeAmountInput(isTicketMode ? amountToInputString(ticketInfo.total, currency) : total, currency)}
onValueChange={onTotalChange}
disabled={isTicketMode}
className="min-w-0 flex-1 border-0 bg-transparent text-[0.84375rem] font-semibold text-m-ink outline-none [font-variant-numeric:tabular-nums] placeholder:text-m-faint"
className="min-w-0 flex-1 border-0 bg-transparent text-[0.84375rem] font-semibold text-m-ink outline-none [font-variant-numeric:tabular-nums] placeholder:font-normal placeholder:text-m-faint"
/>
</div>
@@ -276,10 +276,10 @@ export default function MCostSheet({ tripId, base, people, me, editing, prefill,
<NumericInput
mode="signed-decimal"
signToggleLabel={t('costs.toggleSign')}
placeholder={localizeAmountInput('0.00', currency)}
placeholder={zeroAmountInput(currency)}
value={localizeAmountInput(payerAmounts[p.id] || '', currency)}
onValueChange={v => onPayerAmountChange(p.id, v)}
className="w-full border-0 bg-transparent py-[7px] text-end text-[0.8125rem] font-semibold text-m-ink outline-none"
className="w-full border-0 bg-transparent py-[7px] text-end text-[0.8125rem] font-semibold text-m-ink outline-none placeholder:font-normal placeholder:text-m-faint"
/>
</div>
) : (
@@ -330,10 +330,10 @@ export default function MCostSheet({ tripId, base, people, me, editing, prefill,
<span className="text-[0.75rem] text-m-faint">{sym(currency)}</span>
<NumericInput
mode="decimal"
placeholder={localizeAmountInput('0.00', currency)}
placeholder={zeroAmountInput(currency)}
value={localizeAmountInput(item.price, currency)}
onValueChange={v => handleUpdateItemPrice(item.id, v)}
className="w-full border-0 bg-transparent py-[7px] text-end text-[0.8125rem] font-semibold text-m-ink outline-none"
className="w-full border-0 bg-transparent py-[7px] text-end text-[0.8125rem] font-semibold text-m-ink outline-none placeholder:font-normal placeholder:text-m-faint"
/>
</div>
<button type="button" onClick={() => handleRemoveItem(item.id)} className="flex-none text-m-muted" aria-label={t('common.delete')}>
@@ -371,7 +371,7 @@ export default function MCostSheet({ tripId, base, people, me, editing, prefill,
{people.map(p => (
<div key={p.id} className="flex justify-between text-[0.8125rem]">
<span className="text-m-muted">{nameOf(p)}</span>
<span className="font-semibold text-m-ink [font-variant-numeric:tabular-nums]">{sym(currency)}{(ticketInfo.shares[p.id] || 0).toFixed(2)}</span>
<span className="font-semibold text-m-ink [font-variant-numeric:tabular-nums]">{formatMoney(ticketInfo.shares[p.id] || 0, currency, locale)}</span>
</div>
))}
</div>
@@ -397,7 +397,7 @@ export default function MCostSheet({ tripId, base, people, me, editing, prefill,
{splitMode === 'equally' ? (
on ? (
<span className="flex-none pe-1 text-[0.8125rem] font-semibold text-m-ink [font-variant-numeric:tabular-nums]">
{sym(currency)}{(equalShares[p.id] || 0).toFixed(2)}
{formatMoney(equalShares[p.id] || 0, currency, locale)}
</span>
) : (
<span className="flex-none pe-1 text-[0.6875rem] text-m-faint">{t('costs.tapToInclude')}</span>
@@ -408,10 +408,10 @@ export default function MCostSheet({ tripId, base, people, me, editing, prefill,
<input
type="text"
inputMode="decimal"
placeholder={localizeAmountInput((placeholderShares[p.id] || 0).toFixed(2), currency)}
placeholder={localizeAmountInput(amountToInputString(placeholderShares[p.id] || 0, currency), currency)}
value={localizeAmountInput(customAmounts[p.id] || '', currency)}
onChange={e => handleCustomAmountChange(p.id, e.target.value)}
className="w-full border-0 bg-transparent py-[7px] text-end text-[0.8125rem] font-semibold text-m-ink outline-none placeholder:text-m-faint"
className="w-full border-0 bg-transparent py-[7px] text-end text-[0.8125rem] font-semibold text-m-ink outline-none placeholder:font-normal placeholder:text-m-faint"
/>
</div>
) : (
@@ -426,13 +426,13 @@ export default function MCostSheet({ tripId, base, people, me, editing, prefill,
<div className="mt-2 text-[0.71875rem]">
{splitMode === 'equally' ? (
<span className="text-m-faint">
{participants.size > 0 && t('costs.splitSummary', { count: participants.size, amount: splitShareLabel(each, currency, fx, participants.size, base, sym, locale) })}
{participants.size > 0 && t('costs.splitSummary', { count: participants.size, amount: splitShareLabel(each, currency, fx, participants.size, base, locale) })}
</span>
) : (
<span className={`font-semibold ${customBalanced ? 'text-[color:var(--m-st-confirmed)]' : 'text-[color:var(--m-st-danger)]'}`}>
{customBalanced
? t('costs.splitSummary', { count: participants.size, amount: splitShareLabel(each, currency, fx, participants.size, base, sym, locale) })
: `${sym(currency)}${splitSum.toFixed(2)} / ${sym(currency)}${totalNum.toFixed(2)}`}
? t('costs.splitSummary', { count: participants.size, amount: splitShareLabel(each, currency, fx, participants.size, base, locale) })
: `${formatMoney(splitSum, currency, locale)} / ${formatMoney(totalNum, currency, locale)}`}
</span>
)}
</div>
@@ -5,7 +5,7 @@ import {
} from 'lucide-react'
import MDancingTrek from '../../../components/MDancingTrek'
import { useTranslation } from '../../../../i18n'
import { formatMoney } from '../../../../utils/formatters'
import { formatMoney, localizeAmountInput, zeroAmountInput } from '../../../../utils/formatters'
import { openFile } from '../../../../utils/fileDownload'
import MCostSheet from '../sheets/MCostSheet'
import { ReceiptPreviewModal } from '../../../../components/Budget/ReceiptPreviewModal'
@@ -175,7 +175,7 @@ export default function MCostsTab({ planner, shell }: MTabScreenProps) {
</span>
<div className="min-w-0 flex-1">
<div className="text-[0.78125rem] font-bold text-m-ink">{t('costs.outstanding')}</div>
<div className="font-geist text-[0.59375rem] text-m-faint"><b>{totals.outstandingCount}</b> {t('costs.outstandingItems')}</div>
<div className="font-geist text-[0.59375rem] text-m-faint"><b>{totals.outstandingCount}</b> {t('costs.outstandingItems', { count: totals.outstandingCount })}</div>
</div>
<div className="flex-none font-geist text-[0.9375rem] font-extrabold tabular-nums" style={{ color: STATUS_COLOR.pending }}>
{formatMoney(totals.outstanding, base, locale)}
@@ -873,7 +873,7 @@ function AddPaymentSheet({ open, editing, onClose, tripId, base, tripCurrency, p
<Eyebrow className="mb-[7px] mt-[14px] uppercase">{t('costs.amount')}</Eyebrow>
<div className="flex items-center gap-2">
<input type="text" inputMode="decimal" value={amount} onChange={e => setAmount(e.target.value)} placeholder="0.00" className={FIELD_CLS} />
<input type="text" inputMode="decimal" value={localizeAmountInput(amount, currency)} onChange={e => setAmount(e.target.value)} placeholder={zeroAmountInput(currency)} className={FIELD_CLS} />
<span className="flex-none font-geist text-[0.75rem] font-bold text-m-faint">{currency}</span>
</div>