選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ManageTransaction.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Filament\Company\Resources\Accounting\TransactionResource\Pages;
  3. use App\Enums\Accounting\AccountCategory;
  4. use App\Filament\Company\Resources\Accounting\TransactionResource;
  5. use App\Models\Accounting\Account;
  6. use App\Models\Banking\BankAccount;
  7. use Filament\Actions;
  8. use Filament\Resources\Pages\ManageRecords;
  9. use Filament\Support\Enums\MaxWidth;
  10. class ManageTransaction extends ManageRecords
  11. {
  12. public static string $resource = TransactionResource::class;
  13. protected function getHeaderActions(): array
  14. {
  15. return [
  16. Actions\CreateAction::make('addIncome')
  17. ->label('Add Income')
  18. ->modalWidth(MaxWidth::ThreeExtraLarge)
  19. ->stickyModalHeader()
  20. ->stickyModalFooter()
  21. ->button()
  22. ->outlined()
  23. ->fillForm(static fn (): array => [
  24. 'method' => 'deposit',
  25. 'posted_at' => now()->format('Y-m-d'),
  26. 'bank_account_id' => BankAccount::first()->isEnabled() ? BankAccount::first()->id : null,
  27. 'amount' => '0.00',
  28. 'account_id' => Account::where('category', AccountCategory::Revenue)->where('name', 'Uncategorized Income')->first()->id,
  29. ])
  30. ->mutateFormDataUsing(function (array $data): array {
  31. $method = $data['method'];
  32. if ($method === 'deposit') {
  33. $data['type'] = 'income';
  34. } else {
  35. $data['type'] = 'expense';
  36. }
  37. return $data;
  38. }),
  39. Actions\CreateAction::make('addExpense')
  40. ->label('Add Expense')
  41. ->modalWidth(MaxWidth::ThreeExtraLarge)
  42. ->stickyModalHeader()
  43. ->stickyModalFooter()
  44. ->button()
  45. ->outlined()
  46. ->fillForm(static fn (): array => [
  47. 'method' => 'withdrawal',
  48. 'posted_at' => now()->format('Y-m-d'),
  49. 'bank_account_id' => BankAccount::first()->isEnabled() ? BankAccount::first()->id : null,
  50. 'amount' => '0.00',
  51. 'account_id' => Account::where('category', AccountCategory::Expense)->where('name', 'Uncategorized Expense')->first()->id,
  52. ])
  53. ->mutateFormDataUsing(function (array $data): array {
  54. $method = $data['method'];
  55. if ($method === 'deposit') {
  56. $data['type'] = 'income';
  57. } else {
  58. $data['type'] = 'expense';
  59. }
  60. return $data;
  61. }),
  62. ];
  63. }
  64. }