Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/components/FinanceApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useCallback, useEffect, useMemo, useRef, useState, type CSSProperties } from 'react';
import { Activity, ArrowDownLeft, ArrowDownRight, ArrowLeftRight, ArrowRight, ArrowUpRight, Banknote, BarChart3, Bell, CalendarDays, Check, ChevronDown, ChevronLeft, ChevronRight, CircleHelp, CreditCard, Download, FileText, Filter, LayoutDashboard, Moon, Plus, Power, PiggyBank, Repeat2, Search, Settings, ShieldCheck, Smartphone, Sun, Target, Trash2, TrendingUp, Wallet as WalletIcon, X, type LucideIcon } from 'lucide-react';
import { Area, AreaChart, Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';
import { Budget, BUDGET_MONTH_MIN, BUDGET_MONTH_MAX, MONTHLY_BUDGET_REPEAT_MARKER, budgetsOverlap, categoryColors, digitalWalletBalances, Entry, EntryType, expenseCategories, FinanceData, goldHoldingGrams, incomeCategories, investmentMovement, InvestmentMovement, monthKey, budgetsForMonth, addDays, budgetRange, budgetSpent, countDays, monthRange, newFinanceData, Recurring, seedData, Wallet, walletBalance, walletMarketValue, isBudgetMonth, isDigitalWallet } from '@/lib/finance';
import { Budget, BUDGET_MONTH_MIN, BUDGET_MONTH_MAX, MONTHLY_BUDGET_REPEAT_MARKER, budgetsOverlap, categoryColors, digitalWalletBalances, Entry, EntryType, expenseCategories, FinanceData, goldHoldingGrams, incomeCategories, investmentMovement, InvestmentMovement, monthKey, budgetsForMonth, addDays, budgetRange, budgetSpent, countDays, monthRange, newFinanceData, Recurring, seedData, Wallet, walletBalance, walletMarketValue, isBudgetMonth } from '@/lib/finance';
import { fetchGoldQuote, GoldQuoteError, type GoldQuote } from '@/lib/gold';
import { byCategory, cashflow, byCategoryForDateRange, cashflowForDateRange, dateRangeDayCount, dateRangeMonthCount, entriesForDateRange, metrics, previousDateRange, type ReportDateRange, budgetTotals } from '@/lib/metrics';
import { compact, dateLabel, goldGrams, monthLabel, rupiah, rupiahAxisTick } from '@/lib/format';
Expand Down Expand Up @@ -1067,9 +1067,7 @@ function EditorDialog({ editor, data, period, saving, opener, onClose, onSave }:
const [color, setColor] = useState(editor.kind === 'wallet' ? editor.item?.color || '#10b981' : '#10b981');
const [hasGoal, setHasGoal] = useState(editor.kind === 'wallet' ? Boolean(editor.item?.goal) : false);
const [goalAmount, setGoalAmount] = useState(editor.kind === 'wallet' && editor.item?.goal ? String(editor.item.goal) : '');
const digitalWallets = data.wallets.filter(wallet => isDigitalWallet(wallet) && (!wallet.archived || wallet.id === currentWallet?.preferredWalletId));
const [investmentAsset, setInvestmentAsset] = useState<NonNullable<Wallet['investmentAsset']>>(editor.kind === 'wallet' ? editor.item?.investmentAsset ?? 'money' : 'money');
const [preferredWalletId, setPreferredWalletId] = useState(editor.kind === 'wallet' ? editor.item?.preferredWalletId ?? digitalWallets.find(wallet => !wallet.archived)?.id ?? '' : '');
const [frequency, setFrequency] = useState<Recurring['frequency']>(editor.kind === 'recurring' ? editor.item?.frequency || 'monthly' : 'monthly');
const editedBudget = editor.kind === 'budget' ? editor.item : undefined;
const [budgetTitle, setBudgetTitle] = useState(editedBudget?.title || '');
Expand All @@ -1096,7 +1094,7 @@ function EditorDialog({ editor, data, period, saving, opener, onClose, onSave }:
if (investment && hasGoal && goalValue <= 0) { setError('Isi target dana goal.'); return; }
const newWalletId = editor.item?.id || id();
const initialEntry = !current && !investment && value > 0 ? { type: 'income' as const, amount: value, walletId: newWalletId, category: 'Lainnya', title: 'Saldo Awal', note: '', date: today() } : undefined;
onSave({ id: newWalletId, name: title.trim(), type: investment ? 'investment' : walletType, openingBalance: 0, color, archived: editor.item?.archived || false, goal: investment && hasGoal ? goalValue : undefined, investmentAsset: investment ? investmentAsset : undefined, preferredWalletId: investment ? (investmentAsset === 'gold' ? currentWallet?.preferredWalletId : preferredWalletId || undefined) : undefined }, initialEntry);
onSave({ id: newWalletId, name: title.trim(), type: investment ? 'investment' : walletType, openingBalance: 0, color, archived: editor.item?.archived || false, goal: investment && hasGoal ? goalValue : undefined, investmentAsset: investment ? investmentAsset : undefined, preferredWalletId: investment ? currentWallet?.preferredWalletId : undefined }, initialEntry);
} else if (editor.kind === 'budget') {
if (budgetMode === 'cycle' && !isBudgetMonth(startMonth)) {
setError('Pilih bulan mulai antara Januari 1900 dan Desember 2199, misalnya 2026-12.');
Expand Down Expand Up @@ -1131,7 +1129,6 @@ function EditorDialog({ editor, data, period, saving, opener, onClose, onSave }:
</label>
</div>}
{investment && !current && <label>Jenis simpanan<select value={investmentAsset} onChange={event => setInvestmentAsset(event.target.value as NonNullable<Wallet['investmentAsset']>)}><option value="money">Simpanan rupiah</option><option value="gold">Tabungan emas</option></select><small className="small-note">Jenis tidak bisa diubah setelah simpanan dibuat.</small></label>}
{investment && investmentAsset !== 'gold' && <label>Dompet digital untuk transfer<select value={preferredWalletId} onChange={event => setPreferredWalletId(event.target.value)}><option value="">Pilih dompet (opsional)</option>{digitalWallets.map(wallet => <option key={wallet.id} value={wallet.id}>{wallet.name}{wallet.archived ? ' (diarsipkan)' : ''}</option>)}</select><small className="small-note">Setoran akan mengurangi saldo dompet ini. Pilihan ini menjadi dompet awal untuk transfer berikutnya.</small></label>}
{investment && hasGoal && <label>Target dana<div className="amount-input"><span>Rp</span><MoneyInput value={goalAmount} onValueChange={setGoalAmount} label="Target nominal goal" /></div></label>}
{editor.kind === 'wallet' && !investment && !current && <label>Saldo awal (opsional)<div className="amount-input"><span>Rp</span><MoneyInput value={amount} onValueChange={setAmount} label="Saldo awal dompet" /></div><p className="small-note">Akan otomatis dicatat sebagai transaksi pemasukan "Saldo Awal".</p></label>}
{!investment && editor.kind !== 'wallet' && <label>{editor.kind === 'budget' ? 'Batas anggaran' : 'Nominal'}<div className="amount-input"><span>Rp</span><MoneyInput value={amount} onValueChange={setAmount} label="Nominal rupiah" /></div></label>}
Expand Down
7 changes: 2 additions & 5 deletions src/components/Investments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export function SavingsCards({ data, onCreate, onRename, onRemove, onTransfer, o
</div>)}
</dl>
</div>}
{!gold && wallet.preferredWalletId && <p className="small-note">Dompet pilihan: {names.get(wallet.preferredWalletId) ?? 'Tidak tersedia'}</p>}
{wallet.goal ? (gold && !goldQuote ? <p className="small-note">Target {rupiah(wallet.goal)} · menunggu harga emas</p> : <GoalBar balance={marketValue} goal={wallet.goal} />) : <p className="small-note">Belum ada goal. Ubah simpanan untuk mengatur target.</p>}
<div className="savings-actions">
<MotionButton className="button button-dark" disabled={!gold && !canDeposit} onClick={() => onTransfer({ investmentId: wallet.id, direction: 'deposit' })}>
Expand Down Expand Up @@ -244,9 +243,7 @@ function LegacyInvestmentTransferDialog({ movement, entry, data, initialDate, sa
const previousWalletId = deposit ? entry?.walletId : entry?.targetWalletId;
const wallets = data.wallets.filter(wallet => isDigitalWallet(wallet) && (!wallet.archived || wallet.id === previousWalletId));
const preferredWalletId = investment?.preferredWalletId && wallets.some(wallet => wallet.id === investment.preferredWalletId) ? investment.preferredWalletId : undefined;
const [walletId, setWalletId] = useState(() => previousWalletId ?? preferredWalletId ?? (
deposit ? wallets.find(wallet => walletBalance(data, wallet.id) > 0)?.id : wallets[0]?.id
) ?? '');
const [walletId, setWalletId] = useState(() => previousWalletId ?? (deposit ? '' : preferredWalletId ?? wallets[0]?.id ?? ''));
const [amount, setAmount] = useState(entry ? String(entry.amount) : '');
const [grams, setGrams] = useState(entry?.investmentGrams ? formatGramInput(entry.investmentGrams) : '');
const [date, setDate] = useState(entry?.date ?? initialDate);
Expand Down Expand Up @@ -356,7 +353,7 @@ function LegacyInvestmentTransferDialog({ movement, entry, data, initialDate, sa
<span className="savings-available" id={balanceId}>{gold ? deposit
? `Saldo dompet tersedia ${rupiah(Math.max(available, 0))}`
: `Emas tersedia ${goldHoldingGrams(data, movement.investmentId, entry?.id).toLocaleString('id-ID', { maximumFractionDigits: 6 })} gram · nilai spot ${rupiah(goldHoldingGrams(data, movement.investmentId, entry?.id) * (spot ?? 0))}`
: `Saldo tersedia ${rupiah(Math.max(available, 0))}`}</span>
: deposit && !walletId ? 'Pilih dompet untuk melihat saldo tersedia.' : `Saldo tersedia ${rupiah(Math.max(available, 0))}`}</span>
<label>Tanggal<input type="date" value={date} onChange={event => setDate(event.target.value)} required /></label>
<p className="savings-available">Untuk rekening bank dan e-wallet, lakukan transfer di aplikasi penyedia lalu catat di FinTrack.</p>
</EditorModal>;
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/finance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,18 +508,24 @@ test('simpanan dapat diisi dari bank dan ditarik ke e-wallet tanpa menghitungnya
await expect(page).toHaveURL(/\/investments$/);
await page.getByRole('button', { name: 'Buat simpanan pertama' }).click();
await page.getByLabel('Nama simpanan').fill('Dana darurat');
await expect(page.getByRole('dialog').getByLabel(/dompet/i)).toHaveCount(0);
await page.getByRole('button', { name: 'Simpan Simpanan' }).click();
const savings = page.getByRole('article').filter({ hasText: 'Dana darurat' });
await expect(savings.getByRole('button', { name: 'Tarik', exact: true })).toBeDisabled();
await savings.getByRole('button', { name: 'Setor', exact: true }).click();
let dialog = page.getByRole('dialog');
await expect(dialog.getByLabel('Dompet sumber')).toHaveValue('');
await expect(dialog.getByText('Pilih dompet untuk melihat saldo tersedia.')).toBeVisible();
await dialog.getByLabel('Dompet sumber').selectOption('bca');
await dialog.getByLabel(/Nominal rupiah/).fill('1000000000');
await dialog.getByRole('button', { name: 'Setor dana' }).click();
await expect(dialog.getByRole('alert')).toHaveText('Saldo dompet asal tidak cukup.');
await dialog.getByLabel(/Nominal rupiah/).fill('500000');
await dialog.getByRole('button', { name: 'Setor dana' }).click();
await expect(savings).toContainText(/Rp\s*500\.000/);
await savings.getByRole('button', { name: 'Setor', exact: true }).click();
await expect(dialog.getByLabel('Dompet sumber')).toHaveValue('');
await dialog.getByRole('button', { name: 'Batal' }).click();
await savings.getByRole('button', { name: 'Tarik', exact: true }).click();
dialog = page.getByRole('dialog');
await dialog.getByLabel('Dompet tujuan').selectOption('gopay');
Expand Down
Loading