diff --git a/luckychit/lib/interfaces/manager/group_details_page.dart b/luckychit/lib/interfaces/manager/group_details_page.dart index abc6b3d..81b8fb1 100644 --- a/luckychit/lib/interfaces/manager/group_details_page.dart +++ b/luckychit/lib/interfaces/manager/group_details_page.dart @@ -2732,10 +2732,34 @@ class _GroupDetailsPageState extends State with SingleTickerPr final nextMonthName = _getMonthName(nextMonth); final nextMonthNumber = currentMonthNumber + 1; - // Get current month draw data + // Get draw data - show LATEST AVAILABLE draw (most recent conducted draw) + // Sort draws by year and month to get the most recent one + final sortedDraws = _service.monthlyDraws.toList() + ..sort((a, b) { + if (a.year != b.year) return b.year.compareTo(a.year); + return b.month.compareTo(a.month); + }); + + // Try to find current month's draw first, otherwise show latest available final currentDraw = _service.monthlyDraws.firstWhereOrNull( (draw) => draw.month == currentMonth && draw.year == currentYear, - ); + ) ?? (sortedDraws.isNotEmpty ? sortedDraws.first : null); + + // If we're showing latest draw (not current month), update display names + String displayCurrentMonth = currentMonthName; + int displayCurrentYear = currentYear; + int displayCurrentMonthNum = currentMonthNumber; + + if (currentDraw != null && (currentDraw.month != currentMonth || currentDraw.year != currentYear)) { + // We're showing a past draw as "latest" + displayCurrentMonth = _getMonthName(currentDraw.month); + displayCurrentYear = currentDraw.year; + // Calculate what cycle month this was + if (startDate != null) { + final monthsSinceStart = (currentDraw.year - startDate.year) * 12 + (currentDraw.month - startDate.month); + displayCurrentMonthNum = monthsSinceStart + 1; + } + } // Get financial data for current month final financialData = _service.financialData; @@ -2794,12 +2818,30 @@ class _GroupDetailsPageState extends State with SingleTickerPr children: [ Icon(Icons.calendar_today, color: Colors.green.shade600, size: 20.w), SizedBox(width: 8.w), - Text( - 'Current Month', - style: TextStyle( - fontSize: 16.sp, - fontWeight: FontWeight.w600, - color: Colors.green.shade800, + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + currentDraw != null && (currentDraw.month != currentMonth || currentDraw.year != currentYear) + ? 'Latest Draw' + : 'Current Month', + style: TextStyle( + fontSize: 16.sp, + fontWeight: FontWeight.w600, + color: Colors.green.shade800, + ), + ), + if (currentDraw != null && (currentDraw.month != currentMonth || currentDraw.year != currentYear)) + Text( + 'No draw for current month yet', + style: TextStyle( + fontSize: 12.sp, + color: Colors.orange.shade700, + fontStyle: FontStyle.italic, + ), + ), + ], ), ), ], @@ -2812,7 +2854,7 @@ class _GroupDetailsPageState extends State with SingleTickerPr crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - '$currentMonthName $currentYear', + '$displayCurrentMonth $displayCurrentYear', style: TextStyle( fontSize: 18.sp, fontWeight: FontWeight.bold, @@ -2820,7 +2862,7 @@ class _GroupDetailsPageState extends State with SingleTickerPr ), ), Text( - 'Month $currentMonthNumber of ${group.durationMonths}', + 'Month $displayCurrentMonthNum of ${group.durationMonths}', style: TextStyle( fontSize: 14.sp, color: Colors.green.shade600, @@ -2901,7 +2943,7 @@ class _GroupDetailsPageState extends State with SingleTickerPr ), ), Text( - 'K Thirupathi Reddy', // September 2025 winner from the image + '', // September 2025 winner from the image style: TextStyle( fontSize: 16.sp, fontWeight: FontWeight.bold,