From d25988bb9a6d266e54a68e7b7f519a3d2487ec1b Mon Sep 17 00:00:00 2001 From: Matt Young Date: Fri, 30 Jan 2026 18:07:44 -0600 Subject: [PATCH] Show open invoices on the dashboard. --- .../components/⚡open-invoices.blade.php | 100 ++++++++++++++++++ resources/views/dashboard.blade.php | 4 +- 2 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 resources/views/components/⚡open-invoices.blade.php diff --git a/resources/views/components/⚡open-invoices.blade.php b/resources/views/components/⚡open-invoices.blade.php new file mode 100644 index 0000000..2b82563 --- /dev/null +++ b/resources/views/components/⚡open-invoices.blade.php @@ -0,0 +1,100 @@ +loadInvoices(); + } + + public function loadInvoices(): void + { + $data = Cache::remember('open_invoices', now()->addMinutes(15), function () { + $allOpen = Invoice::where('status', InvoiceStatus::POSTED)->with('client')->get(); + + return [ + 'total' => $allOpen->sum('balance_due'), + 'invoices' => $allOpen + ->sortBy('invoice_date') + ->take(5) + ->map(fn($invoice) => [ + 'uuid' => $invoice->uuid, + 'invoice_number' => $invoice->invoice_number, + 'client_name' => $invoice->client?->abbreviation ?? $invoice->client?->name ?? 'Unknown', + 'invoice_date' => $invoice->invoice_date?->format('M j, Y'), + 'days_old' => $invoice->invoice_date?->diffInDays(now()), + 'balance_due' => $invoice->balance_due, + ]) + ->values() + ->toArray(), + ]; + }); + + // Handle stale cache format + if (!isset($data['total'])) { + Cache::forget('open_invoices'); + $this->loadInvoices(); + return; + } + + $this->totalOpen = $data['total']; + $this->invoices = $data['invoices']; + } + + public function refresh(): void + { + Cache::forget('open_invoices'); + $this->loadInvoices(); + } +}; +?> + +
+
+

Open Invoices

+ +
+

${{ number_format($totalOpen, 0) }}

+ + @if(empty($invoices)) +
+

No open invoices

+
+ @else +
+ + + @foreach($invoices as $invoice) + + + + + + + @endforeach + +
+ + {{ $invoice['invoice_number'] }} + + + {{ $invoice['client_name'] }} + + ${{ number_format($invoice['balance_due'], 0) }} + + {{ $invoice['days_old'] }}d +
+
+ @endif + +

Cached for 15 min

+
\ No newline at end of file diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 47b2ffe..1325aad 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -7,8 +7,8 @@
-
- +
+