Added view rights against plant on view report and Updated alignment on resource
This commit is contained in:
@@ -5,21 +5,20 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\LocatorExporter;
|
||||
use App\Filament\Imports\LocatorImporter;
|
||||
use App\Filament\Resources\LocatorResource\Pages;
|
||||
use App\Filament\Resources\LocatorResource\RelationManagers;
|
||||
use App\Models\Locator;
|
||||
use App\Models\PalletValidation;
|
||||
use App\Models\Plant;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
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;
|
||||
@@ -48,6 +47,7 @@ class LocatorResource 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();
|
||||
})
|
||||
->default(function () {
|
||||
@@ -63,10 +63,9 @@ class LocatorResource extends Resource
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('locPlantError', null);
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', 0);
|
||||
@@ -91,16 +90,15 @@ class LocatorResource extends Resource
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
|
||||
return;
|
||||
}
|
||||
else if (!$locator || Str::length($locator) < 7) {
|
||||
} elseif (! $locator || Str::length($locator) < 7) {
|
||||
$set('locNameError', 'Please scan the valid locator number.');
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('locNameError', null);
|
||||
$set('locator_quantity', PalletValidation::where('locator_number', $locator)->where('plant_id', $plantId)->distinct('pallet_number')->count('pallet_number'));
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
@@ -145,6 +143,7 @@ class LocatorResource 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')
|
||||
@@ -194,6 +193,7 @@ class LocatorResource 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()
|
||||
@@ -213,6 +213,7 @@ class LocatorResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Locator::where('plant_id', $plantId)->orderBy('locator_number', 'asc')->get()->unique('locator_number')->pluck('locator_number', 'locator_number')->toArray();
|
||||
// ->whereNotNull('locator_number')
|
||||
// ->where('locator_number','!=', '')
|
||||
@@ -260,6 +261,12 @@ class LocatorResource 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['locator_number'])) {
|
||||
@@ -295,6 +302,12 @@ class LocatorResource 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['locator_number'])) {
|
||||
@@ -326,7 +339,7 @@ class LocatorResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
|
||||
Reference in New Issue
Block a user