Compare commits
3 commits
feat/add-g
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e6b06b399 | |||
| 9981cf9a9a | |||
| 61f4e42846 |
7 changed files with 80 additions and 6 deletions
7
SPEC.md
7
SPEC.md
|
|
@ -180,8 +180,11 @@ Split `value` meaning per mode:
|
||||||
| `exact` | amount in minor units | sum == amount |
|
| `exact` | amount in minor units | sum == amount |
|
||||||
| `percent` | basis points (100 % = 10000) | sum == 10000 |
|
| `percent` | basis points (100 % = 10000) | sum == 10000 |
|
||||||
|
|
||||||
Multiple payers are supported (`payers` list); the default UI shows a single
|
Multiple payers are supported (`payers` list) — e.g. several people chipping
|
||||||
payer with an "add payer" option.
|
in for a car. The editor shows a single payer by default; choosing "Several
|
||||||
|
people" in *Paid by* lists every member with an amount box. Empty boxes show
|
||||||
|
the unassigned remainder as a placeholder, a live line reads "Remaining" /
|
||||||
|
"Over by" / "Adds up to the total", and the expense list shows "N payers".
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -349,14 +349,18 @@
|
||||||
<div class="item member">
|
<div class="item member">
|
||||||
<Avatar member={m} index={memberIndex(m.id)} size={28} />
|
<Avatar member={m} index={memberIndex(m.id)} size={28} />
|
||||||
<span class="grow name">{m.name}</span>
|
<span class="grow name">{m.name}</span>
|
||||||
<input class="num value" inputmode="decimal" bind:value={payerAmounts[m.id]} aria-label="{t('paid_by_label')}: {m.name}" />
|
<!-- empty boxes hint at what's still unassigned -->
|
||||||
|
<input class="num value" inputmode="decimal" bind:value={payerAmounts[m.id]} aria-label="{t('paid_by_label')}: {m.name}"
|
||||||
|
placeholder={payersRemaining > 0 ? amountInput(payersRemaining, currency) : ''} />
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{#if payersRemaining !== 0 && amount}
|
{#if amount && payersRemaining !== 0}
|
||||||
<span class="small {payersRemaining < 0 ? 'neg' : 'muted'}">
|
<span class="small {payersRemaining < 0 ? 'neg' : 'muted'}">
|
||||||
{payersRemaining > 0 ? t('remaining', { amount: money(payersRemaining, currency) }) : t('over_by', { amount: money(-payersRemaining, currency) })}
|
{payersRemaining > 0 ? t('remaining', { amount: money(payersRemaining, currency) }) : t('over_by', { amount: money(-payersRemaining, currency) })}
|
||||||
</span>
|
</span>
|
||||||
|
{:else if amount && payers.length > 1}
|
||||||
|
<span class="small pos row adds-up"><Icon name="check" size={14} />{t('adds_up')}</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
@ -507,6 +511,8 @@
|
||||||
.value-wrap { gap: 4px; flex-shrink: 0; }
|
.value-wrap { gap: 4px; flex-shrink: 0; }
|
||||||
.value { width: 104px; min-height: 36px; padding: 4px 10px; text-align: right; }
|
.value { width: 104px; min-height: 36px; padding: 4px 10px; text-align: right; }
|
||||||
.value.narrow { width: 64px; }
|
.value.narrow { width: 64px; }
|
||||||
|
.value::placeholder { color: var(--muted); opacity: 0.6; }
|
||||||
|
.adds-up { gap: 4px; }
|
||||||
|
|
||||||
.extras { display: flex; flex-wrap: wrap; gap: 8px; }
|
.extras { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||||
.extras .btn { flex: 1 1 auto; gap: 6px; padding: 0 12px; }
|
.extras .btn { flex: 1 1 auto; gap: 6px; padding: 0 12px; }
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
upload: 'M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M17 8l-5-5-5 5M12 3v12',
|
upload: 'M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M17 8l-5-5-5 5M12 3v12',
|
||||||
down: 'M6 9l6 6 6-6',
|
down: 'M6 9l6 6 6-6',
|
||||||
up: 'M6 15l6-6 6 6',
|
up: 'M6 15l6-6 6 6',
|
||||||
|
check: 'M20 6L9 17l-5-5',
|
||||||
archive: 'M3 4h18v5H3zM5 9v11h14V9M10 13h4',
|
archive: 'M3 4h18v5H3zM5 9v11h14V9M10 13h4',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ const cs: Messages = {
|
||||||
payment_short: 'Platba',
|
payment_short: 'Platba',
|
||||||
add_payment: 'Zaznamenat platbu',
|
add_payment: 'Zaznamenat platbu',
|
||||||
paid_by: 'Platil(a) {name}',
|
paid_by: 'Platil(a) {name}',
|
||||||
paid_by_many: 'Platilo {n} lidí',
|
paid_by_many: { one: '{n} plátce', few: '{n} plátci', other: '{n} plátců' },
|
||||||
your_share: 'váš podíl {amount}',
|
your_share: 'váš podíl {amount}',
|
||||||
you_lent: 'půjčili jste {amount}',
|
you_lent: 'půjčili jste {amount}',
|
||||||
you_borrowed: 'dlužíte {amount}',
|
you_borrowed: 'dlužíte {amount}',
|
||||||
|
|
@ -129,6 +129,7 @@ const cs: Messages = {
|
||||||
split_percent: 'Procenta',
|
split_percent: 'Procenta',
|
||||||
remaining: 'Zbývá: {amount}',
|
remaining: 'Zbývá: {amount}',
|
||||||
over_by: 'Přebývá: {amount}',
|
over_by: 'Přebývá: {amount}',
|
||||||
|
adds_up: 'Součet sedí',
|
||||||
select_all: 'Všichni',
|
select_all: 'Všichni',
|
||||||
select_none: 'Nikdo',
|
select_none: 'Nikdo',
|
||||||
note: 'Poznámka',
|
note: 'Poznámka',
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ const en = {
|
||||||
payment_short: 'Payment',
|
payment_short: 'Payment',
|
||||||
add_payment: 'Record a payment',
|
add_payment: 'Record a payment',
|
||||||
paid_by: 'Paid by {name}',
|
paid_by: 'Paid by {name}',
|
||||||
paid_by_many: 'Paid by {n} people',
|
paid_by_many: { one: '{n} payer', few: '{n} payers', other: '{n} payers' },
|
||||||
your_share: 'your share {amount}',
|
your_share: 'your share {amount}',
|
||||||
you_lent: 'you lent {amount}',
|
you_lent: 'you lent {amount}',
|
||||||
you_borrowed: 'you borrowed {amount}',
|
you_borrowed: 'you borrowed {amount}',
|
||||||
|
|
@ -137,6 +137,7 @@ const en = {
|
||||||
split_percent: 'Percent',
|
split_percent: 'Percent',
|
||||||
remaining: 'Remaining: {amount}',
|
remaining: 'Remaining: {amount}',
|
||||||
over_by: 'Over by: {amount}',
|
over_by: 'Over by: {amount}',
|
||||||
|
adds_up: 'Adds up to the total',
|
||||||
select_all: 'All',
|
select_all: 'All',
|
||||||
select_none: 'None',
|
select_none: 'None',
|
||||||
note: 'Note',
|
note: 'Note',
|
||||||
|
|
|
||||||
|
|
@ -143,3 +143,40 @@ test('two devices share a group end to end', async ({ browser }) => {
|
||||||
await expect(anna.getByRole('heading', { name: 'By category' })).toBeVisible();
|
await expect(anna.getByRole('heading', { name: 'By category' })).toBeVisible();
|
||||||
await expect(anna.getByRole('heading', { name: 'Paid vs. share' })).toBeVisible();
|
await expect(anna.getByRole('heading', { name: 'Paid vs. share' })).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('several people pay for one expense', async ({ browser }) => {
|
||||||
|
const p = await device(browser, 'en-US');
|
||||||
|
await p.goto('/');
|
||||||
|
await p.getByRole('link', { name: 'New group' }).click();
|
||||||
|
await p.getByLabel('Group name').fill('Shared car');
|
||||||
|
await p.getByLabel('Main currency').selectOption('CZK');
|
||||||
|
await p.getByLabel('Your name').fill('Anna');
|
||||||
|
await p.getByPlaceholder('Name').fill('Petr');
|
||||||
|
await p.getByRole('button', { name: 'Add member' }).click();
|
||||||
|
await p.getByPlaceholder('Name').nth(1).fill('Jana');
|
||||||
|
await p.getByRole('button', { name: 'Create group' }).click();
|
||||||
|
await p.getByRole('button', { name: 'Back', exact: true }).click();
|
||||||
|
|
||||||
|
await p.getByRole('link', { name: 'Add expense' }).click();
|
||||||
|
await p.getByLabel('Amount').fill('300000');
|
||||||
|
await p.getByLabel('What was it for?').fill('Car');
|
||||||
|
await p.getByLabel('Paid by', { exact: true }).selectOption({ label: 'Several people' });
|
||||||
|
await p.getByLabel('Paid by: Anna').fill('100000');
|
||||||
|
await p.getByLabel('Paid by: Petr').fill('150000');
|
||||||
|
await expect(p.getByText('Remaining: CZK 50,000.00')).toBeVisible();
|
||||||
|
// The empty box suggests what's left.
|
||||||
|
await expect(p.getByLabel('Paid by: Jana')).toHaveAttribute('placeholder', '50000.00');
|
||||||
|
await p.getByLabel('Paid by: Jana').fill('80000');
|
||||||
|
await expect(p.getByText('Over by: CZK 30,000.00')).toBeVisible();
|
||||||
|
await p.getByRole('button', { name: 'Save', exact: true }).click();
|
||||||
|
await expect(p.getByRole('alert')).toHaveText('The payers don’t add up to the amount.');
|
||||||
|
await p.getByLabel('Paid by: Jana').fill('50000');
|
||||||
|
await expect(p.getByText('Adds up to the total')).toBeVisible();
|
||||||
|
await p.getByRole('button', { name: 'Save', exact: true }).click();
|
||||||
|
|
||||||
|
await expect(p.getByRole('link', { name: /Car/ })).toContainText('3 payers');
|
||||||
|
await p.getByRole('link', { name: 'Balances' }).click();
|
||||||
|
await expect(p.getByText('+CZK 50,000.00')).toBeVisible();
|
||||||
|
await expect(p.getByText('−CZK 50,000.00')).toBeVisible();
|
||||||
|
await expect(p.getByText('Jana → Petr')).toBeVisible();
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,31 @@ describe('replay', () => {
|
||||||
expect(Object.values(bal).reduce((x, y) => x + y)).toBe(0);
|
expect(Object.values(bal).reduce((x, y) => x + y)).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('credits each of several payers (three people buy a car together)', () => {
|
||||||
|
const car = expense({
|
||||||
|
amount: 30000000,
|
||||||
|
payers: [{ member: 'a', amount: 10000000 }, { member: 'b', amount: 15000000 }, { member: 'c', amount: 5000000 }],
|
||||||
|
});
|
||||||
|
const { state } = replay([...baseGroup(), ev({ type: 'expense.created', data: car })]);
|
||||||
|
const bal = balances(state);
|
||||||
|
expect(bal).toEqual({ a: 0, b: 5000000, c: -5000000 });
|
||||||
|
expect(settleUp(bal, ['a', 'b', 'c'])).toEqual([{ from: 'c', to: 'b', amount: 5000000 }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('credits several payers in a foreign currency, summing exactly to the base total', () => {
|
||||||
|
// €100.01 at 25.1 = 2510.251 Kč → 2510.25; payer and share vectors must each sum to it.
|
||||||
|
const e = expense({
|
||||||
|
currency: 'EUR', amount: 10001, rate: '25.1',
|
||||||
|
payers: [{ member: 'a', amount: 5001 }, { member: 'b', amount: 5000 }],
|
||||||
|
});
|
||||||
|
const { state } = replay([...baseGroup(), ev({ type: 'expense.created', data: e })]);
|
||||||
|
const bal = balances(state);
|
||||||
|
expect(Object.values(bal).reduce((x, y) => x + y)).toBe(0);
|
||||||
|
expect(bal.a).toBeGreaterThan(0);
|
||||||
|
expect(bal.b).toBeGreaterThan(0);
|
||||||
|
expect(bal.c).toBeLessThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('ignores invalid expenses (bad sums, unknown members)', () => {
|
it('ignores invalid expenses (bad sums, unknown members)', () => {
|
||||||
const bad1 = expense({ id: 'x2', payers: [{ member: 'a', amount: 1 }] });
|
const bad1 = expense({ id: 'x2', payers: [{ member: 'a', amount: 1 }] });
|
||||||
const bad2 = expense({ id: 'x3', split: { mode: 'equal', entries: [{ member: 'zzz', value: 1 }] } });
|
const bad2 = expense({ id: 'x3', split: { mode: 'equal', entries: [{ member: 'zzz', value: 1 }] } });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue