Added view rights against plant
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-13 15:54:01 +05:30
parent bec3e9f8bd
commit 22c65c4308

View File

@@ -5,26 +5,25 @@ namespace App\Filament\Resources;
use App\Filament\Exports\CharacteristicValueExporter; use App\Filament\Exports\CharacteristicValueExporter;
use App\Filament\Imports\CharacteristicValueImporter; use App\Filament\Imports\CharacteristicValueImporter;
use App\Filament\Resources\CharacteristicValueResource\Pages; use App\Filament\Resources\CharacteristicValueResource\Pages;
use App\Filament\Resources\CharacteristicValueResource\RelationManagers;
use App\Models\CharacteristicValue; use App\Models\CharacteristicValue;
use App\Models\Item; use App\Models\Item;
use App\Models\Line; use App\Models\Line;
use App\Models\Machine; use App\Models\Machine;
use App\Models\Plant; use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form; use Filament\Forms\Form;
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\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\Facades\Filament;
use Filament\Forms\Components\DateTimePicker;
use Filament\Tables\Filters\Filter;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
class CharacteristicValueResource extends Resource class CharacteristicValueResource extends Resource
{ {
@@ -65,7 +64,7 @@ class CharacteristicValueResource extends Resource
Forms\Components\Select::make('line_id') Forms\Components\Select::make('line_id')
->label('Line') ->label('Line')
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id')) { if (! $get('plant_id')) {
return []; return [];
} }
@@ -86,7 +85,7 @@ class CharacteristicValueResource extends Resource
Forms\Components\Select::make('item_id') Forms\Components\Select::make('item_id')
->label('Item') ->label('Item')
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id') || !$get('line_id')) { if (! $get('plant_id') || ! $get('line_id')) {
return []; return [];
} }
@@ -107,7 +106,7 @@ class CharacteristicValueResource extends Resource
Forms\Components\Select::make('machine_id') Forms\Components\Select::make('machine_id')
->label('Machine') ->label('Machine')
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id') || !$get('line_id') || !$get('item_id')) { if (! $get('plant_id') || ! $get('line_id') || ! $get('item_id')) {
return []; return [];
} }
@@ -192,7 +191,7 @@ class CharacteristicValueResource extends Resource
->label('Status') ->label('Status')
->options([ ->options([
'Ok' => 'OK', 'Ok' => 'OK',
'NotOk' => 'Not Ok' 'NotOk' => 'Not Ok',
]) ])
->reactive() ->reactive()
->required(), ->required(),
@@ -296,6 +295,7 @@ class CharacteristicValueResource extends Resource
->nullable() ->nullable()
->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()
@@ -308,13 +308,13 @@ class CharacteristicValueResource extends Resource
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if(empty($plantId)) { if (empty($plantId)) {
return []; return [];
} }
return Line::where('plant_id', $plantId)->pluck('name', 'id'); return Line::where('plant_id', $plantId)->pluck('name', 'id');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : []; // return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -327,13 +327,13 @@ class CharacteristicValueResource extends Resource
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if(empty($plantId)) { if (empty($plantId)) {
return []; return [];
} }
return Item::where('plant_id', $plantId)->pluck('code', 'id'); return Item::where('plant_id', $plantId)->pluck('code', 'id');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : []; // return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -346,13 +346,13 @@ class CharacteristicValueResource extends Resource
$plantId = $get('Plant'); $plantId = $get('Plant');
$lineId = $get('Line'); $lineId = $get('Line');
if(empty($plantId) || empty($lineId)) { if (empty($plantId) || empty($lineId)) {
return []; return [];
} }
return Machine::where('plant_id', $plantId)->where('line_id', $lineId)->pluck('work_center', 'id'); return Machine::where('plant_id', $plantId)->where('line_id', $lineId)->pluck('work_center', 'id');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : []; // return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -368,7 +368,7 @@ class CharacteristicValueResource extends Resource
->label('Status') ->label('Status')
->options([ ->options([
'Ok' => 'OK', 'Ok' => 'OK',
'NotOk' => 'Not Ok' 'NotOk' => 'Not Ok',
]), ]),
DateTimePicker::make(name: 'created_from') DateTimePicker::make(name: 'created_from')
->label('Created From') ->label('Created From')
@@ -387,86 +387,97 @@ class CharacteristicValueResource extends Resource
return $query->whereRaw('1 = 0'); return $query->whereRaw('1 = 0');
} }
if (!empty($data['Plant'])) { if (! empty($data['Plant'])) {
$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['Line'])) { if (! empty($data['Line'])) {
$query->where('line_id', $data['Line']); $query->where('line_id', $data['Line']);
} }
if (!empty($data['Item'])) { if (! empty($data['Item'])) {
$query->where('item_id', $data['Item']); $query->where('item_id', $data['Item']);
} }
if (!empty($data['Machine'])) { if (! empty($data['Machine'])) {
$query->where('machine_id', $data['Machine']); $query->where('machine_id', $data['Machine']);
} }
if (!empty($data['process_order'])) { if (! empty($data['process_order'])) {
$query->where('process_order', $data['process_order']); $query->where('process_order', $data['process_order']);
} }
if (!empty($data['coil_number'])) { if (! empty($data['coil_number'])) {
$query->where('coil_number', $data['coil_number']); $query->where('coil_number', $data['coil_number']);
} }
if (!empty($data['status'])) { if (! empty($data['status'])) {
$query->where('status', $data['status']); $query->where('status', $data['status']);
} }
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']);
} }
// $query->orderBy('created_at', 'asc');
//$query->orderBy('created_at', 'asc');
}) })
->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['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['Item'])) { if (! empty($data['Item'])) {
$indicators[] = 'Item: ' . Item::where('id', $data['Item'])->value('code'); $indicators[] = 'Item: '.Item::where('id', $data['Item'])->value('code');
} }
if (!empty($data['Machine'])) { if (! empty($data['Machine'])) {
$indicators[] = 'Machine: ' . Machine::where('id', $data['Machine'])->value('work_center'); $indicators[] = 'Machine: '.Machine::where('id', $data['Machine'])->value('work_center');
} }
if (!empty($data['process_order'])) { if (! empty($data['process_order'])) {
$indicators[] = 'Process Order: ' . $data['process_order']; $indicators[] = 'Process Order: '.$data['process_order'];
} }
if (!empty($data['coil_number'])) { if (! empty($data['coil_number'])) {
$indicators[] = 'Coil Number: ' . $data['coil_number']; $indicators[] = 'Coil Number: '.$data['coil_number'];
} }
if (!empty($data['status'])) { if (! empty($data['status'])) {
$indicators[] = 'Status: ' . $data['status']; $indicators[] = 'Status: '.$data['status'];
} }
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([