Added auto focus, option limit, loading msg, to datetime warnMsg and report filters
This commit is contained in:
@@ -5,7 +5,11 @@ namespace App\Filament\Resources;
|
|||||||
use App\Filament\Imports\ProductionLineStopImporter;
|
use App\Filament\Imports\ProductionLineStopImporter;
|
||||||
use App\Filament\Resources\ProductionLineStopResource\Pages;
|
use App\Filament\Resources\ProductionLineStopResource\Pages;
|
||||||
use App\Filament\Resources\ProductionLineStopResource\RelationManagers;
|
use App\Filament\Resources\ProductionLineStopResource\RelationManagers;
|
||||||
|
use App\Models\Block;
|
||||||
|
use App\Models\Line;
|
||||||
|
use App\Models\Plant;
|
||||||
use App\Models\ProductionLineStop;
|
use App\Models\ProductionLineStop;
|
||||||
|
use App\Models\Shift;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Forms\Get;
|
use Filament\Forms\Get;
|
||||||
@@ -16,7 +20,11 @@ use Filament\Tables\Table;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Filament\Forms\Components\DateTimePicker;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Tables\Filters\Filter;
|
||||||
|
|
||||||
class ProductionLineStopResource extends Resource
|
class ProductionLineStopResource extends Resource
|
||||||
{
|
{
|
||||||
@@ -68,7 +76,8 @@ class ProductionLineStopResource extends Resource
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return \App\Models\Block::where('plant_id', $get('plant_id'))
|
// return \App\Models\Block::where('plant_id', $get('plant_id'))
|
||||||
|
return Block::where('plant_id', $get('plant_id'))
|
||||||
->pluck('name', 'id')
|
->pluck('name', 'id')
|
||||||
->toArray();
|
->toArray();
|
||||||
})
|
})
|
||||||
@@ -87,7 +96,8 @@ class ProductionLineStopResource extends Resource
|
|||||||
if($get('id'))
|
if($get('id'))
|
||||||
{
|
{
|
||||||
$getShift = ProductionLineStop::where('id', $get('id'))->first();
|
$getShift = ProductionLineStop::where('id', $get('id'))->first();
|
||||||
$getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
|
// $getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
|
||||||
|
$getBlock = Shift::where('id', $getShift->shift_id)->first();
|
||||||
if($getBlock->block_id)
|
if($getBlock->block_id)
|
||||||
{
|
{
|
||||||
$set('block_name', $getBlock->block_id);
|
$set('block_name', $getBlock->block_id);
|
||||||
@@ -137,7 +147,8 @@ class ProductionLineStopResource extends Resource
|
|||||||
// return \App\Models\Shift::where('plant_id', $get('plant_id'))
|
// return \App\Models\Shift::where('plant_id', $get('plant_id'))
|
||||||
// ->pluck('name', 'id')
|
// ->pluck('name', 'id')
|
||||||
// ->toArray();
|
// ->toArray();
|
||||||
return \App\Models\Shift::where('plant_id', $get('plant_id'))
|
// return \App\Models\Shift::where('plant_id', $get('plant_id'))
|
||||||
|
return Shift::where('plant_id', $get('plant_id'))
|
||||||
->where('block_id', $get('block_name'))
|
->where('block_id', $get('block_name'))
|
||||||
->pluck('name', 'id')
|
->pluck('name', 'id')
|
||||||
->toArray();
|
->toArray();
|
||||||
@@ -186,7 +197,8 @@ class ProductionLineStopResource extends Resource
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return \App\Models\Line::where('plant_id', $get('plant_id'))
|
// return \App\Models\Line::where('plant_id', $get('plant_id'))
|
||||||
|
return Line::where('plant_id', $get('plant_id'))
|
||||||
->pluck('name', 'id')
|
->pluck('name', 'id')
|
||||||
->toArray();
|
->toArray();
|
||||||
})
|
})
|
||||||
@@ -203,6 +215,8 @@ class ProductionLineStopResource extends Resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
$lineId = $get('line_id');
|
$lineId = $get('line_id');
|
||||||
|
$set('linestop_id', null);
|
||||||
|
$set('lineStop_reason', null);
|
||||||
|
|
||||||
if (!$lineId) {
|
if (!$lineId) {
|
||||||
$set('plsLineError', 'Please select a line first.');
|
$set('plsLineError', 'Please select a line first.');
|
||||||
@@ -232,11 +246,14 @@ class ProductionLineStopResource extends Resource
|
|||||||
// ->pluck('code', 'id')
|
// ->pluck('code', 'id')
|
||||||
// )
|
// )
|
||||||
->placeholder('Scan the valid code')
|
->placeholder('Scan the valid code')
|
||||||
|
->autofocus(true)
|
||||||
->options(fn () => \App\Models\LineStop::pluck('code', 'id'))
|
->options(fn () => \App\Models\LineStop::pluck('code', 'id'))
|
||||||
->required()
|
->required()
|
||||||
// ->nullable()
|
// ->nullable()
|
||||||
// ->reactive()
|
// ->reactive()
|
||||||
|
->optionsLimit(5)
|
||||||
->searchable()
|
->searchable()
|
||||||
|
->loadingMessage('Loading line stop codes...')
|
||||||
->live(debounce: 500) // Enable live updates
|
->live(debounce: 500) // Enable live updates
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$lineStopId = $get('linestop_id'); // Get entered linestop_id
|
$lineStopId = $get('linestop_id'); // Get entered linestop_id
|
||||||
@@ -264,6 +281,7 @@ class ProductionLineStopResource extends Resource
|
|||||||
->label('From DateTime')
|
->label('From DateTime')
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
|
// ->closeOnDateSelection()
|
||||||
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
|
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
|
||||||
self::updateStopDuration($get, $set)
|
self::updateStopDuration($get, $set)
|
||||||
),
|
),
|
||||||
@@ -274,7 +292,12 @@ class ProductionLineStopResource extends Resource
|
|||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
|
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
|
||||||
self::updateStopDuration($get, $set) //self means it calling the function within the class
|
self::updateStopDuration($get, $set) //self means it calling the function within the class
|
||||||
),
|
)
|
||||||
|
->extraAttributes(fn ($get) => [
|
||||||
|
'class' => $get('plsToDateError') ? 'border-red-500' : '',
|
||||||
|
])
|
||||||
|
->hint(fn ($get) => $get('plsToDateError') ? $get('plsToDateError') : null)
|
||||||
|
->hintColor('danger'),
|
||||||
Forms\Components\TextInput::make('stop_hour')
|
Forms\Components\TextInput::make('stop_hour')
|
||||||
->required()
|
->required()
|
||||||
->label( 'Stop Hour')
|
->label( 'Stop Hour')
|
||||||
@@ -314,15 +337,18 @@ class ProductionLineStopResource extends Resource
|
|||||||
{
|
{
|
||||||
$set('stop_hour', null);
|
$set('stop_hour', null);
|
||||||
$set('stop_min', null);
|
$set('stop_min', null);
|
||||||
|
$set('plsToDateError', 'Time difference must be atlease a minute.');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$set('stop_hour', floor($diffInMinutes / 60));
|
$set('stop_hour', floor($diffInMinutes / 60));
|
||||||
$set('stop_min', $diffInMinutes % 60);
|
$set('stop_min', $diffInMinutes % 60);
|
||||||
|
$set('plsToDateError', null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$set('stop_hour', null);
|
$set('stop_hour', null);
|
||||||
$set('stop_min', null);
|
$set('stop_min', null);
|
||||||
|
$set('plsToDateError', 'To DateTime must be greater.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -336,43 +362,134 @@ class ProductionLineStopResource extends Resource
|
|||||||
->numeric()
|
->numeric()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('linestop.code')
|
Tables\Columns\TextColumn::make('linestop.code')
|
||||||
|
->label('Code')
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('linestop.reason')
|
Tables\Columns\TextColumn::make('linestop.reason')
|
||||||
|
->label('Reason')
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('from_datetime')
|
Tables\Columns\TextColumn::make('from_datetime')
|
||||||
|
->label('From DateTime')
|
||||||
->dateTime()
|
->dateTime()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('to_datetime')
|
Tables\Columns\TextColumn::make('to_datetime')
|
||||||
|
->label('To DateTime')
|
||||||
->dateTime()
|
->dateTime()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('stop_hour')
|
Tables\Columns\TextColumn::make('stop_hour')
|
||||||
|
->label('Stop Hour')
|
||||||
->numeric()
|
->numeric()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('stop_min')
|
Tables\Columns\TextColumn::make('stop_min')
|
||||||
|
->label('Stop Minute')
|
||||||
->numeric()
|
->numeric()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('line.name')
|
Tables\Columns\TextColumn::make('line.name')
|
||||||
|
->label('Line')
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('shift.name')
|
Tables\Columns\TextColumn::make('shift.name')
|
||||||
|
->label('Shift')
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('plant.name')
|
Tables\Columns\TextColumn::make('plant.name')
|
||||||
|
->label('Plant')
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('created_at')
|
Tables\Columns\TextColumn::make('created_at')
|
||||||
|
->label('Created At')
|
||||||
->dateTime()
|
->dateTime()
|
||||||
->sortable()
|
->sortable()
|
||||||
->toggleable(isToggledHiddenByDefault: true),
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
Tables\Columns\TextColumn::make('updated_at')
|
Tables\Columns\TextColumn::make('updated_at')
|
||||||
|
->label('Updated At')
|
||||||
->dateTime()
|
->dateTime()
|
||||||
->sortable()
|
->sortable()
|
||||||
->toggleable(isToggledHiddenByDefault: true),
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
Tables\Columns\TextColumn::make('deleted_at')
|
Tables\Columns\TextColumn::make('deleted_at')
|
||||||
|
->label('Deleted At')
|
||||||
->dateTime()
|
->dateTime()
|
||||||
->sortable()
|
->sortable()
|
||||||
->toggleable(isToggledHiddenByDefault: true),
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
])
|
])
|
||||||
|
|
||||||
->filters([
|
->filters([
|
||||||
|
|
||||||
Tables\Filters\TrashedFilter::make(),
|
Tables\Filters\TrashedFilter::make(),
|
||||||
|
Filter::make('advanced_filters')
|
||||||
|
->label('Advanced Filters')
|
||||||
|
->form([
|
||||||
|
|
||||||
|
Select::make('Plant')
|
||||||
|
->label('Select Plant')
|
||||||
|
->options(function () {
|
||||||
|
return Plant::pluck('name', 'id'); // Assuming 'name' is the column you want to display
|
||||||
|
}),
|
||||||
|
|
||||||
|
//block
|
||||||
|
|
||||||
|
Select::make('Block')
|
||||||
|
->label('Select Block')
|
||||||
|
->options(fn (callable $get) =>
|
||||||
|
$get('Plant')
|
||||||
|
? Block::where('plant_id', $get('Plant'))->pluck('name', 'id')
|
||||||
|
: []
|
||||||
|
)
|
||||||
|
->reactive(),
|
||||||
|
|
||||||
|
//shift
|
||||||
|
|
||||||
|
Select::make('Shift')
|
||||||
|
->label('Select Shift')
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('Plant');
|
||||||
|
$blockId = $get('Block');
|
||||||
|
|
||||||
|
if (!$plantId || !$blockId) {
|
||||||
|
return []; // Return empty if plant or block is not selected
|
||||||
|
}
|
||||||
|
|
||||||
|
return Shift::where('plant_id', $plantId)
|
||||||
|
->where('block_id', $blockId)
|
||||||
|
->pluck('name', 'id');
|
||||||
|
})
|
||||||
|
->reactive(),
|
||||||
|
|
||||||
|
//line
|
||||||
|
|
||||||
|
Select::make('line')
|
||||||
|
->label('Select line')
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('Plant');
|
||||||
|
|
||||||
|
if (!$plantId ) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return Line::where('plant_id', $plantId)
|
||||||
|
->pluck('name', 'id');
|
||||||
|
})
|
||||||
|
->reactive(),
|
||||||
|
|
||||||
|
TextInput::make('Line Stop Code'),
|
||||||
|
|
||||||
|
|
||||||
|
Select::make('reason')
|
||||||
|
->label('Filter by Stop Reason')
|
||||||
|
->options(function () {
|
||||||
|
return \App\Models\Item::whereHas('stickerMasters', function ($query) {
|
||||||
|
$query->whereHas('qualityValidations');
|
||||||
|
})->pluck('code', 'id');
|
||||||
|
})
|
||||||
|
->searchable(),
|
||||||
|
|
||||||
|
DateTimePicker::make(name: 'created_from')
|
||||||
|
->label('Created From')
|
||||||
|
->reactive()
|
||||||
|
->native(false),
|
||||||
|
|
||||||
|
DateTimePicker::make('created_to')
|
||||||
|
->label('Created To')
|
||||||
|
->reactive()
|
||||||
|
->native(false),
|
||||||
|
]),
|
||||||
])
|
])
|
||||||
|
->filtersFormMaxHeight('280px')
|
||||||
->actions([
|
->actions([
|
||||||
Tables\Actions\ViewAction::make(),
|
Tables\Actions\ViewAction::make(),
|
||||||
Tables\Actions\EditAction::make(),
|
Tables\Actions\EditAction::make(),
|
||||||
|
|||||||
Reference in New Issue
Block a user