diff --git a/src/app/admin/clients/[id]/actions.ts b/src/app/admin/clients/[id]/actions.ts
index a5b8229..24bdece 100644
--- a/src/app/admin/clients/[id]/actions.ts
+++ b/src/app/admin/clients/[id]/actions.ts
@@ -289,6 +289,25 @@ export async function updatePaymentStatus(paymentId: string, id: string, status:
revalidatePath(path);
}
+// Imposta il mese in cui un pagamento Γ¨ stato incassato (formato "YYYY-MM").
+// Mappa al primo giorno del mese (mezzogiorno UTC per evitare drift di fuso) e
+// porta lo stato a "saldato" così l'incasso viene attribuito a quel mese nelle analytics.
+export async function setPaymentPaidAt(paymentId: string, id: string, monthStr: string) {
+ await requireAdmin();
+ const m = /^(\d{4})-(\d{2})$/.exec(monthStr);
+ if (!m) throw new Error("Mese non valido");
+ const year = parseInt(m[1], 10);
+ const month = parseInt(m[2], 10);
+ if (month < 1 || month > 12) throw new Error("Mese non valido");
+ const paid_at = new Date(Date.UTC(year, month - 1, 1, 12, 0, 0));
+ await db
+ .update(payments)
+ .set({ paid_at, status: "saldato" })
+ .where(eq(payments.id, paymentId));
+ const { path } = await resolveEntity(id);
+ revalidatePath(path);
+}
+
// Rescales payment amounts when the total changes.
// If the payment has a `percent` field, use it (new plan rows).
// Legacy rows (percent null) fall back to equal split across all rows.
diff --git a/src/app/admin/clients/[id]/page.tsx b/src/app/admin/clients/[id]/page.tsx
index b3f8794..c69b636 100644
--- a/src/app/admin/clients/[id]/page.tsx
+++ b/src/app/admin/clients/[id]/page.tsx
@@ -130,19 +130,40 @@ export default async function ClientDetailPage({
Offerte Attive ({activeOffers.length})