Update CobrosRelationManager.php
This commit is contained in:
+60
-13
@@ -25,19 +25,66 @@ class CobrosRelationManager extends RelationManager
|
|||||||
])
|
])
|
||||||
->filters([])
|
->filters([])
|
||||||
->headerActions([
|
->headerActions([
|
||||||
Tables\Actions\CreateAction::make()->form([
|
Tables\Actions\CreateAction::make()
|
||||||
\Filament\Forms\Components\TextInput::make('cantidad')->numeric()->required()->minValue(1),
|
->form([
|
||||||
\Filament\Forms\Components\TextInput::make('valor')->numeric()->required()->minValue(0),
|
\Filament\Forms\Components\TextInput::make('cantidad')
|
||||||
\Filament\Forms\Components\Textarea::make('notas'),
|
->label('Cantidad de Prendas')
|
||||||
])->action(function (array $data) {
|
->numeric()
|
||||||
$owner = $this->getOwnerRecord();
|
->required()
|
||||||
try {
|
->minValue(1)
|
||||||
$owner->registerCobro((int)$data['cantidad'], (float)$data['valor'], $data['notas'] ?? null, auth()->id() ?? null);
|
->helperText('Prendas a descontar del inventario'),
|
||||||
\Filament\Notifications\Notification::make()->success()->title('Cobro registrado')->send();
|
\Filament\Forms\Components\TextInput::make('valor')
|
||||||
} catch (\Throwable $e) {
|
->label('Valor del Cobro')
|
||||||
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
|
->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([])
|
->actions([])
|
||||||
->bulkActions([]);
|
->bulkActions([]);
|
||||||
|
|||||||
Reference in New Issue
Block a user