diff --git a/luckychit/lib/interfaces/manager/group_details_page.dart b/luckychit/lib/interfaces/manager/group_details_page.dart index a853da0..a91dd6e 100644 --- a/luckychit/lib/interfaces/manager/group_details_page.dart +++ b/luckychit/lib/interfaces/manager/group_details_page.dart @@ -12,6 +12,8 @@ import '../../shared/widgets/financial_table.dart'; import 'member_selection_dialog.dart'; import 'add_user_dialog.dart'; import 'combined_draw_dialog.dart'; +import 'add_past_draw_dialog.dart'; +import 'add_past_payments_dialog.dart'; import 'record_payment_dialog.dart'; import 'payment_history_page.dart'; import '../../features/chitfund_schedule/chitfund_schedule_page.dart'; @@ -114,6 +116,41 @@ class _GroupDetailsPageState extends State with SingleTickerPr ), ], ), + // Backfill menu for imported/active groups + if (widget.group.isActive) + PopupMenuButton( + icon: Icon(Icons.more_vert, size: 24.w, color: Colors.grey.shade700), + tooltip: 'More Options', + onSelected: (value) { + if (value == 'add_past_draw') { + _showAddPastDrawDialog(context); + } else if (value == 'add_past_payments') { + _showAddPastPaymentsDialog(context); + } + }, + itemBuilder: (context) => [ + 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'), + ], + ), + ), + ], + ), ], bottom: PreferredSize( preferredSize: Size.fromHeight(64.h), @@ -1651,6 +1688,90 @@ class _GroupDetailsPageState extends State with SingleTickerPr ); } + void _showAddPastDrawDialog(BuildContext context) { + // Determine which month to add based on existing draws + final existingDraws = _service.monthlyDraws; + final nextMonth = existingDraws.length + 1; + + showDialog( + context: context, + barrierDismissible: false, + builder: (context) => AddPastDrawDialog( + group: widget.group, + monthNumber: nextMonth, + ), + ).then((result) { + if (result == true) { + // Reload draws after adding + _service.loadGroupMonthlyDraws(widget.group.id); + } + }); + } + + void _showAddPastPaymentsDialog(BuildContext context) { + // Ask which month to add payments for + _showMonthSelectionDialog(context); + } + + void _showMonthSelectionDialog(BuildContext context) { + final monthController = TextEditingController(text: '1'); + + showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('Select Month'), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Text('Which month do you want to add payments for?'), + SizedBox(height: 16.h), + TextField( + controller: monthController, + keyboardType: TextInputType.number, + decoration: const InputDecoration( + labelText: 'Month Number', + hintText: 'e.g., 1, 2, 3', + border: OutlineInputBorder(), + ), + ), + ], + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text('Cancel'), + ), + ElevatedButton( + onPressed: () { + final month = int.tryParse(monthController.text); + if (month != null && month >= 1) { + Navigator.pop(context); + _showAddPastPaymentsDialogForMonth(context, month); + } + }, + child: const Text('Continue'), + ), + ], + ), + ); + } + + void _showAddPastPaymentsDialogForMonth(BuildContext context, int monthNumber) { + showDialog( + context: context, + barrierDismissible: false, + builder: (context) => AddPastPaymentsDialog( + group: widget.group, + monthNumber: monthNumber, + ), + ).then((result) { + if (result == true) { + // Reload payments after adding + _paymentService.loadGroupPayments(widget.group.id); + } + }); + } + void _conductDraw(BuildContext context) { showDialog( context: context, diff --git a/luckychit/lib/interfaces/manager/manager_dashboard.dart b/luckychit/lib/interfaces/manager/manager_dashboard.dart index 999435d..78a9304 100644 --- a/luckychit/lib/interfaces/manager/manager_dashboard.dart +++ b/luckychit/lib/interfaces/manager/manager_dashboard.dart @@ -13,6 +13,7 @@ import '../../features/settings/settings_page.dart'; import '../../features/notifications/notification_center_page.dart'; import 'chit_groups_page.dart'; import 'create_group_page.dart'; +import 'import_existing_group_dialog.dart'; import '../../test_animated_draw.dart'; import '../../features/recordings/recordings_page.dart'; @@ -450,11 +451,18 @@ class ManagerDashboard extends StatelessWidget { color: Colors.green.shade600, onTap: () => _showCreateGroupDialog(Get.context!), ), + QuickActionCard( + title: 'Import Existing Chitfund', + subtitle: 'Add a group that already started', + icon: Icons.upload, + color: Colors.blue.shade600, + onTap: () => _showImportGroupDialog(Get.context!), + ), QuickActionCard( title: 'View All Chitfunds', subtitle: 'Manage your existing groups', icon: Icons.list, - color: Colors.blue.shade600, + color: Colors.teal.shade600, onTap: () => _navigateToGroups(), ), QuickActionCard( @@ -580,6 +588,23 @@ class ManagerDashboard extends StatelessWidget { Get.to(() => const CreateGroupPage()); } + void _showImportGroupDialog(BuildContext context) { + showDialog( + context: context, + barrierDismissible: false, + builder: (context) => const ImportExistingGroupDialog(), + ).then((result) { + if (result == true) { + // Reload groups after successful import + ChitGroupService.to.loadManagerChitGroups(); + SnackbarUtil.showSuccess( + 'Group imported! Now add members and backfill past data.', + title: 'Success', + ); + } + }); + } + void _navigateToGroups() { Get.to(() => const ChitGroupsPage()); }