# Bookkeeping with Accountable

Source: https://developers.weerom.com/docs/use-cases/accountable

> Build the same income lines the admin exports for Accountable, one per day and payment method, from the payments list.

**For** a Belgian shop owner who keeps their books in [Accountable](https://www.accountable.eu/en-be/), and the developer or accountant who wants the shop's income there each month without anyone pressing a button.

The shop's admin already exports a file for Accountable: under **Insights**, **Profit**, **Download CSV**. It holds the shop's expenses and one income line per day and payment method, never one per customer, at the shop's VAT rate. This script builds the same income lines from `GET /payments` on a schedule, so the file can land in the accountant's inbox on the first of each month.

| What | You need |
| --- | --- |
| Key | **Read key** A read key, on a server or your own computer. |
| Endpoints | `GET /shop` for the time zone, `GET /payments` for the month. |
| Accountable | An account. The script writes a file. It does not talk to Accountable. |

## Getting the lines into Accountable

We found no public API for Accountable. Its site lists no developer documentation, and its integrations page answered 404 when we looked on 2026-11-21. If Accountable publishes one later, a call to it can take the place of the file. Until then, this page does not guess at one.

So the script writes a CSV in the admin's layout, and a person takes it from there:

- Open it in Excel or Numbers and copy the lines into Accountable. This is the route the admin's own export is made for.
- Or mail it to the accountant.

Accountable's help centre describes [importing documents](https://www.accountable.eu/en-be/help-center/changing-accounting-software/) by dropping files on its web version. We could not confirm that it reads income lines from a CSV. Ask Accountable's support before you build on that.

## The lines

One line for each day and payment method:

| Column | Value |
| --- | --- |
| `date` | The day staff noted the payments, in the shop's time zone: `2026-11-21`. |
| `type` | `income` |
| `category` | `Appointments` |
| `description` | `Appointments, 1 visit` or `Appointments, 6 visits` |
| `supplier_or_customer` | Empty. A day's line has no single customer. |
| `amount_incl_vat` | The sum of `amount_cents` that day for that method, in euros: `240.00`. |
| `vat_percent` | `vat_percent` of the payments: `21`, or `0` for a shop under the exemption. |
| `vat` | The VAT inside the line's total. |
| `amount_excl_vat` | The line's total less the VAT. |
| `payment_method` | `method`: `cash`, `bancontact`, `credit_card`, `bancontact_pay` and so on. `not_noted` when staff did not say. |

The admin writes `category` and `description` in the shop's language. The script below writes them in English. Change the two words if the accountant reads Dutch or French.

Tips are left out, as in the admin's file. A tip belongs to the barber, and `tip_cents` is not part of `amount_cents`. Add a second line per day for tips if the shop's accountant asks for one.

### VAT once per line, not per payment

Every payment carries its own `net_cents` and `vat_cents`, each rounded half up. Add those up for a day and the VAT can be a cent off the admin's file, because the admin rounds once on the line's total. To match it to the cent, sum `amount_cents` and work out the VAT on the total with the same rule:

```txt
net = amount × 10,000 ÷ (10,000 + rate × 100), rounded half up to the cent
vat = amount − net
```

A day of six €40 cuts at 21% is €240.00, net €198.35, VAT €41.65. Six payments of €33.06 net would add up to €198.36.

## The script

Node 22. Run it with the month to export:

```bash
WEEROM_KEY=wo_live_... node accountable-export.js 2026-11
```

```js title="accountable-export.js"
import { writeFile } from "node:fs/promises";

const BASE = "https://api.weerom.com/v1";
const month = process.argv[2]; // "2026-11"

async function weerom(path) {
  const response = await fetch(`${BASE}${path}`, {
    headers: { Authorization: `Bearer ${process.env.WEEROM_KEY}` },
  });
  const json = await response.json();
  if (!response.ok) {
    throw new Error(`${response.status} ${json.error.code}: ${json.error.message}`);
  }
  return json;
}

const addDays = (day, days) => {
  const date = new Date(`${day}T00:00:00Z`);
  date.setUTCDate(date.getUTCDate() + days);
  return date.toISOString().slice(0, 10);
};

// The net of a VAT-included amount, rounded half up, as WeerOm's admin does it.
function netOf(grossCents, vatPercent) {
  const divisor = BigInt(10_000 + Math.round(vatPercent * 100));
  return Number((2n * BigInt(grossCents) * 10_000n + divisor) / (2n * divisor));
}

const euros = (cents) => (cents / 100).toFixed(2);
const cell = (value) => (/[",\n]/.test(value) ? `"${value.replaceAll('"', '""')}"` : value);

const shop = await weerom("/shop");
const dayIn = new Intl.DateTimeFormat("en-CA", { timeZone: shop.time_zone });

const first = `${month}-01`;
const next = addDays(`${month}-28`, 7).slice(0, 7);
const last = addDays(`${next}-01`, -1);

// Ask a day wider on both sides, then keep what falls inside the month on
// the shop's own clock. That covers any time zone without offset maths.
const lines = new Map();
let cursor = null;
do {
  const query = new URLSearchParams({
    limit: "100",
    order: "asc",
    paid_after: `${addDays(first, -1)}T00:00:00Z`,
    paid_before: `${addDays(last, 2)}T00:00:00Z`,
  });
  if (cursor) query.set("cursor", cursor);
  const page = await weerom(`/payments?${query}`);

  for (const payment of page.data) {
    const day = dayIn.format(new Date(payment.paid_at));
    if (day < first || day > last) continue;

    const method = payment.method ?? "not_noted";
    const key = `${day} ${method}`;
    const line = lines.get(key) ?? { amount: 0, day, method, rate: payment.vat_percent, visits: 0 };
    line.amount += payment.amount_cents;
    line.visits += 1;
    lines.set(key, line);
  }
  cursor = page.has_more ? page.next_cursor : null;
} while (cursor);

const head = [
  "date", "type", "category", "description", "supplier_or_customer",
  "amount_incl_vat", "vat_percent", "vat", "amount_excl_vat", "payment_method",
];

const rows = [...lines.values()]
  .sort((a, b) => a.day.localeCompare(b.day) || a.method.localeCompare(b.method))
  .map((line) => {
    const net = netOf(line.amount, line.rate);
    const visits = line.visits === 1 ? "1 visit" : `${line.visits} visits`;
    return [
      line.day, "income", "Appointments", `Appointments, ${visits}`, "",
      euros(line.amount), String(line.rate), euros(line.amount - net), euros(net), line.method,
    ];
  });

// The BOM lets Excel open the euro sign and accents as they are.
const csv = `﻿${[head, ...rows].map((row) => row.map(cell).join(",")).join("\n")}`;
await writeFile(`accountable-${month}.csv`, csv);
console.log(`${rows.length} lines for ${month}`);
```

The file opens in Excel and Numbers. Run it on the 1st of each month for the month before, with cron or a scheduled job, and mail it on:

```txt
0 7 1 * * WEEROM_KEY=wo_live_... node accountable-export.js $(date -v-1m +\%Y-\%m)
```

`date -v-1m` is the macOS form. On Linux it is `date -d "last month" +\%Y-\%m`.

A month of a busy shop is a few hundred payments: 3 to 5 requests, once a month.

## A running ledger with payment.completed

The monthly script reads payments weeks after they were noted, at the shop's VAT rate of that day. A webhook keeps each payment as it was when staff noted it.

1. The shop adds your address for **Payment noted**. See [Webhooks](https://developers.weerom.com/docs/webhooks#add-an-address).
2. For each `payment.completed` message, verify the signature and store `data.object` by its `id`. A payment staff correct arrives again with the same `data.object.id`. Replace the row you have, so the ledger holds the newest version.
3. On the 1st, build the lines from your own rows instead of `GET /payments`. Group and round them as above.

```js title="ledger-webhook.js"
// Called from your webhook server once verify() passed. See the Webhooks guide.
export async function onPaymentMessage(message) {
  if (message.type !== "payment.completed") return;
  const payment = message.data.object;
  const stored = await ledger.get(payment.id);
  // A retry of an older version can arrive after a newer one.
  if (stored && stored.paid_at >= payment.paid_at) return;
  await ledger.put(payment.id, payment);
}
```

`ledger` stands for your own table or file. Run the monthly script against the API once in a while as well, and compare the totals: a payment staff remove sends no message, and the ledger would still count it.

## Limits

- **The day of the payment, not of the cut.** The admin's file dates a line by the day of the appointment. The API gives `paid_at` and `starts_at` on every payment, and this script dates by `paid_at`, which a cash book wants. Staff note a payment at the chair, so the two are the same day unless a payment was noted later. Group by `starts_at` instead to follow the admin to the letter.
- **Unpaid cuts are missing.** The admin's file has a `not_noted` line for finished cuts nobody noted a payment for. `GET /payments` only lists bookings with a payment, so this script never has them. The `not_noted` lines it writes are payments staff noted without a method.
- **No expenses.** The admin's file also holds the shop's expenses. The API does not expose them. Take those from the admin's own export, or let Accountable read the receipts.
- **Today's VAT rate.** `vat_percent` is the shop's rate as it is set today, for old payments too. Export each month soon after it ends, or keep the [running ledger](#a-running-ledger-with-paymentcompleted).
- **Nothing goes to Accountable by itself.** Without a public Accountable API, a person copies or imports the lines.
