Fix budget calculation and display
Ensure daily and weekly budgets are calculated correctly based on the monthly budget, and that the monthly budget is consistent across the app.
This commit is contained in:
@@ -8,8 +8,11 @@ import { safelyLoadBudgetData } from '../budgetUtils';
|
||||
*/
|
||||
export const useBudgetState = () => {
|
||||
// 초기 데이터 로드 시 safelyLoadBudgetData 함수 사용
|
||||
const [budgetData, setBudgetData] = useState<BudgetData>(safelyLoadBudgetData());
|
||||
const [selectedTab, setSelectedTab] = useState<BudgetPeriod>("daily"); // 초기값을 daily로 변경
|
||||
const initialBudgetData = safelyLoadBudgetData();
|
||||
console.log('초기 예산 데이터 로드:', initialBudgetData);
|
||||
|
||||
const [budgetData, setBudgetData] = useState<BudgetData>(initialBudgetData);
|
||||
const [selectedTab, setSelectedTab] = useState<BudgetPeriod>("daily"); // 초기값은 daily
|
||||
const [isInitialized, setIsInitialized] = useState(false);
|
||||
const [lastUpdateTime, setLastUpdateTime] = useState(0);
|
||||
|
||||
|
||||
@@ -13,19 +13,26 @@ export const calculateSpentAmounts = (
|
||||
|
||||
// 오늘 지출 계산
|
||||
const todayExpenses = expenseTransactions.filter(t => {
|
||||
if (t.date.includes('오늘')) return true;
|
||||
if (t.date && (t.date.includes('오늘') || t.date.includes('today'))) return true;
|
||||
return false;
|
||||
});
|
||||
const dailySpent = todayExpenses.reduce((sum, t) => sum + t.amount, 0);
|
||||
|
||||
// 이번 주 지출 계산 (단순화된 버전)
|
||||
const weeklyExpenses = expenseTransactions.filter(t => {
|
||||
if (t.date.includes('오늘') || t.date.includes('어제') || t.date.includes('이번주')) return true;
|
||||
return true;
|
||||
if (t.date && (
|
||||
t.date.includes('오늘') ||
|
||||
t.date.includes('today') ||
|
||||
t.date.includes('어제') ||
|
||||
t.date.includes('yesterday') ||
|
||||
t.date.includes('이번주') ||
|
||||
t.date.includes('this week')
|
||||
)) return true;
|
||||
return false;
|
||||
});
|
||||
const weeklySpent = weeklyExpenses.reduce((sum, t) => sum + t.amount, 0);
|
||||
|
||||
// 이번 달 총 지출 계산
|
||||
// 이번 달 총 지출 계산 (모든 지출 트랜잭션)
|
||||
const monthlySpent = expenseTransactions.reduce((sum, t) => sum + t.amount, 0);
|
||||
|
||||
// 기존 예산 목표 유지 (없으면 기본값 0)
|
||||
@@ -33,6 +40,12 @@ export const calculateSpentAmounts = (
|
||||
const weeklyTarget = prevBudgetData?.weekly?.targetAmount || 0;
|
||||
const monthlyTarget = prevBudgetData?.monthly?.targetAmount || 0;
|
||||
|
||||
console.log("예산 목표 확인:", {
|
||||
일일: dailyTarget,
|
||||
주간: weeklyTarget,
|
||||
월간: monthlyTarget
|
||||
});
|
||||
|
||||
// 예산 데이터 업데이트
|
||||
const updatedBudget = {
|
||||
daily: {
|
||||
|
||||
Reference in New Issue
Block a user