Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / review (pull_request) Failing after 33s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 12s
Laravel Pint / pint (pull_request) Successful in 2m23s
Laravel Larastan / larastan (pull_request) Failing after 3m26s
517 lines
22 KiB
PHP
517 lines
22 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Exports\CharacteristicValueExporter;
|
|
use App\Filament\Imports\CharacteristicValueImporter;
|
|
use App\Filament\Resources\CharacteristicValueResource\Pages;
|
|
use App\Filament\Resources\CharacteristicValueResource\RelationManagers;
|
|
use App\Models\CharacteristicValue;
|
|
use App\Models\Item;
|
|
use App\Models\Line;
|
|
use App\Models\Machine;
|
|
use App\Models\Plant;
|
|
use Filament\Forms;
|
|
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;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Forms\Components\DateTimePicker;
|
|
use Filament\Tables\Filters\Filter;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Tables\Actions\ExportAction;
|
|
use Filament\Tables\Actions\ImportAction;
|
|
|
|
class CharacteristicValueResource extends Resource
|
|
{
|
|
protected static ?string $model = CharacteristicValue::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
|
|
|
protected static ?string $navigationGroup = 'Process Order';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Forms\Components\Select::make('plant_id')
|
|
->label('Plant')
|
|
->relationship('plant', 'name')
|
|
->options(function (callable $get) {
|
|
$userHas = Filament::auth()->user()->plant_id;
|
|
|
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
|
})
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, $set, callable $get) {
|
|
$plantId = $get('plant_id');
|
|
$set('item_id', null);
|
|
$set('line_id', null);
|
|
$set('machine_id', null);
|
|
if (! $plantId) {
|
|
$set('poPlantError', 'Please select a plant first.');
|
|
}
|
|
})
|
|
->extraAttributes(fn ($get) => [
|
|
'class' => $get('poPlantError') ? 'border-red-500' : '',
|
|
])
|
|
->hint(fn ($get) => $get('poPlantError') ? $get('poPlantError') : null)
|
|
->hintColor('danger')
|
|
->required(),
|
|
Forms\Components\Select::make('line_id')
|
|
->label('Line')
|
|
->options(function (callable $get) {
|
|
if (!$get('plant_id')) {
|
|
return [];
|
|
}
|
|
|
|
return Line::where('plant_id', $get('plant_id'))
|
|
->pluck('name', 'id')
|
|
->toArray();
|
|
})
|
|
->afterStateUpdated(function ($state, $set, callable $get) {
|
|
$plantId = $get('plant_id');
|
|
$set('item_id', null);
|
|
$set('machine_id', null);
|
|
if (! $plantId) {
|
|
$set('poPlantError', 'Please select a plant first.');
|
|
}
|
|
})
|
|
->reactive()
|
|
->required(),
|
|
Forms\Components\Select::make('item_id')
|
|
->label('Item')
|
|
->options(function (callable $get) {
|
|
if (!$get('plant_id') || !$get('line_id')) {
|
|
return [];
|
|
}
|
|
|
|
return Item::where('plant_id', $get('plant_id'))
|
|
->pluck('code', 'id')
|
|
->toArray();
|
|
})
|
|
->afterStateUpdated(function ($state, $set, callable $get) {
|
|
$plantId = $get('plant_id');
|
|
$set('machine_id', null);
|
|
if (! $plantId) {
|
|
$set('poPlantError', 'Please select a plant first.');
|
|
}
|
|
})
|
|
->reactive()
|
|
->required()
|
|
->searchable(),
|
|
Forms\Components\Select::make('machine_id')
|
|
->label('Machine')
|
|
->options(function (callable $get) {
|
|
if (!$get('plant_id') || !$get('line_id') || !$get('item_id')) {
|
|
return [];
|
|
}
|
|
|
|
return Machine::where('plant_id', $get('plant_id'))
|
|
->where('line_id', $get('line_id'))
|
|
->pluck('work_center', 'id')
|
|
->toArray();
|
|
})
|
|
->afterStateUpdated(function ($state, $set, callable $get) {
|
|
$plantId = $get('plant_id');
|
|
$set('process_order', null);
|
|
$set('coil_number', null);
|
|
$set('status', null);
|
|
if (! $plantId) {
|
|
$set('poPlantError', 'Please select a plant first.');
|
|
}
|
|
})
|
|
->reactive()
|
|
->required(),
|
|
Forms\Components\TextInput::make('process_order')
|
|
->label('Process Order')
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, $set, callable $get) {
|
|
$plantId = $get('plant_id');
|
|
$set('coil_number', null);
|
|
$set('status', null);
|
|
if (! $plantId) {
|
|
$set('poPlantError', 'Please select a plant first.');
|
|
}
|
|
})
|
|
->required(),
|
|
Forms\Components\TextInput::make('coil_number')
|
|
->label('Coil Number')
|
|
// ->reactive()
|
|
// ->afterStateUpdated(function ($state, $set, callable $get) {
|
|
// $plantId = $get('plant_id');
|
|
// $set('status', null);
|
|
// if (! $plantId) {
|
|
// $set('poPlantError', 'Please select a plant first.');
|
|
// }
|
|
// })
|
|
// ->required(),
|
|
->label('Coil Number')
|
|
->default('0')
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
|
$plantId = $get('plant_id');
|
|
$processOrder = $get('process_order');
|
|
$coilNo = $get('coil_number');
|
|
if (! $plantId) {
|
|
$set('poPlantError', 'Please select a plant first.');
|
|
} elseif (! $processOrder) {
|
|
$set('coil_number', null);
|
|
$set('poPlantError', null);
|
|
} elseif ($coilNo || $coilNo == '0') {
|
|
$existing = CharacteristicValue::where('plant_id', $plantId)
|
|
->where('process_order', $processOrder)
|
|
->where('coil_number', $coilNo)
|
|
->first();
|
|
|
|
if ($existing) {
|
|
$set('poPlantError', null);
|
|
$set('coil_number', null);
|
|
$set('coilNumberError', "Duplicate Coil : '{$coilNo}' found!");
|
|
} else {
|
|
$set('poPlantError', null);
|
|
$set('coilNumberError', null);
|
|
}
|
|
}
|
|
})
|
|
->extraAttributes(fn ($get) => [
|
|
'class' => $get('coilNumberError') ? 'border-red-500' : '',
|
|
])
|
|
->hint(fn ($get) => $get('coilNumberError') ? $get('coilNumberError') : null)
|
|
->hintColor('danger')
|
|
->required(),
|
|
Forms\Components\Select::make('status')
|
|
->label('Status')
|
|
->options([
|
|
'Ok' => 'OK',
|
|
'NotOk' => 'Not Ok'
|
|
])
|
|
->reactive()
|
|
->required(),
|
|
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),
|
|
]);
|
|
}
|
|
|
|
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')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('line.name')
|
|
->label('Line')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('item.code')
|
|
->label('Item')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('machine.work_center')
|
|
->label('Machine')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('process_order')
|
|
->label('Process Order')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('coil_number')
|
|
->label('Coil Number')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('status')
|
|
->label('Status')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('created_by')
|
|
->label('Created By')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->label('Created At')
|
|
->alignCenter()
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
Tables\Columns\TextColumn::make('updated_at')
|
|
->label('Updated At')
|
|
->alignCenter()
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
Tables\Columns\TextColumn::make('deleted_at')
|
|
->label('Deleted At')
|
|
->alignCenter()
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
// ->filters([
|
|
// Tables\Filters\TrashedFilter::make(),
|
|
// ])
|
|
->filters([
|
|
|
|
Tables\Filters\TrashedFilter::make(),
|
|
Filter::make('advanced_filters')
|
|
->label('Advanced Filters')
|
|
->form([
|
|
Select::make('Plant')
|
|
->label('Select Plant')
|
|
->nullable()
|
|
->options(function (callable $get) {
|
|
$userHas = Filament::auth()->user()->plant_id;
|
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
|
})
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
|
$set('Item', null);
|
|
}),
|
|
Select::make('Line')
|
|
->label('Select Line')
|
|
->nullable()
|
|
->options(function (callable $get) {
|
|
$plantId = $get('Plant');
|
|
|
|
if(empty($plantId)) {
|
|
return [];
|
|
}
|
|
|
|
return Line::where('plant_id', $plantId)->pluck('name', 'id');
|
|
|
|
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
|
|
})
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
|
$set('Item', null);
|
|
}),
|
|
Select::make('Item')
|
|
->label('Item Code')
|
|
->nullable()
|
|
->searchable()
|
|
->options(function (callable $get) {
|
|
$plantId = $get('Plant');
|
|
|
|
if(empty($plantId)) {
|
|
return [];
|
|
}
|
|
|
|
return Item::where('plant_id', $plantId)->pluck('code', 'id');
|
|
|
|
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
|
|
})
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
|
$set('process_order', null);
|
|
}),
|
|
Select::make('Machine')
|
|
->label('Select Machine')
|
|
->nullable()
|
|
->options(function (callable $get) {
|
|
$plantId = $get('Plant');
|
|
$lineId = $get('Line');
|
|
|
|
if(empty($plantId) || empty($lineId)) {
|
|
return [];
|
|
}
|
|
|
|
return Machine::where('plant_id', $plantId)->where('line_id', $lineId)->pluck('work_center', 'id');
|
|
|
|
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
|
|
})
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
|
$set('process_order', null);
|
|
}),
|
|
TextInput::make('process_order')
|
|
->label('Process Order')
|
|
->placeholder('Enter Process Order'),
|
|
TextInput::make('coil_number')
|
|
->label('Coil Number')
|
|
->placeholder(placeholder: 'Enter Coil Number'),
|
|
Select::make('status')
|
|
->label('Status')
|
|
->options([
|
|
'Ok' => 'OK',
|
|
'NotOk' => 'Not Ok'
|
|
]),
|
|
DateTimePicker::make(name: 'created_from')
|
|
->label('Created From')
|
|
->placeholder(placeholder: 'Select From DateTime')
|
|
->reactive()
|
|
->native(false),
|
|
DateTimePicker::make('created_to')
|
|
->label('Created To')
|
|
->placeholder(placeholder: 'Select To DateTime')
|
|
->reactive()
|
|
->native(false),
|
|
])
|
|
->query(function ($query, array $data) {
|
|
// Hide all records initially if no filters are applied
|
|
if (empty($data['Plant']) && empty($data['Line']) && empty($data['Item']) && empty($data['Machine']) && empty($data['process_order']) && empty($data['coil_number']) && empty($data['status']) && empty($data['created_from']) && empty($data['created_to'])) {
|
|
return $query->whereRaw('1 = 0');
|
|
}
|
|
|
|
if (!empty($data['Plant'])) {
|
|
$query->where('plant_id', $data['Plant']);
|
|
}
|
|
|
|
if (!empty($data['Line'])) {
|
|
$query->where('line_id', $data['Line']);
|
|
}
|
|
|
|
if (!empty($data['Item'])) {
|
|
$query->where('item_id', $data['Item']);
|
|
}
|
|
|
|
if (!empty($data['Machine'])) {
|
|
$query->where('machine_id', $data['Machine']);
|
|
}
|
|
|
|
if (!empty($data['process_order'])) {
|
|
$query->where('process_order', $data['process_order']);
|
|
}
|
|
|
|
if (!empty($data['coil_number'])) {
|
|
$query->where('coil_number', $data['coil_number']);
|
|
}
|
|
|
|
if (!empty($data['status'])) {
|
|
$query->where('status', $data['status']);
|
|
}
|
|
|
|
if (!empty($data['created_from'])) {
|
|
$query->where('created_at', '>=', $data['created_from']);
|
|
}
|
|
|
|
if (!empty($data['created_to'])) {
|
|
$query->where('created_at', '<=', $data['created_to']);
|
|
}
|
|
|
|
|
|
//$query->orderBy('created_at', 'asc');
|
|
})
|
|
->indicateUsing(function (array $data) {
|
|
$indicators = [];
|
|
|
|
if (!empty($data['Plant'])) {
|
|
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
|
}
|
|
|
|
if (!empty($data['Line'])) {
|
|
$indicators[] = 'Line: ' . Line::where('id', $data['Line'])->value('name');
|
|
}
|
|
|
|
if (!empty($data['Item'])) {
|
|
$indicators[] = 'Item: ' . Item::where('id', $data['Item'])->value('code');
|
|
}
|
|
|
|
if (!empty($data['Machine'])) {
|
|
$indicators[] = 'Machine: ' . Machine::where('id', $data['Machine'])->value('work_center');
|
|
}
|
|
|
|
if (!empty($data['process_order'])) {
|
|
$indicators[] = 'Process Order: ' . $data['process_order'];
|
|
}
|
|
|
|
if (!empty($data['coil_number'])) {
|
|
$indicators[] = 'Coil Number: ' . $data['coil_number'];
|
|
}
|
|
|
|
if (!empty($data['status'])) {
|
|
$indicators[] = 'Status: ' . $data['status'];
|
|
}
|
|
|
|
if (!empty($data['created_from'])) {
|
|
$indicators[] = 'From: ' . $data['created_from'];
|
|
}
|
|
|
|
if (!empty($data['created_to'])) {
|
|
$indicators[] = 'To: ' . $data['created_to'];
|
|
}
|
|
|
|
return $indicators;
|
|
})
|
|
])
|
|
->filtersFormMaxHeight('280px')
|
|
->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()
|
|
->importer(CharacteristicValueImporter::class)
|
|
->label('Import Characteristic Value')
|
|
->color('warning')
|
|
->visible(function () {
|
|
return Filament::auth()->user()->can('view import characteristic value');
|
|
}),
|
|
ExportAction::make()
|
|
->exporter(CharacteristicValueExporter::class)
|
|
->label('Export Characteristic Value')
|
|
->color('warning')
|
|
->visible(function () {
|
|
return Filament::auth()->user()->can('view export characteristic value');
|
|
}),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListCharacteristicValues::route('/'),
|
|
'create' => Pages\CreateCharacteristicValue::route('/create'),
|
|
'view' => Pages\ViewCharacteristicValue::route('/{record}'),
|
|
'edit' => Pages\EditCharacteristicValue::route('/{record}/edit'),
|
|
];
|
|
}
|
|
|
|
public static function getEloquentQuery(): Builder
|
|
{
|
|
return parent::getEloquentQuery()
|
|
->withoutGlobalScopes([
|
|
SoftDeletingScope::class,
|
|
]);
|
|
}
|
|
}
|