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(); + } +}; +?> + +
${{ number_format($totalOpen, 0) }}
+ + @if(empty($invoices)) +No open invoices
+| + + {{ $invoice['invoice_number'] }} + + | ++ {{ $invoice['client_name'] }} + | ++ ${{ number_format($invoice['balance_due'], 0) }} + | ++ {{ $invoice['days_old'] }}d + | +
Cached for 15 min
+