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
| Piece | Path |
|---|---|
| Feature module | src/modules/finance/accounting-system/ — AccountingSystemService (CRUD, routing, circuit breaker), AccountingMappingService (chart-of-accounts mapping, Zoho accounts), ErpAgentService (Tally agent protocol) |
| Port | accounting-system.port.ts — ACCOUNTING_SYSTEM_PORT |
| Port implementation | accounting-system.adapter.ts over the Tally and Zoho clients |
| Pushing journals | erp-integration.service.ts, pure builders in erp-journal.util.ts |
| Nightly push | erp-auto-push.scheduler.ts (06:00), erp-push.processor.ts |
| Schema | 55-finance-accounts.prisma (AccountingSystem), ErpAccountMapping and ErpSyncLog in 51-settlement.prisma |
| Admin | Connect and configure: src/components/integrations/connectors/accounting/. Send journals: src/features/settlements/components/erp-*.tsx |
| Agent script | pnxt-admin/public/tools/tally-agent.mjs, downloadable from the Tally system's "Connector agent" tab |
The record
| Field | Meaning |
|---|---|
type | ZOHO_BOOKS or TALLY_PRIME |
pushMode | API, AGENT or FILE_EXPORT (below) |
status | ACTIVE, INACTIVE (a person), SUSPENDED (5 consecutive failed pushes) |
config | Zoho: organizationId, domain. Tally: companyName, endpointUrl. Never secrets |
connectionId | Zoho credentials (client id, secret, refresh token), envelope-encrypted. Tally has none |
legalEntityId | Optional. Books belong to a legal entity |
autoPush | Push new settlement journals at 06:00 |
agentTokenHash | SHA-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.
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
| ERP | Mode | What happens |
|---|---|---|
| Zoho Books | API | The 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 Books | FILE_EXPORT | CSV download for Zoho's manual journal import |
| Tally Prime | API | The API server posts XML to endpointUrl. Only works when that URL is reachable from the PointNXT server |
| Tally Prime | AGENT | Vouchers are queued as ErpSyncLog rows (PENDING, XML in requestPayload); the connector agent on the Tally PC pulls and posts them |
| Tally Prime | FILE_EXPORT | XML 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.
@PublicRoutewith their own bearer token, throttled, and run in the system's tenant context after authentication. The system must beACTIVEand inAGENTmode, otherwise 403. - Claiming. Up to 10 batches per poll. A batch claimed but not reported within 15 minutes is offered again.
- Results.
SUCCESSorFAILEDwith Tally's response; the XML is dropped from the log once reported. Failures feed the circuit breaker. - Agent script.
tally-agent.mjsneeds Node.js 18+,PNXT_API_URLandPNXT_AGENT_TOKEN; optionalTALLY_URL(defaulthttp://localhost:9000) andPOLL_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:
| Method | Path | Permission | Notes |
|---|---|---|---|
GET | / | SETTLEMENT:READ | No secrets, no token hash |
GET | /:id | SETTLEMENT:READ | |
POST | / | SETTLEMENT:UPDATE | { type, name, code?, pushMode, legalEntityId?, autoPush?, config?, credentials? } |
PUT | /:id | SETTLEMENT:UPDATE | Settings, status, credentials |
DELETE | /:id | SETTLEMENT:UPDATE | Soft delete; credentials and agent token removed |
GET/PUT | /:id/mappings | SETTLEMENT:READ / UPDATE | Chart-of-accounts mapping |
GET | /:id/zoho-accounts | SETTLEMENT:READ | Zoho chart of accounts with stored credentials |
POST | /:id/agent-token | SETTLEMENT:UPDATE | New 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
| Symptom | Likely 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 log | Tally ledger name in the mapping does not exist in the company |
| System shows Suspended | Five pushes in a row failed; fix the cause, then turn it on in Integrations |