Skip to content

HubfiscalAggregateSales

Takes the Hub Fiscal documents in completed status for one day that have not been posted yet, groups them by portal and by type (invoice or credit note) and prepares one journal entry per group to send to Sage X3. A normal day produces 3 to 5 entries, never one entry per document.

It is the first piece of the daily Hub Fiscal → Sage X3 posting process: this node computes and stores the batches, the SageX3Soap node sends them and HubfiscalLogSageBatch stores the result.

Key features:

  • One document, one entry: every document is posted only once. The database guarantees it even if the process is launched several times or at the same time.
  • Net amount, without VAT, summed in cents (no rounding errors). Sage applies VAT using the group’s code.
  • First and last invoice number of each group (TCKINI / TCKFIN), ordered by the numeric sequence (FESH10 comes after FESH9).
  • Simulation mode: computes and shows the entries without writing anything. It is the default.
  • Automatic resend: batches of the day that did not reach Sage correctly are returned again to be resent.
FieldTypeRequiredDescription
credentials_idcredentialsYesHub Fiscal MySQL/MariaDB credential (sqlQuery type)
datetextNoDate to post, YYYY-MM-DD. Accepts {{...}} variables. If empty, yesterday (Madrid time) is used
simularselectNoYes (default): only compute and show. No: create the batches and link the documents
timeouttextNoConnection timeout in ms. Default: 30000

There is no fixed cut-off date: the date is a parameter and gives you exact control over what gets posted.

Only those meeting all three conditions:

  1. Status completed.
  2. No journal entry yet.
  3. Issued on the given date.

The key is the sales portal, not the destination country: an equivalenza.it order shipped to Switzerland is posted with Italy. Within equivalenza.com, the Canary Islands are split off when the postal code of the shipping address starts with 35 or 38.

GroupInvoiceCredit noteInvoice / credit note series
equivalenza.comES_FACES_ABOFESH / AESH
equivalenza.com + Canary IslandsCA_FACCA_ABOFCAH / ACAH
equivalenza.itIT_FACIT_ABOFITH / AITH
equivalenza.frFR_FACFR_ABOFFRH / AFRH
equivalenza.ptPT_FACPT_ABOFHPT / AHPT (Bill.pt)

Credit notes (NC) go in their own entry, with a positive amount; the sign is set by Sage’s entry type.

The payload of each entry is built from the agreed layout for the Sage X3 XX6AISTG service (FTC object), filling in four values: group date (VCRDAT, YYYYMMDD), first and last invoice number (TCKINI, TCKFIN) and the net amount (GROPRI and IMPORTE).

A document that cannot be grouped is never posted silently: it appears in the omitidos list with its reason and is logged.

ReasonMeaning
sin_portalThe portal of the document could not be determined
portal_sin_reglaThe portal has no group defined
tipo_sin_reglaThe type is neither invoice (FT) nor credit note (NC)
sin_numeroIt is completed but has no invoice number
numero_no_numericoThe number has no digits to compute the first and last one

It needs no input data: it reads from the Hub Fiscal database. The date can come from a variable (for example, {{fecha}} from a previous node).

{
"success": true,
"date": "2026-10-12",
"simulated": true,
"documents": 74,
"batch_count": 4,
"batches": [
{
"batch_id": null,
"group_key": "ES_FAC",
"seq": 1,
"doc_count": 12,
"total_net": "471.82",
"ticket_ini": "FESH1",
"ticket_fin": "FESH12",
"sage_doc_origin": "TPE01",
"payload": "{\"XX6AISW0_1\":{...},\"XX6AISW1_1\":{...},...}",
"reintento": false,
"simulated": true
}
],
"omitidos": [],
"message": "[SIMULACIÓN] 2026-10-12: 74 documentos → 4 asientos nuevos"
}
  • batches holds one item per journal entry. It is the list the Iterator node loops over.
  • payload is the entry’s JSON, as text, ready for the object_xml field of SageX3Soap with {{payload}}.
  • batch_id is null in simulation and the batch identifier when writing.
  • reintento: true marks a batch of that day that was not sent correctly and comes out again.

The message text and the omitidos / reintento field names are in Spanish, as they appear in the product.

  • Simulation by default: use it until the amounts match. In simulation no batch is created and no document is linked.
  • Regression guard: if more entries than possible groups (10) came out, or if the input documents did not match the posted plus omitted ones, the node stops with an error.
  • Late documents: a document of day D that arrives after D was run is neither lost nor posted on its own. If date D is run again, it forms a second batch (seq 2) and the first one is left untouched.
  • Simultaneous runs: if two runs overlap on the same day, one creates the entry and the other fails without duplicating anything.

The Hub Fiscal database needs the portal and zone columns in documents, the document_sequences and portal_providers tables, and the batch tables sage_batches and sage_batch_documents. If any are missing, the node stops and tells you which SQL files to apply.

Documents must have a portal and a number: the entry nodes HubfiscalStoreShopify and HubfiscalCreateDocument do this with the Number and complete option.

Daily cron → HubfiscalAggregateSales
→ Decision (any entries?)
→ Iterator (loop over entries)
→ Decision (real send?, not a simulation)
→ SageX3Soap (save, XX6AISTG, object_xml = {{payload}})
→ HubfiscalLogSageBatch (batch_id = {{batch_id}})
→ End

The «real send?» decision prevents a simulation from ever calling Sage.

  • If Sage fails on an entry, the batch stays pending and is resent on the next run of the same day; its documents are already linked to it and do not come back as new.
  • On a day with no sales the node returns batch_count: 0 without error; use a following decision to end the flow.
  • A completed document without an invoice number (for example, a Bill.pt credit note) is reported in omitidos; it does not block the rest. Check it in the fiscal provider, because without a number the group’s first and last ticket cannot be set.