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 visual inspection records the faults that an evaluator identifies during the physical examination of the vehicle — things like body damage, worn tires, cracked glass, or missing safety equipment. Each fault category carries a valoracion weight, and any fault that is present (tiene = 1) subtracts from a perfect score of 1.0. The resulting fallas factor accounts for 35% of the total inspection depreciation, blended with the 65% mechanical factor to produce the final depre_inspeccion coefficient.

The Inspeccion Model

Each fault item in an evaluation produces one row in the inspeccion table:
protected $fillable = [
    'id_vehiculo',    // FK → vehiculos.id
    'nombre',         // Fault section name (e.g. "Carrocería", "Vidrios")
    'caracteristica', // Specific fault within the section
    'tiene',          // 1 = fault is present, 0 = not present (cast to boolean)
    'valoracion',     // Weight deducted when the fault is present (decimal, 4 decimal places)
    'observaciones',  // Free-text notes
];

protected $casts = [
    'tiene'      => 'boolean',
    'valoracion' => 'decimal:4',
];
FieldValuesMeaning
tienetrue / falseWhether this fault was found during inspection
valoracion0.0000 – 1.0000How much this fault reduces the inspection score when present
The fault catalog that drives the inspection form is stored in the SeccionFalla model. Each catalog entry provides titulo, componente (list of characteristics), and valoracion. Admins configure these sections via GET /secciones/listado.
Configure all fault sections in Secciones before evaluators begin creating appraisals. Changes to the SeccionFalla catalog are reflected immediately in every new inspection form — the catalog is loaded fresh on each visit to the inspection page.

Fault Scoring Formula

AvaluoController::evaluar_inspeccion() computes the combined inspection factor stored as depre_inspeccion:
public function evaluar_inspeccion($id)
{
    $pesoFallas  = 35; // weight assigned to visual fault inspection
    $pesoTecnica = 65; // weight assigned to mechanical inspection

    $inspeccion = Inspeccion::where('id_vehiculo', $id)->get();
    $Tecnica    = $this->Tecnica($id); // mechanical factor (see Evaluación Mecánica)

    $data = $inspeccion->toArray();
    $suma = 0;
    foreach ($data as $item) {
        if ($item['tiene'] == 1) {
            $suma += $item['valoracion'];
        }
    }
    $fallas = 1 - $suma;

    $total = round(($pesoTecnica * $Tecnica + $pesoFallas * $fallas) / 100, 3);

    return $total; // stored as depre_inspeccion on the Avaluo record
}
Step-by-step breakdown:
  1. Sum the valoracion of every fault where tiene = 1 (fault is present).
  2. Subtract from 1.0 to get the fallas factor: fallas = 1 - Σ(valoracion where tiene = 1).
  3. Blend with the mechanical Tecnica factor using fixed weights:
    depre_inspeccion = round((65 × Tecnica + 35 × fallas) / 100, 3)
    
  4. Store the result as depre_inspeccion in the avaluos table.
This factor then feeds directly into the final appraisal value:
valorAvaluo = precio_referencial × depre_inspeccion × depre_modelo × depre_kilometraje × factor_reposicion

Workflow

Creating a New Inspection

InspeccionController@index loads the full SeccionFalla catalog and guards against duplicate submissions:
if (Inspeccion::where('id_vehiculo', $id)->exists()) {
    return redirect()->route('resultados.avaluo.continuar', $id)
        ->with('success', 'Ya se ha realizado la evaluación por Inspección para este vehículo.');
}

$secciones = SeccionFalla::all()->map(function ($seccion) {
    return [
        'titulo'          => $seccion->titulo,
        'caracteristicas' => $seccion->componente,
        'valoracion'      => $seccion->valoracion,
    ];
});
On submission, InspeccionController@store accepts a flat data[] array from the React form and bulk-inserts all fault rows in a single query:
$data = $request->input('data');

foreach ($data as $item) {
    $inspecciones[] = [
        'id_vehiculo'    => $id,
        'nombre'         => $item['nombre'],
        'caracteristica' => $item['caracteristica'],
        'tiene'          => $item['tiene'],
        'valoracion'     => $item['valoracion'],
        'observaciones'  => $item['observaciones'],
        'created_at'     => now(),
        'updated_at'     => now(),
    ];
}

Inspeccion::insert($inspecciones);

Editing a Saved Inspection

The edit form loads both the current SeccionFalla catalog and the previously saved Inspeccion rows, keying them by nombre__caracteristica:
$evaluados = Inspeccion::where('id_vehiculo', $vehiculo->id)
    ->get()
    ->keyBy(fn($i) => $i->nombre . '__' . $i->caracteristica);
This merging strategy means that if the admin adds new fault characteristics to the catalog after an appraisal is created, the new items will appear in the edit form with blank (un-marked) values — the evaluator is prompted to complete them. Updates are applied via Inspeccion::updateOrCreate() keyed on (id_vehiculo, nombre, caracteristica).

Sections Configuration

Admins manage fault sections and their characteristics at GET /secciones/listado. The available operations are:
ActionRouteNameDescription
View all sectionsGET /secciones/listadosecciones.indexLists SeccionFalla and SeccionTecnica catalogs
Update a fault sectionPOST /secciones/actualizar/{id}secciones.updateEdit a SeccionFalla entry
Update a técnica sectionPOST /secciones/actualizarTecnica/{id}secciones.updateTecnicaEdit a SeccionTecnica entry
Only users with the admin role can access these routes.

Route Reference

MethodURINameDescription
GET/registro/evaluacion/inspeccion/{id}evaluacion.inspeccionDisplay inspection form
POST/registro/evaluacion/inspeccion/store/{id}evaluacion.inspeccion.storeSave new inspection
GET/registro/evaluacion/inspeccion/edit/{id}evaluacion.inspeccion.editDisplay edit form
POST/registro/evaluacion/inspeccion/update/{id}evaluacion.inspeccion.updateUpdate saved inspection
GET/secciones/listadosecciones.indexAdmin: manage fault sections
All registration routes require auth and verified middleware. The InspeccionController enforces VehiculoPolicy::view on read operations and VehiculoPolicy::update on write operations.

Build docs developers (and LLMs) love