Skip to main content

Accounting systems

An AccountingSystem is one set of books: a Zoho Books organisation or a Tally Prime company. It is connected from Integrations → App Directory → Accounting, like a channel or courier, and owns its IntegrationConnection when it has credentials. Settlement journals are then posted to it from Settlements → Accounting sync, or every night. See ADR-0004 for why.

This page covers the connection and delivery. Journal building (chart of accounts, voucher layout) is described in Settlements; the XML and REST details are on Tally Prime and Zoho Books.

Code map​

PiecePath
Feature modulesrc/modules/finance/accounting-system/ — AccountingSystemService (CRUD, routing, circuit breaker), AccountingMappingService (chart-of-accounts mapping, Zoho accounts), ErpAgentService (Tally agent protocol)
Portaccounting-system.port.ts — ACCOUNTING_SYSTEM_PORT
Port implementationaccounting-system.adapter.ts over the Tally and Zoho clients
Pushing journalserp-integration.service.ts, pure builders in erp-journal.util.ts
Nightly pusherp-auto-push.scheduler.ts (06:00), erp-push.processor.ts
Schema55-finance-accounts.prisma (AccountingSystem), ErpAccountMapping and ErpSyncLog in 51-settlement.prisma
AdminConnect and configure: src/components/integrations/connectors/accounting/. Send journals: src/features/settlements/components/erp-*.tsx
Agent scriptpnxt-admin/public/tools/tally-agent.mjs, downloadable from the Tally system's "Connector agent" tab

The record​

FieldMeaning
typeZOHO_BOOKS or TALLY_PRIME
pushModeAPI, AGENT or FILE_EXPORT (below)
statusACTIVE, INACTIVE (a person), SUSPENDED (5 consecutive failed pushes)
configZoho: organizationId, domain. Tally: companyName, endpointUrl. Never secrets
connectionIdZoho credentials (client id, secret, refresh token), envelope-encrypted. Tally has none
legalEntityIdOptional. Books belong to a legal entity
autoPushPush new settlement journals at 06:00
agentTokenHashSHA-256 of the Tally agent token; the token is shown once

One active system per legal entity (or per "no entity") and ERP is allowed.

Which system gets a settlement​

AccountingSystemService.resolveForSettlement follows Settlement → Channel → Seller → LegalEntity, then picks the active system of the ERP type with that legal entity, falling back to the active system without an entity.

Single entity in the admin today

The admin exposes one legal entity per tenant and does not offer a legal-entity picker, so systems are created without one and keep every entity's books. The API accepts legalEntityId for when multi-entity setup is added.

Push modes​

ERPModeWhat happens
Zoho BooksAPIThe API posts a manual journal per settlement with the stored credentials. Every account code needs a Zoho account id in the mapping, or the push is refused with the missing codes
Zoho BooksFILE_EXPORTCSV download for Zoho's manual journal import
Tally PrimeAPIThe API server posts XML to endpointUrl. Only works when that URL is reachable from the PointNXT server
Tally PrimeAGENTVouchers are queued as ErpSyncLog rows (PENDING, XML in requestPayload); the connector agent on the Tally PC pulls and posts them
Tally PrimeFILE_EXPORTXML download for Tally's Import Data

Zoho credentials are verified by reading the organisation's chart of accounts before they are stored. They are pasted once (client id, secret, refresh token from a Zoho self client); there is no OAuth redirect flow yet.

Tally connector agent​

The agent is for the common case: Tally on an office PC that the API cannot reach. All traffic is outbound from the PC.

  • Token. pnxt_tally_<systemId>_<random>. Only its SHA-256 is stored, compared in constant time. Issuing a new token revokes the old one. Deleting the system clears it.
  • Endpoints. @PublicRoute with their own bearer token, throttled, and run in the system's tenant context after authentication. The system must be ACTIVE and in AGENT mode, otherwise 403.
  • Claiming. Up to 10 batches per poll. A batch claimed but not reported within 15 minutes is offered again.
  • Results. SUCCESS or FAILED with Tally's response; the XML is dropped from the log once reported. Failures feed the circuit breaker.
  • Agent script. tally-agent.mjs needs Node.js 18+, PNXT_API_URL and PNXT_AGENT_TOKEN; optional TALLY_URL (default http://localhost:9000) and POLL_SECONDS (default 60). It is a reference implementation; running it as a Windows service is left to the customer.

Nightly auto-push​

At 06:00 (after settlement and gateway syncs) the scheduler queues one erp-push job per ACTIVE system with autoPush on and a mode other than FILE_EXPORT. The job pushes up to 50 settlements that have journal entries, no SUCCESS/PENDING/IN_PROGRESS log for this system, and whose books this system keeps. One settlement failing does not stop the rest.

Chart-of-accounts mapping​

Stored per system (ErpAccountMapping.accountingSystemId). For each PointNXT account code, Tally needs the exact ledger name; Zoho needs an account id, picked from the organisation's chart of accounts once credentials are stored. Unmapped codes fall back to the default ledger names.

API surface​

Under /v1/finance/accounting-systems, @TenantScoped(), audit-logged mutations:

MethodPathPermissionNotes
GET/SETTLEMENT:READNo secrets, no token hash
GET/:idSETTLEMENT:READ
POST/SETTLEMENT:UPDATE{ type, name, code?, pushMode, legalEntityId?, autoPush?, config?, credentials? }
PUT/:idSETTLEMENT:UPDATESettings, status, credentials
DELETE/:idSETTLEMENT:UPDATESoft delete; credentials and agent token removed
GET/PUT/:id/mappingsSETTLEMENT:READ / UPDATEChart-of-accounts mapping
GET/:id/zoho-accountsSETTLEMENT:READZoho chart of accounts with stored credentials
POST/:id/agent-tokenSETTLEMENT:UPDATENew Tally agent token, shown once

Journals, under /v1/finance/settlement/erp: GET /:systemId/tally/export, POST /:systemId/tally/push, GET /:systemId/zoho/export-csv, POST /:systemId/zoho/push, GET /sync-logs?accountingSystemId=. Agent: GET /v1/finance/erp-agent/vouchers, POST /v1/finance/erp-agent/vouchers/:id/result. Platform admins read a tenant's systems at GET /v1/finance/admin/accounting-systems?tenantId=.

Registry rows ZOHO_BOOKS and TALLY_PRIME (category accounting) are in integration-registry.seed.ts.

Failure modes​

SymptomLikely cause
Connecting Zoho returns 422 "Zoho Books rejected the credentials"Wrong client/secret/refresh token, wrong data centre domain, or wrong organisation id
"Map these accounts to Zoho Books accounts first: …"Zoho account ids missing in the mapping for those codes
Tally batches stay "Waiting for agent"Agent not running, wrong token, or system not in AGENT mode. Check "Agent last checked in" on the system
Tally push fails "Failed to connect to Tally Prime at …"API mode with an endpoint the server cannot reach: use the agent
"Ledger not found" in the logTally ledger name in the mapping does not exist in the company
System shows SuspendedFive pushes in a row failed; fix the cause, then turn it on in Integrations