# Xero sync

TowConnect sends invoices, contacts and payments to Xero automatically, and brings back payments recorded in Xero.

Once **Xero** is connected, TowConnect keeps the books in step with it. Nothing is entered twice. When an invoice is sent, TowConnect creates it in Xero. When an invoice is marked paid, TowConnect records the payment there. When a payment is recorded in Xero, TowConnect marks the invoice paid. TowConnect syncs in the background about every 5 minutes.

## Connecting

1. Go to **Settings → Connect → Xero** and click **Connect Xero**.
2. Sign in to Xero and choose the organisation to link.
3. Back in TowConnect, the card shows **Connected to** and the organisation's name. Set the 2 account codes (below) and press **Save**.

## The 2 account codes

- **Sales account code**: the income account that invoice lines are posted to, from the Xero chart of accounts (in Xero, **Accounting → Chart of accounts**). Xero's default sales account is `200`.
- **Payment account code**: the account that payments are recorded against, usually the business's bank account (Xero's default is `090`). It must have **Enable payments** ticked in Xero.

## What syncs, and when

- **When an invoice is sent**, TowConnect creates or updates the customer as a Xero contact. Business customers carry their ABN and payment terms, and walk-in jobs use the job's contact. TowConnect then creates the invoice in Xero as **Awaiting Payment**, with GST set from the workspace's tax settings and any PO or order reference.
- **When an invoice is marked paid**, TowConnect records the payment on the Xero invoice against the payment account.
- **When a payment is recorded in Xero** and the invoice is fully paid there, TowConnect marks the invoice paid automatically and sends a bell notification.

Every invoice shows a sync label: **Xero pending** (waiting for the next background sync), **Xero ✓** (synced) or **Xero failed**, with a **Retry** button.

> The sync never emails or texts customers, because it only moves accounting records. Customers get an email only when an invoice is sent.

> TowConnect reflects a part payment in Xero only once the invoice is **fully paid** there. Invoices sent before Xero was connected are not copied. Only invoices sent while Xero is connected are synced.

## If a sync fails

- The invoice shows a **Xero failed** label. The most common causes are a wrong account code or an archived Xero contact.
- Fix the cause, for example by correcting the code under **Settings → Connect → Xero**, then press **Retry** on the invoice.
- After repeated failures, the workspace's admins get a notification. TowConnect keeps trying in the meantime.
- If the card shows **Needs reconnect**, connect again from the card. Nothing else needs fixing.

## Disconnecting

When **Disconnect** is pressed under **Settings → Connect → Xero**, TowConnect stops syncing and gives up its access to Xero. Invoices already in Xero stay there unchanged, and TowConnect keeps the sync history.
