fixed finacial data
This commit is contained in:
parent
233ee692bd
commit
ab66002dc5
|
|
@ -616,14 +616,22 @@ const generateFinancialData = (chitGroup) => {
|
||||||
const monthlyInstallment = chitGroup.monthly_installment;
|
const monthlyInstallment = chitGroup.monthly_installment;
|
||||||
const commission = chitGroup.foreman_commission_amount;
|
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)
|
// 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++) {
|
for (let i = 0; i < totalMonths; i++) {
|
||||||
const month = i + 1;
|
// Calculate the actual calendar month and year for this cycle month
|
||||||
const year = 2025 + Math.floor((month - 1) / 12);
|
const totalMonthsFromStart = startMonth + i;
|
||||||
const monthName = getMonthName((month - 1) % 12);
|
const currentMonth = totalMonthsFromStart % 12; // 0-11
|
||||||
const monthYear = `${monthName}-${year.toString().substring(2)}`;
|
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)
|
// Calculate dividend (difference between chit value and bid amount)
|
||||||
const dividend = chitValue - currentBidAmount;
|
const dividend = chitValue - currentBidAmount;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
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(
|
final currentMonthFinancial = financialData.firstWhereOrNull(
|
||||||
(entry) => entry.monthYear == '$currentMonth/$currentYear',
|
(entry) => entry.monthYear == displayedMonthKey,
|
||||||
);
|
);
|
||||||
|
|
||||||
// For next month
|
// For next month
|
||||||
|
final nextMonthKey = getFinancialMonthKey(nextMonth, nextYear);
|
||||||
final nextMonthFinancial = financialData.firstWhereOrNull(
|
final nextMonthFinancial = financialData.firstWhereOrNull(
|
||||||
(entry) => entry.monthYear == '$nextMonth/$nextYear',
|
(entry) => entry.monthYear == nextMonthKey,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Only show section if we have actual data (not just fallbacks)
|
// 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
|
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 currentBidAmount = currentMonthFinancial?.bidAmount ?? currentDraw?.prizeAmount;
|
||||||
final currentPrizeAmount = currentDraw?.prizeAmount;
|
final currentPrizeAmount = currentMonthFinancial?.bidAmount ?? currentDraw?.prizeAmount;
|
||||||
|
|
||||||
// For next month
|
// For next month
|
||||||
final nextBidAmount = nextMonthFinancial?.bidAmount;
|
final nextBidAmount = nextMonthFinancial?.bidAmount;
|
||||||
|
|
@ -2943,11 +2959,11 @@ class _GroupDetailsPageState extends State<GroupDetailsPage> with SingleTickerPr
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
'', // September 2025 winner from the image
|
currentDraw?.winner?.fullName ?? 'Not Conducted',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16.sp,
|
fontSize: 16.sp,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.w500,
|
||||||
color: Colors.green.shade800,
|
color: currentDraw?.winner?.fullName != null ? Colors.green.shade800 : Colors.grey.shade500,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue