Removed searchable and added report filter func. and visible rights added for import / export buttons and readonly mode updated to production_quantity control

This commit is contained in:
dhanabalan
2025-05-12 19:11:11 +05:30
parent e86abbc88e
commit e6563c9e31

View File

@@ -7,11 +7,15 @@ use App\Filament\Exports\ProductionPlanExporter;
use App\Filament\Imports\ProductionPlanImporter; use App\Filament\Imports\ProductionPlanImporter;
use App\Filament\Resources\ProductionPlanResource\Pages; use App\Filament\Resources\ProductionPlanResource\Pages;
use App\Filament\Resources\ProductionPlanResource\RelationManagers; use App\Filament\Resources\ProductionPlanResource\RelationManagers;
use App\Models\Block;
use App\Models\Line;
use App\Models\Plant;
use App\Models\ProductionPlan; use App\Models\ProductionPlan;
use App\Models\Shift; use App\Models\Shift;
use Carbon\Carbon; use Carbon\Carbon;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Forms\Get; use Filament\Forms\Get;
use Filament\Resources\Resource; use Filament\Resources\Resource;
@@ -21,7 +25,9 @@ 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 Filament\Forms\Components\Section; use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Tables\Actions\ExportAction; use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Filters\Filter;
use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Request;
class ProductionPlanResource extends Resource class ProductionPlanResource extends Resource
@@ -78,7 +84,7 @@ class ProductionPlanResource extends Resource
return []; return [];
} }
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();
}) })
@@ -466,7 +472,7 @@ class ProductionPlanResource extends Resource
->required() ->required()
->integer() ->integer()
->label('Production Quantity') ->label('Production Quantity')
->readOnly() ->readOnly(fn (callable $get) => !$get('id'))
->default(0), ->default(0),
Forms\Components\TextInput::make('id') Forms\Components\TextInput::make('id')
->hidden() ->hidden()
@@ -520,14 +526,11 @@ class ProductionPlanResource extends Resource
->numeric() ->numeric()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('line.name') Tables\Columns\TextColumn::make('line.name')
->sortable() ->sortable(),// ->searchable(),
->searchable(),
Tables\Columns\TextColumn::make('shift.name') Tables\Columns\TextColumn::make('shift.name')
->sortable() ->sortable(),// ->searchable(),
->searchable(),
Tables\Columns\TextColumn::make('plant.name') Tables\Columns\TextColumn::make('plant.name')
->sortable() ->sortable(),// ->searchable(),
->searchable(),
Tables\Columns\TextColumn::make('operator_id') Tables\Columns\TextColumn::make('operator_id')
->label('Operator ID') ->label('Operator ID')
->sortable(), ->sortable(),
@@ -546,7 +549,138 @@ class ProductionPlanResource extends Resource
]) ])
->filters([ ->filters([
Tables\Filters\TrashedFilter::make(), Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters')
->label('Advanced Filters')
->form([
//plant
Select::make('Plant')
->label('Select Plant')
->nullable()
->options(function () {
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);
}),
//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
Select::make('Block')
->label('Select Block')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId ) {
return [];
}
return Block::where('plant_id', $get('Plant'))->pluck('name', 'id');
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Shift', null);
}),
//shift
Select::make('Shift')
->label('Select Shift')
->nullable()
->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(),
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) {
if (empty($data['Plant']) && empty($data['Shift']) && empty($data['Line']) && empty($data['created_from']) && empty($data['created_to'])) {
return $query->whereRaw('1 = 0');
}
if ($plant = $data['Plant'] ?? null) {
$query->where('plant_id', $plant);
}
if ($shift = $data['Shift'] ?? null) {
$query->where('shift_id', $shift);
}
if ($line = $data['Line'] ?? null) {
$query->where('line_id', $line);
}
if ($from = $data['created_from'] ?? null) {
$query->where('created_at', '>=', $from);
}
if ($to = $data['created_to'] ?? null) {
$query->where('created_at', '<=', $to);
}
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'];
}
return $indicators;
})
]) ])
->filtersFormMaxHeight('280px')
->actions([ ->actions([
Tables\Actions\ViewAction::make(), Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(), Tables\Actions\EditAction::make(),
@@ -561,10 +695,15 @@ class ProductionPlanResource extends Resource
]) ])
->headerActions([ ->headerActions([
ImportAction::make() ImportAction::make()
->importer(ProductionPlanImporter::class) ->importer(ProductionPlanImporter::class)
->maxRows(100000), ->visible(function() {
ExportAction::make() return Filament::auth()->user()->can('view import production plan');
->exporter(ProductionPlanExporter::class), }),
ExportAction::make()
->exporter(ProductionPlanExporter::class)
->visible(function() {
return Filament::auth()->user()->can('view export production plan');
}),
]); ]);
} }