1
0
forked from poc/pds

Added rework locator invoice validation resource pages

This commit is contained in:
dhanabalan
2025-07-01 15:10:35 +05:30
parent fcf1fed70d
commit b13b5dbb05
5 changed files with 1873 additions and 0 deletions

View File

@@ -0,0 +1,365 @@
<?php
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\ReworkLocatorInvoiceValidation;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
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;
class ReworkLocatorInvoiceValidationResource extends Resource
{
protected static ?string $model = ReworkLocatorInvoiceValidation::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Export Dispatch';
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('')
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->reactive()
->relationship('plant', 'name')
->disabled(fn (Get $get) => $get('rework_type'))
->required()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
if ($plantId)
{
$set('plant', $plantId);
$set('invoice_number', null);
$set('scan_pallet_no', null);
$set('scan_serial_no', null);
$set('rework_type', null);
}
else
{
$set('plant', null);
$set('invoice_number', null);
$set('scan_pallet_no', null);
$set('scan_serial_no', null);
$set('rework_type', null);
}
}),
Forms\Components\Hidden::make('plant')
->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')))
// ->readOnly(fn ($get) => $get('rework_type') == 'pallet')
->reactive()
->extraAttributes([
'wire:keydown.enter' => 'processInvoiceRework($event.target.value)',
]),
Forms\Components\TextInput::make('scan_pallet_no')
->label('Scan Pallet No')
->required( fn ($get) => $get('rework_type') == 'pallet')
->readOnly(fn ($get) => $get('rework_type') == 'invoice')
->reactive()
->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')
->reactive()
->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'))))
->extraAttributes([
'wire:keydown.enter' => 'processSno($event.target.value)',
]),
Forms\Components\Radio::make('rework_type')
->label('Rework Type')
->options([
'invoice' => 'Invoice',
'pallet' => 'Pallet',
])
->reactive()
->required()
->disabled(fn (Get $get) => ($get('invoice_number') || $get('scan_pallet_no') || $get('scan_serial_no')))
->hidden(fn (callable $get) => !$get('plant'))
->inline()
->inlineLabel(false)
// ->default('invoice')
->afterStateUpdated(function ($state, callable $set) {
if ($state == 'pallet') {
$set('reworkType', $state);
$set('invoice_number', null);
$set('scan_pallet_no', null);
$set('scan_serial_no', null);
} elseif ($state == 'invoice') {
$set('reworkType', $state);
$set('invoice_number', null);
$set('scan_pallet_no', null);
$set('scan_serial_no', null);
}
else {
$set('reworkType', null);
$set('invoice_number', null);
$set('scan_pallet_no', null);
$set('scan_serial_no', null);
}
}),
Forms\Components\Hidden::make('reworkType')
->reactive(),
ToggleButtons::make('update_invoice')
->label('Rework entire invoice?')
->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')))
->afterStateUpdated(function ($state, callable $set, callable $get, $livewire) {
$plantId = $get('plant');
$invoiceNumber = $get('invoice_number');
$rows = LocatorInvoiceValidation::where('invoice_number', $invoiceNumber)
->where('plant_id', $plantId)
->get();
$notCompletedCount = LocatorInvoiceValidation::where('invoice_number', $invoiceNumber)
->where('plant_id', $plantId)
->where(function($query) {
$query->whereNull('scanned_status')
->orWhere('scanned_status', '');
})
->count();
$isScanningComplete = true;
foreach ($rows as $row)
{
if ($row->scanned_status !== 'Scanned') {
$isScanningComplete = false;
break;
}
}
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()
->send();
return;
}
}),
ToggleButtons::make('update_pallet')
->label('Rework entire pallet?')
->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')))
->afterStateUpdated(function ($state, callable $set, callable $get, $livewire) {
$plantId = $get('plant');
$invoiceNumber = $get('invoice_number');
$rows = LocatorInvoiceValidation::where('invoice_number', $invoiceNumber)
->where('plant_id', $plantId)
->get();
$notCompletedCount = LocatorInvoiceValidation::where('invoice_number', $invoiceNumber)
->where('plant_id', $plantId)
->where(function($query) {
$query->whereNull('scanned_status')
->orWhere('scanned_status', '');
})
->count();
$isScanningComplete = true;
foreach ($rows as $row)
{
if ($row->scanned_status !== 'Scanned') {
$isScanningComplete = false;
break;
}
}
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()
->send();
return;
}
}),
Forms\Components\Hidden::make('created_by')
->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('scanned_by')
->default(Filament::auth()->user()?->name),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(5)
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('No.')
->label('No.')
->alignCenter()
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
$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')
->label('Plant')
->sortable(),
Tables\Columns\TextColumn::make('invoice_number')
->label('Invoice Number')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('serial_number')
->label('Serial Number')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('pallet_number')
->label('Pallet Number')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('locator_number')
->label('Locator Number')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('scanned_status')
->label('Scanned Status')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('upload_status')
->label('Upload Status')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('created_by')
->label('Created By')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->alignCenter()
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('updated_by')
->label('Updated By')
->alignCenter()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->label('Updated At')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('scanned_by')
->label('Scanned By')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('scanned_at')
->label('Scanned At')
->alignCenter()
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('reworked_by')
->label('Reworked By')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('reworked_at')
->label('Reworked At')
->alignCenter()
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('deleted_at')
->label('Deleted At')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->headerActions([
ImportAction::make()
->importer(ReworkLocatorInvoiceValidationImporter::class)
->visible(function() {
return Filament::auth()->user()->can('view import rework invoice validation');
}),
ExportAction::make()
->exporter(ReworkLocatorInvoiceValidationExporter::class)
->visible(function() {
return Filament::auth()->user()->can('view export rework invoice validation');
}),
])
->filters([
Tables\Filters\TrashedFilter::make(),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListReworkLocatorInvoiceValidations::route('/'),
'create' => Pages\CreateReworkLocatorInvoiceValidation::route('/create'),
'view' => Pages\ViewReworkLocatorInvoiceValidation::route('/{record}'),
'edit' => Pages\EditReworkLocatorInvoiceValidation::route('/{record}/edit'),
];
}
public static function getNavigationLabel(): string
{
return 'Rework Invoice / Pallet';
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Filament\Resources\ReworkLocatorInvoiceValidationResource\Pages;
use App\Filament\Resources\ReworkLocatorInvoiceValidationResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditReworkLocatorInvoiceValidation extends EditRecord
{
protected static string $resource = ReworkLocatorInvoiceValidationResource::class;
protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\ReworkLocatorInvoiceValidationResource\Pages;
use App\Filament\Resources\ReworkLocatorInvoiceValidationResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListReworkLocatorInvoiceValidations extends ListRecords
{
protected static string $resource = ReworkLocatorInvoiceValidationResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\ReworkLocatorInvoiceValidationResource\Pages;
use App\Filament\Resources\ReworkLocatorInvoiceValidationResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;
class ViewReworkLocatorInvoiceValidation extends ViewRecord
{
protected static string $resource = ReworkLocatorInvoiceValidationResource::class;
protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
];
}
}