Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/lucavallini/aibar-frontend/llms.txt

Use this file to discover all available pages before exploring further.

The Combustible module is the primary cost-tracking tool in Aibar SRL App. Every time a truck is refuelled, operators log the litres dispensed, the amount paid, the odometer reading, and — optionally — the trip the vehicle was running at the time. Because fuel is typically the largest variable operating expense in a transport fleet, this data feeds directly into per-vehicle cost analysis via the gastoTotalPorCamion summary endpoint. The list view defaults to the last 30 days so dispatchers see recent activity at a glance, with a single toggle to expand to the full historical record.

Data Models

CargaCombustible

The read model returned by the API for every fuel load record.
export interface CargaCombustible {
  id: string;
  camion_id: string;
  viaje_id: string | null;
  litros: number;
  monto: number;
  fecha: string;
  kms_al_momento: number | null;
  registrado_por: string | null;
  creado_en: string;
}
id
string
required
Unique identifier for the fuel load record.
camion_id
string
required
ID of the truck that was refuelled.
viaje_id
string | null
Trip the truck was assigned to at the time of the load. null when the load was not linked to any trip.
litros
number
required
Volume of fuel dispensed, in litres.
monto
number
required
Total cost of the fuel load in the local currency.
fecha
string
required
Date of the fuel load in ISO 8601 format (YYYY-MM-DD). Defaults to today when not supplied at creation.
kms_al_momento
number | null
Odometer reading recorded at the time of refuelling. null if not captured.
registrado_por
string | null
ID of the user who created the record. Set by the backend.
creado_en
string
required
UTC timestamp of when the record was inserted into the database.

CargaCombustibleCreate

The write model sent to the API when registering a new fuel load.
export interface CargaCombustibleCreate {
  camion_id: string;
  viaje_id?: string;
  litros: number;
  monto: number;
  fecha?: string;
  kms_al_momento?: number;
}
camion_id
string
required
ID of the truck being refuelled. Must match an existing truck in the fleet.
litros
number
required
Litres of fuel loaded. Must be greater than zero — the component validates this before submitting.
monto
number
required
Total cost of the load. Must be greater than zero.
viaje_id
string
Optional. Links this fuel load to a specific trip. When provided, the load can be attributed to a route’s operating cost.
fecha
string
Optional. ISO 8601 date string (YYYY-MM-DD). When omitted, the backend defaults to the current date.
kms_al_momento
number
Optional. Odometer value at the time of refuelling. Useful for calculating fuel consumption per kilometre over time.

CombustibleService

CombustibleService is a root-level Angular injectable that wraps all fuel-related API calls.
@Injectable({ providedIn: 'root' })
export class CombustibleService {
  private apiUrl = `${environment.apiUrl}/combustible`;

  constructor(private http: HttpClient) {}
}

listar()

Fetches a paginated list of fuel loads. By default, only loads from the last 30 days are returned.
listar(
  camionId?: string,
  pagina: number = 1,
  tamanoPagina: number = 20,
  soloUltimos30Dias: boolean = true
): Observable<RespuestaPaginada<CargaCombustible>>
HTTP request:
GET /combustible/?pagina=1&tamano_pagina=20&solo_ultimos_30_dias=true&camion_id=<camionId>
The camion_id query parameter is appended only when camionId is provided. The response is wrapped in the standard RespuestaPaginada<T> envelope:
export interface RespuestaPaginada<T> {
  items: T[];
  total: number;
  pagina: number;
  tamano_pagina: number;
  total_paginas: number;
}

30-Day Filter

soloUltimos30Dias defaults to true, which means the API only returns fuel loads with a fecha within the past 30 calendar days. This keeps the default list relevant and fast. To retrieve the complete historical record for a truck, pass false:
this.combustibleService.listar(camionId, 1, 20, false);
In the ListaCombustible component, this is controlled by the verTodoElHistorico signal and wired to a checkbox in the UI:
toggleVerTodo(): void {
  this.verTodoElHistorico.set(!this.verTodoElHistorico());
  this.pagina.set(1);
  this.cargarCargas();
}

crear()

Posts a new fuel load record to the API.
crear(datos: CargaCombustibleCreate): Observable<CargaCombustible>
HTTP request:
POST /combustible/
Content-Type: application/json

{
  "camion_id": "abc-123",
  "litros": 350,
  "monto": 87500,
  "fecha": "2025-07-10",
  "kms_al_momento": 142500
}
The component validates that camion_id is set and that both litros and monto are greater than zero before calling this method:
confirmarAlta(): void {
  if (!this.nuevaCarga.camion_id || this.nuevaCarga.litros <= 0 || this.nuevaCarga.monto <= 0) {
    this.error.set('Camión, litros y monto son obligatorios (mayores a cero)');
    return;
  }
  this.combustibleService.crear(this.nuevaCarga).subscribe({
    next: () => {
      this.cerrarModal();
      this.pagina.set(1);
      this.cargarCargas();
    },
    error: () => this.error.set('No se pudo registrar la carga')
  });
}

gastoTotalPorCamion()

Returns an aggregate cost summary for a single truck — across all loads ever recorded, regardless of date range.
gastoTotalPorCamion(
  camionId: string
): Observable<{
  camion_id: string;
  total_litros: number;
  total_monto: number;
  cantidad_cargas: number;
}>
HTTP request:
GET /combustible/<camionId>/gasto-total
camion_id
string
The truck ID the summary belongs to.
total_litros
number
Total litres of fuel loaded across all records for this truck.
total_monto
number
Total amount spent on fuel for this truck.
cantidad_cargas
number
Number of individual fuel load records for this truck.

Usage example

The component calls gastoTotalPorCamion() whenever a truck filter is active, and stores the result in the gastoTotal signal for display:
if (camionId) {
  this.combustibleService.gastoTotalPorCamion(camionId).subscribe({
    next: (resumen) => this.gastoTotal.set(resumen)
  });
} else {
  this.gastoTotal.set(null);
}
The summary banner in the template then renders it:
@if (gastoTotal()) {
  <div class="resumen">
    <span><strong>{{ gastoTotal()!.cantidad_cargas }}</strong> cargas</span>
    <span><strong>{{ gastoTotal()!.total_litros }}</strong> litros totales</span>
    <span><strong>${{ gastoTotal()!.total_monto }}</strong> gastado</span>
  </div>
}
To see the total spend for a specific truck, pass its camion_id to both listar() and gastoTotalPorCamion(). The list will show the paginated load history, and the summary will show lifetime totals — irrespective of the 30-day filter currently active on the list.
const camionId = 'abc-123';

// Paginated load list (last 30 days by default)
this.combustibleService.listar(camionId, 1, 20).subscribe(/* ... */);

// Lifetime cost summary
this.combustibleService.gastoTotalPorCamion(camionId).subscribe(resumen => {
  console.log(`Total spent: $${resumen.total_monto} across ${resumen.cantidad_cargas} loads`);
});

Linking a Fuel Load to a Trip

The viaje_id field is optional on CargaCombustibleCreate. When a truck is refuelled mid-route or at the start of a trip, supply the trip’s ID to associate the cost directly with that journey:
const carga: CargaCombustibleCreate = {
  camion_id: 'abc-123',
  viaje_id: 'viaje-456',
  litros: 200,
  monto: 50000,
  fecha: '2025-07-10',
};

this.combustibleService.crear(carga).subscribe({
  next: (registro) => console.log('Fuel load linked to trip:', registro.viaje_id),
});
When no trip is in progress or the load is a depot fill unrelated to a specific route, omit viaje_id entirely. The stored record will have viaje_id: null.

How the List Component Works

1

Load trucks on init

ngOnInit fetches all trucks via CamionesService (up to 1 000 records) and builds a Record<string, string> map of camion_id → patente for fast label resolution.
2

Fetch fuel loads

cargarCargas() calls listar() with the current page, page size, truck filter, and the verTodoElHistorico flag. The paginated result is stored in the cargas signal.
3

Show per-truck summary

If a truck filter is active, gastoTotalPorCamion() is also called and the result is shown in the summary banner above the table.
4

Paginate

The <app-paginacion> component handles page navigation. Changing pages re-calls cargarCargas() with the new page number.
5

Register a new load

Clicking + Nueva carga opens a modal. On confirm, crear() is called, the modal closes, and the list resets to page 1 and reloads.
The table displays the truck’s licence plate (patente) rather than its raw UUID. The nombrePatente() helper resolves camion_id against the pre-loaded camionesPorId map. If a truck ID cannot be resolved, it falls back to 'Desconocido'.

Build docs developers (and LLMs) love