Overview
The cost calculation system automatically computes the total inspection cost based on vehicle motorization types. Each engine type has a different inspection rate, reflecting the varying complexity and time requirements for different propulsion systems.The system uses differential pricing based on motorization technology, with electric vehicles receiving the lowest rates and diesel vehicles the highest.
Pricing Structure
The current ITV inspection rates are defined in thecalcularYMostrarTotal() function (script.js:268):
Diesel
€50 per vehicleHighest rate due to emissions testing complexity
Gasoline
€45 per vehicleStandard combustion engine inspection
Hybrid
€35 per vehicleReduced rate for eco-friendly technology
Electric
€30 per vehicleLowest rate - minimal emissions inspection needed
Core Function: calcularYMostrarTotal()
The main calculation function (script.js:268) handles all pricing logic:
Calculation Process
The cost calculation follows a systematic workflow:Define Rate Table
Tariff structure is established with rates for each motorization type (Diesel: €50, Gasoline: €45, Hybrid: €35, Electric: €30).
Count Vehicles by Type
The system iterates through
vehiculosData array and counts vehicles by motorization type.Calculate Subtotals
Individual costs are calculated by multiplying vehicle count by respective rate.
Data Source
Vehicle Data Array
The calculation function relies on thevehiculosData global array, which is populated by procesarDatosVehiculos() (script.js:189):
script.js:189-204
Each vehicle object in
vehiculosData contains: vehicle number, motorization type, ITV status, and observations.Visual Representation
Itemized Breakdown
The calculation displays a detailed cost breakdown with visual styling (styles.css:666-673):- Breakdown Item Styles
- Total Display Styles
- Container Styles
styles.css:666-673
Icon Mapping
TheobtenerEmojiMotorizacion() helper function (script.js:326) provides visual indicators:
script.js:326-334
The default 🚗 emoji serves as a fallback for any unexpected motorization types.
Example Calculations
Here are some real-world calculation scenarios:Single Vehicle - Diesel
Single Vehicle - Diesel
Input:Display:
- 1 Diesel vehicle
Mixed Fleet - 5 Vehicles
Mixed Fleet - 5 Vehicles
Input:Display:
- 2 Diesel vehicles
- 1 Gasoline vehicle
- 1 Hybrid vehicle
- 1 Electric vehicle
Electric Fleet - 10 Vehicles
Electric Fleet - 10 Vehicles
Input:Display:
- 10 Electric vehicles
Integration with Results Display
The cost calculation is called as part of the main calculation workflow incalcular() (script.js:119):
script.js:119-148
Display Container
Results are rendered in the total section of index.html (index.html:76-84):index.html:76-84
Styling Details
The total amount display has distinctive styling (styles.css:361-374):styles.css:361-374
Performance Considerations
Efficient Iteration
Single pass through vehicle data using
forEach() for countingConditional Rendering
Only motorization types with vehicles are displayed in the breakdown
Template Strings
HTML generation uses efficient template literals
No External Dependencies
Pure JavaScript calculation with no library dependencies
Customization Options
The rate structure can be easily modified by updating thetarifas object:
Rate changes take effect immediately without requiring changes to other parts of the system.
Error Handling
The calculation is wrapped in a try-catch block (script.js:144-147) to handle unexpected errors:script.js:144-147
Next Steps
Results Display
See how calculated costs are presented to users
Data Validation
Learn about the validation that precedes calculation