Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AdjustmentResource.php 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. use Wallo\FilamentSelectify\Components\ToggleButton;
  16. class AdjustmentResource extends Resource
  17. {
  18. protected static ?string $model = Adjustment::class;
  19. protected static ?string $cluster = Settings::class;
  20. public static function form(Form $form): Form
  21. {
  22. return $form
  23. ->schema([
  24. Forms\Components\Section::make('General')
  25. ->schema([
  26. Forms\Components\TextInput::make('name')
  27. ->autofocus()
  28. ->required()
  29. ->maxLength(255),
  30. Forms\Components\Textarea::make('description')
  31. ->label('Description')
  32. ->autosize(),
  33. ]),
  34. Forms\Components\Section::make('Configuration')
  35. ->schema([
  36. Forms\Components\Select::make('category')
  37. ->localizeLabel()
  38. ->options(AdjustmentCategory::class)
  39. ->default(AdjustmentCategory::Tax)
  40. ->live()
  41. ->required(),
  42. Forms\Components\Select::make('type')
  43. ->localizeLabel()
  44. ->options(AdjustmentType::class)
  45. ->default(AdjustmentType::Sales)
  46. ->live()
  47. ->required(),
  48. ToggleButton::make('recoverable')
  49. ->label('Recoverable')
  50. ->default(false)
  51. ->visible(fn (Forms\Get $get) => AdjustmentCategory::parse($get('category')) === AdjustmentCategory::Tax && AdjustmentType::parse($get('type')) === AdjustmentType::Purchase),
  52. ])
  53. ->columns()
  54. ->visibleOn('create'),
  55. Forms\Components\Section::make('Adjustment Details')
  56. ->schema([
  57. Forms\Components\Select::make('computation')
  58. ->localizeLabel()
  59. ->options(AdjustmentComputation::class)
  60. ->default(AdjustmentComputation::Percentage)
  61. ->live()
  62. ->required(),
  63. Forms\Components\TextInput::make('rate')
  64. ->localizeLabel()
  65. ->rate(static fn (Forms\Get $get) => $get('computation'))
  66. ->required(),
  67. Forms\Components\Select::make('scope')
  68. ->localizeLabel()
  69. ->options(AdjustmentScope::class),
  70. ])
  71. ->columns(),
  72. Forms\Components\Section::make('Dates')
  73. ->schema([
  74. Forms\Components\DateTimePicker::make('start_date'),
  75. Forms\Components\DateTimePicker::make('end_date'),
  76. ])
  77. ->columns()
  78. ->visible(fn (Forms\Get $get) => AdjustmentCategory::parse($get('category')) === AdjustmentCategory::Discount),
  79. ]);
  80. }
  81. public static function table(Table $table): Table
  82. {
  83. return $table
  84. ->columns([
  85. Tables\Columns\TextColumn::make('name')
  86. ->label('Name')
  87. ->sortable(),
  88. Tables\Columns\TextColumn::make('category')
  89. ->searchable(),
  90. Tables\Columns\TextColumn::make('type')
  91. ->searchable(),
  92. Tables\Columns\TextColumn::make('rate')
  93. ->localizeLabel()
  94. ->rate(static fn (Adjustment $record) => $record->computation->value)
  95. ->searchable()
  96. ->sortable(),
  97. ])
  98. ->filters([
  99. //
  100. ])
  101. ->actions([
  102. Tables\Actions\EditAction::make(),
  103. ])
  104. ->bulkActions([
  105. //
  106. ]);
  107. }
  108. public static function getRelations(): array
  109. {
  110. return [
  111. //
  112. ];
  113. }
  114. public static function getPages(): array
  115. {
  116. return [
  117. 'index' => Pages\ListAdjustments::route('/'),
  118. 'create' => Pages\CreateAdjustment::route('/create'),
  119. 'edit' => Pages\EditAdjustment::route('/{record}/edit'),
  120. ];
  121. }
  122. }