3 Commits

Author SHA1 Message Date
dhanabalan
a0db69a4c8 Added rework locator invoice validation livewire page and table 2025-07-01 15:12:12 +05:30
dhanabalan
b13b5dbb05 Added rework locator invoice validation resource pages 2025-07-01 15:10:35 +05:30
dhanabalan
fcf1fed70d Added rework locator invoice validation model file 2025-07-01 15:08:58 +05:30
9 changed files with 2105 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(),
];
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace App\Livewire;
use App\Models\LocatorInvoiceValidation;
use App\Models\PalletValidation;
use Livewire\Component;
class InvoiceReworkDataTable extends Component
{
public $plantId;
public $invoiceNumber;
public $palletNumber;
public $reworkTyp;
public bool $isOpen = false;
public $records = [];
public $showConfirmationModal = false;
public $invoiceNo;
protected $listeners =
[
'loadData' => 'loadlocatorInvoiceData',
];
public function loadlocatorInvoiceData($invoiceNumber, $palletNumber, $plantId, $reworkType)
{
$this->invoiceNumber = $invoiceNumber;
$this->palletNumber = $palletNumber;
$this->plantId = $plantId;
$this->reworkTyp = $reworkType;
if ($reworkType == 'invoice')
{
$this->records = LocatorInvoiceValidation::query()->where('plant_id', $plantId)->where('invoice_number', $invoiceNumber)->orderBy('created_at', 'asc')->get()// ->orderByDesc('created_at')
->map(function ($record) {
return [
'created_at' => $record->created_at ?? '',
'created_by' => $record->created_by ?? '',
'serial_number' => $record->serial_number ?? '',
'pallet_number' => $record->pallet_number ?? '',
'locator_number' => $record->locator_number ?? '',
'scanned_status' => $record->scanned_status ?? '',
'scanned_at' => $record->scanned_at ?? '',
'scanned_by' => $record->scanned_by ?? '',
];
})
->toArray();
}
else if ($reworkType == 'pallet')
{
$this->records = PalletValidation::query()->where('plant_id', $plantId)->where('pallet_number', $palletNumber)->orderBy('scanned_at', 'asc')->get()
->map(function ($record) {
return [
'created_at' => $record->created_at ?? '',
'created_by' => $record->created_by ?? '',
'serial_number' => $record->serial_number ?? '',
// 'pallet_number' => $record->pallet_number,
// 'locator_number' => $record->locator_number,
// 'scanned_status' => $record->scanned_status,
'scanned_at' => $record->scanned_at ?? '',
'scanned_by' => $record->scanned_by ?? '',
];
})
->toArray();
}
else
{
$this->records = [];
}
}
public function render()
{
return view('livewire.invoice-rework-data-table');
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class ReworkLocatorInvoiceValidation extends Model
{
use SoftDeletes;
protected $fillable = [
'plant_id',
'invoice_number',
'serial_number',
'pallet_number',
'locator_number',
'scanned_status',
'upload_status',
'created_by',
'scanned_by',
'updated_by',
'reworked_by',
'created_at',
'updated_at',
'scanned_at',
'reworked_at',
];
public function plant(): BelongsTo
{
return $this->belongsTo(Plant::class);
}
}

View File

@@ -0,0 +1,28 @@
<x-filament::page>
<form wire:submit.prevent="create" class="space-y-6">
{{-- Form Section --}}
<div class="filament-form space-y-6">
{{ $this->form }}
</div>
{{-- Livewire Component (Invoice Table) --}}
<div class="bg-white shadow rounded-xl p-4">
<livewire:invoice-rework-data-table />
</div>
{{-- Heading after Livewire component (optional) --}}
{{-- <h2>hello</h2> --}}
{{-- Actions --}}
<div class="filament-actions mt-6">
<x-filament::actions>
@foreach ($this->getFormActions() as $action)
{{ $action }}
@endforeach
</x-filament::actions>
</div>
</form>
</x-filament::page>

View File

@@ -0,0 +1,86 @@
<div class="p-4">
@if ($reworkTyp == null || $reworkTyp == '')
<h2 class="text-lg text-center font-bold mb-4 uppercase tracking-wider" style="padding-top: 10px">
Choose 'Plant and Rework Type' then scan valid 'Invoice or Pallet' number to proceed..!
</h2>
@elseif ($reworkTyp == 'invoice')
{{-- No data available for the selected plant and production order! --}}
<h2 class="text-lg font-bold mb-4 text-gray-700 uppercase tracking-wider">
REWORK INVOICE DATA TABLE :
</h2>
<div class="overflow-x-auto rounded-lg shadow">
<table class="w-full divide-y divide-gray-200 text-sm text-center">
<thead class="bg-gray-100 text-s font-semibold uppercase text-gray-700">
<tr>
<th class="border px-4 py-2">No</th>
<th class="border px-4 py-2">Created Datetime</th>
<th class="border px-4 py-2">Created By</th>
<th class="border px-4 py-2">Serial Number</th>
<th class="border px-4 py-2">Pallet Number</th>
<th class="border px-4 py-2">Locator Number</th>
<th class="border px-4 py-2">Scanned Status</th>
<th class="border px-4 py-2">Scanned Datetime</th>
<th class="border px-4 py-2">Scanned By</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
@forelse ($records as $index => $record)
<tr class="hover:bg-gray-50">
<td class="border px-4 py-2">{{ $index + 1 }}</td>
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['created_at'] ?? '' }}</td>
<td class="border px-4 py-2">{{ $record['created_by'] ?? '' }}</td>
<td class="border px-4 py-2">{{ $record['serial_number'] ?? '' }}</td>
<td class="border px-4 py-2">{{ $record['pallet_number'] ?? '' }}</td>
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['locator_number'] ?? '' }}</td>
<td class="border px-4 py-2">{{ $record['scanned_status'] ?? '' }}</td>
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['scanned_at'] ?? '' }}</td>
<td class="border px-4 py-2">{{ $record['scanned_by'] ?? '' }}</td>
</tr>
@empty
<tr>
<td colspan="9" class="px-4 py-4 text-center text-gray-500">
No records found.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
@elseif ($reworkTyp == 'pallet')
<h2 class="text-lg font-bold mb-4 text-gray-700 uppercase tracking-wider">
REWORK PALLET DATA TABLE :
</h2>
<div class="overflow-x-auto rounded-lg shadow">
<table class="w-full divide-y divide-gray-200 text-sm text-center">
<thead class="bg-gray-100 text-s font-semibold uppercase text-gray-700">
<tr>
<th class="border px-4 py-2">No</th>
<th class="border px-4 py-2">Created Datetime</th>
<th class="border px-4 py-2">Created By</th>
<th class="border px-4 py-2">Serial Number</th>
<th class="border px-4 py-2">Scanned Datetime</th>
<th class="border px-4 py-2">Scanned By</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
@forelse ($records as $index => $record)
<tr class="hover:bg-gray-50">
<td class="border px-4 py-2">{{ $index + 1 }}</td>
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['created_at'] ?? '' }}</td>
<td class="border px-4 py-2">{{ $record['created_by'] ?? '' }}</td>
<td class="border px-4 py-2">{{ $record['serial_number'] ?? '' }}</td>
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['scanned_at'] ?? '' }}</td>
<td class="border px-4 py-2">{{ $record['scanned_by'] ?? '' }}</td>
</tr>
@empty
<tr>
<td colspan="9" class="px-4 py-4 text-center text-gray-500">
No records found.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
@endif
</div>