# Whole-project audit — 16 November 2026 (what was looked at, the checks, the rules, the results)

Prepared by the owner with Claude (AI engineer) for the owners and for TravelClip. It follows handbook 25 (how to audit) and
continues handbook 24 (the financial audit of the same day). Every test was run on COPIES of the database — never the live one.
Read with: 27 (the repeatable checklist), 28 (what other package builders and corporate tools have that we do not), 29 (every
money flow, split, report and who to pay).

## 1. Opinion in one sentence
Ready to go live on the money side: the engine is proven, every sale adds up to the cent, no live deal loses money on any ticket
size, refunds and cancellations are recorded with their reasons and references, and the security tests all pass — with matters to
note below (thin margins on big corporate tickets, a self-test that must be run on the baseline database, a few product gaps).

## 2. What was looked at, how, and the result
| Area | What was checked | How | Result |
|---|---|---|---|
| Code syntax | Every PHP file (224) and every admin/booker/site JavaScript file (91) | `php -l`, `node --check` | 0 errors |
| Leftovers | Debug output (var_dump, print_r, console.log), TODO/FIXME | search of src, api, admin, corporate | none (one false hit: the text "PKG-XXXXXX") |
| Money engine | Every rule, guard, permission and document end to end | self-test `tools/backoffice-audit.php` on the baseline database (pre-sortout 2026-11-08) | 522 / 522 (528 / 528 later the same day, with the launch-phase tests) |
| Money engine on TODAY's settings | Same self-test on a copy of the live database | as above, default source | 476 / 520 — the 44 failures are ONE cause: the test's own agent deal would lose R0.84 on a coach ticket under today's 1% card fee and 2.9% + R2 gateway, so the deal guard (correctly) refuses to save it and every later step that needs that deal fails. Not a defect; the guard works. Run the self-test with `GW_AUDIT_SOURCE=storage/backups/pre-sortout-2026-11-08.sqlite`. |
| Security controls | Sessions hashed and never in an address, throttles, gateway amount must match, payout changes need the password and are told to the owner, two-step sign-in (RFC 6238), signed document links, audit log sealed after go-live | `tools/security-audit.php` | 74 / 74 |
| Security forensic sweep | 256 API actions × nobody / customer / agent / suspended agent / admin: access, isolation (agent A cannot see or change agent B), money tables untouched by anyone below admin, injection (SQL, HTML, paths, templates, type confusion, oversized input) | `tools/security-sweep.php` | see section 5 |
| Every sale adds up | Each paid sale: sale = supplier + gateway + VAT + agent + Getaway + API Travel Solutions (+ what was kept on a cancellation) | new Finance → Platform → "Every sale — who gets what", checked over Aug–Nov | 191 sales, Check R0.00 on every line (one line first showed −R1 100: a cancelled sale whose kept amount is a label line like "sale" — fixed so the line shows "Sale (or kept)") |
| Live deals on today's settings | Our own sales, every agent, every corporate client, at a usual ticket, R500 and R20 000 | the real pricing engine (sale calculator) for each | No deal loses money at any size. Thin: corporate fixed fees on big tickets (keeps R172.83 on a R20 898 flight, R21.03 on a R20 717 coach trip); agents' flights at R20 000 keep about R105 (0.5%); Kestrel R5.12 on a R774 flight. |
| Refunds and cancellations | Every channel (see section 3) | code trace + data | Sound; every refund needs amount, reference, supplier penalty, our fee, gateway fee; credit note issued; agent commission reversed or clawed back |
| Payment before booking | Any booking "on account" | data + code search | 13 on-account bookings, all corporate test trips on 3–4 Nov (before the rule), all cancelled with R0 paid. No code path can create on-account any more; only reads remain for old data. 188 unpaid cancelled seed bookings from 26–27 Sep, R0 paid. |
| TravelClip doors | Who can talk to it, what it can read | code review | Only logins with ai_logins; booker/agent jump-in only on a signed one-hour pass made from the owner's dashboard; CORS only for this server's own host; tech mode needs the secret (hash only, per session) and is never available in a booker; file reader refuses .git, config folders, client config.php, keys, .env, .sqlite, backups, partner documents, TravelClip's memory; SQL reader refuses password/token/secret/session tables and columns and is read-only. Books-proof run uses a fixed path, no user input. |

## 3. Refunds — how each channel is tracked (even when we do it by hand)
- **Guest or agent booking cancelled after payment** → status cancelled, pay status `refund_due`; it shows on the dashboard and in
  Finance until the refund is recorded. "Record the refund" (`booking-refunded`) needs: the amount that went back, its reference
  (gateway or bank — a refund done by EFT outside the gateway is recorded the same way), the supplier's penalty, our cancellation
  fee and the gateway fee. It needs two-step sign-in from go-live. It writes the refunds table, a credit note, reverses the ledger
  lines not yet on a statement, and puts a clawback on the agent's next statement for lines already paid (`reversed_settled`).
  A refunded booking can never be reopened; a new booking is made instead.
- **Chargeback** → the same action with kind = chargeback (shows as a chargeback in Finance → Platform refunds).
- **Corporate client cancels a sector** in their booker → cancelled + `refund_due` if paid, admins notified, ledger synced; a
  sector already refunded, travelled or in the past cannot be cancelled (refuses).
- **On-request product not confirmed in 12 hours / deposit balance not paid by its due date** → cancelled automatically, `refund_due`
  when money came in.
- **What the books show**: Finance → Platform → refunds (paid, refunded, kept, supplier penalty, our fee, gateway fee, reference);
  credit notes in Books; VAT register adjusts in the month of the credit note.

## 4. Products — what we cover (corporate, agent) and the gaps
**Corporate booker has:** policy, approvals board, traveller profiles, trips and sectors, invoices and statements, monthly fee,
card fee, per-sector service fees, budgets, calendar, desk, training, cancellations with refund-due, reports, own domain/folder,
the owner's jump-in with TravelClip.
**Agent (non-corporate) has:** sign-up and verification, a deal (the only source of their rates), trading rule (no deal = cannot
trade), own packages with approval, links and sites, quotes, sales, monthly statements, payout details protected by password,
commission earned on travel and reversed on cancellation, desk, training.
**Gaps found against other tools** → handbook 28.

## 5. Security sweep result
16 API files, 256 actions, five kinds of visitor: 1 024 access calls, 909 isolation calls (agent A and customer 1 using agent B's
and customer 2's ids and e-mail), 7 020 hostile injection calls as nobody/agent/customer and 1 896 as an admin, plus a check of
files that must never be served. No money table was changed by anyone below an admin; no other agent's or customer's private
data came back; no SQL error, stack trace or file path in any answer. It raised 14 flags; each was checked by hand:
| Flag | Verdict |
|---|---|
| change-password "answers" nobody / customer / suspended (4 flags) | Sweep artefact: the sweep itself skips sign-out actions and returns "skipped"; the real action needs a login and the current password. |
| quote-mail-preview reachable by an agent | By design: agents make and mail their own quotes; it answered "Quote not found" for someone else's. |
| /log.php is served | Only on this computer (the local dev server, 127.0.0.1). Anywhere else it needs the secret log key, otherwise 403 Forbidden. |
| /uploads/ shows the PHP version (X-Powered-By) | Live hosting (Apache) already removes it in .htaccess. The local server showed it on bare folders — FIXED: the router now answers bare folders with its own plain 404. |
| partner/email-send answered 502 to hostile input | The polite "could not send the e-mail" message (no mail server on this computer) — no crash, no leak. |
| review.php and pay-balance.php open for strangers (6 flags) | False alarm: both pages show only the form and "We could not find a booking with that reference and e-mail" — a booking is shown only with its reference AND the e-mail it was booked with (and lookups are throttled). |
Verdict: no real vulnerability found; one cosmetic header fixed.

TravelClip's "audit" answer now also runs every live deal (our own sales, each agent, each corporate) at a usual ticket, R500
and R20 000 on today's settings, and lists losses and thin sales (we keep under 1%) grouped by sale type.

## 6. Matters for the owners (decisions, not defects)
1. Corporate fixed service fees do not grow with the ticket — on a R20 000 ticket we keep under 1%. Consider a % fee with a minimum.
2. Kestrel Mining: R5.12 kept on a R774 flight; agent share on this client still larger than ours (handbook 24).
3. Agents' flights at R20 000 keep about 0.5% — fine for volume, but watch it.
4. Monthly-fee split is now fixed at 50% (it was "follow the live rule").
5. Invoice legal details must be entered before go-live (go-live refuses without them).
6. The self-test should be run on the baseline database; its own test deals do not include a coach fee.
7. The TravelClip jump-in pass lasts one hour and cannot be cancelled early (low risk: it lives only in that tab).

## 7. What changed during this audit
- Finance → Platform → **Every sale — who gets what**: one line per sale, every party's rand, Check column (always R0.00).
- Rates by client → **The money map**: every way we sell, who sets the price, what we earn, which owners' split applies, where to
  change it, and "See a sample sale" through the real engine.

## 8. Lessons
- A test that passes on old data can fail on new settings because the guards are doing their job — read the reason before
  calling it a bug.
- Fixed fees are the commonest silent margin leak on big tickets; always run the sample sale at R500 and R20 000.
- Show every sale on one line with a Check column: the books prove themselves to anyone who reads them.
