Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/alber1802/AvaluoVehicular/llms.txt

Use this file to discover all available pages before exploring further.

The mechanical evaluation records the condition of every functional system in the vehicle — engine, transmission, suspension, brakes, and so on. Each component is assessed individually using a configurable catalog (SeccionTecnica), and the resulting scores are aggregated into a single Técnica factor that contributes 65% of the overall inspection depreciation applied to the final appraisal value.

The Sistema Model

Each evaluated component produces one row in the sistemas table, represented by the Sistema model:
protected $fillable = [
    'id_vehiculo',   // FK → vehiculos.id
    'titulo',        // System group name (e.g. "Motor", "Transmisión")
    'componente',    // Specific component name within the group
    'estado',        // Condition score — cast to array
    'valoracion',    // Weight of this component (decimal, 5 decimal places)
    'observaciones', // Free-text notes
];

protected $casts = [
    'estado'     => 'array',
    'valoracion' => 'decimal:5',
];
FieldRangeMeaning
valoracion0.00000 – 1.00000The weight this component carries in the total mechanical score
estadonumeric value(s)The condition assigned during evaluation; multiplied by valoracion to produce the depreciation contribution
The catalog that drives the form is stored in SeccionTecnica. Each catalog entry exposes titulo, componente, valoracion, and opciones (the selectable condition levels shown to the evaluator in the UI).
The mechanical evaluation contributes 65% of the depre_inspeccion factor that is stored on the Avaluo record. The remaining 35% comes from the visual fault inspection. Together they form the complete inspection depreciation factor factor_c.

Scoring Formula

AvaluoController::Tecnica() iterates over every Sistema row for the vehicle and accumulates the weighted depreciation:
public function Tecnica($id)
{
    $vehiculo = Vehiculo::where('id', $id)->first();
    $tecnicas = Sistema::where('id_vehiculo', $vehiculo->id)->get();
    $valorTecnicas = 0;

    foreach ($tecnicas as $tecnica) {
        if ($tecnica->valoracion != null) {
            $valorTecnicas += $tecnica->valoracion * $tecnica->estado;
        }
    }

    return 1 - $valorTecnicas;
}
The result is a factor between 0 and 1 where 1 means perfect mechanical condition (zero depreciation) and lower values represent increasing mechanical wear. This factor is then blended with the fault inspection score inside evaluar_inspeccion():
factor_c = round((65 × Tecnica + 35 × fallas) / 100, 3)
The factor_c value is stored as depre_inspeccion on the Avaluo record and participates directly in the final estimated value:
valorAvaluo = precio_referencial × factor_c × depre_modelo × depre_kilometraje × factor_reposicion

Workflow

Creating a New Evaluation

When the evaluator selects Mecánica on the method selection screen, they are routed to the evaluation form. The MecanicaController@index method loads the full SeccionTecnica catalog and checks whether systems have already been saved for this vehicle:
// If systems already exist, redirect to the continuar route
if (Sistema::where('id_vehiculo', $id)->exists()) {
    return redirect()->route('resultados.avaluo.continuar', $id)
        ->with('success', 'Ya se ha realizado la evaluación mecánica para este vehículo.');
}

$tecnicas = SeccionTecnica::all()->map(function ($tecnica) {
    return [
        'titulo'      => $tecnica->titulo,
        'componentes' => $tecnica->componente,
        'valoracion'  => $tecnica->valoracion,
        'opciones'    => $tecnica->opciones,
    ];
});
On submission, MecanicaController@store flattens the nested sistemas[].componentes[] payload into individual rows and bulk-inserts them with Sistema::insert():
foreach ($datos['sistemas'] as $sistema) {
    $titulo = $sistema['titulo'];

    foreach ($sistema['componentes'] as $componente) {
        $registrosMecanica[] = [
            'id_vehiculo'  => $id,
            'titulo'       => $titulo,
            'componente'   => $componente['componente'],
            'estado'       => $componente['estado'],
            'valoracion'   => $componente['valoracion'],
            'observaciones' => $componente['observaciones'],
            'created_at'   => now(),
            'updated_at'   => now(),
        ];
    }
}

Sistema::insert($registrosMecanica);

Editing a Saved Evaluation

The edit form merges the live SeccionTecnica catalog with the previously saved Sistema rows, keyed by titulo__componente. This ensures that even if the admin later changes the catalog, the evaluator sees the full current catalog with their previous answers pre-filled. Updates are persisted via Sistema::updateOrCreate() keyed on (id_vehiculo, titulo, componente).

Route Reference

MethodURINameDescription
GET/registro/evaluacion/mecanica/{id}evaluacion.mecanicaDisplay evaluation form
POST/registro/evaluacion/mecanica/store/{id}evaluacion.mecanica.storeSave new evaluation
GET/registro/evaluacion/mecanica/edit/{id}evaluacion.mecanica.editDisplay edit form
POST/registro/evaluacion/mecanica/update/{id}evaluacion.mecanica.updateUpdate saved evaluation
All routes require auth and verified middleware. Edit and update operations additionally enforce VehiculoPolicy::update — admins can edit any vehicle’s evaluation; evaluators can only edit vehicles they own (id_evaluador = Auth::id()).

Build docs developers (and LLMs) love