# Customer Management

## Global Customer Registry

Customers are stored in a **shared registry** across all tenants. Each customer's
identity (CNIC, contact, name) is stored once globally. Tenant-specific data
(package, village, internet ID, status) is stored in `tenant_customer_profiles`.

This design prevents duplicate customer records when the same person has
connections with multiple ISPs on the platform.

---

## Deduplication Rules

When adding a new customer, the system checks:
1. **CNIC** — must be globally unique
2. **Contact number** — must be globally unique

If a match is found:
- The existing customer record is reused
- A new `tenant_customer_profile` is created for this tenant
- The user is notified that the customer already exists in the system

---

## Customer Fields

### Identity (global, shared)
| Field | Description |
|---|---|
| `name` | Full name |
| `father_name` | Father's name |
| `cnic` | National ID — globally unique |
| `contact` | Phone number — globally unique |
| `email` | Email (optional) |
| `photo` | Profile photo |

### ISP Profile (per tenant)
| Field | Description |
|---|---|
| `internet_id` | ISP-assigned connection ID |
| `package_id` | Subscribed package |
| `village_id` | Village/area |
| `address` | Physical address |
| `status` | `active` / `inactive` / `suspended` |
| `due_amount` | Carried forward dues |
| `docs` | JSON — scanned documents |

---

## Adding a Customer

1. Go to **Customers → Add Customer**
2. Enter CNIC — system checks for existing match
3. If new: fill in full identity and ISP profile details
4. If existing: confirm reuse and fill in ISP profile only

---

## Bulk Import

1. Go to **Customers → Import**
2. Download the CSV template
3. Fill in customer data (one row per customer)
4. Upload the file
5. Preview the import (shows matches and new records)
6. Confirm to import

Existing customers (matched by CNIC or contact) are not duplicated — only their
tenant profile is created if missing.

---

## Customer Status

| Status | Meaning |
|---|---|
| `active` | Connection active, bills generated monthly |
| `inactive` | Connection off, no new bills |
| `suspended` | Temporarily suspended |
