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

AdjustmentResource.php 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace App\Filament\Company\Clusters\Settings\Resources;
  3. use App\Enums\Accounting\AdjustmentCategory;
  4. use App\Enums\Accounting\AdjustmentComputation;
  5. use App\Enums\Accounting\AdjustmentScope;
  6. use App\Enums\Accounting\AdjustmentType;
  7. use App\Filament\Company\Clusters\Settings;
  8. use App\Filament\Company\Clusters\Settings\Resources\AdjustmentResource\Pages;
  9. use App\Models\Accounting\Adjustment;
  10. use Filament\Forms;
  11. use Filament\Forms\Form;
  12. use Filament\Resources\Resource;
  13. use Filament\Tables;
  14. use Filament\Tables\Table;
  15. class AdjustmentResource extends Resource
  16. {
  17. protected static ?string $model = Adjustment::class;
  18. protected static ?string $cluster = Settings::class;
  19. public static function form(Form $form): Form
  20. {
  21. return $form
  22. ->schema([
  23. Forms\Components\Section::make('General')
  24. ->schema([
  25. Forms\Components\TextInput::make('name')
  26. ->autofocus()
  27. ->required()
  28. ->maxLength(255),
  29. Forms\Components\Textarea::make('description')
  30. ->label('Description'),
  31. ]),
  32. Forms\Components\Section::make('Configuration')
  33. ->schema([
  34. Forms\Components\Select::make('category')
  35. ->localizeLabel()
  36. ->options(AdjustmentCategory::class)
  37. ->default(AdjustmentCategory::Tax)
  38. ->live()
  39. ->required(),
  40. Forms\Components\Select::make('type')
  41. ->localizeLabel()
  42. ->options(AdjustmentType::class)
  43. ->default(AdjustmentType::Sales)
  44. ->live()
  45. ->required(),
  46. Forms\Components\Checkbox::make('recoverable')
  47. ->label('Recoverable')
  48. ->default(false)
  49. ->helperText('When enabled, tax is tracked separately as claimable from the government. Non-recoverable taxes are treated as part of the expense.')
  50. ->visible(fn (Forms\Get $get) => AdjustmentCategory::parse($get('category'))->isTax() && AdjustmentType::parse($get('type'))->isPurchase()),
  51. ])
  52. ->columns()
  53. ->visibleOn('create'),
  54. Forms\Components\Section::make('Adjustment Details')
  55. ->schema([
  56. Forms\Components\Select::make('computation')
  57. ->localizeLabel()
  58. ->options(AdjustmentComputation::class)
  59. ->default(AdjustmentComputation::Percentage)
  60. ->live()
  61. ->required(),
  62. Forms\Components\TextInput::make('rate')
  63. ->localizeLabel()
  64. ->rate(static fn (Forms\Get $get) => $get('computation'))
  65. ->required(),
  66. Forms\Components\Select::make('scope')
  67. ->localizeLabel()
  68. ->options(AdjustmentScope::class),
  69. ])
  70. ->columns(),
  71. Forms\Components\Section::make('Dates')
  72. ->schema([
  73. Forms\Components\DateTimePicker::make('start_date'),
  74. Forms\Components\DateTimePicker::make('end_date'),
  75. ])
  76. ->columns()
  77. ->visible(fn (Forms\Get $get) => AdjustmentCategory::parse($get('category'))->isDiscount()),
  78. ]);
  79. }
  80. public static function table(Table $table): Table
  81. {
  82. return $table
  83. ->columns([
  84. Tables\Columns\TextColumn::make('name')
  85. ->label('Name')
  86. ->sortable(),
  87. Tables\Columns\TextColumn::make('category')
  88. ->searchable(),
  89. Tables\Columns\TextColumn::make('type')
  90. ->searchable(),
  91. Tables\Columns\TextColumn::make('rate')
  92. ->localizeLabel()
  93. ->rate(static fn (Adjustment $record) => $record->computation->value)
  94. ->searchable()
  95. ->sortable(),
  96. ])
  97. ->filters([
  98. //
  99. ])
  100. ->actions([
  101. Tables\Actions\EditAction::make(),
  102. ])
  103. ->bulkActions([
  104. //
  105. ]);
  106. }
  107. public static function getRelations(): array
  108. {
  109. return [
  110. //
  111. ];
  112. }
  113. public static function getPages(): array
  114. {
  115. return [
  116. 'index' => Pages\ListAdjustments::route('/'),
  117. 'create' => Pages\CreateAdjustment::route('/create'),
  118. 'edit' => Pages\EditAdjustment::route('/{record}/edit'),
  119. ];
  120. }
  121. }