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:31:12 +05:30
parent 4a4259612b
commit f4a6496411

View File

@@ -5,31 +5,24 @@ namespace App\Filament\Resources;
use App\Filament\Exports\PalletValidationExporter; use App\Filament\Exports\PalletValidationExporter;
use App\Filament\Imports\PalletValidationImporter; use App\Filament\Imports\PalletValidationImporter;
use App\Filament\Resources\PalletValidationResource\Pages; use App\Filament\Resources\PalletValidationResource\Pages;
use App\Filament\Resources\PalletValidationResource\RelationManagers;
use App\Models\Item;
use App\Models\LocatorInvoiceValidation; use App\Models\LocatorInvoiceValidation;
use App\Models\PalletValidation; use App\Models\PalletValidation;
use App\Models\Plant; use App\Models\Plant;
use App\Models\StickerMaster;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Section; use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form; use Filament\Forms\Form;
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\Forms\Components\Actions;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Log;
use Filament\Tables\Actions\Action;
use Filament\Forms\Components\DateTimePicker;
use Filament\Tables\Filters\Filter;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
class PalletValidationResource extends Resource class PalletValidationResource extends Resource
{ {
@@ -55,6 +48,7 @@ class PalletValidationResource 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();
}) })
->afterStateUpdated(function ($state, callable $set) { ->afterStateUpdated(function ($state, callable $set) {
@@ -74,8 +68,7 @@ class PalletValidationResource extends Resource
'x-model' => 'value', 'x-model' => 'value',
'x-on:keydown.enter.prevent' => '$wire.processPalletNo()', 'x-on:keydown.enter.prevent' => '$wire.processPalletNo()',
]) ])
->suffixAction(fn ($get,$set) => ->suffixAction(fn ($get, $set) => Forms\Components\Actions\Action::make('addPallet')
Forms\Components\Actions\Action::make('addPallet')
->label('') ->label('')
->button() ->button()
->icon('heroicon-o-plus') ->icon('heroicon-o-plus')
@@ -105,14 +98,12 @@ class PalletValidationResource extends Resource
} else { } else {
$newNumber = str_pad(intval($serialPart2) + 1, strlen($serialPart2), '0', STR_PAD_LEFT); $newNumber = str_pad(intval($serialPart2) + 1, strlen($serialPart2), '0', STR_PAD_LEFT);
} }
} } elseif ($lastPallet1) {
else if ($lastPallet1) {
$serialPart1 = substr($lastPallet1->pallet_number, strlen($prefix)); $serialPart1 = substr($lastPallet1->pallet_number, strlen($prefix));
// OR // OR
// $serialPart = str_replace($prefix, '', $lastPallet->pallet_number); // $serialPart = str_replace($prefix, '', $lastPallet->pallet_number);
$newNumber = str_pad(intval($serialPart1) + 1, strlen($serialPart1), '0', STR_PAD_LEFT); $newNumber = str_pad(intval($serialPart1) + 1, strlen($serialPart1), '0', STR_PAD_LEFT);
} } elseif ($lastPallet2) {
else if ($lastPallet2) {
$serialPart2 = substr($lastPallet2->pallet_number, strlen($prefix)); $serialPart2 = substr($lastPallet2->pallet_number, strlen($prefix));
// OR // OR
// $serialPart = str_replace($prefix, '', $lastPallet->pallet_number); // $serialPart = str_replace($prefix, '', $lastPallet->pallet_number);
@@ -172,6 +163,7 @@ class PalletValidationResource extends Resource
if (! $plantId) { if (! $plantId) {
return []; return [];
} }
return PalletValidation::query() return PalletValidation::query()
->where('plant_id', $plantId) ->where('plant_id', $plantId)
->where(function ($query) { ->where(function ($query) {
@@ -186,7 +178,7 @@ class PalletValidationResource extends Resource
->toArray(); ->toArray();
}), }),
Forms\Components\View::make('forms.components.save-pallet-button') Forms\Components\View::make('forms.components.save-pallet-button'),
]) ])
->columns(5), ->columns(5),
Forms\Components\TextInput::make('id') Forms\Components\TextInput::make('id')
@@ -199,7 +191,6 @@ class PalletValidationResource extends Resource
public static function table(Table $table): Table public static function table(Table $table): Table
{ {
return $table return $table
->columns([ ->columns([
// Tables\Columns\TextColumn::make('id') // Tables\Columns\TextColumn::make('id')
// ->label('ID') // ->label('ID')
@@ -212,6 +203,7 @@ class PalletValidationResource 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')
@@ -286,6 +278,7 @@ class PalletValidationResource 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()
@@ -309,6 +302,7 @@ class PalletValidationResource extends Resource
if (! $plantId) { if (! $plantId) {
return []; return [];
} }
return PalletValidation::where('plant_id', $plantId) return PalletValidation::where('plant_id', $plantId)
// ->whereNotNull('pallet_number') // ->whereNotNull('pallet_number')
// ->where('pallet_number', '!=', '') // ->where('pallet_number', '!=', '')
@@ -339,6 +333,7 @@ class PalletValidationResource extends Resource
if (! $plantId) { if (! $plantId) {
return []; return [];
} }
return PalletValidation::where('plant_id', $plantId) return PalletValidation::where('plant_id', $plantId)
->whereNotNull('locator_number') ->whereNotNull('locator_number')
->where('locator_number', '!=', '') ->where('locator_number', '!=', '')
@@ -393,6 +388,12 @@ class PalletValidationResource extends Resource
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
$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['pallet_number'])) { if (! empty($data['pallet_number'])) {
@@ -448,6 +449,12 @@ class PalletValidationResource 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['pallet_number'])) { if (! empty($data['pallet_number'])) {
@@ -495,7 +502,7 @@ class PalletValidationResource extends Resource
} }
return $indicators; return $indicators;
}) }),
]) ])
->filtersFormMaxHeight('280px') ->filtersFormMaxHeight('280px')
->actions([ ->actions([
@@ -521,6 +528,7 @@ class PalletValidationResource extends Resource
// ->options(Plant::pluck('name', 'id')->toArray()) // ->options(Plant::pluck('name', 'id')->toArray())
->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();
}) })
->required() ->required()
@@ -555,6 +563,7 @@ class PalletValidationResource extends Resource
]) ])
->action(function (array $data) { ->action(function (array $data) {
$selectedPalletNumber = $data['pallet_list']; $selectedPalletNumber = $data['pallet_list'];
return redirect()->route('download-reprint-qr-pdf', ['palletNo' => $selectedPalletNumber]); return redirect()->route('download-reprint-qr-pdf', ['palletNo' => $selectedPalletNumber]);
}) })