diff --git a/app/Filament/Resources/FareResource.php b/app/Filament/Resources/FareResource.php new file mode 100644 index 000000000..59ce6d3e1 --- /dev/null +++ b/app/Filament/Resources/FareResource.php @@ -0,0 +1,109 @@ +schema([ + Forms\Components\Section::make('Fare Information') + ->description('When a fare is assigned to a subfleet, the price, cost and capacity can be overridden, so you can create default values that will apply to most of your subfleets, and change them where they will differ.') + ->schema([ + TextInput::make('code')->hint('How this fare class will show up on a ticket')->required()->string(), + TextInput::make('name')->hint('The fare class name, E.g "Economy" or "First"')->required()->string(), + Select::make('type')->hint('If this is a passenger or cargo fare')->options(FareType::labels())->native(false)->required(), + Toggle::make('active')->offIcon('heroicon-m-x-circle')->offColor('danger')->onIcon('heroicon-m-check-circle')->onColor('success')->default(true), + ])->columns(3), + Forms\Components\Section::make('Base Fare Finances') + ->schema([ + TextInput::make('price')->hint('This is the price of a ticket or price per kg')->numeric(), + TextInput::make('cost')->hint('The operating cost per unit (passenger or kg)')->numeric(), + TextInput::make('capacity')->hint('Max seats or capacity available. This can be adjusted in the subfleet')->numeric(), + TextInput::make('notes')->hint('Any notes about this fare')->string(), + ])->columns(2), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + TextColumn::make('code')->label('Code'), + TextColumn::make('name')->label('Name')->searchable(), + TextColumn::make('type')->label('Type')->formatStateUsing(fn ($state): string => FareType::label($state)), + TextColumn::make('price')->label('Price')->money(setting('units.currency')), + TextColumn::make('cost')->label('Cost')->money(setting('units.currency')), + TextColumn::make('notes')->label('Notes'), + IconColumn::make('active')->label('Active')->color(fn (Fare $record) => $record->active ? 'success' : 'danger')->icon(fn ($state) => $state ? 'heroicon-o-check-circle' : 'heroicon-o-x-circle'), + ]) + ->filters([ + Tables\Filters\TrashedFilter::make(), + ]) + ->actions([ + Tables\Actions\EditAction::make(), + Tables\Actions\DeleteAction::make(), + Tables\Actions\ForceDeleteAction::make(), + Tables\Actions\RestoreAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + Tables\Actions\ForceDeleteBulkAction::make(), + Tables\Actions\RestoreBulkAction::make(), + ]), + ]) + ->emptyStateActions([ + Tables\Actions\CreateAction::make()->label('Add Fare'), + ]); + } + + public static function getEloquentQuery(): Builder + { + return parent::getEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListFares::route('/'), + 'create' => Pages\CreateFare::route('/create'), + 'edit' => Pages\EditFare::route('/{record}/edit'), + ]; + } +} diff --git a/app/Filament/Resources/FareResource/Pages/CreateFare.php b/app/Filament/Resources/FareResource/Pages/CreateFare.php new file mode 100644 index 000000000..e7e8fe6b9 --- /dev/null +++ b/app/Filament/Resources/FareResource/Pages/CreateFare.php @@ -0,0 +1,16 @@ +getResource()::getUrl('index'); + } +} diff --git a/app/Filament/Resources/FareResource/Pages/EditFare.php b/app/Filament/Resources/FareResource/Pages/EditFare.php new file mode 100644 index 000000000..a48a493eb --- /dev/null +++ b/app/Filament/Resources/FareResource/Pages/EditFare.php @@ -0,0 +1,26 @@ +getResource()::getUrl('index'); + } +} diff --git a/app/Filament/Resources/FareResource/Pages/ListFares.php b/app/Filament/Resources/FareResource/Pages/ListFares.php new file mode 100644 index 000000000..5b2e04b7d --- /dev/null +++ b/app/Filament/Resources/FareResource/Pages/ListFares.php @@ -0,0 +1,24 @@ +arguments(['resourceTitle' => 'fares', 'exportType' => ImportExportType::FARES]), + ImportAction::make('import')->arguments(['resourceTitle' => 'fares', 'importType' => ImportExportType::FARES]), + Actions\CreateAction::make()->label('Add Fare')->icon('heroicon-o-plus-circle'), + ]; + } +}