Settlement Ingestion & Reconciliation Lifecycle
End-to-End Workflow
The settlement and financial reconciliation pipeline transitions transactions through six core states:
1. Ingestion Channels & Triggers
Settlements enter the system via two distinct mechanisms:
A. Automated Daily Sync
- Scheduler: Runs automatically via
SettlementReconciliationScheduler(cron0 2 * * *) and periodic interval syncs onAPP_BULL_QUEUES.SYNC. - API Fetch: For platforms with direct financial APIs (e.g. Amazon SP-API Finances API), the system automatically polls for finalized disbursement cycles without manual user intervention.
B. Manual File Upload
- Endpoints:
POST /v1/finance/settlement/importfor settlement reports;POST /v1/finance/settlement/import/fbafor the Amazon FBA Inventory Adjustments and Customer Returns reports (kind). - Supported Formats:
.csv,.tsv,.txt,.xlsx - Supported Providers: Amazon Settlement Flat File V2, Flipkart Settlement File, Meesho Payout Flat File, Shopify Balance Settlement CSV. COD remittances and gateway files have their own endpoints.
- Handling: The file is uploaded through the API (upload purpose
settlement-imports), anImportBatchis created, and a jobuploadis queued onAPP_BULL_QUEUES.SETTLEMENT. The API returns the batch at once.
2. Processing & Parsing Rules
The background worker in SettlementImportProcessor routes the file to its corresponding parser:
- Amazon Parser (
AmazonSettlementFileParser/AmazonFinancesApiAdapter):- Extracts
Order,Refund, andOtherTransactionlines. - Maps fee codes:
Commission,ShippingChargeback,GiftwrapChargeback,VariableClosingFee,PickPackFee,TCS, andTDS.
- Extracts
- Flipkart Parser (
FlipkartSettlementFileParser):- Extracts order items, marketplace fees, customer shipping fees, pick-and-pack charges, and reverse shipping fees.
- Meesho Parser (
MeeshoSettlementFileParser):- Handles Meesho net settlement structures, waiver credits, and penalty adjustments.
- Shopify Parser (
ShopifySettlementFileParser):- Parses payment gateway fees, refunds, adjustments, and payouts.
Idempotency & Deduplication
- File deduplication: an upload is hashed (SHA-256 of the bytes) and an
ImportBatchwith the same hash for the channel is returned instead of queuing a second parse. - Payout identity: a payout is unique on
(tenantId, source, partnerId, externalPayoutId); a re-import adds lines to the same payout. - Line deduplication: every line carries a
dedupeHash; re-importing the same report inserts nothing. A partner that restates a line produces a new line with the sameidentityKey, and the old line is markedsupersededById(lines are never updated).
3. Auditing Rules & Tolerances
Once transactions are normalized, the SettlementFeeAuditorService audits each line against configured rate cards:
| Audit Check | Tolerance Rule | Failure Behavior |
|---|---|---|
| Marketplace Commission | Configurable slab tolerance (default ₹0.50 or 0.1%) | Flags PlatformFeeCategory.COMMISSION as OVERCHARGED; auto-generates claim line |
| Freight & Weight Audit | Compared against courier billing weight vs warehouse captured volumetric weight (L * W * H / 5000) | Flags weight discrepancy if billed weight exceeds captured weight by more than 50g |
| RTO Reverse Shipping | Strict ₹0.00 allowance. If isRtoOrder === true, reverse fee must be 0 | Automatically flags PlatformFeeCategory.REVERSE_SHIPPING as OVERCHARGED with dispute reason |
| Marketplace charges | Lines with no order (subjectType ACCOUNT, SKU, INBOUND_SHIPMENT…) carry their own category (advertising, storage, subscription) | Posted to their own expense ledgers; never part of an order's receivable. A person can correct a line's category, which re-posts the payout's journal |
4. Journal Vouchers
Every payout (marketplace, COD or gateway) gets balanced vouchers from SettlementJournalService. The database refuses an unbalanced voucher at commit.
- Sales Credit
4000 Marketplace Sales - Commission, shipping, closing and fulfilment fees Debit
5000–5050 - GST TCS (s.52) Debit
1300 TCS Receivable(claimed on the GST portal) - Income-tax TDS (s.194-O) Debit
1310 TDS Receivable(claimed against Form 26AS) - Net payout Debit the source's clearing account:
1120marketplace,1121COD,1122gateway
A payout spanning months posts each month's lines in that month and carries the balance through 1250. When lines change, posted vouchers are reversed and fresh ones posted. See Settlements → Journal and ERP.
5. Bank Statement UTR Allocation
When a bank statement is imported for a bank account:
- Each credit whose reference is a payout's UTR or id, and whose amount equals what those payouts should bank, is allocated at once.
- A person allocates the rest, splitting one credit across payouts of any source.
- Tolerance: allocations must add up to the credit within ₹1.00.
- Each payout's
bankAllocatedandbankStatus(UNMATCHED,PARTIAL,MATCHED) follow its allocations.
6. Direct ERP Export & Push
Vouchers are pushed per payout, per voucher or per date range; one already sent to a system is skipped:
- Tally Prime: Direct HTTP push to port
9000or XML download (Tally Prime Guide). - Zoho Books: Direct OAuth REST API journal creation or CSV export (Zoho Books Guide).