From ab66002dc5a860bb6f3b7697ade564f5b305e358 Mon Sep 17 00:00:00 2001 From: Deep Koluguri Date: Thu, 6 Nov 2025 18:38:43 -0500 Subject: [PATCH] fixed finacial data --- .../src/controllers/chitGroupController.js | 18 ++++++++--- .../manager/group_details_page.dart | 32 ++++++++++++++----- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/backend/src/controllers/chitGroupController.js b/backend/src/controllers/chitGroupController.js index 6ebe11d..39eef01 100644 --- a/backend/src/controllers/chitGroupController.js +++ b/backend/src/controllers/chitGroupController.js @@ -616,14 +616,22 @@ const generateFinancialData = (chitGroup) => { const monthlyInstallment = chitGroup.monthly_installment; const commission = chitGroup.foreman_commission_amount; + // Use actual start_date if available, otherwise default to current date + const startDate = chitGroup.start_date ? new Date(chitGroup.start_date) : new Date(); + const startMonth = startDate.getMonth(); // 0-11 (0 = January) + const startYear = startDate.getFullYear(); + // Calculate starting bid amount (typically 85-90% of chit value) - let currentBidAmount = chitValue * 0.8765; // Starting at 87.65% + let currentBidAmount = chitGroup.total_value * 0.8765; // Starting at 87.65% for (let i = 0; i < totalMonths; i++) { - const month = i + 1; - const year = 2025 + Math.floor((month - 1) / 12); - const monthName = getMonthName((month - 1) % 12); - const monthYear = `${monthName}-${year.toString().substring(2)}`; + // Calculate the actual calendar month and year for this cycle month + const totalMonthsFromStart = startMonth + i; + const currentMonth = totalMonthsFromStart % 12; // 0-11 + const currentYear = startYear + Math.floor(totalMonthsFromStart / 12); + + const monthName = getMonthName(currentMonth); + const monthYear = `${monthName}-${currentYear.toString().substring(2)}`; // Calculate dividend (difference between chit value and bid amount) const dividend = chitValue - currentBidAmount; diff --git a/luckychit/lib/interfaces/manager/group_details_page.dart b/luckychit/lib/interfaces/manager/group_details_page.dart index 81b8fb1..a141de1 100644 --- a/luckychit/lib/interfaces/manager/group_details_page.dart +++ b/luckychit/lib/interfaces/manager/group_details_page.dart @@ -2761,15 +2761,30 @@ class _GroupDetailsPageState extends State with SingleTickerPr } } - // Get financial data for current month + // Helper function to convert month/year to financial data format (e.g., "Oct-25") + String getFinancialMonthKey(int month, int year) { + const monthAbbreviations = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + final monthAbbr = monthAbbreviations[month - 1]; + final yearShort = year.toString().substring(2); // "2025" -> "25" + return '$monthAbbr-$yearShort'; + } + + // Get financial data for displayed month (could be current or latest draw month) final financialData = _service.financialData; + + // For the displayed draw month (current or latest) + final displayedMonthKey = getFinancialMonthKey( + currentDraw?.month ?? currentMonth, + currentDraw?.year ?? currentYear + ); final currentMonthFinancial = financialData.firstWhereOrNull( - (entry) => entry.monthYear == '$currentMonth/$currentYear', + (entry) => entry.monthYear == displayedMonthKey, ); // For next month + final nextMonthKey = getFinancialMonthKey(nextMonth, nextYear); final nextMonthFinancial = financialData.firstWhereOrNull( - (entry) => entry.monthYear == '$nextMonth/$nextYear', + (entry) => entry.monthYear == nextMonthKey, ); // Only show section if we have actual data (not just fallbacks) @@ -2781,9 +2796,10 @@ class _GroupDetailsPageState extends State with SingleTickerPr return SizedBox.shrink(); // Hide section if no real data } - // Determine bid/prize amounts - use actual data or null + // Determine bid/prize amounts - ALWAYS use financial data bid_amount (the actual bid for that month) + // The draw's prize_amount might be just the monthly installment, but we want to show the actual bid final currentBidAmount = currentMonthFinancial?.bidAmount ?? currentDraw?.prizeAmount; - final currentPrizeAmount = currentDraw?.prizeAmount; + final currentPrizeAmount = currentMonthFinancial?.bidAmount ?? currentDraw?.prizeAmount; // For next month final nextBidAmount = nextMonthFinancial?.bidAmount; @@ -2943,11 +2959,11 @@ class _GroupDetailsPageState extends State with SingleTickerPr ), ), Text( - '', // September 2025 winner from the image + currentDraw?.winner?.fullName ?? 'Not Conducted', style: TextStyle( fontSize: 16.sp, - fontWeight: FontWeight.bold, - color: Colors.green.shade800, + fontWeight: FontWeight.w500, + color: currentDraw?.winner?.fullName != null ? Colors.green.shade800 : Colors.grey.shade500, ), ), ],