Added view rights against plant on view report and Updated alignments 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 11:02:25 +05:30
parent 75d87cda29
commit 0a69d515a4

View File

@@ -5,30 +5,28 @@ namespace App\Filament\Resources;
use App\Filament\Exports\ReworkLocatorInvoiceValidationExporter; use App\Filament\Exports\ReworkLocatorInvoiceValidationExporter;
use App\Filament\Imports\ReworkLocatorInvoiceValidationImporter; use App\Filament\Imports\ReworkLocatorInvoiceValidationImporter;
use App\Filament\Resources\ReworkLocatorInvoiceValidationResource\Pages; use App\Filament\Resources\ReworkLocatorInvoiceValidationResource\Pages;
use App\Filament\Resources\ReworkLocatorInvoiceValidationResource\RelationManagers;
use App\Models\InvoiceValidation;
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\ReworkLocatorInvoiceValidation; use App\Models\ReworkLocatorInvoiceValidation;
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\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\ToggleButtons;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Notifications\Notification;
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\Section;
use Filament\Forms\Components\ToggleButtons;
use Filament\Forms\Get;
use Filament\Notifications\Notification;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Forms\Components\DateTimePicker;
use Filament\Tables\Filters\Filter;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Select;
class ReworkLocatorInvoiceValidationResource extends Resource class ReworkLocatorInvoiceValidationResource extends Resource
{ {
@@ -54,20 +52,18 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->required() ->required()
->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, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if ($plantId) if ($plantId) {
{
$set('plant', $plantId); $set('plant', $plantId);
$set('invoice_number', null); $set('invoice_number', null);
$set('scan_pallet_no', null); $set('scan_pallet_no', null);
$set('scan_serial_no', null); $set('scan_serial_no', null);
$set('rework_type', null); $set('rework_type', null);
} } else {
else
{
$set('plant', null); $set('plant', null);
$set('invoice_number', null); $set('invoice_number', null);
$set('scan_pallet_no', null); $set('scan_pallet_no', null);
@@ -128,8 +124,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$set('invoice_number', null); $set('invoice_number', null);
$set('scan_pallet_no', null); $set('scan_pallet_no', null);
$set('scan_serial_no', null); $set('scan_serial_no', null);
} } else {
else {
$set('reworkType', null); $set('reworkType', null);
$set('invoice_number', null); $set('invoice_number', null);
$set('scan_pallet_no', null); $set('scan_pallet_no', null);
@@ -163,16 +158,14 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->count(); ->count();
$isScanningComplete = true; $isScanningComplete = true;
foreach ($rows as $row) foreach ($rows as $row) {
{
if ($row->scanned_status != 'Scanned') { if ($row->scanned_status != 'Scanned') {
$isScanningComplete = false; $isScanningComplete = false;
break; break;
} }
} }
if (!$isScanningComplete) if (! $isScanningComplete) {
{
Notification::make() Notification::make()
->title("Scanned invoice number: '$invoiceNumber' does not completed the scanning process!<br>Has '$notCompletedCount' pending serial number to scan!<br>Please, scan the valid completed invoice number to proceed...") ->title("Scanned invoice number: '$invoiceNumber' does not completed the scanning process!<br>Has '$notCompletedCount' pending serial number to scan!<br>Please, scan the valid completed invoice number to proceed...")
->danger() ->danger()
@@ -181,6 +174,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$set('invoice_number', null); $set('invoice_number', null);
$set('update_invoice', null); $set('update_invoice', null);
return; return;
} }
}), }),
@@ -198,15 +192,13 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$serialNo = trim($get('scan_serial_no')); $serialNo = trim($get('scan_serial_no'));
$updatePalletStatus = $get('update_pallet') ?? null; $updatePalletStatus = $get('update_pallet') ?? null;
if ($updatePalletStatus == 0) if ($updatePalletStatus == 0) {
{
return; return;
} }
if (strlen($palletNumber) < 10) if (strlen($palletNumber) < 10) {
{
Notification::make() Notification::make()
->title("Invalid: Pallet Number") ->title('Invalid: Pallet Number')
->body("Pallet number '$palletNumber' must be at least 10 digits.") ->body("Pallet number '$palletNumber' must be at least 10 digits.")
->danger() ->danger()
->duration(5000) ->duration(5000)
@@ -216,13 +208,13 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$set('scan_serial_no', null); $set('scan_serial_no', null);
$set('scan_pallet_no', null); $set('scan_pallet_no', null);
$set('update_pallet', null); $set('update_pallet', null);
return; return;
} }
$PalletSerialNumbers = PalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNumber)->first(); $PalletSerialNumbers = PalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNumber)->first();
if (!$PalletSerialNumbers) if (! $PalletSerialNumbers) {
{
Notification::make() Notification::make()
->title('Pallet Not Found') ->title('Pallet Not Found')
->body("Pallet number '$palletNumber' doesn't exist in pallet table!<br><br>Scan the valid exist 'Pallet Number' to proceed..!") ->body("Pallet number '$palletNumber' doesn't exist in pallet table!<br><br>Scan the valid exist 'Pallet Number' to proceed..!")
@@ -234,6 +226,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$set('scan_serial_no', null); $set('scan_serial_no', null);
$set('scan_pallet_no', null); $set('scan_pallet_no', null);
$set('update_pallet', null); $set('update_pallet', null);
return; return;
} }
@@ -242,8 +235,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->get(); ->get();
$isScanningComplete = true; $isScanningComplete = true;
foreach ($rows as $row) foreach ($rows as $row) {
{
if ($row->pallet_status != 'Completed') { if ($row->pallet_status != 'Completed') {
$isScanningComplete = false; $isScanningComplete = false;
break; break;
@@ -254,8 +246,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$isScanningComplete = false; $isScanningComplete = false;
} }
if (!$isScanningComplete) if (! $isScanningComplete) {
{
Notification::make() Notification::make()
->title('Pallet Not Completed') ->title('Pallet Not Completed')
->body("Scanned pallet number '$palletNumber' doesn't completed the master packing!<br><br>Please, scan the valid completed pallet number to proceed..!") ->body("Scanned pallet number '$palletNumber' doesn't completed the master packing!<br><br>Please, scan the valid completed pallet number to proceed..!")
@@ -267,13 +258,11 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$set('scan_serial_no', null); $set('scan_serial_no', null);
$set('scan_pallet_no', null); $set('scan_pallet_no', null);
$set('update_pallet', null); $set('update_pallet', null);
return; return;
} } else {
else
{
$locatExist = ($PalletSerialNumbers->locator_number != null && $PalletSerialNumbers->locator_number != '') ? $PalletSerialNumbers->locator_number : ''; $locatExist = ($PalletSerialNumbers->locator_number != null && $PalletSerialNumbers->locator_number != '') ? $PalletSerialNumbers->locator_number : '';
if ($locatExist) if ($locatExist) {
{
Notification::make() Notification::make()
->title('Locator Pallet Found') ->title('Locator Pallet Found')
->body("Scanned pallet number '$palletNumber' exist in locator number '$locatExist'.<br><br>Remove scanned 'Pallet' from 'Locator' to proceed re-master packing..!") ->body("Scanned pallet number '$palletNumber' exist in locator number '$locatExist'.<br><br>Remove scanned 'Pallet' from 'Locator' to proceed re-master packing..!")
@@ -285,14 +274,12 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$set('scan_serial_no', null); $set('scan_serial_no', null);
$set('scan_pallet_no', null); $set('scan_pallet_no', null);
$set('update_pallet', null); $set('update_pallet', null);
return; return;
} } else {
else if (strlen($serialNo) > 0 && (strlen($serialNo) < 9 || strlen($serialNo) > 20)) {
{
if (strlen($serialNo) > 0 && (strlen($serialNo) < 9 || strlen($serialNo) > 20))
{
Notification::make() Notification::make()
->title("Invalid: Serial Number") ->title('Invalid: Serial Number')
->body("Serial number '$serialNo' should contain minimum 9 digits and maximum 20 digits.") ->body("Serial number '$serialNo' should contain minimum 9 digits and maximum 20 digits.")
->danger() ->danger()
->duration(5000) ->duration(5000)
@@ -301,12 +288,11 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$livewire->dispatch('loadData', '', $palletNumber, $plantId, 'pallet'); $livewire->dispatch('loadData', '', $palletNumber, $plantId, 'pallet');
$set('scan_serial_no', null); $set('scan_serial_no', null);
$set('update_pallet', null); $set('update_pallet', null);
return; return;
} } elseif (strlen($serialNo) > 0 && ! ctype_alnum($serialNo)) {
else if (strlen($serialNo) > 0 && !ctype_alnum($serialNo))
{
Notification::make() Notification::make()
->title("Invalid: Serial Number") ->title('Invalid: Serial Number')
->body("Serial number '$serialNo' must contain alpha-numeric values only.") ->body("Serial number '$serialNo' must contain alpha-numeric values only.")
->danger() ->danger()
->duration(5000) ->duration(5000)
@@ -315,13 +301,12 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$livewire->dispatch('loadData', '', $palletNumber, $plantId, 'pallet'); $livewire->dispatch('loadData', '', $palletNumber, $plantId, 'pallet');
$set('scan_serial_no', null); $set('scan_serial_no', null);
$set('update_pallet', null); $set('update_pallet', null);
return; return;
} }
if ($updatePalletStatus == 1) if ($updatePalletStatus == 1) {
{ foreach ($rows as $row) {
foreach ($rows as $row)
{
$row->forceDelete(); // Delete the row from the original table $row->forceDelete(); // Delete the row from the original table
} }
@@ -336,6 +321,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$set('scan_serial_no', null); $set('scan_serial_no', null);
$set('scan_pallet_no', null); $set('scan_pallet_no', null);
$set('update_pallet', null); $set('update_pallet', null);
return; return;
} }
} }
@@ -349,7 +335,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->hidden() ->hidden()
->readOnly(), ->readOnly(),
]) ])
->columns(5) ->columns(5),
]); ]);
} }
@@ -364,6 +350,7 @@ class ReworkLocatorInvoiceValidationResource 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')
@@ -455,9 +442,6 @@ class ReworkLocatorInvoiceValidationResource extends Resource
return Filament::auth()->user()->can('view export rework invoice validation'); return Filament::auth()->user()->can('view export rework invoice validation');
}), }),
]) ])
// ->filters([
// Tables\Filters\TrashedFilter::make(),
// ])
->filters([ ->filters([
Tables\Filters\TrashedFilter::make(), Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters') Filter::make('advanced_filters')
@@ -471,6 +455,7 @@ class ReworkLocatorInvoiceValidationResource 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()
@@ -494,6 +479,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
if (! $plantId) { if (! $plantId) {
return []; return [];
} }
return ReworkLocatorInvoiceValidation::where('plant_id', $plantId) return ReworkLocatorInvoiceValidation::where('plant_id', $plantId)
->whereNotNull('invoice_number') ->whereNotNull('invoice_number')
->where('invoice_number', '!=', '') ->where('invoice_number', '!=', '')
@@ -515,6 +501,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
if (! $plantId) { if (! $plantId) {
return []; return [];
} }
return ReworkLocatorInvoiceValidation::where('plant_id', $plantId) return ReworkLocatorInvoiceValidation::where('plant_id', $plantId)
->whereNotNull('pallet_number') ->whereNotNull('pallet_number')
->where('pallet_number', '!=', '') ->where('pallet_number', '!=', '')
@@ -533,6 +520,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
if (! $plantId) { if (! $plantId) {
return []; return [];
} }
return ReworkLocatorInvoiceValidation::where('plant_id', $plantId) return ReworkLocatorInvoiceValidation::where('plant_id', $plantId)
->whereNotNull('locator_number') ->whereNotNull('locator_number')
->where('locator_number', '!=', '') ->where('locator_number', '!=', '')
@@ -571,6 +559,12 @@ class ReworkLocatorInvoiceValidationResource 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['invoice_number'])) { if (! empty($data['invoice_number'])) {
@@ -610,6 +604,12 @@ class ReworkLocatorInvoiceValidationResource 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['invoice_number'])) { if (! empty($data['invoice_number'])) {
@@ -643,8 +643,9 @@ class ReworkLocatorInvoiceValidationResource extends Resource
if (! empty($data['rework_by'])) { if (! empty($data['rework_by'])) {
$indicators[] = 'Reworked By: '.$data['rework_by']; $indicators[] = 'Reworked By: '.$data['rework_by'];
} }
return $indicators; return $indicators;
}) }),
]) ])
->filtersFormMaxHeight('280px') ->filtersFormMaxHeight('280px')
->actions([ ->actions([