schema([ DateTimePicker::make('fecha_recepcion') ->label('Fecha de Recepción') ->required() ->default(now()), TextInput::make('cantidad') ->label('Cantidad Recibida') ->numeric() ->required() ->minValue(1) ->maxValue(fn () => $this->getOwnerRecord()?->faltantes ?? 0) ->helperText(fn () => 'Disponible para recibir: ' . ($this->getOwnerRecord()?->faltantes ?? 0)), TextInput::make('prendas_defectuosas') ->label('Prendas Defectuosas') ->numeric() ->default(0) ->minValue(0) ->helperText('Si hay prendas defectuosas, regístralas aquí. Estas no pasarán al inventario.'), Textarea::make('notas') ->label('Notas / Observaciones') ->rows(3) ->maxLength(65535), ]); } public function table(Tables\Table $table): Tables\Table { return $table ->columns([ TextColumn::make('id') ->label('#') ->sortable(), TextColumn::make('fecha_recepcion') ->label('Fecha Recepción') ->dateTime('d/m/Y H:i') ->sortable(), TextColumn::make('cantidad') ->label('Cantidad') ->sortable(), TextColumn::make('prendas_defectuosas') ->label('Defectuosas') ->default(0) ->badge() ->color(fn ($state) => $state > 0 ? 'danger' : 'gray'), TextColumn::make('cantidad_efectiva') ->label('Cantidad Efectiva') ->getStateUsing(fn ($record) => $record->cantidad - ($record->prendas_defectuosas ?? 0)) ->badge() ->color('success'), TextColumn::make('usuario.name') ->label('Usuario') ->searchable(), TextColumn::make('notas') ->label('Notas') ->limit(50) ->wrap() ->toggleable(), TextColumn::make('created_at') ->label('Creado') ->dateTime('d/m/Y H:i') ->sortable() ->toggleable(isToggledHiddenByDefault: true), ]) ->defaultSort('fecha_recepcion', 'desc') ->headerActions([ CreateAction::make() ->label('Nueva Recepción') ->icon('heroicon-o-plus-circle') ->disabled(fn () => ($this->getOwnerRecord()?->faltantes ?? 0) <= 0) ->mutateFormDataUsing(function (array $data): array { // Asignar usuario actual $data['user_id'] = Auth::id(); return $data; }), ]) ->actions([ EditAction::make(), DeleteAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]) ->emptyStateHeading('Sin recepciones registradas') ->emptyStateDescription('Las recepciones quedarán disponibles automáticamente para el inventario de prendas.') ->emptyStateIcon('heroicon-o-inbox-arrow-down'); } }