Update CobrosRelationManager.php
This commit is contained in:
+60
-13
@@ -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([]);
|
||||
|
||||
Reference in New Issue
Block a user