1
0
forked from poc/pds

Added view rights against plant on view report and Updated alignment on resource

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