diff --git a/app/Filament/Resources/ConfeccionResource/RelationManagers/CobrosRelationManager.php b/app/Filament/Resources/ConfeccionResource/RelationManagers/CobrosRelationManager.php index 37b6c93..540755e 100644 --- a/app/Filament/Resources/ConfeccionResource/RelationManagers/CobrosRelationManager.php +++ b/app/Filament/Resources/ConfeccionResource/RelationManagers/CobrosRelationManager.php @@ -25,19 +25,66 @@ class CobrosRelationManager extends RelationManager ]) ->filters([]) ->headerActions([ - Tables\Actions\CreateAction::make()->form([ - \Filament\Forms\Components\TextInput::make('cantidad')->numeric()->required()->minValue(1), - \Filament\Forms\Components\TextInput::make('valor')->numeric()->required()->minValue(0), - \Filament\Forms\Components\Textarea::make('notas'), - ])->action(function (array $data) { - $owner = $this->getOwnerRecord(); - try { - $owner->registerCobro((int)$data['cantidad'], (float)$data['valor'], $data['notas'] ?? null, auth()->id() ?? null); - \Filament\Notifications\Notification::make()->success()->title('Cobro registrado')->send(); - } catch (\Throwable $e) { - \Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send(); - } - }), + Tables\Actions\CreateAction::make() + ->form([ + \Filament\Forms\Components\TextInput::make('cantidad') + ->label('Cantidad de Prendas') + ->numeric() + ->required() + ->minValue(1) + ->helperText('Prendas a descontar del inventario'), + \Filament\Forms\Components\TextInput::make('valor') + ->label('Valor del Cobro') + ->numeric() + ->required() + ->minValue(0) + ->prefix('$') + ->step(0.01), + \Filament\Forms\Components\Textarea::make('notas') + ->label('Notas') + ->rows(3), + ]) + ->action(function (array $data, RelationManager $livewire) { + $owner = $livewire->getOwnerRecord(); + + try { + $owner->registerCobro( + (int) $data['cantidad'], + (float) $data['valor'], + $data['notas'] ?? null, + auth()->id() + ); + + \Filament\Notifications\Notification::make() + ->success() + ->title('Cobro registrado correctamente') + ->body("Se descontaron {$data['cantidad']} prendas del inventario.") + ->send(); + + // Refrescar la tabla + $livewire->dispatch('refresh'); + + } catch (\Illuminate\Validation\ValidationException $e) { + \Filament\Notifications\Notification::make() + ->danger() + ->title('Error de validación') + ->body($e->getMessage()) + ->persistent() + ->send(); + throw $e; + } catch (\Throwable $e) { + \Filament\Notifications\Notification::make() + ->danger() + ->title('Error al registrar cobro') + ->body($e->getMessage()) + ->persistent() + ->send(); + throw $e; + } + }) + ->modalHeading('Registrar Cobro') + ->modalSubmitActionLabel('Registrar') + ->successNotificationTitle('Cobro registrado'), ]) ->actions([]) ->bulkActions([]);