Refactor category budget setting
The category budget setting is now based on the monthly budget amount, which is then divided into daily and weekly budgets.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import { BudgetData, BudgetPeriod, CategoryBudget, Transaction } from './types';
|
||||
import { EXPENSE_CATEGORIES } from '@/constants/categoryIcons';
|
||||
|
||||
@@ -53,7 +52,7 @@ export const calculateCategorySpending = (
|
||||
}));
|
||||
};
|
||||
|
||||
// 예산 데이터 업데이트 계산
|
||||
// 예산 데이터 업데이트 계산 - 수정된 함수
|
||||
export const calculateUpdatedBudgetData = (
|
||||
prevBudgetData: BudgetData,
|
||||
type: BudgetPeriod,
|
||||
@@ -61,79 +60,35 @@ export const calculateUpdatedBudgetData = (
|
||||
): BudgetData => {
|
||||
console.log(`예산 업데이트 계산: 타입=${type}, 금액=${amount}`);
|
||||
|
||||
if (type === 'monthly') {
|
||||
// 문제 수정: 일일 예산은 월간/30, 주간 예산은 월간/4.3으로 계산
|
||||
const dailyAmount = Math.round(amount / 30);
|
||||
const weeklyAmount = Math.round(amount / 4.3);
|
||||
|
||||
console.log(`월간 예산 ${amount}원으로 설정 → 일일: ${dailyAmount}원, 주간: ${weeklyAmount}원`);
|
||||
|
||||
return {
|
||||
daily: {
|
||||
targetAmount: dailyAmount,
|
||||
spentAmount: prevBudgetData.daily.spentAmount,
|
||||
remainingAmount: Math.max(0, dailyAmount - prevBudgetData.daily.spentAmount)
|
||||
},
|
||||
weekly: {
|
||||
targetAmount: weeklyAmount,
|
||||
spentAmount: prevBudgetData.weekly.spentAmount,
|
||||
remainingAmount: Math.max(0, weeklyAmount - prevBudgetData.weekly.spentAmount)
|
||||
},
|
||||
monthly: {
|
||||
targetAmount: amount,
|
||||
spentAmount: prevBudgetData.monthly.spentAmount,
|
||||
remainingAmount: Math.max(0, amount - prevBudgetData.monthly.spentAmount)
|
||||
}
|
||||
};
|
||||
} else if (type === 'weekly') {
|
||||
// 문제 수정: 월간 예산은 주간*4.3, 일일 예산은 주간/7로 계산
|
||||
const monthlyAmount = Math.round(amount * 4.3);
|
||||
const dailyAmount = Math.round(amount / 7);
|
||||
|
||||
console.log(`주간 예산 ${amount}원으로 설정 → 월간: ${monthlyAmount}원, 일일: ${dailyAmount}원`);
|
||||
|
||||
return {
|
||||
daily: {
|
||||
targetAmount: dailyAmount,
|
||||
spentAmount: prevBudgetData.daily.spentAmount,
|
||||
remainingAmount: Math.max(0, dailyAmount - prevBudgetData.daily.spentAmount)
|
||||
},
|
||||
weekly: {
|
||||
targetAmount: amount,
|
||||
spentAmount: prevBudgetData.weekly.spentAmount,
|
||||
remainingAmount: Math.max(0, amount - prevBudgetData.weekly.spentAmount)
|
||||
},
|
||||
monthly: {
|
||||
targetAmount: monthlyAmount,
|
||||
spentAmount: prevBudgetData.monthly.spentAmount,
|
||||
remainingAmount: Math.max(0, monthlyAmount - prevBudgetData.monthly.spentAmount)
|
||||
}
|
||||
};
|
||||
} else {
|
||||
// 문제 수정: 주간 예산은 일일*7, 월간 예산은 일일*30으로 계산
|
||||
const weeklyAmount = Math.round(amount * 7);
|
||||
const monthlyAmount = Math.round(amount * 30);
|
||||
|
||||
console.log(`일일 예산 ${amount}원으로 설정 → 주간: ${weeklyAmount}원, 월간: ${monthlyAmount}원`);
|
||||
|
||||
return {
|
||||
daily: {
|
||||
targetAmount: amount,
|
||||
spentAmount: prevBudgetData.daily.spentAmount,
|
||||
remainingAmount: Math.max(0, amount - prevBudgetData.daily.spentAmount)
|
||||
},
|
||||
weekly: {
|
||||
targetAmount: weeklyAmount,
|
||||
spentAmount: prevBudgetData.weekly.spentAmount,
|
||||
remainingAmount: Math.max(0, weeklyAmount - prevBudgetData.weekly.spentAmount)
|
||||
},
|
||||
monthly: {
|
||||
targetAmount: monthlyAmount,
|
||||
spentAmount: prevBudgetData.monthly.spentAmount,
|
||||
remainingAmount: Math.max(0, monthlyAmount - prevBudgetData.monthly.spentAmount)
|
||||
}
|
||||
};
|
||||
}
|
||||
// 카테고리 예산은 항상 월간 기준이므로, monthly 계산 방식 사용
|
||||
// 월간→주간→일간 순서로 변환
|
||||
const monthlyAmount = type === 'monthly' ? amount :
|
||||
type === 'weekly' ? Math.round(amount * 4.3) :
|
||||
Math.round(amount * 30);
|
||||
|
||||
// 월간 금액에서 주간, 일간 계산
|
||||
const weeklyAmount = Math.round(monthlyAmount / 4.3);
|
||||
const dailyAmount = Math.round(monthlyAmount / 30);
|
||||
|
||||
console.log(`예산 변환: 월간=${monthlyAmount}원, 주간=${weeklyAmount}원, 일간=${dailyAmount}원`);
|
||||
|
||||
return {
|
||||
daily: {
|
||||
targetAmount: dailyAmount,
|
||||
spentAmount: prevBudgetData.daily.spentAmount,
|
||||
remainingAmount: Math.max(0, dailyAmount - prevBudgetData.daily.spentAmount)
|
||||
},
|
||||
weekly: {
|
||||
targetAmount: weeklyAmount,
|
||||
spentAmount: prevBudgetData.weekly.spentAmount,
|
||||
remainingAmount: Math.max(0, weeklyAmount - prevBudgetData.weekly.spentAmount)
|
||||
},
|
||||
monthly: {
|
||||
targetAmount: monthlyAmount,
|
||||
spentAmount: prevBudgetData.monthly.spentAmount,
|
||||
remainingAmount: Math.max(0, monthlyAmount - prevBudgetData.monthly.spentAmount)
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// 지출액 계산 (일일, 주간, 월간)
|
||||
|
||||
Reference in New Issue
Block a user