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\Imports\ReworkLocatorInvoiceValidationImporter;
use App\Filament\Resources\ReworkLocatorInvoiceValidationResource\Pages;
use App\Filament\Resources\ReworkLocatorInvoiceValidationResource\RelationManagers;
use App\Models\InvoiceValidation;
use App\Models\LocatorInvoiceValidation;
use App\Models\PalletValidation;
use App\Models\Plant;
use App\Models\ReworkLocatorInvoiceValidation;
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\Components\ToggleButtons;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Notifications\Notification;
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\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
{
@@ -54,20 +52,18 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->required()
->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, callable $get) {
$plantId = $get('plant_id');
if ($plantId)
{
if ($plantId) {
$set('plant', $plantId);
$set('invoice_number', null);
$set('scan_pallet_no', null);
$set('scan_serial_no', null);
$set('rework_type', null);
}
else
{
} else {
$set('plant', null);
$set('invoice_number', null);
$set('scan_pallet_no', null);
@@ -79,8 +75,8 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->reactive(),
Forms\Components\TextInput::make('invoice_number')
->label('Scan Invoice No')
->required( fn ($get) => $get('rework_type') == 'invoice')
->readOnly(fn (callable $get) => (!$get('plant') || $get('rework_type') != 'invoice' || $get('scan_pallet_no') || $get('scan_serial_no')))
->required(fn ($get) => $get('rework_type') == 'invoice')
->readOnly(fn (callable $get) => (! $get('plant') || $get('rework_type') != 'invoice' || $get('scan_pallet_no') || $get('scan_serial_no')))
// ->readOnly(fn ($get) => $get('rework_type') == 'pallet')
->reactive()
->extraAttributes([
@@ -88,17 +84,17 @@ class ReworkLocatorInvoiceValidationResource extends Resource
]),
Forms\Components\TextInput::make('scan_pallet_no')
->label('Scan Pallet No')
->required( fn ($get) => $get('rework_type') == 'pallet')
->required(fn ($get) => $get('rework_type') == 'pallet')
->readOnly(fn ($get) => $get('rework_type') == 'invoice')
->minLength(10)
->reactive()
->readOnly(fn (callable $get) => (!$get('plant') || !$get('rework_type') || ($get('rework_type') == 'invoice' && !$get('invoice_number')) || $get('scan_serial_no')))
->readOnly(fn (callable $get) => (! $get('plant') || ! $get('rework_type') || ($get('rework_type') == 'invoice' && ! $get('invoice_number')) || $get('scan_serial_no')))
->extraAttributes([
'wire:keydown.enter' => 'processPalletno($event.target.value)',
]),
Forms\Components\TextInput::make('scan_serial_no')
->label('Scan Serial No')
->readOnly(fn (callable $get) => (!$get('plant') || !$get('rework_type') || ($get('rework_type') == 'invoice' && !$get('invoice_number')) || ($get('rework_type') == 'invoice' && $get('scan_pallet_no')) || ($get('rework_type') == 'pallet' && !$get('scan_pallet_no'))))
->readOnly(fn (callable $get) => (! $get('plant') || ! $get('rework_type') || ($get('rework_type') == 'invoice' && ! $get('invoice_number')) || ($get('rework_type') == 'invoice' && $get('scan_pallet_no')) || ($get('rework_type') == 'pallet' && ! $get('scan_pallet_no'))))
->minLength(9)
->reactive()
->extraAttributes([
@@ -113,7 +109,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->reactive()
->required()
->disabled(fn (Get $get) => ($get('invoice_number') || $get('scan_pallet_no') || $get('scan_serial_no')))
->hidden(fn (callable $get) => !$get('plant'))
->hidden(fn (callable $get) => ! $get('plant'))
->inline()
->inlineLabel(false)
// ->default('invoice')
@@ -128,8 +124,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$set('invoice_number', null);
$set('scan_pallet_no', null);
$set('scan_serial_no', null);
}
else {
} else {
$set('reworkType', null);
$set('invoice_number', null);
$set('scan_pallet_no', null);
@@ -144,7 +139,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->boolean()
->grouped()
->reactive()
->hidden(fn (callable $get) => (!$get('plant') || $get('rework_type') != 'invoice' || !$get('invoice_number') || $get('update_invoice') == '0' || $get('scan_pallet_no') || $get('scan_serial_no')))
->hidden(fn (callable $get) => (! $get('plant') || $get('rework_type') != 'invoice' || ! $get('invoice_number') || $get('update_invoice') == '0' || $get('scan_pallet_no') || $get('scan_serial_no')))
->afterStateUpdated(function ($state, callable $set, callable $get, $livewire) {
$plantId = $get('plant');
@@ -156,23 +151,21 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$notCompletedCount = LocatorInvoiceValidation::where('invoice_number', $invoiceNumber)
->where('plant_id', $plantId)
->where(function($query) {
->where(function ($query) {
$query->whereNull('scanned_status')
->orWhere('scanned_status', '');
})
->count();
$isScanningComplete = true;
foreach ($rows as $row)
{
foreach ($rows as $row) {
if ($row->scanned_status != 'Scanned') {
$isScanningComplete = false;
break;
}
}
if (!$isScanningComplete)
{
if (! $isScanningComplete) {
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...")
->danger()
@@ -181,6 +174,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$set('invoice_number', null);
$set('update_invoice', null);
return;
}
}),
@@ -190,7 +184,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->boolean()
->grouped()
->reactive()
->hidden(fn (callable $get) => (!$get('plant') || $get('rework_type') != 'pallet' || $get('update_pallet') == '0' || !$get('scan_pallet_no') || $get('scan_serial_no')))
->hidden(fn (callable $get) => (! $get('plant') || $get('rework_type') != 'pallet' || $get('update_pallet') == '0' || ! $get('scan_pallet_no') || $get('scan_serial_no')))
->afterStateUpdated(function ($state, callable $set, callable $get, $livewire) {
$plantId = $get('plant');
@@ -198,15 +192,13 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$serialNo = trim($get('scan_serial_no'));
$updatePalletStatus = $get('update_pallet') ?? null;
if ($updatePalletStatus == 0)
{
if ($updatePalletStatus == 0) {
return;
}
if (strlen($palletNumber) < 10)
{
if (strlen($palletNumber) < 10) {
Notification::make()
->title("Invalid: Pallet Number")
->title('Invalid: Pallet Number')
->body("Pallet number '$palletNumber' must be at least 10 digits.")
->danger()
->duration(5000)
@@ -216,13 +208,13 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$set('scan_serial_no', null);
$set('scan_pallet_no', null);
$set('update_pallet', null);
return;
}
$PalletSerialNumbers = PalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNumber)->first();
if (!$PalletSerialNumbers)
{
if (! $PalletSerialNumbers) {
Notification::make()
->title('Pallet Not Found')
->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_pallet_no', null);
$set('update_pallet', null);
return;
}
@@ -242,20 +235,18 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->get();
$isScanningComplete = true;
foreach ($rows as $row)
{
foreach ($rows as $row) {
if ($row->pallet_status != 'Completed') {
$isScanningComplete = false;
break;
}
}
if(count($rows) <= 0) {
if (count($rows) <= 0) {
$isScanningComplete = false;
}
if (!$isScanningComplete)
{
if (! $isScanningComplete) {
Notification::make()
->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..!")
@@ -267,13 +258,11 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$set('scan_serial_no', null);
$set('scan_pallet_no', null);
$set('update_pallet', null);
return;
}
else
{
} else {
$locatExist = ($PalletSerialNumbers->locator_number != null && $PalletSerialNumbers->locator_number != '') ? $PalletSerialNumbers->locator_number : '';
if ($locatExist)
{
if ($locatExist) {
Notification::make()
->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..!")
@@ -285,14 +274,12 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$set('scan_serial_no', null);
$set('scan_pallet_no', null);
$set('update_pallet', null);
return;
}
else
{
if (strlen($serialNo) > 0 && (strlen($serialNo) < 9 || strlen($serialNo) > 20))
{
} else {
if (strlen($serialNo) > 0 && (strlen($serialNo) < 9 || strlen($serialNo) > 20)) {
Notification::make()
->title("Invalid: Serial Number")
->title('Invalid: Serial Number')
->body("Serial number '$serialNo' should contain minimum 9 digits and maximum 20 digits.")
->danger()
->duration(5000)
@@ -301,12 +288,11 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$livewire->dispatch('loadData', '', $palletNumber, $plantId, 'pallet');
$set('scan_serial_no', null);
$set('update_pallet', null);
return;
}
else if (strlen($serialNo) > 0 && !ctype_alnum($serialNo))
{
} elseif (strlen($serialNo) > 0 && ! ctype_alnum($serialNo)) {
Notification::make()
->title("Invalid: Serial Number")
->title('Invalid: Serial Number')
->body("Serial number '$serialNo' must contain alpha-numeric values only.")
->danger()
->duration(5000)
@@ -315,13 +301,12 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$livewire->dispatch('loadData', '', $palletNumber, $plantId, 'pallet');
$set('scan_serial_no', null);
$set('update_pallet', null);
return;
}
if ($updatePalletStatus == 1)
{
foreach ($rows as $row)
{
if ($updatePalletStatus == 1) {
foreach ($rows as $row) {
$row->forceDelete(); // Delete the row from the original table
}
@@ -336,6 +321,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
$set('scan_serial_no', null);
$set('scan_pallet_no', null);
$set('update_pallet', null);
return;
}
}
@@ -349,7 +335,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->hidden()
->readOnly(),
])
->columns(5)
->columns(5),
]);
}
@@ -364,6 +350,7 @@ class ReworkLocatorInvoiceValidationResource 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')
@@ -444,20 +431,17 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->importer(ReworkLocatorInvoiceValidationImporter::class)
->label('Import Rework Invoice')
->color('warning')
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import rework invoice validation');
}),
ExportAction::make()
->exporter(ReworkLocatorInvoiceValidationExporter::class)
->label('Export Rework Invoice')
->color('warning')
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export rework invoice validation');
}),
])
// ->filters([
// Tables\Filters\TrashedFilter::make(),
// ])
->filters([
Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters')
@@ -471,6 +455,7 @@ class ReworkLocatorInvoiceValidationResource 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()
@@ -491,12 +476,13 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->label('Invoice Number')
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId) {
if (! $plantId) {
return [];
}
return ReworkLocatorInvoiceValidation::where('plant_id', $plantId)
->whereNotNull('invoice_number')
->where('invoice_number','!=', '')
->where('invoice_number', '!=', '')
->orderBy('invoice_number', 'asc')
->get()
->unique('invoice_number')
@@ -512,12 +498,13 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->label('Pallet Number')
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId) {
if (! $plantId) {
return [];
}
return ReworkLocatorInvoiceValidation::where('plant_id', $plantId)
->whereNotNull('pallet_number')
->where('pallet_number','!=', '')
->where('pallet_number', '!=', '')
->orderBy('pallet_number', 'asc')
->get()
->unique('pallet_number')
@@ -530,12 +517,13 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->label('Locator Number')
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId) {
if (! $plantId) {
return [];
}
return ReworkLocatorInvoiceValidation::where('plant_id', $plantId)
->whereNotNull('locator_number')
->where('locator_number','!=', '')
->where('locator_number', '!=', '')
->orderBy('locator_number', 'asc')
->get()
->unique('locator_number')
@@ -569,38 +557,44 @@ class ReworkLocatorInvoiceValidationResource extends Resource
return $query->whereRaw('1 = 0');
}
if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null
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['invoice_number'])) {
if (! empty($data['invoice_number'])) {
$query->where('invoice_number', $data['invoice_number']);
}
if (!empty($data['serial_number'])) {
if (! empty($data['serial_number'])) {
$query->where('serial_number', $data['serial_number']);
}
if (!empty($data['pallet_number'])) {
if (! empty($data['pallet_number'])) {
$query->where('pallet_number', $data['pallet_number']);
}
if (!empty($data['locator_number'])) {
if (! empty($data['locator_number'])) {
$query->where('locator_number', $data['locator_number']);
}
if (!empty($data['scanned_status'])) {
if (! empty($data['scanned_status'])) {
$query->where('scanned_status', $data['scanned_status']);
}
if (!empty($data['rework_from'])) {
if (! empty($data['rework_from'])) {
$query->where('reworked_at', '>=', $data['rework_from']);
}
if (!empty($data['rework_to'])) {
if (! empty($data['rework_to'])) {
$query->where('reworked_at', '<=', $data['rework_to']);
}
if (!empty($data['rework_by'])) {
if (! empty($data['rework_by'])) {
$query->where('reworked_by', $data['rework_by']);
}
@@ -608,43 +602,50 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->indicateUsing(function (array $data) {
$indicators = [];
if (!empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
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['invoice_number'])) {
$indicators[] = 'Invoice Number: ' . $data['invoice_number'];
if (! empty($data['invoice_number'])) {
$indicators[] = 'Invoice Number: '.$data['invoice_number'];
}
if (!empty($data['serial_number'])) {
$indicators[] = 'Serial Number: ' . $data['serial_number'];
if (! empty($data['serial_number'])) {
$indicators[] = 'Serial Number: '.$data['serial_number'];
}
if (!empty($data['pallet_number'])) {
$indicators[] = 'Pallet Number: ' . $data['pallet_number'];
if (! empty($data['pallet_number'])) {
$indicators[] = 'Pallet Number: '.$data['pallet_number'];
}
if (!empty($data['locator_number'])) {
$indicators[] = 'Locator Number: ' . $data['locator_number'];
if (! empty($data['locator_number'])) {
$indicators[] = 'Locator Number: '.$data['locator_number'];
}
if (!empty($data['scanned_status'])) {
$indicators[] = 'Scanned Status: ' . $data['scanned_status'];
if (! empty($data['scanned_status'])) {
$indicators[] = 'Scanned Status: '.$data['scanned_status'];
}
if (!empty($data['rework_from'])) {
$indicators[] = 'From: ' . $data['rework_from'];
if (! empty($data['rework_from'])) {
$indicators[] = 'From: '.$data['rework_from'];
}
if (!empty($data['rework_to'])) {
$indicators[] = 'To: ' . $data['rework_to'];
if (! empty($data['rework_to'])) {
$indicators[] = 'To: '.$data['rework_to'];
}
if (!empty($data['rework_by'])) {
$indicators[] = 'Reworked By: ' . $data['rework_by'];
if (! empty($data['rework_by'])) {
$indicators[] = 'Reworked By: '.$data['rework_by'];
}
return $indicators;
})
}),
])
->filtersFormMaxHeight('280px')
->actions([