|
@@ -24,10 +24,12 @@ use Filament\Tables\Columns\Summarizers\Summarizer;
|
24
|
24
|
use Filament\Tables\Columns\TextColumn;
|
25
|
25
|
use Filament\Tables\Table;
|
26
|
26
|
use Illuminate\Contracts\Support\Htmlable;
|
|
27
|
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
27
|
28
|
use Illuminate\Database\Eloquent\Collection;
|
28
|
29
|
use Illuminate\Database\Query\Builder;
|
29
|
30
|
use Illuminate\Support\Str;
|
30
|
31
|
use Livewire\Attributes\Computed;
|
|
32
|
+use Livewire\Attributes\Url;
|
31
|
33
|
|
32
|
34
|
/**
|
33
|
35
|
* @property Form $form
|
|
@@ -42,6 +44,9 @@ class RecordPayments extends ListRecords
|
42
|
44
|
|
43
|
45
|
public ?array $data = [];
|
44
|
46
|
|
|
47
|
+ #[Url(as: 'invoice_id')]
|
|
48
|
+ public ?int $invoiceId = null;
|
|
49
|
+
|
45
|
50
|
public function getBreadcrumb(): ?string
|
46
|
51
|
{
|
47
|
52
|
return 'Record Payments';
|
|
@@ -58,7 +63,20 @@ class RecordPayments extends ListRecords
|
58
|
63
|
|
59
|
64
|
$this->form->fill();
|
60
|
65
|
|
61
|
|
- $this->reset('tableFilters');
|
|
66
|
+ $preservedClientId = $this->tableFilters['client_id']['value'] ?? null;
|
|
67
|
+
|
|
68
|
+ $this->tableFilters = [
|
|
69
|
+ 'client_id' => $preservedClientId ? ['value' => $preservedClientId] : [],
|
|
70
|
+ 'currency_code' => ['value' => CurrencyAccessor::getDefaultCurrency()],
|
|
71
|
+ ];
|
|
72
|
+
|
|
73
|
+ // Auto-fill payment amount if invoice_id is provided
|
|
74
|
+ if ($invoiceId = $this->invoiceId) {
|
|
75
|
+ $invoice = Invoice::find($invoiceId);
|
|
76
|
+ if ($invoice && $invoice->client_id == $preservedClientId) {
|
|
77
|
+ $this->paymentAmounts[$invoiceId] = $invoice->amount_due;
|
|
78
|
+ }
|
|
79
|
+ }
|
62
|
80
|
}
|
63
|
81
|
|
64
|
82
|
protected function getHeaderActions(): array
|
|
@@ -311,13 +329,15 @@ class RecordPayments extends ListRecords
|
311
|
329
|
}),
|
312
|
330
|
Tables\Filters\SelectFilter::make('client_id')
|
313
|
331
|
->label('Client')
|
|
332
|
+ ->selectablePlaceholder(false)
|
314
|
333
|
->options(fn () => Client::query()->pluck('name', 'id')->toArray())
|
315
|
334
|
->searchable()
|
316
|
|
- ->default(function () {
|
317
|
|
- // TODO: This needs to be applied through the url with a query parameter, it shouldn't be able to be removed though
|
318
|
|
- $clientCount = Client::count();
|
|
335
|
+ ->query(function (EloquentBuilder $query, array $data) {
|
|
336
|
+ if (blank($data['value'] ?? null)) {
|
|
337
|
+ return $query->whereRaw('1 = 0'); // No results if no client is selected
|
|
338
|
+ }
|
319
|
339
|
|
320
|
|
- return $clientCount === 1 ? Client::first()?->id : null;
|
|
340
|
+ return $query->where('client_id', $data['value']);
|
321
|
341
|
}),
|
322
|
342
|
Tables\Filters\SelectFilter::make('status')
|
323
|
343
|
->multiple()
|