Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
379 lines
19 KiB
PHP
379 lines
19 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Exports\CharacteristicApproverMasterExporter;
|
|
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\Actions\ExportAction;
|
|
use Filament\Tables\Actions\ImportAction;
|
|
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')
|
|
->required()
|
|
->default(function () {
|
|
return optional(CharacteristicApproverMaster::latest()->first())->plant_id;
|
|
})
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
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');
|
|
})
|
|
->required()
|
|
->default(function () {
|
|
return optional(CharacteristicApproverMaster::latest()->first())->machine_id ?? [];
|
|
})
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('machine_name')
|
|
->label('Machine')
|
|
->columnSpan(2)
|
|
->reactive()
|
|
->required()
|
|
->minLength(5)
|
|
->default(function () {
|
|
return optional(CharacteristicApproverMaster::latest()->first())->machine_name ?? '';
|
|
})
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('characteristic_field')
|
|
->label('Master Characteristic Field')
|
|
->columnSpan(2)
|
|
->reactive()
|
|
->required()
|
|
->minLength(1)
|
|
->default('NIL')
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
if (strtolower($state) == 'nil' || $state == '' || $state == null) {
|
|
$set('characteristic_field', 'NIL');
|
|
}
|
|
$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')
|
|
->reactive()
|
|
->required()
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('mail1')
|
|
->label('Mail ID')
|
|
->columnSpan(['default' => 1, 'sm' => 2])
|
|
->reactive()
|
|
->required()
|
|
->suffixIcon('heroicon-m-envelope')
|
|
->suffixIconColor('primary')
|
|
->email()
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('duration1')
|
|
->label('Duration (HH.MM)')
|
|
->reactive()
|
|
->required()
|
|
->minLength(4)
|
|
->maxLength(5)
|
|
->regex('/^([0-9]|0[0-9]|1[0-9]|2[0-3])\.(0[0-9]|[1-5][0-9])$/')
|
|
->validationMessages([
|
|
// 'regex' => 'Duration must be 4 digits in HH.MM format (e.g., 12.30, 23.59). Hours: 00-23, Minutes: 00-59.',
|
|
'regex' => 'Duration must be HH.MM format (example: 00.00 - 23.59)',
|
|
// 'length' => 'Duration must be exactly 5 characters',
|
|
])
|
|
->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')
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('mail2')
|
|
->label('Mail ID')
|
|
->columnSpan(['default' => 1, 'sm' => 2])
|
|
->reactive()
|
|
->suffixIcon('heroicon-m-envelope')
|
|
->suffixIconColor('primary')
|
|
->email()
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('duration2')
|
|
->label('Duration (HH.MM)')
|
|
->reactive()
|
|
->length(4)
|
|
->regex('/^([0-9]|0[0-9]|1[0-9]|2[0-3])\.(0[0-9]|[1-5][0-9])$/')
|
|
->validationMessages([
|
|
'regex' => 'Duration must be HH.MM format (example: 00.00 - 23.59)',
|
|
])
|
|
->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')
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('mail3')
|
|
->label('Mail ID')
|
|
->columnSpan(['default' => 1, 'sm' => 2])
|
|
->reactive()
|
|
->suffixIcon('heroicon-m-envelope')
|
|
->suffixIconColor('primary')
|
|
->email()
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('updated_by', Filament::auth()->user()?->name);
|
|
}),
|
|
Forms\Components\TextInput::make('duration3')
|
|
->label('Duration (HH.MM)')
|
|
->reactive()
|
|
->length(4)
|
|
->regex('/^([0-9]|0[0-9]|1[0-9]|2[0-3])\.(0[0-9]|[1-5][0-9])$/')
|
|
->validationMessages([
|
|
'regex' => 'Duration must be HH.MM format (example: 00.00 - 23.59)',
|
|
])
|
|
->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('Master 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('E-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('E-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('E-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(),
|
|
]),
|
|
])
|
|
->headerActions([
|
|
// ImportAction::make()
|
|
// ->label('Import Characteristics Approver Master')
|
|
// ->color('warning')
|
|
// ->importer(CharacteristicApproverMasterImporter::class)
|
|
// ->visible(function () {
|
|
// return Filament::auth()->user()->can('view import characteristic approver master');
|
|
// }),
|
|
ExportAction::make()
|
|
->label('Export Characteristics Approver Master')
|
|
->color('warning')
|
|
->exporter(CharacteristicApproverMasterExporter::class)
|
|
->visible(function () {
|
|
return Filament::auth()->user()->can('view export characteristic approver master');
|
|
}),
|
|
]);
|
|
}
|
|
|
|
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,
|
|
]);
|
|
}
|
|
}
|