Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Reimbursements as a First-Class Carbon Document — implementation plan
Spec (data model): .ai/specs/implemented/2026-09-23-reimbursements-first-class.md
Spec (shared shape): .ai/specs/2026-09-23-editable-imported-spend-documents.md
Research: .ai/research/2026-09-22-sap-grade-ap-ar-document-model.md
Branch: rillet-ramp-accounting-provider
The model: imported, then editable — never hand-created. The Ramp sync is the only thing that brings a reimbursement into existence, so there is no create form and no
newroute. But an imported reimbursement lands Draft (the sync no longer auto-posts) and is editable while Draft — header fields and coding lines, including adding and removing lines — then a human Posts it. The detail surface is a full page with read and edit modes, carries a SOURCE badge (provider logo + name + external id), and guards the header-total-equals-line-sum invariant before Post. A Posted row is immutable.The sync CREATES; it never re-writes an existing document. Once a row exists in Carbon, Carbon's copy is authoritative and no later sync run touches its header or its lines. Accepted cost, stated in the spec: a provider-side correction made after import does not flow through. There is no activity/timeline surface — Carbon has no generic activity table, the audit log is the real history, and the SOURCE badge carries provenance on its own.
If a task below seems to want a create form or a
newroute, it is the wrong task — STOP and report.
Line dimensions go through the EXISTING
DimensionSelector. The shared spec (commitf821ddf9c2) reversed the earlier "defer the wider dimension set" decision. Do not build a picker per concept (Department, Location, Supplier, Item, Customer, Employee, Work Center, Process, Item Posting Group) — reuseapps/erp/app/modules/accounting/ui/JournalEntries/DimensionSelector.tsx, which already renders the company's configured dimensions generically, colours each entity type, and serves the high-cardinality ones (Customer, Supplier, Item) from the client stores through a searchable virtualized Combobox. It already covers Project and CostCenter as entity types, which is why this plan has no Project-picker task.That reverses the spec's earlier "v1 needs no migration" claim:
DimensionSelectorworks in{dimensionId, valueId}pairs, so Task 1 adds a genericreimbursementLineDimensionchild table mirroringjournalLineDimension. The legacyreimbursementLine.costCenterId/projectIdcolumns stay — the Ramp sync writes them and posting reads them — and Task 9's posting pass unions both sources, de-duplicating bydimensionId. Consolidating onto the generic table alone is a documented follow-up, not this plan's work.
Ask-First gate. The spec flags three Ask-First items (new tables, new edge function, Ramp rework) as autonomously resolved, awaiting veto. Do not start Task 1 until the user has confirmed. If no confirmation is on record, STOP and ask — do not improvise.
Universal rule for every task in this plan. After ANY
pnpm exec turbo …command, rungit status --short packages/database/and revert generated-artifact churn:git checkout -- packages/database/src/types.ts packages/database/src/swagger-docs-schema.ts packages/database/supabase/functions/lib/types.tsThe ONLY exception is Task 2, where
pnpm run generate:typesregenerates those files deliberately and they must be committed. (.ai/lessons.md— "Turbo typecheck/test runs can regenerate@carbon/databaseartifacts as ride-along churn".)
Never a whole-repo typecheck. Only
pnpm exec turbo run typecheck --filter=erp,--filter=@carbon/ee,--filter=@carbon/jobs.
Path correction, carried forward. Both specs say the Ramp reimbursement syncer is
ramp-sync-reimbursement.tsnearpackages/ee/src/ramp/lib/suppliers.ts. It is not. The real file ispackages/jobs/src/inngest/functions/integrations/ramp-sync-reimbursement.ts(788 lines, Inngest-coupled), with its family driver atpackages/jobs/src/inngest/functions/integrations/ramp-sync-reimbursement-family.ts. Task 23 targets the real files. Do not go looking inpackages/ee/src/ramp/.
Scope boundary with the sibling spec. Tasks 12 and 13 build the SOURCE badge and the line editor as reusable, document-agnostic components in
apps/erp/app/components/, because.ai/specs/2026-09-23-editable-imported-spend-documents.mdrequires charges to use the same ones. Converting the charge UI to use them, and stoppingramp-sync-card.tsfrom auto-posting charges, are that spec's work and are OUT OF SCOPE here — see "Coordination with the sibling spec" at the end.
Progress
- Task 1: Migration — reimbursement schema, control account, settlement + payment payee
- Task 2: Regenerate database types
- Task 3: Seed data — 2180 account, account default, sequence row
- Task 4:
invoicing.models.ts— status constants + EDIT validators - Task 5:
invoicing.service.ts— readers +updateReimbursementheader write - Task 6:
invoicing.service.ts— Kysely line writers - Task 7: Accounting defaults — Employee Reimbursements Payable picker
- Task 8:
build-reimbursement-journal.ts(pure) + its Deno test - Task 9:
post-reimbursementedge function driver +config.toml - Task 10:
post-reimbursementhandler + transaction Deno tests - Task 11: Dimension data plumbing for the line editor
- Task 12: Shared
DocumentSourceBadgecomponent - Task 13: Shared
DocumentLineEditorcomponent - Task 14:
path.toentries for reimbursements - Task 15:
ReimbursementStatus+ReimbursementsTable - Task 16: Reimbursement detail — read mode
- Task 17: Reimbursement detail — edit mode
- Task 18: Post + Void action routes, with the totals guard
- Task 19: Nav entry under Accounts Payable
- Task 20: Settlement target — models + service
- Task 21:
post-payment— reimbursement settlement arm - Task 22: Payment UI — employee payee + reimbursement apply target
- Task 23: Ramp inbound — create a Draft
reimbursement; never auto-post, never re-write - Task 24:
@carbon/eeaccounting —reimbursemententity type + plumbing - Task 25: Rillet
ReimbursementSyncer - Task 26: Rillet payout — close
UNSUPPORTED_REIMBURSEMENT_PAYMENT - Task 27: QBO
ReimbursementSyncer - Task 28: Xero
ReimbursementSyncer - Task 29: Full validation gate
- Task 30: Browser verification via
/test
Dependencies
1 → 2 → everything else
2 → 3, 4, 7, 8 (parallel)
4 → 5 → 6, 15, 16, 20, 23
5 → 14 → 15, 16, 17, 18
8 → 9 → 10, 18, 23
11 → 13 → 17
12 → 16
6 → 17
16, 17, 18 → 19
20 → 21, 22 (21, 22 parallel)
2 → 24 → 25, 27, 28 (25, 27, 28 parallel)
25 → 26
all → 29 → 30
Independent, safe to run as parallel subagents once their dependencies are met:
- Tasks 3, 4, 7, 8 (after Task 2) — different files.
- Tasks 11, 12 (after Task 2) — different files.
- Tasks 21, 22 (after Task 20) — edge function vs ERP UI.
- Tasks 25, 27, 28 (after Task 24) — one provider directory each.
Task 1: Migration — reimbursement schema, control account, settlement + payment payee
Depends on: none
Files:
- Create:
packages/database/supabase/migrations/<generated>_reimbursements-first-class.sql - Copy from (precedent):
packages/database/supabase/migrations/20260922195151_rename-card-transactions-to-charges.sql(tables, triggers, RLS, sequence, event trigger) - Copy from (precedent):
packages/database/supabase/migrations/20260908142501_returns-module.sqllines 278–339 (nullable account default + company-group account seed) - Copy from (precedent):
packages/database/supabase/migrations/20260630093809_ar-ap-payments.sqllines 413–486 (invoiceSettlementtarget columns, XOR CHECK, partial indexes), lines 191–249 (paymentparty check)
Steps:
Create the file — never hand-pick or backdate the timestamp:
pnpm db:migrate:new reimbursements-first-classConfirm the generated filename's HHMMSS is not
000000; if it is, delete the file and re-run.Write the SQL below into that file, in this order. Every statement is idempotent (the deploy runner retries a failed file over committed partial state).
(a) Enum + journal enum labels.
ALTER TYPE … ADD VALUEmust not be referenced later in the same migration — nothing below does.DO $$ BEGIN IF to_regtype('public."reimbursementStatus"') IS NULL THEN CREATE TYPE public."reimbursementStatus" AS ENUM ('Draft', 'Posted', 'Voided'); END IF; END; $$; ALTER TYPE "journalEntrySourceType" ADD VALUE IF NOT EXISTS 'Reimbursement'; ALTER TYPE "journalLineDocumentType" ADD VALUE IF NOT EXISTS 'Reimbursement';(b) Tables.
reimbursementLinemirrorschargeLineexactly (accountId,costCenterId,projectId,description,amount,sequence) — the spec's Line-shape decision row requires it so one line editor serves both documents. Do not add or rename a line column.CREATE TABLE IF NOT EXISTS "reimbursement" ( id TEXT NOT NULL DEFAULT id('reimb'), "companyId" TEXT NOT NULL, "reimbursementId" TEXT NOT NULL, "employeeId" TEXT NOT NULL, status "reimbursementStatus" NOT NULL DEFAULT 'Draft', integration TEXT NOT NULL DEFAULT 'ramp', "reimbursementDate" DATE NOT NULL, "postingDate" DATE, "currencyCode" TEXT NOT NULL REFERENCES "currencyCode"(code), "exchangeRate" NUMERIC NOT NULL DEFAULT 1 CHECK ("exchangeRate" > 0), amount NUMERIC NOT NULL CHECK (amount > 0), "payableAccountId" TEXT REFERENCES "account"(id), reference TEXT, notes TEXT, "journalId" TEXT REFERENCES "journal"(id), "postedAt" TIMESTAMP WITH TIME ZONE, "postedBy" TEXT REFERENCES "user"(id), "voidedAt" TIMESTAMP WITH TIME ZONE, "voidedBy" TEXT REFERENCES "user"(id), "createdBy" TEXT NOT NULL REFERENCES "user"(id), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), "updatedBy" TEXT REFERENCES "user"(id), "updatedAt" TIMESTAMP WITH TIME ZONE, "customFields" JSONB, CONSTRAINT "reimbursement_pkey" PRIMARY KEY (id, "companyId"), CONSTRAINT "reimbursement_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"(id) ON DELETE CASCADE, CONSTRAINT "reimbursement_employeeId_fkey" FOREIGN KEY ("employeeId", "companyId") REFERENCES "employee"(id, "companyId") ON UPDATE CASCADE ON DELETE RESTRICT, CONSTRAINT "reimbursement_reimbursementId_companyId_key" UNIQUE ("reimbursementId", "companyId"), CONSTRAINT "reimbursement_lifecycle_audit_check" CHECK ( (status = 'Draft' AND "journalId" IS NULL AND "postedAt" IS NULL AND "postedBy" IS NULL AND "voidedAt" IS NULL AND "voidedBy" IS NULL) OR (status = 'Posted' AND "postingDate" IS NOT NULL AND "postedAt" IS NOT NULL AND "postedBy" IS NOT NULL AND "voidedAt" IS NULL AND "voidedBy" IS NULL) OR (status = 'Voided' AND "postingDate" IS NOT NULL AND "postedAt" IS NOT NULL AND "postedBy" IS NOT NULL AND "voidedAt" IS NOT NULL AND "voidedBy" IS NOT NULL) ) ); CREATE TABLE IF NOT EXISTS "reimbursementLine" ( id TEXT NOT NULL DEFAULT id('reimbl'), "companyId" TEXT NOT NULL, "reimbursementId" TEXT NOT NULL, "accountId" TEXT NOT NULL REFERENCES "account"(id), "costCenterId" TEXT, "projectId" TEXT, description TEXT, amount NUMERIC NOT NULL, sequence INTEGER NOT NULL DEFAULT 0, "createdBy" TEXT NOT NULL REFERENCES "user"(id), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), "updatedBy" TEXT REFERENCES "user"(id), "updatedAt" TIMESTAMP WITH TIME ZONE, "customFields" JSONB, CONSTRAINT "reimbursementLine_pkey" PRIMARY KEY (id, "companyId"), CONSTRAINT "reimbursementLine_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"(id) ON DELETE CASCADE, CONSTRAINT "reimbursementLine_reimbursementId_fkey" FOREIGN KEY ("reimbursementId", "companyId") REFERENCES "reimbursement"(id, "companyId") ON DELETE CASCADE, CONSTRAINT "reimbursementLine_costCenterId_fkey" FOREIGN KEY ("costCenterId", "companyId") REFERENCES "costCenter"(id, "companyId") ON UPDATE CASCADE ON DELETE SET NULL ("costCenterId"), CONSTRAINT "reimbursementLine_projectId_fkey" FOREIGN KEY ("projectId", "companyId") REFERENCES "project"(id, "companyId") ON UPDATE CASCADE ON DELETE SET NULL ("projectId") ); -- Generic dimension pairs for a coding line. DimensionSelector works in -- {dimensionId, valueId} pairs and the two legacy columns above cannot hold -- them, so the editor needs this table. The legacy columns STAY (the Ramp -- sync writes them, posting reads them); Task 9's posting pass unions both -- sources and de-duplicates by dimensionId. -- -- This MIRRORS "journalLineDimension" (20260228024512_dimensions.sql:116-138) -- and deliberately departs from the usual table template to do so, because -- it is the same kind of thing and the two are read together at posting: -- * single-column PRIMARY KEY ("id") — NOT the usual composite -- ("id","companyId"); journalLineDimension is PK ("id") alone. -- * single-column FK to "dimension"("id"). `dimension` is companyGroup- -- scoped with a single-column PK, like `account` and `item`, so a -- composite (dimensionId, companyId) FK would not resolve. -- * plain "companyId" REFERENCES "company"("id"). -- * no createdBy/updatedBy — journalLineDimension carries only createdAt, -- and an association row written and replaced wholesale by one code path -- has no independent authorship worth recording. CREATE TABLE IF NOT EXISTS "reimbursementLineDimension" ( "id" TEXT NOT NULL DEFAULT id('reimbld'), "reimbursementLineId" TEXT NOT NULL, "dimensionId" TEXT NOT NULL, "valueId" TEXT NOT NULL, "companyId" TEXT NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), CONSTRAINT "reimbursementLineDimension_pkey" PRIMARY KEY ("id"), CONSTRAINT "reimbursementLineDimension_line_dimension_key" UNIQUE ("reimbursementLineId", "dimensionId"), CONSTRAINT "reimbursementLineDimension_reimbursementLineId_fkey" FOREIGN KEY ("reimbursementLineId", "companyId") REFERENCES "reimbursementLine"("id", "companyId") ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT "reimbursementLineDimension_dimensionId_fkey" FOREIGN KEY ("dimensionId") REFERENCES "dimension"("id") ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT "reimbursementLineDimension_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE ); -- valueId is INTENTIONALLY not a foreign key, exactly as on -- journalLineDimension (see the comment at 20260228024512:131-134). For a -- Custom dimension it references dimensionValue.id; for an entity-based one -- it references that entity's table (location.id, department.id, …). Adding -- a FK here would break every entity-typed dimension. The polymorphic -- reference is enforced at the application layer.The UNIQUE on
("reimbursementLineId","dimensionId")is what makes "one value per dimension per line" true in the database — the same invariantDimensionSelectorenforces in the UI, and the same two-column shapejournalLineDimension_journalLineId_dimensionId_keyuses. Note the line FK is composite becausereimbursementLine's OWN pk is composite; only thedimensionandcompanyreferences are single-column.integration TEXT NOT NULL DEFAULT 'ramp'mirrorscharge.integrationand is what the SOURCE badge reads. There is deliberately noimportedAtcolumn: an earlier draft of this plan added one to timestamp an Activity entry, and the spec has since dropped the activity/timeline surface altogether (Carbon has no generic activity table; the audit log is the real history). The SOURCE badge carries provenance without it. Do not re-introduce it.(c) Indexes —
companyIdand EVERY FK, mirroring thechargeblock (precedent lines 196–221):CREATE INDEX IF NOT EXISTS "reimbursement_companyId_idx" ON "reimbursement" ("companyId"); CREATE INDEX IF NOT EXISTS "reimbursement_companyId_status_idx" ON "reimbursement" ("companyId", status); CREATE INDEX IF NOT EXISTS "reimbursement_companyId_reimbursementDate_idx" ON "reimbursement" ("companyId", "reimbursementDate"); CREATE INDEX IF NOT EXISTS "reimbursement_employeeId_companyId_idx" ON "reimbursement" ("employeeId", "companyId"); CREATE INDEX IF NOT EXISTS "reimbursement_currencyCode_idx" ON "reimbursement" ("currencyCode"); CREATE INDEX IF NOT EXISTS "reimbursement_payableAccountId_idx" ON "reimbursement" ("payableAccountId"); CREATE INDEX IF NOT EXISTS "reimbursement_journalId_idx" ON "reimbursement" ("journalId"); CREATE INDEX IF NOT EXISTS "reimbursement_createdBy_idx" ON "reimbursement" ("createdBy"); CREATE INDEX IF NOT EXISTS "reimbursement_updatedBy_idx" ON "reimbursement" ("updatedBy"); CREATE INDEX IF NOT EXISTS "reimbursement_postedBy_idx" ON "reimbursement" ("postedBy"); CREATE INDEX IF NOT EXISTS "reimbursement_voidedBy_idx" ON "reimbursement" ("voidedBy"); CREATE INDEX IF NOT EXISTS "reimbursementLine_companyId_idx" ON "reimbursementLine" ("companyId"); CREATE INDEX IF NOT EXISTS "reimbursementLine_reimbursementId_companyId_idx" ON "reimbursementLine" ("reimbursementId", "companyId"); CREATE INDEX IF NOT EXISTS "reimbursementLine_accountId_idx" ON "reimbursementLine" ("accountId"); CREATE INDEX IF NOT EXISTS "reimbursementLine_costCenterId_companyId_idx" ON "reimbursementLine" ("costCenterId", "companyId"); CREATE INDEX IF NOT EXISTS "reimbursementLine_projectId_idx" ON "reimbursementLine" ("projectId"); CREATE INDEX IF NOT EXISTS "reimbursementLine_createdBy_idx" ON "reimbursementLine" ("createdBy"); CREATE INDEX IF NOT EXISTS "reimbursementLine_updatedBy_idx" ON "reimbursementLine" ("updatedBy"); -- The same three journalLineDimension carries (20260228024512:136-138). CREATE INDEX IF NOT EXISTS "reimbursementLineDimension_reimbursementLineId_idx" ON "reimbursementLineDimension" ("reimbursementLineId"); CREATE INDEX IF NOT EXISTS "reimbursementLineDimension_dimensionId_idx" ON "reimbursementLineDimension" ("dimensionId"); CREATE INDEX IF NOT EXISTS "reimbursementLineDimension_companyId_idx" ON "reimbursementLineDimension" ("companyId");(d) Triggers — clone all four from the precedent, renaming
charge→reimbursement,chargeLine→reimbursementLine,chargeStatus→reimbursementStatus. These are what make "editable while Draft, immutable once Posted" true in the database, which the shared spec relies on as the backstop behind the UI guard:public.check_reimbursement_account_company_group()(precedent lines 224–269) — guard"payableAccountId"only (there is nocardAccountId); skip the check whenpayableAccountId IS NULL. Triggerreimbursement_account_companyGroup_guardBEFORE INSERT OR UPDATE OF"companyId","payableAccountId".public.check_reimbursement_line_account_company_group()(precedent lines 271–305) — verbatim rename. TriggerreimbursementLine_account_companyGroup_guard.public.check_reimbursement_draft_mutation()(precedent lines 309–390) — verbatim rename. The Draft→Draft arm (IF OLD.status = 'Draft' AND NEW.status = 'Draft' THEN RETURN NEW;) is what permits header editing, so keep it exactly. The Draft→Posted arm's allowed-field list gainspayableAccountId, because the posting transaction resolves and stores it. Triggerreimbursement_draft_guard.public.lock_reimbursement_line_parent()(precedent lines 393–470) — verbatim rename, including thepg_trigger_depth() > 1cascade escape. This is what refuses a line write against a Posted parent. TriggerreimbursementLine_draft_guard.
(e) RLS — clone the precedent's blocks (lines 476–560) verbatim with the renames. Four policies named exactly
SELECT/INSERT/UPDATE/DELETEon each table, schema-qualified, helper result cast::text[]:SELECTviaget_companies_with_employee_role();INSERT/UPDATE/DELETEviaget_companies_with_employee_permission('invoicing_create'|'invoicing_update'|'invoicing_delete'), each additionally requiringstatus = 'Draft'(header) or the parentEXISTS (… h.status = 'Draft')(lines).reimbursementLineDimensiongets SELECT / INSERT / DELETE only — the same threejournalLineDimensioncarries (20260228024512:144-172), and the right set here for an independent reason: Task 6 replaces a line's dimensions by delete-then-insert, so nothing ever issues an UPDATE against this table. Gate them on invoicing permissions (not accounting, unlike the precedent — this is an invoicing document), reaching the Draft check through TWO joins (reimbursementLineDimension→reimbursementLine→reimbursement). It carries its owncompanyId, so thecompanyId = ANY(...)clause is direct; theEXISTSis only for the Draft check.(f) Account default — nullable BY DESIGN with a runtime AP fallback (precedent
20260908142501lines 278–281):ALTER TABLE "accountDefault" ADD COLUMN IF NOT EXISTS "employeeReimbursementsPayableAccount" TEXT REFERENCES "account"("id") ON DELETE RESTRICT ON UPDATE CASCADE;Then seed account
2180 "Employee Reimbursements Payable"for every existing company group, copying theDO $$ … LOOPat20260908142501lines 289–326 exactly, changing only:- parent lookup:
"isGroup" = TRUE AND name = 'Current Liabilities'(resolve the parent group by NAME, never by number — group headers carrynumber = NULL;.ai/lessons.md"Chart-of-accounts group headers have no number") - the INSERT values:
'2180', 'Employee Reimbursements Payable', FALSE, 'Other Current Liability'::"accountType", 'Balance Sheet'::"glIncomeBalance", 'Liability'::"glAccountClass", 'Current'::"glConsolidatedRate"(matching the sibling2150/2160/2170rows inseed.data.ts) - on a missing parent,
RAISE WARNING … ; CONTINUE;— never insert an orphan.
Then backfill the default, guarded on name so a customized chart that already uses 2180 for something else stays NULL (precedent lines 328–339):
UPDATE "accountDefault" ad SET "employeeReimbursementsPayableAccount" = ( SELECT a.id FROM "account" a INNER JOIN "company" c ON c."companyGroupId" = a."companyGroupId" WHERE c.id = ad."companyId" AND a.number = '2180' AND a.name = 'Employee Reimbursements Payable' LIMIT 1 ) WHERE ad."employeeReimbursementsPayableAccount" IS NULL;(g) Settlement target. Add the fourth target and widen the XOR:
ALTER TABLE "invoiceSettlement" ADD COLUMN IF NOT EXISTS "targetReimbursementId" TEXT; DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM pg_constraint WHERE conname = 'invoiceSettlement_targetReimbursementId_fkey' ) THEN ALTER TABLE "invoiceSettlement" ADD CONSTRAINT "invoiceSettlement_targetReimbursementId_fkey" FOREIGN KEY ("targetReimbursementId", "companyId") REFERENCES "reimbursement"(id, "companyId") ON DELETE RESTRICT ON UPDATE CASCADE; END IF; END; $$; -- Widen the target XOR. `invoiceSettlement` is financial data, so the swap -- is guarded on the constraint's own DEFINITION (not just its name): a retry -- that already sees the widened form does nothing, and never drops a live -- constraint. Added NOT VALID then validated separately so the ADD takes a -- brief lock and the scan runs under SHARE UPDATE EXCLUSIVE. -- -- It cannot reject an existing row: every existing row satisfies the old -- three-way XOR, and `targetReimbursementId` is NULL on all of them, so each -- sum is exactly 1. VALIDATE is therefore guaranteed to pass — it proves -- that rather than assuming it. DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM pg_constraint WHERE conname = 'invoiceSettlement_target_check' AND pg_get_constraintdef(oid) LIKE '%targetReimbursementId%' ) THEN ALTER TABLE "invoiceSettlement" DROP CONSTRAINT IF EXISTS "invoiceSettlement_target_check"; ALTER TABLE "invoiceSettlement" ADD CONSTRAINT "invoiceSettlement_target_check" CHECK ( (("targetSalesInvoiceId" IS NOT NULL)::int + ("targetPurchaseInvoiceId" IS NOT NULL)::int + ("targetMemoId" IS NOT NULL)::int + ("targetReimbursementId" IS NOT NULL)::int) = 1 ) NOT VALID; ALTER TABLE "invoiceSettlement" VALIDATE CONSTRAINT "invoiceSettlement_target_check"; END IF; END; $$; CREATE INDEX IF NOT EXISTS "invoiceSettlement_targetReimbursementId_idx" ON "invoiceSettlement" ("targetReimbursementId") WHERE "targetReimbursementId" IS NOT NULL;(h) Payment payee —
paymentis PRODUCTION-CRITICAL. A reimbursement payout is a disbursement to an employee, andpaymenttoday is customer XOR supplier. The spec approves the widening and requires the migration to be additive and idempotent, so every statement below is guarded and nothing is destructive. Adding a nullable column with no default is a catalogue-only operation in PostgreSQL 11+, so it does not rewrite the table.ALTER TABLE "payment" ADD COLUMN IF NOT EXISTS "employeeId" TEXT; DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM pg_constraint WHERE conname = 'payment_employeeId_fkey' ) THEN ALTER TABLE "payment" ADD CONSTRAINT "payment_employeeId_fkey" FOREIGN KEY ("employeeId", "companyId") REFERENCES "employee"(id, "companyId") ON DELETE RESTRICT ON UPDATE CASCADE; END IF; END; $$; -- Same guarded swap as (g), and for a stronger reason: this is the payments -- table. The guard reads the constraint DEFINITION, so re-running the -- migration after success is a no-op and never leaves `payment` briefly -- unconstrained. -- -- **It cannot reject an existing row.** Every existing payment satisfies the -- old customer-XOR-supplier rule, and `employeeId` is NULL on all of them -- (the column was just added), so each sum is exactly 1. The widened form is -- strictly weaker than the old one on the existing column pair — it only -- ADDS a third way to be valid — so no historical row can fail it. DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM pg_constraint WHERE conname = 'payment_party_check' AND pg_get_constraintdef(oid) LIKE '%employeeId%' ) THEN ALTER TABLE "payment" DROP CONSTRAINT IF EXISTS "payment_party_check"; ALTER TABLE "payment" ADD CONSTRAINT "payment_party_check" CHECK ( (("customerId" IS NOT NULL)::int + ("supplierId" IS NOT NULL)::int + ("employeeId" IS NOT NULL)::int) = 1 ) NOT VALID; ALTER TABLE "payment" VALIDATE CONSTRAINT "payment_party_check"; END IF; END; $$; CREATE INDEX IF NOT EXISTS "payment_employeeId_companyId_idx" ON "payment" ("employeeId", "companyId") WHERE "employeeId" IS NOT NULL;Before applying, confirm on the local database that the pre-existing constraint is named exactly
payment_party_check(it is, per20260630093809_ar-ap-payments.sql:225). If a later migration renamed it, STOP and report — a guard keyed on the wrong name would silently leave the old constraint in place and the new column unconstrained.(i) Sequence + event trigger (precedent lines 563–601):
INSERT INTO "sequence" ( "table", name, prefix, suffix, next, size, step, "companyId" ) SELECT 'reimbursement', 'Reimbursement', 'REIMB-%{yyyy}-%{mm}-', NULL, 0, 6, 1, c.id FROM "company" c ON CONFLICT DO NOTHING; SELECT attach_event_trigger( 'reimbursement', ARRAY[]::TEXT[], ARRAY[]::TEXT[] ); NOTIFY pgrst, 'reload schema';Do not add a
packages/jobs/src/backups/renames.tsentry — this migration renames and drops nothing.Apply it:
pnpm db:migrate
Verify:
psql "$(grep -m1 DATABASE_URL .env.local | cut -d= -f2-)" -c "\d reimbursement" -c "\d reimbursementLine" -c "\d reimbursementLineDimension" -c "SELECT conname, convalidated, pg_get_constraintdef(oid) FROM pg_constraint WHERE conname IN ('invoiceSettlement_target_check','payment_party_check');" -c "SELECT count(*) AS payments_violating FROM \"payment\" WHERE ((\"customerId\" IS NOT NULL)::int + (\"supplierId\" IS NOT NULL)::int + (\"employeeId\" IS NOT NULL)::int) <> 1;" -c "SELECT unnest(enum_range(NULL::\"reimbursementStatus\"));" -c "SELECT count(*) FROM \"sequence\" WHERE \"table\"='reimbursement';"
# Expected: both \d outputs list the composite PK ("id","companyId"), the
# id('reimb') / id('reimbl') defaults, the four audit columns, and the RLS
# policies SELECT/INSERT/UPDATE/DELETE; reimbursementLine's columns are exactly
# accountId, costCenterId, projectId, description, amount, sequence plus
# id/companyId/reimbursementId/audit/customFields — the same set as chargeLine,
# and NO importedAt column anywhere; reimbursementLineDimension exists with a
# single-column PK ("id"), UNIQUE(reimbursementLineId, dimensionId), a
# single-column FK to dimension(id), and NO foreign key on valueId; BOTH
# constraints come
# back with convalidated = t and a definition mentioning targetReimbursementId /
# employeeId respectively; payments_violating is 0 (the widened CHECK rejects no
# existing row); the enum prints Draft, Posted, Voided; the sequence count
# equals the number of companies in the local DB (>= 1).
#
# Then run the migration a SECOND time (psql -f on the same file). It must
# succeed with no error and leave payments_violating at 0 — that is the
# idempotency proof for the production-critical payment table.
Out of scope: Do not touch purchaseInvoice, supplier, or supplierType.
No backfill of existing employee-supplier purchase invoices (spec: "No backfill
— a backfill would rewrite posted history"). Do not add a reimbursementType
enum — a reimbursement has exactly one shape. Do not add a column per dimension
concept to reimbursementLine — that is what reimbursementLineDimension is
for. Do not drop costCenterId / projectId; the spec keeps them and posting
unions both sources. Do not add an importedAt column.
Task 2: Regenerate database types
Depends on: Task 1
Files:
- Modify:
packages/database/src/types.ts— generated - Modify:
packages/database/src/swagger-docs-schema.ts— generated - Modify:
packages/database/supabase/functions/lib/types.ts— generated
Steps:
- Run:
pnpm run generate:types - These three files are generated — never hand-edit them. This is the ONE task where their modification is intended and must be committed.
Verify:
grep -c '"reimbursement"\|reimbursement:' packages/database/src/types.ts && grep -n 'reimbursementStatus' packages/database/src/types.ts | head -3 && grep -n '"Reimbursement"' packages/database/src/types.ts | head -3 && grep -n 'targetReimbursementId' packages/database/src/types.ts | head -2
# Expected: a non-zero count; `reimbursementStatus: "Draft" | "Posted" | "Voided"`
# appears in the Enums block; "Reimbursement" appears in the
# journalEntrySourceType and journalLineDocumentType unions;
# targetReimbursementId appears on the invoiceSettlement Row type.
Out of scope: No other file changes in this task. If git status shows
anything outside packages/database/src/ and
packages/database/supabase/functions/lib/types.ts, revert it.
Task 3: Seed data — 2180 account, account default, sequence row
Depends on: Task 2
Files:
- Modify:
packages/database/supabase/functions/lib/seed.data.ts— add the account row, theaccountDefaultsentry, and the sequence row - Copy from (precedent): the same file, line 711 (
current-liabilitiesgroup), lines 715–717 (2150/2160/2170sibling rows), line 815 (salesReturnsAccount: "4900"), lines 497–505 (thechargesequence row)
Steps:
- In the chart-of-accounts array, immediately after the
2170row (currently line 717), insert:{ key: "2180", number: "2180", name: "Employee Reimbursements Payable", isGroup: false, parentKey: "current-liabilities", accountType: "Other Current Liability", incomeBalance: "Balance Sheet", class: "Liability", consolidatedRate: "Current", createdBy: "system" }, - In the
accountDefaultsobject (starts line 810), next tosalesReturnsAccount: "4900",add:employeeReimbursementsPayableAccount: "2180", - In the sequences array, immediately after the
chargeentry (lines 497–505), add:{ table: "reimbursement", name: "Reimbursement", prefix: "REIMB-%{yyyy}-%{mm}-", suffix: null, next: 0, size: 6, step: 1 },
Verify:
grep -n '"2180"\|employeeReimbursementsPayableAccount\|table: "reimbursement"' packages/database/supabase/functions/lib/seed.data.ts
# Expected: exactly three hits — the account row (number: "2180"), the
# accountDefaults entry, and the sequence row.
Out of scope: Do not renumber or rename any existing account. Do not touch
packages/database/src/datasets/** — the demo datasets seed no reimbursements
in v1.
Task 4: invoicing.models.ts — status constants + EDIT validators
Depends on: Task 2
Files:
- Modify:
apps/erp/app/modules/invoicing/invoicing.models.ts— add aReimbursementssection after theChargessection (currently ends line 441) - Copy from (precedent): the same file, lines 428–441 (
chargeStatus/ChargeStatusType) for the constants, and lines 366–385 (memoValidator) for thezfdheader-field style
Steps:
- Append after the Charges section. Note what is absent and must stay
absent: there is no create validator, because Carbon never hand-creates a
reimbursement.
reimbursementUpdateValidatoris an EDIT-only schema — it requiresidand deliberately omitsreimbursementId(the readable id is allocated by the sync and is not user-editable) andemployeeId(the payee is who Ramp says incurred the expense; re-pointing it would falsify the document).// ---------------------------------------------------------------------- // Reimbursements (employee expense payables — imported from a spend tool, // then editable in Carbon while Draft; never hand-created) // ---------------------------------------------------------------------- export const reimbursementStatus = ["Draft", "Posted", "Voided"] as const; export type ReimbursementStatusType = (typeof reimbursementStatus)[number]; export function isReimbursementLocked( status: string | null | undefined ): boolean { return status !== null && status !== undefined && status !== "Draft"; } // Header edit. No create counterpart by design. export const reimbursementUpdateValidator = z.object({ id: z.string().min(1), reimbursementDate: z .string() .min(1, { message: "Reimbursement date is required" }), currencyCode: z.string().min(1, { message: "Currency is required" }), exchangeRate: zfd.numeric(z.number().positive().default(1)), amount: zfd.numeric( z.number().finite().positive({ message: "Amount must be positive" }) ), reference: zfd.text(z.string().optional()), notes: zfd.text(z.string().optional()) }); // One coding line. The five stored columns mirror chargeLine, plus the // generic dimension pairs DimensionSelector works in. Do NOT add a field per // dimension concept — that is what `dimensions` is. // // These lines arrive as parsed JSON from a hidden field, not as form data, // so this validator is plain zod (no zfd coercion) — zfd.numeric expects a // FormData string and would reject an already-numeric amount. export const reimbursementLineDimensionValidator = z.object({ dimensionId: z.string().min(1), valueId: z.string().min(1) }); export const reimbursementLineValidator = z.object({ id: z.string().optional(), accountId: z.string().min(1, { message: "Account is required" }), costCenterId: z.string().nullish(), projectId: z.string().nullish(), description: z.string().nullish(), amount: z .number() .finite() .positive({ message: "Line amount must be positive" }), dimensions: z.array(reimbursementLineDimensionValidator).default([]) }); // The editor submits the whole line set as ONE hidden JSON field, so the // route parses that string and runs it through this array. export const reimbursementLinesValidator = z .array(reimbursementLineValidator) .min(1, { message: "A reimbursement needs at least one line" }); - Do not touch
invoiceSettlementBase/invoiceSettlementValidator/paymentValidatorhere — those change in Task 20.
Verify:
grep -n "reimbursementStatus\|ReimbursementStatusType\|isReimbursementLocked\|reimbursementUpdateValidator\|reimbursementLineDimensionValidator\|reimbursementLineValidator\|reimbursementLinesValidator\|reimbursementValidator\b" apps/erp/app/modules/invoicing/invoicing.models.ts && pnpm exec turbo run typecheck --filter=erp && git status --short packages/database/
# Expected: the grep prints the seven intended exports (including
# reimbursementLineDimensionValidator) and NO bare `reimbursementValidator`
# (a create validator). If a create validator appears, the task is wrong.
# typecheck exits 0; `git status --short packages/database/` prints NOTHING.
# If it lists generated files, revert them:
# git checkout -- packages/database/src/types.ts packages/database/src/swagger-docs-schema.ts packages/database/supabase/functions/lib/types.ts
Out of scope: No create validator, no new-route schema. No service or UI
changes.
Task 5: invoicing.service.ts — readers + updateReimbursement header write
Depends on: Task 4
Files:
- Modify:
apps/erp/app/modules/invoicing/invoicing.service.ts— add the readers and the header update next to the charge functions (line 1434-area) - Copy from (precedent): the same file —
getCharge(1434–1445) andgetCharges(1447–1478) for the readers;upsertMemo's update branch for thesanitize(...)+updatedAtshape
Steps:
- Add, using the module's standard shape (client first, return the raw
{ data, error }, never throw, always scope bycompanyId):export async function getReimbursement( client: SupabaseClient<Database>, companyId: string, id: string ) { return client .from("reimbursement") // Embed the generic dimension rows with the lines — the editor and the // read-mode badges both need them, and a per-line query would be an N+1. .select("*, reimbursementLine(*, reimbursementLineDimension(*))") .eq("id", id) .eq("companyId", companyId) .single(); } export async function getReimbursements( client: SupabaseClient<Database>, companyId: string, args: GenericQueryFilters & { search: string | null; status: ReimbursementStatusType | null; employeeId: string | null; } ) { let query = client .from("reimbursement") .select("*", { count: "exact" }) .eq("companyId", companyId); if (args.search) { query = query.or( `reimbursementId.ilike.%${args.search}%,reference.ilike.%${args.search}%` ); } if (args.status) query = query.eq("status", args.status); if (args.employeeId) query = query.eq("employeeId", args.employeeId); // Newest first by the sequential reimbursementId (REIMB-yyyy-mm-NNNNNN), // mirroring getCharges' chargeId desc default. query = setGenericQueryFilters(query, args, [ { column: "reimbursementId", ascending: false } ]); return query; } /** * Header edit. `.eq("status", "Draft")` is defence in depth alongside the * RLS UPDATE policy and the reimbursement_draft_guard trigger — a Posted * document is immutable, and a caller that tries gets zero rows rather than * a silent partial write. There is deliberately no insert branch: the Ramp * sync is the only thing that creates a reimbursement. */ export async function updateReimbursement( client: SupabaseClient<Database>, reimbursement: z.infer<typeof reimbursementUpdateValidator> & { companyId: string; updatedBy: string; customFields?: Json; } ) { const { id, companyId, ...update } = reimbursement; return client .from("reimbursement") .update({ ...sanitize(update), updatedAt: today(getLocalTimeZone()).toString() }) .eq("id", id) .eq("companyId", companyId) .eq("status", "Draft") .select("id, reimbursementId") .single(); } - Add
ReimbursementStatusTypeto the type import block at the top of the file (the one that already importsChargeStatusType,ChargeTypeat lines 44–45).
Verify:
grep -n "export async function .*Reimbursement" apps/erp/app/modules/invoicing/invoicing.service.ts && pnpm exec turbo run typecheck --filter=erp && git status --short packages/database/
# Expected: the grep prints exactly three functions — getReimbursement,
# getReimbursements, updateReimbursement. It must NOT print an insert/upsert
# with a createdBy branch, nor a deleteReimbursement.
# typecheck exits 0; git status prints nothing for packages/database/.
Out of scope: No line writes here (Task 6 — they are multi-row and need
Kysely). No insert branch. Do not build a DB client in this file — it is
barrel-exported to the browser (no-db-client-in-service).
Task 6: invoicing.service.ts — Kysely line writers
Depends on: Task 5
Files:
- Modify:
apps/erp/app/modules/invoicing/invoicing.service.ts— add the line writers afterupdateReimbursement - Copy from (precedent): the same file,
replaceInvoiceSettlements(2483–2670) — specifically itsdb: Kysely<KyselyDatabase>signature, thedb.transaction().execute()wrapper, theforUpdate()parent lock + status re-assert prologue at 2495–2507, and the delete-all-then-reinsert body at 2650–2670 - Copy from (precedent):
apps/erp/app/modules/inventory/inventory.service.tsgenerateInventoryCountLines(1868–1993) — the same shape with a bulk.values(rows.map(...))insert
Steps:
- The existing type-only import at
invoicing.service.ts:3already provides what is needed — do not add a value import:
Invoicing already has siximport type { Kysely, KyselyDatabase } from "@carbon/database/client";db: Kysely<KyselyDatabase>service functions (979, 1355, 2248, 2272, 2483, 3266), so this extends an established pattern. - Add:
The/** * Replace every coding line of a Draft reimbursement, transactionally. * * Kysely BYPASSES RLS, so the parent is re-read `forUpdate()` and its status * re-asserted inside the transaction — exactly as replaceInvoiceSettlements * does. The reimbursementLine_draft_guard trigger is the final backstop, but * it raises a raw 55000; this throws a message the route can flash. * * Delete-all-then-reinsert rather than a diff: the editor submits the whole * line set as one field, so a diff would be more code for the same result. */ export async function upsertReimbursementLines( db: Kysely<KyselyDatabase>, args: { reimbursementId: string; companyId: string; createdBy: string; lines: z.infer<typeof reimbursementLineValidator>[]; } ) { return db.transaction().execute(async (trx) => { const reimbursement = await trx .selectFrom("reimbursement") .select(["id", "status"]) .where("id", "=", args.reimbursementId) .where("companyId", "=", args.companyId) .forUpdate() .executeTakeFirst(); if (!reimbursement) throw new Error("Reimbursement not found"); if (reimbursement.status !== "Draft") throw new Error( "Coding lines can only be edited while the reimbursement is Draft" ); await trx .deleteFrom("reimbursementLine") .where("reimbursementId", "=", args.reimbursementId) .where("companyId", "=", args.companyId) .execute(); if (args.lines.length === 0) return 0; // RETURNING id, so the dimension rows can be bound to the line they // belong to without relying on PostgreSQL's unspecified INSERT row // order — the same reason post-charge allocates journal line ids up // front. Insert order is preserved by `sequence`, but do NOT zip the // returned rows by position; key them by `sequence`. const inserted = await trx .insertInto("reimbursementLine") .values( args.lines.map((line, index) => ({ reimbursementId: args.reimbursementId, companyId: args.companyId, accountId: line.accountId, costCenterId: line.costCenterId ?? null, projectId: line.projectId ?? null, description: line.description ?? null, amount: line.amount, sequence: index, createdBy: args.createdBy })) ) .returning(["id", "sequence"]) .execute(); const idBySequence = new Map(inserted.map((r) => [r.sequence, r.id])); const dimensionRows = args.lines.flatMap((line, index) => { const lineId = idBySequence.get(index); if (!lineId) throw new Error("Failed to map reimbursement line"); return (line.dimensions ?? []).map((d) => ({ reimbursementLineId: lineId, companyId: args.companyId, dimensionId: d.dimensionId, valueId: d.valueId })); }); if (dimensionRows.length) { await trx .insertInto("reimbursementLineDimension") .values(dimensionRows) .execute(); } return args.lines.length; }); }reimbursementLineDimensionrows need no explicit delete — the line delete above cascades them (ON DELETE CASCADEon the line FK), so the replace is still one delete and two inserts.sequenceis assigned 0-based from array order — that ischargeLine's convention and whatpost-reimbursementorders by. Do not usepurchaseInvoiceLine's 1-basedsortOrder. - Do not add a
deleteReimbursementLine. Removing a line is expressed by submitting the line set without it; a separate per-line delete endpoint would be a second write path into the same state with its own Draft guard to get wrong. If a later task appears to need one, STOP and report.
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm exec tsx -e "import('@carbon/checks').then(async (m) => { const r = await m.runChecks?.({ only: ['no-db-client-in-service'] }); console.log(JSON.stringify(r ?? 'runner-signature-differs', null, 2)); })" 2>/dev/null || grep -n "getPostgresConnectionPool\|getPostgresClient\|new Pool(\|PostgresDriver" apps/erp/app/modules/invoicing/invoicing.service.ts; git status --short packages/database/
# Expected: typecheck exits 0. The conformance check reports NO
# no-db-client-in-service violations; if the programmatic runner signature
# differs the grep fallback runs and must print NOTHING (those four tokens are
# exactly what the check bans in a *.service.ts — see
# packages/checks/src/conformance/no-db-client-in-service.ts). A `db: Kysely<KyselyDatabase>`
# PARAMETER is the prescribed fix and is not a violation.
# git status prints nothing for packages/database/.
Out of scope: Do not construct a pool or client in this file. Do not add a
per-line delete endpoint. Do not touch replaceInvoiceSettlements.
Task 7: Accounting defaults — Employee Reimbursements Payable picker
Depends on: Task 2
Files:
- Modify:
apps/erp/app/modules/accounting/accounting.models.ts— add the field todefaultBalanceSheetAccountValidator - Modify:
apps/erp/app/modules/accounting/ui/AccountDefaults/AccountDefaultsForm.tsx— add the field to thepayablescategory group - Copy from (precedent): the same form, the
payablesgroup (lines 194–226), fieldsupplierWriteOffAccount(lines 220–225) - Copy from (precedent):
accounting.models.tsline 500 (scrapAccount: z.string().optional()) — the optional-account-default shape
Steps:
- In
defaultBalanceSheetAccountValidator, next topayablesAccount(line 457), add — optional, because the column is nullable by design with a runtime AP fallback, and a required field would break saves on every company whose chart has no 2180:employeeReimbursementsPayableAccount: z.string().optional(), - In
AccountDefaultsForm.tsx, inside thepayablesgroup'sfieldsarray, aftersupplierWriteOffAccount, add:{ name: "employeeReimbursementsPayableAccount", label: t`Employee Reimbursements Payable`, description: t`Liability account for amounts owed to employees for expense reimbursements. Falls back to Payables when unset`, badgeType: "Liability" } - Nothing else is needed:
updateDefaultAccounts(the generic.update(defaultAccounts)) andaccounting.defaults.test.tsboth iterateObject.keys(defaultAccountValidator.shape), so the new key flows through.
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm --filter erp test -- accounting.defaults && git status --short packages/database/
# Expected: typecheck exits 0; the accounting.defaults test file passes
# ("Test Files 1 passed"); git status prints nothing for packages/database/.
Out of scope: Do not make any EXISTING account default optional or required. Do not add a new category group.
Task 8: build-reimbursement-journal.ts (pure) + its Deno test
Depends on: Task 2
Files:
- Create:
packages/database/supabase/functions/post-reimbursement/build-reimbursement-journal.ts - Create:
packages/database/supabase/functions/post-reimbursement/build-reimbursement-journal.test.ts - Copy from (precedent):
packages/database/supabase/functions/post-charge/build-charge-journal.ts(the whole file — imports,GLAccountClass,AccountType,pushLine,requireLineSum,assertExchangeRate/toBase, theassertBalancedbackstop,BALANCE_TOLERANCE = 0.01)
Steps:
- Create the builder as a pure function — no DB, no I/O, no clock. Amounts are
natural-balance-signed via
credit()/debit()from../lib/utils.ts(.ai/lessons.md— "Journal debit/credit is derived from account class + amount sign, not the raw sign": a positive amount on a Liability account IS a credit). Signature:export interface BuildReimbursementJournalInput { reimbursement: { amount: number; payableAccountId: string; currencyCode: string; exchangeRate: number; }; lines: ReimbursementLineInput[]; // accountId, amount, costCenterId, projectId, description accounts: Record<string, { class: GLAccountClass }>; documentId: string; documentReadableId: string; } export interface ReimbursementJournalLine { accountId: string; amount: number; description: string; documentType: "Reimbursement"; documentId: string; costCenterId?: string | null; projectId?: string | null; } export function buildReimbursementJournal( input: BuildReimbursementJournalInput ): { journalLines: ReimbursementJournalLine[] }; - Body — there is exactly ONE shape (the charge builder's
case "Charge"arm, with the card liability replaced by the resolved payable account):assertExchangeRate(exchangeRate);toBase = (v) => toBaseAmount(v, exchangeRate).requireLineSum(): at least one line; everyline.amountfinite and> 0;|Σ lines − amount| <= EPSILONelse throw`Reimbursement ${documentReadableId}: line sum ${lineSum} does not equal header amount ${amount}`. This is the invariant the UI's totals guard (Task 18) mirrors — the message text is what a developer sees if the guard is ever bypassed.- For each line:
magnitude = toBase(line.amount); accumulate intopayableMagnitude;pushLine("debit", classOf(line.accountId), magnitude, {…})withdescription: line.description ?? "Employee reimbursement". - After the loop:
pushLine("credit", classOf(payableAccountId), payableMagnitude, { accountId: payableAccountId, description: "Employee reimbursement payable" }). Take the class from theaccountsmap, not a hard-coded"liability"— the fallback AP trade account is also a Liability, but the class must come from the resolved account so a mis-classed default fails loudly. assertBalanced(signedDebitTotal, 0, BALANCE_TOLERANCE, "Reimbursement journal").classOfthrows`Reimbursement ${documentReadableId}: missing account class for ${accountId}`on an unknown id.
- Write the golden-master test mirroring
post-charge/build-charge-journal.test.ts(read it for the assertion style). Cover at minimum:- the spec's AC1 case — lines
500(Expense) +120(Expense), payable (Liability)620,exchangeRate: 1→ three lines, debits+500and+120on the expense accounts,+620on the liability (a positive amount on a Liability is a CREDIT), andtotalDebits == totalCredits; - the AP-fallback case — identical output when the payable account id is the AP trade account (AC2: the journal must still balance);
costCenterId/projectIdcarried through onto the matching line only — this is what becomes thejournalLineDimensionrows the edited coding is for;- a line sum that disagrees with the header → throws;
- a zero or negative line amount → throws;
exchangeRate: 1.25→ every magnitude divided (never multiplied) and the entry still balanced.
- the spec's AC1 case — lines
Verify:
cd packages/database/supabase/functions && deno test --no-lock --no-check post-reimbursement/build-reimbursement-journal.test.ts
# Expected: "ok | N passed | 0 failed" with N >= 6.
Out of scope: No DB access, no Deno.env, no new Date() in this file.
Do not add a reimbursement "type" discriminator — unlike a charge there is one
shape.
Task 9: post-reimbursement edge function driver + config.toml
Depends on: Task 8
Files:
- Create:
packages/database/supabase/functions/post-reimbursement/index.ts - Create:
packages/database/supabase/functions/post-reimbursement/handler.ts - Create:
packages/database/supabase/functions/post-reimbursement/post-reimbursement-transaction.ts - Create:
packages/database/supabase/functions/post-reimbursement/post-reimbursement-post.ts - Create:
packages/database/supabase/functions/post-reimbursement/post-reimbursement-void.ts - Modify:
packages/database/supabase/config.toml— add[functions.post-reimbursement] - Copy from (precedent):
packages/database/supabase/functions/post-charge/index.ts,handler.ts,post-charge-transaction.ts,post-charge-post.ts,post-charge-void.ts(one-for-one)
Steps:
index.ts— verbatim clone ofpost-charge/index.tswith the renames:getConnectionPool(1)at module scope,handlePostReimbursement(req, (args) => postReimbursementTransaction(db, args)).handler.ts— clonepost-charge/handler.ts. Validator:const payloadValidator = z.object({ type: z.enum(["post", "void"]).default("post"), reimbursementId: z.string(), userId: z.string(), companyId: z.string() });Auth is
await requirePermissions(req, args.companyId, args.userId, { update: "invoicing" }), and the record is re-read undercompanyIdin the transaction, so a foreign id fails rather than posting cross-tenant.Both callers are the ERP's own action routes (Task 18) — under the new model the Ramp sync no longer posts, so a human's Post click is what reaches
type: "post".post-reimbursement-transaction.ts— clonepost-charge-transaction.ts:- ONE
db.transaction().execute(). - The FIRST read is the tenant-scoped
.forUpdate()select onreimbursementbyid+companyId, selectingid, reimbursementId, employeeId, status, amount, currencyCode, exchangeRate, payableAccountId, journalId, plussql<string>"reimbursementDate"::textand `sql<string | null>`"postingDate"::text. Not found →throw new Error("Reimbursement not found"). - Idempotency:
type === "post" && status === "Posted"→ return the storedjournalId;type === "void" && status === "Voided"→ return the storedjournalId(spec AC4's "re-voiding returns the stored journal id without a second reversal"). Otherwise require the expected status. - Load
companySettings.accountingEnabledandcompany.companyGroupId/baseCurrencyCode/timezone; build the context withdatetime.timestamp()anddatetime.today(company.timezone).toString().
- ONE
post-reimbursement-post.ts— clonepost-charge-post.ts, changing only:- Read the lines from
reimbursementLineordered bysequence, thenid. - Resolve the payable account by ID from
accountDefault, never by number or name (.ai/lessons.md— "Never resolve a control account by number/name"):
Thatconst defaults = await trx.selectFrom("accountDefault") .select(["employeeReimbursementsPayableAccount", "payablesAccount"]) .where("companyId", "=", companyId) .executeTakeFirst(); const payableAccountId = reimbursement.payableAccountId ?? defaults?.employeeReimbursementsPayableAccount ?? defaults?.payablesAccount ?? null; if (!payableAccountId) { throw new Error( "No employee reimbursements payable account and no payables account is configured" ); }?? payablesAccountchain is spec AC2 — an upgrading company with the new default unset must still post. accountIds = [...new Set([payableAccountId, ...lines.map(l => l.accountId)])]; the sameaccountquery filtered bycompanyGroupId,active = true,isGroup = false; the same "must be active posting accounts in this company group" throw on a count mismatch or a missing class.- Replace the charge's card/offset class assertions with ONE check:
accounts[payableAccountId]?.class !== "Liability"→throw new Error("Reimbursement payable account must be a Liability account"). - Keep the cost-center and project existence checks verbatim.
postingDate = reimbursement.postingDate ?? reimbursement.reimbursementDate, thenresolveAccountingPeriod(trx, companyId, postingDate, "historical-with-shift").buildReimbursementJournal({...}); journaldescription:Reimbursement ${reimbursement.reimbursementId}``,sourceType: "Reimbursement",journalEntryId: await getNextSequence(trx, "journalEntry", companyId).allocateJournalLineIds— import it from../post-charge/journal-line-ids.ts(already generic; do NOT copy the file).- Journal lines get
documentType: "Reimbursement" as const. - The cost-center and project
dimensionlookups and theirjournalLineDimensioninserts are verbatim, including the two throws ("Company group has no active Cost Center dimension" / "… Project dimension") — the spec's cost-center criterion requires that refusal. - Then union the generic dimension rows. Read
reimbursementLineDimensionfor the document's lines and emit ajournalLineDimensionrow per pair, de-duplicating bydimensionIdagainst the two legacy columns above — the spec keepscostCenterId/projectIdAND adds the generic table, so a line that carries a Cost Center in both must produce ONE dimension row, not two (journalLineDimensionis one value per dimension per line). Resolve the conflict in favour of the generic table. Put the reason in the CODE COMMENT, not just here: the two legacy columns are what the sync wrote at import; the generic table is where a human's edit lands — and human intent beats a machine default. A reader who finds that precedence surprising needs the sentence at the call site. Validate everydimensionIdis active and belongs to the company group, throwing in the same shape as the two existing checks. - Final update sets
status: "Posted", journalId, postingDate, payableAccountId, postedAt, postedBy, updatedAt, updatedBy.
- Read the lines from
post-reimbursement-void.ts— clonepost-charge-void.tsverbatim with the renames: the provenance guard becomesoriginalJournal.sourceType !== "Reimbursement", the line guardline.documentType !== "Reimbursement", the reversal description`VOID Reimbursement ${reimbursement.reimbursementId}`, the reversal linesamount: -Number(line.amount)withdocumentType: "Reimbursement", and the dimension rows re-mapped throughreversalByOriginal.config.toml— after the[functions.post-charge]block (lines 217–220), add:[functions.post-reimbursement] enabled = true verify_jwt = true entrypoint = "./functions/post-reimbursement/index.ts"(Deployment is all-at-once and directory-driven, so this entry is for the settings and for discoverability — not a deploy gate.)
Verify:
cd packages/database/supabase/functions && deno check --no-lock post-reimbursement/index.ts && grep -A 3 '\[functions.post-reimbursement\]' ../config.toml
# Expected: `deno check` prints "Check file:///.../post-reimbursement/index.ts"
# and exits 0 with no diagnostics; the grep prints enabled = true,
# verify_jwt = true and the entrypoint line.
Out of scope: Do not change post-charge or post-payment. Do not add a
reimbursement case to post-memo.
Task 10: post-reimbursement handler + transaction Deno tests
Depends on: Task 9
Files:
- Create:
packages/database/supabase/functions/post-reimbursement/handler.test.ts - Create:
packages/database/supabase/functions/post-reimbursement/post-reimbursement-test-fixture.ts - Create:
packages/database/supabase/functions/post-reimbursement/post-reimbursement-transaction.test.ts - Copy from (precedent):
packages/database/supabase/functions/post-charge/handler.test.ts,post-charge-test-fixture.ts,post-charge-transaction.test.ts
Steps:
handler.test.ts— clone the charge version'swithAuthTransportharness. Assert: a service-role token is accepted; anauthenticatedtoken lackinginvoicing_updateis rejected; a malformed body returns a 500 with anerrorfield.post-reimbursement-test-fixture.ts— clone the charge fixture's in-memory Kysely stub, swapping thecharge/chargeLinetables forreimbursement/reimbursementLineand adding anaccountDefaultrow so the payable resolution can be exercised.post-reimbursement-transaction.test.ts— cases:- AC1 post with two lines → ONE
journalrowsourceType = "Reimbursement", threejournalLinerows, the header flips toPostedwithjournalIdset andpayableAccountIdstored; - AC2
employeeReimbursementsPayableAccountNULL → the journal creditspayablesAccountinstead and still balances; - both NULL → throws "No employee reimbursements payable account…";
- AC3 a line with
costCenterIdand an active Cost Center dimension → onejournalLineDimensionrow on that line only; the same line with NO active dimension → throws "Company group has no active Cost Center dimension"; - AC4 void a Posted row → a second Posted journal whose line amounts are
the exact negation, dimensions copied, status
Voided; voiding it AGAIN returns the samejournalIdand writes nothing; - posting a
Voidedrow → throws "Cannot post reimbursement in status Voided"; - a payable account whose class is not
Liability→ throws; - dimension union + de-duplication: a line carrying
costCenterId = XAND areimbursementLineDimensionrow for the SAME Cost Center dimension with valueYproduces exactly ONEjournalLineDimensionrow for that dimension, carryingY(the generic table wins); a line carrying only the legacy column still produces its row; a line carrying a generic dimension with no legacy counterpart produces its row; - an inactive or out-of-group
dimensionIdon a generic row → throws; - a reimbursement id belonging to another company → "Reimbursement not found".
- AC1 post with two lines → ONE
Verify:
cd packages/database/supabase/functions && deno test --no-lock --no-check post-reimbursement/
# Expected: every test file passes — "ok | N passed | 0 failed", N >= 15
# (build-reimbursement-journal + handler + transaction).
Out of scope: No live-database tests (deno task test:db is a separate
lane). Do not modify the post-charge tests.
Task 11: Dimension data plumbing for the line editor
Depends on: Task 2
Files:
- Modify:
apps/erp/app/modules/invoicing/ui/Reimbursement/index.ts— re-export the shared dimension types (Task 15 creates this file; if it does not exist yet, create it here with just these exports) - Copy from (precedent):
apps/erp/app/routes/x+/journal-entry+/$journalEntryId.tsx:68-72— the loader callgetActiveDimensionsWithValues(client, companyGroupId, companyId)inside thePromise.all, and line 120dimensions: dimensions.data ?? [] - Copy from (precedent):
apps/erp/app/modules/accounting/ui/JournalEntries/types.ts:10-23—DimensionWithValuesandJournalLineDimensionValue - Copy from (precedent):
apps/erp/app/routes/x+/journal-entry+/$journalEntryId.details.tsx:48— the submit shapedimensions?: Array<{ dimensionId: string; valueId: string }>
Steps:
- This task replaces an earlier
Projectpicker task. That task existed because the line editor needed aprojectIdcombobox that does not exist inapps/erp/app/components/Form/. It is no longer needed:DimensionSelectoralready handles Project and CostCenter as dimension entity types (both appear in itsentityTypeColorsmap), so the editor needs dimension data, not new pickers. Do not buildapps/erp/app/components/Form/Project.tsx,getProjectsList, orapi+/accounting.projects.ts— they would be dead code. - Confirm the existing reader is reusable as-is:
getActiveDimensionsWithValues(client, companyGroupId, companyId)inapps/erp/app/modules/accounting/accounting.service.ts. It is company-GROUP scoped with a company argument, which is exactly what the reimbursement detail routes have fromrequirePermissions. Add no new service function. If its signature differs from the journal-entry call site, STOP and report rather than writing a parallel reader. - The two types the editor passes around (
DimensionWithValues,JournalLineDimensionValue) live inapps/erp/app/modules/accounting/ui/JournalEntries/types.ts. Import them from there rather than redefining them — a second copy would drift fromDimensionSelector's own props and the mismatch would only show at a call site. If a shared home is wanted later that is a follow-up, not this task. - Record the contract the next three tasks depend on, so they cannot disagree:
- the detail and edit loaders (Tasks 16, 17) add
getActiveDimensionsWithValues(...)to theirPromise.alland returndimensions: dimensions.data ?? []; - the editor (Task 13) takes
availableDimensions: DimensionWithValues[]and holds each line's current pairs asJournalLineDimensionValue[]; - the hidden JSON field carries only
dimensions: Array<{ dimensionId, valueId }>per line — the display names inJournalLineDimensionValueare client-side only and must be stripped on submit, exactly as$journalEntryId.details.tsx:48expects.
- the detail and edit loaders (Tasks 16, 17) add
Verify:
grep -n "getActiveDimensionsWithValues" apps/erp/app/modules/accounting/accounting.service.ts apps/erp/app/routes/x+/journal-entry+/\$journalEntryId.tsx && grep -n "DimensionWithValues\|JournalLineDimensionValue" apps/erp/app/modules/accounting/ui/JournalEntries/types.ts && ls apps/erp/app/components/Form/Project.tsx 2>&1 | tail -1
# Expected: getActiveDimensionsWithValues is defined in accounting.service.ts
# and called in the journal-entry loader; both types are exported from the
# JournalEntries types file; and the `ls` prints "No such file or directory"
# for Project.tsx — confirming the dead picker was NOT built.
Out of scope: Do not build a Project or Cost Center picker. Do not add a new dimensions service function or API route. Do not move the shared types.
Task 12: Shared DocumentSourceBadge component
Depends on: Task 2
Files:
- Create:
apps/erp/app/components/DocumentSourceBadge.tsx - Modify:
apps/erp/app/components/index.ts— import + exportDocumentSourceBadge - Modify:
packages/ee/src/ramp/config.tsx— theLogostyle clamp (lines 233–262) - Copy from (precedent, THE BADGE):
apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceHeader.tsxlines 84–96 (reading the mapping off route data) and lines 334–345 (the existing Ramp source badge — a<Status color="blue">optionally wrapped in a deep link) - Copy from (precedent, THE LOGO):
apps/erp/app/modules/settings/ui/Integrations/IntegrationCard.tsx:77—<integration.logo className="h-10 w-auto" />
Steps:
- Context you need before writing this. There is no reusable
<IntegrationLogo>/<ProviderLogo>component in the repo — the logo is aReact.FC<ComponentProps<"svg">>field on each integration config (packages/ee/src/types.ts:155-190), looked up withgetIntegrationConfigById(id)(packages/ee/src/index.ts:67-69). The only existing source badge is text-only. This task creates the reusable one that both this plan and the sibling charge spec need. - Bundle safety (read before worrying about it).
@carbon/ee's barrel is already imported into the ERP client bundle byapps/erp/app/routes/x+/settings+/integrations.tsx(import { integrations as availableIntegrations } from "@carbon/ee"), so the config chain is proven client-safe. Importing it into an invoicing component adds it to that route's bundle but introduces no server-only module. Do not attempt a logo-extraction refactor of all twelve providers to avoid this — it is out of scope and the sibling spec does not ask for it. - Fix the Ramp logo's size clamp first.
packages/ee/src/ramp/config.tsxlines ~251–257 currently spread...props.styleBEFORE hard-codedheight: "1.25rem", so the clamp wins and a caller cannot make the logo badge-sized. Invert the order so an incoming style overrides the default:
Keep the existing comment, amended to say the defaults are overridable. If any other integration'sstyle={{ height: "1.25rem", width: "auto", maxWidth: "100%", ...props.style }}Logohas the same inverted clamp, leave it alone — only Ramp is needed here, and changing twelve logos is a different change. - Write the component. It is document-agnostic — it takes strings, not a
reimbursement — because the charge detail page uses the same one:
Body:type DocumentSourceBadgeProps = { /** The provider id stored on the document, e.g. `charge.integration`. */ integration: string | null | undefined; /** The provider's own identifier, from externalIntegrationMapping.externalId. */ externalId?: string | null; /** externalIntegrationMapping.metadata.deepLink, when the provider has one. */ deepLink?: string | null; /** Renders the label above the badge. Defaults to "Source". */ label?: ReactNode; };const config = integration ? getIntegrationConfigById(integration as IntegrationID) : undefined;- Render nothing (
return null) whenintegrationis falsy — a document with no provider has no SOURCE field. - When
configresolves, render<config.logo style={{ height: "0.875rem" }} />next toconfig.name; when it does not (an unknown provider id), fall back to the raw id in a<Status color="blue">so the field is never blank — an unrecognised provider is data, not a crash. - Beneath, render
externalIdintext-xs text-muted-foreground font-monowhen present. - Wrap the whole thing in
<a href={deepLink} target="_blank" rel="noreferrer">whendeepLinkis set, exactly asPurchaseInvoiceHeader.tsx:334-345does.
- Register it in
apps/erp/app/components/index.tsalongsideDocumentHeader(line 13 import / line 71 export).
Verify:
pnpm exec turbo run typecheck --filter=erp --filter=@carbon/ee && grep -n "DocumentSourceBadge" apps/erp/app/components/index.ts && grep -n -A 6 'style={{' packages/ee/src/ramp/config.tsx | grep -n "props.style" && git status --short packages/database/
# Expected: both typechecks exit 0; the components index grep shows the import
# and the export; the config grep shows `...props.style` appearing AFTER the
# height/width/maxWidth defaults (if it still appears first, step 3 was not
# applied); git status prints nothing for packages/database/.
Out of scope: Do not wire this into the charge UI — that is the sibling
spec's work. Do not refactor other providers' Logo components. Do not add a
ramp entry to INTEGRATION_LABELS in
apps/erp/app/modules/accounting/ui/SyncTieOut/SyncTieOutTable.tsx — that map
is the tie-out surface's own, and this badge replaces the need for it here.
Task 13: Shared DocumentLineEditor component
Depends on: Task 11
Files:
- Create:
apps/erp/app/components/DocumentLineEditor/DocumentLineEditor.tsx - Create:
apps/erp/app/components/DocumentLineEditor/DocumentLineRow.tsx - Create:
apps/erp/app/components/DocumentLineEditor/types.ts - Create:
apps/erp/app/components/DocumentLineEditor/index.ts - Copy from (precedent, CONTAINER):
apps/erp/app/modules/accounting/ui/JournalEntries/JournalEntryForm.tsx—generateId/createEmptyLine(72–85), theuseStateinitialiser (111–119),handleLineChange/handleDeleteLine/handleAddLine(139–159),linesJson(161–172), the hidden field<input type="hidden" name="lines" value={linesJson} />(280), the running totals +<Status color="green">Balanced</Status>badge, and the grid header / rows / totals block (312–400) - Copy from (precedent, ROW):
apps/erp/app/modules/accounting/ui/JournalEntries/JournalLineRow.tsx(151 lines — the fully-controlledonChange({ ...line, field })style,AccountControlled, a rawInput, andNumberField+NumberInputwithINPUT_FORMATfromuseCurrencyDecimals(currencyCode)) - Copy from (precedent, TYPES):
apps/erp/app/modules/accounting/ui/JournalEntries/types.ts(ClientJournalLine)
Steps:
Why here and not in the invoicing module. The shared spec requires one line editor for charges AND reimbursements, so it lives in
apps/erp/app/components/(the repo's home for components two modules share, e.g.Activity.tsx,DocumentHeader.tsx). It must know nothing about either document.types.ts:import type { JournalLineDimensionValue } from "~/modules/accounting/ui/JournalEntries/types"; export type ClientDocumentLine = { /** Client-only row key. Never sent to the server. */ key: string; /** Persisted line id when the row came from the database; absent for a new row. */ id?: string; accountId: string; description: string; amount: number | null; /** * Generic dimension pairs, edited through DimensionSelector. Carries the * display names client-side; only {dimensionId, valueId} is submitted. */ dimensions: JournalLineDimensionValue[]; /** * The two legacy columns. The EDITOR does not write them — the Ramp sync * does, and posting unions them with `dimensions`. They ride along * read-only so a round-trip through the editor cannot drop what the sync * imported. */ costCenterId: string | null; projectId: string | null; };DocumentLineRow.tsx— props mirrorJournalLineRow's fully-controlled shape:type DocumentLineRowProps = { line: ClientDocumentLine; index: number; currencyCode: string; availableDimensions: DimensionWithValues[]; /** Collapsed rows show account + amount only; expanded adds the rest. */ isExpanded: boolean; onToggleExpand: () => void; onChange: (line: ClientDocumentLine) => void; onDelete: () => void; canDelete: boolean; isDisabled: boolean; };Cells, collapsed:
<AccountControlled>(from~/components/Form), a plain<Input size="sm">for description, and a<NumberField><NumberInput/></NumberField>for amount withformatOptions={INPUT_FORMAT.money(currencyCode, currencyDecimals)}andstep={INPUT_STEP.money(currencyDecimals)}fromuseCurrencyDecimals(currencyCode). A digit or step literal here is ano-inline-fraction-digits/ precision violation — take both from the helpers. TrailingIconButtondelete, and aLuChevronRightexpand toggle in the leading cell (the collapsible-row patternPurchaseInvoiceSummary.tsx:41-55uses).Expanded adds the existing
DimensionSelector, not a picker per concept:{availableDimensions.length > 0 && ( <DimensionSelector journalLineId={line.key} availableDimensions={availableDimensions} currentDimensions={line.dimensions} onChange={(dimensions) => onChange({ ...line, dimensions })} autoSave={false} /> )}Copy the mount verbatim from
JournalLineRow.tsx:92-97— including theavailableDimensions.length > 0guard, which is what stops an empty selector rendering for a company that has configured no dimensions.Two things to know about that component. Its
journalLineIdprop is named for its origin, not its meaning — withautoSave={false}it is only an identity for the control, so passing the line's clientkeyis correct. Read its body first to confirm that; ifjournalLineIdis used for anything beyond identity on the non-autoSave path, STOP and report rather than passing a fake id into a fetcher. And it sources the high-cardinality types (Customer, Supplier, Item) from the client stores itself, so the editor supplies nothing for them.Do not build a Cost Center or Project combobox.
DimensionSelectoralready covers both as entity types, along with Department, Location, Employee, Work Center, Process, Item Posting Group, Supplier Type and the rest — that is the whole reason the spec reuses it.DocumentLineEditor.tsx:type DocumentLineEditorProps = { /** The form field name for the hidden JSON payload. Defaults to "lines". */ name?: string; initialLines: ClientDocumentLine[]; currencyCode: string; /** From getActiveDimensionsWithValues in the route loader (Task 11). */ availableDimensions: DimensionWithValues[]; /** The document header amount the lines must sum to. */ headerAmount: number; isDisabled?: boolean; /** Notified on every change so the page header can show the running total. */ onTotalChange?: (total: number, isBalanced: boolean) => void; };useState<ClientDocumentLine[]>seeded frominitialLines, falling back to onecreateEmptyLine()when empty.handleAddLine/handleLineChange(index, line)/handleDeleteLine(index);canDeleteislines.length > 1(the document must always have at least one coding line —requireLineSumin Task 8 throws on zero).+ Add line itembuttons at both top and bottom of the card, per the shared spec.- Derived
total = Σ (line.amount ?? 0)andisBalanced = Math.abs(total - headerAmount) < 0.01— the same 0.01 thresholdJournalEntryFormuses and the same onebuild-reimbursement-journal'sBALANCE_TOLERANCEuses, so the UI and the edge function agree. Render a<Status color={isBalanced ? "green" : "red"}>reading Balanced / Unbalanced in the card header, and callonTotalChange(total, isBalanced)in auseEffectso the page header can mirror it. - Emit the single hidden field:
where<input type="hidden" name={name ?? "lines"} value={linesJson} />linesJsonmaps each row to{ id, accountId, costCenterId, projectId, description, amount, dimensions: line.dimensions.map(({ dimensionId, valueId }) => ({ dimensionId, valueId })) }. Note it dropskey(client-only) and strips the dimension display names —JournalLineDimensionValuecarriesdimensionName/valueNamefor rendering, and the server contract is only the id pair, exactly as$journalEntryId.details.tsx:48declares. - React key is
line.key, never the array index (re-ordering would move rows under the cursor).
index.tsre-exports the component and the type. Do not add it toapps/erp/app/components/index.ts— it is a directory component imported by path, like~/components/LineReorder.
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm exec biome check apps/erp/app/components/DocumentLineEditor/ && grep -rn "minimumFractionDigits\|maximumFractionDigits\|step={0\." apps/erp/app/components/DocumentLineEditor/ ; grep -rn "DimensionSelector" apps/erp/app/components/DocumentLineEditor/ ; git status --short packages/database/
# Expected: typecheck exits 0; biome reports no errors; the precision grep
# prints NOTHING (any hit is a no-inline-fraction-digits violation — take the
# digits from INPUT_FORMAT and the step from INPUT_STEP); the DimensionSelector
# grep DOES print a match (the editor must reuse it, not reimplement pickers);
# git status prints nothing for packages/database/.
Out of scope: Do not wire this into the charge UI (sibling spec). Do not add
line reordering (~/components/LineReorder) — sequence follows array order
and reordering coding lines changes nothing about the journal. No per-line
child routes. Do not modify DimensionSelector itself; if it needs a change to
be reusable here, STOP and report — it is live on journal entries.
Task 14: path.to entries for reimbursements
Depends on: Task 5
Files:
- Modify:
apps/erp/app/utils/path.ts - Copy from (precedent): the same file, lines 1460–1468 — the
memoblock (memo,memoDelete,memoNew,memoPost,memoVoid) and line 564 (creditMemos: \${x}/invoicing/credit-memos`). That is the established split: the LIST sits under/x/invoicing/`, the full-page DOCUMENT sits at its own top level.
Steps:
- Add, in the same block style as the memo entries and with an equivalent
explanatory comment:
and, next to// Reimbursements — employee expense payables imported from a spend tool. // The list lives under invoicing (it is an AP nav entry); the document is a // full page of its own, because the coding-line editor does not fit the // Drawer detail convention (see // .ai/specs/2026-09-23-editable-imported-spend-documents.md). reimbursement: (id: string) => generatePath(`${x}/reimbursements/${id}`), reimbursementEdit: (id: string) => generatePath(`${x}/reimbursements/${id}/edit`), reimbursementPost: (id: string) => generatePath(`${x}/reimbursements/${id}/post`), reimbursementVoid: (id: string) => generatePath(`${x}/reimbursements/${id}/void`),creditMemos(line 564):reimbursements: `${x}/invoicing/reimbursements`, - There is deliberately no
reimbursementNewand noreimbursementDelete: a reimbursement is never hand-created, and a Draft that should not exist is a sync problem, not a user action.
Verify:
grep -n "reimbursement" apps/erp/app/utils/path.ts && pnpm exec turbo run typecheck --filter=erp && git status --short packages/database/
# Expected: the grep prints exactly five entries — reimbursement,
# reimbursementEdit, reimbursementPost, reimbursementVoid, reimbursements.
# It must NOT print reimbursementNew or reimbursementDelete.
# typecheck exits 0; git status prints nothing for packages/database/.
Out of scope: Do not rename or move any existing path.
Task 15: ReimbursementStatus + ReimbursementsTable
Depends on: Tasks 5, 14
Files:
- Create:
apps/erp/app/modules/invoicing/ui/Reimbursement/ReimbursementStatus.tsx - Create:
apps/erp/app/modules/invoicing/ui/Reimbursement/ReimbursementsTable.tsx - Create:
apps/erp/app/modules/invoicing/ui/Reimbursement/index.ts - Modify:
apps/erp/app/modules/invoicing/ui/index.ts— addexport * from "./Reimbursement"; - Copy from (precedent):
apps/erp/app/modules/invoicing/ui/Charge/ChargeStatus.tsx(21 lines, verbatim shape) andapps/erp/app/modules/invoicing/ui/Charge/ChargesTable.tsx(149 lines) andCharge/index.ts
Steps:
ReimbursementStatus.tsx— cloneChargeStatus.tsxexactly, typing the prop as(typeof reimbursementStatus)[number] | nulland keeping the same colour mapping (Draftgray,Postedgreen,Voidedred).ReimbursementsTable.tsx— cloneChargesTable.tsx, changing:type ReimbursementRow = Database["public"]["Tables"]["reimbursement"]["Row"]- Columns:
reimbursementId(Hyperlink topath.to.reimbursement(row.original.id),meta.icon: <LuHash />, pinned left);status(static filter overreimbursementStatus,pluralHeader: t\Statuses`);employeeIdrendered withfrom~/components(it takesemployeeId: string | nulland resolves the name throughusePeople(), andemployee.idIS the user id — so this works directly);reimbursementDate(formatDate(value, undefined, locale));reference;amount(per-row currency viauseCurrencyDecimalsLookup()+formatMoney(amount, locale, code, currencyDecimals(code))— never a cross-currency total);journalId` (hidden by default). title={t\Reimbursements`,table="reimbursement",withSavedView,defaultColumnPinning={{ left: ["reimbursementId"] }},defaultColumnVisibility={{ journalId: false }}`.- No "New" action button.
ChargesTablehas none for the same reason: the document is never hand-created. - Default sort is
reimbursementIddescending, whichgetReimbursementsalready applies — but the shared spec's "drafts pile up unreviewed" risk means Draft rows must be findable, so ALSO set the status column's default filter chip to none and leave sorting alone. Do not invent a "Drafts first" sort; it is not in either spec.
Reimbursement/index.ts:export { default as ReimbursementStatus } from "./ReimbursementStatus"; export { default as ReimbursementsTable } from "./ReimbursementsTable";- Add
export * from "./Reimbursement";toui/index.ts, alphabetically after./PurchaseInvoice.
Verify:
pnpm exec turbo run typecheck --filter=erp && grep -n "Reimbursement" apps/erp/app/modules/invoicing/ui/index.ts && git status --short packages/database/
# Expected: typecheck exits 0; the barrel grep shows
# `export * from "./Reimbursement";`; git status prints nothing for
# packages/database/.
Out of scope: No form here. Do not touch ChargesTable.tsx.
Task 16: Reimbursement detail — read mode
Depends on: Tasks 5, 12, 14, 15
Files:
- Create:
apps/erp/app/routes/x+/invoicing+/reimbursements.tsx— the list - Create:
apps/erp/app/routes/x+/reimbursements+/_layout.tsx - Create:
apps/erp/app/routes/x+/reimbursements+/$reimbursementId.tsx— read mode - Create:
apps/erp/app/modules/invoicing/ui/Reimbursement/ReimbursementSummary.tsx - Modify:
apps/erp/app/modules/invoicing/ui/Reimbursement/index.ts— export it - Copy from (precedent, LIST):
apps/erp/app/routes/x+/invoicing+/charges.tsx(73 lines) - Copy from (precedent, LAYOUT):
apps/erp/app/routes/x+/credits+/_layout.tsx(19 lines) - Copy from (precedent, PAGE FRAME):
apps/erp/app/routes/x+/journal-entry+/$journalEntryId.tsx— the plain centeredmax-w-5xlpage. Use this, NOT the purchase-invoice three-panePanelProvider+ResizablePanelsframe — this document has one card and a line list, not an explorer and a properties rail. - Copy from (precedent, LINES TABLE):
apps/erp/app/routes/x+/invoicing+/charges.$id.tsxlines 186–225 (the read-only account / cost center / description / amount table) - Copy from (precedent, MAPPING READ):
apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.tsxlines 85–94 — the inlineexternalIntegrationMapping.maybeSingle()read in a loader
Steps:
invoicing+/reimbursements.tsx— clonecharges.tsx:handle = { breadcrumb: "Reimbursements", to: path.to.reimbursements, module: "invoicing" }; loaderrequirePermissions(request, { view: "invoicing" }), readssearch,status,employeeIdfromsearchParamsplusgetGenericQueryFilters, callsgetReimbursements, redirects topath.to.invoicingwith a flash on error; default export renders<ReimbursementsTable data count />in a<VStack spacing={0} className="h-full">. No<Outlet />— unlikecharges.tsx, the detail is a separate full page, not a Drawer child.reimbursements+/_layout.tsx— clonecredits+/_layout.tsx:metatitle"Carbon | Reimbursements",handle = { breadcrumb: "Invoicing", to: path.to.invoicing, module: "invoicing" }, renders<Outlet />.$reimbursementId.tsxloader —requirePermissions(request, { view: "invoicing" }), then aPromise.allof:getReimbursement(client, companyId, id)(redirect topath.to.reimbursementswith a flash on error);- the account lookup for the header + every line, ONE query not N+1 —
client.from("account").select("id, number, name").eq("companyGroupId", companyGroupId).in("id", [...new Set(accountIds)]), exactly ascharges.$id.tsx:60-72does; - the provider mapping, copied from
purchase-invoice+/$invoiceId.tsx:85-94with the entity type changed:
Keep that file's comment about falling back toclient .from("externalIntegrationMapping") .select("id, externalId, metadata") .eq("companyId", companyId) .eq("integration", "ramp") .eq("entityType", "reimbursement") .eq("entityId", id) .maybeSingle()nullsilently when RLS denies or no mapping exists — the badge must degrade, not throw."reimbursement"is the entityType Task 23 writes; if Task 23 has not run yet this simply returns null and the badge shows the provider without an external id. - the journal, when
journalIdis set (charges.$id.tsx:74-86); getActiveDimensionsWithValues(client, companyGroupId, companyId)(Task 11's contract) — read mode renders the line dimensions as badges, and the edit route (Task 17) needs the same list, so both loaders fetch it.
ReimbursementSummary.tsx— a<Card>whoseCardHeadercarries thereimbursementIdasCardTitle, the<ReimbursementStatus>, an<EmployeeAvatar employeeId={reimbursement.employeeId} />, and — in a labelled field to the right —<DocumentSourceBadge integration={reimbursement.integration} externalId={mapping?.externalId} deepLink={mapping?.metadata?.deepLink} />from Task 12.CardContentholds a<dl>of date / amount / currency / reference / journal link (thecharges.$id.tsx:139-184block) and the read-only lines table (charges.$id.tsx:186-225). Each line's dimensions render as read-only badges — reuse the colour map and badge shape fromDimensionSelector.tsx(entityTypeColors/getColor) so a dimension looks the same in read mode and edit mode. Resolve every id to a NAME:charges.$id.tsx:210rendersline.costCenterId ?? "—", which shows a raw id to the user and is a defect worth not copying. The generic pairs already carrydimensionName/valueNamefromgetActiveDimensionsWithValues; the two legacy columns resolve through the same dimension list.No Activity component. An earlier draft of this plan built a
ReimbursementActivity.tsxthat derived an "imported from Ramp" row from animportedAtcolumn. The spec has since dropped the activity/timeline surface entirely: Carbon has no generic activity table, the audit log is the real document history, and building one to match the reference screenshots would invent a subsystem for a decoration. The SOURCE badge carries the provenance on its own. Do not create an Activity component, and do not add animportedAtcolumn.Do still mount the real history: the audit-log trigger + drawer via
useAuditLog({ entityType: "reimbursement", entityId: id, companyId, variant: "card-action" }), followingPurchaseInvoiceHeader.tsx:63. Note the two-part contract —triggergoes in the card header,drawermust be mounted at component root (the hook's own comment explains why).Default export: the page frame from
journal-entry+/$journalEntryId.tsx— a centeredmax-w-5xlcolumn holding<ReimbursementSummary>, plus a header action bar with Edit (link topath.to.reimbursementEdit(id), rendered only whenstatus === "Draft"andpermissions.can("update", "invoicing")), Post (Task 18) and Void (Task 18).
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm exec biome check apps/erp/app/routes/x+/reimbursements+/ apps/erp/app/routes/x+/invoicing+/reimbursements.tsx apps/erp/app/modules/invoicing/ui/Reimbursement/ && git status --short packages/database/
# Expected: typecheck exits 0; biome reports no errors; git status prints
# nothing for packages/database/.
Out of scope: No editing here (Task 17). Do not use Response.json(...) —
return plain objects or data(value, init). Do not create an activity table,
an Activity component, or an importedAt column — the spec drops that surface.
Task 17: Reimbursement detail — edit mode
Depends on: Tasks 6, 13, 16
Files:
- Create:
apps/erp/app/routes/x+/reimbursements+/$reimbursementId.edit.tsx - Create:
apps/erp/app/modules/invoicing/ui/Reimbursement/ReimbursementEditForm.tsx - Modify:
apps/erp/app/modules/invoicing/ui/Reimbursement/index.ts— export the form - Copy from (precedent, FORM + HIDDEN-JSON SUBMIT):
apps/erp/app/modules/accounting/ui/JournalEntries/JournalEntryForm.tsx— one<ValidatedForm>wrapping a Details card and a Lines card, the hiddenlinesfield, the header-level running total, and thename="intent"submit buttons - Copy from (precedent, ACTION):
apps/erp/app/routes/x+/journal-entry+/$journalEntryId.details.tsx— readingformData.get("lines"), theJSON.parseinside try/catch that flashes"Invalid lines data"rather than throwing, and the validate-then-save sequence - Copy from (precedent, LOCK GUARD):
apps/erp/app/utils/lockedGuard.server.ts(requireUnlocked({ request, isLocked, redirectTo, message })) and its use inapps/erp/app/routes/x+/purchase-invoice+/$invoiceId.details.tsx
Steps:
- Loader —
requirePermissions(request, { update: "invoicing" }), load the reimbursement ANDgetActiveDimensionsWithValues(client, companyGroupId, companyId)(Task 11's contract), thenrequireUnlocked({ request, isLocked: isReimbursementLocked(reimbursement.status), redirectTo: path.to.reimbursement(id), message: "A posted reimbursement cannot be edited" }). This is what makes spec AC "A Posted reimbursement is not editable" true for a direct URL, not just a hidden button. The RLS policy and thereimbursement_draft_guardtrigger are the backstops behind it. - Action:
assertIsPost;requirePermissions(request, { update: "invoicing" }); readformDataONCE.const intent = formData.get("intent") as string;—"save"or"save-and-post".validator(reimbursementUpdateValidator).validate(formData)→validationErroron failure.- Re-read the row and hard-guard
existing.status !== "Draft"before any write, returning a flash (thecredits+/$memoId.tsx:87-92guard) — a readable message beats a raw 55000 from the trigger. - Parse the lines:
JSON.parse(formData.get("lines") as string)inside try/catch → on failurereturn data({}, await flash(request, error(null, "Invalid lines data"))); thenreimbursementLinesValidator.safeParse(parsed)→validationError- equivalent flash on failure. await updateReimbursement(client, { ...validation.data, companyId, updatedBy: userId, customFields: setCustomFields(formData) }).await upsertReimbursementLines(getDatabaseClient(), { reimbursementId: id, companyId, createdBy: userId, lines })—getDatabaseClientis imported from~/services/database.server. A route may import a.servermodule; the service file may not, which is why the client is built here and passed in (no-db-client-in-service). Wrap it in try/catch and flash the thrown message, followingpayments+/$paymentId.applications.set.tsx:88-103.- The totals guard: before doing anything for
intent === "save-and-post", recomputeΣ lines.amountand compare tovalidation.data.amountwith the same< 0.01tolerance the editor uses. On a mismatch, flash"The coding lines must sum to the reimbursement amount before posting"and redirect back to the edit page without calling the edge function — the shared spec requires the refusal to happen "before any edge-function call". - On success:
intent === "save"redirects topath.to.reimbursement(id)withsuccess("Reimbursement updated");"save-and-post"falls through to the Post action's logic (call the same helper Task 18 extracts, do not duplicate the invoke).
ReimbursementEditForm.tsx— props{ initialValues: z.infer<typeof reimbursementUpdateValidator>; initialLines: ClientDocumentLine[]; status: string }. One<ValidatedForm method="post" validator={reimbursementUpdateValidator} defaultValues={initialValues}>containing:- a Details card —
<DatePicker name="reimbursementDate">,<Currency name="currencyCode">,<Number name="amount" formatOptions={INPUT_FORMAT.money(currencyCode, currencyDecimals)} step={INPUT_STEP.money(currencyDecimals)}>,<Input name="reference">,<TextArea name="notes">,<CustomFormFields table="reimbursement" />,<Hidden name="id" />,<Hidden name="exchangeRate" />. The employee and the readable id are displayed, not editable — they are not in the validator. - a Line items card rendering
<DocumentLineEditor initialLines={initialLines} currencyCode={currencyCode} availableDimensions={dimensions} headerAmount={amount} onTotalChange={setTotals} />from Task 13. - the running total in the page header, driven by
onTotalChange, with the Balanced / Unbalanced<Status>. - footer:
Cancel(link back topath.to.reimbursement(id)),Save(name="intent" value="save"), andSave and post(name="intent" value="save-and-post",isDisabledwhile unbalanced).
- a Details card —
initialLinesis mapped in the route component fromreimbursement.reimbursementLinesorted bysequence, assigning each row a fresh clientkey, and hydratingdimensionsfrom the embeddedreimbursementLineDimensionrows — joined againstavailableDimensionsto fill thedimensionName/valueNamethe badges render. ExtendgetReimbursement's select in Task 5 to embed them (reimbursementLine(*, reimbursementLineDimension(*))) rather than issuing a second query per line (.claude/rules/database-patterns.md— never query in a loop). The two legacy columns ride along onClientDocumentLineuntouched.
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm exec biome check apps/erp/app/routes/x+/reimbursements+/ apps/erp/app/modules/invoicing/ui/Reimbursement/ && grep -n "getDatabaseClient" apps/erp/app/routes/x+/reimbursements+/\$reimbursementId.edit.tsx && git status --short packages/database/
# Expected: typecheck exits 0; biome reports no errors; the grep shows
# getDatabaseClient imported from ~/services/database.server and called at the
# upsertReimbursementLines call site (the client must be built in the ROUTE,
# not the service); git status prints nothing for packages/database/.
Out of scope: No create path. No per-line delete endpoint. Do not make the employee or the readable id editable.
Task 18: Post + Void action routes, with the totals guard
Depends on: Tasks 9, 14, 16
Files:
- Create:
apps/erp/app/routes/x+/reimbursements+/$reimbursementId.post.tsx - Create:
apps/erp/app/routes/x+/reimbursements+/$reimbursementId.void.tsx - Create:
apps/erp/app/modules/invoicing/reimbursement.server.ts— the shared post helper (a.serverfile, not barrel-exported) - Copy from (precedent):
apps/erp/app/routes/x+/credits+/$memoId.post.tsx(whole file, 47 lines — including the(result.data as { message?: string })?.message ?? result.error.messageunwrap, which matters because a Supabase edge function puts its useful text in the body, noterror.message) andcharges.$id.void.tsx(46 lines) - Copy from (precedent,
.serverplacement):apps/erp/app/modules/invoicing/stripe-customer.server.ts— an in-module.server.tsthatinvoicing/index.tsdeliberately does not re-export
Steps:
reimbursement.server.ts— one exported helper so the Post route and Task 17'ssave-and-postintent cannot drift:export async function postReimbursement(args: { reimbursementId: string; companyId: string; userId: string; }): Promise<{ error: string | null }>;Body:
getCarbonServiceRole().functions.invoke("post-reimbursement", { body: { type: "post", ...args } }), returning the unwrapped message on failure and{ error: null }on success. This file is not added toapps/erp/app/modules/invoicing/index.ts.On success it also settles a deferred Ramp payout. Task 23 step 5 records an already-paid Ramp reimbursement's payout intent on the
externalIntegrationMappingmetadata ({ rampPaymentId, paidAt, bankAccountId }) instead of creating a payment at import, because a Draft cannot be settled. So after the edge function reports success, this helper reads that metadata and — when present and not already settled — creates thepayment(Disbursement,employeeId, the recorded bank account,paidAt, and the preserved source FX, never a re-derived rate) plus itsinvoiceSettlementwithtargetReimbursementId, then clears the intent from the metadata so a re-post cannot double-pay. Reuse Task 22's settlement path rather than writing the rows by hand.Make that step idempotent and non-fatal: a failure to record the payout must NOT unwind the successful post (the journal is already written). Flash a warning naming the reimbursement and leave the intent on the metadata so it can be retried.
$reimbursementId.post.tsx—assertIsPost;requirePermissions(request, { update: "invoicing" }); then the totals guard, server-side, before the invoke:- read the reimbursement and its lines with
getReimbursement; - refuse a non-Draft status with a flash;
- compute
Σ reimbursementLine.amountand compare againstreimbursement.amountwith the< 0.01tolerance; on mismatch, redirect topath.to.reimbursement(id)flashing"The coding lines must sum to the reimbursement amount before posting"without calling the edge function. - otherwise call
postReimbursement(...)and flash the result. The edge function'srequireLineSumenforces the same invariant, but the shared spec requires the UI to refuse first, with a clear message.
- read the reimbursement and its lines with
$reimbursementId.void.tsx— clonecharges.$id.void.tsxverbatim with the renames:update: "invoicing", invokepost-reimbursementwithtype: "void", redirect topath.to.reimbursement(id)withsuccess("Reimbursement voided"). No totals guard — a void reverses whatever was posted.Wire both into Task 16's header action bar: Post shown only when
status === "Draft", Void only whenstatus === "Posted", both gated onpermissions.can("update", "invoicing"). Void opens theConfirmmodal with the charge drawer's copy ("This posts a reversing journal entry and cannot be undone.",charges.$id.tsx:271-280).
Verify:
pnpm exec turbo run typecheck --filter=erp && grep -n "reimbursement.server" apps/erp/app/modules/invoicing/index.ts ; grep -c "post-reimbursement" apps/erp/app/modules/invoicing/reimbursement.server.ts && git status --short packages/database/
# Expected: typecheck exits 0. The FIRST grep must print NOTHING — the .server
# file must not be barrel-exported (it would reach the client graph). The
# second grep prints 1 — the edge function is invoked in exactly one place, so
# the Post route and the save-and-post intent cannot diverge.
# git status prints nothing for packages/database/.
Out of scope: No delete route. Do not invoke post-reimbursement from
anywhere else in the ERP.
Task 19: Nav entry under Accounts Payable
Depends on: Tasks 16, 17, 18
Files:
- Modify:
apps/erp/app/modules/invoicing/ui/useInvoicingSubmodules.tsx - Copy from (precedent): the same file, the
Chargesentry — the last route in theAccounts Payablegroup
Steps:
- In the
Accounts Payablegroup'sroutesarray, after theChargesentry, append:
Add the icon to the{ name: t`Reimbursements`, to: path.to.reimbursements, icon: <LuWallet />, table: "reimbursement", permission: "invoicing" }react-icons/luimport block at the top of the file. IfLuWalletdoes not exist in the installedreact-iconsversion, pick another from the icons this file already imports (LuBanknote,LuCreditCard,LuReceipt,LuReceiptText— noteLuReceiptis taken by Charges) rather than inventing a name. - Leave the comment above
isRouteVisibleintact — it explains why the entry is gated on permission only and not on a connected spend integration, which applies to reimbursements identically.
Verify:
grep -n "Reimbursements" -B 2 -A 6 apps/erp/app/modules/invoicing/ui/useInvoicingSubmodules.tsx && pnpm exec turbo run typecheck --filter=erp && git status --short packages/database/
# Expected: the grep shows the Reimbursements entry immediately after the
# Charges entry, inside the `Accounts Payable` group; typecheck exits 0;
# git status prints nothing for packages/database/.
Out of scope: Do not reorder the existing AP entries. Do not add a Receivables or Payments entry.
Task 20: Settlement target — models + service
Depends on: Task 5
Files:
- Modify:
apps/erp/app/modules/invoicing/invoicing.models.ts—invoiceSettlementBase(line 446-area),invoiceSettlementValidator(469–486),paymentValidator(401–425) - Modify:
apps/erp/app/modules/invoicing/invoicing.service.ts—getInvoiceSettlements(1490-area),replaceInvoiceSettlements(2483–2670, guard at 2534–2545),getMemoApplications(1694–1757) - Copy from (precedent): the existing
targetMemoIdhandling in all three
Steps:
invoiceSettlementBase— addtargetReimbursementId: zfd.text(z.string().optional())next totargetMemoId.invoiceSettlementValidator's target refine — widen the exactly-one check to four columns and update the message to"Application must target exactly one document (sales invoice, purchase invoice, memo, or reimbursement)".paymentValidator— addemployeeId: zfd.text(z.string().optional())and replace theBoolean(d.customerId) !== Boolean(d.supplierId)refine with an exactly-one-of-three check:
Leave.refine( (d) => [d.customerId, d.supplierId, d.employeeId].filter(Boolean).length === 1, { message: "A payment requires exactly one party (customer, supplier, or employee)", path: ["customerId"] } )memoValidator's party refine alone — a memo has no employee party.getInvoiceSettlements— extend the embed to..., targetReimbursement:targetReimbursementId(reimbursementId)and add the field to the localSettlementtype.replaceInvoiceSettlements— the per-draft guard at 2534–2545 mirrors the edge function's. Add the employee arm: when the payment's party is an employee, the ONLY legal target istargetReimbursementId, anddiscountAmount/writeOffAmountmust be 0 (a reimbursement payout takes no trade discount). Throw"An employee payment targets reimbursements only, without discounts or write-offs".getMemoApplications— theif (s.targetSalesInvoiceId) … else if …chain at 1739–1757 produces a discriminated union; add theelse if (s.targetReimbursementId) → { type: "reimbursement" }arm so the union stays total.
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm --filter erp test -- invoicing.models invoicing.settlements invoicing.application-history && git status --short packages/database/
# Expected: typecheck exits 0; the three invoicing test files pass
# ("Test Files 3 passed"); git status prints nothing for packages/database/.
# If an existing test asserts the OLD two-party payment message, update the
# assertion — do not weaken the validator to satisfy it.
Out of scope: Do not change appliedAmount/sourceAmount/FX semantics.
Do not touch invoiceSettlement_anyComponent_check behaviour.
Task 21: post-payment — reimbursement settlement arm
Depends on: Task 20
Files:
- Modify:
packages/database/supabase/functions/post-payment/post-payment-transaction.ts— the target switch (271–286), the refund prior-rows query (354), the write-back normalization (727–732) - Modify:
packages/database/supabase/functions/post-payment/build-payment-journal.ts— the application-target type (25–27) and switch (188–205) - Modify:
packages/database/supabase/functions/shared/payment-funding.ts—SettlementBalanceRow(236–237) andinvoiceRemainingAmounts(292) - Modify:
packages/database/supabase/functions/post-payment/post-payment.test.ts - Copy from (precedent): the existing
isRefund/targetMemoIdarm in each file
Steps:
post-payment-transaction.ts— introduce anisReimbursementdiscriminator derived from the payment row'semployeeIdbeing non-null, and extend the target-column resolution:
Extend the per-draft rejection so a reimbursement payment carries NO other target, noconst targetColumn = isReimbursement ? "targetReimbursementId" : isRefund ? "targetMemoId" : isAR ? "targetSalesInvoiceId" : "targetPurchaseInvoiceId";memoId/sourcePaymentIdsource, and zerodiscountAmount/writeOffAmount, throwing the existing"Unsupported payment settlement target".- The write-back normalization (727–732) gains
targetReimbursementId: isReimbursement ? application.targetId : nulland the three existing keys each gain&& !isReimbursement. build-payment-journal.ts— a reimbursement payout debits the reimbursement's storedpayableAccountId(which Task 9's post pass writes onto the row) and credits the bank asset — structurally the AP arm with the payables control account swapped. Read the id off the reimbursement row; never re-resolve it by number or name (.ai/lessons.md— "Never resolve a control account by number/name"), and never re-derive it fromaccountDefaultat payment time, because the default may have changed since the document posted. Extend the target-type union with"reimbursement", add the arm, and keepthrow new Error("Invalid payment application target")as the exhaustiveness guard.payment-funding.ts— addtargetReimbursementIdtoSettlementBalanceRowand an arm ininvoiceRemainingAmountsso a reimbursement's remaining balance nets prior applications the way an invoice's does.- Add tests to
post-payment.test.ts: a disbursement to an employee settling a Posted reimbursement in full → one balanced journal (payable debited, bank credited) and a settlement row carrying onlytargetReimbursementId; a partial application leaves the correct remaining balance; a reimbursement payment carrying adiscountAmount→ throws.
Verify:
cd packages/database/supabase/functions && deno test --no-lock --no-check post-payment/ shared/payment-funding.test.ts
# Expected: "ok | N passed | 0 failed" — every pre-existing post-payment and
# payment-funding test still passes, plus the three new reimbursement cases.
# If a pre-existing test now fails, the arm was added in the wrong place —
# STOP and report rather than relaxing the assertion.
Out of scope: Do not change the AR, AP, or refund arms' behaviour. Do not
touch post-memo.
Task 22: Payment UI — Pay expense modal, employee payee, reimbursement apply target
Depends on: Task 20
Files:
- Create:
apps/erp/app/modules/invoicing/ui/Reimbursement/PayExpenseModal.tsx - Create:
apps/erp/app/routes/x+/reimbursements+/$reimbursementId.pay.tsx - Modify:
apps/erp/app/utils/path.ts— addreimbursementPay: (id) => \${x}/reimbursements/${id}/pay`` - Modify:
apps/erp/app/modules/invoicing/ui/Payment/PaymentForm.tsx— employee payee option - Modify:
apps/erp/app/modules/invoicing/ui/Payment/PaymentApplyTable.tsx— seeding (173–176) and theonSavepayload (472–486) - Modify:
apps/erp/app/modules/invoicing/ui/Payment/PaymentApplications.tsx— target resolution (47–49, 63–65, 84–86) and the link branch (175–190) - Modify:
apps/erp/app/routes/x+/payments+/$paymentId.tsx— load the employee's open reimbursements when the payment's party is an employee - Copy from (precedent): the
isRefund/ memo branch already threaded through all three components
Steps:
The
Pay expensemodal (spec: "Payout — the Pay expense modal"). An action on the detail page of a Posted, not-fully-paid reimbursement opens a small modal over aTotal Duedisplay with exactly three inputs:- Amount — defaults to the full balance due but is editable; partial payment is supported, so do not lock it to the balance;
- Date — the payment date;
- Account — the bank/cash account the payout is drawn from.
Those three are a 1:1 match for Rillet's
POST /reimbursements/{id}/payments({amount, date, account_code}), which is what lets Task 26 close the staleUNSUPPORTED_REIMBURSEMENT_PAYMENTwith no impedance — keep the field set exactly these three.Build it from
~/components/Modals+ValidatedForm, cloning the shape of an existing three-field action modal in invoicing (grepapps/erp/app/modules/invoicing/ui/for aModal-suffixed component and copy the nearest; if none exists, clone~/components/Modals'Confirmstructure and add the fields). Use<Number>withINPUT_FORMAT.money(currencyCode, currencyDecimals),<DatePicker>, and the existing bank-account picker the payment form already uses — do not invent a new account selector.$reimbursementId.pay.tsxis the action: validate, then create thepayment(paymentType: "Disbursement",employeeId, the chosen bank account, the amount and date) plus oneinvoiceSettlementwithtargetReimbursementId, and post it through the existing payment path. ReusereplaceInvoiceSettlementsrather than writing settlement rows by hand — Task 20 taught it the employee arm. Balance and "fully paid" come from the settlement rows, so do not add apaidAmountcolumn toreimbursement.PaymentForm.tsx— where the form picks a party, add an Employee option rendering<Employee name="employeeId" />(from~/components/Form). Read the existing customer/supplier branch first and mirror its exact conditional shape; only ONE of the three fields may be mounted at a time so the zod refine holds.$paymentId.tsxloader — whenpayment.employeeIdis set, load that employee'sPostedreimbursements with their settled-to-date balance and pass them toPaymentApplyTablein place of the invoice list. Reuse the existing balance query shape (invoicing.service.ts:1878-1890) rather than writing a new one.PaymentApplyTable.tsx— add anisReimbursementbranch:- seeding (173–176):
isReimbursement ? a.targetReimbursementId : … onSave(472–486):targetReimbursementId: isReimbursement ? r.id : undefined, with the existing three keys gated&& !isReimbursement.
- seeding (173–176):
PaymentApplications.tsx— add the reimbursement arm to the target resolution and a fourth link branch rendering<Hyperlink to={path.to.reimbursement(id)}>{reimbursementId}</Hyperlink>.
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm --filter erp test -- PaymentApplyTable PaymentForm && grep -n "reimbursementPay" apps/erp/app/utils/path.ts && grep -cE "name=\"(amount|paymentDate|bankAccount)\"" apps/erp/app/modules/invoicing/ui/Reimbursement/PayExpenseModal.tsx && git status --short packages/database/
# Expected: typecheck exits 0; both component test files pass
# ("Test Files 2 passed"); the path entry exists; the modal field grep prints
# 3 — exactly the three fields Rillet's payments endpoint takes, no more (a
# fourth field means the 1:1 mapping Task 26 relies on has been broken);
# git status prints nothing for packages/database/.
Out of scope: Do not change AR receipt or AP disbursement behaviour for
customers and suppliers. Do not add credit-application
(AvailableCreditsTable) support for reimbursements. Do not add a paidAmount
column — the settlement rows are the source of truth for the balance.
Task 23: Ramp inbound — create a Draft reimbursement; never auto-post, never re-write
Depends on: Tasks 6, 9
Files:
- Modify:
packages/jobs/src/inngest/functions/integrations/ramp-sync-reimbursement.ts(788 lines — this is the real path, notpackages/ee/src/ramp/as both specs say) - Modify:
packages/jobs/src/inngest/functions/integrations/ramp-sync-reimbursement-family.ts— the DI bag built at lines 48–69 - Copy from (precedent, STAGING):
packages/jobs/src/inngest/functions/integrations/ramp-sync-card-stage.ts(177 lines —stageOrResumeRampChargeat line 49: the advisory lock, the mapping lookup,get_next_sequence, the header+lines insert). Do NOT copy its Draft resume at 98–121, which refreshes the header and deletes-then-reinserts the lines — that is exactly the behaviour the spec now forbids (see step 1) - Copy from (precedent, LINE SCALING):
packages/jobs/src/inngest/functions/integrations/ramp-sync-card.ts:187(scaleLinesToTotal)
Steps:
Replace
stageOrResumeRampReimbursementInvoicewithcreateRampReimbursement— note the name: it creates, and never updates. The spec's rule is "provider owns it until it lands; Carbon owns it after". Modelled onstageOrResumeRampChargeexcept for the resume:- advisory lock key
ramp:reimbursement:${companyId}:${rampId}(unchanged); - the
externalIntegrationMappingentity type changes from"bill"to"reimbursement"— this is the value Task 16's loader reads to show the external id in the SOURCE badge, so the two must match exactly; - readable id from
get_next_sequence('reimbursement', companyId); - insert
reimbursementwithstatus: "Draft",integration: "ramp",employeeId,reimbursementDate,postingDate,currencyCode,exchangeRate,amount,reference = RAMP-REIMB-<rampId>,companyId,createdBy: "system". NoimportedAt— that column was removed with the Activity surface; - then
reimbursementLinerows with 0-basedsequence(thechargeLineconvention, and the orderpost-reimbursementreads by) — NOTpurchaseInvoiceLine's 1-basedsortOrder; - and, when the mapping already exists, DO NOTHING. Return the existing row as already-synced. Do not refresh the header, do not touch the lines, do not re-read Ramp's coding. Delete the resume branch rather than narrowing it — a narrowed one invites a later edit to widen it back.
Why this is load-bearing, not housekeeping. The old resume path replaced a Draft's lines on every sweep. That was harmless while nothing was editable, but under the editable model a reviewer codes a Draft, the hourly sweep re-runs, and their work is gone — silently, with no error and no way to tell it happened. The accepted cost, stated in the spec: a provider-side correction made after import (Ramp re-codes the expense) does not flow through; the reviewer sees what originally arrived and can re-edit. That is the right trade, because the alternative destroys human work.
- advisory lock key
Remove the auto-post. Delete the
deps.postInvoicecall and thepostPurchaseInvoicewiring; the row stays Draft. This is the shared spec's one behavioural change and the whole reason an editable moment exists. Do NOT replace it with apost-reimbursementinvoke.Replace
resolveEmployeeSupplier(lines 713–718) with an employee resolution: map the Ramp user to a Carbonemployeethrough the existing employee/user relationship (.claude/rules/user-employee-job-relationships.md—employee.idIS the user id). Resolve by the Ramp user's email againstuser.emailjoined toemployeefor the company. When no employee matches, fail the item visibly with"Reimbursement has no matching Carbon employee — invite <email> as an employee, then retry"— never auto-create an employee and never fall back to a synthetic supplier. That failure path is spec AC5 and the "employee vs user identity confusion" risk row.buildReimbursementLineskeepscodeSelectionsand its account/costCenter/project validation, and must now also applyscaleLinesToTotal(lines, headerAmount, decimals)— the card path does this (ramp-sync-card.ts:187) and the reimbursement path does not.post-reimbursement'srequireLineSumrejects a header/line mismatch outright, and under the Draft model an unbalanced import would block Post with no obvious cause.A Ramp-PAID reimbursement still imports as Draft — confirm at import, record the payout at Post. This is now resolved in the spec, not a plan guess.
The bind:
createOrResumeRampPayment(572–589) creates an AP payment + settlement today, and the family's gating requiresREIMBURSED/REIMBURSED_VIA_PUSHto have a posted settlement before confirming to Ramp. A Draft cannot be settled, so the two cannot both happen at import.The rationale for decoupling them, which belongs in the code comment and not just in this plan: the editable window exists for CODING, not for deciding whether the employee was paid. Whether Ramp already paid the employee is a settled fact about the outside world; which GL accounts the expense hits is the thing a reviewer is being given a chance to correct. Holding the import hostage to the payout would confuse the two.
So:
- Confirm to Ramp at import. Ramp's "synced" means the ERP has the record, which it does.
- Record the payout at Post. The Ramp-paid branch records the payout
intent on the mapping's
metadata({ rampPaymentId, paidAt, bankAccountId }) instead of creating a payment; Task 18's Post helper then creates thepayment+invoiceSettlement— withemployeeId,targetReimbursementIdand the preserved source FX — immediately after the edge function reports success. - The source-FX snapshot must be preserved on that metadata, exactly as the existing resume path preserves it today; re-deriving the rate at Post time would post the payout at a different rate than Ramp used.
ramp-sync-reimbursement-family.ts— update the DI bag: removepostInvoice, renameinvoiceDeepLinkUrl→reimbursementDeepLinkUrlpointing atpath.to.reimbursement(id)(it is what the SOURCE badge'sdeepLinkrenders). ThesyncType: "REIMBURSEMENT_SYNC"confirm stays.validateLegacyDraft(line 89) adopted a legacy Draft purchase invoice bysupplierReference. Delete it. There is no legacyreimbursementrow to adopt (the table is new), and keeping it would let a new sync attach itself to an old employee-supplier invoice. Existing employee-supplier purchase invoices are left exactly as they are — no backfill, no rewrite.
Verify:
pnpm exec turbo run typecheck --filter=@carbon/jobs && pnpm --filter @carbon/jobs test -- ramp-sync-reimbursement && grep -nE "postInvoice|postPurchaseInvoice|updateTable\(\"reimbursement|deleteFrom\(\"reimbursementLine" packages/jobs/src/inngest/functions/integrations/ramp-sync-reimbursement.ts packages/jobs/src/inngest/functions/integrations/ramp-sync-reimbursement-family.ts ; git status --short packages/database/
# Expected: typecheck exits 0; the ramp-sync-reimbursement tests pass — any
# test asserting a purchaseInvoice is created must be rewritten to assert a
# Draft reimbursement, and any test asserting the row ends Posted must be
# rewritten to assert Draft; that is the behaviour change, not a regression.
# The grep must print NOTHING: no auto-post path, and no UPDATE of an existing
# reimbursement or DELETE of its lines — the sync creates only.
# git status prints nothing for packages/database/.
Then prove edits survive a re-sync — this is the spec's new acceptance
criterion and the whole point of the change. Add a test to the
ramp-sync-reimbursement suite that runs the sync twice around an edit:
pnpm --filter @carbon/jobs test -- ramp-sync-reimbursement
# The test must: (1) run the syncer against a Ramp reimbursement and assert a
# Draft row with its imported lines; (2) simulate a reviewer's edit — change a
# line's accountId, change its amount, and ADD a second line; (3) run the
# syncer AGAIN with the SAME Ramp payload; (4) assert the row's header and BOTH
# lines are byte-identical to the edited state, the added line still exists,
# and no line was deleted or re-inserted (compare line ids, not just values —
# a delete-then-reinsert would produce the same values with new ids and must
# fail this test).
# Expected: "Test Files 1 passed" with that case green.
Out of scope: Do not delete resolveEmployeeSupplier
(packages/ee/src/ramp/lib/suppliers.ts:235) — the spec retains it for the
QBO/Xero provider-side vendor mapping (Tasks 27–28). Do not touch
ramp-sync-bill.ts, ramp-sync-card.ts (the charge auto-post is the sibling
spec's), or ramp-sync-repayment.ts.
Task 24: @carbon/ee accounting — reimbursement entity type + plumbing
Depends on: Task 2
Files:
- Modify:
packages/ee/src/accounting/core/types.ts— theAccountingEntityTypeunion (241–258) - Modify:
packages/ee/src/accounting/core/models.ts—ENTITY_DEFINITIONS(120–216),DEFAULT_SYNC_CONFIG.entities(218–292),SyncConfigSchema.entities(798–817),PostingPolicyEntry.backingEntityType(321–350),POSTING_POLICY(358+) - Modify:
packages/ee/src/accounting/core/posting.ts—PostingSyncDocumentSyncFlags(105–112),decideDocumentFamily(367–410) - Modify:
packages/ee/src/accounting/core/subscriptions.ts—COMMON_PUSH_TABLES(37–46) - Modify:
packages/ee/src/accounting/providers/rillet/provider.ts—RILLET_PUSH_ONLY_ENTITIES(248–258) - Modify:
packages/ee/src/accounting/providers/quickbooks-online/provider.ts—QBO_CARBON_OWNED_ENTITIES(312–323) - Modify:
packages/ee/src/accounting/providers/xero/provider.ts—XERO_CARBON_OWNED_ENTITIES(107–117) - Modify:
packages/jobs/src/inngest/functions/events/sync-tables.ts—TABLE_TO_ENTITY_MAP(13–26) - Modify:
packages/jobs/src/inngest/functions/integrations/reconcile.ts—ReconcileEntityType(40–50), the decision switch (168–186) - Modify:
packages/jobs/src/inngest/functions/integrations/reconcile-executor.ts—SNAPSHOT_TABLES(45–62),MAPPED_TYPES(64–75) - Modify:
packages/jobs/src/inngest/functions/integrations/accounting-outbound-sweep.ts— a reimbursement sweep block modelled on the charge block (322–358) - Modify:
packages/jobs/src/inngest/functions/integrations/accounting-sync-operations.ts— aSWEPT_REIMBURSEMENT_STATUSESnext toSWEPT_CHARGE_STATUSES(1582) - Modify:
apps/erp/app/modules/settings/ui/Integrations/SyncActivity.tsx—ENTITY_LABELS(166–178),ENTITY_PATHS(184–194) - Modify:
packages/ee/src/accounting/core/sync-factory.test.ts— the exact-key-set assertion (194–206) - Copy from (precedent): every
chargeentry in each of the files above
Steps:
types.ts— add| "reimbursement"toAccountingEntityType, with a doc comment: "A Carbonreimbursement(employee expense payable) pushed as the provider's native reimbursement object, or an employee-vendor bill where the provider has none." Note the rule file currently statesemployeeis declared but unimplemented — that stays true;reimbursementis a separate member. Several maps below are totalRecords, so the compiler will list every site that needs a member — work the typecheck errors, do not hunt by hand.models.ts:ENTITY_DEFINITIONS.reimbursement—label: "Reimbursements",type: "document",supportedDirections: ["push-to-accounting"](mirror thechargeentry's field set exactly).DEFAULT_SYNC_CONFIG.entities.reimbursement—enabled: false(spec:defaultEnabled: false), the rest mirroringcharge.SyncConfigSchema.entities.reimbursement: createEntityConfigSchema().optional().- Widen
PostingPolicyEntry.backingEntityTypewith| "reimbursement". POSTING_POLICY.Reimbursement— the newjournalEntrySourceTypevalue makes this totalRecordincomplete until it is added:Reimbursement: { representation: "document", family: "ap", backingEntityType: "reimbursement", defaultEnabled: false, defaultGranularity: "individual" },
posting.ts— addreimbursementEnabled?: booleantoPostingSyncDocumentSyncFlags, and an arm indecideDocumentFamily'sdocumentSyncEnabledternary chain:backingEntityType === "reimbursement" ? args.docSync.reimbursementEnabled === true : …(alongside thecreditMemo/vendorCreditarms). Without it the chain falls through tofalseand a Reimbursement journal pushes as a plain journal entry ON TOP of the pushed document — a double-post.subscriptions.ts— append toCOMMON_PUSH_TABLES:// Reimbursements push on the transition to Posted/Voided; the row is never // deleted once posted (Draft-only DELETE), so only INSERT/UPDATE. { table: "reimbursement", operations: ["INSERT", "UPDATE"] }- The three provider entity arrays — add
"reimbursement"beside"charge"inRILLET_PUSH_ONLY_ENTITIES,QBO_CARBON_OWNED_ENTITIES,XERO_CARBON_OWNED_ENTITIES. sync-tables.ts—reimbursement: "reimbursement".reconcile.ts—| "reimbursement"inReconcileEntityType;case "reimbursement":falling intoreconcileDocument(input)besidecase "charge":.reconcile-executor.ts—reimbursement: { table: "reimbursement", columns: "id, status, updatedAt" }inSNAPSHOT_TABLES;"reimbursement"inMAPPED_TYPES.accounting-sync-operations.ts—export const SWEPT_REIMBURSEMENT_STATUSES = ["Posted", "Voided"] as const;Draft is deliberately absent: an unposted document has no journal and nothing to push.accounting-outbound-sweep.ts— a reimbursement block cloned from the charge block (322–358): gate onprovider.getSyncConfig("reimbursement"),pageIds({ table: "reimbursement", statuses: SWEPT_REIMBURSEMENT_STATUSES, dateColumn: "reimbursementDate", floor })plus a second pass ondateColumn: "voidedAt"withstatuses: ["Voided"]for late voids, union the ids, push{ entityType: "reimbursement", entityId: id }refs, and anelse skippedReasons.push("reimbursements: reimbursement sync is disabled"). There is notypefilter — unlike a charge, every reimbursement is document-shaped.SyncActivity.tsx—reimbursement: "Reimbursement"inENTITY_LABELS,reimbursement: path.to.reimbursementinENTITY_PATHS.sync-factory.test.ts:194-206asserts the EXACT Rillet registry key list — add"reimbursement"there once Task 25 registers the syncer. Until then the test still passes; do not pre-add the key.
Verify:
pnpm exec turbo run typecheck --filter=@carbon/ee --filter=@carbon/jobs --filter=erp && pnpm --filter @carbon/ee test -- posting-policy sync-factory && pnpm --filter @carbon/jobs test -- subscriptions-mapping && git status --short packages/database/
# Expected: all three typechecks exit 0; the posting-policy test (which asserts
# POSTING_POLICY totality against the DB enum) passes; sync-factory and
# subscriptions-mapping pass. git status prints nothing for packages/database/.
Out of scope: Do not register any provider syncer here (Tasks 25, 27, 28).
Do not change charge's policy row or its per-row isDocBackedCharge special
case — a reimbursement is document-represented by policy and needs no per-row
analogue.
Task 25: Rillet ReimbursementSyncer
Depends on: Task 24
Files:
- Create:
packages/ee/src/accounting/providers/rillet/entities/reimbursement.ts - Create:
packages/ee/src/accounting/providers/rillet/entities/__tests__/reimbursement.test.ts - Modify:
packages/ee/src/accounting/providers/rillet/index.ts— import (line 4-area), re-export (13-area), registry key (36–48); leaveSyncFactory.registerat line 61 untouched - Modify:
packages/ee/src/accounting/providers/rillet/entities/bill.ts— REMOVE the employee special case - Modify:
packages/ee/src/accounting/core/sync-factory.test.ts— add"reimbursement"to the Rillet key-set assertion (194–206) - Copy from (precedent):
packages/ee/src/accounting/providers/rillet/entities/charge.ts(378 lines —RilletChargeSyncerat 163,mapChargeToRilletChargeat 87–160) - Copy from (precedent):
providers/rillet/entities/bill.tslines 270–291 (toRilletReimbursement), 611–633 (payable resolution +UNMAPPED_ACCOUNTS), 655–685 (thecreateReimbursementcall + idempotency key), 367–377 (deleteReimbursementrouting)
Steps:
- Create
RilletReimbursementSyncer, modelled onRilletChargeSyncer:- source rows from
reimbursement+reimbursementLine, joined to the employee's provider vendor mapping (Rillet's/reimbursementstakes avendor_id); mapReimbursementToRilletReimbursement(...)— a pure exported mapper mirroringmapChargeToRilletCharge: one item per coded line (account_code, amount,fields[]= the Cost Center / Project field + value),reimbursement_date=reimbursementDate,impact_date=postingDate,payable_account_code= the Rillet code mapped from the reimbursement's storedpayableAccountId,external_referencescarrying the Carbon id;- the
UNMAPPED_ACCOUNTSWarning when the payable account or any line account has no Rillet code — copy the message and metadata shape verbatim frombill.ts:611-633; - transport via the EXISTING
provider.tsmethods —createReimbursement(1023–1035),getReimbursement(1016–1021),deleteReimbursement(809–811). Do not add new transport. - Voided →
deleteReimbursement(remoteId), following theChargeSyncerBaselifecycle.
- source rows from
- Register it:
reimbursement: RilletReimbursementSyncerinrilletSyncerRegistry, plus the import andexport * from "./entities/reimbursement";. - Remove the employee-supplier detour from
bill.ts: deleteEMPLOYEE_SUPPLIER_TYPE/REIMBURSEMENT_REMOTE_KIND(279–282),employeeSupplierIds/reimbursementPayableCodes/reimbursementRemoteIds(300–305),isReimbursement(321–339), thelinkEntitiesoverride (341–358), themapToRemotepayable block (611–633), and theupsertRemotereimbursement branch (655–685). MovetoRilletReimbursement(270–291) into the new file.bill.tsgoes back to doing one thing. Escape hatch: if any ALREADY-SYNCED bill carriesmetadata.remoteKind === "reimbursement"inexternalIntegrationMapping, deleting thedeleteRemotebranch (367–377) would send a future void toDELETE /bills/{id}against a reimbursement id. Keep ONLY that branch as a legacy read-path, with a comment saying it exists solely for mappings written before this change. If you conclude no such mappings can exist in any environment, STOP and confirm before deleting it. - Tests: the pure mapper's output for a two-line reimbursement; the
UNMAPPED_ACCOUNTSWarning when the payable account is unmapped; a Voided row issuingDELETE /reimbursements/{id}.
Verify:
pnpm exec turbo run typecheck --filter=@carbon/ee && pnpm --filter @carbon/ee test -- reimbursement bill sync-factory && git status --short packages/database/
# Expected: typecheck exits 0; the new reimbursement tests pass, the existing
# bill tests still pass with the employee cases removed, and sync-factory's
# Rillet key-set assertion now includes "reimbursement".
# git status prints nothing for packages/database/.
Out of scope: Do not touch the QBO or Xero providers. Do not change
core/document-costing.ts's loadChargeCostingLines.
Task 26: Rillet payout — close UNSUPPORTED_REIMBURSEMENT_PAYMENT
Depends on: Task 25
Files:
- Modify:
packages/ee/src/accounting/providers/rillet/provider.ts— addcreateReimbursementPaymentnext tocreateBillPayment - Modify:
packages/ee/src/accounting/providers/rillet/entities/payment.ts— replace the bail-out at 434–456, extendpushRemotePayment(401–508) - Modify:
packages/ee/src/accounting/providers/rillet/models.ts— the payment payload/response schema, next toReimbursementSchema(372–394) - Modify:
packages/ee/src/accounting/core/posting.ts— theJOURNAL_ENTRY_SYNC_ERROR_CODEScomment at 599–603 - Modify:
packages/ee/src/accounting/providers/rillet/entities/__tests__/payment-push.test.ts - Copy from (precedent):
provider.tscreateBillPayment(the sibling ofcreateInvoicePayment), andpayment.ts:469-508(the payload +buildRilletIdempotencyKey+ composite entity id)
Steps:
provider.ts— addcreateReimbursementPayment(reimbursementId, payment, idempotencyKey)→POST /reimbursements/{id}/payments, body{ amount, date, account_code }, with the same envelope/idempotency handling ascreateBillPayment. The endpoint was confirmed in the 2026-09-23 API survey.payment.ts— delete theUNSUPPORTED_REIMBURSEMENT_PAYMENTthrow (434–456) and replace it with a real branch: when the settled document is a reimbursement (its mapping entity type is"reimbursement", resolved the same way the AR/AP arms resolve"invoice"/"bill"at 419–430), callcreateReimbursementPaymentwith the payload shape used at 469–486 and an idempotency key of{ operation: "create reimbursement payment", localId: \${carbonPaymentId}:${targetDocumentId}` }. Keep theUNSYNCED_DOCUMENTWarning for an unsynced reimbursement and theUNMAPPED_ACCOUNTS` Warning for an unmapped bank account — both still apply.posting.ts—UNSUPPORTED_REIMBURSEMENT_PAYMENTstays in the union (older operation rows still carry it), but rewrite its comment to say the code is retired for new runs as of this change and is kept only so historical failure rows still render. Do not remove the member.- Tests in
payment-push.test.ts: a reimbursement payout POSTs to/reimbursements/{id}/paymentsand the operation closesCompleted(spec AC — explicitly notUNSUPPORTED_REIMBURSEMENT_PAYMENT); an unsynced reimbursement still returnsUNSYNCED_DOCUMENT.
Verify:
pnpm exec turbo run typecheck --filter=@carbon/ee && pnpm --filter @carbon/ee test -- payment-push payment && git status --short packages/database/
# Expected: typecheck exits 0; payment-push and payment tests pass, including
# the new Completed assertion; no test still asserts
# UNSUPPORTED_REIMBURSEMENT_PAYMENT for a NEW reimbursement payout.
# git status prints nothing for packages/database/.
Out of scope: The spec's risk row says this endpoint is "documented but unexercised by Carbon" and must be probed on the Rillet sandbox before shipping. That needs live credentials and is a human gate — recorded in Task 30; do not fake it with a mock and call it verified.
Task 27: QBO ReimbursementSyncer
Depends on: Task 24
Files:
- Create:
packages/ee/src/accounting/providers/quickbooks-online/entities/reimbursement.ts - Create:
packages/ee/src/accounting/providers/quickbooks-online/entities/__tests__/reimbursement.test.ts - Modify:
packages/ee/src/accounting/providers/quickbooks-online/index.ts— import (line 4-area), re-export (14-area), registry key (37–48) - Copy from (precedent):
packages/ee/src/accounting/providers/quickbooks-online/entities/charge.ts(591 lines —QboChargeSyncerat 209,mapChargeToQboPurchaseat 121–207) - Copy from (precedent):
providers/quickbooks-online/entities/bill.ts— theBillpayload shape
Steps:
- QBO has no native reimbursement object, so a reimbursement is pushed as a
Billagainst an employee Vendor (the spec's provider table; SAP and D365 do the same). The employee→vendor resolution stays provider-side: reuse the mapping-first lookup on thevendorentity type, creating the QBO Vendor JIT if absent — mirror howQboChargeSyncerJIT-syncs its merchant vendor. This is the one placeresolveEmployeeSupplier's naming convention survives. mapReimbursementToQboBill(...)— a pure exported mapper: oneLineperreimbursementLinewithAccountBasedExpenseLineDetail.AccountRef= the mapped QBO account,TxnDate=reimbursementDate,VendorRef= the employee vendor,APAccountRef= the QBO account mapped from the reimbursement's storedpayableAccountId(so the segregated control account survives into QBO),DocNumber=reimbursementId.- Extend the
ChargeSyncerBaselifecycle:upsertRemote→ create/update Bill;deleteRemote→ the provider's bill delete. ReadQboChargeSyncer'supdateMappedChargescomment atcharge.ts:214before deciding whether the same flag applies. - Register
reimbursement: QboReimbursementSyncerinqboSyncerRegistry. - Tests: the mapper's output for the spec's two-line case (a
Billagainst the employee vendor with two account-based lines and the segregatedAPAccountRef); an unmapped account →UNMAPPED_ACCOUNTS.
Verify:
pnpm exec turbo run typecheck --filter=@carbon/ee && pnpm --filter @carbon/ee test -- quickbooks && git status --short packages/database/
# Expected: typecheck exits 0; the QBO test suite passes including the new
# reimbursement cases. git status prints nothing for packages/database/.
Out of scope: No QBO BillPayment push in this task — the existing
PaymentSyncer AP arm already handles a Bill target once the mapping exists;
verify that, do not extend it. Do not touch Rillet or Xero.
Task 28: Xero ReimbursementSyncer
Depends on: Task 24
Files:
- Create:
packages/ee/src/accounting/providers/xero/entities/reimbursement.ts - Create:
packages/ee/src/accounting/providers/xero/entities/__tests__/reimbursement.test.ts - Modify:
packages/ee/src/accounting/providers/xero/index.ts— import (line 4-area), re-export (15-area), registry key (37–51) - Copy from (precedent):
packages/ee/src/accounting/providers/xero/entities/charge.ts(693 lines —XeroChargeSyncerat 218,mapChargeToXeroBankTransactionat 151–216) - Copy from (precedent):
providers/xero/entities/bill.ts— theACCPAYinvoice shape;ContactSyncerfor the employee Contact
Steps:
- Xero has no reimbursement object either: push an
ACCPAYinvoice against an employee Contact, resolved through the existingvendormapping (Xero'sContactSyncerbacks bothcustomerandvendor). mapReimbursementToXeroInvoice(...)— a pure exported mapper:Type: "ACCPAY",Contact= the employee contact,Date=reimbursementDate,InvoiceNumber=reimbursementId, oneLineItemper reimbursement line withAccountCode= the mapped Xero code,Trackingfor cost center / project,Status: "AUTHORISED". Use the adapter's named contract constants inpackages/ee/src/accounting/providers/xero/serialize.tsfor any external rounding — never a scale literal.- Register
reimbursement: XeroReimbursementSyncerinxeroSyncerRegistry. - Tests mirroring Task 27's.
Verify:
pnpm exec turbo run typecheck --filter=@carbon/ee && pnpm --filter @carbon/ee test -- xero && git status --short packages/database/
# Expected: typecheck exits 0; the Xero test suite passes including the new
# reimbursement cases. git status prints nothing for packages/database/.
Out of scope: Do not attach remote files (the rule notes the Xero and QBO charge adapters do not attach them today either). Do not touch Rillet or QBO.
Task 29: Full validation gate
Depends on: Tasks 1–28
Files:
- Modify (documentation sync):
.claude/rules/accounting-sync-handlers.md— theAccountingEntityTypelist at line 27, the note at line 20 thatemployeeis not implemented (still true, but sayreimbursementnow is), and a newreimbursementsection modelled on "Card charges as provider objects" (297+).claude/rules/ramp-integration.md— the sync-loop table row at line 284 (ramp-reimbursementsnow becomes a Draftreimbursement, not apurchaseInvoice (Employee supplier)), the syncer description at 300–302, theresolveEmployeeSuppliernote at 402, the fact that the reimbursement family no longer auto-posts, and the fact that the sync creates but never re-writes an existing document (with the accepted cost: a provider-side correction after import does not flow through)packages/ee/src/accounting/AGENTS.mdandapps/erp/app/modules/invoicing/AGENTS.md(if present) — the new tables, service functions and entity type.ai/specs/implemented/2026-09-23-reimbursements-first-class.md— changelog entry, and correct theramp-sync-reimbursement.tspath (it is in@carbon/jobs, notpackages/ee/src/ramp/)
Steps:
- Run, in order, fixing every failure before moving on:
pnpm exec biome check --write apps/erp packages/ee packages/jobs pnpm exec turbo run typecheck --filter=erp pnpm exec turbo run typecheck --filter=@carbon/ee pnpm exec turbo run typecheck --filter=@carbon/jobs pnpm run test cd packages/database/supabase/functions && deno test --no-lock --no-check && cd - pnpm db:migrate pnpm db:check:datasets pnpm db:check:backupspnpm db:migratemust run BEFORE the twodb:check:*commands — they read the live local schema, and a stale database fails them for the wrong reason. - After the turbo runs,
git status --short packages/database/. The ONLYpackages/database/changes that may remain are the new migration file, theseed.data.tsedit, theconfig.tomledit, thepost-reimbursement/directory, thepost-payment/sharededits, and the Task 2 generated types. Revert anything else. - Run
/translateto fill any new emptymsgstrentries inpackages/locale/locales/*/*.pointroduced by the new UI strings — Phase D adds a lot of them. - Update the documentation files above. A rule that still says a Ramp reimbursement becomes a purchase invoice, or that the family auto-posts, is stale the moment this lands.
Verify:
pnpm exec turbo run typecheck --filter=erp --filter=@carbon/ee --filter=@carbon/jobs && pnpm run test && pnpm db:check:datasets && pnpm db:check:backups && git status --short packages/database/
# Expected: every typecheck exits 0; `pnpm run test` reports 0 failed across
# all packages; db:check:datasets prints a pass for all four datasets;
# db:check:backups gives a verdict of pass (and, from the pre-commit hook, will
# regenerate and stage packages/jobs/manifests/schema.json — that staged file
# is EXPECTED churn, unlike the generated types).
# git status --short packages/database/ lists ONLY the intended files above.
Out of scope: Do not run a whole-repo tsc --noEmit or pnpm typecheck —
it OOMs. Do not commit unless the user asks.
Task 30: Browser verification via /test
Depends on: Task 29
Files:
- Read only. The stack is already running (
crbn up) athttps://erp.rillet-ramp-accounting-provider.dev.
Steps:
- Invoke the
/testskill (it calls/authfirst for the DEV_BYPASS_EMAIL session, then drives the app withagent-browser). Base URL:https://erp.rillet-ramp-accounting-provider.dev. - Enable accounting for the dev company if it is off
(
/x/settings/accounting) — otherwisepost-reimbursementskips journal creation and the posting criteria cannot be observed. - Seeding the fixture. There is no create form, so a Draft reimbursement
must come from the Ramp sync (credential-gated) or a SQL fixture. Insert one
directly against the local database:
- one
reimbursementrow:status 'Draft',integration 'ramp', a realemployeeIdfromemployee,amount 620, base currency,createdBy 'system'(there is noimportedAtcolumn); - two
reimbursementLinerows: 500 to a travel expense account and 120 to a meals expense account,sequence0 and 1; - one
externalIntegrationMappingrow:integration 'ramp',entityType 'reimbursement',entityId= the reimbursement id,externalId= a fake Ramp id. Use real account ids from the company's chart —.ai/lessons.mdwarns that hand-built SQL fixtures which skip a companion row produce 404s in the UI.
- one
- Walk this script, capturing a screenshot at each numbered step:
- Nav — open
/x/invoicing. AReimbursementsentry appears in the Accounts Payable group, immediately afterCharges. Click it; the list loads and the seeded row shows as Draft. - SOURCE badge — open the row. The detail page shows a SOURCE field with the Ramp logo, the name "Ramp", and the external id. There is deliberately no Activity/timeline rail — confirm none is rendered.
- Edit header — click Edit. Change the reference and save. The value persists.
- Edit a line — change line 1's account and description, then open the
expanded row and set two dimensions through the
DimensionSelector(pick a Cost Center and one other configured type). Save. Every change persists, and read mode renders the dimensions as coloured badges with NAMES, not ids. - Add a line + running total —
+ Add line item, type an amount, and confirm the running total in the page header updates as you type; the badge flips to Unbalanced because the lines no longer sum to 620. Remove the line and confirm it returns to Balanced. - Totals guard — deliberately leave the lines unbalanced and click Post.
It is refused with a clear message and no journal is created (check
/x/accounting/journal-entries). - Post — restore balance, Post. Status flips to
Posted; the Journal link resolves; the journal debits 500 and 120 to the line accounts and credits 620 to the employee-payable account;totalDebits == totalCredits; each line'sjournalLineDimensioncarries its cost center / project. - Posted is not editable — the Edit control is absent, and navigating
directly to
/x/reimbursements/<id>/editredirects back with a message. - AP fallback — clear
Employee Reimbursements Payableat/x/accounting/defaults, seed and post a second reimbursement, and confirm the credit lands on the Payables trade account. Restore the default. - Void — Void the posted reimbursement. Status
Voided, a second Posted journal exists whose lines are the exact negation. Submit Void again and confirm no third journal is created. - Edits survive a re-sync (spec's new criterion). This needs the Ramp sandbox, so if credentials are absent record it NOT VERIFIED here and rely on Task 23's unit test, which proves the same invariant. With credentials: edit a Draft's lines, re-run the Ramp sync, and assert the edits are intact and no line id changed.
- Pay expense — on the posted reimbursement, open Pay expense. The modal shows Total Due and exactly three fields (Amount defaulted to the balance, Date, Account). Enter a PARTIAL amount and submit; the payment posts and the reimbursement shows a remaining balance. Pay the remainder and confirm it settles fully.
- Not in Purchase Invoices — open
/x/invoicing/purchasingand confirm the reimbursements do NOT appear. - Not in AP aging — open the supplier/AP aging report and confirm no employee-named supplier was created and the amounts are absent.
- Legacy rows intact — open a pre-existing employee-supplier purchase invoice, if the dev company has one, and confirm it still loads with its Post action intact.
- Nav — open
- Record every screenshot path and the pass/fail per acceptance criterion.
- Credential-gated — report as explicitly NOT verified rather than claiming
them:
- the Ramp inbound criterion (a real Ramp reimbursement landing Draft with no synthetic supplier) — needs Ramp sandbox credentials;
- the Rillet criteria (
/reimbursementsrecord, andPOST /reimbursements/{id}/paymentsclosingCompleted) — needs Rillet sandbox credentials, and the spec's risk row requires a live probe of the payments endpoint before shipping; - the QBO criterion (a
Billagainst the employee vendor) — needs QBO sandbox credentials.
Verify:
# The /test skill's own report is the verification artifact. It must state,
# per acceptance criterion, PASS with a screenshot path or NOT VERIFIED with
# the reason.
# Expected: the posting, fallback, dimension, void, edit, add-line, totals-guard,
# posted-immutability, SOURCE-badge, Pay-expense, nav,
# purchase-invoice-separation, AP-aging and legacy-rows criteria all PASS with
# screenshots. The Ramp inbound, edits-survive-re-sync, Rillet and QBO criteria
# are reported NOT VERIFIED (credential gate) — with the note that
# edits-survive-re-sync IS proven by Task 23's unit test. The toolchain
# criterion was covered by Task 29.
Out of scope: Do not modify code from this task — a failure here means returning to the owning task. Do not commit; do not open a PR unless asked.
Acceptance-criteria coverage
Re-checked against both specs at commit 595e0ba188. Every criterion in scope
maps to at least one task.
.ai/specs/implemented/2026-09-23-reimbursements-first-class.md
| Criterion | Tasks |
|---|---|
Two lines (500 + 120) post to ONE journal; 620 credited to employee-payable; Posted + journalId |
1, 2, 8, 9, 10, 18, 30 (step 7) |
| Control account unset → AP trade fallback, still balances | 1(f), 3, 7, 8, 9, 10, 30 (step 9) |
costCenterId writes journalLineDimension; no active dimension refuses |
9, 10, 13, 30 (steps 4, 7) |
Void writes a balanced reversal → Voided; re-void returns the stored id |
9, 10, 18, 30 (step 10) |
Ramp reimbursement syncs as a reimbursement, no synthetic supplier, lands Draft |
23, 30 (credential-gated) |
| Detail shows SOURCE: Ramp logo + name + external id | 12, 16, 23, 30 (step 2) |
| Editing a Draft's lines then re-running the Ramp sync leaves the edits intact (new) | 23 (step 1 + its re-sync test), 30 (step 11, credential-gated) |
A Draft can be edited: header, a line's account/amount/description/cost centre/project, + Add line item, running total |
4, 5, 6, 11, 13, 17, 30 (steps 3–5) |
| A Posted reimbursement is not editable | 1(d) trigger, 1(e) RLS, 17 requireUnlocked, 30 (step 8) |
| Pay expense modal — amount (editable, partial allowed) / date / account | 1(g), 1(h), 20, 21, 22 (step 0), 30 (step 12) |
Rillet /reimbursements + POST /reimbursements/{id}/payments closes Completed |
22 (step 0), 25, 26, 30 (credential-gated) |
QBO creates a Bill against the employee vendor |
27, 30 (credential-gated) |
Reimbursements under Accounts Payable, opens the list |
15, 16, 19, 30 (step 1) |
| No longer in the Purchase Invoices list | 23, 30 (step 13) — see caveat below |
| Absent from supplier/AP aging | 1, 23, 30 (step 14) |
| Existing employee-supplier purchase invoices still load and post | 23 (out-of-scope guard), 30 (step 15) |
generate:types, scoped typechecks, pnpm run test, db:check:* green |
2, 29 |
Removed with the spec: the "Activity entry — Reimbursement imported from Ramp" criterion. No task covers it because the surface no longer exists.
.ai/specs/2026-09-23-editable-imported-spend-documents.md — the shared shape, as it applies to reimbursements
| Criterion | Tasks |
|---|---|
| Import lands Draft, not Posted | 23, 30 (step 1) |
| SOURCE field with logo + name + external id | 12, 16, 30 (step 2) |
| After a human edits a Draft's lines, re-running the sync leaves them intact (new) | 23 (step 1 + its re-sync test), 30 (step 11) |
| Edit mode changes header + a line's account, amount and description; Save persists | 5, 6, 13, 17, 30 (steps 3–4) |
The line editor renders the company's configured dimensions through the existing DimensionSelector |
1(b) reimbursementLineDimension, 4, 6, 11, 13, 17, 30 (step 4) |
+ Add line item; running total updates on type and on remove |
13, 17, 30 (step 5) |
| Post refused, before any edge-function call, while unbalanced | 17, 18, 30 (step 6) |
Posting writes journalLineDimension per line and flips to Posted |
9 (unions both sources), 10, 30 (step 7) |
| Posted is not editable — controls absent AND a direct action refused | 1(d), 1(e), 17, 30 (step 8) |
| Browser-verified end to end: import → edit → add line → post | 30 |
Removed with the spec: the Activity-entry criterion.
The same spec's CHARGE criteria are not covered here — see Coordination below.
Coordination with the sibling spec
.ai/specs/2026-09-23-editable-imported-spend-documents.md has no plan of its
own yet. This plan builds the two shared components it needs
(DocumentSourceBadge, Task 12; DocumentLineEditor, Task 13) as
document-agnostic components in apps/erp/app/components/, so the charge work
can consume them without modification. Three pieces of that spec are
deliberately NOT in this plan and will go unimplemented unless separately
planned:
ramp-sync-card.tsmust stop invokingpost-chargeso charges land Draft (that spec's first acceptance criterion).charges.$id.tsxmust move from the read-only Drawer to a read/edit full page using the two shared components, and gain a Post action.invoicing.service.tsneedsupdateCharge+upsertChargeLines, with the same.serverKysely handoff Task 6 establishes.
Flag this when handing the plan over.
Where the specs were too thin to plan from
Resolved since the first draft (spec commits f821ddf9c2, 595e0ba188) —
listed so nobody re-opens them:
The payout has no payee→ approved:payment.employeeId, CHECK widened to customer XOR supplier XOR employee, employee arm throughpost-payment/build-payment-journal/payment-funding. Tasks 1(h), 20, 21, 22. The migration is additive and idempotent, and Task 1(h) argues explicitly why the widened CHECK cannot reject an existing row (it is strictly weaker on the existing column pair).Ramp-paid vs Draft→ approved as proposed: confirm at import, record the payout at Post, because the editable window is for coding rather than for deciding whether the employee was paid. Task 23 step 5, Task 18.Re-syncing a Draft overwrites human edits→ resolved: the sync creates and never re-writes. Task 23 step 1, with a re-sync test in its Verify.The Activity entry has no table→ resolved by dropping the feature. TheimportedAtcolumn, the Activity component and the related criteria are all removed; the SOURCE badge carries provenance. Tasks 1, 16, 30.The Project picker does not exist→ moot:DimensionSelectoralready covers Project and CostCenter as dimension entity types, so no picker is built. Task 11 became dimension data plumbing instead.The→ resolved from precedent:dimensionFK shape is unverifiedreimbursementLineDimensionmirrorsjournalLineDimension(20260228024512_dimensions.sql:116-138) — single-column PK("id"), single-column FK todimension("id"), plaincompanyIdFK,valueIddeliberately NOT a foreign key (polymorphic across Custom and entity-typed dimensions),UNIQUE (reimbursementLineId, dimensionId), and nocreatedBy/updatedBy. Task 1(b) builds it outright; the STOP is gone.Which dimension source wins at posting→ confirmed: the generic table beats the legacy columns, because the columns are what the sync wrote and the table is where a human's edit lands. Task 9 carries that rationale in the code comment; Task 10 pins it with a test.
Still open — flag these before or during execution:
DimensionSelector.journalLineIdis a misnamed prop. The editor passes a reimbursement line's client key into a prop named for journal lines. WithautoSave={false}it should only be an identity, but Task 13 requires reading the component body to confirm before relying on it, and STOPs if the prop reaches a fetcher. The spec says "reuse it" without noting the prop mismatch.The editor does not write the legacy columns. The shared spec's line table lists only Account / Amount / Description / Dimensions, so a reviewer cannot change an imported
costCenterIddirectly — only add a Cost Center dimension that then wins at posting. That is coherent but surprising, and the reimbursements spec's own criterion still says "cost centre/project" are editable. Task 13 threads the legacy values through read-only so a round-trip cannot drop them."No longer appears in the Purchase Invoices list" is only true for new rows. The spec also resolves "no backfill", so existing employee-supplier purchase invoices deliberately remain there. Task 30 steps 13 and 15 test both halves; the spec should say so.
The two-mode detail surface has no exact precedent. The ERP has the three-pane
PanelProviderdocument (purchase invoice, quote) and the plain centred single-card page (journal entry). The spec's description matches the journal entry, which is also the ERP's only hidden-JSON-field editable line list, so the plan uses it — but neither spec says which.No reusable integration-logo component exists. The shared spec says the logo "comes from the integration registry … so a new provider gets its badge with no extra work", but today it is only rendered inline in settings and the only existing source badge (
PurchaseInvoiceHeader.tsx:334-345) is text-only. Task 12 builds the reusable one and fixes Ramp'sLogo, which hard-codesheight: "1.25rem"ahead of...props.styleso a caller cannot size it.reimbursementStatusis referenced by the spec's DDL but never declared. Task 1(a) declares it.The spec's DDL omits every lifecycle guard the
chargeprecedent has — the Draft-only mutation trigger, the line-parent lock, the company-group account guards, the lifecycle audit CHECK. Task 1(d) clones all four. Under the editable model these are load-bearing: they are what the shared spec means by "the lifecycle trigger is the backstop".currencyCodeis bare TEXT in the spec's DDL; the precedent references"currencyCode"(code). Task 1(b) adds the FK.No sequence is mentioned outside a SQL comment.
REIMB-%{yyyy}-%{mm}-needs asequencerow per existing company (migration) and an entry inseed.data.tsfor new ones. Tasks 1(i) and 3.The outbound-sync plumbing is one sentence ("syncers for the three providers"). It is thirteen files — Task 24 enumerates them.
backingEntityType: "reimbursement"is not a legal value today. Both the union inPostingPolicyEntryand the ternary chain indecideDocumentFamilyneed widening; missing the second silently double-posts. Task 24 steps 2 and 3.Xero has no acceptance criterion although it is in the provider table. Task 28 builds it; its own tests are the only contract.
The Rillet payments endpoint is unproven against the live sandbox. The spec's risk row demands a probe before shipping — credentials required, so Tasks 26 and 30 mark it a human gate rather than treating a mock as proof.