up
This commit is contained in:
@@ -19,27 +19,48 @@ class EditConfeccion extends EditRecord
|
|||||||
Actions\Action::make('agregarRecepcion')
|
Actions\Action::make('agregarRecepcion')
|
||||||
->label('Agregar recepción')
|
->label('Agregar recepción')
|
||||||
->modalHeading('Agregar Recepción')
|
->modalHeading('Agregar Recepción')
|
||||||
|
->disabled(fn (): bool => ($this->getRecord()->faltantes ?? 0) <= 0)
|
||||||
->form([
|
->form([
|
||||||
Forms\Components\DatePicker::make('fecha_recepcion')->default(now())->required(),
|
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'),
|
Forms\Components\Textarea::make('notas'),
|
||||||
])
|
])
|
||||||
->action(function (array $data): void {
|
->action(function (array $data): void {
|
||||||
$record = $this->getRecord();
|
$record = $this->getRecord();
|
||||||
|
|
||||||
\App\Models\Recepcion::create([
|
try {
|
||||||
'referencia_type' => \App\Models\Confeccion::class,
|
\App\Models\Recepcion::create([
|
||||||
'referencia_id' => $record->id,
|
'referencia_type' => \App\Models\Confeccion::class,
|
||||||
'cantidad' => (int) $data['cantidad'],
|
'referencia_id' => $record->id,
|
||||||
'fecha_recepcion' => $data['fecha_recepcion'],
|
'cantidad' => (int) $data['cantidad'],
|
||||||
'notas' => $data['notas'] ?? null,
|
'fecha_recepcion' => $data['fecha_recepcion'],
|
||||||
]);
|
'notas' => $data['notas'] ?? null,
|
||||||
|
]);
|
||||||
|
|
||||||
\Filament\Notifications\Notification::make()
|
\Filament\Notifications\Notification::make()
|
||||||
->success()
|
->success()
|
||||||
->title('Recepción registrada')
|
->title('Recepción registrada')
|
||||||
->body('La recepción se creó correctamente.')
|
->body('La recepción se creó correctamente.')
|
||||||
->send();
|
->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)
|
// 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]));
|
$this->redirect(route('filament.admin.resources.confeccions.edit', ['record' => $record->id]));
|
||||||
|
|||||||
+6
-1
@@ -23,7 +23,12 @@ class RecepcionesRelationManager extends RelationManager
|
|||||||
{
|
{
|
||||||
return $form->schema([
|
return $form->schema([
|
||||||
DateTimePicker::make('fecha_recepcion')->required(),
|
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'),
|
Textarea::make('notas'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -23,7 +23,12 @@ class RecepcionesRelationManager extends RelationManager
|
|||||||
{
|
{
|
||||||
return $form->schema([
|
return $form->schema([
|
||||||
DateTimePicker::make('fecha_recepcion')->required(),
|
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'),
|
Textarea::make('notas'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user