|
@@ -0,0 +1,71 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace App\Filament\Exports\Accounting;
|
|
4
|
+
|
|
5
|
+use App\Enums\Accounting\PaymentMethod;
|
|
6
|
+use App\Enums\Accounting\TransactionType;
|
|
7
|
+use App\Models\Accounting\Transaction;
|
|
8
|
+use Carbon\Carbon;
|
|
9
|
+use Filament\Actions\Exports\ExportColumn;
|
|
10
|
+use Filament\Actions\Exports\Exporter;
|
|
11
|
+use Filament\Actions\Exports\Models\Export;
|
|
12
|
+
|
|
13
|
+class TransactionExporter extends Exporter
|
|
14
|
+{
|
|
15
|
+ protected static ?string $model = Transaction::class;
|
|
16
|
+
|
|
17
|
+ public static function getColumns(): array
|
|
18
|
+ {
|
|
19
|
+ return [
|
|
20
|
+ ExportColumn::make('posted_at')
|
|
21
|
+ ->formatStateUsing(function (?Carbon $state) {
|
|
22
|
+ return $state?->toDateString();
|
|
23
|
+ }),
|
|
24
|
+ ExportColumn::make('description'),
|
|
25
|
+ ExportColumn::make('amount'),
|
|
26
|
+ ExportColumn::make('account.name')
|
|
27
|
+ ->label('Category'),
|
|
28
|
+ ExportColumn::make('bankAccount.account.name')
|
|
29
|
+ ->label('Account'),
|
|
30
|
+ ExportColumn::make('type')
|
|
31
|
+ ->formatStateUsing(function (?TransactionType $state) {
|
|
32
|
+ return $state?->getLabel();
|
|
33
|
+ }),
|
|
34
|
+ ExportColumn::make('payeeable.name')
|
|
35
|
+ ->label('Payee'),
|
|
36
|
+ ExportColumn::make('payment_method')
|
|
37
|
+ ->formatStateUsing(function (?PaymentMethod $state) {
|
|
38
|
+ return $state?->getLabel();
|
|
39
|
+ }),
|
|
40
|
+ ExportColumn::make('notes')
|
|
41
|
+ ->enabledByDefault(false),
|
|
42
|
+ ExportColumn::make('transactionable_type')
|
|
43
|
+ ->label('Source type')
|
|
44
|
+ ->formatStateUsing(static function ($state) {
|
|
45
|
+ return class_basename($state);
|
|
46
|
+ })
|
|
47
|
+ ->enabledByDefault(false),
|
|
48
|
+ ExportColumn::make('payeeable_type')
|
|
49
|
+ ->label('Payee type')
|
|
50
|
+ ->formatStateUsing(static function ($state) {
|
|
51
|
+ return class_basename($state);
|
|
52
|
+ })
|
|
53
|
+ ->enabledByDefault(false),
|
|
54
|
+ ExportColumn::make('is_payment')
|
|
55
|
+ ->enabledByDefault(false),
|
|
56
|
+ ExportColumn::make('reviewed')
|
|
57
|
+ ->enabledByDefault(false),
|
|
58
|
+ ];
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ public static function getCompletedNotificationBody(Export $export): string
|
|
62
|
+ {
|
|
63
|
+ $body = 'Your transaction export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
|
64
|
+
|
|
65
|
+ if ($failedRowsCount = $export->getFailedRowsCount()) {
|
|
66
|
+ $body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ return $body;
|
|
70
|
+ }
|
|
71
|
+}
|