6.4 KiB
📝 How to Add Past Draws and Winners
Step-by-step guide to backfill historical draw data for imported groups.
🎯 Use Case
You imported a group that started 6 months ago. Now you need to record:
- Month 1 Draw: John Doe won ₹99,000
- Month 2 Draw: Jane Smith won ₹98,500
- Month 3 Draw: Bob Johnson won ₹98,000
- ... and so on
🚀 Quick Steps
Method 1: Using the UI (Coming Soon)
Step 1: Go to Group Details Page
Step 2: Click "Actions" menu (top right)
Step 3: Select "Add Past Draw Result"
Step 4: Fill in the form:
- Month number (e.g., 1, 2, 3)
- Select winner from member list
- Enter prize amount
Step 5: Click "Add Draw"
Repeat for each past month!
Method 2: Using the API Directly (For Now)
Since the UI buttons aren't wired yet, you can use the API directly:
1. Get Your Auth Token
Login and copy your token from browser DevTools:
F12 → Application → Local Storage → auth_token
2. Add Past Draw via API
curl -X POST https://chitfund.deepteklabs.com/api/monthly-draws \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-d '{
"group_id": "YOUR_GROUP_ID",
"month": 6,
"year": 2024,
"winner_id": "MEMBER_USER_ID",
"prize_amount": 98000,
"is_past_draw": true,
"client_seed": "PAST_DRAW_JUNE_2024"
}'
3. Repeat for Each Month
Change the parameters:
month: 6, 7, 8, etc.year: 2024winner_id: Different member for each drawprize_amount: Amount they won
🔍 How to Get IDs
Get Group ID:
- Go to Group Details page
- Check URL or browser console
- Or list all groups via API:
curl https://chitfund.deepteklabs.com/api/chit-groups/manager \
-H "Authorization: Bearer YOUR_TOKEN"
Get Member IDs:
- View group members in UI
- Or list members via API:
curl https://chitfund.deepteklabs.com/api/members/YOUR_GROUP_ID/members \
-H "Authorization: Bearer YOUR_TOKEN"
📋 Example: Complete Backfill
Scenario:
- Group started: June 2024
- Current: December 2024 (Month 7)
- Need to add: 6 past draws
API Calls:
# Set your token
TOKEN="your_auth_token_here"
GROUP_ID="your_group_id_here"
# Month 1 - June 2024
curl -X POST https://chitfund.deepteklabs.com/api/monthly-draws \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"group_id": "'$GROUP_ID'",
"month": 6,
"year": 2024,
"winner_id": "john_doe_user_id",
"prize_amount": 99000,
"is_past_draw": true
}'
# Month 2 - July 2024
curl -X POST https://chitfund.deepteklabs.com/api/monthly-draws \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"group_id": "'$GROUP_ID'",
"month": 7,
"year": 2024,
"winner_id": "jane_smith_user_id",
"prize_amount": 98500,
"is_past_draw": true
}'
# Month 3 - August 2024
curl -X POST https://chitfund.deepteklabs.com/api/monthly-draws \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"group_id": "'$GROUP_ID'",
"month": 8,
"year": 2024,
"winner_id": "bob_johnson_user_id",
"prize_amount": 98000,
"is_past_draw": true
}'
# Continue for months 4, 5, 6...
🛠️ Add UI Buttons (For You to Implement)
I created the dialogs but need to add buttons to access them. Here's where:
Location: Group Details Page Actions Menu
Add these options to the PopupMenuButton in group_details_page.dart:
PopupMenuItem(
value: 'add_past_draw',
child: Row(
children: [
Icon(Icons.history, color: Colors.blue.shade600),
SizedBox(width: 12.w),
const Text('Add Past Draw Result'),
],
),
),
PopupMenuItem(
value: 'add_past_payments',
child: Row(
children: [
Icon(Icons.payment_outlined, color: Colors.green.shade600),
SizedBox(width: 12.w),
const Text('Add Past Payments'),
],
),
),
Then handle the selection:
onSelected: (value) {
if (value == 'add_past_draw') {
_showAddPastDrawDialog();
} else if (value == 'add_past_payments') {
_showAddPastPaymentsDialog();
}
}
void _showAddPastDrawDialog() {
// Need to determine which month to add
final currentMonth = _determineCurrentMonth();
showDialog(
context: context,
builder: (context) => AddPastDrawDialog(
group: widget.group,
monthNumber: currentMonth,
),
).then((result) {
if (result == true) {
_chitGroupService.loadGroupMonthlyDraws(widget.group.id);
}
});
}
void _showAddPastPaymentsDialog() {
final currentMonth = _determineCurrentMonth();
showDialog(
context: context,
builder: (context) => AddPastPaymentsDialog(
group: widget.group,
monthNumber: currentMonth,
),
).then((result) {
if (result == true) {
_paymentService.loadGroupPayments(widget.group.id);
}
});
}
📊 Recommended Workflow
Option A: Use API (Current - Works Now)
- Get group ID and member IDs
- Use curl commands above
- Add all past draws via API
- Verify in UI
Option B: Add UI Buttons (Better UX)
- Add buttons to group details page
- Import dialogs I created
- Click through UI to add draws
- More user-friendly
🎓 Quick Reference
API Endpoint:
POST /api/monthly-draws
Required Fields:
group_id- The imported group's IDmonth- Month number (1-12)year- Year (e.g., 2024)winner_id- User ID of the winnerprize_amount- Amount wonis_past_draw: true- Flag for past draws
Optional:
client_seed- Any string (e.g., "PAST_JUNE_2024")
⚠️ Important Notes
- Add members FIRST before adding draws
- Winner must be a member of the group
- Can't duplicate - only one draw per month/year
- Month/year must match group timeline
- Prize amounts should be realistic
🔗 Files You Need
The dialogs are already created:
- ✅
AddPastDrawDialog- Ready to use - ✅
AddPastPaymentsDialog- Ready to use - ⚠️ Just need to add buttons in
group_details_page.dart
💡 Quick Solution
For now, use the API method (curl commands) to add past draws.
For better UX, I can add the buttons to the group details page - just let me know!
See the API examples above to add past draws immediately! 🚀
Or say "add the UI buttons" and I'll wire them up for you.