# Tenant Management

## What is a Tenant?

A **tenant** represents one ISP business. Each tenant:
- Gets its own subdomain (`{slug}.eims.test`)
- Sees only its own customers, bills, packages, and users
- Can be independently suspended or activated

---

## Tenant Fields

| Field | Description |
|---|---|
| `name` | Business display name |
| `slug` | Subdomain identifier (lowercase, no spaces) |
| `phone` | Primary business phone |
| `email` | Business contact email |
| `address` | Physical address |
| `logo` | Logo image (stored in `storage/business/logo/`) |
| `prop_name_1/2` | Proprietor names (for bill header) |
| `prop_phone_1/2` | Proprietor phones |
| `status` | `active` / `suspended` / `cancelled` |
| `subscription_plan` | `trial` / `basic` / `pro` |
| `subscription_expires_at` | Subscription expiry date |

---

## Creating a Tenant (Super-Admin)

1. Log in to `https://eims.test` as super-admin
2. Go to **Tenants → Add Tenant**
3. Fill in business details and slug
4. A domain record is automatically created as `{slug}.eims.test`
5. Create the tenant admin user and assign the `admin` role

---

## Tenant Isolation

All tenant data is filtered by `tenant_id` automatically. When a user accesses
`isinternet.eims.test`, the tenancy middleware:

1. Reads the subdomain (`isinternet`)
2. Looks up the matching tenant record
3. Stores the tenant in scope for the duration of the request
4. All queries automatically filter to that tenant's data

---

## Suspending a Tenant

Set `status = suspended`. Suspended tenants receive a maintenance page instead
of the normal application.
