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
+23 -5
View File
@@ -10,8 +10,10 @@ import { SYMBOLS } from './BudgetPanel.constants';
import type { TripMember } from './BudgetPanelMemberChips';
import type { ExpensePrefill } from './CostsPanel';
import {
amountInCurrency,
amountPattern,
calculateTicketShares,
clampAmountDecimals,
hasTicketSplit,
newExpenseSeed,
payersBalanced,
@@ -81,7 +83,7 @@ export function useExpenseForm({
localToday()
)
);
const [currency, setCurrency] = useState(editing ? editingCurrency : seed.currency);
const [currency, setCurrencyState] = useState(editing ? editingCurrency : seed.currency);
const [day, setDay] = useState(editing ? editing.expense_date || localToday() : seed.day);
const [note, setNote] = useState(() => readUserNote(editing));
// Edit and prefill seeds are padded to the currency's decimals (#2175): the DB
@@ -222,7 +224,23 @@ export function useExpenseForm({
? ticketValid
: totalNum !== 0 && (participants.size === 0 || splitMode === 'equally' || customBalanced));
const onTotalChange = (v: string) => setTotal(v.replace(',', '.'));
// Every amount field takes only the decimals its currency has (#2604): a won
// amount typed as 1000.555 would otherwise be saved as typed, listed as ₩1,001
// and reopened as 1001.
const asAmount = (raw: string) => clampAmountDecimals(raw.replace(',', '.'), currency);
const onTotalChange = (v: string) => setTotal(asAmount(v));
// A switch to a currency with fewer decimals cuts what was already typed the same way.
const setCurrency = (next: string) => {
const cut = (m: Record<number, string>) =>
Object.fromEntries(Object.entries(m).map(([id, v]) => [id, amountInCurrency(v, next)]));
setCurrencyState(next);
setTotal((prev) => amountInCurrency(prev, next));
setPayerAmounts(cut);
setCustomAmounts(cut);
setTicketItems((prev) => prev.map((item) => ({ ...item, price: amountInCurrency(item.price, next) })));
};
// Keep the payer amounts summing to the total as it changes, including in ticket
// mode, where the total is derived from the ticket items rather than typed. Only
@@ -266,7 +284,7 @@ export function useExpenseForm({
};
const onPayerAmountChange = (id: number, v: string) => {
const val = v.replace(',', '.');
const val = asAmount(v);
const nextPinned = new Set(pinnedPayers);
nextPinned.add(id);
setPinnedPayers(nextPinned);
@@ -274,7 +292,7 @@ export function useExpenseForm({
};
const handleCustomAmountChange = (id: number, raw: string) => {
const val = raw.replace(',', '.');
const val = asAmount(raw);
if (val === '' || amountPattern(currency, true).test(val)) {
setCustomAmounts((prev) => ({ ...prev, [id]: val }));
}
@@ -292,7 +310,7 @@ export function useExpenseForm({
};
const handleUpdateItemPrice = (id: string, raw: string) => {
const price = raw.replace(',', '.');
const price = asAmount(raw);
if (price === '' || amountPattern(currency, false).test(price)) {
setTicketItems((prev) => prev.map((item) => (item.id === id ? { ...item, price } : item)));
}