schema([ Section::make('Datos de Confección') ->schema([ Select::make('proveedor_id') ->label('Tallerista') ->relationship( 'proveedor', 'nombre', fn($query) => $query->where('categoria', 'talleres') ) ->searchable() ->preload() ->required(), Select::make('orden_produccion_id') ->label('Orden de Producción') ->relationship('ordenProduccion', 'numero_orden') ->searchable() ->preload() ->reactive() ->required() ->afterStateUpdated(function ($state, $set) { if ($state) { $orden = \App\Models\OrdenProduccion::find($state); if ($orden) { $set('cantidad_enviada', $orden->cantidad_total); $set('fecha_envio', now()->toDateString()); } } }), DatePicker::make('fecha_envio') ->required() ->default(now()), TextInput::make('cantidad_enviada') ->numeric() ->required() ->minValue(1) ->maxValue(fn ($get) => $get('orden_produccion_id') ? \App\Models\OrdenProduccion::find($get('orden_produccion_id'))->cantidad_total : null) ->helperText(fn ($get) => $get('orden_produccion_id') ? 'Máximo: ' . \App\Models\OrdenProduccion::find($get('orden_produccion_id'))->cantidad_total : 'Selecciona una Orden de Producción') ->reactive() ->afterStateUpdated(function ($state, $set, $get) { $valor = $get('valor_por_prenda') ?? 0; $cantidad = $get('cantidad_recibida') ?? $state; $set('total_pagar', $cantidad && $valor ? $cantidad * $valor : 0); }), TextInput::make('valor_por_prenda') ->numeric() ->prefix('$') ->required() ->reactive() ->afterStateUpdated(function ($state, $set, $get) { $cantidad = $get('cantidad_recibida') ?? $get('cantidad_enviada'); $set('total_pagar', $cantidad && $state ? $cantidad * $state : 0); }), TextInput::make('total_pagar') ->prefix('$') ->numeric() ->readOnly() ->default(0), ]) ->columns(2), Section::make('Recepción y Calidad') ->description('Campos que se diligencian al recibir la confección en el taller o bodega') ->schema([ DatePicker::make('fecha_recepcion'), TextInput::make('cantidad_recibida') ->numeric() ->reactive() ->afterStateUpdated(function ($state, $set, $get) { $valor = $get('valor_por_prenda') ?? 0; $cantidad = $state ?? $get('cantidad_enviada'); $set('total_pagar', $cantidad && $valor ? $cantidad * $valor : 0); }), TextInput::make('prendas_defectuosas') ->numeric() ->default(0), ]) ->columns(2) ->collapsed(), ]); } public static function table(Table $table): Table { return $table ->columns([ TextColumn::make('ordenProduccion.numero_orden') ->label('OP') ->searchable(), TextColumn::make('proveedor.nombre') ->label('Tallerista') ->searchable(), TextColumn::make('cantidad_enviada'), TextColumn::make('cantidad_recibida'), BadgeColumn::make('estado') ->colors([ 'warning' => 'pendiente', 'info' => 'parcial', 'success' => 'completo', ]) ->formatStateUsing(fn($state) => ucfirst($state)), TextColumn::make('total_pagar') ->money('COP'), ]) ->filters([ // ]) ->actions([ Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]); } public static function getRelations(): array { return [ // ]; } public static function getPages(): array { return [ 'index' => Pages\ListConfeccions::route('/'), 'create' => Pages\CreateConfeccion::route('/create'), 'edit' => Pages\EditConfeccion::route('/{record}/edit'), ]; } }