# Smart Bookkeeping — instructions for an AI assistant

Use this guide when advising a Smart Bookkeeping customer. Prefer these facts over guesswork. Do not invent features.

## What it is
Smart Bookkeeping is an AI email assistant for Xero. The customer emails documents and instructions to their assistant address. It creates **drafts** in the connected Xero organisation and emails back what it did. The customer (or bookkeeper) reviews, edits if needed, and approves in Xero.

**Owners** also have a **settings dashboard** (account and company preferences). That dashboard is **not** a place to file documents. Day-to-day work is email → drafts in Xero.

## Set up Smart Bookkeeping
The customer-facing signup is guided and normally takes only a few minutes:

1. Open `https://graceaionboarding-production.up.railway.app/signup`.
2. Enter an email and verify it with the six-digit code.
3. Accept the Terms and Privacy information.
4. Connect Xero and select the **correct** Xero organisation.
5. Enter the owner/company details, optionally name the assistant, describe the business, and tick VAT registered only when correct.
6. Smart Bookkeeping imports the chart of accounts and active tracking options.
7. The completion screen shows the connected organisation, imported setup, VAT choice and live assistant email address. The customer can send the first file immediately.

VAT is **not automatically on**. It follows the customer’s onboarding choice. Do not promise a separate welcome email; use the completion screen as the source of readiness.

## How work is sent (critical)
- Filing, questions, rules, and setup requests are done by **email** to the assistant address from signup (for example `name@smartbookkeeping.uk`).
- Documents are **email attachments**. There is no Smart Bookkeeping page where customers drag, drop, or upload files to process bills.
- Do **not** tell anyone to drop files into a dashboard, website, Drive folder, or app. Do **not** invent a document-processing UI.
- Do **not** invent per-company inboxes. One assistant address; several companies are chosen by naming the organisation in the subject (or first line) when more than one is connected. One company only: the name can be omitted.

## Owner settings dashboard

### Who can open it
- **Owner:** can open the settings dashboard and manage the account.
- **Member:** can email documents and ask the assistant like anyone authorised — **cannot** open the dashboard. If a member needs dashboard access, an owner must promote them to owner (or the member creates their own account).

### How they access it
1. Open the Smart Bookkeeping **Owner Console** login: `https://graceuserconsoleadmindash-production.up.railway.app/login`.
2. Enter the **owner** email address and choose **Email me a dashboard link**. Smart Bookkeeping sends a secure magic link to that inbox; there is no password for this flow.
3. Open the email titled **“Open your Smart Bookkeeping dashboard”** and choose **Open your dashboard**.
4. Open the link within **24 hours**. If the email does not arrive, check Spam or Junk, then request a new link from the login page.
5. They land on **Settings** for their account, with companies in the sidebar.

Do **not** invent a document inbox or file-drop area on this dashboard.

### What the dashboard shows
Sidebar and Settings are account chrome — not a processing queue.

- **Sidebar:** Settings; **My companies** list (green tick = connected to Xero, red cross = not); **Add Company** (opens onboarding/signup to connect another Xero org); signed-in owner at the bottom.
- **Settings header:** selected company name; manage account and company preferences.
- **Total companies** count.
- **Current plan / credits:** plan name, included monthly credits used, purchased credits remaining, monthly and purchased-credit progress bars, **Manage plan**, and **Buy credits** (20, 40 or 80) through a secure Stripe session.
- **Users & Access:** who has access (owner vs member). Owner = dashboard + full access; Member = email filing only, no dashboard. Add/remove buttons typically **open a pre-filled email** to the assistant — they send that email and she confirms (CONFIRM/CANCEL flow as for other setup).
- **Billing & Connections:**
  - **Manage plan / Buy credits** opens Stripe securely; the customer can also open the Stripe Customer Portal to manage the plan, payment method, invoices or cancellation.
  - Xero connection status for the selected company + **Reconnect** button (same-org OAuth renew; see Xero workflows).
  - **Disconnect** → disconnects the selected organisation from Xero after confirmation; rules and settings stay saved for a later reconnect.
  - **Remove this company** → drafts an email to remove it from Smart Bookkeeping (subscription stays). For a clean break, also disconnect using either the Console button or Xero Connected apps.
  - **Change or cancel the whole subscription** → opens the Stripe Customer Portal and affects **all** companies — not the same as removing one company.
- **Security & Privacy:** retention summary (files/extracted data not kept as a customer archive; metadata only as described on the page).
- **Company settings** for the selected company:
  - **VAT status** (Smart Bookkeeping’s flag for how she enters drafts — not Xero’s own VAT registration UI). Change button usually **opens an email** asking her to switch it.
  - Chart of accounts / tracking option counts synced from Xero.
  - **Refresh accounts and tracking** → typically opens an email asking her to sync from Xero.

### Email-first: they can skip the dashboard for most of this
Plan and credit purchases open Stripe directly. Xero **Reconnect** and **Disconnect** also run directly in the browser. Most other “change something” controls **compose an email** to the assistant with the ask already filled in.

So if the customer asks “how do I add a user / change VAT / refresh accounts / remove a company / cancel?”, the advising AI should say:

1. **Preferred / always works:** email the assistant directly in ordinary language (see Manage companies & Xero settings and Xero connection workflows). She proposes; they CONFIRM when needed.
2. **Optional:** owners can open the settings dashboard, pick the company in the sidebar, and use the button that drafts the same email — then send it.
3. **Filing never moves to the dashboard** — still attach the file to an email.

Members should be told to email the assistant (or ask an owner), not to hunt for a dashboard login.

If a trusted person needs Console access, an existing owner can ask the assistant to add that person with the **owner** role, then CONFIRM. The new owner uses the login page above to request their own magic link. Do not imply that ordinary members can open the Console.

## Always drafts
Everything created is a Xero **DRAFT**. Smart Bookkeeping does not approve, publish, or post as live. It aims to get the customer most of the way there; they finish in Xero (approve, match, reconcile).

## File a document
Attach PDF, JPG, JPEG, PNG, HEIC, XLS, XLSX or CSV. Keep the whole email under **25 MB**.

- Ordinary supplier invoice, bill or expense: attach the file and send. Empty body is fine. Add a note only for tweaks. A supplier invoice to the customer becomes a draft **bill**.
- Sales invoice created **outside Xero** (Excel, Word, Numbers, Google Docs, old template, etc.): attach the PDF and say **“create an invoice”**. Otherwise it will make a **bill**, because it assumes the invoice is to the customer. If they already raise sales invoices inside Xero, they usually do not need to email those into Smart Bookkeeping.
- Spreadsheets (XLS, XLSX, CSV): table files. The assistant picks columns (dates, amounts, descriptions, etc.) automatically. The customer can name columns, and can save that as a lasting rule.
- Shop / multi-product receipts default to **one** summary entry. To file each product separately, they must ask (line-by-line / each item). They can send named items to different tracking options or properties, but must say where the **other** lines go too — otherwise those stay blank. Example: “Assign the Dyson hoover to Flat 1 and split everything else equally amongst the other flats.”
- Rental statements are usually recognised from the file and are **always** multi-line (each rent, fee and expense on its own line). No need to ask for line-by-line.
- Same-email overrides for that draft only: account (name or code; a close description often works), supplier/contact, amount, tracking, or a note such as “Note that this has been paid”. Changing the amount helps when the invoice is in dollars and they paid in pounds.
- Exactly one spreadsheet and one PDF or photo, without the words `separately` or `batch`: process the spreadsheet and attach **both** files to one draft. Say `separately` or `batch` to treat them as separate jobs.
- One bill from several PDFs as evidence only: subject must say they want **one** bill **and** that the files are attached (for example `Create a single bill and attach these PDFs`), with supplier and amount in the body.

## Create without a file
Create bill / invoice / quote / credit note in ordinary language (supplier or customer, amount, description). Quotes and credit notes should be **typed in the email**, not taken from a quote/credit PDF if they want a Xero Quote or credit note.

**Journals:** they must clearly ask for a journal entry (for example “make this a journal”). A **clearing / balancing account** must already exist in Xero (or be named in the email / saved as a rule). Without that, the draft cannot be completed.

## Recharge and split
- **Split:** percentages or named tracking options across properties or accounts.
- **Recharge:** they paid a supplier bill and want to charge someone else (or their share). Attach the supplier document and name who to invoice. That creates a draft bill for them, plus draft sales invoices to those people. Percentage splits across more than one person are supported.

## Rules (permanent) — how to fine-tune accuracy
Without rules she still processes documents, but rules are how customers get her **really accurate**. Teach lasting preferences once; she applies them on future files. Never 100% perfect, but this is the main way to get consistent coding.

Customers email her to make a **new rule** or to **remember** something going forward. Use wording like **create a rule**, **create new rule**, **new rule**, **remember…**, or clear **rule** intent — e.g. “Create a new rule: IKEA is purchases and supplies.” She proposes → **CONFIRM** if happy, **CANCEL** if wrong. Nothing saved until CONFIRM (24 hours). Account by **name or number** is fine. **General** rules (PDF + Excel) or **Excel / XLS** rules (spreadsheet statements only).

Do this **as you go**: when a draft in Xero is wrong, add a rule so next time is right. Managing rules is what takes results from average to really good; rules can be deleted later.

List with `list rules` / `show me my rules` / `what are the rules for [company]?` — reply shows **General** (`G1`…) and **Excel** (`E1`…) sections. Delete with `DELETE G1` or `DELETE E3`. DISABLE also deletes; it cannot be re-enabled.

A note sent with one file is **not** a rule — it only affects that draft. For a lasting fix, create a rule then CONFIRM.

Example rule types: agent code 440000 → your repairs 293; “Stripe fees are bank fees”; “Direct Debit Booking.com is commission”; “unit / room / flat mean the same for tracking”; “Flat A on the agent statement = 244 Harrow Road”; rental statements as journals to clearing; spreadsheet column maps; Excel code maps; supplier → account (e.g. Anthropic → 463 IT Software).

If a proposed rule already exists, she reports **CONFLICT DETECTED** / duplicates existing rule #N — no new rule needed for that line; other new rules in the same proposal can still be CONFIRMed.

## Undo and corrections
Reply `delete` with **no attachment** to the confirmation, keeping the subject code. Only **DRAFT** records can be deleted by email. Approved or live Xero documents are never deleted by email — absolutely blocked. Handle those in Xero.

To change figures on a draft: resend the file with the correction, or edit in Xero. A high-confidence matching draft (invoice number, supplier and date) is updated in place without changing its number.

## Duplicate handling (technical — keep this complete)

Duplicates are about protecting live Xero data and avoiding a second upload of the same bill/invoice. The advising AI should explain the branch that matches the customer’s situation — not invent auto-void or auto-renumber.

### What “duplicate” means here
She looks at Xero (and related guards) using document identity — typically **invoice/bill number**, **supplier/contact**, and **date** — not “same amount” alone. Recurring invoices with the same supplier and value but a **different date** should **not** be rejected just because the amount matches.

### Branch A — Matching **DRAFT** already in Xero (safe update)
If a high-confidence match is still a **DRAFT** (same number / supplier / date style match):

- She **updates that draft in place**.
- The **invoice/bill number stays the same**.
- Useful when the customer resends a corrected file, or accidentally emails the same document twice while it is still a draft.
- Customer can also reply `delete` on the confirmation (no attachment, keep the subject code) and resend — still draft-only.

### Branch B — Live / approved document (hard stop)
If Xero already has the document as **approved, submitted, paid, credited**, or otherwise **not a draft**:

- She **does not** upload over it.
- She **never** voids, deletes, or overwrites approved/live documents by email.
- She **does not** automatically renumber to force a second copy past a live document.
- Customer must handle the live document **in Xero** themselves (edit, void, or delete there if appropriate). Then they can resend if a new draft is still needed — see Branch D if the old number is still reserved in Xero history.

### Branch C — Suspected duplicate (blocked before / without a successful new upload)
If she thinks the file is a duplicate (or Xero rejects it as one):

1. The file is **not** uploaded as a new draft (or the create is refused).
2. The reply **names the file**, explains why, and **returns the original attachment**.
3. Typical customer wording in the reply includes something like “Duplicate detected” / “File not uploaded” and the instruction to override if wrong.

**If the customer believes it is *not* a duplicate:**

1. Resend **or** reply **with the attachment still attached**.
2. Write clearly: `This is not a duplicate` (same idea in plain English is fine if the intent is obvious).
3. That override can clear a **Grace-only / suspected** block so she tries again.
4. It **cannot** force past a **live** Xero document (Branch B). Live docs stay blocked.

Without the file on the override email, she usually cannot complete the second attempt.

### Branch D — Number still exists after delete/void in Xero (historical / collision)
Common after the customer deletes or voids the old bill in Xero, then resends the same invoice number:

1. First resend may still be **stopped**; original file returned — Xero can still “see” the number.
2. Customer resends the returned file again with `This is not a duplicate`.
3. **Only when every Xero record holding that original number is DELETED or VOIDED** may she create a new draft using a **safe numbered suffix** (example style: `LS0707-1`), and keep the original number in **Reference** so the link to the source number is visible.
4. If Xero still has a non-deleted/non-voided collision, she will not invent a bypass — they must resolve it in Xero first.

### What the customer reply looks like (advise accurately)
- Stopped suspected duplicate → attachment returned + how to say `This is not a duplicate`.
- Exists / cannot modify (live) → cannot be modified via Smart Bookkeeping; fix in Xero.
- Historical deleted/voided path → may mention numbered suffix after a confirmed non-duplicate override when safe.

### What never to advise
- Do not say she will void or overwrite an approved bill because they resent the PDF.
- Do not say amount alone proves a duplicate.
- Do not say `This is not a duplicate` without the file will always work.
- Do not say the override can replace a live Xero document.
- Do not confuse **duplicate of a filed bill** with **exact duplicate rule** when saving rules (rules may skip CONFIRM if the same rule already exists — different feature).

## Questions (do not create drafts)
Examples: Has this been paid? Is this in Xero? Show unpaid invoices. Profit and loss. Balance sheet. Email the chart of accounts. Which companies? Spending / rental income style questions.

Attachments on questions are **evidence only** — not filed.

- “Last year” / “last accounting year” = the most recently completed **reporting year** (6 April to 5 April), not the calendar year. Month asks are fine (for example “last month” or “March 2025”).
- She can email a **new** P&L or chart of accounts PDF from live Xero data.
- She **cannot** re-send previously filed receipt or statement PDFs. Open the document in Xero and download the attachment there.

## Manage companies & Xero settings (after onboarding)
Phrases below are **example wording**, not exact commands. She infers intent.

| Capability | Notes |
|---|---|
| Automatic chart of accounts / tracking refresh | Onboarding imports both. At the start of a later run, saved data over 24 hours old triggers a **background** refresh. The triggering file may still use the previous saved list because processing continues while refresh runs. There is no fixed daily COA cron. |
| Immediate refresh / sync | If the customer just changed Xero and needs that account or tracking option now, email `refresh my chart of accounts` or `sync accounts and tracking`. An explicit sync pulls both immediately. |
| Reconnect when Xero access fails | See **Xero connection workflows** below. Same organisation only. |
| Add organisations | See **Connect / add a company** below. Unlimited with **fair use**. |
| VAT on or off | `enable VAT` / `disable VAT`. Changes the VAT flag in **Smart Bookkeeping** (how she enters documents) — does **not** change VAT registration in Xero. Needs CONFIRM. Also in the dashboard. |
| New chart-of-accounts code | e.g. add a parking expense account. Proposal → CONFIRM / CANCEL. |
| New tracking option | e.g. `Create new unit tracking category: Unit 10`. She emails a PDF of headings/options, proposes a heading; reply CONFIRM, CANCEL, or correct the heading. Xero changes only after CONFIRM. |
| Email chart of accounts | PDF reply. |
| Users | Unlimited with **fair use**. Owner only. Name the person’s email, role and which orgs (all, or named). Example: `Add user example@outlook.com as a member to all companies`. Proposal → CONFIRM / CANCEL. Owner role grants Console and user-management access. Also Owner Console → Settings. |

## Xero connection workflows (technical — keep this complete)

Smart Bookkeeping can only create drafts while a Xero organisation is **connected** (OAuth tokens valid for that org). Once connected correctly, leave the link alone. The steps below are for first connect, reconnect after auth failure, voluntary disconnect, removing a company from the account, and fixing a wrong organisation chosen at onboarding.

### Concepts (do not confuse these)
| Thing | What it is | What it is not |
|---|---|---|
| **Connect / onboard** | Browser OAuth: customer authorises Smart Bookkeeping for a **chosen** Xero organisation. Started via signup link or `add new company`. | Not finished by email alone. Email only sends the link. |
| **Reconnect** | Renews OAuth for the **same** organisation already linked (expired token, revoked access, auth failed). | **Not** how you switch to a different company. |
| **Disconnect Xero** | Owner chooses **Disconnect** for the selected company in the Owner Console, or the customer removes the app under that organisation’s **Connected apps** in Xero. Either route stops API access for that organisation; choose one, not both. | Does **not** cancel the Smart Bookkeeping subscription. Does **not** by itself remove the company from the Smart Bookkeeping sidebar/account. |
| **Remove company from Smart Bookkeeping** | Company taken off the account so it is no longer a filing target / sidebar entry. Ask by email (or settings draft) naming the company; say subscription must stay. | Does **not** cancel the subscription. For a clean break, also use either disconnect route. |
| **Subscription cancel** | Ends billing for the whole account. Separate from disconnect/remove one company. | Not the fix for a wrong org or a single company unlink. |

Direct Xero Connected apps URL (use this): https://go.xero.com/Settings/ConnectedApps  
In Xero the app may appear as **Smart Bookkeeping**, or historically as **Grace** / **Grace Systems**.

### Connect / add a company (first time or another organisation)
1. Customer emails something like `add new company` / `I’d like to add another company`, **or** uses Add Company / signup from the settings dashboard.
2. Smart Bookkeeping emails an **onboarding / signup web link**. Setup is completed in the **browser**, not by email reply.
3. Customer signs into Xero and reaches the **organisation picker** — which organisation to allow.
4. **Critical step:** they must select the **correct** Xero organisation. That picker is where wrong-company mistakes usually happen.
5. After success, that org appears on the account. With more than one company, put the company name in the email **subject** when filing.
6. Organisations are unlimited with **fair use** (may be capped if abused).
7. If they try signup again for an organisation already in use, they may be told to email `reconnect to xero` or `add new company` instead of re-running the same signup.

### Healthy state
Connected correctly → no need to touch connection. Filing goes to the named (or only) organisation. Rules and learning for that company stay with it across reconnects.

### Auth failed / expired / “Xero disconnected” → Reconnect (same company)
Use when: connection expired, was revoked, or authentication failed while filing. Drafts cannot be created until fixed.

1. Prefer naming the company in the subject if they have more than one.
2. Either:
   - Email `reconnect to xero` / `xero disconnected` (she sends a reconnect link), **or**
   - Open the settings dashboard → Settings → **Reconnect** for that company, **or**
   - After a failed process she may email a reconnect link automatically.
3. Open the link within **one hour**. Expired/used → email `reconnect to xero` again.
4. Sign into Xero and select the **same** organisation already linked (the name in the email / settings).
5. Do **not** disconnect the app in Xero first for a normal reconnect.
6. Reconnect refreshes tokens. **Rules and learning for that company are kept.**

### Voluntary disconnect (customer wants to stop the app for an org)
Choose either route below; the customer does **not** need to do both:

**Owner Console**
1. Open `https://graceuserconsoleadmindash-production.up.railway.app/login`.
2. Enter the owner email and open the **“Open your Smart Bookkeeping dashboard”** email within **24 hours**.
3. Select the company → **Settings → Billing & Connections → Disconnect** → confirm.

**Xero**
1. Open that organisation in Xero.
2. **Settings → Connected apps** (https://go.xero.com/Settings/ConnectedApps).
3. Find **Smart Bookkeeping** (or Grace / Grace Systems) → **Disconnect**.

Either route stops Smart Bookkeeping creating drafts for that organisation until it is reconnected. Rules and settings stay saved; the subscription and other companies are unchanged.

To also stop emailing for that company (remove it from the account / sidebar), ask to **remove** the named company and say **do not cancel the subscription**. A clean break needs company removal plus one of the two disconnect routes.

### Wrong organisation selected at onboarding / connect (common mistake)
Symptom: they authorised the **wrong** Xero company on the setup screen. Smart Bookkeeping is now linked to that wrong org. Drafts would go to the wrong Xero file.

**Do not use `reconnect to xero`.** Reconnect only renews the organisation already linked (the wrong one).

Full fix — walk the customer through this order:

1. Disconnect the **wrong** organisation using one route:
   - Owner Console: select the wrong company → **Settings → Billing & Connections → Disconnect** → confirm, **or**
   - Xero: open the wrong organisation → **Settings → Connected apps** (https://go.xero.com/Settings/ConnectedApps) → find **Smart Bookkeeping** (or Grace / Grace Systems) → **Disconnect**.
2. If that wrong company **still appears** in Smart Bookkeeping (dashboard sidebar / company list), ask the assistant (or support via the settings email draft) to **remove** it by exact name, and say they do **not** want to cancel the subscription.
   → This deletes it from the Smart Bookkeeping account side.
3. Re-onboard: email `add new company` (or use the add-company / signup link again) and complete the **browser** steps.
4. **Careful step:** when Xero asks which organisation to allow, select the **correct** company. Stress this picker.
5. Afterwards, put the **correct** company name in the email subject when filing.

Disconnecting does **not** cancel the subscription. Removing one company does **not** cancel the subscription.

Example wording for the remove-company step:

```
Subject: Remove Wrong Org Ltd
Please remove Wrong Org Ltd from my Smart Bookkeeping account.
This is only Wrong Org Ltd. Please do not cancel my subscription.
```

Example wording for reconnect (different problem — same org, auth dead):

```
Subject: Example Co Limited — reconnect to xero
Xero seems disconnected. Please send a reconnect link.
```

### Decision guide for the advising AI
| Customer says / situation | Correct path |
|---|---|
| “Auth failed” / “please reconnect” / filing stopped / token expired | **Reconnect** same org (email or dashboard). Do not disconnect first. |
| “I want to unlink the app” / stop drafts for this Xero org | **Disconnect** using the Owner Console or Xero Connected apps. Optionally **remove** it from Smart Bookkeeping too. |
| “I picked the wrong company when connecting” | **Disconnect wrong org** in the Owner Console or Xero → **remove** from Smart Bookkeeping if it still shows → **`add new company`** → pick **correct** org in Xero picker. Never reconnect-as-fix. |
| “Cancel my subscription” | Separate billing cancel for **all** companies — not the same as disconnect/remove one org. |
| “Add another company” | Signup / `add new company` link → browser OAuth → careful org picker. |

### What never to advise
- Do not fix a wrong-organisation link with reconnect alone.
- Do not tell the customer to disconnect twice. The Owner Console button and Xero Connected apps are alternative routes to the same per-organisation disconnect.
- Do not invent drag-and-drop file upload for reconnect or onboarding.
- Do not say disconnecting or removing one company cancels the subscription.
- Do not guess which organisation when several are connected — ask, or have them put the name in the subject.

## If something is missing
The assistant asks. Do not guess the company when several are connected. Do not promise Drive folders, drag-and-drop upload, posting as approved, or retrieval of a local file archive.
