feat(reports): financial hasData existence flag (service + route)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-02 10:13:42 +02:00
parent 8b7099c4c1
commit 58203ca8ea
2 changed files with 24 additions and 0 deletions

View File

@@ -630,3 +630,23 @@ export async function getExpenseLedger(
}
return out;
}
/**
* Window-independent existence check: does this port have any payment OR
* expense? Drives the Financial report-level empty state.
*/
export async function financialHasData(portId: string): Promise<boolean> {
const [pay, exp] = await Promise.all([
db
.select({ one: sql<number>`1` })
.from(payments)
.where(eq(payments.portId, portId))
.limit(1),
db
.select({ one: sql<number>`1` })
.from(expenses)
.where(eq(expenses.portId, portId))
.limit(1),
]);
return pay.length > 0 || exp.length > 0;
}