up
This commit is contained in:
+130
@@ -0,0 +1,130 @@
|
||||
<?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\Forms\Components\Select;
|
||||
use Filament\Tables\Actions\DeleteAction;
|
||||
use Filament\Tables\Actions\EditAction;
|
||||
use Filament\Tables\Actions\CreateAction;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AjustesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'ajustes';
|
||||
protected static ?string $recordTitleAttribute = 'id';
|
||||
protected static ?string $title = 'Reprocesos/Ajustes';
|
||||
|
||||
public function form(Forms\Form $form): Forms\Form
|
||||
{
|
||||
return $form->schema([
|
||||
Select::make('tipo')
|
||||
->label('Tipo de Ajuste')
|
||||
->options([
|
||||
'reproceso' => 'Reproceso (permite re-recepción)',
|
||||
'ajuste_entrada' => 'Ajuste de Entrada',
|
||||
'ajuste_salida' => 'Ajuste de Salida',
|
||||
])
|
||||
->required()
|
||||
->default('reproceso')
|
||||
->helperText('Los reprocesos permiten volver a recibir las prendas cuando regresen arregladas'),
|
||||
|
||||
TextInput::make('cantidad')
|
||||
->label('Cantidad')
|
||||
->numeric()
|
||||
->required()
|
||||
->minValue(1),
|
||||
|
||||
DateTimePicker::make('fecha')
|
||||
->label('Fecha del Ajuste')
|
||||
->required()
|
||||
->default(now()),
|
||||
|
||||
Textarea::make('notas')
|
||||
->label('Notas / Motivo')
|
||||
->rows(3)
|
||||
->maxLength(65535),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Tables\Table $table): Tables\Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('#')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('tipo')
|
||||
->label('Tipo')
|
||||
->badge()
|
||||
->color(fn ($state) => match($state) {
|
||||
'reproceso' => 'warning',
|
||||
'ajuste_entrada' => 'success',
|
||||
'ajuste_salida' => 'danger',
|
||||
default => 'gray',
|
||||
})
|
||||
->formatStateUsing(fn ($state) => match($state) {
|
||||
'reproceso' => 'Reproceso',
|
||||
'ajuste_entrada' => 'Ajuste Entrada',
|
||||
'ajuste_salida' => 'Ajuste Salida',
|
||||
default => $state,
|
||||
}),
|
||||
|
||||
TextColumn::make('cantidad')
|
||||
->label('Cantidad')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('fecha')
|
||||
->label('Fecha')
|
||||
->dateTime('d/m/Y H:i')
|
||||
->sortable(),
|
||||
|
||||
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', 'desc')
|
||||
->headerActions([
|
||||
CreateAction::make()
|
||||
->label('Nuevo Ajuste')
|
||||
->icon('heroicon-o-plus-circle')
|
||||
->mutateFormDataUsing(function (array $data): array {
|
||||
$data['user_id'] = Auth::id();
|
||||
return $data;
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateHeading('Sin ajustes registrados')
|
||||
->emptyStateDescription('Los reprocesos permiten re-recepción de prendas que requieren corrección.')
|
||||
->emptyStateIcon('heroicon-o-arrow-path');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user