# Accountant Export — Movement File + Form 6111

**Date:** 2026-06-01
**Status:** Draft
**Spec:** 181
**Tier:** All tiers
**Depends on:** `invoices-core`, `invoice-receipt-document`, `invoice-credit-notes`, `expenses-module`, `vendors-suppliers`, `contractor-payouts`, `financial-statements`, `israeli-tax-reports`, `uniform-format-export`, `foundation-auth-rbac`
**Referenced by:** `reports-navigation-hub`, `settings-module`, `integration-hub`

---

## Overview

Most Israeli SMBs hand bookkeeping to an external accountant (רואה חשבון / יועץ מס) who imports the business's transactions into accounting software (Hashavshevet/חשבשבת and compatible packages). This spec backs the `/settings/integrations/accounting` route with a movement-file export, providing:

1. **Movement file (קובץ תנועות)** — periodic export of journal movements in the Hashavshevet-compatible uniform movement format, importable by Israeli accounting software.
2. **Form 6111 (טופס 6111)** — the ITA-standardized annual report-of-accounts line mapping that accountants file with the annual return; closes gap G3 (financial-statements produces human/xlsx P&L but not the 6111 field-coded structure).
3. **Accountant access** — a scoped role + invite so the business's accountant can pull exports without full tenant access.

---

## Derived ledger (movement source)

Zync is a documents+cash system, not double-entry. Movements are **derived** from source documents into a posting view at export time:

| Source event | Debit | Credit |
|--------------|-------|--------|
| Tax invoice issued | Customer (A/R) | Revenue + VAT-payable |
| Receipt / payment in | Bank/Cash | Customer (A/R) |
| Credit note | Revenue + VAT-payable | Customer (A/R) |
| Expense (deductible) | Expense category + VAT-input | Vendor (A/P) / Bank |
| Contractor payout | Subcontractor expense | Bank, Withholding-payable (856) |

Account codes come from a tenant **chart of accounts** mapping (defaults seeded; editable in settings). Each movement carries: date, reference (doc number), account code, debit/credit, amount, counter-account, VAT code, description.

> **Amount semantics:** derived movements use face-value document amounts (invoice `subtotal`/`total`, expense `amount`, payout `amount`). ILS-normalization for foreign-currency invoices is deferred — IL tenants invoice in ILS; multi-currency `total_ils` is not in schema (same decision as `israeli-tax-reports`).

> **Derived-ledger interface (consumed by `uniform-format-export`, spec 180):** the movement-derivation function — `deriveMovements(tenantId, periodFrom, periodTo) → Movement[]` over the source events in the table above — is also the input to spec 180's B100/B110 journal records. Spec 180 calls this function when `coa_mappings` exist for the tenant (the "accountant-export enabled" signal); with no chart of accounts mapped, spec 180 emits B100/B110 counts of 0 (documents-only mode, legally permitted). The interface and the enabled-signal are defined here; spec 180 consumes them and does not re-derive movements.

```sql
CREATE TABLE coa_accounts (              -- chart of accounts (tenant-editable, seeded)
  id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  tenant_id   UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
  code        TEXT NOT NULL,             -- e.g. '4000' revenue, '1100' A/R
  name        TEXT NOT NULL,
  type        TEXT NOT NULL CHECK (type IN ('asset','liability','equity','revenue','expense')),
  form6111_code TEXT,                    -- mapping to Form 6111 field
  UNIQUE (tenant_id, code)
);

CREATE TABLE coa_mappings (              -- maps document categories → account codes
  tenant_id    UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
  source_kind  TEXT NOT NULL,            -- 'revenue' | 'vat_payable' | 'ar' | 'bank' | expense category | ...
  account_code TEXT NOT NULL,
  PRIMARY KEY (tenant_id, source_kind)
);

CREATE TABLE accountant_export_jobs (
  id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  tenant_id   UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
  kind        TEXT NOT NULL CHECK (kind IN ('movement_file','form6111')),
  period_from DATE NOT NULL,
  period_to   DATE NOT NULL,
  status      TEXT NOT NULL DEFAULT 'pending',
  r2_key      TEXT,
  download_expires_at TIMESTAMPTZ,
  generated_by UUID REFERENCES users(id) ON DELETE SET NULL,
  created_at  TIMESTAMPTZ DEFAULT NOW()
);
```

---

## Form 6111

6111 groups P&L and balance-sheet lines into ITA-numbered fields per [gov.il itc6111](https://www.gov.il/he/service/itc6111) and the official "דברי הסבר לטופס 6111" (e.g. field **1300** = revenue from sales/services, **2000** = cost of sales, **3000** = production expenses, **3500** = selling & marketing, **5000** = G&A, **6666** = net profit/loss; balance-sheet lines are a separate section, not the 5000-series). Zync produces the **profit-and-loss section** (fields **1300–6666** in v1) from source documents via `coa_accounts.form6111_code`, plus a **tax-adjustment section** stub for the accountant to complete. **6111 turnover (field 1300) and P&L amounts are reported ex-VAT** (statutory; VAT is reported separately via PCN874) and **reconcile to the movement file** — the financial-statements dashboard's VAT-inclusive gross revenue is a separate report per its own spec. Output: structured Excel with one row per 6111 field code + amount + the supporting Zync category breakdown, so the accountant can reconcile and file. Inventory receipts embedded in expense OCR payloads (`sourceMetadata.stockLines`) are treated as a dedicated `inventory_stock` source and default to **field 2000** rather than inflating ordinary operating-expense categories. *(Rationale: prior illustrative 1010/2010/5000-BS examples were wrong; real ITA P&L codes differ. 2026-07-05 rationale: stock-line receipts represent inventory received into stock and should compose into cost-of-sales / inventory reporting, not OPEX.)*

---

## Accountant access

A scoped grant lets the business invite its accountant:

```sql
ALTER TABLE tenant_memberships ADD COLUMN is_accountant BOOLEAN DEFAULT false;
-- accountant role: read-only on financial reports + export endpoints; no edit, no customer PII beyond billing identity
-- (Rationale: migration 0041 alters tenant_memberships, not tenant_members.)
```

Accountant role (built on `foundation-auth-rbac`): permissions `reports:read`, `reports:export`, `accountant:export`. Cannot edit documents, manage users, or see non-financial modules. Invited via `/settings/users` with role "Accountant".

---

## UI — `/settings/integrations/accounting`

```
┌──────────────────────────────────────────────────────────────┐
│  Accountant Export                                           │
│                                                              │
│  Movement file (קובץ תנועות)                                 │
│    Period [Q1 2026 ▾] / custom   Format [Hashavshevet ▾]    │
│    [Generate movement file]                                  │
│                                                              │
│  Form 6111 (annual)                                          │
│    Tax year [2025 ▾]                                         │
│    [Generate 6111 Excel]                                     │
│                                                              │
│  Inventory count (מפקד מלאי)                                 │
│    As of [2025 ▾ → 31/12/2025]                               │
│    [Download Inventory Count XLSX]                           │
│                                                              │
│  Chart of accounts            [Edit mapping →]               │
│    23 accounts · 6111 codes mapped: 21/23  ⚠               │
│                                                              │
│  Your accountant                                            │
│    accountant@cpa.co.il · Accountant role · invited 3/2026  │
│    [Invite accountant]                                       │
│                                                              │
│  ── Recent exports ─────────────────────────────────────────│
│  Movement Q1 2026 · 2026-04-02 · [⬇]                        │
└──────────────────────────────────────────────────────────────┘
```

CP1255 encoding for the movement file (Hashavshevet import expectation), same bundled table as `uniform-format-export`.

---

## API

```
GET  /api/coa/accounts                       → chart of accounts
PUT  /api/coa/accounts                        → edit accounts + 6111 mapping
GET  /api/coa/mappings                         → category→account mapping
PUT  /api/coa/mappings                         → edit mapping
POST /api/reports/accountant/movement         → generate movement file (period, format) → job
POST /api/reports/accountant/form6111         → generate 6111 (year) → job
GET  /api/reports/accountant/inventory-count/xlsx?asOf=YYYY-MM-DD
                                            → direct XLSX physical count sheet
GET  /api/reports/accountant/exports          → list jobs
GET  /api/reports/accountant/exports/:id      → status + signed url
```

Export endpoints require `accountant:export` (held by OWNER/ADMIN and the Accountant role). Generation audited.

---

## Architecture Decisions

| Decision | Choice | Reason |
|----------|--------|--------|
| Derived ledger, not stored GL | Compute movements at export | Zync stays a documents+cash app; a full posted GL would duplicate source-of-truth and require reconciliation |
| Reuse `coa_accounts` for 6111 + movement + מבנה אחיד B110 | One chart | Single account mapping feeds movement file, Form 6111 field codes, and the uniform-format journal records |
| Accountant as scoped role | Not full member, not separate auth | Accountant needs financial read+export only; reuses RBAC instead of a parallel portal |
| 6111 P&L section only in v1 | Tax-adjustment section as stub | Tax adjustments require professional judgment; Zync supplies the auditable base, accountant completes the filing |
| Hashavshevet uniform movement format | Not a proprietary CSV | It is the de-facto import standard across IL accounting software |
