Skip to main content
The TMT Platform generates digital invoices (facturas electrónicas) that comply with Venezuelan fiscal regulation. Every completed ticket sale triggers an invoice through the TFHKA API — a certified Venezuelan digital billing provider — and the result is stored in Firestore alongside the original order.

How billing works

Invoices are generated in two contexts:
  • Order billing — triggered automatically after a ticket sale completes. The process_order_billing function enriches the order with purchaser and client data, then emits an invoice. The resulting billing_info object is written back to the orders document.
  • Expense billing — triggered manually via generateBillingFromExpenses. Used to issue invoices for operational expenses (e.g. production costs, logistics) tied to an event. The result is stored independently in the event_invoices collection.

What data goes into an invoice

Each invoice is built from three sources:
SourceData used
Order / expense recordTicket quantities, zones, amounts, currency, payment methods
u_clients documentBuyer identity (TipoIdentificacion, NumeroIdentificacion, RazonSocial, address, email)
data/exchange_ratesUSD → BSD conversion rate applied to all monetary fields
Invoice numbers are assigned sequentially using a Firestore transaction on the data/invoice_counter document. This guarantees no two invoices share the same number, even under concurrent load.

Tax calculations

Every invoice includes Venezuelan taxes computed from the order totals:
  • IVA (16%) — applied to the pre-tax subtotal on all invoices.
  • IGTF (3%) — applied when payment was made in foreign currency (Zelle, Efectivo Dólares, or Efectivo Divisa). The IGTF base is the lesser of the total-with-IVA or the amount paid in foreign currency.
All monetary values are expressed in BSD (bolívares) as the primary currency, with a TotalesOtraMoneda block carrying the equivalent USD amounts at the recorded exchange rate.

What is stored after a successful invoice

For expense invoices, a document is created in event_invoices/{numeroDocumento} with:
FieldDescription
invoice_idThe numeroDocumento returned by TFHKA
event_idThe event the invoice belongs to
client_idThe client derived from the event
expense_typeThe expense category passed in the request
currencyThe currency of the expense (USD or BSD)
billed_itemsArray of expense line items
created_atServer timestamp
api_responseFull raw response from the TFHKA API
statusAlways "EMITTED" on successful creation
For order invoices, the TFHKA response is stored inside orders/{order_id} under the billing_info field.
The TFHKA integration currently points to the demo environment (demoemisionv2.thefactoryhka.com.ve). Update BASE_URL, USER, and PASSWORD in billing.js before going to production.

Subsections

Digital Invoicing

Complete reference for billing_emision and generateBillingFromExpenses, the internal invoice generation flow, the full DocumentoElectronico structure, and Firestore storage details.

Build docs developers (and LLMs) love