Fix budget calculation error
Fixes an issue where entering a monthly budget resulted in incorrect daily, weekly, and monthly budget calculations, leading to incorrect display on the spending and analytics screens.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
import { BudgetData, BudgetPeriod, CategoryBudget, Transaction } from './types';
|
||||
import { EXPENSE_CATEGORIES } from '@/constants/categoryIcons';
|
||||
|
||||
@@ -52,7 +53,7 @@ export const calculateCategorySpending = (
|
||||
}));
|
||||
};
|
||||
|
||||
// 예산 데이터 업데이트 계산 - 수정된 함수
|
||||
// 예산 데이터 업데이트 계산 - 완전히 수정된 함수
|
||||
export const calculateUpdatedBudgetData = (
|
||||
prevBudgetData: BudgetData,
|
||||
type: BudgetPeriod,
|
||||
@@ -60,17 +61,25 @@ export const calculateUpdatedBudgetData = (
|
||||
): BudgetData => {
|
||||
console.log(`예산 업데이트 계산: 타입=${type}, 금액=${amount}`);
|
||||
|
||||
// 카테고리 예산은 항상 월간 기준이므로, monthly 계산 방식 사용
|
||||
// 월간→주간→일간 순서로 변환
|
||||
const monthlyAmount = type === 'monthly' ? amount :
|
||||
type === 'weekly' ? Math.round(amount * 4.3) :
|
||||
Math.round(amount * 30);
|
||||
// 모든 타입에 대해 월간 예산을 기준으로 계산
|
||||
let monthlyAmount = amount;
|
||||
|
||||
// 월간 금액에서 주간, 일간 계산
|
||||
const weeklyAmount = Math.round(monthlyAmount / 4.3);
|
||||
// 선택된 탭이 월간이 아닌 경우, 올바른 월간 값으로 변환
|
||||
if (type === 'daily') {
|
||||
// 일일 예산이 입력된 경우: 일일 * 30 = 월간
|
||||
monthlyAmount = amount * 30;
|
||||
console.log(`일일 예산 ${amount}원 → 월간 예산 ${monthlyAmount}원으로 변환`);
|
||||
} else if (type === 'weekly') {
|
||||
// 주간 예산이 입력된 경우: 주간 * 4.3 = 월간
|
||||
monthlyAmount = Math.round(amount * 4.3);
|
||||
console.log(`주간 예산 ${amount}원 → 월간 예산 ${monthlyAmount}원으로 변환`);
|
||||
}
|
||||
|
||||
// 월간 예산을 기준으로 일일, 주간 예산 계산
|
||||
const dailyAmount = Math.round(monthlyAmount / 30);
|
||||
const weeklyAmount = Math.round(monthlyAmount / 4.3);
|
||||
|
||||
console.log(`예산 변환: 월간=${monthlyAmount}원, 주간=${weeklyAmount}원, 일간=${dailyAmount}원`);
|
||||
console.log(`최종 예산 계산: 월간=${monthlyAmount}원, 주간=${weeklyAmount}원, 일일=${dailyAmount}원`);
|
||||
|
||||
return {
|
||||
daily: {
|
||||
|
||||
Reference in New Issue
Block a user