Endpoint
Authentication
Requires JWT authentication token. The authenticated user’s ID is automatically recorded ascreado_por for all imported records.
Request Body
Operational area identifier to assign to all imported records
Fuel station identifier to assign to all imported records
Array of record objects to import. Each record should contain:
Date in format DD/MM/YYYY or Excel serial date number
Driver’s full name (matched against existing drivers)
Vehicle plate (will be normalized to format ABC-123)
Fuel type: ACPM, GASOLINA, or EXTRA. Defaults to GASOLINA if not specified
Total fuel cost (can include thousand separators and currency symbols)
Quantity in gallons (can include decimal separators)
Response
Number of records successfully imported
Total number of records in the import file
Examples
Import Fuel Records
Import with Excel Serial Dates
Success Response Example
Status Code:200 OK
Data Processing
Plate Normalization
The system automatically normalizes vehicle plates:- ABC123 → ABC-123 (adds hyphen after 3 letters)
- DEF 456 → DEF-456 (replaces space with hyphen)
- GHI-789 → GHI-789 (no change needed)
Date Parsing
Supports multiple date formats:- DD/MM/YYYY: “15/03/2024”
- Excel serial number: 45361 (days since 1900-01-01)
- ISO format: “2024-03-15”
Number Parsing
Handles various numeric formats:- With thousand separators: “150,000” or “150.000”
- With currency symbols: “$150,000” or “COP 150000”
- With decimal separators: “12.5” or “12,5”
- Plain numbers: “150000”
Driver Matching
Driver names are matched using a robust algorithm:- Convert to uppercase
- Remove non-alphanumeric characters
- Match against existing drivers in
areas_conductorestable - If no match found,
conductor_idis set to null
Plate Matching
Plates are matched after normalization:- Normalize format (add hyphen if needed)
- Convert to uppercase
- Match against active plates in
areas_placastable (estado = ‘ACTIVADA’) - If no match found, the record fails with a specific error
Validation Rules
Required Fields
Each record must include:FECHAPLACAVALOR TANQUEOCANTIDAD GALONES
Plate Validation
The plate must:- Exist in the
areas_placastable - Have status
ACTIVADA - Match after normalization
Numeric Validation
VALOR TANQUEOmust be a valid positive numberCANTIDAD GALONESmust be a valid positive number- Both fields accept decimal values
Automatic Calculations
For each imported record:- costo_por_galon: Calculated as
valor_tanqueo / cantidad_galones - tipo_operacion: Set to “TANQUEO”
- concepto: Set to “OPERATIVO”
- creado_por: Set to authenticated user’s ID
- tipo_combustible: Defaults to “GASOLINA” if not specified or empty
Error Handling
Common Errors
- “Datos incompletos”: Missing required fields (FECHA, PLACA, or VALOR TANQUEO)
- “Placa no encontrada”: Vehicle plate doesn’t exist or is not active
- Parse errors: Invalid date or number formats
- Database errors: Constraint violations or connection issues
Partial Success
The import operation processes all records and reports:- How many were successfully imported
- How many failed with detailed error information
- The original row data for each failed record
Implementation Notes
Performance
- All records are validated before insertion
- Catalog data (plates, drivers) is loaded once at the start
- Uses in-memory maps for fast lookups
- Batch insert for all valid records
Character Encoding
- Handles Spanish characters (tildes, ñ) correctly
- Converts all text to uppercase for matching
- Removes accents and special characters for robust matching
Transaction Safety
- Valid records are inserted in a single transaction
- If the batch insert fails, all records in that batch are rolled back
- Error records are never inserted
Excel Template Example
| FECHA | NOMBRE CONDUCTOR | PLACA | TIPO COMBUSTIBLE | VALOR TANQUEO | CANTIDAD GALONES |
|---|---|---|---|---|---|
| 15/03/2024 | Juan Carlos Pérez | ABC-123 | ACPM | $150,000 | 12.5 |
| 15/03/2024 | María González | DEF456 | GASOLINA | 95000 | 7.3 |
| 16/03/2024 | Carlos López | GHI-789 | ACPM | 180,000 | 15.0 |
Best Practices
- Validate plates first: Ensure all vehicle plates exist in the system before importing
- Use consistent formats: Stick to one date and number format throughout the file
- Include driver names: Even though optional, it helps with record keeping
- Review errors: Check the error array for any failed records and fix them
- Test with small batches: Import a few records first to validate the format
- Keep backup: Save the original file in case you need to re-import
Related Endpoints
- Create Fuel Record - Create individual records
- List Fuel Records - View imported records
- Update Fuel Record - Fix imported records if needed