Created: 18.01.2026
Goal: Enable users to upload/send outgoing invoices (Accounts Receivable) to Orcha for processing, tracking, and management alongside existing Accounts Payable functionality.
Scope:
Why: Complete financial document management requires tracking both incoming (AP) and outgoing (AR) invoices. This enables:
| Aspect | Accounts Payable (Current) | Accounts Receivable (New) |
|---|---|---|
| Direction | Received FROM suppliers | Sent TO customers |
| We are | Recipient/Buyer | Issuer/Seller |
| Key party | Issuer (supplier) | Recipient (customer) |
| Payment focus | When WE need to pay | When CUSTOMER should pay |
| Validation | Validate supplier VAT | Validate our VAT matches tenant |
| Cost center | Assign to cost center | Not applicable |
| Accruals | Expense accrual | Revenue recognition |
| GL accounts | Expense accounts | Revenue accounts |
document_type Enum (Recommended)-- Current enum
CREATE TYPE document_type AS ENUM ('invoice');
-- New enum
CREATE TYPE document_type AS ENUM ('invoice', 'ar-invoice');
-- OR more explicit:
CREATE TYPE document_type AS ENUM ('ap-invoice', 'ar-invoice');
ALTER TABLE document ADD COLUMN invoice_direction TEXT; -- 'incoming' | 'outgoing'
The existing StructuredData schema can be reused, but field interpretation differs:
| Field | AP Interpretation | AR Interpretation |
|---|---|---|
issuer |
Supplier (external) | Our company (should match tenant) |
recipient |
Our company | Customer (external) |
cost-center |
Assign expense | N/A for AR |
service-category |
Categorize expense | Categorize revenue |
bu-code |
DATEV expense code | DATEV revenue code (if applicable) |
com.getorcha.erp.ingestion)queue-for-ingestion! can handle AR invoicescom.getorcha.workers.ingestion.extraction)com.getorcha.workers.ingestion.validation)check-issuer-matches-tenant - For AR, issuer should match tenant company infocheck-recipient-country becomes more critical for AR (customer location)com.getorcha.workers.ingestion.post-process)AccountsMatcher - Required for revenue account matching (load revenue accounts dataset)TaxComplianceAnalyzer - Still relevant, adapt for issuer perspectiveUncertainValidationsResolver - Still applicableAccrualsMatcher - Adapt for revenue recognitionCostCenterMatcher - Not applicable for revenuelayout.clj);; Current structure:
[:li "Accounts Payable"]
[:li "Settings"]
;; New structure:
[:li "Accounts Payable"]
[:li "Accounts Receivable"] ;; NEW - between AP and Settings
[:li "Settings"]
/ar or /receivables - AR list page/ar/:document-id - AR detail page/ar/upload - AR upload endpoint/ar/events - AR SSE eventsSimilar to AP list but with adapted columns:
| AP Column | AR Column |
|---|---|
| Supplier | Customer |
| Total Amount | Invoice Amount |
| Due Date | Payment Due |
| Status | Status |
| Validation | Validation |
Additional AR-specific columns (future):
Swap emphasis of issuer/recipient:
AP Detail Panel:
AR Detail Panel:
Remove/Hide for AR:
Add for AR:
ar-invoice to document_type enum (migration)ar-invoice)AccountsMatcher to use revenue accounts for ARAccrualsMatcher for revenue recognitionManual Upload:
Email Ingestion:
| Processor | Run for AR? | Notes |
|---|---|---|
| AccountsMatcher | ✅ | Required - use revenue accounts dataset |
| CostCenterMatcher | ❌ | Not applicable for revenue |
| AccrualsMatcher | ✅ | Adapt for revenue recognition |
| TaxComplianceAnalyzer | ✅ | Adapt for issuer perspective |
| UncertainValidationsResolver | ✅ | Still needed |
Requirement: Validate that AR invoice issuer matches one of the tenant's legal entities.
Approach: Reuse existing multi-entity support from AP:
Decision: Extend document_type enum with ar-invoice value.
Decision: Reuse existing extraction prompt.
Requirement: Support revenue account matching for AR line items.
Implementation:
AccountsMatcher runs for AR with revenue account configurationmigrations/YYYYMMDD-add-ar-invoice-type.up.sql - Extend enum| File | Change |
|---|---|
erp/ui/layout.clj |
Add AR nav item |
erp/http/documents.clj |
New AR routes and handlers (or parameterize existing) |
erp/http/routes.clj |
Register AR routes |
workers/ingestion/validation.clj |
Add issuer-tenant validation (reuse multi-entity logic) |
workers/ingestion.clj |
Skip cost center for AR, run revenue account matching |
workers/ingestion/post-process/accounts.clj |
Support revenue accounts dataset |
workers/acquisition/triage.clj |
Add AP/AR classifier after extraction |
schema/structured_data.clj |
No changes needed (schema is direction-agnostic) |
| Risk | Mitigation |
|---|---|
| Confusion between AP/AR | Clear UI labeling, separate navigation |
| Wrong classification | Allow reclassification, clear error messages |
| Extraction errors for AR | Monitor quality, adjust prompt if needed |
| Performance impact | Separate processing queues if needed |