Fix admin billing status chart limited to invoices created this month.
Deploy Ladill Care / deploy (push) Successful in 1m23s
Deploy Ladill Care / deploy (push) Successful in 1m23s
Show the current invoice book by status so Paid/Partial are not hidden when create dates fall outside MTD. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -134,9 +134,8 @@ class AdminOverviewService
|
||||
->select('status', DB::raw('count(*) as total'))
|
||||
->groupBy('status')
|
||||
->orderByDesc('total')
|
||||
->get();
|
||||
|
||||
$statusLabels = config('care.appointment_statuses', []);
|
||||
->get()
|
||||
->keyBy('status');
|
||||
|
||||
$completionRate = $period['total'] > 0
|
||||
? round(($period['completed'] / $period['total']) * 100, 1)
|
||||
@@ -159,6 +158,14 @@ class AdminOverviewService
|
||||
];
|
||||
}
|
||||
|
||||
$appointmentStatusRows = collect(config('care.appointment_statuses', []))
|
||||
->map(fn (string $label, string $status) => [
|
||||
'label' => $label,
|
||||
'value' => (int) ($byStatus->get($status)?->total ?? 0),
|
||||
])
|
||||
->values()
|
||||
->all();
|
||||
|
||||
return [
|
||||
'period_label' => 'This month',
|
||||
'from' => $from->toDateString(),
|
||||
@@ -174,10 +181,7 @@ class AdminOverviewService
|
||||
'breakdowns' => [
|
||||
[
|
||||
'title' => 'Appointments by status (this month)',
|
||||
'rows' => $this->pctRows($byStatus->map(fn ($row) => [
|
||||
'label' => $statusLabels[$row->status] ?? str_replace('_', ' ', (string) $row->status),
|
||||
'value' => (int) $row->total,
|
||||
])->all(), $period['total']),
|
||||
'rows' => $this->pctRows($appointmentStatusRows, $period['total']),
|
||||
],
|
||||
],
|
||||
'alerts' => $alerts,
|
||||
@@ -301,17 +305,47 @@ class AdminOverviewService
|
||||
$period = $this->reports->financeReport($ownerRef, $organization->id, $from, $to, $branchId);
|
||||
$today = $this->reports->dashboardStats($ownerRef, $organization->id, $branchId, true);
|
||||
|
||||
// Current book by status (not limited to invoices created this month —
|
||||
// MTD create-date filtering made demos look like "100% Open").
|
||||
$byStatus = Bill::owned($ownerRef)
|
||||
->where('organization_id', $organization->id)
|
||||
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))
|
||||
->where('status', '!=', Bill::STATUS_VOID)
|
||||
->whereBetween('created_at', [$from, $to])
|
||||
->select('status', DB::raw('count(*) as total'), DB::raw('sum(balance_minor) as balance'))
|
||||
->groupBy('status')
|
||||
->orderByDesc('total')
|
||||
->get();
|
||||
->get()
|
||||
->keyBy('status');
|
||||
|
||||
$statusLabels = config('care.bill_statuses', []);
|
||||
$statusOrder = [
|
||||
Bill::STATUS_OPEN,
|
||||
Bill::STATUS_PARTIAL,
|
||||
Bill::STATUS_PAID,
|
||||
Bill::STATUS_DRAFT,
|
||||
];
|
||||
$statusTotal = (int) $byStatus->sum(fn ($row) => (int) $row->total);
|
||||
$statusRows = [];
|
||||
foreach ($statusOrder as $status) {
|
||||
if (! array_key_exists($status, $statusLabels) && ! $byStatus->has($status)) {
|
||||
continue;
|
||||
}
|
||||
$count = (int) ($byStatus->get($status)?->total ?? 0);
|
||||
$statusRows[] = [
|
||||
'label' => $statusLabels[$status] ?? $status,
|
||||
'value' => $count,
|
||||
];
|
||||
}
|
||||
foreach ($byStatus as $status => $row) {
|
||||
if (in_array($status, $statusOrder, true)) {
|
||||
continue;
|
||||
}
|
||||
$statusRows[] = [
|
||||
'label' => $statusLabels[$status] ?? (string) $status,
|
||||
'value' => (int) $row->total,
|
||||
];
|
||||
}
|
||||
|
||||
$currency = strtoupper((string) config('care.billing.currency', config('care.currency', 'GHS')));
|
||||
$money = fn (int $minor) => $currency.' '.number_format($minor / 100, 2);
|
||||
|
||||
@@ -341,11 +375,8 @@ class AdminOverviewService
|
||||
],
|
||||
'breakdowns' => [
|
||||
[
|
||||
'title' => 'Invoices by status (this month)',
|
||||
'rows' => $this->pctRows($byStatus->map(fn ($row) => [
|
||||
'label' => $statusLabels[$row->status] ?? (string) $row->status,
|
||||
'value' => (int) $row->total,
|
||||
])->all(), $period['invoice_count']),
|
||||
'title' => 'Invoices by status (current book)',
|
||||
'rows' => $this->pctRows($statusRows, $statusTotal),
|
||||
],
|
||||
],
|
||||
'alerts' => $alerts,
|
||||
|
||||
Reference in New Issue
Block a user