Added view rights against plant on view report and Updated alignments and load available item code logic 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:56:53 +05:30
parent f1c0dc738c
commit f9cb090a25

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\ProductCharacteristicsMasterExporter; use App\Filament\Exports\ProductCharacteristicsMasterExporter;
use App\Filament\Imports\ProductCharacteristicsMasterImporter; use App\Filament\Imports\ProductCharacteristicsMasterImporter;
use App\Filament\Resources\ProductCharacteristicsMasterResource\Pages; use App\Filament\Resources\ProductCharacteristicsMasterResource\Pages;
use App\Filament\Resources\ProductCharacteristicsMasterResource\RelationManagers;
use App\Models\Item; use App\Models\Item;
use App\Models\Line; use App\Models\Line;
use App\Models\Machine; use App\Models\Machine;
@@ -14,19 +13,19 @@ use App\Models\ProductCharacteristicsMaster;
use App\Models\WorkGroupMaster; use App\Models\WorkGroupMaster;
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\TextInput;
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\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\Forms\Components\DateTimePicker;
use Filament\Tables\Filters\Filter;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
class ProductCharacteristicsMasterResource extends Resource class ProductCharacteristicsMasterResource extends Resource
{ {
@@ -45,13 +44,14 @@ class ProductCharacteristicsMasterResource extends Resource
->relationship('plant', 'name') ->relationship('plant', 'name')
->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()
->required(), ->required(),
Forms\Components\Select::make('item_id') Forms\Components\Select::make('item_id')
->label('Item Code') ->label('Item Code')
//->relationship('item', 'code') // ->relationship('item', 'code')
->searchable() ->searchable()
->reactive() ->reactive()
->options(function (callable $get) { ->options(function (callable $get) {
@@ -59,6 +59,7 @@ class ProductCharacteristicsMasterResource extends Resource
if (empty($plantId)) { if (empty($plantId)) {
return []; return [];
} }
return \App\Models\Item::where('plant_id', $plantId)->pluck('code', 'id'); return \App\Models\Item::where('plant_id', $plantId)->pluck('code', 'id');
}) })
->required(), ->required(),
@@ -70,12 +71,13 @@ class ProductCharacteristicsMasterResource extends Resource
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');
}) })
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('machine_id', null); $set('machine_id', null);
if (!$get('work_group_master_id')) { if (! $get('work_group_master_id')) {
$set('machine_id', null); $set('machine_id', null);
} }
}) })
@@ -86,7 +88,7 @@ class ProductCharacteristicsMasterResource extends Resource
->required() ->required()
->reactive() ->reactive()
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id') || !$get('line_id')) { if (! $get('plant_id') || ! $get('line_id')) {
return []; return [];
} }
@@ -94,23 +96,22 @@ class ProductCharacteristicsMasterResource extends Resource
$workGroupIds = []; $workGroupIds = [];
for ($i = 1; $i <= $line->no_of_operation; $i++) { for ($i = 1; $i <= $line->no_of_operation; $i++) {
$column = "work_group{$i}_id"; $column = "work_group{$i}_id";
if (!empty($line->$column)) { if (! empty($line->$column)) {
$workGroupIds[] = $line->$column; $workGroupIds[] = $line->$column;
} }
} }
return WorkGroupMaster::where('plant_id', $get('plant_id'))->whereIn('id', $workGroupIds)->pluck('name', 'id')->toArray(); return WorkGroupMaster::where('plant_id', $get('plant_id'))->whereIn('id', $workGroupIds)->pluck('name', 'id')->toArray();
}) })
->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) {
$lineId = $get('line_id'); $lineId = $get('line_id');
if (!$lineId) { if (! $lineId) {
$set('mGroupWorkError', 'Please select a line first.'); $set('mGroupWorkError', 'Please select a line first.');
$set('machine_id', null); $set('machine_id', null);
return; return;
} } else {
else
{
// $grpWrkCnr = Line::find($lineId)->group_work_center; // $grpWrkCnr = Line::find($lineId)->group_work_center;
// if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1) // if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1)
// { // {
@@ -130,7 +131,7 @@ class ProductCharacteristicsMasterResource extends Resource
->hintColor('danger'), ->hintColor('danger'),
Forms\Components\Select::make('machine_id') Forms\Components\Select::make('machine_id')
->label('Work Center') ->label('Work Center')
//->relationship('machine', 'name'), // ->relationship('machine', 'name'),
->searchable() ->searchable()
->reactive() ->reactive()
->options(function (callable $get) { ->options(function (callable $get) {
@@ -148,7 +149,7 @@ class ProductCharacteristicsMasterResource extends Resource
->pluck('work_center', 'id'); ->pluck('work_center', 'id');
}) })
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
if (!$get('plant_id') || !$get('line_id') || !$get('work_group_master_id')) { if (! $get('plant_id') || ! $get('line_id') || ! $get('work_group_master_id')) {
$set('machine_id', null); $set('machine_id', null);
} }
}) })
@@ -208,9 +209,9 @@ class ProductCharacteristicsMasterResource extends Resource
$upper = $get('upper'); $upper = $get('upper');
$middle = $value; $middle = $value;
if (!is_null($lower) && !is_null($upper) && !is_null($middle)) { if (! is_null($lower) && ! is_null($upper) && ! is_null($middle)) {
if (!($lower <= $middle && $middle <= $upper)) { if (! ($lower <= $middle && $middle <= $upper)) {
$fail("Middle must be between Lower and Upper (Lower ≤ Middle ≤ Upper)."); $fail('Middle must be between Lower and Upper (Lower ≤ Middle ≤ Upper).');
} }
} }
}; };
@@ -233,6 +234,7 @@ class ProductCharacteristicsMasterResource 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')
@@ -317,11 +319,7 @@ class ProductCharacteristicsMasterResource extends Resource
->sortable() ->sortable()
->toggleable(isToggledHiddenByDefault: true), ->toggleable(isToggledHiddenByDefault: true),
]) ])
// ->filters([
// Tables\Filters\TrashedFilter::make(),
// ])
->filters([ ->filters([
Tables\Filters\TrashedFilter::make(), Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters') Filter::make('advanced_filters')
->label('Advanced Filters') ->label('Advanced Filters')
@@ -331,6 +329,7 @@ class ProductCharacteristicsMasterResource 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()
@@ -343,50 +342,48 @@ class ProductCharacteristicsMasterResource 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) {
$set('Item', null); $set('Item', null);
}), }),
Select::make('Item') Select::make('Item')
->label('Item Code') ->label('Search by Item Code')
->nullable() ->nullable()
->searchable() ->searchable()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if(empty($plantId)) { return Item::whereHas('productCharacteristicsMasters', function ($query) use ($plantId) {
return []; if ($plantId) {
$query->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') : [];
}) })
->reactive() ->reactive(),
->afterStateUpdated(function ($state, callable $set, callable $get) { // ->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('process_order', null); // $set('process_order', null);
}), // }),
Select::make('work_group_master') Select::make('work_group_master')
->label('Select Work Group Master') ->label('Select Work Group Master')
->nullable() ->nullable()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if(empty($plantId)) { if (empty($plantId)) {
return []; return [];
} }
return WorkGroupMaster::where('plant_id', $plantId)->pluck('name', 'id'); return WorkGroupMaster::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) {
@@ -399,13 +396,13 @@ class ProductCharacteristicsMasterResource 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) {
@@ -421,7 +418,7 @@ class ProductCharacteristicsMasterResource extends Resource
->label('Characteristics Type') ->label('Characteristics Type')
->options([ ->options([
'Product' => 'Product', 'Product' => 'Product',
'Process' => 'Process' 'Process' => 'Process',
]), ]),
DateTimePicker::make(name: 'created_from') DateTimePicker::make(name: 'created_from')
->label('Created From') ->label('Created From')
@@ -440,78 +437,89 @@ class ProductCharacteristicsMasterResource 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['work_group_master'])) { if (! empty($data['work_group_master'])) {
$query->where('work_group_master_id', $data['work_group_master']); $query->where('work_group_master_id', $data['work_group_master']);
} }
if (!empty($data['Machine'])) { if (! empty($data['Machine'])) {
$query->where('machine_id', $data['Machine']); $query->where('machine_id', $data['Machine']);
} }
if (!empty($data['characteristics_type'])) { if (! empty($data['characteristics_type'])) {
$query->where('characteristics_type', $data['characteristics_type']); $query->where('characteristics_type', $data['characteristics_type']);
} }
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['work_group_master'])) { if (! empty($data['work_group_master'])) {
$indicators[] = 'Work Group Master: ' . WorkGroupMaster::where('id', $data['work_group_master'])->value('name'); $indicators[] = 'Work Group Master: '.WorkGroupMaster::where('id', $data['work_group_master'])->value('name');
} }
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['characteristics_type'])) { if (! empty($data['characteristics_type'])) {
$indicators[] = 'Characteristics Type: ' . $data['characteristics_type']; $indicators[] = 'Characteristics Type: '.$data['characteristics_type'];
} }
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([
@@ -530,14 +538,14 @@ class ProductCharacteristicsMasterResource extends Resource
->label('Import Product Characteristics Masters') ->label('Import Product Characteristics Masters')
->color('warning') ->color('warning')
->importer(ProductCharacteristicsMasterImporter::class) ->importer(ProductCharacteristicsMasterImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import product characteristics master'); return Filament::auth()->user()->can('view import product characteristics master');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Product Characteristics Masters') ->label('Export Product Characteristics Masters')
->color('warning') ->color('warning')
->exporter(ProductCharacteristicsMasterExporter::class) ->exporter(ProductCharacteristicsMasterExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export product characteristics master'); return Filament::auth()->user()->can('view export product characteristics master');
}), }),
]); ]);