Refactor plant selection logic in ItemResource and StickerMasterResource to order by code
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 12s
Gemini PR Review / review (pull_request) Failing after 22s
Laravel Larastan / larastan (pull_request) Failing after 2m19s
Laravel Pint / pint (pull_request) Failing after 2m50s

This commit is contained in:
dhanabalan
2025-12-01 10:09:22 +05:30
parent c8c38a05f4
commit 173638cd19
2 changed files with 10 additions and 14 deletions

View File

@@ -237,9 +237,6 @@ class ItemResource 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')
@@ -251,11 +248,11 @@ class ItemResource 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)->orderBy('code')->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void { ->afterStateUpdated(function ($state, callable $set, callable $get): void {
$set('item_id', null); $set('code', null);
$set('operator_id', null); $set('operator_id', null);
}), }),
Select::make('code') Select::make('code')
@@ -300,7 +297,7 @@ class ItemResource extends Resource
// Hide all records initially if no filters are applied // Hide all records initially if no filters are applied
if ( if (
empty($data['Plant']) && empty($data['Plant']) &&
empty($data['item_id']) && empty($data['code']) &&
empty($data['description']) && empty($data['description']) &&
empty($data['uom']) && empty($data['uom']) &&
empty($data['category']) && empty($data['category']) &&
@@ -314,8 +311,8 @@ class ItemResource extends Resource
$query->where('plant_id', $data['Plant']); $query->where('plant_id', $data['Plant']);
} }
if (! empty($data['item_id'])) { if (! empty($data['code'])) {
$query->where('item_id', $data['item_id']); $query->where('id', $data['code']);
} }
if (! empty($data['description'])) { if (! empty($data['description'])) {
@@ -337,7 +334,6 @@ class ItemResource extends Resource
if (! empty($data['created_to'])) { if (! empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']); $query->where('created_at', '<=', $data['created_to']);
} }
}) })
->indicateUsing(function (array $data) { ->indicateUsing(function (array $data) {
$indicators = []; $indicators = [];
@@ -346,8 +342,8 @@ class ItemResource extends Resource
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name'); $indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} }
if (! empty($data['item_id'])) { if (! empty($data['code'])) {
$indicators[] = 'Item Code: '.$data['item_id']; $indicators[] = 'Item Code: '.Item::where('id', $data['code'])->value('code');
} }
if (! empty($data['description'])) { if (! empty($data['description'])) {
@@ -621,10 +617,10 @@ class ItemResource extends Resource
}), }),
// ->maxRows(100000), // ->maxRows(100000),
ExportAction::make() ExportAction::make()
// ->columnMapping(true) // ->columnMapping(true)
->label('Export Items') ->label('Export Items')
->color('warning') ->color('warning')
// ->fileName("Items Report " . date('Y-m-d H:i:s')) // ->fileName("Items Report " . date('Y-m-d H:i:s'))
->exporter(ItemExporter::class) ->exporter(ItemExporter::class)
->visible(function () { ->visible(function () {
return Filament::auth()->user()->can('view export item'); return Filament::auth()->user()->can('view export item');

View File

@@ -601,7 +601,7 @@ class StickerMasterResource 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)->orderBy('code')->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void { ->afterStateUpdated(function ($state, callable $set, callable $get): void {