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,6 +48,7 @@ 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 () {
@@ -59,10 +59,9 @@ class MotorTestingMasterResource extends Resource
$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);
} }
}) })
@@ -108,17 +107,17 @@ class MotorTestingMasterResource extends Resource
$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);
@@ -145,16 +144,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')
@@ -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');
} }
}) })
@@ -627,6 +608,12 @@ class MotorTestingMasterResource extends Resource
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'])) {
@@ -642,7 +629,9 @@ class MotorTestingMasterResource extends Resource
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) {
$query->where('plant_id', $pId);
}
})->pluck('id')->toArray(); })->pluck('id')->toArray();
if (! empty($descIds)) { if (! empty($descIds)) {
@@ -652,8 +641,7 @@ class MotorTestingMasterResource extends Resource
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);
} }
@@ -694,6 +682,12 @@ class MotorTestingMasterResource extends Resource
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'])) {
@@ -707,8 +701,7 @@ class MotorTestingMasterResource extends Resource
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';
} }
@@ -745,7 +738,7 @@ class MotorTestingMasterResource extends Resource
} }
return $indicators; return $indicators;
}) }),
]) ])
->filtersFormMaxHeight('280px') ->filtersFormMaxHeight('280px')
->actions([ ->actions([