Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 14s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 19s
Laravel Pint / pint (pull_request) Successful in 5m27s
Laravel Larastan / larastan (pull_request) Failing after 5m36s
302 lines
14 KiB
PHP
302 lines
14 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\CharacteristicApproverMasterResource\Pages;
|
|
use App\Models\CharacteristicApproverMaster;
|
|
use App\Models\Machine;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Components\Section;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
|
|
class CharacteristicApproverMasterResource extends Resource
|
|
{
|
|
protected static ?string $model = CharacteristicApproverMaster::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
|
|
|
protected static ?string $navigationGroup = 'Laser Marking';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Section::make('')
|
|
->schema([
|
|
Forms\Components\Select::make('plant_id')
|
|
->label('Plant')
|
|
->columnSpan(2)
|
|
->reactive()
|
|
->relationship('plant', 'name')
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
})
|
|
->required(),
|
|
Forms\Components\Select::make('machine_id')
|
|
->label('Work Center')
|
|
->columnSpan(2)
|
|
// ->relationship('machine', 'name')
|
|
->reactive()
|
|
->searchable()
|
|
->options(function (callable $get) {
|
|
$plantId = $get('plant_id');
|
|
if (empty($plantId)) {
|
|
return [];
|
|
}
|
|
|
|
return Machine::where('plant_id', $plantId)->pluck('work_center', 'id');
|
|
})
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
})
|
|
->required(),
|
|
Forms\Components\TextInput::make('characteristic_field')
|
|
->label('Characteristic Field')
|
|
->columnSpan(2)
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('machine_name')
|
|
->label('Machine')
|
|
->columnSpan(2)
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Section::make('Approver - 1')
|
|
// ->description('Prevent abuse by limiting the number of requests per period')
|
|
->columnSpan(['default' => 2, 'sm' => 4])
|
|
->schema([
|
|
Forms\Components\TextInput::make('name1')
|
|
->label('Name')
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('mail1')
|
|
->label('Mail')
|
|
->columnSpan(['default' => 1, 'sm' => 2])
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('duration1')
|
|
->label('Duration (HH.MM)')
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
])
|
|
->collapsed()// collapsible()
|
|
->columns(['default' => 1, 'sm' => 4]),
|
|
Section::make('Approver - 2')
|
|
->columnSpan(['default' => 2, 'sm' => 4])
|
|
->schema([
|
|
Forms\Components\TextInput::make('name2')
|
|
->label('Name')
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('mail2')
|
|
->label('Mail')
|
|
->columnSpan(['default' => 1, 'sm' => 2])
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('duration2')
|
|
->label('Duration (HH.MM)')
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
])
|
|
->collapsed()// collapsible()
|
|
->columns(['default' => 1, 'sm' => 4]),
|
|
Section::make('Approver - 3')
|
|
->columnSpan(['default' => 2, 'sm' => 4])
|
|
->schema([
|
|
Forms\Components\TextInput::make('name3')
|
|
->label('Name')
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('mail3')
|
|
->label('Mail')
|
|
->columnSpan(['default' => 1, 'sm' => 2])
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('duration3')
|
|
->label('Duration (HH.MM)')
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
])
|
|
->collapsed()// collapsible()
|
|
->columns(['default' => 1, 'sm' => 4]),
|
|
Forms\Components\Hidden::make('created_by')
|
|
->label('Created By')
|
|
->default(Filament::auth()->user()?->name),
|
|
Forms\Components\Hidden::make('updated_by')
|
|
->label('Updated By')
|
|
->default(Filament::auth()->user()?->name),
|
|
Forms\Components\TextInput::make('id')
|
|
->hidden()
|
|
->readOnly(),
|
|
])
|
|
->columns(['default' => 1, 'sm' => 4]),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('No.')
|
|
->label('No.')
|
|
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
|
|
$paginator = $livewire->getTableRecords();
|
|
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
|
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
|
|
|
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
|
}),
|
|
Tables\Columns\TextColumn::make('plant.name')
|
|
->label('Plant')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('machine.work_center')
|
|
->label('Work Center')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('characteristic_field')
|
|
->label('Characteristic Field')
|
|
->alignCenter()
|
|
->searchable()
|
|
->formatStateUsing(fn (string $state): string => strtoupper(__($state)))
|
|
->extraAttributes(['class' => 'uppercase'])
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('machine_name')
|
|
->label('Machine Name')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('name1')
|
|
->label('Approver Name 1')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('mail1')
|
|
->label('Mail 1')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('duration1')
|
|
->label('Duration 1 (Hour.Minute)')
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('name2')
|
|
->label('Approver Name 2')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('mail2')
|
|
->label('Mail 2')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('duration2')
|
|
->label('Duration 2 (Hour.Minute)')
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('name3')
|
|
->label('Approver Name 3')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('mail3')
|
|
->label('Mail 3')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('duration3')
|
|
->label('Duration 3 (Hour.Minute)')
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->label('Created At')
|
|
->alignCenter()
|
|
->dateTime()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('created_by')
|
|
->label('Created By')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('updated_at')
|
|
->label('Updated At')
|
|
->alignCenter()
|
|
->dateTime()
|
|
->searchable()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
Tables\Columns\TextColumn::make('updated_by')
|
|
->label('Updated By')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
Tables\Columns\TextColumn::make('deleted_at')
|
|
->label('Deleted At')
|
|
->dateTime()
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->filters([
|
|
Tables\Filters\TrashedFilter::make(),
|
|
])
|
|
->actions([
|
|
Tables\Actions\ViewAction::make(),
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
Tables\Actions\ForceDeleteBulkAction::make(),
|
|
Tables\Actions\RestoreBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListCharacteristicApproverMasters::route('/'),
|
|
'create' => Pages\CreateCharacteristicApproverMaster::route('/create'),
|
|
'view' => Pages\ViewCharacteristicApproverMaster::route('/{record}'),
|
|
'edit' => Pages\EditCharacteristicApproverMaster::route('/{record}/edit'),
|
|
];
|
|
}
|
|
|
|
public static function getEloquentQuery(): Builder
|
|
{
|
|
return parent::getEloquentQuery()
|
|
->withoutGlobalScopes([
|
|
SoftDeletingScope::class,
|
|
]);
|
|
}
|
|
}
|