feat: initialize Dr-Panel project with patient file number support
This commit is contained in:
@@ -0,0 +1,291 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\SurgeryCenterResource\Pages;
|
||||
use App\Models\SurgeryCenter;
|
||||
use App\Services\PdfService;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Actions\BulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\FontWeight;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Collection;
|
||||
use OpenSpout\Common\Entity\Row;
|
||||
use OpenSpout\Writer\XLSX\Writer;
|
||||
|
||||
class SurgeryCenterResource extends Resource
|
||||
{
|
||||
protected static ?string $model = SurgeryCenter::class;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getNavigationIcon(): \BackedEnum|string|null
|
||||
{
|
||||
return 'heroicon-o-building-office-2';
|
||||
}
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('navigation.groups.clinic');
|
||||
}
|
||||
|
||||
public static function getNavigationSort(): ?int
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('navigation.surgery_centers.title');
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('navigation.surgery_centers.singular');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('navigation.surgery_centers.title');
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Grid::make()
|
||||
->schema([
|
||||
Section::make()
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label(__('surgery_centers.fields.name'))
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->columnSpanFull(),
|
||||
|
||||
TextInput::make('phone')
|
||||
->label(__('surgery_centers.fields.phone'))
|
||||
->maxLength(50),
|
||||
|
||||
TextInput::make('email')
|
||||
->label(__('surgery_centers.fields.email'))
|
||||
->email()
|
||||
->maxLength(100),
|
||||
|
||||
TextInput::make('contact_person')
|
||||
->label(__('surgery_centers.fields.contact_person'))
|
||||
->maxLength(100)
|
||||
->columnSpanFull(),
|
||||
|
||||
Textarea::make('address')
|
||||
->label(__('surgery_centers.fields.address'))
|
||||
->rows(2)
|
||||
->columnSpanFull(),
|
||||
|
||||
Textarea::make('description')
|
||||
->label(__('surgery_centers.fields.description'))
|
||||
->rows(3)
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->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('name')
|
||||
->label(__('surgery_centers.fields.name'))
|
||||
->weight(FontWeight::Medium)
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('phone')
|
||||
->label(__('surgery_centers.fields.phone'))
|
||||
->placeholder('-'),
|
||||
|
||||
TextColumn::make('email')
|
||||
->label(__('surgery_centers.fields.email'))
|
||||
->placeholder('-'),
|
||||
|
||||
TextColumn::make('contact_person')
|
||||
->label(__('surgery_centers.fields.contact_person'))
|
||||
->placeholder('-'),
|
||||
|
||||
TextColumn::make('address')
|
||||
->label(__('surgery_centers.fields.address'))
|
||||
->limit(40)
|
||||
->placeholder('-'),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->label(__('surgery_centers.fields.created_at'))
|
||||
->sortable(),
|
||||
])
|
||||
->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',
|
||||
__('surgery_centers.fields.name'),
|
||||
__('surgery_centers.fields.phone'),
|
||||
__('surgery_centers.fields.email'),
|
||||
__('surgery_centers.fields.contact_person'),
|
||||
__('surgery_centers.fields.address'),
|
||||
]));
|
||||
|
||||
foreach ($records as $record) {
|
||||
$writer->addRow(Row::fromValues([
|
||||
$record->id,
|
||||
$record->name,
|
||||
$record->phone,
|
||||
$record->email,
|
||||
$record->contact_person,
|
||||
$record->address,
|
||||
]));
|
||||
}
|
||||
|
||||
$writer->close();
|
||||
|
||||
return response()->streamDownload(function () use ($tempPath) {
|
||||
readfile($tempPath);
|
||||
@unlink($tempPath);
|
||||
}, 'surgery-centers-' . 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 = SurgeryCenter::orderBy('name')->get();
|
||||
|
||||
$tempPath = tempnam(sys_get_temp_dir(), 'export_') . '.xlsx';
|
||||
$writer = new Writer();
|
||||
$writer->openToFile($tempPath);
|
||||
|
||||
$writer->addRow(Row::fromValues([
|
||||
'ID',
|
||||
__('surgery_centers.fields.name'),
|
||||
__('surgery_centers.fields.phone'),
|
||||
__('surgery_centers.fields.email'),
|
||||
__('surgery_centers.fields.contact_person'),
|
||||
__('surgery_centers.fields.address'),
|
||||
]));
|
||||
|
||||
foreach ($records as $record) {
|
||||
$writer->addRow(Row::fromValues([
|
||||
$record->id,
|
||||
$record->name,
|
||||
$record->phone,
|
||||
$record->email,
|
||||
$record->contact_person,
|
||||
$record->address,
|
||||
]));
|
||||
}
|
||||
|
||||
$writer->close();
|
||||
|
||||
return response()->streamDownload(function () use ($tempPath) {
|
||||
readfile($tempPath);
|
||||
@unlink($tempPath);
|
||||
}, 'surgery-centers-' . 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 = SurgeryCenter::orderBy('name')->get();
|
||||
|
||||
return PdfService::download(
|
||||
'exports.surgery-centers-pdf',
|
||||
['records' => $records],
|
||||
'surgery-centers-' . now()->format('Y-m-d') . '.pdf',
|
||||
);
|
||||
}),
|
||||
])
|
||||
->label(__('table.export'))
|
||||
->color('orange')
|
||||
->button(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSurgeryCenters::route('/'),
|
||||
'create' => Pages\CreateSurgeryCenter::route('/create'),
|
||||
'edit' => Pages\EditSurgeryCenter::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user