feat: add initial balance support to accounts, enhancing account management and balance calculations across components

This commit is contained in:
Julien Froidefond
2025-11-30 12:13:02 +01:00
parent c26ba9ddc6
commit 184a073bb1
13 changed files with 117 additions and 30 deletions

View File

@@ -14,6 +14,7 @@ import Link from "next/link";
import type { Account, Folder } from "@/lib/types";
import { accountTypeIcons, accountTypeLabels } from "./constants";
import { Checkbox } from "@/components/ui/checkbox";
import { getAccountBalance } from "@/lib/account-utils";
interface AccountCardProps {
account: Account;
@@ -37,10 +38,11 @@ export function AccountCard({
onSelect,
}: AccountCardProps) {
const Icon = accountTypeIcons[account.type];
const realBalance = getAccountBalance(account);
return (
<Card className={cn("relative", isSelected && "ring-2 ring-primary")}>
<CardHeader className="pb-1.5">
<CardHeader className="pb-0">
<div className="flex items-start justify-between">
<div className="flex items-center gap-2 flex-1">
{onSelect && (
@@ -89,14 +91,14 @@ export function AccountCard({
</DropdownMenu>
</div>
</CardHeader>
<CardContent className="pt-1.5">
<CardContent className="pt-1">
<div
className={cn(
"text-xl font-bold mb-1.5",
account.balance >= 0 ? "text-emerald-600" : "text-red-600"
realBalance >= 0 ? "text-emerald-600" : "text-red-600"
)}
>
{formatCurrency(account.balance)}
{formatCurrency(realBalance)}
</div>
<div className="flex items-center justify-between text-xs text-muted-foreground">
<Link

View File

@@ -24,6 +24,7 @@ interface AccountFormData {
type: Account["type"];
folderId: string;
externalUrl: string;
initialBalance: number;
}
interface AccountEditDialogProps {
@@ -99,6 +100,24 @@ export function AccountEditDialog({
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label>Solde initial</Label>
<Input
type="number"
step="0.01"
value={formData.initialBalance}
onChange={(e) =>
onFormDataChange({
...formData,
initialBalance: parseFloat(e.target.value) || 0,
})
}
placeholder="0.00"
/>
<p className="text-xs text-muted-foreground">
Solde de départ pour équilibrer le compte
</p>
</div>
<div className="space-y-2">
<Label>Lien externe (portail banque)</Label>
<Input