123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
-
- namespace App\Filament\Company\Clusters\Settings\Resources;
-
- use App\Enums\Accounting\AdjustmentCategory;
- use App\Enums\Accounting\AdjustmentComputation;
- use App\Enums\Accounting\AdjustmentScope;
- use App\Enums\Accounting\AdjustmentStatus;
- use App\Enums\Accounting\AdjustmentType;
- use App\Filament\Company\Clusters\Settings;
- use App\Filament\Company\Clusters\Settings\Resources\AdjustmentResource\Pages;
- use App\Models\Accounting\Adjustment;
- use Filament\Forms;
- use Filament\Forms\Form;
- use Filament\Resources\Resource;
- use Filament\Tables;
- use Filament\Tables\Table;
-
- class AdjustmentResource extends Resource
- {
- protected static ?string $model = Adjustment::class;
-
- protected static ?string $cluster = Settings::class;
-
- public static function form(Form $form): Form
- {
- return $form
- ->schema([
- Forms\Components\Section::make('General')
- ->schema([
- Forms\Components\TextInput::make('name')
- ->autofocus()
- ->required()
- ->maxLength(255),
- Forms\Components\Textarea::make('description')
- ->label('Description'),
- ]),
- Forms\Components\Section::make('Configuration')
- ->schema([
- Forms\Components\Select::make('category')
- ->localizeLabel()
- ->options(AdjustmentCategory::class)
- ->default(AdjustmentCategory::Tax)
- ->live()
- ->required(),
- Forms\Components\Select::make('type')
- ->localizeLabel()
- ->options(AdjustmentType::class)
- ->default(AdjustmentType::Sales)
- ->live()
- ->required(),
- Forms\Components\Checkbox::make('recoverable')
- ->label('Recoverable')
- ->default(false)
- ->helperText('When enabled, tax is tracked separately as claimable from the government. Non-recoverable taxes are treated as part of the expense.')
- ->visible(fn (Forms\Get $get) => AdjustmentCategory::parse($get('category'))->isTax() && AdjustmentType::parse($get('type'))->isPurchase()),
- ])
- ->columns()
- ->visibleOn('create'),
- Forms\Components\Section::make('Adjustment Details')
- ->schema([
- Forms\Components\Select::make('computation')
- ->localizeLabel()
- ->options(AdjustmentComputation::class)
- ->default(AdjustmentComputation::Percentage)
- ->live()
- ->required(),
- Forms\Components\TextInput::make('rate')
- ->localizeLabel()
- ->rate(static fn (Forms\Get $get) => $get('computation'))
- ->required(),
- Forms\Components\Select::make('scope')
- ->localizeLabel()
- ->options(AdjustmentScope::class),
- ])
- ->columns(),
- Forms\Components\Section::make('Dates')
- ->schema([
- Forms\Components\DateTimePicker::make('start_date'),
- Forms\Components\DateTimePicker::make('end_date')
- ->after('start_date'),
- ])
- ->columns()
- ->visible(fn (Forms\Get $get) => AdjustmentCategory::parse($get('category'))->isDiscount()),
- ]);
- }
-
- public static function table(Table $table): Table
- {
- return $table
- ->columns([
- Tables\Columns\TextColumn::make('name')
- ->label('Name')
- ->sortable(),
- Tables\Columns\TextColumn::make('category')
- ->searchable(),
- Tables\Columns\TextColumn::make('type')
- ->searchable(),
- Tables\Columns\TextColumn::make('status')
- ->badge(),
- Tables\Columns\TextColumn::make('rate')
- ->localizeLabel()
- ->rate(static fn (Adjustment $record) => $record->computation->value)
- ->searchable()
- ->sortable(),
- ])
- ->filters([
- //
- ])
- ->actions([
- Tables\Actions\ActionGroup::make([
- Tables\Actions\EditAction::make(),
- Tables\Actions\Action::make('archive')
- ->label('Archive')
- ->icon('heroicon-o-archive-box-x-mark')
- ->color('danger')
- ->requiresConfirmation()
- ->visible(static fn (Adjustment $record) => $record->status !== AdjustmentStatus::Archived)
- ->action(fn (Adjustment $record) => $record->update(['status' => AdjustmentStatus::Archived])),
- ]),
- ])
- ->bulkActions([
- //
- ]);
- }
-
- public static function getRelations(): array
- {
- return [
- //
- ];
- }
-
- public static function getPages(): array
- {
- return [
- 'index' => Pages\ListAdjustments::route('/'),
- 'create' => Pages\CreateAdjustment::route('/create'),
- 'edit' => Pages\EditAdjustment::route('/{record}/edit'),
- ];
- }
- }
|