Andrew Wallo 4 月之前
父節點
當前提交
b2e392f3a5

+ 1
- 1
app/DTO/AccountTransactionDTO.php 查看文件

@@ -14,6 +14,6 @@ class AccountTransactionDTO
14 14
         public string $credit,
15 15
         public string $balance,
16 16
         public ?TransactionType $type,
17
-        public ?array $tableAction,
17
+        public ?string $url = null,
18 18
     ) {}
19 19
 }

+ 51
- 13
app/Filament/Company/Resources/Accounting/TransactionResource/Pages/ViewTransaction.php 查看文件

@@ -4,15 +4,26 @@ namespace App\Filament\Company\Resources\Accounting\TransactionResource\Pages;
4 4
 
5 5
 use App\Filament\Actions\EditTransactionAction;
6 6
 use App\Filament\Company\Resources\Accounting\TransactionResource;
7
+use App\Filament\Company\Resources\Purchases\BillResource\Pages\ViewBill;
8
+use App\Filament\Company\Resources\Purchases\VendorResource;
9
+use App\Filament\Company\Resources\Sales\ClientResource;
10
+use App\Filament\Company\Resources\Sales\InvoiceResource\Pages\ViewInvoice;
11
+use App\Models\Accounting\Bill;
12
+use App\Models\Accounting\Invoice;
7 13
 use App\Models\Accounting\JournalEntry;
8 14
 use App\Models\Accounting\Transaction;
15
+use App\Models\Common\Client;
16
+use App\Models\Common\Vendor;
9 17
 use Filament\Actions;
18
+use Filament\Infolists\Components\IconEntry;
10 19
 use Filament\Infolists\Components\Section;
11 20
 use Filament\Infolists\Components\TextEntry;
12 21
 use Filament\Infolists\Infolist;
13 22
 use Filament\Resources\Pages\ViewRecord;
14 23
 use Filament\Support\Enums\IconPosition;
15 24
 
25
+use function Filament\Support\get_model_label;
26
+
16 27
 class ViewTransaction extends ViewRecord
17 28
 {
18 29
     protected static string $resource = TransactionResource::class;
@@ -22,6 +33,24 @@ class ViewTransaction extends ViewRecord
22 33
         return [
23 34
             EditTransactionAction::make()
24 35
                 ->outlined(),
36
+            Actions\ViewAction::make('viewAssociatedDocument')
37
+                ->outlined()
38
+                ->icon('heroicon-o-document-text')
39
+                ->hidden(static fn (Transaction $record): bool => ! $record->transactionable_id)
40
+                ->label(static function (Transaction $record) {
41
+                    if (! $record->transactionable_type) {
42
+                        return 'View document';
43
+                    }
44
+
45
+                    return 'View ' . get_model_label($record->transactionable_type);
46
+                })
47
+                ->url(static function (Transaction $record) {
48
+                    return match ($record->transactionable_type) {
49
+                        Bill::class => ViewBill::getUrl(['record' => $record->transactionable_id]),
50
+                        Invoice::class => ViewInvoice::getUrl(['record' => $record->transactionable_id]),
51
+                        default => null,
52
+                    };
53
+                }),
25 54
             Actions\ActionGroup::make([
26 55
                 Actions\ActionGroup::make([
27 56
                     Actions\Action::make('markAsReviewed')
@@ -69,35 +98,44 @@ class ViewTransaction extends ViewRecord
69 98
                             ->date(),
70 99
                         TextEntry::make('type')
71 100
                             ->badge(),
72
-                        TextEntry::make('is_payment')
101
+                        IconEntry::make('is_payment')
73 102
                             ->label('Payment')
74
-                            ->badge()
75
-                            ->formatStateUsing(fn (bool $state): string => $state ? 'Yes' : 'No')
76
-                            ->color(fn (bool $state): string => $state ? 'info' : 'gray')
77
-                            ->visible(fn (Transaction $record): bool => $record->isPayment()),
103
+                            ->boolean(),
78 104
                         TextEntry::make('description')
79 105
                             ->label('Description'),
80 106
                         TextEntry::make('bankAccount.account.name')
81
-                            ->label('Bank Account')
82
-                            ->visible(fn (Transaction $record): bool => $record->bankAccount !== null),
107
+                            ->label('Account')
108
+                            ->hidden(static fn (Transaction $record): bool => ! $record->bankAccount),
83 109
                         TextEntry::make('payeeable.name')
84 110
                             ->label('Payee')
85
-                            ->visible(fn (Transaction $record): bool => $record->payeeable !== null),
111
+                            ->hidden(static fn (Transaction $record): bool => ! $record->payeeable_type)
112
+                            ->url(static function (Transaction $record): ?string {
113
+                                if (! $record->payeeable_type) {
114
+                                    return null;
115
+                                }
116
+
117
+                                return match ($record->payeeable_type) {
118
+                                    Vendor::class => VendorResource::getUrl('view', ['record' => $record->payeeable_id]),
119
+                                    Client::class => ClientResource::getUrl('view', ['record' => $record->payeeable_id]),
120
+                                    default => null,
121
+                                };
122
+                            })
123
+                            ->link(),
86 124
                         TextEntry::make('account.name')
87 125
                             ->label('Category')
88
-                            ->visible(fn (Transaction $record): bool => $record->account !== null),
126
+                            ->hidden(static fn (Transaction $record): bool => ! $record->account),
89 127
                         TextEntry::make('amount')
90 128
                             ->label('Amount')
91
-                            ->currency(fn (Transaction $record) => $record->bankAccount?->account->currency_code ?? 'USD'),
129
+                            ->currency(static fn (Transaction $record) => $record->bankAccount?->account->currency_code ?? 'USD'),
92 130
                         TextEntry::make('reviewed')
93 131
                             ->label('Status')
94 132
                             ->badge()
95
-                            ->formatStateUsing(fn (bool $state): string => $state ? 'Reviewed' : 'Not Reviewed')
96
-                            ->color(fn (bool $state): string => $state ? 'success' : 'warning'),
133
+                            ->formatStateUsing(static fn (bool $state): string => $state ? 'Reviewed' : 'Not Reviewed')
134
+                            ->color(static fn (bool $state): string => $state ? 'success' : 'warning'),
97 135
                         TextEntry::make('notes')
98 136
                             ->label('Notes')
99 137
                             ->columnSpan(2)
100
-                            ->visible(fn (Transaction $record): bool => filled($record->notes)),
138
+                            ->visible(static fn (Transaction $record): bool => filled($record->notes)),
101 139
                     ]),
102 140
             ]);
103 141
     }

+ 2
- 4
app/Filament/Company/Resources/Purchases/BillResource/Pages/ViewBill.php 查看文件

@@ -10,7 +10,6 @@ use Filament\Infolists\Components\Section;
10 10
 use Filament\Infolists\Components\TextEntry;
11 11
 use Filament\Infolists\Infolist;
12 12
 use Filament\Resources\Pages\ViewRecord;
13
-use Filament\Support\Enums\FontWeight;
14 13
 use Filament\Support\Enums\IconPosition;
15 14
 
16 15
 class ViewBill extends ViewRecord
@@ -55,9 +54,8 @@ class ViewBill extends ViewRecord
55 54
                             ->badge(),
56 55
                         TextEntry::make('vendor.name')
57 56
                             ->label('Vendor')
58
-                            ->color('primary')
59
-                            ->weight(FontWeight::SemiBold)
60
-                            ->url(static fn (Bill $record) => VendorResource::getUrl('view', ['record' => $record->vendor_id])),
57
+                            ->url(static fn (Bill $record) => VendorResource::getUrl('view', ['record' => $record->vendor_id]))
58
+                            ->link(),
61 59
                         TextEntry::make('total')
62 60
                             ->label('Total')
63 61
                             ->currency(fn (Bill $record) => $record->currency_code),

+ 2
- 1
app/Filament/Company/Resources/Purchases/VendorResource/Pages/ViewVendor.php 查看文件

@@ -77,7 +77,8 @@ class ViewVendor extends ViewRecord
77 77
                             ->label('Primary phone'),
78 78
                         TextEntry::make('website')
79 79
                             ->label('Website')
80
-                            ->url(static fn ($state) => $state, true),
80
+                            ->url(static fn ($state) => $state, true)
81
+                            ->link(),
81 82
                     ]),
82 83
                 Section::make('Additional Details')
83 84
                     ->columns()

+ 2
- 1
app/Filament/Company/Resources/Sales/ClientResource/Pages/ViewClient.php 查看文件

@@ -90,7 +90,8 @@ class ViewClient extends ViewRecord
90 90
                             ->label('Primary phone'),
91 91
                         TextEntry::make('website')
92 92
                             ->label('Website')
93
-                            ->url(static fn ($state) => $state, true),
93
+                            ->url(static fn ($state) => $state, true)
94
+                            ->link(),
94 95
                     ]),
95 96
                 Section::make('Additional Details')
96 97
                     ->columns()

+ 2
- 4
app/Filament/Company/Resources/Sales/EstimateResource/Pages/ViewEstimate.php 查看文件

@@ -14,7 +14,6 @@ use Filament\Infolists\Components\Section;
14 14
 use Filament\Infolists\Components\TextEntry;
15 15
 use Filament\Infolists\Infolist;
16 16
 use Filament\Resources\Pages\ViewRecord;
17
-use Filament\Support\Enums\FontWeight;
18 17
 use Filament\Support\Enums\IconPosition;
19 18
 use Illuminate\Support\HtmlString;
20 19
 
@@ -93,9 +92,8 @@ class ViewEstimate extends ViewRecord
93 92
                                     ->badge(),
94 93
                                 TextEntry::make('client.name')
95 94
                                     ->label('Client')
96
-                                    ->color('primary')
97
-                                    ->weight(FontWeight::SemiBold)
98
-                                    ->url(static fn (Estimate $record) => ClientResource::getUrl('view', ['record' => $record->client_id])),
95
+                                    ->url(static fn (Estimate $record) => ClientResource::getUrl('view', ['record' => $record->client_id]))
96
+                                    ->link(),
99 97
                                 TextEntry::make('expiration_date')
100 98
                                     ->label('Expiration date')
101 99
                                     ->asRelativeDay(),

+ 2
- 4
app/Filament/Company/Resources/Sales/InvoiceResource/Pages/ViewInvoice.php 查看文件

@@ -14,7 +14,6 @@ use Filament\Infolists\Components\Section;
14 14
 use Filament\Infolists\Components\TextEntry;
15 15
 use Filament\Infolists\Infolist;
16 16
 use Filament\Resources\Pages\ViewRecord;
17
-use Filament\Support\Enums\FontWeight;
18 17
 use Filament\Support\Enums\IconPosition;
19 18
 use Illuminate\Support\HtmlString;
20 19
 
@@ -90,9 +89,8 @@ class ViewInvoice extends ViewRecord
90 89
                                     ->badge(),
91 90
                                 TextEntry::make('client.name')
92 91
                                     ->label('Client')
93
-                                    ->color('primary')
94
-                                    ->weight(FontWeight::SemiBold)
95
-                                    ->url(static fn (Invoice $record) => ClientResource::getUrl('view', ['record' => $record->client_id])),
92
+                                    ->url(static fn (Invoice $record) => ClientResource::getUrl('view', ['record' => $record->client_id]))
93
+                                    ->link(),
96 94
                                 TextEntry::make('amount_due')
97 95
                                     ->label('Amount due')
98 96
                                     ->currency(static fn (Invoice $record) => $record->currency_code),

+ 2
- 1
app/Filament/Company/Resources/Sales/RecurringInvoiceResource/Pages/ViewRecurringInvoice.php 查看文件

@@ -108,7 +108,8 @@ class ViewRecurringInvoice extends ViewRecord
108 108
                                     ->label('Client')
109 109
                                     ->color('primary')
110 110
                                     ->weight(FontWeight::SemiBold)
111
-                                    ->url(static fn (RecurringInvoice $record) => ClientResource::getUrl('view', ['record' => $record->client_id])),
111
+                                    ->url(static fn (RecurringInvoice $record) => ClientResource::getUrl('view', ['record' => $record->client_id]))
112
+                                    ->link(),
112 113
                                 TextEntry::make('last_date')
113 114
                                     ->label('Last invoice')
114 115
                                     ->date()

+ 15
- 0
app/Models/Accounting/Transaction.php 查看文件

@@ -9,6 +9,9 @@ use App\Enums\Accounting\AccountCategory;
9 9
 use App\Enums\Accounting\AccountType;
10 10
 use App\Enums\Accounting\PaymentMethod;
11 11
 use App\Enums\Accounting\TransactionType;
12
+use App\Filament\Company\Resources\Accounting\TransactionResource\Pages\ViewTransaction;
13
+use App\Filament\Company\Resources\Purchases\BillResource\Pages\ViewBill;
14
+use App\Filament\Company\Resources\Sales\InvoiceResource\Pages\ViewInvoice;
12 15
 use App\Models\Banking\BankAccount;
13 16
 use App\Models\Common\Client;
14 17
 use App\Models\Common\Contact;
@@ -246,6 +249,18 @@ class Transaction extends Model
246 249
         ];
247 250
     }
248 251
 
252
+    public function getReportTableUrl(): string
253
+    {
254
+        if ($this->transactionable_type && ! $this->is_payment) {
255
+            return match ($this->transactionable_type) {
256
+                Bill::class => ViewBill::getUrl(['record' => $this->transactionable_id]),
257
+                default => ViewInvoice::getUrl(['record' => $this->transactionable_id]),
258
+            };
259
+        }
260
+
261
+        return ViewTransaction::getUrl(['record' => $this->id]);
262
+    }
263
+
249 264
     protected static function newFactory(): Factory
250 265
     {
251 266
         return TransactionFactory::new();

+ 14
- 0
app/Providers/MacroServiceProvider.php 查看文件

@@ -19,6 +19,7 @@ use Filament\Forms\Components\DatePicker;
19 19
 use Filament\Forms\Components\Field;
20 20
 use Filament\Forms\Components\TextInput;
21 21
 use Filament\Infolists\Components\TextEntry;
22
+use Filament\Support\Enums\IconPosition;
22 23
 use Filament\Tables\Columns\TextColumn;
23 24
 use Filament\Tables\Contracts\HasTable;
24 25
 use Illuminate\Contracts\Support\Htmlable;
@@ -375,6 +376,19 @@ class MacroServiceProvider extends ServiceProvider
375 376
             return $this;
376 377
         });
377 378
 
379
+        TextEntry::macro('link', function (bool $condition = true): static {
380
+            if ($condition) {
381
+                $this
382
+                    ->limit(50)
383
+                    ->openUrlInNewTab()
384
+                    ->icon('heroicon-o-arrow-top-right-on-square')
385
+                    ->iconColor('primary')
386
+                    ->iconPosition(IconPosition::After);
387
+            }
388
+
389
+            return $this;
390
+        });
391
+
378 392
         Money::macro('swapAmountFor', function ($newCurrency) {
379 393
             $oldCurrency = $this->currency->getCurrency();
380 394
             $balanceInSubunits = $this->getAmount();

+ 1
- 35
app/Services/ReportService.php 查看文件

@@ -20,12 +20,9 @@ use App\Enums\Accounting\AccountType;
20 20
 use App\Enums\Accounting\BillStatus;
21 21
 use App\Enums\Accounting\DocumentEntityType;
22 22
 use App\Enums\Accounting\InvoiceStatus;
23
-use App\Enums\Accounting\TransactionType;
24
-use App\Filament\Company\Resources\Accounting\TransactionResource\Pages\ViewTransaction;
25 23
 use App\Models\Accounting\Account;
26 24
 use App\Models\Accounting\Bill;
27 25
 use App\Models\Accounting\Invoice;
28
-use App\Models\Accounting\Transaction;
29 26
 use App\Support\Column;
30 27
 use App\Utilities\Currency\CurrencyAccessor;
31 28
 use App\Utilities\Currency\CurrencyConverter;
@@ -207,7 +204,6 @@ class ReportService
207 204
                 credit: '',
208 205
                 balance: money($currentBalance, $defaultCurrency)->format(),
209 206
                 type: null,
210
-                tableAction: null
211 207
             );
212 208
 
213 209
             foreach ($account->journalEntries as $journalEntry) {
@@ -237,7 +233,7 @@ class ReportService
237 233
                     credit: $journalEntry->type->isCredit() ? $formattedAmount : '',
238 234
                     balance: money($currentBalance, $defaultCurrency)->format(),
239 235
                     type: $transaction->type,
240
-                    tableAction: $this->determineTableAction($transaction),
236
+                    url: $transaction->getReportTableUrl(),
241 237
                 );
242 238
             }
243 239
 
@@ -251,7 +247,6 @@ class ReportService
251 247
                 credit: money($periodCreditTotal, $defaultCurrency)->format(),
252 248
                 balance: money($currentBalance, $defaultCurrency)->format(),
253 249
                 type: null,
254
-                tableAction: null
255 250
             );
256 251
 
257 252
             $accountTransactions[] = new AccountTransactionDTO(
@@ -262,7 +257,6 @@ class ReportService
262 257
                 credit: '',
263 258
                 balance: money($balanceChange, $defaultCurrency)->format(),
264 259
                 type: null,
265
-                tableAction: null
266 260
             );
267 261
 
268 262
             $reportCategories[] = [
@@ -275,34 +269,6 @@ class ReportService
275 269
         return new ReportDTO(categories: $reportCategories, fields: $columns);
276 270
     }
277 271
 
278
-    // TODO: Refactor and potentially only use the url
279
-    private function determineTableAction(Transaction $transaction): array
280
-    {
281
-        if ($transaction->transactionable_type === null) {
282
-            return [
283
-                'type' => 'transaction',
284
-                'action' => match ($transaction->type) {
285
-                    TransactionType::Journal => 'editJournalEntry',
286
-                    TransactionType::Transfer => 'editTransfer',
287
-                    default => 'editTransaction',
288
-                },
289
-                'id' => $transaction->id,
290
-            ];
291
-        } elseif ($transaction->is_payment) {
292
-            return [
293
-                'type' => 'view_transaction',
294
-                'url' => ViewTransaction::getUrl(['record' => $transaction->id]),
295
-                'id' => $transaction->id,
296
-            ];
297
-        } else {
298
-            return [
299
-                'type' => 'transactionable',
300
-                'model' => $transaction->transactionable_type,
301
-                'id' => $transaction->transactionable_id,
302
-            ];
303
-        }
304
-    }
305
-
306 272
     public function buildTrialBalanceReport(string $trialBalanceType, string $asOfDate, array $columns = []): ReportDTO
307 273
     {
308 274
         $asOfDateCarbon = Carbon::parse($asOfDate);

+ 1
- 1
app/Transformers/AccountTransactionReportTransformer.php 查看文件

@@ -44,7 +44,7 @@ class AccountTransactionReportTransformer extends BaseReportTransformer
44 44
                         'description' => [
45 45
                             'id' => $transaction->id,
46 46
                             'description' => $transaction->description,
47
-                            'tableAction' => $transaction->tableAction,
47
+                            'url' => $transaction->url,
48 48
                         ],
49 49
                         'debit' => $transaction->debit,
50 50
                         'credit' => $transaction->credit,

+ 4
- 0
resources/css/filament/company/theme.css 查看文件

@@ -10,6 +10,10 @@
10 10
 
11 11
 @config 'tailwind.config.js';
12 12
 
13
+.fi-in-text-item .group-hover\/item\:underline, .fi-ta-text-item .group-hover\/item\:underline {
14
+    @apply text-primary-600 dark:text-primary-400 font-semibold;
15
+}
16
+
13 17
 .fi-sidebar-nav {
14 18
     scrollbar-width: thin;
15 19
 }

+ 11
- 40
resources/views/components/company/tables/reports/account-transactions.blade.php 查看文件

@@ -49,46 +49,17 @@
49 49
                             ])
50 50
                         >
51 51
                             @if(is_array($cell) && isset($cell['description']))
52
-                                @if(isset($cell['id']) && $cell['tableAction'])
53
-                                    @if($cell['tableAction']['type'] === 'transaction')
54
-                                        <x-filament::link
55
-                                            :href="TransactionResource::getUrl(parameters: [
56
-                                                'tableAction' => $cell['tableAction']['action'],
57
-                                                'tableActionRecord' => $cell['tableAction']['id'],
58
-                                            ])"
59
-                                            target="_blank"
60
-                                            color="primary"
61
-                                            icon="heroicon-o-arrow-top-right-on-square"
62
-                                            :icon-position="$iconPosition"
63
-                                            icon-size="w-4 h-4 min-w-4 min-h-4"
64
-                                        >
65
-                                            {{ $cell['description'] }}
66
-                                        </x-filament::link>
67
-                                    @elseif($cell['tableAction']['type'] === 'view_transaction')
68
-                                        <x-filament::link
69
-                                            :href="$cell['tableAction']['url']"
70
-                                            target="_blank"
71
-                                            color="primary"
72
-                                            icon="heroicon-o-arrow-top-right-on-square"
73
-                                            :icon-position="$iconPosition"
74
-                                            icon-size="w-4 h-4 min-w-4 min-h-4"
75
-                                        >
76
-                                            {{ $cell['description'] }}
77
-                                        </x-filament::link>
78
-                                    @else
79
-                                        <x-filament::link
80
-                                            :href="$cell['tableAction']['model'] === Bill::class
81
-                                                ? ViewBill::getUrl(['record' => $cell['tableAction']['id']])
82
-                                                : ViewInvoice::getUrl(['record' => $cell['tableAction']['id']])"
83
-                                            target="_blank"
84
-                                            color="primary"
85
-                                            icon="heroicon-o-arrow-top-right-on-square"
86
-                                            :icon-position="$iconPosition"
87
-                                            icon-size="w-4 h-4 min-w-4 min-h-4"
88
-                                        >
89
-                                            {{ $cell['description'] }}
90
-                                        </x-filament::link>
91
-                                    @endif
52
+                                @if(isset($cell['id']) && isset($cell['url']))
53
+                                    <x-filament::link
54
+                                        :href="$cell['url']"
55
+                                        target="_blank"
56
+                                        color="primary"
57
+                                        icon="heroicon-o-arrow-top-right-on-square"
58
+                                        :icon-position="$iconPosition"
59
+                                        icon-size="w-4 h-4 min-w-4 min-h-4"
60
+                                    >
61
+                                        {{ $cell['description'] }}
62
+                                    </x-filament::link>
92 63
                                 @else
93 64
                                     {{ $cell['description'] }}
94 65
                                 @endif

Loading…
取消
儲存