feat: 컨트롤러에 결제 금액 표시 로직 추가
This commit is contained in:
@@ -10,6 +10,7 @@ import '../services/subscription_url_matcher.dart';
|
||||
import '../widgets/common/snackbar/app_snackbar.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../utils/billing_date_util.dart';
|
||||
import '../utils/billing_cost_util.dart';
|
||||
import 'package:permission_handler/permission_handler.dart' as permission;
|
||||
|
||||
/// AddSubscriptionScreen의 비즈니스 로직을 관리하는 Controller
|
||||
@@ -485,14 +486,22 @@ class AddSubscriptionController {
|
||||
|
||||
try {
|
||||
// 콤마 제거하고 숫자만 추출
|
||||
final monthlyCost =
|
||||
final inputCost =
|
||||
double.parse(monthlyCostController.text.replaceAll(',', ''));
|
||||
|
||||
// 이벤트 가격 파싱
|
||||
// 결제 주기에 따라 월 비용으로 변환
|
||||
final monthlyCost =
|
||||
BillingCostUtil.convertToMonthlyCost(inputCost, billingCycle);
|
||||
|
||||
// 이벤트 가격 파싱 및 월 비용 변환
|
||||
double? eventPrice;
|
||||
if (isEventActive && eventPriceController.text.isNotEmpty) {
|
||||
eventPrice =
|
||||
final inputEventPrice =
|
||||
double.tryParse(eventPriceController.text.replaceAll(',', ''));
|
||||
if (inputEventPrice != null) {
|
||||
eventPrice =
|
||||
BillingCostUtil.convertToMonthlyCost(inputEventPrice, billingCycle);
|
||||
}
|
||||
}
|
||||
|
||||
// 선택일이 오늘(또는 과거)이면 결제 주기에 맞춰 다음 회차로 보정하여 저장 + 영업일 이월
|
||||
|
||||
@@ -13,6 +13,7 @@ import '../widgets/dialogs/delete_confirmation_dialog.dart';
|
||||
import '../widgets/common/snackbar/app_snackbar.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../utils/billing_date_util.dart';
|
||||
import '../utils/billing_cost_util.dart';
|
||||
|
||||
/// DetailScreen의 비즈니스 로직을 관리하는 Controller
|
||||
class DetailScreenController extends ChangeNotifier {
|
||||
@@ -58,6 +59,8 @@ class DetailScreenController extends ChangeNotifier {
|
||||
set billingCycle(String value) {
|
||||
if (_billingCycle != value) {
|
||||
_billingCycle = value;
|
||||
// 결제 주기 변경 시 금액 표시 업데이트
|
||||
_updateMonthlyCostFormat();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -170,14 +173,18 @@ class DetailScreenController extends ChangeNotifier {
|
||||
_eventStartDate = subscription.eventStartDate;
|
||||
_eventEndDate = subscription.eventEndDate;
|
||||
|
||||
// 이벤트 가격 초기화
|
||||
// 이벤트 가격 초기화 (월 비용을 결제 주기별 실제 금액으로 변환)
|
||||
if (subscription.eventPrice != null) {
|
||||
final actualEventPrice = BillingCostUtil.convertFromMonthlyCost(
|
||||
subscription.eventPrice!,
|
||||
_billingCycle,
|
||||
);
|
||||
if (currency == 'KRW') {
|
||||
eventPriceController.text = NumberFormat.decimalPattern()
|
||||
.format(subscription.eventPrice!.toInt());
|
||||
.format(actualEventPrice.toInt());
|
||||
} else {
|
||||
eventPriceController.text =
|
||||
NumberFormat('#,##0.00').format(subscription.eventPrice!);
|
||||
NumberFormat('#,##0.00').format(actualEventPrice);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,16 +278,23 @@ class DetailScreenController extends ChangeNotifier {
|
||||
}
|
||||
|
||||
/// 통화 단위에 따른 금액 표시 형식 업데이트
|
||||
/// 월 비용을 결제 주기에 맞는 실제 금액으로 변환하여 표시
|
||||
void _updateMonthlyCostFormat() {
|
||||
// 월 비용을 결제 주기별 실제 금액으로 변환
|
||||
final actualCost = BillingCostUtil.convertFromMonthlyCost(
|
||||
subscription.monthlyCost,
|
||||
_billingCycle,
|
||||
);
|
||||
|
||||
if (_currency == 'KRW') {
|
||||
// 원화는 소수점 없이 표시
|
||||
final intValue = subscription.monthlyCost.toInt();
|
||||
final intValue = actualCost.toInt();
|
||||
monthlyCostController.text =
|
||||
NumberFormat.decimalPattern().format(intValue);
|
||||
} else {
|
||||
// 달러는 소수점 2자리까지 표시
|
||||
monthlyCostController.text =
|
||||
NumberFormat('#,##0.00').format(subscription.monthlyCost);
|
||||
NumberFormat('#,##0.00').format(actualCost);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,11 +414,14 @@ class DetailScreenController extends ChangeNotifier {
|
||||
|
||||
// 구독 정보 업데이트
|
||||
|
||||
// 콤마 제거하고 숫자만 추출
|
||||
// 콤마 제거하고 숫자만 추출 후 월 비용으로 변환
|
||||
double monthlyCost = 0.0;
|
||||
try {
|
||||
monthlyCost =
|
||||
final inputCost =
|
||||
double.parse(monthlyCostController.text.replaceAll(',', ''));
|
||||
// 결제 주기에 따라 월 비용으로 변환
|
||||
monthlyCost =
|
||||
BillingCostUtil.convertToMonthlyCost(inputCost, _billingCycle);
|
||||
} catch (e) {
|
||||
// 파싱 오류 발생 시 기본값 사용
|
||||
monthlyCost = subscription.monthlyCost;
|
||||
@@ -412,7 +429,7 @@ class DetailScreenController extends ChangeNotifier {
|
||||
|
||||
debugPrint('[DetailScreenController] 구독 업데이트 시작: '
|
||||
'${subscription.serviceName} → ${serviceNameController.text}, '
|
||||
'금액: $subscription.monthlyCost → $monthlyCost $_currency');
|
||||
'금액: ${subscription.monthlyCost} → $monthlyCost $_currency');
|
||||
|
||||
subscription.serviceName = serviceNameController.text;
|
||||
subscription.monthlyCost = monthlyCost;
|
||||
@@ -433,11 +450,13 @@ class DetailScreenController extends ChangeNotifier {
|
||||
subscription.eventStartDate = _eventStartDate;
|
||||
subscription.eventEndDate = _eventEndDate;
|
||||
|
||||
// 이벤트 가격 파싱
|
||||
// 이벤트 가격 파싱 및 월 비용 변환
|
||||
if (_isEventActive && eventPriceController.text.isNotEmpty) {
|
||||
try {
|
||||
subscription.eventPrice =
|
||||
final inputEventPrice =
|
||||
double.parse(eventPriceController.text.replaceAll(',', ''));
|
||||
subscription.eventPrice =
|
||||
BillingCostUtil.convertToMonthlyCost(inputEventPrice, _billingCycle);
|
||||
} catch (e) {
|
||||
subscription.eventPrice = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user