571 lines
26 KiB
PHP
571 lines
26 KiB
PHP
<?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\Plant;
|
|
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;
|
|
use Filament\Forms\Components\DateTimePicker;
|
|
use Filament\Tables\Filters\Filter;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Select;
|
|
|
|
class ReworkLocatorInvoiceValidationResource extends Resource
|
|
{
|
|
protected static ?string $model = ReworkLocatorInvoiceValidation::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
|
|
|
protected static ?string $navigationGroup = 'Export Dispatch';
|
|
|
|
protected static ?int $navigationSort = 7;
|
|
|
|
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()
|
|
->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)
|
|
{
|
|
$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')
|
|
->minLength(10)
|
|
->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)',
|
|
'enterkeyhint' => 'done',
|
|
]),
|
|
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'))))
|
|
->minLength(9)
|
|
->reactive()
|
|
->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()
|
|
->duration(5000)
|
|
->send();
|
|
|
|
$set('invoice_number', null);
|
|
$set('update_invoice', null);
|
|
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');
|
|
|
|
$palletNumber = $get('scan_pallet_no');
|
|
|
|
$rows = PalletValidation::where('pallet_number', $palletNumber)
|
|
->where('plant_id', $plantId)
|
|
->get();
|
|
|
|
$isScanningComplete = true;
|
|
foreach ($rows as $row)
|
|
{
|
|
if ($row->pallet_status != 'Completed') {
|
|
$isScanningComplete = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!$isScanningComplete)
|
|
{
|
|
Notification::make()
|
|
->title("Scanned pallet number '$palletNumber' does not completed the master packing!<br>Please, scan the valid completed pallet number to proceed...")
|
|
->danger()
|
|
->duration(5000)
|
|
->send();
|
|
|
|
$set('scan_pallet_no', null);
|
|
$set('update_pallet', null);
|
|
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')
|
|
->alignCenter()
|
|
->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)
|
|
->label('Import Rework Invoice')
|
|
->color('warning')
|
|
->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() {
|
|
return Filament::auth()->user()->can('view export rework invoice validation');
|
|
}),
|
|
])
|
|
// ->filters([
|
|
// Tables\Filters\TrashedFilter::make(),
|
|
// ])
|
|
->filters([
|
|
Tables\Filters\TrashedFilter::make(),
|
|
Filter::make('advanced_filters')
|
|
->label('Advanced Filters')
|
|
->form([
|
|
Select::make('Plant')
|
|
->label('Select Plant')
|
|
->nullable()
|
|
->options(function () {
|
|
return Plant::pluck('name', 'id');
|
|
})
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
|
$set('pallet_number', null);
|
|
$set('invoice_number', null);
|
|
$set('serial_number', null);
|
|
$set('scanned_status', null);
|
|
$set('locator_number', null);
|
|
$set('created_from', null);
|
|
$set('created_to', null);
|
|
$set('created_by', null);
|
|
$set('scanned_from', null);
|
|
$set('scanned_to', null);
|
|
$set('scanned_by', null);
|
|
}),
|
|
Select::make('invoice_number')
|
|
->label('Invoice Number')
|
|
->options(function (callable $get) {
|
|
$plantId = $get('Plant');
|
|
if (!$plantId) {
|
|
return [];
|
|
}
|
|
return ReworkLocatorInvoiceValidation::where('plant_id', $plantId)
|
|
->whereNotNull('invoice_number')
|
|
->where('invoice_number','!=', '')
|
|
->orderBy('invoice_number', 'asc')
|
|
->get()
|
|
->unique('invoice_number')
|
|
->pluck('invoice_number', 'invoice_number')
|
|
->toArray();
|
|
})
|
|
->searchable()
|
|
->reactive(),
|
|
TextInput::make('serial_number')
|
|
->label('Serial Number')
|
|
->placeholder(placeholder: 'Enter Serial Number'),
|
|
Select::make('pallet_number')
|
|
->label('Pallet Number')
|
|
->options(function (callable $get) {
|
|
$plantId = $get('Plant');
|
|
if (!$plantId) {
|
|
return [];
|
|
}
|
|
return ReworkLocatorInvoiceValidation::where('plant_id', $plantId)
|
|
->whereNotNull('pallet_number')
|
|
->where('pallet_number','!=', '')
|
|
->orderBy('pallet_number', 'asc')
|
|
->get()
|
|
->unique('pallet_number')
|
|
->pluck('pallet_number', 'pallet_number')
|
|
->toArray();
|
|
})
|
|
->searchable()
|
|
->reactive(),
|
|
Select::make('locator_number')
|
|
->label('Locator Number')
|
|
->options(function (callable $get) {
|
|
$plantId = $get('Plant');
|
|
if (!$plantId) {
|
|
return [];
|
|
}
|
|
return ReworkLocatorInvoiceValidation::where('plant_id', $plantId)
|
|
->whereNotNull('locator_number')
|
|
->where('locator_number','!=', '')
|
|
->orderBy('locator_number', 'asc')
|
|
->get()
|
|
->unique('locator_number')
|
|
->pluck('locator_number', 'locator_number')
|
|
->toArray();
|
|
})
|
|
->searchable()
|
|
->reactive(),
|
|
Select::make('scanned_status')
|
|
->label('Scanned Status')
|
|
->options([
|
|
'Scanned' => 'Scanned',
|
|
]),
|
|
DateTimePicker::make(name: 'rework_from')
|
|
->label('Rework From')
|
|
->placeholder(placeholder: 'Select From DateTime')
|
|
->reactive()
|
|
->native(false),
|
|
DateTimePicker::make('rework_to')
|
|
->label('Rework To')
|
|
->placeholder(placeholder: 'Select To DateTime')
|
|
->reactive()
|
|
->native(false),
|
|
TextInput::make('rework_by')
|
|
->label('Rework By')
|
|
->placeholder(placeholder: 'Enter Rework By'),
|
|
])
|
|
->query(function ($query, array $data) {
|
|
// Hide all records initially if no filters are applied
|
|
if (empty($data['Plant']) && empty($data['invoice_number']) && empty($data['serial_number']) && empty($data['pallet_number']) && empty($data['locator_number']) && empty($data['scanned_status']) && empty($data['rework_from']) && empty($data['rework_to']) && empty($data['rework_by'])) {
|
|
return $query->whereRaw('1 = 0');
|
|
}
|
|
|
|
if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null
|
|
$query->where('plant_id', $data['Plant']);
|
|
}
|
|
|
|
if (!empty($data['invoice_number'])) {
|
|
$query->where('invoice_number', $data['invoice_number']);
|
|
}
|
|
|
|
if (!empty($data['serial_number'])) {
|
|
$query->where('serial_number', $data['serial_number']);
|
|
}
|
|
|
|
if (!empty($data['pallet_number'])) {
|
|
$query->where('pallet_number', $data['pallet_number']);
|
|
}
|
|
|
|
if (!empty($data['locator_number'])) {
|
|
$query->where('locator_number', $data['locator_number']);
|
|
}
|
|
if (!empty($data['scanned_status'])) {
|
|
$query->where('scanned_status', $data['scanned_status']);
|
|
}
|
|
|
|
if (!empty($data['rework_from'])) {
|
|
$query->where('reworked_at', '>=', $data['rework_from']);
|
|
}
|
|
|
|
if (!empty($data['rework_to'])) {
|
|
$query->where('reworked_at', '<=', $data['rework_to']);
|
|
}
|
|
|
|
if (!empty($data['rework_by'])) {
|
|
$query->where('reworked_by', $data['rework_by']);
|
|
}
|
|
|
|
})
|
|
->indicateUsing(function (array $data) {
|
|
$indicators = [];
|
|
|
|
if (!empty($data['Plant'])) {
|
|
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
|
}
|
|
|
|
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['pallet_number'])) {
|
|
$indicators[] = 'Pallet Number: ' . $data['pallet_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['rework_from'])) {
|
|
$indicators[] = 'From: ' . $data['rework_from'];
|
|
}
|
|
|
|
if (!empty($data['rework_to'])) {
|
|
$indicators[] = 'To: ' . $data['rework_to'];
|
|
}
|
|
|
|
if (!empty($data['rework_by'])) {
|
|
$indicators[] = 'Reworked By: ' . $data['rework_by'];
|
|
}
|
|
return $indicators;
|
|
})
|
|
])
|
|
->filtersFormMaxHeight('280px')
|
|
->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 getNavigationLabel(): string
|
|
{
|
|
return 'Scan Rework';
|
|
}
|
|
|
|
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 getEloquentQuery(): Builder
|
|
{
|
|
return parent::getEloquentQuery()
|
|
->withoutGlobalScopes([
|
|
SoftDeletingScope::class,
|
|
]);
|
|
}
|
|
}
|