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\Imports\ProductCharacteristicsMasterImporter;
use App\Filament\Resources\ProductCharacteristicsMasterResource\Pages;
use App\Filament\Resources\ProductCharacteristicsMasterResource\RelationManagers;
use App\Models\Item;
use App\Models\Line;
use App\Models\Machine;
@@ -14,19 +13,19 @@ use App\Models\ProductCharacteristicsMaster;
use App\Models\WorkGroupMaster;
use Filament\Facades\Filament;
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\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
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
{
@@ -45,6 +44,7 @@ class ProductCharacteristicsMasterResource extends Resource
->relationship('plant', 'name')
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->reactive()
@@ -59,6 +59,7 @@ class ProductCharacteristicsMasterResource extends Resource
if (empty($plantId)) {
return [];
}
return \App\Models\Item::where('plant_id', $plantId)->pluck('code', 'id');
})
->required(),
@@ -70,6 +71,7 @@ class ProductCharacteristicsMasterResource extends Resource
if (empty($plantId)) {
return [];
}
return Line::where('plant_id', $plantId)->pluck('name', 'id');
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -107,10 +109,9 @@ class ProductCharacteristicsMasterResource extends Resource
if (! $lineId) {
$set('mGroupWorkError', 'Please select a line first.');
$set('machine_id', null);
return;
}
else
{
} else {
// $grpWrkCnr = Line::find($lineId)->group_work_center;
// if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1)
// {
@@ -210,7 +211,7 @@ class ProductCharacteristicsMasterResource extends Resource
if (! is_null($lower) && ! is_null($upper) && ! is_null($middle)) {
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();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
@@ -317,11 +319,7 @@ class ProductCharacteristicsMasterResource extends Resource
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
// ->filters([
// Tables\Filters\TrashedFilter::make(),
// ])
->filters([
Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters')
->label('Advanced Filters')
@@ -331,6 +329,7 @@ class ProductCharacteristicsMasterResource extends Resource
->nullable()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->reactive()
@@ -356,24 +355,22 @@ class ProductCharacteristicsMasterResource extends Resource
$set('Item', null);
}),
Select::make('Item')
->label('Item Code')
->label('Search by Item Code')
->nullable()
->searchable()
->options(function (callable $get) {
$plantId = $get('Plant');
if(empty($plantId)) {
return [];
return Item::whereHas('productCharacteristicsMasters', function ($query) use ($plantId) {
if ($plantId) {
$query->where('plant_id', $plantId);
}
return Item::where('plant_id', $plantId)->pluck('code', 'id');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
})->pluck('code', 'id');
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('process_order', null);
}),
->reactive(),
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
// $set('process_order', null);
// }),
Select::make('work_group_master')
->label('Select Work Group Master')
->nullable()
@@ -421,7 +418,7 @@ class ProductCharacteristicsMasterResource extends Resource
->label('Characteristics Type')
->options([
'Product' => 'Product',
'Process' => 'Process'
'Process' => 'Process',
]),
DateTimePicker::make(name: 'created_from')
->label('Created From')
@@ -442,6 +439,12 @@ class ProductCharacteristicsMasterResource extends Resource
if (! empty($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'])) {
@@ -472,7 +475,6 @@ class ProductCharacteristicsMasterResource extends Resource
$query->where('created_at', '<=', $data['created_to']);
}
// $query->orderBy('created_at', 'asc');
})
->indicateUsing(function (array $data) {
@@ -480,6 +482,12 @@ class ProductCharacteristicsMasterResource extends Resource
if (! empty($data['Plant'])) {
$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'])) {
@@ -511,7 +519,7 @@ class ProductCharacteristicsMasterResource extends Resource
}
return $indicators;
})
}),
])
->filtersFormMaxHeight('280px')
->actions([