fixed finacial data

This commit is contained in:
Deep Koluguri 2025-11-06 18:38:43 -05:00
parent 233ee692bd
commit ab66002dc5
2 changed files with 37 additions and 13 deletions

View File

@ -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;

View File

@ -2761,15 +2761,30 @@ class _GroupDetailsPageState extends State<GroupDetailsPage> 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<GroupDetailsPage> 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<GroupDetailsPage> 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,
),
),
],