mirror of
https://github.com/Zproger/Aurum.git
synced 2026-11-18 08:02:49 +07:00
Initial public release
Aurum — a self-hosted personal finance operating system: cash flow, net worth tracking, budgets, goals, recurring payments, reports, proactive alerts, and a compound-interest returns calculator, all bilingual (RU/EN) and mobile-first. Ships as a three-container Docker Compose stack (Postgres + FastAPI + nginx-served React frontend). See README.md for setup and CONTRIBUTING.md for development.
This commit is contained in:
87
frontend/src/components/roi/RoiCalculatorCard.tsx
Normal file
87
frontend/src/components/roi/RoiCalculatorCard.tsx
Normal file
@@ -0,0 +1,87 @@
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card";
|
||||
import { Input, Label } from "@/components/ui/Input";
|
||||
import { useTranslation } from "@/lib/i18n";
|
||||
|
||||
interface RoiCalculatorCardProps {
|
||||
investment: string;
|
||||
onInvestmentChange: (value: string) => void;
|
||||
monthlyIncome: string;
|
||||
onMonthlyIncomeChange: (value: string) => void;
|
||||
annualRoiPercent: number | null;
|
||||
paybackYears: number | null;
|
||||
}
|
||||
|
||||
/** Quick "is this a good deal" check — purchase price + expected monthly
|
||||
* income in, annual return % and payback period out. Purely a scratchpad:
|
||||
* not tied to any Asset, doesn't persist, doesn't read anything else you've
|
||||
* tracked in the app — only these two numbers. Same formula AssetsTable
|
||||
* already shows inline for assets that have monthly_cash_flow set, just
|
||||
* usable before you've committed to adding one. The multi-year, compound-
|
||||
* interest projection built from these same numbers lives in
|
||||
* RoiProjectionCard, rendered alongside this one on RoiPage. */
|
||||
export function RoiCalculatorCard({
|
||||
investment,
|
||||
onInvestmentChange,
|
||||
monthlyIncome,
|
||||
onMonthlyIncomeChange,
|
||||
annualRoiPercent,
|
||||
paybackYears,
|
||||
}: RoiCalculatorCardProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t("roi.calculator.title")}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<Label htmlFor="roi-investment">{t("roi.calculator.investmentLabel")}</Label>
|
||||
<Input
|
||||
id="roi-investment"
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
placeholder="100000"
|
||||
value={investment}
|
||||
onChange={(event) => onInvestmentChange(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="roi-income">{t("roi.calculator.monthlyIncomeLabel")}</Label>
|
||||
<Input
|
||||
id="roi-income"
|
||||
type="number"
|
||||
step="0.01"
|
||||
placeholder="830"
|
||||
value={monthlyIncome}
|
||||
onChange={(event) => onMonthlyIncomeChange(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{annualRoiPercent === null ? (
|
||||
<p className="text-xs text-text-muted">{t("roi.calculator.hint")}</p>
|
||||
) : (
|
||||
<div className="rounded-lg bg-surface-2 p-3.5">
|
||||
<p className="text-xs font-semibold uppercase tracking-wide text-text-muted">
|
||||
{t("roi.calculator.annualRoiLabel")}
|
||||
</p>
|
||||
<p
|
||||
className="mt-1 text-2xl font-semibold tabular-nums"
|
||||
style={{ color: annualRoiPercent >= 0 ? "var(--success)" : "var(--danger)" }}
|
||||
>
|
||||
{annualRoiPercent.toFixed(1)}%
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-text-muted">
|
||||
{paybackYears !== null
|
||||
? t("roi.calculator.payback", { years: paybackYears.toFixed(1) })
|
||||
: t("roi.calculator.noPayback")}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
162
frontend/src/components/roi/RoiProjectionCard.tsx
Normal file
162
frontend/src/components/roi/RoiProjectionCard.tsx
Normal file
@@ -0,0 +1,162 @@
|
||||
import { Legend, Line, LineChart, ResponsiveContainer, Tooltip, XAxis } from "recharts";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card";
|
||||
import { formatCurrency } from "@/lib/format";
|
||||
import { useTranslation } from "@/lib/i18n";
|
||||
|
||||
interface RoiProjectionCardProps {
|
||||
investmentAmount: number;
|
||||
annualIncome: number;
|
||||
annualRoiPercent: number;
|
||||
}
|
||||
|
||||
const CHART_MAX_YEARS = 30;
|
||||
const CHART_TICKS = [0, 5, 10, 15, 20, 25, 30];
|
||||
const TABLE_YEARS = [1, 5, 10, 20, 30];
|
||||
|
||||
interface ChartPoint {
|
||||
year: number;
|
||||
compound: number;
|
||||
simple: number;
|
||||
}
|
||||
|
||||
function ChartTooltip({
|
||||
active,
|
||||
payload,
|
||||
compoundLabel,
|
||||
simpleLabel,
|
||||
}: {
|
||||
active?: boolean;
|
||||
payload?: Array<{ payload: ChartPoint }>;
|
||||
compoundLabel: string;
|
||||
simpleLabel: string;
|
||||
}) {
|
||||
if (!active || !payload?.length) return null;
|
||||
const point = payload[0].payload;
|
||||
return (
|
||||
<div className="rounded-lg border border-border bg-surface-1 px-3 py-2 text-sm shadow-md">
|
||||
<p className="text-text-muted">{point.year}</p>
|
||||
<p className="font-medium" style={{ color: "var(--series-1)" }}>
|
||||
{compoundLabel}: {formatCurrency(point.compound)}
|
||||
</p>
|
||||
<p className="text-text-muted">
|
||||
{simpleLabel}: {formatCurrency(point.simple)}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Everything here is derived only from the two numbers typed into
|
||||
* RoiCalculatorCard (investment amount, monthly income) — no data from
|
||||
* Asset/AssetValuation or anywhere else in the app. Two scenarios,
|
||||
* compounded annually from the same starting point:
|
||||
* compound(year) = investment × (1 + annualRoiPercent)^year — the whole
|
||||
* annual return (rent/dividends) is assumed reinvested back into the
|
||||
* same investment every year, so next year's return is earned on a
|
||||
* larger base too.
|
||||
* simple(year) = investment + annualIncome × year — the investment
|
||||
* itself never grows, income is just set aside in cash each year.
|
||||
* The gap between the two lines *is* what compounding is worth. */
|
||||
export function RoiProjectionCard({ investmentAmount, annualIncome, annualRoiPercent }: RoiProjectionCardProps) {
|
||||
const { t } = useTranslation();
|
||||
const rate = annualRoiPercent / 100;
|
||||
const compoundLabel = t("roi.calculator.chartCompoundLabel");
|
||||
const simpleLabel = t("roi.calculator.chartSimpleLabel");
|
||||
|
||||
const chartData: ChartPoint[] = Array.from({ length: CHART_MAX_YEARS + 1 }, (_, year) => ({
|
||||
year,
|
||||
compound: investmentAmount * Math.pow(1 + rate, year),
|
||||
simple: investmentAmount + annualIncome * year,
|
||||
}));
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t("roi.calculator.projectionTitle")}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-5">
|
||||
<p className="text-xs text-text-muted">{t("roi.calculator.projectionHint", { percent: annualRoiPercent.toFixed(1) })}</p>
|
||||
|
||||
<div className="h-56 w-full sm:h-64">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart data={chartData} margin={{ top: 8, right: 4, bottom: 0, left: 4 }}>
|
||||
<XAxis
|
||||
dataKey="year"
|
||||
type="number"
|
||||
domain={[0, CHART_MAX_YEARS]}
|
||||
ticks={CHART_TICKS}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
tick={{ fill: "var(--text-muted)", fontSize: 11 }}
|
||||
/>
|
||||
<Tooltip content={<ChartTooltip compoundLabel={compoundLabel} simpleLabel={simpleLabel} />} cursor={{ stroke: "var(--gridline)", strokeWidth: 1 }} />
|
||||
<Legend
|
||||
verticalAlign="top"
|
||||
height={24}
|
||||
formatter={(value) => (value === "compound" ? compoundLabel : simpleLabel)}
|
||||
wrapperStyle={{ fontSize: 12, color: "var(--text-muted)" }}
|
||||
/>
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="compound"
|
||||
stroke="var(--series-1)"
|
||||
strokeWidth={2}
|
||||
dot={false}
|
||||
isAnimationActive={false}
|
||||
/>
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="simple"
|
||||
stroke="var(--text-muted)"
|
||||
strokeWidth={2}
|
||||
strokeDasharray="4 4"
|
||||
dot={false}
|
||||
isAnimationActive={false}
|
||||
/>
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="text-xs font-semibold uppercase tracking-wide text-text-muted">{t("roi.calculator.tableTitle")}</p>
|
||||
<ul className="mt-2 divide-y divide-gridline">
|
||||
<li className="flex items-center gap-3 py-2 text-xs font-medium text-text-muted">
|
||||
<span className="flex-1" />
|
||||
<span className="w-28 shrink-0 text-right">{t("roi.calculator.colCompound")}</span>
|
||||
<span className="hidden w-28 shrink-0 text-right sm:block">{t("roi.calculator.colSimple")}</span>
|
||||
<span className="w-24 shrink-0 text-right">{t("roi.calculator.colDifference")}</span>
|
||||
</li>
|
||||
{TABLE_YEARS.map((year) => {
|
||||
const compound = investmentAmount * Math.pow(1 + rate, year);
|
||||
const simple = investmentAmount + annualIncome * year;
|
||||
// Rounded to the cent before comparing sign — compound and simple
|
||||
// agree exactly in year 1, but Math.pow's floating-point error
|
||||
// can leave a sub-cent residue. `|| 0` also normalizes -0 (which
|
||||
// is >= 0 but still formats as "-$0") to a plain positive 0.
|
||||
const difference = Math.round((compound - simple) * 100) / 100 || 0;
|
||||
return (
|
||||
<li key={year} className="flex items-center gap-3 py-2.5">
|
||||
<span className="flex-1 text-sm text-text-secondary">
|
||||
{year === 1 ? t("roi.calculator.yearOne") : t("roi.calculator.yearN", { years: year })}
|
||||
</span>
|
||||
<span className="w-28 shrink-0 text-right text-sm font-medium tabular-nums text-text-primary">
|
||||
{formatCurrency(compound)}
|
||||
</span>
|
||||
<span className="hidden w-28 shrink-0 text-right text-sm tabular-nums text-text-muted sm:block">
|
||||
{formatCurrency(simple)}
|
||||
</span>
|
||||
<span
|
||||
className="w-24 shrink-0 text-right text-sm tabular-nums"
|
||||
style={{ color: difference >= 0 ? "var(--success)" : "var(--danger)" }}
|
||||
>
|
||||
{difference >= 0 ? "+" : ""}
|
||||
{formatCurrency(difference)}
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user