feat: add payment card grouping and analysis
This commit is contained in:
@@ -118,6 +118,7 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
required DateTime nextBillingDate,
|
||||
String? websiteUrl,
|
||||
String? categoryId,
|
||||
String? paymentCardId,
|
||||
bool isAutoDetected = false,
|
||||
int repeatCount = 1,
|
||||
DateTime? lastPaymentDate,
|
||||
@@ -136,6 +137,7 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
nextBillingDate: nextBillingDate,
|
||||
websiteUrl: websiteUrl,
|
||||
categoryId: categoryId,
|
||||
paymentCardId: paymentCardId,
|
||||
isAutoDetected: isAutoDetected,
|
||||
repeatCount: repeatCount,
|
||||
lastPaymentDate: lastPaymentDate,
|
||||
@@ -268,17 +270,22 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
/// 총 월간 지출을 계산합니다. (로케일별 기본 통화로 환산)
|
||||
Future<double> calculateTotalExpense({String? locale}) async {
|
||||
if (_subscriptions.isEmpty) return 0.0;
|
||||
Future<double> calculateTotalExpense({
|
||||
String? locale,
|
||||
List<SubscriptionModel>? subset,
|
||||
}) async {
|
||||
final targetSubscriptions = subset ?? _subscriptions;
|
||||
if (targetSubscriptions.isEmpty) return 0.0;
|
||||
|
||||
// locale이 제공되지 않으면 현재 로케일 사용
|
||||
final targetCurrency =
|
||||
locale != null ? CurrencyUtil.getDefaultCurrency(locale) : 'KRW'; // 기본값
|
||||
|
||||
debugPrint('[calculateTotalExpense] 계산 시작 - 타겟 통화: $targetCurrency');
|
||||
debugPrint('[calculateTotalExpense] 계산 시작 - 타겟 통화: $targetCurrency, '
|
||||
'대상 구독: ${targetSubscriptions.length}개');
|
||||
double total = 0.0;
|
||||
|
||||
for (final subscription in _subscriptions) {
|
||||
for (final subscription in targetSubscriptions) {
|
||||
final currentPrice = subscription.currentPrice;
|
||||
debugPrint('[calculateTotalExpense] ${subscription.serviceName}: '
|
||||
'$currentPrice ${subscription.currency} (이벤트 적용: ${subscription.isCurrentlyInEvent})');
|
||||
@@ -292,15 +299,19 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
total += converted ?? currentPrice;
|
||||
}
|
||||
|
||||
debugPrint('[calculateTotalExpense] 총 지출 계산 완료: $total $targetCurrency');
|
||||
debugPrint('[calculateTotalExpense] 총 지출 계산 완료: $total '
|
||||
'$targetCurrency (대상 ${targetSubscriptions.length}개)');
|
||||
return total;
|
||||
}
|
||||
|
||||
/// 최근 6개월의 월별 지출 데이터를 반환합니다. (로케일별 기본 통화로 환산)
|
||||
Future<List<Map<String, dynamic>>> getMonthlyExpenseData(
|
||||
{String? locale}) async {
|
||||
Future<List<Map<String, dynamic>>> getMonthlyExpenseData({
|
||||
String? locale,
|
||||
List<SubscriptionModel>? subset,
|
||||
}) async {
|
||||
final now = DateTime.now();
|
||||
final List<Map<String, dynamic>> monthlyData = [];
|
||||
final targetSubscriptions = subset ?? _subscriptions;
|
||||
|
||||
// locale이 제공되지 않으면 현재 로케일 사용
|
||||
final targetCurrency =
|
||||
@@ -321,7 +332,7 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
// 해당 월에 활성화된 구독 계산
|
||||
for (final subscription in _subscriptions) {
|
||||
for (final subscription in targetSubscriptions) {
|
||||
if (isCurrentMonth) {
|
||||
// 현재 월인 경우: 모든 활성 구독 포함 (calculateTotalExpense와 동일하게)
|
||||
final cost = subscription.currentPrice;
|
||||
|
||||
Reference in New Issue
Block a user