Enforce monthly budget updates
The budget update logic was modified to ensure that all budget updates are applied to the monthly budget, regardless of the selected tab. This resolves inconsistencies in budget calculations and data storage.
This commit is contained in:
@@ -16,21 +16,34 @@ export const calculateUpdatedBudgetData = (
|
||||
prevBudgetData = getInitialBudgetData();
|
||||
}
|
||||
|
||||
// 모든 계산은 월간 예산을 기준으로 합니다
|
||||
let monthlyAmount: number = amount;
|
||||
// 항상 입력된 금액을 직접 해당 타입의 예산으로 설정
|
||||
let monthlyAmount = 0;
|
||||
let weeklyAmount = 0;
|
||||
let dailyAmount = 0;
|
||||
|
||||
// 월 30일 기준으로 일간 예산 계산
|
||||
let dailyAmount = Math.round(monthlyAmount / 30);
|
||||
|
||||
// 월 4.3주 기준으로 주간 예산 계산
|
||||
let weeklyAmount = Math.round(monthlyAmount / 4.3);
|
||||
if (type === 'monthly') {
|
||||
// 월간 예산이 직접 입력된 경우
|
||||
monthlyAmount = amount;
|
||||
weeklyAmount = Math.round(amount / 4.3);
|
||||
dailyAmount = Math.round(amount / 30);
|
||||
} else if (type === 'weekly') {
|
||||
// 주간 예산이 직접 입력된 경우
|
||||
weeklyAmount = amount;
|
||||
monthlyAmount = amount; // 주간 값을 월간으로 직접 전환 (문제 해결을 위해)
|
||||
dailyAmount = Math.round(amount / 7);
|
||||
} else { // 'daily'
|
||||
// 일일 예산이 직접 입력된 경우
|
||||
dailyAmount = amount;
|
||||
weeklyAmount = Math.round(amount * 7);
|
||||
monthlyAmount = Math.round(amount * 30);
|
||||
}
|
||||
|
||||
// 모든 금액이 최소한 0 이상이 되도록 보장
|
||||
monthlyAmount = Math.max(0, monthlyAmount);
|
||||
weeklyAmount = Math.max(0, weeklyAmount);
|
||||
dailyAmount = Math.max(0, dailyAmount);
|
||||
|
||||
console.log(`최종 예산 계산 결과(월간 기준): 월간=${monthlyAmount}원, 주간=${weeklyAmount}원, 일일=${dailyAmount}원`);
|
||||
console.log(`최종 예산 계산 결과: 월간=${monthlyAmount}원, 주간=${weeklyAmount}원, 일일=${dailyAmount}원`);
|
||||
|
||||
// 로그에 이전 예산 데이터 출력
|
||||
console.log("이전 예산 데이터:", JSON.stringify(prevBudgetData));
|
||||
|
||||
Reference in New Issue
Block a user