manicanldes-backend/docs/b2b-partner-reporting-api.md

2.5 KiB

B2B partner reporting (Phase 3J)

GET /api/v1/b2b/accounts/:id/report requires a bearer session and the dedicated b2b.report.read permission. The account must belong to the caller's organization; missing or out-of-scope accounts return 404. A report is available even when an account has no orders or is not verified, so staff can inspect its history.

The response contains accountId and a currencies array sorted by currency code. Each currency contains:

Field Meaning
orderCount All partner orders, including cancelled orders
activeOrderCount Orders without cancellation
cancelledOrderCount Orders with a recorded cancellation
unpaidOrderCount Active orders with no unreversed receipts
partiallyPaidOrderCount Active orders paid above zero but below merchandise total
paidOrderCount Active orders with merchandise fully paid
merchandiseTotal Total merchandise value of active orders
paidTotal Unreversed receipts against active orders
outstandingTotal Active merchandise value minus unreversed receipts

All amounts are exact decimal strings with two fractional digits. Different currencies are never combined or converted. Each order contributes once regardless of how many receipts it has. Reversals restore outstanding balances; cancelled orders retain their counts but contribute no financial totals. An account with no orders returns { "accountId": "<uuid>", "currencies": [] }.

Reports cover all recorded history. A repeatable-read transaction provides a consistent account lookup and aggregate. Reads create no audit events and change no order/payment records. This is a merchandise-balance report; it does not establish credit utilization, overdue status, tax, shipping, refunds, gateway settlement, or accounting receivables.

The permission migration grants access to existing system Owner roles. Custom roles need an explicit RBAC grant. No schema, provider, or configuration change is required beyond deploying the append-only permission migration. Removing a custom role's report permission disables access; financial records remain intact.