Overview
The calculation engine processes vehicle inspection data, calculates costs based on motorization types, and displays comprehensive results to the user.calcular()
Main calculation orchestrator that coordinates all data processing and result display. Source:script.js:119-148
Parameters
This function takes no parameters.Returns
void - Does not return a value
Process Flow
- Obtains client data
- Validates all vehicle forms
- Processes vehicle data
- Displays client information
- Displays ITV status for each vehicle
- Displays vehicle observations
- Calculates and displays total cost
Error Handling
The function is wrapped in a try-catch block. Any errors are logged to console and displayed to the user via
mostrarError().Example Implementation
obtenerDatosCliente()
Extracts and returns client information from the main form. Source:script.js:154-161
Parameters
This function takes no parameters.Returns
Object - Client data object with the following structure:
Example Implementation
Usage
procesarDatosVehiculos()
Extracts data from all vehicle forms and stores it in the globalvehiculosData array.
Source: script.js:189-204
Parameters
This function takes no parameters. It processes forms based on the globalnumeroAutos variable.
Returns
void - Does not return a value
Side Effects
- Resets the global
vehiculosDataarray - Populates
vehiculosDatawith one object per vehicle
Vehicle Data Structure
Each vehicle object contains:Example Implementation
This function assumes that
validarFormulariosVehiculos() has already been called and returned true.calcularYMostrarTotal()
Calculates the total cost based on vehicle motorization types and displays a detailed breakdown. Source:script.js:268-319
Parameters
This function takes no parameters. It uses the globalvehiculosData array.
Returns
void - Does not return a value
Pricing Structure
| Motorization | Cost per Vehicle |
|---|---|
| Diesel | 50€ |
| Gasolina | 45€ |
| Híbrido | 35€ |
| Eléctrico | 30€ |
Calculation Logic
- Count vehicles by motorization type
- Calculate cost per type (quantity × rate)
- Sum all costs for total
- Generate detailed breakdown with emojis
- Display in the
#totalcontainer
Example Implementation
Output Example
For 2 Diesel, 1 Gasolina, and 1 Eléctrico:obtenerEmojiMotorizacion()
Returns the emoji icon for a given motorization type. Source:script.js:326-334
Parameters
The motorization type: “Diesel”, “Gasolina”, “Hibrido”, or “Electrico”
Returns
string - The emoji corresponding to the motorization type, or ”🚗” as default
Emoji Mapping
| Motorization | Emoji |
|---|---|
| Diesel | 🛢️ |
| Gasolina | ⛽ |
| Hibrido | 🔋 |
| Electrico | ⚡ |
| Default | 🚗 |
Example Implementation
Usage
calcularYMostrar()
Combined function that validates, calculates, hides forms, and displays results. Source:script.js:693-704
Parameters
This function takes no parameters.Returns
void - Does not return a value
Process Flow
- Validates all vehicle forms
- Exits early if validation fails
- Calls
calcular()to process data - Calls
ocultarCaja()to hide forms - After 500ms delay, adds action buttons
Example Implementation
This is the function called by the “Calcular Resultados” button. It serves as the main entry point for the calculation workflow.
Display Functions
mostrarInformacionCliente()
Source:script.js:210-218
Displays client information in the results section.
Client data object returned by
obtenerDatosCliente()mostrarEstadosITV()
Source:script.js:223-239
Displays the ITV approval status for each vehicle with color-coded styling.
mostrarObservaciones()
Source:script.js:244-263
Displays all vehicle observations. Shows “Sin observaciones registradas” if none exist.
Animation Functions
ocultarCaja()
Source:script.js:339-355
Animates the form sections out and triggers result display.
mostrarResultados()
Source:script.js:360-375
Animates the results section in and scrolls to it smoothly.
Related Functions
- Form Generation - Generate vehicle forms
- Data Validation - Validate before calculation
- Export Functions - Export calculation results