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 PDF report is the final, deliverable output of the appraisal workflow. Once all data collection steps are complete — vehicle registration, mechanical evaluation, visual inspection, and image upload — evaluators can trigger on-demand PDF generation. The resulting document packages every piece of collected data, all calculated depreciation factors, and the final estimated vehicle value into a single professional file that can be downloaded, printed, or shared with clients.
Route
PDF generation is handled by ArchivoControler and sits under the /archivos prefix, protected by the auth and verified middleware.
| Method | URI | Name | Controller Method | Purpose |
|---|
GET | /archivos/generarPdf/{id} | archivos.generarPdf | ArchivoControler@generarPdf | Generate (or regenerate) the PDF for appraisal {id} |
The route requires the authenticated user to be authorized to view the vehicle ($this->authorize('view', $vehiculo)). Unauthorized access is rejected before any PDF work begins.
What’s Included in the Report
The private prepararDatosPdf method assembles all data passed to the Blade template at resources/views/pdf/avaluo.blade.php. The following information is included in every generated report:
Vehicle Data
All core vehicle attributes recorded during registration:
| Field | Description |
|---|
Brand (marca) | Vehicle make, including brand-level depreciation rates |
Model & year (año_fabricacion) | Used to calculate model-age depreciation |
Plate (placa) | Also used to name the PDF file |
| Chassis / VIN | Vehicle identification |
Mileage (kilometraje) | Used to calculate kilometrage depreciation |
| Color | Cosmetic description |
| Origin | Import/national origin |
| Fuel type | Petrol, diesel, hybrid, etc. |
Reference price (precio_referencial) | Base value before depreciation |
The user assigned as evaluator (id_evaluador) is fetched and included so the report is attributable to a named professional:
$evaluador = User::where('id', $vehiculo->id_evaluador)->firstOrFail();
Mechanical Systems Results
Each Sistema record for the vehicle is mapped to a structured array and passed as $sistemas:
$sistemas = Sistema::where('id_vehiculo', $id)->get()->map(function ($item) {
return [
'sistema' => $item->titulo,
'componente' => $item->componente,
'estado' => $item->estado,
'observaciones' => $item->observaciones,
];
});
Visual Inspection Faults
Each Inspeccion fault record is included, showing whether the fault was present (tiene = 1) and its weighted valuation:
$inspeccion = Inspeccion::where('id_vehiculo', $id)->get()->map(function ($item) {
return [
'componente' => $item->nombre,
'caracteristica' => $item->caracteristica,
'tiene' => $item->tiene,
'valoracion' => $item->valoracion,
'observaciones' => $item->observaciones,
];
});
Accessories
All applicable accessories (aplica = 1) are listed with their condition and observations.
Vehicle Images
All VehiculoImagen records are embedded directly in the report:
$imagenes = VehiculoImagen::where('id_vehiculo', $id)->get();
Depreciation Factors
The report documents every factor used to calculate the final value, giving full transparency to the appraisal methodology:
| Variable | Description |
|---|
factorModelo (depre_modelo) | Age-based depreciation — max(1 − (tasa_k × antigüedad), valor_residual) |
factorKilometraje (depre_kilometraje) | Mileage-based depreciation — max(1 − (0.000001 × km), 0.05) |
factorInspeccion (depre_inspeccion) | Weighted combination of technical inspection (65%) and fault inspection (35%) |
factorReposicion (factor_reposicion) | Fixed replacement cost factor of 1.2 |
// Final value formula (from calcularFactoresDepreciacion)
$valorCalculado = $vehiculo->precio_referencial
* $factorInspeccion
* $factorModelo
* $factorKilometraje
* $factorReposicion;
$valorResidual = (float) ($vehiculo->precio_referencial * $marca->valor_residual);
$valorFinal = (float) max($valorCalculado, $valorResidual);
// Cap: if calculated value exceeds reference price, drop the reposición factor
if ($valorFinal >= $vehiculo->precio_referencial) {
$valorFinal = $vehiculo->precio_referencial
* $factorInspeccion
* $factorModelo
* $factorKilometraje;
}
Final Value and Residual Value
| Variable | Description |
|---|
valorFinal (final_estimacion) | The final estimated market value of the vehicle |
valorResidual | Minimum floor value — precio_referencial × valor_residual |
Currency
The moneda field from the appraisal record is displayed alongside all monetary values so the report is unambiguous about the currency used.
The Archivo Model
Every time a PDF is generated, the resulting file is saved to storage and its path is recorded in the archivos table via the Archivo model. If a record for the vehicle already exists, the old file is deleted and the record is updated; otherwise, a new record is created.
// app/Models/Archivo.php
protected $fillable = [
'id_vehiculo', // Foreign key → vehiculos.id
'tipo_archivo', // Always 'pdf' for generated reports
'url', // Storage-relative path, e.g. "pdfReportes/Avaluo_ABC123_20240610_120000.pdf"
'comentario', // Optional notes
'fecha', // Generation date (cast to date)
];
Files are stored under storage/app/public/pdfReportes/ and named deterministically:
pdfReportes/Avaluo_{placa}_{YYYYMMDD_HHmmss}.pdf
$nombreArchivo = 'Avaluo_' . ($vehiculo->placa ?? $vehiculo->id) . '_' . now()->format('Ymd_His') . '.pdf';
$rutaPdf = 'pdfReportes/' . $nombreArchivo;
PDF Library
The project uses mPDF via the carlos-meneses/laravel-mpdf package. The controller loads the compiled Blade view as HTML and writes the binary output to storage:
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
$pdf = LaravelMpdf::loadHtml(view('pdf.avaluo', $data));
Storage::disk('public')->put($rutaPdf, $pdf->output());
The PDF is generated on demand each time the route is visited. If the appraisal data has changed since the last generation (e.g., inspection results were updated), visiting the route again will overwrite the previous file with a freshly rendered version.
Before generating the PDF, confirm that all appraisal steps have been completed: vehicle registration, mechanical evaluation, visual inspection, accessories, and image upload. Missing data in any section will result in incomplete sections in the report, and some fields (such as CondicionGeneral) will cause an exception if not present.