From 1eb41c57257a99a2493fb3659a2eebfe72b4f74e Mon Sep 17 00:00:00 2001 From: lizandrogd <77708265+lizandrogd@users.noreply.github.com> Date: Mon, 19 Jan 2026 19:59:24 -0500 Subject: [PATCH] up --- .../Pages/EditConfeccion.php | 47 ++++++++++++++----- .../RecepcionesRelationManager.php | 7 ++- .../RecepcionesRelationManager.php | 7 ++- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/app/Filament/Resources/ConfeccionResource/Pages/EditConfeccion.php b/app/Filament/Resources/ConfeccionResource/Pages/EditConfeccion.php index dce0390..972bab6 100644 --- a/app/Filament/Resources/ConfeccionResource/Pages/EditConfeccion.php +++ b/app/Filament/Resources/ConfeccionResource/Pages/EditConfeccion.php @@ -19,27 +19,48 @@ class EditConfeccion extends EditRecord Actions\Action::make('agregarRecepcion') ->label('Agregar recepción') ->modalHeading('Agregar Recepción') + ->disabled(fn (): bool => ($this->getRecord()->faltantes ?? 0) <= 0) ->form([ Forms\Components\DatePicker::make('fecha_recepcion')->default(now())->required(), - Forms\Components\TextInput::make('cantidad')->numeric()->required()->minValue(1), + Forms\Components\TextInput::make('cantidad') + ->numeric() + ->required() + ->minValue(1) + ->maxValue(fn () => $this->getRecord()->faltantes ?? 0) + ->helperText(fn () => 'Máximo: ' . ($this->getRecord()->faltantes ?? 0)) + ->default(fn () => $this->getRecord()->faltantes ?? 0), Forms\Components\Textarea::make('notas'), ]) ->action(function (array $data): void { $record = $this->getRecord(); - \App\Models\Recepcion::create([ - 'referencia_type' => \App\Models\Confeccion::class, - 'referencia_id' => $record->id, - 'cantidad' => (int) $data['cantidad'], - 'fecha_recepcion' => $data['fecha_recepcion'], - 'notas' => $data['notas'] ?? null, - ]); + try { + \App\Models\Recepcion::create([ + 'referencia_type' => \App\Models\Confeccion::class, + 'referencia_id' => $record->id, + 'cantidad' => (int) $data['cantidad'], + 'fecha_recepcion' => $data['fecha_recepcion'], + 'notas' => $data['notas'] ?? null, + ]); - \Filament\Notifications\Notification::make() - ->success() - ->title('Recepción registrada') - ->body('La recepción se creó correctamente.') - ->send(); + \Filament\Notifications\Notification::make() + ->success() + ->title('Recepción registrada') + ->body('La recepción se creó correctamente.') + ->send(); + } catch (\Illuminate\Validation\ValidationException $e) { + \Filament\Notifications\Notification::make() + ->danger() + ->title('Error') + ->body($e->validator->errors()->first() ?? 'Error al crear la recepción.') + ->send(); + } catch (\Throwable $e) { + \Filament\Notifications\Notification::make() + ->danger() + ->title('Error') + ->body($e->getMessage()) + ->send(); + } // Refrescar la página para ver cambios (redirigir explicitando el record para evitar error de ruta) $this->redirect(route('filament.admin.resources.confeccions.edit', ['record' => $record->id])); diff --git a/app/Filament/Resources/ConfeccionResource/RelationManagers/RecepcionesRelationManager.php b/app/Filament/Resources/ConfeccionResource/RelationManagers/RecepcionesRelationManager.php index cc38950..f2218e5 100644 --- a/app/Filament/Resources/ConfeccionResource/RelationManagers/RecepcionesRelationManager.php +++ b/app/Filament/Resources/ConfeccionResource/RelationManagers/RecepcionesRelationManager.php @@ -23,7 +23,12 @@ class RecepcionesRelationManager extends RelationManager { return $form->schema([ DateTimePicker::make('fecha_recepcion')->required(), - TextInput::make('cantidad')->numeric()->required()->minValue(1), + TextInput::make('cantidad') + ->numeric() + ->required() + ->minValue(1) + ->maxValue(fn () => $this->getOwnerRecord()?->faltantes ?? 0) + ->helperText(fn () => 'Máximo: ' . ($this->getOwnerRecord()?->faltantes ?? 0)), Textarea::make('notas'), ]); } diff --git a/app/Filament/Resources/TintoreriaResource/RelationManagers/RecepcionesRelationManager.php b/app/Filament/Resources/TintoreriaResource/RelationManagers/RecepcionesRelationManager.php index 4dcd602..0f86e43 100644 --- a/app/Filament/Resources/TintoreriaResource/RelationManagers/RecepcionesRelationManager.php +++ b/app/Filament/Resources/TintoreriaResource/RelationManagers/RecepcionesRelationManager.php @@ -23,7 +23,12 @@ class RecepcionesRelationManager extends RelationManager { return $form->schema([ DateTimePicker::make('fecha_recepcion')->required(), - TextInput::make('cantidad')->numeric()->required()->minValue(1), + TextInput::make('cantidad') + ->numeric() + ->required() + ->minValue(1) + ->maxValue(fn () => $this->getOwnerRecord()?->faltantes ?? 0) + ->helperText(fn () => 'Máximo: ' . ($this->getOwnerRecord()?->faltantes ?? 0)), Textarea::make('notas'), ]); }