Updated report filter func. and visible rights added for import / export buttons
This commit is contained in:
@@ -9,6 +9,7 @@ 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\Block;
|
||||||
use App\Models\Line;
|
use App\Models\Line;
|
||||||
|
use App\Models\LineStop;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\ProductionLineStop;
|
use App\Models\ProductionLineStop;
|
||||||
use App\Models\Shift;
|
use App\Models\Shift;
|
||||||
@@ -368,10 +369,12 @@ class ProductionLineStopResource extends Resource
|
|||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('stop_hour')
|
Tables\Columns\TextColumn::make('stop_hour')
|
||||||
->label('Stop Hour')
|
->label('Stop Hour')
|
||||||
|
->alignCenter()
|
||||||
->numeric()
|
->numeric()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('stop_min')
|
Tables\Columns\TextColumn::make('stop_min')
|
||||||
->label('Stop Minute')
|
->label('Stop Minute')
|
||||||
|
->alignCenter()
|
||||||
->numeric()
|
->numeric()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('line.name')
|
Tables\Columns\TextColumn::make('line.name')
|
||||||
@@ -404,31 +407,62 @@ class ProductionLineStopResource extends Resource
|
|||||||
])
|
])
|
||||||
|
|
||||||
->filters([
|
->filters([
|
||||||
|
|
||||||
Tables\Filters\TrashedFilter::make(),
|
Tables\Filters\TrashedFilter::make(),
|
||||||
Filter::make('advanced_filters')
|
Filter::make('advanced_filters')
|
||||||
->label('Advanced Filters')
|
->label('Advanced Filters')
|
||||||
->form([
|
->form([
|
||||||
|
|
||||||
|
//plant
|
||||||
Select::make('Plant')
|
Select::make('Plant')
|
||||||
->label('Select Plant')
|
->label('Select Plant')
|
||||||
|
->nullable()
|
||||||
->options(function () {
|
->options(function () {
|
||||||
return Plant::pluck('name', 'id'); // Assuming 'name' is the column you want to display
|
return Plant::pluck('name', 'id'); // Assuming 'name' is the column you want to display
|
||||||
|
})
|
||||||
|
->reactive()
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$set('Line', null);
|
||||||
|
$set('Block', null);
|
||||||
|
$set('Shift', null);
|
||||||
|
$set('line_stop_id', null);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
//line
|
||||||
|
Select::make('Line')
|
||||||
|
->label('Select line')
|
||||||
|
->nullable()
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('Plant');
|
||||||
|
|
||||||
|
if (!$plantId ) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return Line::where('plant_id', $plantId)
|
||||||
|
->pluck('name', 'id');
|
||||||
|
})
|
||||||
|
->reactive(),
|
||||||
|
|
||||||
//block
|
//block
|
||||||
Select::make('Block')
|
Select::make('Block')
|
||||||
->label('Select Block')
|
->label('Select Block')
|
||||||
->options(fn (callable $get) =>
|
->nullable()
|
||||||
$get('Plant')
|
->options(function (callable $get) {
|
||||||
? Block::where('plant_id', $get('Plant'))->pluck('name', 'id')
|
$plantId = $get('Plant');
|
||||||
: []
|
|
||||||
)
|
if (!$plantId ) {
|
||||||
->reactive(),
|
return [];
|
||||||
|
}
|
||||||
|
return Block::where('plant_id', $get('Plant'))->pluck('name', 'id');
|
||||||
|
})
|
||||||
|
->reactive()
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$set('Shift', null);
|
||||||
|
}),
|
||||||
|
|
||||||
//shift
|
//shift
|
||||||
Select::make('Shift')
|
Select::make('Shift')
|
||||||
->label('Select Shift')
|
->label('Select Shift')
|
||||||
|
->nullable()
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('Plant');
|
$plantId = $get('Plant');
|
||||||
$blockId = $get('Block');
|
$blockId = $get('Block');
|
||||||
@@ -443,79 +477,62 @@ class ProductionLineStopResource extends Resource
|
|||||||
})
|
})
|
||||||
->reactive(),
|
->reactive(),
|
||||||
|
|
||||||
//line
|
Select::make('line_stop_id') //linestop_id
|
||||||
Select::make('line')
|
->label('Search by Line Stop Code')
|
||||||
->label('Select line')
|
->nullable()
|
||||||
|
// ->options(fn () => LineStop::orderBy('code')->whereHas('productionLineStops')->pluck('code', 'id'))
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('Plant');
|
$pId = $get('Plant');
|
||||||
|
return LineStop::orderBy('code')->whereHas('productionLineStops', function ($query) use ($pId) {
|
||||||
if (!$plantId ) {
|
if ($pId) {
|
||||||
return [];
|
$query->where('plant_id', $pId);
|
||||||
}
|
}
|
||||||
return Line::where('plant_id', $plantId)
|
})->pluck('code', 'id');
|
||||||
->pluck('name', 'id');
|
|
||||||
})
|
})
|
||||||
|
->searchable()
|
||||||
->reactive(),
|
->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')
|
DateTimePicker::make(name: 'created_from')
|
||||||
->label('Created From')
|
->label('Created From')
|
||||||
|
->placeholder(placeholder: 'Select From DateTime')
|
||||||
->reactive()
|
->reactive()
|
||||||
->native(false),
|
->native(false),
|
||||||
|
|
||||||
DateTimePicker::make('created_to')
|
DateTimePicker::make('created_to')
|
||||||
->label('Created To')
|
->label('Created To')
|
||||||
|
->placeholder(placeholder: 'Select To DateTime')
|
||||||
->reactive()
|
->reactive()
|
||||||
->native(false),
|
->native(false),
|
||||||
])
|
])
|
||||||
->query(function ($query, array $data) {
|
->query(function ($query, array $data) {
|
||||||
|
if (empty($data['Plant']) && empty($data['Shift']) && empty($data['Line']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['line_stop_id'])) {
|
||||||
|
return $query->whereRaw('1 = 0');
|
||||||
|
}
|
||||||
|
|
||||||
if ($plant = $data['Plant'] ?? null) {
|
if ($plant = $data['Plant'] ?? null) {
|
||||||
$query->where('plant_id', $plant);
|
$query->where('plant_id', $plant);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter by Shift
|
|
||||||
if ($shift = $data['Shift'] ?? null) {
|
if ($shift = $data['Shift'] ?? null) {
|
||||||
// Get shift data here, if needed, but no block_id filtering yet
|
|
||||||
$query->where('shift_id', $shift);
|
$query->where('shift_id', $shift);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($block = $data['Block'] ?? null) {
|
if ($line = $data['Line'] ?? null) {
|
||||||
// Use whereHas to filter by block_id in the Shift table
|
|
||||||
$query->whereHas('shift', function ($query) use ($block) {
|
|
||||||
$query->where('block_id', $block);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($line = $data['line'] ?? null) {
|
|
||||||
$query->where('line_id', $line);
|
$query->where('line_id', $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($code = $data['Line Stop Code'] ?? null) {
|
if ($code = $data['line_stop_id'] ?? null) {
|
||||||
// Find the linestop_id by code entered
|
// Find the linestop_id by code entered
|
||||||
$lineStop = \App\Models\LineStop::where('code', 'like', "%{$code}%")->first();
|
// $lineStop = \App\Models\LineStop::where('code', 'like', "%{$code}%")->first();
|
||||||
|
|
||||||
// If we find a matching LineStop, use its id to filter production_line_stops
|
// // If we find a matching LineStop, use its id to filter production_line_stops
|
||||||
if ($lineStop) {
|
// if ($lineStop) {
|
||||||
$query->where('linestop_id', $lineStop->id);
|
// $query->where('linestop_id', $lineStop->id);
|
||||||
} else {
|
// } else {
|
||||||
// If no match found, you can either handle it as an error or return no results
|
// // If no match found, you can either handle it as an error or return no results
|
||||||
$query->where('linestop_id', null); // This will return no results if no match
|
// $query->where('linestop_id', null); // This will return no results if no match
|
||||||
}
|
// }
|
||||||
}
|
$query->where('linestop_id', $code);
|
||||||
|
|
||||||
if ($reason = $data['reason'] ?? null) {
|
|
||||||
$query->where('reason_id', $reason);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($from = $data['created_from'] ?? null) {
|
if ($from = $data['created_from'] ?? null) {
|
||||||
@@ -525,12 +542,39 @@ class ProductionLineStopResource extends Resource
|
|||||||
if ($to = $data['created_to'] ?? null) {
|
if ($to = $data['created_to'] ?? null) {
|
||||||
$query->where('created_at', '<=', $to);
|
$query->where('created_at', '<=', $to);
|
||||||
}
|
}
|
||||||
|
// return $query;
|
||||||
return $query;
|
|
||||||
})
|
})
|
||||||
|
->indicateUsing(function (array $data) {
|
||||||
|
$indicators = [];
|
||||||
|
|
||||||
|
if (!empty($data['Plant'])) {
|
||||||
|
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Shift'])) {
|
||||||
|
$indicators[] = 'Shift: ' . Shift::where('id', $data['Shift'])->value('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Line'])) {
|
||||||
|
$indicators[] = 'Line: ' . Line::where('id', $data['Line'])->value('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_from'])) {
|
||||||
|
$indicators[] = 'From: ' . $data['created_from'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_to'])) {
|
||||||
|
$indicators[] = 'To: ' . $data['created_to'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['line_stop_id'])) {
|
||||||
|
$lineStopCod = LineStop::find($data['line_stop_id'])->code ?? 'Unknown';
|
||||||
|
$indicators[] = 'Line Stop Code: ' . $lineStopCod;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $indicators;
|
||||||
|
})
|
||||||
])
|
])
|
||||||
|
|
||||||
->filtersFormMaxHeight('280px')
|
->filtersFormMaxHeight('280px')
|
||||||
->actions([
|
->actions([
|
||||||
Tables\Actions\ViewAction::make(),
|
Tables\Actions\ViewAction::make(),
|
||||||
@@ -547,9 +591,14 @@ class ProductionLineStopResource extends Resource
|
|||||||
->headerActions([
|
->headerActions([
|
||||||
ImportAction::make()
|
ImportAction::make()
|
||||||
->importer(ProductionLineStopImporter::class)
|
->importer(ProductionLineStopImporter::class)
|
||||||
->maxRows(100000),
|
->visible(function() {
|
||||||
|
return Filament::auth()->user()->can('view import production line stop');
|
||||||
|
}),
|
||||||
ExportAction::make()
|
ExportAction::make()
|
||||||
->exporter(ProductionLineStopExporter::class),
|
->exporter(ProductionLineStopExporter::class)
|
||||||
|
->visible(function() {
|
||||||
|
return Filament::auth()->user()->can('view export production line stop');
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user