up
This commit is contained in:
+125
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProcesoAcabadoResource\RelationManagers;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Tables\Actions\DeleteAction;
|
||||
use Filament\Tables\Actions\EditAction;
|
||||
use Filament\Tables\Actions\CreateAction;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RecepcionesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'recepciones';
|
||||
protected static ?string $recordTitleAttribute = 'id';
|
||||
protected static ?string $title = 'Recepciones de Acabados';
|
||||
|
||||
public function form(Forms\Form $form): Forms\Form
|
||||
{
|
||||
return $form->schema([
|
||||
DateTimePicker::make('fecha_recepcion')
|
||||
->label('Fecha de Recepción')
|
||||
->required()
|
||||
->default(now()),
|
||||
|
||||
TextInput::make('cantidad')
|
||||
->label('Cantidad Recibida')
|
||||
->numeric()
|
||||
->required()
|
||||
->minValue(1)
|
||||
->maxValue(fn () => $this->getOwnerRecord()?->faltantes ?? 0)
|
||||
->helperText(fn () => 'Disponible para recibir: ' . ($this->getOwnerRecord()?->faltantes ?? 0)),
|
||||
|
||||
TextInput::make('prendas_defectuosas')
|
||||
->label('Prendas Defectuosas')
|
||||
->numeric()
|
||||
->default(0)
|
||||
->minValue(0)
|
||||
->helperText('Si hay prendas defectuosas, regístralas aquí. Estas no pasarán al inventario.'),
|
||||
|
||||
Textarea::make('notas')
|
||||
->label('Notas / Observaciones')
|
||||
->rows(3)
|
||||
->maxLength(65535),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Tables\Table $table): Tables\Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('#')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('fecha_recepcion')
|
||||
->label('Fecha Recepción')
|
||||
->dateTime('d/m/Y H:i')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('cantidad')
|
||||
->label('Cantidad')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('prendas_defectuosas')
|
||||
->label('Defectuosas')
|
||||
->default(0)
|
||||
->badge()
|
||||
->color(fn ($state) => $state > 0 ? 'danger' : 'gray'),
|
||||
|
||||
TextColumn::make('cantidad_efectiva')
|
||||
->label('Cantidad Efectiva')
|
||||
->getStateUsing(fn ($record) => $record->cantidad - ($record->prendas_defectuosas ?? 0))
|
||||
->badge()
|
||||
->color('success'),
|
||||
|
||||
TextColumn::make('usuario.name')
|
||||
->label('Usuario')
|
||||
->searchable(),
|
||||
|
||||
TextColumn::make('notas')
|
||||
->label('Notas')
|
||||
->limit(50)
|
||||
->wrap()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->label('Creado')
|
||||
->dateTime('d/m/Y H:i')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->defaultSort('fecha_recepcion', 'desc')
|
||||
->headerActions([
|
||||
CreateAction::make()
|
||||
->label('Nueva Recepción')
|
||||
->icon('heroicon-o-plus-circle')
|
||||
->disabled(fn () => ($this->getOwnerRecord()?->faltantes ?? 0) <= 0)
|
||||
->mutateFormDataUsing(function (array $data): array {
|
||||
// Asignar usuario actual
|
||||
$data['user_id'] = Auth::id();
|
||||
return $data;
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateHeading('Sin recepciones registradas')
|
||||
->emptyStateDescription('Las recepciones quedarán disponibles automáticamente para el inventario de prendas.')
|
||||
->emptyStateIcon('heroicon-o-inbox-arrow-down');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user