50 lines
1.8 KiB
PHP
50 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ConfeccionResource\Pages;
|
|
|
|
use App\Filament\Resources\ConfeccionResource;
|
|
use Filament\Actions;
|
|
use Filament\Forms;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
|
|
class EditConfeccion extends EditRecord
|
|
{
|
|
protected static string $resource = ConfeccionResource::class;
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Actions\DeleteAction::make(),
|
|
|
|
Actions\Action::make('agregarRecepcion')
|
|
->label('Agregar recepción')
|
|
->modalHeading('Agregar Recepción')
|
|
->form([
|
|
Forms\Components\DatePicker::make('fecha_recepcion')->default(now())->required(),
|
|
Forms\Components\TextInput::make('cantidad')->numeric()->required()->minValue(1),
|
|
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,
|
|
]);
|
|
|
|
\Filament\Notifications\Notification::make()
|
|
->success()
|
|
->title('Recepción registrada')
|
|
->body('La recepción se creó correctamente.')
|
|
->send();
|
|
|
|
// Refrescar la página para ver cambios
|
|
$this->redirect($this->getUrl());
|
|
}),
|
|
];
|
|
}
|
|
}
|