components([ Grid::make() ->schema([ Section::make() ->schema([ TextInput::make('illness') ->label(__('patient_illness.fields.illness')) ->required() ->maxLength(200) ->columnSpanFull(), Select::make('row_no') ->label(__('patient_illness.fields.row_no')) ->options([ 1 => __('patient_illness.row_options.first'), 2 => __('patient_illness.row_options.second'), ]) ->required(), TextInput::make('priority') ->label(__('patient_illness.fields.priority')) ->numeric() ->minValue(1), ]) ->columns(2) ->columnSpanFull() ->footerActions([ fn (string $operation) => Action::make('create') ->label(__('filament-panels::resources/pages/create-record.form.actions.create.label')) ->submit('create') ->keyBindings(['mod+s']) ->visible($operation === 'create'), fn (string $operation) => Action::make('createAnother') ->label(__('filament-panels::resources/pages/create-record.form.actions.create_another.label')) ->action('createAnother') ->keyBindings(['mod+shift+s']) ->color('gray') ->visible($operation === 'create'), fn (string $operation) => Action::make('cancelCreate') ->label(__('filament-panels::resources/pages/create-record.form.actions.cancel.label')) ->url(static::getUrl('index')) ->color('gray') ->visible($operation === 'create'), fn (string $operation) => Action::make('save') ->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label')) ->submit('save') ->keyBindings(['mod+s']) ->visible($operation === 'edit'), fn (string $operation) => Action::make('cancelEdit') ->label(__('filament-panels::resources/pages/edit-record.form.actions.cancel.label')) ->url(static::getUrl('index')) ->color('gray') ->visible($operation === 'edit'), ]), ]) ->columnSpanFull(), ]); } public static function table(Table $table): Table { return $table ->columns([ TextColumn::make('illness') ->label(__('patient_illness.fields.illness')) ->weight(FontWeight::Medium) ->searchable() ->sortable(), TextColumn::make('row_no') ->label(__('patient_illness.fields.row_no')) ->badge() ->color('gray') ->formatStateUsing(fn (int $state): string => $state === 1 ? __('patient_illness.row_options.first') : __('patient_illness.row_options.second')) ->sortable(), TextColumn::make('priority') ->label(__('patient_illness.fields.priority')) ->badge() ->color('primary') ->sortable(), ]) ->reorderable('priority') ->defaultSort('priority') ->groups([ Group::make('row_no') ->label(__('patient_illness.fields.row_no')) ->getTitleFromRecordUsing(fn (PatientIllness $record): string => $record->row_no === 1 ? __('patient_illness.row_options.first') : __('patient_illness.row_options.second')), ]) ->defaultGroup('row_no') ->groupingSettingsHidden() ->recordActions([ EditAction::make(), DeleteAction::make(), ]) ->toolbarActions([ BulkActionGroup::make([ DeleteBulkAction::make(), BulkAction::make('export_excel_selected') ->label(__('table.export_excel_selected')) ->icon('heroicon-o-table-cells') ->color('success') ->action(function (Collection $records) { $tempPath = tempnam(sys_get_temp_dir(), 'export_') . '.xlsx'; $writer = new Writer(); $writer->openToFile($tempPath); $writer->addRow(Row::fromValues([ 'ID', __('patient_illness.fields.illness'), __('patient_illness.fields.row_no'), __('patient_illness.fields.priority'), ])); foreach ($records as $record) { $writer->addRow(Row::fromValues([ $record->id, $record->illness, $record->row_no, $record->priority, ])); } $writer->close(); return response()->streamDownload(function () use ($tempPath) { readfile($tempPath); @unlink($tempPath); }, 'patient-illness-' . now()->format('Y-m-d') . '.xlsx', [ 'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ]); }), ]), ActionGroup::make([ Action::make('export_excel') ->label(__('table.export_excel')) ->color('success') ->icon('heroicon-o-table-cells') ->action(function () { $records = PatientIllness::orderBy('row_no')->orderBy('priority')->get(); $tempPath = tempnam(sys_get_temp_dir(), 'export_') . '.xlsx'; $writer = new Writer(); $writer->openToFile($tempPath); $writer->addRow(Row::fromValues([ 'ID', __('patient_illness.fields.illness'), __('patient_illness.fields.row_no'), __('patient_illness.fields.priority'), ])); foreach ($records as $record) { $writer->addRow(Row::fromValues([ $record->id, $record->illness, $record->row_no, $record->priority, ])); } $writer->close(); return response()->streamDownload(function () use ($tempPath) { readfile($tempPath); @unlink($tempPath); }, 'patient-illness-' . now()->format('Y-m-d') . '.xlsx', [ 'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ]); }), Action::make('export_pdf') ->label(__('table.export_pdf')) ->color('danger') ->icon('heroicon-o-document-arrow-down') ->action(function () { $records = PatientIllness::orderBy('row_no')->orderBy('priority')->get(); return PdfService::download( 'exports.patient-illness-pdf', ['records' => $records], 'patient-illness-' . now()->format('Y-m-d') . '.pdf', ); }), ]) ->label(__('table.export')) ->color('orange') ->button(), ]); } public static function getPages(): array { return [ 'index' => Pages\ListPatientIllnesses::route('/'), 'create' => Pages\CreatePatientIllness::route('/create'), 'edit' => Pages\EditPatientIllness::route('/{record}/edit'), ]; } }