Skip to main content
Office metric functions let you understand how individual sales offices (taquillas) are performing across an event. They draw from the orders and orders_transactions PostgreSQL tables and from Firestore office documents. All functions accept a JSON body with a top-level data key.

sold_by_office

Returns ticket sales and revenue grouped by office name. Queries the orders PostgreSQL table and aggregates ticket counts (via json_array_length(tickets::json)) and total revenue per office.

Request parameters

data.event_id
string
Filter results to a specific event.
data.from
string
Start date in YYYY-MM-DD format. Matches records where date_created >= from.
data.to
string
End date in YYYY-MM-DD format. Matches records where date_created <= to.

Example request

{
  "data": {
    "event_id": "evt_9kXp2",
    "from": "2024-03-01",
    "to": "2024-03-31"
  }
}

Response

data.office_sold
array
One entry per office that recorded sales matching the filters.
data.total_tickets
number
Sum of total_sales across all offices in the result.
data.total_amount
number
Sum of total_amount across all offices in the result.

Example response

{
  "message": "Datos cantidad de tickets vendidos por taquillas ",
  "status": 200,
  "data": {
    "office_sold": [
      {
        "event_id": "evt_9kXp2",
        "event_name": "Festival de Verano 2024",
        "office_name": "Taquilla Central",
        "total_sales": 180,
        "total_amount": 4500.00
      },
      {
        "event_id": "evt_9kXp2",
        "event_name": "Festival de Verano 2024",
        "office_name": "Taquilla Norte",
        "total_sales": 132,
        "total_amount": 3300.00
      }
    ],
    "total_tickets": 312,
    "total_amount": 7800.00
  }
}
total_sales in the per-office array is a ticket count, not a transaction count. One order may contain multiple tickets.

offices_vs_offices_active

Counts how many offices are assigned to a specific event and breaks that count down into active and inactive offices. The function reads the offices Firestore collection and checks each office’s events subcollection for the given event_id.
This function iterates over every document in the offices collection and issues one subcollection query per office. Response time scales linearly with the total number of offices on the platform.

Request parameters

data.event_id
string
required
The event to check. Each office’s events subcollection is queried for a document with id == event_id.

Example request

{
  "data": {
    "event_id": "evt_9kXp2"
  }
}

Response

data.result
array
Single-element array with the office count breakdown.

Example response

{
  "message": "Datos cantidad de taquillas vs taquillas activas ",
  "status": 200,
  "data": {
    "result": [
      {
        "total": 10,
        "total_activas": 8,
        "total_inactivas": 2
      }
    ]
  }
}
An office is counted toward this event only if a document exists in offices/{officeId}/events with id == event_id. Offices not assigned to the event are excluded entirely.

sold_by_usbs

Returns sales made through USB/offline devices, broken down by office and currency. Queries the orders_transactions PostgreSQL table, grouping by event_id, office_name, event_name, and amount_currency. Uses amount_exchange (the local-currency equivalent) rather than the base amount.

Request parameters

data.event_id
string
Filter to a specific event.
data.from
string
Start date in YYYY-MM-DD format.
data.to
string
End date in YYYY-MM-DD format.

Example request

{
  "data": {
    "event_id": "evt_9kXp2",
    "from": "2024-03-01",
    "to": "2024-03-31"
  }
}

Response

data.office_sold
array
One entry per office/currency combination with USB sales.
data.total_amount_usd
number
Sum of all total_amount values where amount_currency == "USD".
data.total_amount_bs
number
Sum of all total_amount values where amount_currency == "VEF".

Example response

{
  "message": "Datos ventas",
  "status": 200,
  "data": {
    "office_sold": [
      {
        "event_id": "evt_9kXp2",
        "event_name": "Festival de Verano 2024",
        "office_name": "Taquilla Central",
        "amount_currency": "USD",
        "total_amount": 1200.00
      },
      {
        "event_id": "evt_9kXp2",
        "event_name": "Festival de Verano 2024",
        "office_name": "Taquilla Central",
        "amount_currency": "VEF",
        "total_amount": 45000.00
      }
    ],
    "total_amount_usd": 1200.00,
    "total_amount_bs": 45000.00
  }
}
sold_by_usbs uses amount_exchange — the exchanged local-currency amount — rather than the base amount. This is useful when comparing multi-currency USB sales in a common denomination.

Build docs developers (and LLMs) love