HubfiscalAggregateSales
Description
Section titled “Description”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 (FESH10comes afterFESH9). - 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.
Configuration
Section titled “Configuration”| Field | Type | Required | Description |
|---|---|---|---|
| credentials_id | credentials | Yes | Hub Fiscal MySQL/MariaDB credential (sqlQuery type) |
| date | text | No | Date to post, YYYY-MM-DD. Accepts {{...}} variables. If empty, yesterday (Madrid time) is used |
| simular | select | No | Yes (default): only compute and show. No: create the batches and link the documents |
| timeout | text | No | Connection 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.
Which documents are included
Section titled “Which documents are included”Only those meeting all three conditions:
- Status
completed. - No journal entry yet.
- Issued on the given date.
How they are grouped
Section titled “How they are grouped”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.
| Group | Invoice | Credit note | Invoice / credit note series |
|---|---|---|---|
| equivalenza.com | ES_FAC | ES_ABO | FESH / AESH |
| equivalenza.com + Canary Islands | CA_FAC | CA_ABO | FCAH / ACAH |
| equivalenza.it | IT_FAC | IT_ABO | FITH / AITH |
| equivalenza.fr | FR_FAC | FR_ABO | FFRH / AFRH |
| equivalenza.pt | PT_FAC | PT_ABO | FHPT / 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).
What is left out
Section titled “What is left out”A document that cannot be grouped is never posted silently: it appears in the omitidos list with its reason and is logged.
| Reason | Meaning |
|---|---|
sin_portal | The portal of the document could not be determined |
portal_sin_regla | The portal has no group defined |
tipo_sin_regla | The type is neither invoice (FT) nor credit note (NC) |
sin_numero | It is completed but has no invoice number |
numero_no_numerico | The 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).
Output
Section titled “Output”{ "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"}batchesholds one item per journal entry. It is the list the Iterator node loops over.payloadis the entry’s JSON, as text, ready for theobject_xmlfield of SageX3Soap with{{payload}}.batch_idisnullin simulation and the batch identifier when writing.reintento: truemarks 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.
Process safety
Section titled “Process safety”- 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 (
seq2) 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.
Requirements
Section titled “Requirements”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.
Typical Flow
Section titled “Typical Flow”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}}) → EndThe «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: 0without error; use a following decision to end the flow. - A
completeddocument without an invoice number (for example, a Bill.pt credit note) is reported inomitidos; 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.
Related Nodes
Section titled “Related Nodes”- HubfiscalLogSageBatch - Stores Sage’s result in the batch and the documents
- SageX3Soap - Sends each entry to Sage X3
- HubfiscalStoreShopify - Registers the order and assigns portal and numbering
- HubfiscalCreateDocument - Registers the document in Hub Fiscal