+ {visible.map((lead) => {
+ const subtitle = lead.next_action
+ ? lead.next_action
+ : [lead.company, relativeDays(lead.last_contact_date)].filter(Boolean).join(" — ");
+ return (
-
- {initials(lead.name)}
-
-
-
{lead.name}
-
- {lead.next_action
- ? lead.next_action
- : [lead.company, relativeDays(lead.last_contact_date)]
- .filter(Boolean)
- .join(" · ")}
-
+
+
{lead.name}
+
{subtitle}
-
- Contatta →
+
+ Apri →
-
- ))}
-
+ );
+ })}
+
{leads.length > MAX_ROWS && (
Vedi tutti i {leads.length} lead
diff --git a/src/lib/dashboard-queries.ts b/src/lib/dashboard-queries.ts
index e2cafc3..7469314 100644
--- a/src/lib/dashboard-queries.ts
+++ b/src/lib/dashboard-queries.ts
@@ -1,9 +1,10 @@
import { db } from "@/db";
import { clients, projects, payments } from "@/db/schema";
-import { eq, sum, count } from "drizzle-orm";
+import { eq, sum, count, sql } from "drizzle-orm";
export type KpiStats = {
clientiAttivi: number;
+ clientiNuoviMese: number; // clients created in the current calendar month
revenueTotale: string; // sum of projects.accepted_total (non-archived)
pagamentiInSospeso: string; // sum of payments.amount where status = 'da_saldare' or 'inviata'
progettiInCorso: number; // projects not archived
@@ -20,6 +21,13 @@ export async function getDashboardStats(): Promise
{
.from(clients)
.where(eq(clients.archived, false));
+ const [clientiNuoviMeseRow] = await db
+ .select({ count: count() })
+ .from(clients)
+ .where(
+ sql`date_trunc('month', ${clients.created_at}) = date_trunc('month', now())`
+ );
+
const [revenueRow] = await db
.select({ total: sum(projects.accepted_total) })
.from(projects)
@@ -46,6 +54,7 @@ export async function getDashboardStats(): Promise {
const kpi: KpiStats = {
clientiAttivi: clientiAttiviRow?.count ?? 0,
+ clientiNuoviMese: clientiNuoviMeseRow?.count ?? 0,
revenueTotale: revenueRow?.total ?? "0",
pagamentiInSospeso: pagamentiSospeso.toFixed(2),
progettiInCorso: progettiRow?.count ?? 0,