306 lines
12 KiB
PHP
306 lines
12 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Exports\PalletValidationExporter;
|
|
use App\Filament\Imports\PalletValidationImporter;
|
|
use App\Filament\Resources\PalletValidationResource\Pages;
|
|
use App\Filament\Resources\PalletValidationResource\RelationManagers;
|
|
use App\Models\PalletValidation;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Components\Section;
|
|
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\Actions;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Tables\Actions\ExportAction;
|
|
use Filament\Tables\Actions\ImportAction;
|
|
use Log;
|
|
use Filament\Tables\Actions\Action;
|
|
|
|
|
|
class PalletValidationResource extends Resource
|
|
{
|
|
protected static ?string $model = PalletValidation::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')
|
|
->relationship('plant', 'name')
|
|
->required()
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('pallet_number', null);
|
|
$set('serial_number', null);
|
|
$set('removeSno_number', null);
|
|
$set('Sno_quantity', 0);
|
|
$set('pending_pallet_list', null);
|
|
}),
|
|
Forms\Components\TextInput::make('pallet_number')
|
|
->label('Scan Pallet No')
|
|
->reactive()
|
|
->required()
|
|
->readonly() //fn ($get) => (bool)$get('pallet_number_locked') || $get('serial_number') || $get('removeSno_number')
|
|
->extraAttributes([
|
|
'x-data' => '{ value: "" }',
|
|
'x-model' => 'value',
|
|
'x-on:keydown.enter.prevent' => '$wire.processPalletNo()',
|
|
])
|
|
->suffixAction(fn ($get,$set) =>
|
|
Forms\Components\Actions\Action::make('addPallet')
|
|
->label('')
|
|
->button()
|
|
->icon('heroicon-o-plus')
|
|
->color('primary')
|
|
->extraAttributes([
|
|
'class' => 'p-1 w-7 h-7',
|
|
])
|
|
->action(function ($get, $set, $livewire) {
|
|
$plantId = $get('plant_id');
|
|
|
|
$user = Filament::auth()->user();
|
|
|
|
$operatorName = $user->name;
|
|
|
|
$clickedTime = now();
|
|
|
|
$created = $operatorName;
|
|
|
|
session(['pallet_clicked_time' => $clickedTime->toDateTimeString()]);
|
|
|
|
session(['pallet_created_by' => $created]);
|
|
|
|
$year = now()->format('y');
|
|
$month = now()->format('m');
|
|
$prefix = "EP-{$year}{$month}";
|
|
$lastPallet = PalletValidation::where('pallet_number', 'like', "{$prefix}%")
|
|
->where('plant_id', $plantId)
|
|
->orderByDesc('pallet_number')
|
|
->first();
|
|
$newNumber = $lastPallet
|
|
? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT)
|
|
: '001';
|
|
$newPalletNumber = "{$prefix}{$newNumber}";
|
|
|
|
$set('pallet_number', $newPalletNumber);
|
|
$set('pallet_number_locked', true);
|
|
$set('plant_id', $plantId);
|
|
|
|
$livewire->redirectToQrPdf($newPalletNumber);
|
|
})
|
|
),
|
|
|
|
Forms\Components\TextInput::make('serial_number')
|
|
->label('Scan Serial No')
|
|
->reactive()
|
|
->readOnly(fn (callable $get) => !$get('pallet_number') || $get('removeSno_number'))
|
|
->extraAttributes([
|
|
'x-on:keydown.enter.prevent' => '$wire.processPalletSNo()',
|
|
]),
|
|
Forms\Components\TextInput::make('removeSno_number')
|
|
->label('Remove Serial No')
|
|
->reactive()
|
|
->readOnly(fn (callable $get) => !$get('pallet_number') || $get('serial_number'))
|
|
->extraAttributes([
|
|
'x-data' => '{ value: "" }',
|
|
'x-model' => 'value',
|
|
'x-on:keydown.enter.prevent' => '$wire.processRemoveSNo()',
|
|
]),
|
|
|
|
Forms\Components\TextInput::make('Sno_quantity')
|
|
->label('SNo. Quantity')
|
|
->readOnly()
|
|
->default('0'),
|
|
Forms\Components\Hidden::make('created_by')
|
|
->default(Filament::auth()->user()?->name),
|
|
Forms\Components\Hidden::make('scanned_by')
|
|
->default(Filament::auth()->user()?->name),
|
|
Forms\Components\Hidden::make('pallet_number_locked')
|
|
->default(false),
|
|
Forms\Components\Select::make('pending_pallet_list')
|
|
->label('Pending Pallet List')
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
$set('pallet_number', $state);
|
|
$set('pallet_number_locked', false);
|
|
})
|
|
->options(function ($get) {
|
|
|
|
$plantId = $get('plant_id');
|
|
|
|
if (!$plantId) {
|
|
return [];
|
|
}
|
|
return PalletValidation::query()
|
|
->where('plant_id', $plantId)
|
|
->where(function($query) {
|
|
$query->whereNull('pallet_status')
|
|
->orWhere('pallet_status', '');
|
|
})
|
|
->whereNotNull('pallet_number')
|
|
->orderBy('pallet_number', 'asc')
|
|
->pluck('pallet_number')
|
|
->unique()
|
|
->mapWithKeys(fn($number) => [$number => $number])
|
|
->toArray();
|
|
}),
|
|
|
|
Forms\Components\View::make('forms.components.save-pallet-button')
|
|
])
|
|
->columns(5),
|
|
Forms\Components\TextInput::make('id')
|
|
->hidden()
|
|
->readOnly(),
|
|
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
|
|
->columns([
|
|
// Tables\Columns\TextColumn::make('id')
|
|
// ->label('ID')
|
|
// ->numeric()
|
|
// ->sortable(),
|
|
|
|
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')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('pallet_number')
|
|
->label('Pallet Number')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('serial_number')
|
|
->label('Serial Number')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('pallet_status')
|
|
->label('Pallet Status')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('locator_number')
|
|
->label('Locator Number')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('locator_quantity')
|
|
->label('Locator Quantity')
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('created_by')
|
|
->label('Created By')
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('scanned_by')
|
|
->label('Scanned By')
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('updated_by')
|
|
->label('Updated By')
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->dateTime()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('updated_at')
|
|
->dateTime()
|
|
->alignCenter()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
Tables\Columns\TextColumn::make('scanned_at')
|
|
->dateTime()
|
|
->alignCenter()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
Tables\Columns\TextColumn::make('deleted_at')
|
|
->dateTime()
|
|
->alignCenter()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->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(),
|
|
]),
|
|
])
|
|
->headerActions([
|
|
ImportAction::make()
|
|
->importer(PalletValidationImporter::class)
|
|
->visible(function() {
|
|
return Filament::auth()->user()->can('view import pallet validation');
|
|
}),
|
|
ExportAction::make()
|
|
->exporter(PalletValidationExporter::class)
|
|
->visible(function() {
|
|
return Filament::auth()->user()->can('view export pallet validation');
|
|
}),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListPalletValidations::route('/'),
|
|
'create' => Pages\CreatePalletValidation::route('/create'),
|
|
'view' => Pages\ViewPalletValidation::route('/{record}'),
|
|
'edit' => Pages\EditPalletValidation::route('/{record}/edit'),
|
|
];
|
|
}
|
|
|
|
public static function getEloquentQuery(): Builder
|
|
{
|
|
return parent::getEloquentQuery()
|
|
->withoutGlobalScopes([
|
|
SoftDeletingScope::class,
|
|
]);
|
|
}
|
|
}
|