# Deploy — 11 new features

## NEW files (4)

| File | Purpose |
|---|---|
| `includes/admin_list.php` | Shared list toolkit — sticky filters, search, CSV export, stat cards |
| `includes/notify.php` | Notification engine — links, types, send, delete, read tracking |
| `admin/notifications.php` | Admin → send / manage / bulk-delete notifications |
| `emomigration.php` | Migration — run once, then delete |

## MODIFIED files

### `includes/` (5)

| File | What changed |
|---|---|
| `shares.php` | **Rupee/percent share mode**, `shares_breakdown()`, **seller share held until order completes**, `shares_release_order()` |
| `kyc.php` | Mandatory sections per role, progress bar, "Required" badges |
| `theme.php` | **Grouped compact sidebar** (accordion), clickable notification dropdown |
| `notify.php` | *(new)* |
| `admin_list.php` | *(new)* |

### `admin/` (25)

| File | What changed |
|---|---|
| `user_list.php` | **Credit/Debit modal with mandatory reason**, 8 report cards, sticky filters, CSV export |
| `product_management.php` | **₹ / % share toggle**, share columns show both, sticky filters, CSV export |
| `services.php` | Search, filters, **CSV export** for categories and sub-categories |
| `orders.php` | Releases the held seller share when an order is Completed |
| `notifications.php` | *(new)* |
| 21 more admin pages | Sidebar link to Notifications |

### `seller/` (1)

`orders.php` — releases the held seller share on completion.

### root (1)

`category.php` — **sub-category tabs**, product cards restyled to the navy + gold theme.

---

## Run the migration

```
https://yourdomain.com/emomigration.php
```

Then **delete it**.

### New columns on `seller_services` and `agency_services`

| Column | Type | Purpose |
|---|---|---|
| `share_mode` | `VARCHAR(10) DEFAULT 'percent'` | `percent` or `amount` |
| `seller_share_amt` | `DECIMAL(10,2)` | Seller share in rupees |
| `subscription_discount_amt` | `DECIMAL(10,2)` | Subscriber discount in rupees |
| `referral_share_amt` | `DECIMAL(10,2)` | Referral share in rupees |
| `staff_share_amt` | `DECIMAL(10,2)` | Staff share in rupees |
| `company_share_amt` | `DECIMAL(10,2)` | Company share in rupees (auto) |

### New columns on `notifications`

| Column | Type | Purpose |
|---|---|---|
| `link` | `VARCHAR(255)` | Where tapping the notification goes |
| `type` | `VARCHAR(30) DEFAULT 'general'` | Icon and colour |
| `read_at` | `DATETIME` | When it was opened |
| `created_by` | `INT` | Admin who sent it |

Plus index `idx_notif_user`.

The migration also **backfills** the rupee columns from the existing percentages and gives old notifications a sensible type and link. No table is created or dropped.

---

## What each feature does

### 1. Sidebar organised

Menus are grouped under headings — **MAIN · EXPLORE · MY ACCOUNT · MONEY · ACTIVITY · SUPPORT · MEMBERSHIP** (seller: MAIN · BUSINESS · MY ACCOUNT · MONEY · SUPPORT). Only one group opens at a time, and fonts/padding are tighter so everything fits without scrolling.

### 2. Sub-categories as tabs

In Government Portals and Agency & Software, sub-categories now sit as **horizontal pill tabs at the top** (sticky while you scroll) with products directly below. The first tab opens automatically, so you never land on an empty page. Tabs scroll sideways on mobile.

### 3. Product cards match the theme

Navy + gold: gold-to-navy top edge, glass icon tile, navy buy button with a gold hairline, tighter radius and a lift on hover. Purchased cards turn green, pending amber. Category colours now only tint the icon, so the grid looks consistent.

### 4. Credit / Debit with a reason

The old blank "Transfer Type" dropdown is gone. There is now a proper modal:

- **Credit** or **Debit** toggle
- Pick **Main** or **Virtual** wallet, current balance shown on each
- Amount with live "balance after" and an over-draw guard
- **Reason is mandatory** — five one-click presets, plus an optional note
- Save is disabled until amount and reason are both filled

The reason is stored in the wallet ledger, the user's update history, **and** sent to the user as a notification.

### 5. Share as a rupee amount

Product Management → Update has a **PERCENTAGE / FIXED AMOUNT** switch.

- **Percent mode** — as before; company share = 100% − the rest
- **Rupee mode** — type ₹ for each share; **company share = selling price − the rest**
- Each field shows its counterpart live (₹ under a %, % under a ₹)
- Saving is blocked if the shares exceed 100% or the selling price
- Switching to rupee mode carries the current percentages over as rupees
- The table shows the primary unit large and the other small, with a **₹ Fixed** or **% Percent** badge

Both modes stay in sync in the database, so every existing report keeps working.

### 6. KYC mandatory by role

| Role | Mandatory sections |
|---|---|
| Customer / member | Personal, Address, **Bank** |
| Seller | Personal, Address, Bank, **Business** |

The KYC page now shows a progress bar with the percentage, names exactly which sections are still missing, and puts a red **Required** badge on unfilled mandatory cards (green once filled).

### 7. Seller share held until the order completes

On purchase the seller share is **recorded but not paid** — it sits in `product_share_ledger` with `paid = 0` and shows in reports as pending. The moment an order is set to **Completed** (by admin or the seller) it is credited to the seller's main wallet and the seller gets a notification.

Referral and staff shares are unchanged — they credit immediately. Re-completing an order will not pay twice.

### 8. Notifications are clickable and manageable

Every notification now carries a **type** (icon + colour) and a **link**. Tapping one in the bell dropdown marks it read and jumps straight to the relevant page.

Admin → **User Management → Notifications**:

- **Send** to everyone, customers, sellers, staff, or one user — with a type and an optional custom link
- **All Notifications** — search, filter by type / read state / user, select and delete, export CSV
- **Bulk Delete** — by type and read state, or everything older than 30 days

### 9. Sticky filters, search and export

On **User list**, **Product Management** and **Service list**:

- A filter **stays applied** until you press **Reset** — navigate away, come back, it is still there
- A blue banner shows how many filters are on and exactly what they are
- **CSV export** always exports what the filter is showing (with a UTF-8 BOM, so Excel reads it correctly)
- Each list remembers its own filters independently

### 10. Report row on the user list

Eight cards above the list: **Total Users**, **Sellers**, **Joined Today** (+ this week), **KYC Pending** (+ approved), **No KYC Yet**, **Subscribed** (+ blocked), plus **Total Main Wallet** and **Total Virtual Wallet**.

New filters: KYC state, subscription, account status, joined (today / 7 / 30 days / this month) and wallet balance.

### 11. Service list export

Categories and sub-categories each get their own CSV button, plus a shared search, category filter and status filter.

---

## Post-deploy check

1. Run `emomigration.php` → all green → delete it.
2. Product Management → **Update** → switch to **FIXED AMOUNT**, type ₹320 / ₹80 / ₹40 / ₹40 on an ₹800 product → company should read **₹320**. Push the total over ₹800 → Save goes grey.
3. Buy that product as a customer → the seller's wallet should **not** change; Product Management shows the share as pending.
4. Set the order to **Completed** → the seller's wallet increases and they get a notification.
5. User list → **Credit / Debit** → try to submit without a reason → blocked. Add a reason → check it appears in Wallet History and in the user's notifications.
6. User list → set KYC filter to Pending → leave the page → come back → **still filtered**, with the blue banner. Press Reset → cleared.
7. **Export CSV** on all three lists.
8. Open a Government Portals category → sub-categories appear as tabs at the top with products below.
9. Profile → KYC as a customer → three Required badges; as a seller → four.
10. Admin → **Notifications** → send one to all sellers with type *Offer* → check the bell, tap it, confirm it opens the linked page.
