feat: build dashboard reporting #1

Merged
kdaniel2410 merged 6 commits from codex/dashboard-reporting into main 2026-06-25 10:59:28 +00:00
3 changed files with 20 additions and 11 deletions
Showing only changes of commit 44165e39b1 - Show all commits
+12 -9
View File
@@ -52,7 +52,7 @@ export const load: PageServerLoad = async ({ locals }) => {
const soonDate = dateOnly(addDays(today, 60));
const monthStart = dateOnly(startOfMonth(today));
const monthEnd = dateOnly(endOfMonth(today));
const sixMonthsAgo = startOfMonth(addMonths(today, -5));
const currentTrendStart = startOfMonth(addMonths(today, -5));
const activeContractCondition = and(
eq(contracts.organizationId, activeOrganizationId),
@@ -202,13 +202,7 @@ export const load: PageServerLoad = async ({ locals }) => {
totalGbp: invoices.totalGbp
})
.from(invoices)
.where(
and(
eq(invoices.organizationId, activeOrganizationId),
gte(invoices.issueDate, dateOnly(sixMonthsAgo)),
isNull(invoices.archivedAt)
)
)
.where(and(eq(invoices.organizationId, activeOrganizationId), isNull(invoices.archivedAt)))
]);
const activeContractIds = activeContractRows.map((contract) => contract.id);
@@ -292,9 +286,17 @@ export const load: PageServerLoad = async ({ locals }) => {
roomTypes.set(room.type, summary);
}
const hasCurrentTrendInvoices = billingTrendInvoiceRows.some(
(invoice) => parseISO(invoice.issueDate).getTime() >= currentTrendStart.getTime()
);
const trendEnd =
hasCurrentTrendInvoices || recentInvoiceRows.length === 0
? today
: parseISO(recentInvoiceRows[0].issueDate);
const trendStart = startOfMonth(addMonths(trendEnd, -5));
const billingTrendMap = new Map<string, { month: string; label: string; totalGbp: number }>();
for (let index = 0; index < 6; index += 1) {
const month = addMonths(sixMonthsAgo, index);
const month = addMonths(trendStart, index);
billingTrendMap.set(monthKey(month), {
month: monthKey(month),
label: monthLabel(month),
@@ -341,6 +343,7 @@ export const load: PageServerLoad = async ({ locals }) => {
recentInvoices: recentInvoiceRows,
meta: {
monthLabel: monthLabel(today),
billingTrendDescription: `Issued invoice totals from ${monthLabel(trendStart)} to ${monthLabel(trendEnd)}.`,
overdueInvoiceBasis:
'Invoices have no payment status yet, so this shows invoices past due date.'
}
+5 -1
View File
@@ -24,7 +24,11 @@
<MetricCards metrics={data.metrics} monthLabel={data.meta.monthLabel} {formatMoney} />
<div class="grid gap-4 xl:grid-cols-2">
<BillingTrend records={data.billingTrend} {formatMoney} />
<BillingTrend
records={data.billingTrend}
description={data.meta.billingTrendDescription}
{formatMoney}
/>
<RoomSummary metrics={data.metrics} summary={data.roomSummary} />
</div>
+3 -1
View File
@@ -6,9 +6,11 @@
let {
records,
description,
formatMoney
}: {
records: PageData['billingTrend'];
description: string;
formatMoney: (value: unknown) => string;
} = $props();
@@ -19,7 +21,7 @@
<Card.Root>
<Card.Header>
<Card.Title>Billing trend</Card.Title>
<Card.Description>Issued invoice totals over the last six months.</Card.Description>
<Card.Description>{description}</Card.Description>
</Card.Header>
<Card.Content>
{#if hasValues}