Added view rights against plant on view report and Updated alignment on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s

This commit is contained in:
dhanabalan
2026-01-14 09:23:07 +05:30
parent 4ad848054f
commit 978a23449a

View File

@@ -5,21 +5,20 @@ namespace App\Filament\Resources;
use App\Filament\Exports\LocatorExporter; use App\Filament\Exports\LocatorExporter;
use App\Filament\Imports\LocatorImporter; use App\Filament\Imports\LocatorImporter;
use App\Filament\Resources\LocatorResource\Pages; use App\Filament\Resources\LocatorResource\Pages;
use App\Filament\Resources\LocatorResource\RelationManagers;
use App\Models\Locator; use App\Models\Locator;
use App\Models\PalletValidation; use App\Models\PalletValidation;
use App\Models\Plant; use App\Models\Plant;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Get;
use Filament\Tables\Actions\ImportAction;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Select; use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form; use Filament\Forms\Form;
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\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Filters\Filter; use Filament\Tables\Filters\Filter;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
@@ -48,25 +47,25 @@ class LocatorResource 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(Locator::latest()->first())->plant_id; return optional(Locator::latest()->first())->plant_id;
}) })
->disabled(fn (Get $get) => !empty($get('id'))) ->disabled(fn (Get $get) => ! empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null)) // ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
// Ensure `linestop_id` is not cleared // Ensure `linestop_id` is not cleared
if (!$plantId) { if (! $plantId) {
$set('locPlantError', 'Please select a plant first.'); $set('locPlantError', 'Please select a plant first.');
$set('locator_number', null); $set('locator_number', null);
$set('locator_quantity', 0); $set('locator_quantity', 0);
$set('operator_id', Filament::auth()->user()?->name); $set('operator_id', Filament::auth()->user()?->name);
return; return;
} } else {
else
{
$set('locPlantError', null); $set('locPlantError', null);
$set('locator_number', null); $set('locator_number', null);
$set('locator_quantity', 0); $set('locator_quantity', 0);
@@ -86,21 +85,20 @@ class LocatorResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
$locator = $get('locator_number'); $locator = $get('locator_number');
if (!$plantId) { if (! $plantId) {
$set('locNameError', 'Please select a plant first.'); $set('locNameError', 'Please select a plant first.');
$set('locator_number', null); $set('locator_number', null);
$set('locator_quantity', 0); $set('locator_quantity', 0);
$set('operator_id', Filament::auth()->user()?->name); $set('operator_id', Filament::auth()->user()?->name);
return; return;
} } elseif (! $locator || Str::length($locator) < 7) {
else if (!$locator || Str::length($locator) < 7) {
$set('locNameError', 'Please scan the valid locator number.'); $set('locNameError', 'Please scan the valid locator number.');
$set('locator_quantity', 0); $set('locator_quantity', 0);
$set('operator_id', Filament::auth()->user()?->name); $set('operator_id', Filament::auth()->user()?->name);
return; return;
} } else {
else
{
$set('locNameError', null); $set('locNameError', null);
$set('locator_quantity', PalletValidation::where('locator_number', $locator)->where('plant_id', $plantId)->distinct('pallet_number')->count('pallet_number')); $set('locator_quantity', PalletValidation::where('locator_number', $locator)->where('plant_id', $plantId)->distinct('pallet_number')->count('pallet_number'));
$set('operator_id', Filament::auth()->user()?->name); $set('operator_id', Filament::auth()->user()?->name);
@@ -145,6 +143,7 @@ class LocatorResource 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('plant.name') Tables\Columns\TextColumn::make('plant.name')
@@ -194,6 +193,7 @@ class LocatorResource 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()
@@ -210,9 +210,10 @@ class LocatorResource extends Resource
->label('Locator Number') ->label('Locator Number')
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if (!$plantId) { if (! $plantId) {
return []; return [];
} }
return Locator::where('plant_id', $plantId)->orderBy('locator_number', 'asc')->get()->unique('locator_number')->pluck('locator_number', 'locator_number')->toArray(); return Locator::where('plant_id', $plantId)->orderBy('locator_number', 'asc')->get()->unique('locator_number')->pluck('locator_number', 'locator_number')->toArray();
// ->whereNotNull('locator_number') // ->whereNotNull('locator_number')
// ->where('locator_number','!=', '') // ->where('locator_number','!=', '')
@@ -258,75 +259,87 @@ class LocatorResource extends Resource
return $query->whereRaw('1 = 0'); return $query->whereRaw('1 = 0');
} }
if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
$query->where('plant_id', $data['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 (!empty($data['locator_number'])) { if (! empty($data['locator_number'])) {
$query->where('locator_number', $data['locator_number']); $query->where('locator_number', $data['locator_number']);
} }
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { //isset($data['locator_quantity']) && if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { // isset($data['locator_quantity']) &&
$query->where('locator_quantity', $data['locator_quantity']);//(int) $query->where('locator_quantity', $data['locator_quantity']); // (int)
} }
if (!empty($data['created_from'])) { if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']); $query->where('created_at', '>=', $data['created_from']);
} }
if (!empty($data['created_to'])) { if (! empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']); $query->where('created_at', '<=', $data['created_to']);
} }
if (!empty($data['created_by'])) { if (! empty($data['created_by'])) {
$query->where('operator_id', $data['created_by']); $query->where('operator_id', $data['created_by']);
} }
if (!empty($data['updated_from'])) { if (! empty($data['updated_from'])) {
$query->where('updated_at', '>=', $data['updated_from']); $query->where('updated_at', '>=', $data['updated_from']);
} }
if (!empty($data['updated_to'])) { if (! empty($data['updated_to'])) {
$query->where('updated_at', '<=', $data['updated_to']); $query->where('updated_at', '<=', $data['updated_to']);
} }
}) })
->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['locator_number'])) { if (! empty($data['locator_number'])) {
$indicators[] = 'Locator Number: ' . $data['locator_number']; $indicators[] = 'Locator Number: '.$data['locator_number'];
} }
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { //isset($data['locator_quantity']) && if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { // isset($data['locator_quantity']) &&
$indicators[] = 'Locator Quantity: ' . $data['locator_quantity']; $indicators[] = 'Locator Quantity: '.$data['locator_quantity'];
} }
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'];
} }
if (!empty($data['created_by'])) { if (! empty($data['created_by'])) {
$indicators[] = 'Created By: ' . $data['created_by']; $indicators[] = 'Created By: '.$data['created_by'];
} }
if (!empty($data['updated_from'])) { if (! empty($data['updated_from'])) {
$indicators[] = 'Updated From: ' . $data['updated_from']; $indicators[] = 'Updated From: '.$data['updated_from'];
} }
if (!empty($data['updated_to'])) { if (! empty($data['updated_to'])) {
$indicators[] = 'Updated To: ' . $data['updated_to']; $indicators[] = 'Updated To: '.$data['updated_to'];
} }
return $indicators; return $indicators;
}) }),
]) ])
->filtersFormMaxHeight('280px') ->filtersFormMaxHeight('280px')
->actions([ ->actions([
@@ -345,14 +358,14 @@ class LocatorResource extends Resource
->label('Import Locators') ->label('Import Locators')
->color('warning') ->color('warning')
->importer(LocatorImporter::class) ->importer(LocatorImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import locator'); return Filament::auth()->user()->can('view import locator');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Locators') ->label('Export Locators')
->color('warning') ->color('warning')
->exporter(LocatorExporter::class) ->exporter(LocatorExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export locator'); return Filament::auth()->user()->can('view export locator');
}), }),
]); ]);