167 lines
5.7 KiB
PHP
167 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\InventarioPrendaResource\Pages;
|
|
use App\Filament\Resources\InventarioPrendaResource\RelationManagers;
|
|
use App\Models\InventarioPrenda;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
use Filament\Forms\Components\{
|
|
Select,
|
|
TextInput,
|
|
DatePicker,
|
|
Section
|
|
};
|
|
use Filament\Tables\Columns\{
|
|
TextColumn,
|
|
BadgeColumn
|
|
};
|
|
|
|
class InventarioPrendaResource extends Resource
|
|
{
|
|
protected static ?string $model = InventarioPrenda::class;
|
|
|
|
protected static ?string $navigationGroup = 'Gestión';
|
|
protected static ?int $navigationSort = 6;
|
|
protected static ?string $navigationIcon = 'heroicon-o-circle-stack';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form->schema([
|
|
Section::make('Ingreso a Inventario')
|
|
->schema([
|
|
Select::make('orden_produccion_id')
|
|
->label('Orden de Producción')
|
|
->relationship('ordenProduccion', 'numero_orden')
|
|
->searchable()
|
|
->preload()
|
|
->required(),
|
|
|
|
TextInput::make('cantidad_terminada')
|
|
->numeric()
|
|
->required()
|
|
->afterStateUpdated(function ($state, $set) {
|
|
// Mantener la cantidad disponible igual a la terminada al crear
|
|
$set('cantidad_disponible', $state);
|
|
}),
|
|
|
|
Select::make('producto_id')
|
|
->label('Producto (opcional)')
|
|
->relationship('producto', 'nombre')
|
|
->searchable()
|
|
->preload()
|
|
->nullable()
|
|
->helperText('Si se selecciona, el stock del producto se incrementará automáticamente cuando se guarde.'),
|
|
|
|
TextInput::make('cantidad_disponible')
|
|
->disabled()
|
|
->dehydrated(false),
|
|
|
|
DatePicker::make('fecha_ingreso')
|
|
->required(),
|
|
|
|
Select::make('estado')
|
|
->options([
|
|
'en_bodega' => 'En bodega',
|
|
'lista_despacho' => 'Lista para despacho',
|
|
])
|
|
->required(),
|
|
])
|
|
->columns(2),
|
|
|
|
Section::make('Distribución')
|
|
->schema([
|
|
\Filament\Forms\Components\Repeater::make('distribuciones')
|
|
->label('Distribuciones por bodega / color / talla')
|
|
->schema([
|
|
Select::make('bodega_id')
|
|
->label('Bodega')
|
|
->relationship('bodega', 'nombre')
|
|
->required(),
|
|
|
|
Select::make('color_id')
|
|
->label('Color')
|
|
->relationship('color', 'nombre')
|
|
->nullable(),
|
|
|
|
Select::make('size_id')
|
|
->label('Talla')
|
|
->relationship('size', 'nombre')
|
|
->nullable(),
|
|
|
|
TextInput::make('cantidad')
|
|
->label('Cantidad')
|
|
->numeric()
|
|
->required()
|
|
->minValue(1),
|
|
])
|
|
->columns(1)
|
|
->dehydrated(false)
|
|
->minItems(0)
|
|
->helpMessage('Agrega una o varias filas para distribuir la cantidad terminada entre bodegas/variantes.'),
|
|
])
|
|
->columns(1),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('ordenProduccion.numero_orden')
|
|
->label('OP')
|
|
->searchable(),
|
|
|
|
TextColumn::make('cantidad_terminada'),
|
|
|
|
TextColumn::make('cantidad_disponible'),
|
|
|
|
TextColumn::make('fecha_ingreso')
|
|
->date(),
|
|
|
|
BadgeColumn::make('estado')
|
|
->formatStateUsing(fn($state) => match ($state) {
|
|
'en_bodega' => 'En bodega',
|
|
'lista_despacho' => 'Lista para despacho',
|
|
})
|
|
->colors([
|
|
'secondary' => 'en_bodega',
|
|
'success' => 'lista_despacho',
|
|
]),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
RelationManagers\DistribucionesRelationManager::class,
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListInventarioPrendas::route('/'),
|
|
'create' => Pages\CreateInventarioPrenda::route('/create'),
|
|
'edit' => Pages\EditInventarioPrenda::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|