Merge pull request 'Refactor plant selection logic in ItemResource and StickerMasterResource to order by code' (#33) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s

Reviewed-on: #33
This commit was merged in pull request #33.
This commit is contained in:
2025-12-01 04:40:07 +00:00
2 changed files with 10 additions and 14 deletions

View File

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

View File

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