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:
@@ -7,11 +7,15 @@ use App\Filament\Exports\ProductionPlanExporter;
|
||||
use App\Filament\Imports\ProductionPlanImporter;
|
||||
use App\Filament\Resources\ProductionPlanResource\Pages;
|
||||
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\Shift;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\Resource;
|
||||
@@ -21,7 +25,9 @@ use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
class ProductionPlanResource extends Resource
|
||||
@@ -78,7 +84,7 @@ class ProductionPlanResource extends Resource
|
||||
return [];
|
||||
}
|
||||
|
||||
return \App\Models\Block::where('plant_id', $get('plant_id'))
|
||||
return Block::where('plant_id', $get('plant_id'))
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
@@ -466,7 +472,7 @@ class ProductionPlanResource extends Resource
|
||||
->required()
|
||||
->integer()
|
||||
->label('Production Quantity')
|
||||
->readOnly()
|
||||
->readOnly(fn (callable $get) => !$get('id'))
|
||||
->default(0),
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
@@ -520,14 +526,11 @@ class ProductionPlanResource extends Resource
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('line.name')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
->sortable(),// ->searchable(),
|
||||
Tables\Columns\TextColumn::make('shift.name')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
->sortable(),// ->searchable(),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
->sortable(),// ->searchable(),
|
||||
Tables\Columns\TextColumn::make('operator_id')
|
||||
->label('Operator ID')
|
||||
->sortable(),
|
||||
@@ -546,7 +549,138 @@ class ProductionPlanResource extends Resource
|
||||
])
|
||||
->filters([
|
||||
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([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\EditAction::make(),
|
||||
@@ -561,10 +695,15 @@ class ProductionPlanResource extends Resource
|
||||
])
|
||||
->headerActions([
|
||||
ImportAction::make()
|
||||
->importer(ProductionPlanImporter::class)
|
||||
->maxRows(100000),
|
||||
ExportAction::make()
|
||||
->exporter(ProductionPlanExporter::class),
|
||||
->importer(ProductionPlanImporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view import production plan');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->exporter(ProductionPlanExporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view export production plan');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user