|
@@ -0,0 +1,104 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace App\Filament\Exports\Common;
|
|
4
|
+
|
|
5
|
+use App\Models\Common\Client;
|
|
6
|
+use Filament\Actions\Exports\ExportColumn;
|
|
7
|
+use Filament\Actions\Exports\Exporter;
|
|
8
|
+use Filament\Actions\Exports\Models\Export;
|
|
9
|
+
|
|
10
|
+class ClientExporter extends Exporter
|
|
11
|
+{
|
|
12
|
+ protected static ?string $model = Client::class;
|
|
13
|
+
|
|
14
|
+ public static function getColumns(): array
|
|
15
|
+ {
|
|
16
|
+ return [
|
|
17
|
+ ExportColumn::make('name'),
|
|
18
|
+ ExportColumn::make('account_number'),
|
|
19
|
+ ExportColumn::make('primaryContact.full_name')
|
|
20
|
+ ->label('Primary contact'),
|
|
21
|
+ ExportColumn::make('primaryContact.email')
|
|
22
|
+ ->label('Email'),
|
|
23
|
+ ExportColumn::make('primaryContact.first_available_phone')
|
|
24
|
+ ->label('Phone'),
|
|
25
|
+ ExportColumn::make('currency_code'),
|
|
26
|
+ ExportColumn::make('balance') // TODO: Potentially find an easier way to calculate this
|
|
27
|
+ ->state(function (Client $record) {
|
|
28
|
+ return $record->invoices()
|
|
29
|
+ ->unpaid()
|
|
30
|
+ ->get()
|
|
31
|
+ ->sumMoneyInDefaultCurrency('amount_due');
|
|
32
|
+ })
|
|
33
|
+ ->money(),
|
|
34
|
+ ExportColumn::make('overdue_amount')
|
|
35
|
+ ->state(function (Client $record) {
|
|
36
|
+ return $record->invoices()
|
|
37
|
+ ->overdue()
|
|
38
|
+ ->get()
|
|
39
|
+ ->sumMoneyInDefaultCurrency('amount_due');
|
|
40
|
+ })
|
|
41
|
+ ->money(),
|
|
42
|
+ ExportColumn::make('billingAddress.address_string')
|
|
43
|
+ ->label('Billing address')
|
|
44
|
+ ->enabledByDefault(false),
|
|
45
|
+ ExportColumn::make('billingAddress.address_line_1')
|
|
46
|
+ ->label('Billing address line 1'),
|
|
47
|
+ ExportColumn::make('billingAddress.address_line_2')
|
|
48
|
+ ->label('Billing address line 2'),
|
|
49
|
+ ExportColumn::make('billingAddress.city')
|
|
50
|
+ ->label('Billing city'),
|
|
51
|
+ ExportColumn::make('billingAddress.state.name')
|
|
52
|
+ ->label('Billing state'),
|
|
53
|
+ ExportColumn::make('billingAddress.postal_code')
|
|
54
|
+ ->label('Billing postal code'),
|
|
55
|
+ ExportColumn::make('billingAddress.country.name')
|
|
56
|
+ ->label('Billing country'),
|
|
57
|
+ ExportColumn::make('shippingAddress.recipient')
|
|
58
|
+ ->label('Shipping recipient')
|
|
59
|
+ ->enabledByDefault(false),
|
|
60
|
+ ExportColumn::make('shippingAddress.phone')
|
|
61
|
+ ->label('Shipping phone')
|
|
62
|
+ ->enabledByDefault(false),
|
|
63
|
+ ExportColumn::make('shippingAddress.address_string')
|
|
64
|
+ ->label('Shipping address')
|
|
65
|
+ ->enabledByDefault(false),
|
|
66
|
+ ExportColumn::make('shippingAddress.address_line_1')
|
|
67
|
+ ->label('Shipping address line 1')
|
|
68
|
+ ->enabledByDefault(false),
|
|
69
|
+ ExportColumn::make('shippingAddress.address_line_2')
|
|
70
|
+ ->label('Shipping address line 2')
|
|
71
|
+ ->enabledByDefault(false),
|
|
72
|
+ ExportColumn::make('shippingAddress.city')
|
|
73
|
+ ->label('Shipping city')
|
|
74
|
+ ->enabledByDefault(false),
|
|
75
|
+ ExportColumn::make('shippingAddress.state.name')
|
|
76
|
+ ->label('Shipping state')
|
|
77
|
+ ->enabledByDefault(false),
|
|
78
|
+ ExportColumn::make('shippingAddress.postal_code')
|
|
79
|
+ ->label('Shipping postal code')
|
|
80
|
+ ->enabledByDefault(false),
|
|
81
|
+ ExportColumn::make('shippingAddress.country.name')
|
|
82
|
+ ->label('Shipping country')
|
|
83
|
+ ->enabledByDefault(false),
|
|
84
|
+ ExportColumn::make('shippingAddress.notes')
|
|
85
|
+ ->label('Delivery instructions')
|
|
86
|
+ ->enabledByDefault(false),
|
|
87
|
+ ExportColumn::make('website')
|
|
88
|
+ ->enabledByDefault(false),
|
|
89
|
+ ExportColumn::make('notes')
|
|
90
|
+ ->enabledByDefault(false),
|
|
91
|
+ ];
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ public static function getCompletedNotificationBody(Export $export): string
|
|
95
|
+ {
|
|
96
|
+ $body = 'Your client export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
|
97
|
+
|
|
98
|
+ if ($failedRowsCount = $export->getFailedRowsCount()) {
|
|
99
|
+ $body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ return $body;
|
|
103
|
+ }
|
|
104
|
+}
|