Fix budget display issue

Correctly display monthly budget amount.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-22 11:23:57 +00:00
parent 0702145431
commit 13351fd613
2 changed files with 11 additions and 29 deletions

View File

@@ -34,8 +34,8 @@ export const useBudgetGoalUpdate = (
// 현재 최신 예산 데이터 로드 (다른 곳에서 변경되었을 수 있음) // 현재 최신 예산 데이터 로드 (다른 곳에서 변경되었을 수 있음)
const currentBudgetData = safelyLoadBudgetData(); const currentBudgetData = safelyLoadBudgetData();
// 예산 데이터 업데이트 - 일간, 주간, 월간 예산이 모두 자동으로 계산 // 예산 데이터 업데이트 - 항상 월간 예산을 기준으로 계산
const updatedBudgetData = calculateUpdatedBudgetData(currentBudgetData, type, amount); const updatedBudgetData = calculateUpdatedBudgetData(currentBudgetData, 'monthly', amount);
console.log('새 예산 데이터 계산됨:', updatedBudgetData); console.log('새 예산 데이터 계산됨:', updatedBudgetData);
// 상태 및 스토리지 둘 다 업데이트 // 상태 및 스토리지 둘 다 업데이트
@@ -67,10 +67,9 @@ export const useBudgetGoalUpdate = (
console.log('예산 목표 업데이트 완료:', updatedBudgetData); console.log('예산 목표 업데이트 완료:', updatedBudgetData);
// 성공 메시지 표시 // 성공 메시지 표시
const periodText = type === 'daily' ? '일일' : type === 'weekly' ? '주간' : '월간';
toast({ toast({
title: "예산 설정 완료", title: "예산 설정 완료",
description: `${periodText} 예산이 ${amount.toLocaleString()}원으로 설정되었습니다.`, description: `월간 예산이 ${amount.toLocaleString()}원으로 설정되었습니다.`,
}); });
} catch (error) { } catch (error) {
console.error('예산 목표 업데이트 중 오류:', error); console.error('예산 목표 업데이트 중 오류:', error);

View File

@@ -16,38 +16,21 @@ export const calculateUpdatedBudgetData = (
prevBudgetData = getInitialBudgetData(); prevBudgetData = getInitialBudgetData();
} }
// 선택된 타입에 따라 다른 타입의 예산도 자동으로 계산 // 모든 계산은 월간 예산을 기준으로 합니다
let monthlyAmount: number, weeklyAmount: number, dailyAmount: number; let monthlyAmount: number = amount;
if (type === 'monthly') { // 월 30일 기준으로 일간 예산 계산
// 월간 예산이 직접 입력된 경우 let dailyAmount = Math.round(monthlyAmount / 30);
monthlyAmount = amount;
// 월 30일 기준 // 월 4.3주 기준으로 주간 예산 계산
dailyAmount = Math.round(monthlyAmount / 30); let weeklyAmount = Math.round(monthlyAmount / 4.3);
// 월 4.3주 기준 (30일 / 7일)
weeklyAmount = Math.round(monthlyAmount / 4.3);
} else if (type === 'weekly') {
// 주간 예산이 직접 입력된 경우
weeklyAmount = amount;
// 월 4.3주 기준 (30일 / 7일)
monthlyAmount = Math.round(weeklyAmount * 4.3);
// 주 7일 기준
dailyAmount = Math.round(weeklyAmount / 7);
} else { // 'daily'
// 일일 예산이 직접 입력된 경우
dailyAmount = amount;
// 주 7일 기준
weeklyAmount = Math.round(dailyAmount * 7);
// 월 30일 기준
monthlyAmount = Math.round(dailyAmount * 30);
}
// 모든 금액이 최소한 0 이상이 되도록 보장 // 모든 금액이 최소한 0 이상이 되도록 보장
monthlyAmount = Math.max(0, monthlyAmount); monthlyAmount = Math.max(0, monthlyAmount);
weeklyAmount = Math.max(0, weeklyAmount); weeklyAmount = Math.max(0, weeklyAmount);
dailyAmount = Math.max(0, dailyAmount); dailyAmount = Math.max(0, dailyAmount);
console.log(`최종 예산 계산 결과: 월간=${monthlyAmount}원, 주간=${weeklyAmount}원, 일일=${dailyAmount}`); console.log(`최종 예산 계산 결과(월간 기준): 월간=${monthlyAmount}원, 주간=${weeklyAmount}원, 일일=${dailyAmount}`);
// 로그에 이전 예산 데이터 출력 // 로그에 이전 예산 데이터 출력
console.log("이전 예산 데이터:", JSON.stringify(prevBudgetData)); console.log("이전 예산 데이터:", JSON.stringify(prevBudgetData));