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:26:35 +05:30
parent 978a23449a
commit 4a4259612b

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\MotorTestingMasterExporter; use App\Filament\Exports\MotorTestingMasterExporter;
use App\Filament\Imports\MotorTestingMasterImporter; use App\Filament\Imports\MotorTestingMasterImporter;
use App\Filament\Resources\MotorTestingMasterResource\Pages; use App\Filament\Resources\MotorTestingMasterResource\Pages;
use App\Filament\Resources\MotorTestingMasterResource\RelationManagers;
use App\Models\Configuration; use App\Models\Configuration;
use App\Models\Item; use App\Models\Item;
use App\Models\MotorTestingMaster; use App\Models\MotorTestingMaster;
@@ -20,12 +19,12 @@ 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\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\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Filters\Filter;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
class MotorTestingMasterResource extends Resource class MotorTestingMasterResource extends Resource
@@ -49,20 +48,20 @@ class MotorTestingMasterResource 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(MotorTestingMaster::latest()->first())->plant_id; return optional(MotorTestingMaster::latest()->first())->plant_id;
}) })
->disabled(fn (Get $get) => !empty($get('id'))) ->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if (!$plantId) { if (! $plantId) {
$set('mTmError', 'Please select a plant first.'); $set('mTmError', 'Please select a plant first.');
return; return;
} } else {
else
{
$set('mTmError', null); $set('mTmError', null);
} }
}) })
@@ -78,10 +77,10 @@ class MotorTestingMasterResource extends Resource
->reactive(), ->reactive(),
Forms\Components\Select::make('item_id') Forms\Components\Select::make('item_id')
->label('Item Code') ->label('Item Code')
//->relationship('item', 'name') // ->relationship('item', 'name')
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if (!$plantId) { if (! $plantId) {
return []; return [];
} }
@@ -106,19 +105,19 @@ class MotorTestingMasterResource extends Resource
->minLength(6) ->minLength(6)
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$code = $get('subassembly_code'); $code = $get('subassembly_code');
if (!$code) { if (! $code) {
$set('iCodeError', 'Scan the valid Subassembly Code.'); $set('iCodeError', 'Scan the valid Subassembly Code.');
return; return;
} } else {
else
{
if (strlen($code) < 6) { if (strlen($code) < 6) {
$set('iCodeError', 'Subassembly code must be at least 6 digits.'); $set('iCodeError', 'Subassembly code must be at least 6 digits.');
return; return;
} } elseif (! preg_match('/^[a-zA-Z0-9]{6,}$/', $code)) {
else if (!preg_match('/^[a-zA-Z0-9]{6,}$/', $code)) { $set('code', null);
$set('code',null);
$set('iCodeError', 'Subassembly code must contain only alpha-numeric characters.'); $set('iCodeError', 'Subassembly code must contain only alpha-numeric characters.');
return; return;
} }
$set('iCodeError', null); $set('iCodeError', null);
@@ -143,24 +142,21 @@ class MotorTestingMasterResource extends Resource
Forms\Components\Select::make('phase') Forms\Components\Select::make('phase')
->label('Phase') ->label('Phase')
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if ($plantId) if ($plantId) {
{ return Configuration::where('plant_id', $plantId)
return Configuration::where('plant_id', $plantId) ->where('c_name', 'MOTOR_PHASE')
->where('c_name', 'MOTOR_PHASE') ->orderBy('created_at')
->orderBy('created_at') ->pluck('c_value', 'c_value')
->pluck('c_value', 'c_value') ->toArray();
->toArray(); } else {
} return Configuration::where('c_name', 'MOTOR_PHASE')
else ->orderBy('created_at')
{ ->pluck('c_value', 'c_value')
return Configuration::where('c_name', 'MOTOR_PHASE') ->toArray();
->orderBy('created_at') }
->pluck('c_value', 'c_value') })
->toArray();
}
})
->selectablePlaceholder(false) ->selectablePlaceholder(false)
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -197,16 +193,13 @@ class MotorTestingMasterResource extends Resource
->selectablePlaceholder(false) ->selectablePlaceholder(false)
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if ($plantId) if ($plantId) {
{
return Configuration::where('plant_id', $plantId) return Configuration::where('plant_id', $plantId)
->where('c_name', 'MOTOR_CONNECTION') ->where('c_name', 'MOTOR_CONNECTION')
->orderBy('created_at') ->orderBy('created_at')
->pluck('c_value', 'c_value') ->pluck('c_value', 'c_value')
->toArray(); ->toArray();
} } else {
else
{
return Configuration::where('c_name', 'MOTOR_CONNECTION') return Configuration::where('c_name', 'MOTOR_CONNECTION')
->orderBy('created_at') ->orderBy('created_at')
->pluck('c_value', 'c_value') ->pluck('c_value', 'c_value')
@@ -230,16 +223,13 @@ class MotorTestingMasterResource extends Resource
->selectablePlaceholder(false) ->selectablePlaceholder(false)
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if ($plantId) if ($plantId) {
{
return Configuration::where('plant_id', $plantId) return Configuration::where('plant_id', $plantId)
->where('c_name', 'INSULATION_RESISTANCE_TYPE') ->where('c_name', 'INSULATION_RESISTANCE_TYPE')
->orderBy('created_at') ->orderBy('created_at')
->pluck('c_value', 'c_value') ->pluck('c_value', 'c_value')
->toArray(); ->toArray();
} } else {
else
{
return Configuration::where('c_name', 'INSULATION_RESISTANCE_TYPE') return Configuration::where('c_name', 'INSULATION_RESISTANCE_TYPE')
->orderBy('created_at') ->orderBy('created_at')
->pluck('c_value', 'c_value') ->pluck('c_value', 'c_value')
@@ -317,6 +307,7 @@ class MotorTestingMasterResource 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')
@@ -474,6 +465,7 @@ class MotorTestingMasterResource 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()
@@ -488,6 +480,7 @@ class MotorTestingMasterResource extends Resource
->nullable() ->nullable()
->options(function (callable $get) { ->options(function (callable $get) {
$pId = $get('Plant'); $pId = $get('Plant');
return Item::whereHas('motorTestingMasters', function ($query) use ($pId) { return Item::whereHas('motorTestingMasters', function ($query) use ($pId) {
if ($pId) { if ($pId) {
$query->where('plant_id', $pId); $query->where('plant_id', $pId);
@@ -505,7 +498,7 @@ class MotorTestingMasterResource extends Resource
->options([ ->options([
'All' => 'All', 'All' => 'All',
'Y' => 'Y', 'Y' => 'Y',
'N' => 'N' 'N' => 'N',
]) ])
->default(null) ->default(null)
->inlineLabel(false) ->inlineLabel(false)
@@ -516,16 +509,13 @@ class MotorTestingMasterResource extends Resource
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if ($plantId) if ($plantId) {
{
return Configuration::where('plant_id', $plantId) return Configuration::where('plant_id', $plantId)
->where('c_name', 'MOTOR_PHASE') ->where('c_name', 'MOTOR_PHASE')
->orderBy('created_at') ->orderBy('created_at')
->pluck('c_value', 'c_value') ->pluck('c_value', 'c_value')
->toArray(); ->toArray();
} } else {
else
{
return Configuration::where('c_name', 'MOTOR_PHASE') return Configuration::where('c_name', 'MOTOR_PHASE')
->orderBy('created_at') ->orderBy('created_at')
->pluck('c_value', 'c_value') ->pluck('c_value', 'c_value')
@@ -544,16 +534,13 @@ class MotorTestingMasterResource extends Resource
->nullable() ->nullable()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if ($plantId) if ($plantId) {
{
return Configuration::where('plant_id', $plantId) return Configuration::where('plant_id', $plantId)
->where('c_name', 'MOTOR_CONNECTION') ->where('c_name', 'MOTOR_CONNECTION')
->orderBy('created_at') ->orderBy('created_at')
->pluck('c_value', 'c_value') ->pluck('c_value', 'c_value')
->toArray(); ->toArray();
} } else {
else
{
return Configuration::where('c_name', 'MOTOR_CONNECTION') return Configuration::where('c_name', 'MOTOR_CONNECTION')
->orderBy('created_at') ->orderBy('created_at')
->pluck('c_value', 'c_value') ->pluck('c_value', 'c_value')
@@ -571,12 +558,9 @@ class MotorTestingMasterResource extends Resource
->nullable() ->nullable()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if (!$plantId) if (! $plantId) {
{
return MotorTestingMaster::whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by'); return MotorTestingMaster::whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by');
} } else {
else
{
return MotorTestingMaster::where('plant_id', $plantId)->whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by'); return MotorTestingMaster::where('plant_id', $plantId)->whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by');
} }
}) })
@@ -597,12 +581,9 @@ class MotorTestingMasterResource extends Resource
->nullable() ->nullable()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if (!$plantId) if (! $plantId) {
{
return MotorTestingMaster::whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by'); return MotorTestingMaster::whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by');
} } else {
else
{
return MotorTestingMaster::where('plant_id', $plantId)->whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by'); return MotorTestingMaster::where('plant_id', $plantId)->whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by');
} }
}) })
@@ -625,127 +606,139 @@ class MotorTestingMasterResource 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['Item'])) { if (! empty($data['Item'])) {
$itemIds = Item::where('id', $data['Item']) $itemIds = Item::where('id', $data['Item'])
->pluck('id') ->pluck('id')
->toArray(); ->toArray();
if (!empty($itemIds)) { if (! empty($itemIds)) {
$query->whereIn('item_id', $itemIds); $query->whereIn('item_id', $itemIds);
} }
} }
if (!empty($data['description'])) { if (! empty($data['description'])) {
$pId = $data['Plant'] ?? null; $pId = $data['Plant'] ?? null;
$descIds = Item::where('description', 'like', '%' . $data['description'] . '%')->whereHas('motorTestingMasters', function ($query) use ($pId) { $descIds = Item::where('description', 'like', '%'.$data['description'].'%')->whereHas('motorTestingMasters', function ($query) use ($pId) {
if ($pId) { $query->where('plant_id', $pId); } if ($pId) {
})->pluck('id')->toArray(); $query->where('plant_id', $pId);
}
})->pluck('id')->toArray();
if (!empty($descIds)) { if (! empty($descIds)) {
$query->whereIn('item_id', $descIds); $query->whereIn('item_id', $descIds);
} }
} }
if ($data['isi_type'] == 'Y') { if ($data['isi_type'] == 'Y') {
$query->where('isi_model', true); $query->where('isi_model', true);
} } elseif ($data['isi_type'] == 'N') {
else if ($data['isi_type'] == 'N') {
$query->where('isi_model', false); $query->where('isi_model', false);
} }
if (!empty($data['phase_type'])) { if (! empty($data['phase_type'])) {
$query->where('phase', $data['phase_type']); $query->where('phase', $data['phase_type']);
} }
if (!empty($data['connection_type'])) { if (! empty($data['connection_type'])) {
$query->where('connection', $data['connection_type']); $query->where('connection', $data['connection_type']);
} }
if (!empty($data['created_by'])) { if (! empty($data['created_by'])) {
$query->where('created_by', $data['created_by']); $query->where('created_by', $data['created_by']);
} }
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['updated_by'])) { if (! empty($data['updated_by'])) {
$query->where('updated_by', $data['updated_by']); $query->where('updated_by', $data['updated_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['Item'])) { if (! empty($data['Item'])) {
$itemCode = Item::find($data['Item'])->code ?? 'Unknown'; $itemCode = Item::find($data['Item'])->code ?? 'Unknown';
$indicators[] = 'Item Codes: ' . $itemCode; $indicators[] = 'Item Codes: '.$itemCode;
} }
if (!empty($data['description'])) { if (! empty($data['description'])) {
$indicators[] = 'Description: ' . $data['description']; $indicators[] = 'Description: '.$data['description'];
} }
if ($data['isi_type'] == 'Y') { if ($data['isi_type'] == 'Y') {
$indicators[] = 'ISI Model: Yes'; $indicators[] = 'ISI Model: Yes';
} } elseif ($data['isi_type'] == 'N') {
else if ($data['isi_type'] == 'N') {
$indicators[] = 'ISI Model: No'; $indicators[] = 'ISI Model: No';
} }
if (!empty($data['phase_type'])) { if (! empty($data['phase_type'])) {
$indicators[] = 'Phase: ' . $data['phase_type']; $indicators[] = 'Phase: '.$data['phase_type'];
} }
if (!empty($data['connection_type'])) { if (! empty($data['connection_type'])) {
$indicators[] = 'Connection: ' . $data['connection_type']; $indicators[] = 'Connection: '.$data['connection_type'];
} }
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['created_from'])) { if (! empty($data['created_from'])) {
$indicators[] = 'Created From: ' . $data['created_from']; $indicators[] = 'Created From: '.$data['created_from'];
} }
if (!empty($data['created_to'])) { if (! empty($data['created_to'])) {
$indicators[] = 'Created To: ' . $data['created_to']; $indicators[] = 'Created To: '.$data['created_to'];
} }
if (!empty($data['updated_by'])) { if (! empty($data['updated_by'])) {
$indicators[] = 'Updated By: ' . $data['updated_by']; $indicators[] = 'Updated By: '.$data['updated_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([
@@ -764,14 +757,14 @@ class MotorTestingMasterResource extends Resource
->label('Import Motor Testing Masters') ->label('Import Motor Testing Masters')
->color('warning') ->color('warning')
->importer(MotorTestingMasterImporter::class) ->importer(MotorTestingMasterImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import motor testing master'); return Filament::auth()->user()->can('view import motor testing master');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Motor Testing Masters') ->label('Export Motor Testing Masters')
->color('warning') ->color('warning')
->exporter(MotorTestingMasterExporter::class) ->exporter(MotorTestingMasterExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export motor testing master'); return Filament::auth()->user()->can('view export motor testing master');
}), }),
]); ]);