# Admin Features Guide

Complete guide for managers to edit, delete, and manage their chit groups.

---

## 🎯 Overview

As a manager, you have complete control over:
- Monthly draws (edit/delete)
- Chit groups (edit/delete before starting)
- Members (edit details, remove from group)
- Payments and reports

---

## 📋 Table of Contents

1. [Manage Monthly Draws](#manage-monthly-draws)
2. [Manage Chit Groups](#manage-chit-groups)
3. [Manage Members](#manage-members)
4. [Member Numbers](#member-numbers)
5. [API Reference](#api-reference)

---

## 🎲 Manage Monthly Draws

### Edit Draw (Fix Mistakes)

**When to use**: Wrong winner selected or incorrect prize amount

**How to**:
1. Go to Draws tab
2. Find the incorrect draw
3. Click ✏️ (Edit icon)
4. Select correct winner and/or update prize amount
5. Add notes explaining the correction
6. Click "Update Draw"

**API**: `PUT /api/monthly-draws/{drawId}`

**What you can edit**:
- Winner (select from member list)
- Prize amount
- Notes

**What you CANNOT edit**:
- Month/year (delete and recreate instead)
- Draw date

---

### Delete Draw (Remove Mistakes)

**When to use**: Draw was added for wrong month or by mistake

**How to**:
1. Go to Draws tab
2. Find the incorrect draw
3. Click 🗑️ (Delete icon)
4. Confirm deletion (shows draw details)
5. Draw is permanently removed

**API**: `DELETE /api/monthly-draws/{drawId}`

**Warning**: Deletion is permanent! Consider editing instead if possible.

---

## 🏢 Manage Chit Groups

### Edit Group Details

**When**: Only for groups in "Forming" status (not started yet)

**How to**:
1. Open group details page
2. Click top menu (⋮)
3. Select "Edit Group Details"
4. Update any field (name, amounts, dates, etc.)
5. Click "Update Group"

**API**: `PUT /api/chit-groups/{groupId}`

**What you can edit**:
- Group name
- Total value
- Monthly installment
- Duration (months)
- Max members
- Commission amount
- Draw date (1-31)

**Restriction**: Only works for groups in "forming" status. Once started, cannot edit!

---

### Delete Group

**When**: Only for groups in "Forming" status with 0 active members

**How to**:
1. Remove all members first (status → 'removed')
2. Click top menu (⋮)
3. Select "Delete Group"
4. Confirm deletion

**API**: `DELETE /api/chit-groups/{groupId}`

**Requirements**:
- ✅ Status must be "forming"
- ✅ Must have 0 active members (removed members are OK)

**Note**: Removed members don't block deletion!

---

## 👥 Manage Members

### Member Numbers

Every member gets a readable number:
- **Member #1, #2, #3...**
- Auto-assigned when they join
- Unique within each group
- Easy to reference verbally

**Display**:
- Purple circle badge with #X
- "Member #X" chip on card
- Large display in edit dialog

**Usage**:
- "Call Member Number 5"
- "Member #3 hasn't paid"
- Print on receipts

---

### Edit Member Details

**When**: Anytime! Works for all group statuses

**How to**:
1. Go to Members tab
2. Click menu (⋮) on member card
3. Select "Edit Member"
4. Update any field
5. Click "Update Member"

**API**: `PUT /api/auth/member/{memberId}`

**What you can edit**:
- Full name
- Mobile number (must be unique, 10 digits)
- Email address
- Physical address
- Emergency contact

**What you CANNOT edit**:
- Member number (auto-assigned)
- UUID (permanent identifier)

**Features**:
- View member number (highlighted in purple)
- View/copy UUID for technical support
- All fields optional (update only what you need)

---

### Remove Member from Group

**Important**: This removes them from THIS group only, NOT from the system!

**How to**:
1. Go to Members tab
2. Click menu (⋮) on member card
3. Select "Remove"
4. Confirm removal

**API**: `DELETE /api/members/{groupId}/members/{userId}`

**What happens**:
- ✅ Member removed from THIS group
- ✅ Their account remains active
- ✅ They can still login
- ✅ They remain in other groups
- ✅ Can be re-added to this group
- ✅ All data preserved

**Restriction**: Only works for groups in "forming" status

---

## 🔄 Common Workflows

### Fix Wrong Draw Winner
```
1. Draws tab → Find draw → Click ✏️
2. Select correct winner
3. Add note: "Corrected winner selection"
4. Update → ✅ Fixed!
```

### Update Member Phone Number
```
1. Members tab → Member menu (⋮) → Edit Member
2. Update mobile number
3. Update → ✅ They'll now get SMS/WhatsApp!
```

### Delete Empty Test Group
```
1. Remove all members (if any)
2. Top menu (⋮) → Delete Group
3. Confirm → ✅ Group deleted!
```

### Fix Group Name Before Starting
```
1. Top menu (⋮) → Edit Group Details
2. Update name
3. Update → ✅ Name fixed!
4. Start group when ready
```

---

## 🔒 Permissions & Restrictions

### What Managers CAN Do:
- ✅ Edit/delete their own group draws
- ✅ Edit group details (if forming)
- ✅ Delete groups (if forming & 0 active members)
- ✅ Edit any member's details
- ✅ Remove members from groups

### What Managers CANNOT Do:
- ❌ Edit other manager's groups
- ❌ Edit groups after they start
- ❌ Delete groups with active members
- ❌ Delete member accounts (only remove from group)
- ❌ Change member numbers or UUIDs

---

## 🎨 Visual Reference

### Member Card
```
┌────────────────────────────────────┐
│  [#5]  K Sundeep Reddy  [Member #5]│
│        9876543228                   │
│        [Active] ₹1,02,500 paid      │
│                              [⋮]    │
└────────────────────────────────────┘
```

### Draw Card
```
┌────────────────────────────────────┐
│ [🎲] March 2025 Draw                │
│      Winner: K Sundeep Reddy        │
│      [Completed] ₹1,95,000           │
│                                     │
│                      15/3/2025      │
│                      [✏️] [🗑️]      │
└────────────────────────────────────┘
```

### Top Menu (Forming Group)
```
[⋮] Menu
  ├─ ✏️ Edit Group Details
  ├─ 🗑️ Delete Group
  ├─ 👥 Select Members
  ├─ ➕ Add New User
  ├─ 🕐 Add Past Draw Result
  └─ 💰 Add Past Payments
```

---

## 📊 Status-Based Features

### "Forming" Status 🟡
**You CAN**:
- ✅ Edit group details
- ✅ Delete group (if 0 active members)
- ✅ Add/remove members
- ✅ Edit member details
- ✅ Add past draws/payments

**You CANNOT**:
- ❌ Conduct live draws (not started)

### "Active" Status 🟢
**You CAN**:
- ✅ Conduct monthly draws
- ✅ Edit/delete draws
- ✅ Edit member details
- ✅ Record payments
- ✅ View reports

**You CANNOT**:
- ❌ Edit group details (locked)
- ❌ Delete group
- ❌ Remove members

---

## ⚠️ Important Notes

### Deletions Are Permanent
- No undo button
- Always double-check before deleting
- Consider editing instead when possible

### "Remove Member" ≠ "Delete User"
- Removing member only removes them from THAT group
- Their account stays active
- They can still be in other groups
- Can be re-added later

### Group Edits Before Start Only
- Once you start a group, details are locked
- Check everything carefully before starting
- Members and draws can still be edited after start

---

## 🔍 Member ID System

### Two Types of IDs

**1. Member Number** (Human-friendly)
- Format: #1, #2, #3, #4...
- Display: Large purple badge
- Usage: Verbal communication, receipts, WhatsApp
- Example: "Member #5"

**2. UUID** (Technical)
- Format: c5530367-7110-4914-bfa6-f03818dedeb2
- Display: Hidden by default (show in edit dialog)
- Usage: Database operations, API calls
- Example: For technical support only

**Best Practice**: 
- Show users the member number (#5)
- Keep UUID for backend operations

---

## 📱 API Quick Reference

### Monthly Draws
```
POST   /api/monthly-draws              Create draw
GET    /api/monthly-draws/group/{id}   List draws
PUT    /api/monthly-draws/{id}         Edit draw ⭐
DELETE /api/monthly-draws/{id}         Delete draw ⭐
```

### Chit Groups
```
POST   /api/chit-groups                Create group
GET    /api/chit-groups/manager        List my groups
PUT    /api/chit-groups/{id}           Edit group ⭐
DELETE /api/chit-groups/{id}           Delete group ⭐
POST   /api/chit-groups/{id}/start     Start group
```

### Members
```
POST   /api/auth/create-member         Create member
GET    /api/members/{gId}/members      List members
PUT    /api/auth/member/{id}           Edit member ⭐
DELETE /api/members/{gId}/members/{uId} Remove from group ⭐
```

⭐ = New admin features

---

## 🧪 Testing Checklist

- [ ] Create test group
- [ ] Add members (see member numbers #1, #2, #3)
- [ ] Add past draw
- [ ] Edit draw (change winner)
- [ ] Delete draw
- [ ] Edit member (update phone)
- [ ] Edit group name
- [ ] Remove all members
- [ ] Delete group
- [ ] Verify large fonts work for elderly users

---

## 🆘 Support

### Common Issues
- **Can't delete group**: Check if all members are removed (not just inactive)
- **404 on member delete**: Using member.userId (not member.id)?
- **Can't edit group**: Is status "forming"?
- **Module not found**: Run `npm install` in backend

See `TROUBLESHOOTING.md` for more help.

---

## 🎉 Latest Updates (November 2025)

- ✅ Added member numbers (#1, #2, #3...)
- ✅ Complete admin edit/delete features
- ✅ Accessibility improvements for elderly users
- ✅ Fixed duplicate winner prevention
- ✅ Removed all hardcoded data
- ✅ Enhanced UI/UX

---

**Version**: 2.0  
**Status**: Production Ready ✅

