From 900f3c1d5848bb848d99288eb16c2cafcb259901 Mon Sep 17 00:00:00 2001 From: Yugonito Date: Tue, 27 Oct 2026 21:40:53 +0100 Subject: [PATCH] feat: spread an annual amount over 12 monthly entries, add Dividendes category Co-Authored-By: Claude Opus 5.5 --- prisma/seed.ts | 1 + src/components/OperationForm.tsx | 33 ++++++++++++++++++++++--- src/server/services/operations.ts | 28 +++++++++++++++++++++- tests/server/operations.test.ts | 40 +++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 4 deletions(-) diff --git a/prisma/seed.ts b/prisma/seed.ts index 9396fdc..8fc2d12 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -23,6 +23,7 @@ const CATEGORIES: { name: string; emoji: string; kind: OpKind }[] = [ { name: "Remboursement employeur", emoji: "🧾", kind: "INCOME" }, { name: "IK", emoji: "🚗", kind: "INCOME" }, { name: "Prime", emoji: "💶", kind: "INCOME" }, + { name: "Dividendes", emoji: "📈", kind: "INCOME" }, { name: "Autres revenus", emoji: "➕", kind: "INCOME" }, ]; diff --git a/src/components/OperationForm.tsx b/src/components/OperationForm.tsx index 86a8f68..13a148e 100644 --- a/src/components/OperationForm.tsx +++ b/src/components/OperationForm.tsx @@ -2,7 +2,7 @@ import { useRouter } from "next/navigation"; import { useMemo, useState, useTransition } from "react"; -import { bpToPercentLabel, fullSplit, parseEuro, validateSplit } from "@/domain/money"; +import { bpToPercentLabel, formatEuro, fullSplit, parseEuro, validateSplit } from "@/domain/money"; import type { AllocationMode, Frequency, OpKind, Split } from "@/domain/types"; import { deleteOperationAction, saveOperationAction } from "@/server/actions/operations"; import { CustomSplitFields } from "./CustomSplitFields"; @@ -89,6 +89,7 @@ export function OperationForm({ const [chargeKey, setChargeKey] = useState(initial?.chargeKey ?? ""); const [allocationMode, setAllocationMode] = useState(initial?.allocationMode ?? "REDUCE_SHARED"); const [recurring, setRecurring] = useState(false); + const [spread, setSpread] = useState(false); const [frequency, setFrequency] = useState("MONTHLY"); const [endDate, setEndDate] = useState(""); const [showMore, setShowMore] = useState( @@ -162,6 +163,7 @@ export function OperationForm({ allocatedToOperationId: allocated && chargeKey.startsWith("o:") ? chargeKey.slice(2) : null, allocationMode: allocated ? allocationMode : null, makeRecurring: !initial && recurring ? { frequency, endDate: endDate || null } : undefined, + spreadOverYear: !initial && spread, }); if (!result.ok) return setError(result.error); router.push(returnTo); @@ -258,7 +260,7 @@ export function OperationForm({ {showMore && ( @@ -270,11 +272,36 @@ export function OperationForm({ {!initial && (
+ + {spread && ( +

+ {(() => { + const cents = parseEuro(amount); + return cents && cents >= 12 + ? `12 entrées de ${formatEuro(Math.floor(cents / 12))} par mois à partir de la date choisie, comme un revenu mensuel.` + : "Saisissez le montant de l'année : il sera réparti en 12 mois à partir de la date choisie."; + })()} +

+ )}