# Admin Guide

For the gym owner and Admin staff. No technical knowledge is needed. Labels in **bold** are the words you see on screen (English); the Urdu screens have the same layout from right to left.

> Switch language with the **English / اردو** button and the theme with the sun/moon button, at the top of every screen. Your choice is saved on your account.

## 1. First start (once)

1. The technical operator installs the app and runs the setup command, which prints a one-time **setup token** (valid 24 hours). See `docs/DEPLOYMENT.md` §5.
2. Open the web address, go to **/setup**, and fill in **Create the first Admin**: the token, your username, email, name and a password of at least 12 characters (common passwords, and passwords containing your username or email, are refused).
3. After this, setup is closed for good. Further Admins and Trainers are added under **Staff**.
4. Open **Website → Gym** and enter the gym name, address, phone numbers, opening hours and default language. Then **Plans**, to add your membership plans and prices.

## 2. Signing in and your account

- **Sign in** with your username or email and password. After a few wrong passwords the screen slows down (it never locks you out).
- You stay signed in on each device for up to 90 days of inactivity. **Sign out** from the account menu.
- **Forgot your password?** Admins get a reset link by email (valid 30 minutes; it signs you out everywhere). Trainers ask an Admin instead.
- **Profile**: your name, phone, language and (Admins only) your password. Changing your password signs out your other devices.

## 3. Dashboard

Everything is calculated on the server in Pakistan time.

- **Money**: today's collections, this month's income (split Cash / Online) and outstanding payments. Only verified payments count, on the date they were paid.
- **Members**: total, active, inactive and expired. Archived members are not counted (a note shows how many there are).
- **Daily income this month** chart (**Show as a table** for exact numbers), **Today** (new members and inquiries), **Ending in the next 7 days**, **Payment status**, **Trainers** (last sign-in) and **Recent payment corrections**.
- A yellow or red bar at the top warns when backups are not set up, failed or are overdue.

## 4. Inquiries (Join Now form)

1. Visitors fill in **Join Now** on the website. New inquiries show a badge on **Inquiries**.
2. Open one, call the person (the **Call** button), and set the **Status** (New, Pending, Approved, Rejected). A "Member" badge means the phone number already belongs to a member.
3. To sign them up, press **Add member**: the form is filled in from the inquiry, including their WhatsApp choice.
4. You can **Delete inquiry** afterwards (password, reason, confirmation); the member and all their history stay.

## 5. Members

- **Members** lists Active, Inactive and Archived members with search, filters and sorting.
- **Add member**: name, phone (one member per phone number), age, gender, address, and whether they agree to WhatsApp messages. Each member gets an ID like **GYM-001**.
- On a member's page: edit details, upload or replace the photo, Admin notes (Trainers can read but not change them), memberships, payments, workout notes, WhatsApp messages and consent history.
- **WhatsApp consent**: **Record consent** or opt the member out. Opted-out members receive nothing, automatic or manual.
- **Archive** a member who has left (not possible while they have an active membership); **Restore** brings back the same record and ID. Trainers can do both.
- **Delete permanently**: members always have history that is kept forever (WhatsApp consent, messages, notes, payment corrections), so the app shows why they cannot be deleted and suggests archiving. This is deliberate (D-131). Photo removal is Admin-only.

## 6. Plans and memberships

- **Plans**: **Add plan** as Monthly (1 or more calendar months) or a number of days, with a price. **Deactivate** hides a plan from the website and from new sales; existing memberships keep their terms.
- On a member's page, **Add membership** (or **Renew**): choose a plan; Admins may set a **custom price** with a reason (it is logged). Record the first payment now if you have it.
- A membership becomes active only after **at least part of the price is paid and verified**: **Save and activate**, or later with **Activate**.
- Dates are worked out by the app: a monthly plan from 15 Jan ends 14 Feb; renewing early starts the day after the current one ends (shown as Upcoming); renewing late starts on the activation date. Every renewal is a new record; earlier ones stay in the history.
- Each night the app expires finished memberships (the member becomes Inactive) and starts Upcoming ones. **Expiries** lists memberships ending in the next 7, 14 or 30 days.

## 7. Payments and receipts

- Open **Payments** from a membership. **Record payment**: amount, Cash or Online, date (today or earlier, never later), optional reference. You cannot pay more than is due.
- **Cash** is always verified. **Online** can be marked verified (you have seen it in the account) or left **pending**: pending money does not reduce the balance until someone presses **Verify** (or **Reject**, with a reason).
- Each verified payment gets a numbered **receipt** (REC-0001 …), viewable as a PDF and shareable (**Share REC-…**: by WhatsApp, or download it and press **I shared it myself**).
- **Correct** a payment (amount, method, date, reference) with a reason: the old receipt is marked VOID and a new one is issued; the correction history is kept forever. Admins can also **Correct total due**.
- **Payments** in the menu (Admin only) is the full ledger with filters.
- Permanent deletion of receipts, payments and membership records is possible for Admins with your password, a reason and a second confirmation, in that order (receipts first). Use it only for genuine mistakes; corrections are usually the right tool.

## 8. Staff

- **Add staff**: Admin or Trainer, username, name, optional email/phone, and a password.
- **Deactivate** a Trainer who leaves: they are signed out at once. **Reactivate** later if needed.
- **Reset password** (Trainers) and **Sign out of all devices**.
- **Delete permanently** removes the account's access but keeps everything they recorded, under their name. You cannot deactivate or delete yourself or the last active Admin.

## 9. Exercises and workout notes

- **Exercises**: shared library; anyone can **Add exercise** or edit (names are unique). Exercises are not deleted.
- **Workout notes** on a member's page: anyone can add; Trainers edit or delete only their own; Admins can edit or delete any and see deleted notes. Deleting hides a note but keeps it. Notes of archived members are read-only.

## 10. WhatsApp

Until the Meta WhatsApp account is connected, the app is either **off** or, on a test system, in a clearly labelled **simulated** mode. Nothing is sent to anyone in simulation.

- **WhatsApp → Templates** (Admin): create message templates, which Meta must approve. Choose a default template for each automatic message: membership confirmation, payment received, expiry reminder (set how many days before, 1–30) and membership expired. Reminders and expiry notices are sent at 10:00.
- **WhatsApp → Messages**: every message and its status. Temporary failures are retried every 15 minutes, 3 times; then they are marked Failed. Filter **Needs a follow-up only** and **Mark as followed up** after you have handled it.
- On a member's page, **Send WhatsApp message** sends an approved template (only to members who agreed and have not opted out).

## 11. Expenses and reports

- **Expenses**: **Add expense** with title, category (Rent, Utilities, Salaries, Equipment, Maintenance, Other), amount in whole rupees, date (not in the future) and Cash/Online. Edit any time (history is kept); delete with your password.
- **Reports**: Income, Expenses, Summary and Members, for this month, last month, this year or any dates (up to two years). Filter Cash/Online. **Download PDF**. Income and expenses are shown separately; there is no profit figure. Archived members appear only if you tick **List archived members**.
- **Export personal data** (Members report) needs your password and is recorded in the Activity Log.

## 12. Settings

- **Overview**: links to gym details and reminder days, the deletion rules, and the sign-in, password and record-keeping rules (read-only: they are fixed requirements).
- **Activity Log**: who did what and when, filterable. Personal details are never stored there, only which fields changed. Kept 2 years.
- **Login history**: every sign-in attempt. Names that match no account are shortened (in case a password was typed by mistake). Kept 2 years.
- **Backups**: status of the weekly backup (Sundays 03:00), how many are kept (8), the last success and recent runs. **Restoring is done by the technical operator, not in the app** (`docs/BACKUP_RESTORE.md`).

## 13. Good practice

- Give each person their own account; never share passwords.
- Deactivate Trainers on their last day.
- Check **Payments → pending** and **WhatsApp → Needs a follow-up** regularly.
- Glance at **Settings → Backups** weekly; tell the operator if it shows a warning.
- Keep the backup encryption key's offline copy somewhere safe: without it, backups cannot be restored.

## 14. If something goes wrong

| What you see                                                    | What to do                                                                                   |
| --------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| "Please sign in to continue"                                    | Your session ended (inactivity, password change, or an Admin signed you out). Sign in again. |
| "This request was blocked because it did not come from the app" | Open the app from its normal address, not a saved copy of a page.                            |
| "Someone else changed this … Reload it and try again"           | Two people edited the same thing; reload and repeat your change.                             |
| A member cannot be deleted                                      | Expected; archive them instead (§5).                                                         |
| Activate is not offered                                         | Record or verify a payment first (§6).                                                       |
| Images cannot be uploaded                                       | Image storage (Cloudinary) is not connected yet; the operator must set it up.                |
| WhatsApp shows "off" or "simulated"                             | The Meta account is not connected yet (operator task).                                       |
| Backup warning on the dashboard                                 | Tell the technical operator.                                                                 |
