1
0
forked from poc/pds

Added view rights against plant on view report and Updated alignments on resource

This commit is contained in:
dhanabalan
2026-01-14 10:33:59 +05:30
parent 8c0676e9b8
commit adb61638c9

View File

@@ -6,7 +6,6 @@ use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction;
use App\Filament\Exports\ProductionPlanExporter; 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\Models\Block; use App\Models\Block;
use App\Models\Line; use App\Models\Line;
use App\Models\Plant; use App\Models\Plant;
@@ -16,19 +15,18 @@ 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\Components\DateTimePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Forms\Get; use Filament\Forms\Get;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction; use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table; 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\Select;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Filters\Filter;
use Illuminate\Support\Facades\Request;
class ProductionPlanResource extends Resource class ProductionPlanResource extends Resource
{ {
@@ -55,22 +53,22 @@ class ProductionPlanResource extends Resource
->reactive() ->reactive()
->options(function (callable $get) { ->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id; $userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(ProductionPlan::latest()->first())->plant_id; return optional(ProductionPlan::latest()->first())->plant_id;
}) })
->disabled(fn (Get $get) => !empty($get('id'))) ->disabled(fn (Get $get) => ! empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_name', null)) // ->afterStateUpdated(fn ($set) => $set('block_name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
$set('block_name', null); $set('block_name', null);
if (!$plantId) { if (! $plantId) {
$set('ppPlantError', 'Please select a plant first.'); $set('ppPlantError', 'Please select a plant first.');
return; return;
} } else {
else
{
$set('ppPlantError', null); $set('ppPlantError', null);
} }
}) })
@@ -84,7 +82,7 @@ class ProductionPlanResource extends Resource
// ->nullable() // ->nullable()
->label('Block') ->label('Block')
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id')) { if (! $get('plant_id')) {
return []; return [];
} }
@@ -95,16 +93,15 @@ class ProductionPlanResource extends Resource
->reactive() ->reactive()
->default(function () { ->default(function () {
$latestShiftId = optional(ProductionPlan::latest()->first())->shift_id; $latestShiftId = optional(ProductionPlan::latest()->first())->shift_id;
return optional(Shift::where('id', $latestShiftId)->first())->block_id; return optional(Shift::where('id', $latestShiftId)->first())->block_id;
}) })
//->afterStateUpdated(fn ($set) => $set('shift_id', null)) // ->afterStateUpdated(fn ($set) => $set('shift_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id')) if ($get('id')) {
{
$getShift = ProductionPlan::where('id', $get('id'))->first(); $getShift = ProductionPlan::where('id', $get('id'))->first();
$getBlock = 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);
$set('ppBlockError', null); $set('ppBlockError', null);
} }
@@ -113,12 +110,11 @@ class ProductionPlanResource extends Resource
$blockId = $get('block_name'); $blockId = $get('block_name');
$set('shift_id', null); $set('shift_id', null);
if (!$blockId) { if (! $blockId) {
$set('ppBlockError', 'Please select a block first.'); $set('ppBlockError', 'Please select a block first.');
return; return;
} } else {
else
{
$set('ppBlockError', null); $set('ppBlockError', null);
} }
}) })
@@ -133,7 +129,7 @@ class ProductionPlanResource extends Resource
// ->nullable() // ->nullable()
->autofocus(true) ->autofocus(true)
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id') || !$get('block_name')) { if (! $get('plant_id') || ! $get('block_name')) {
return []; return [];
} }
@@ -148,11 +144,9 @@ class ProductionPlanResource extends Resource
}) })
// ->afterStateUpdated(fn ($set) => $set('line_id', null)) // ->afterStateUpdated(fn ($set) => $set('line_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id')) if ($get('id')) {
{
$getShift = ProductionPlan::where('id', $get('id'))->first(); $getShift = ProductionPlan::where('id', $get('id'))->first();
if($getShift->shift_id) if ($getShift->shift_id) {
{
$set('shift_id', $getShift->shift_id); $set('shift_id', $getShift->shift_id);
$set('ppShiftError', null); $set('ppShiftError', null);
} }
@@ -161,12 +155,11 @@ class ProductionPlanResource extends Resource
$curShiftId = $get('shift_id'); $curShiftId = $get('shift_id');
$set('line_id', null); $set('line_id', null);
if (!$curShiftId) { if (! $curShiftId) {
$set('ppShiftError', 'Please select a shift first.'); $set('ppShiftError', 'Please select a shift first.');
return; return;
} } else {
else
{
$set('ppShiftError', null); $set('ppShiftError', null);
} }
}) })
@@ -185,7 +178,7 @@ class ProductionPlanResource extends Resource
// ->toArray() // Convert collection to array // ->toArray() // Convert collection to array
// ) // )
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id') || !$get('block_name') || !$get('shift_id')) { if (! $get('plant_id') || ! $get('block_name') || ! $get('shift_id')) {
return []; return [];
} }
@@ -198,17 +191,13 @@ class ProductionPlanResource extends Resource
// return optional(ProductionPlan::latest()->first())->line_id; // return optional(ProductionPlan::latest()->first())->line_id;
// }) // })
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id')) if ($get('id')) {
{
$getShift = ProductionPlan::where('id', $get('id'))->first(); $getShift = ProductionPlan::where('id', $get('id'))->first();
if($getShift->line_id) if ($getShift->line_id) {
{
$set('line_id', $getShift->line_id); $set('line_id', $getShift->line_id);
$set('ppLineError', null); $set('ppLineError', null);
} }
} } else {
else
{
$currentDT = Carbon::now()->toDateTimeString(); $currentDT = Carbon::now()->toDateTimeString();
$set('created_at', $currentDT); $set('created_at', $currentDT);
$set('update_date', null); $set('update_date', null);
@@ -217,44 +206,39 @@ class ProductionPlanResource extends Resource
$lineId = $get('line_id'); $lineId = $get('line_id');
// $set('plan_quantity', null); // $set('plan_quantity', null);
if (!$lineId) { if (! $lineId) {
$set('ppLineError', 'Please select a line first.'); $set('ppLineError', 'Please select a line first.');
return;
}
else
{
$isUpdate = !empty($get('id'));
if (!$isUpdate)
{
$exists = ProductionPlan::where('plant_id', $get('plant_id'))
->where('shift_id', $get('shift_id'))
->where('line_id', $get('line_id'))
->whereDate('created_at', today())
->latest()
->exists();
if ($exists) return;
{ } else {
$set('line_id', null); $isUpdate = ! empty($get('id'));
$set('ppLineError', 'Production plan already updated.'); if (! $isUpdate) {
return; $exists = ProductionPlan::where('plant_id', $get('plant_id'))
}
else
{
$existShifts = ProductionPlan::where('plant_id', $get('plant_id'))
->where('shift_id', $get('shift_id')) ->where('shift_id', $get('shift_id'))
->where('line_id', $get('line_id')) ->where('line_id', $get('line_id'))
->whereDate('created_at', Carbon::yesterday()) ->whereDate('created_at', today())
->latest() ->latest()
->exists(); ->exists();
if ($existShifts) //if ($existShifts->count() > 0) if ($exists) {
{ $set('line_id', null);
//$currentDate = date('Y-m-d'); $set('ppLineError', 'Production plan already updated.');
return;
} else {
$existShifts = ProductionPlan::where('plant_id', $get('plant_id'))
->where('shift_id', $get('shift_id'))
->where('line_id', $get('line_id'))
->whereDate('created_at', Carbon::yesterday())
->latest()
->exists();
if ($existShifts) { // if ($existShifts->count() > 0)
// $currentDate = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 days')); $yesterday = date('Y-m-d', strtotime('-1 days'));
$shiftId = Shift::where('id', $get('shift_id')) $shiftId = Shift::where('id', $get('shift_id'))
->first(); ->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0]; [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
$hRs = (int) $hRs; $hRs = (int) $hRs;
@@ -262,27 +246,26 @@ class ProductionPlanResource extends Resource
$totalMinutes = $hRs * 60 + $miNs; $totalMinutes = $hRs * 60 + $miNs;
$from_dt = $yesterday . ' ' . $shiftId->start_time; $from_dt = $yesterday.' '.$shiftId->start_time;
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes")); $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
$currentDateTime = date('Y-m-d H:i:s'); $currentDateTime = date('Y-m-d H:i:s');
// Check if current date time is within the range // Check if current date time is within the range
if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) { if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
//echo "Choosed a valid shift..."; // echo "Choosed a valid shift...";
$set('line_id', null); $set('line_id', null);
$set('ppLineError', 'Production plan already updated.'); $set('ppLineError', 'Production plan already updated.');
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')'); // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
return; return;
} } else {
else
{
$currentDate = date('Y-m-d'); $currentDate = date('Y-m-d');
$shiftId = Shift::where('id', $get('shift_id')) $shiftId = Shift::where('id', $get('shift_id'))
->first(); ->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0]; [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
$hRs = (int) $hRs; $hRs = (int) $hRs;
@@ -290,33 +273,33 @@ class ProductionPlanResource extends Resource
$totalMinutes = $hRs * 60 + $miNs; $totalMinutes = $hRs * 60 + $miNs;
$from_dt = $currentDate . ' ' . $shiftId->start_time; $from_dt = $currentDate.' '.$shiftId->start_time;
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes")); $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
$currentDateTime = date('Y-m-d H:i:s'); $currentDateTime = date('Y-m-d H:i:s');
// Check if current date time is within the range // Check if current date time is within the range
if (!($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) { if (! ($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
//echo "Choosed a valid shift..."; // echo "Choosed a valid shift...";
$set('line_id', null); $set('line_id', null);
$set('ppLineError', 'Choosed a invalid shift.'); $set('ppLineError', 'Choosed a invalid shift.');
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')'); // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
return; return;
} }
} }
$set('ppLineError', null); $set('ppLineError', null);
return; return;
} } else {
else // $currentDate = date('Y-m-d');
{
//$currentDate = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 days')); $yesterday = date('Y-m-d', strtotime('-1 days'));
$shiftId = Shift::where('id', $get('shift_id')) $shiftId = Shift::where('id', $get('shift_id'))
->first(); ->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0]; [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
$hRs = (int) $hRs; $hRs = (int) $hRs;
@@ -324,30 +307,29 @@ class ProductionPlanResource extends Resource
$totalMinutes = $hRs * 60 + $miNs; $totalMinutes = $hRs * 60 + $miNs;
$from_dt = $yesterday . ' ' . $shiftId->start_time; $from_dt = $yesterday.' '.$shiftId->start_time;
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes")); $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
$currentDateTime = date('Y-m-d H:i:s'); $currentDateTime = date('Y-m-d H:i:s');
// Check if current date time is within the range // Check if current date time is within the range
if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) { if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
//echo "Choosed a valid shift..."; // echo "Choosed a valid shift...";
// here i'm updating created as yesterday // here i'm updating created as yesterday
$set('created_at', $from_dt); $set('created_at', $from_dt);
$set('update_date', '1'); $set('update_date', '1');
$set('ppLineError', null); $set('ppLineError', null);
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')'); // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
return; return;
} } else {
else
{
$currentDate = date('Y-m-d'); $currentDate = date('Y-m-d');
$shiftId = Shift::where('id', $get('shift_id')) $shiftId = Shift::where('id', $get('shift_id'))
->first(); ->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0]; [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
$hRs = (int) $hRs; $hRs = (int) $hRs;
@@ -355,24 +337,26 @@ class ProductionPlanResource extends Resource
$totalMinutes = $hRs * 60 + $miNs; $totalMinutes = $hRs * 60 + $miNs;
$from_dt = $currentDate . ' ' . $shiftId->start_time; $from_dt = $currentDate.' '.$shiftId->start_time;
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes")); $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
$currentDateTime = date('Y-m-d H:i:s'); $currentDateTime = date('Y-m-d H:i:s');
// Check if current date time is within the range // Check if current date time is within the range
if (!($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) { if (! ($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
//echo "Choosed a valid shift..."; // echo "Choosed a valid shift...";
$set('line_id', null); $set('line_id', null);
$set('ppLineError', 'Choosed a invalid shift.'); $set('ppLineError', 'Choosed a invalid shift.');
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')'); // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
return; return;
} }
} }
$set('ppLineError', null); $set('ppLineError', null);
return; return;
} }
@@ -449,21 +433,18 @@ class ProductionPlanResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$planQuan = $get('plan_quantity'); $planQuan = $get('plan_quantity');
if(!$get('update_date') ) if (! $get('update_date')) {
{ if (! $get('id')) {
if(!$get('id'))
{
$currentDT = Carbon::now()->toDateTimeString(); $currentDT = Carbon::now()->toDateTimeString();
$set('created_at', $currentDT); $set('created_at', $currentDT);
} }
} }
if (!$planQuan) { if (! $planQuan) {
$set('ppPlanQuanError', 'Scan the valid plan quantity.'); $set('ppPlanQuanError', 'Scan the valid plan quantity.');
return; return;
} } else {
else
{
$set('ppPlanQuanError', null); $set('ppPlanQuanError', null);
} }
}) })
@@ -476,7 +457,7 @@ class ProductionPlanResource extends Resource
->required() ->required()
->integer() ->integer()
->label('Production Quantity') ->label('Production Quantity')
->readOnly(fn (callable $get) => !$get('id')) ->readOnly(fn (callable $get) => ! $get('id'))
->default(0), ->default(0),
Forms\Components\TextInput::make('id') Forms\Components\TextInput::make('id')
->hidden() ->hidden()
@@ -493,7 +474,7 @@ class ProductionPlanResource extends Resource
->readOnly(), ->readOnly(),
Forms\Components\Hidden::make('operator_id') Forms\Components\Hidden::make('operator_id')
->default(Filament::auth()->user()->name), ->default(Filament::auth()->user()->name),
]) ])
->columns(2), ->columns(2),
]); ]);
} }
@@ -529,6 +510,7 @@ class ProductionPlanResource extends Resource
$paginator = $livewire->getTableRecords(); $paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10; $perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1; $currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration; return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}), }),
Tables\Columns\TextColumn::make('plan_quantity') Tables\Columns\TextColumn::make('plan_quantity')
@@ -544,7 +526,7 @@ class ProductionPlanResource extends Resource
Tables\Columns\TextColumn::make('line.name') Tables\Columns\TextColumn::make('line.name')
->label('Line') ->label('Line')
->alignCenter() ->alignCenter()
->sortable(),// ->searchable(), ->sortable(), // ->searchable(),
Tables\Columns\TextColumn::make('shift.block.name') Tables\Columns\TextColumn::make('shift.block.name')
->label('Block') ->label('Block')
->alignCenter() ->alignCenter()
@@ -552,11 +534,11 @@ class ProductionPlanResource extends Resource
Tables\Columns\TextColumn::make('shift.name') Tables\Columns\TextColumn::make('shift.name')
->label('Shift') ->label('Shift')
->alignCenter() ->alignCenter()
->sortable(),// ->searchable(), ->sortable(), // ->searchable(),
Tables\Columns\TextColumn::make('plant.name') Tables\Columns\TextColumn::make('plant.name')
->label('Plant') ->label('Plant')
->alignCenter() ->alignCenter()
->sortable(),// ->searchable(), ->sortable(), // ->searchable(),
Tables\Columns\TextColumn::make('created_at') Tables\Columns\TextColumn::make('created_at')
->label('Created At') ->label('Created At')
->dateTime() ->dateTime()
@@ -584,7 +566,7 @@ class ProductionPlanResource extends Resource
Filter::make('advanced_filters') Filter::make('advanced_filters')
->label('Advanced Filters') ->label('Advanced Filters')
->form([ ->form([
//plant // plant
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
@@ -593,6 +575,7 @@ class ProductionPlanResource extends Resource
// }) // })
->options(function (callable $get) { ->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id; $userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
@@ -602,31 +585,33 @@ class ProductionPlanResource extends Resource
$set('Shift', null); $set('Shift', null);
}), }),
//line // line
Select::make('Line') Select::make('Line')
->label('Select line') ->label('Select line')
->nullable() ->nullable()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if (!$plantId ) { if (! $plantId) {
return []; return [];
} }
return Line::where('plant_id', $plantId) return Line::where('plant_id', $plantId)
->pluck('name', 'id'); ->pluck('name', 'id');
}) })
->reactive(), ->reactive(),
//block // block
Select::make('Block') Select::make('Block')
->label('Select Block') ->label('Select Block')
->nullable() ->nullable()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if (!$plantId ) { if (! $plantId) {
return []; return [];
} }
return Block::where('plant_id', $get('Plant'))->pluck('name', 'id'); return Block::where('plant_id', $get('Plant'))->pluck('name', 'id');
}) })
->reactive() ->reactive()
@@ -634,7 +619,7 @@ class ProductionPlanResource extends Resource
$set('Shift', null); $set('Shift', null);
}), }),
//shift // shift
Select::make('Shift') Select::make('Shift')
->label('Select Shift') ->label('Select Shift')
->nullable() ->nullable()
@@ -642,7 +627,7 @@ class ProductionPlanResource extends Resource
$plantId = $get('Plant'); $plantId = $get('Plant');
$blockId = $get('Block'); $blockId = $get('Block');
if (!$plantId || !$blockId) { if (! $plantId || ! $blockId) {
return []; // Return empty if plant or block is not selected return []; // Return empty if plant or block is not selected
} }
@@ -669,52 +654,65 @@ class ProductionPlanResource extends Resource
return $query->whereRaw('1 = 0'); return $query->whereRaw('1 = 0');
} }
if ($plant = $data['Plant'] ?? null) { if (! empty($data['Plant'])) {// if ($plant = $data['Plant'] ?? null) {
$query->where('plant_id', $plant); $query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
} }
if ($shift = $data['Shift'] ?? null) { if (! empty($data['Shift'])) {// if ($shift = $data['Shift'] ?? null) {
$query->where('shift_id', $shift); $query->where('shift_id', $data['Shift']);
} }
if ($line = $data['Line'] ?? null) { if (! empty($data['Line'])) {// if ($line = $data['Line'] ?? null) {
$query->where('line_id', $line); $query->where('line_id', $data['Line']);
} }
if ($from = $data['created_from'] ?? null) { if (! empty($data['created_from'])) {// if ($from = $data['created_from'] ?? null) {
$query->where('created_at', '>=', $from); $query->where('created_at', '>=', $data['created_from']);
} }
if ($to = $data['created_to'] ?? null) { if (! empty($data['created_to'])) {// if ($to = $data['created_to'] ?? null) {
$query->where('created_at', '<=', $to); $query->where('created_at', '<=', $data['created_to']);
} }
return $query; return $query;
}) })
->indicateUsing(function (array $data) { ->indicateUsing(function (array $data) {
$indicators = []; $indicators = [];
if (!empty($data['Plant'])) { if (! empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name'); $indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
} }
if (!empty($data['Shift'])) { if (! empty($data['Shift'])) {
$indicators[] = 'Shift: ' . Shift::where('id', $data['Shift'])->value('name'); $indicators[] = 'Shift: '.Shift::where('id', $data['Shift'])->value('name');
} }
if (!empty($data['Line'])) { if (! empty($data['Line'])) {
$indicators[] = 'Line: ' . Line::where('id', $data['Line'])->value('name'); $indicators[] = 'Line: '.Line::where('id', $data['Line'])->value('name');
} }
if (!empty($data['created_from'])) { if (! empty($data['created_from'])) {
$indicators[] = 'From: ' . $data['created_from']; $indicators[] = 'From: '.$data['created_from'];
} }
if (!empty($data['created_to'])) { if (! empty($data['created_to'])) {
$indicators[] = 'To: ' . $data['created_to']; $indicators[] = 'To: '.$data['created_to'];
} }
return $indicators; return $indicators;
}) }),
]) ])
->filtersFormMaxHeight('280px') ->filtersFormMaxHeight('280px')
->actions([ ->actions([
@@ -726,7 +724,7 @@ class ProductionPlanResource extends Resource
Tables\Actions\DeleteBulkAction::make(), Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(), Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(), Tables\Actions\RestoreBulkAction::make(),
FilamentExportBulkAction::make('export') FilamentExportBulkAction::make('export'),
]), ]),
]) ])
->headerActions([ ->headerActions([
@@ -734,14 +732,14 @@ class ProductionPlanResource extends Resource
->label('Import Production Plans') ->label('Import Production Plans')
->color('warning') ->color('warning')
->importer(ProductionPlanImporter::class) ->importer(ProductionPlanImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import production plan'); return Filament::auth()->user()->can('view import production plan');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Production Plans') ->label('Export Production Plans')
->color('warning') ->color('warning')
->exporter(ProductionPlanExporter::class) ->exporter(ProductionPlanExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export production plan'); return Filament::auth()->user()->can('view export production plan');
}), }),
]); ]);