Show unset daily/weekly budget
The daily and weekly budget values now display "설정되지 않음" when they are not set.
This commit is contained in:
@@ -57,7 +57,7 @@ export const calculateCategorySpending = (
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
// 예산 데이터 업데이트 계산 - 완전히 수정된 함수
|
// 예산 데이터 업데이트 계산 - 수정된 함수
|
||||||
export const calculateUpdatedBudgetData = (
|
export const calculateUpdatedBudgetData = (
|
||||||
prevBudgetData: BudgetData,
|
prevBudgetData: BudgetData,
|
||||||
type: BudgetPeriod,
|
type: BudgetPeriod,
|
||||||
@@ -65,24 +65,26 @@ export const calculateUpdatedBudgetData = (
|
|||||||
): BudgetData => {
|
): BudgetData => {
|
||||||
console.log(`예산 업데이트 계산: 타입=${type}, 금액=${amount}`);
|
console.log(`예산 업데이트 계산: 타입=${type}, 금액=${amount}`);
|
||||||
|
|
||||||
// 모든 타입에 대해 월간 예산을 기준으로 계산
|
// 선택된 타입에 따라 다른 타입의 예산도 자동으로 계산
|
||||||
let monthlyAmount = amount;
|
let monthlyAmount, weeklyAmount, dailyAmount;
|
||||||
|
|
||||||
// 선택된 탭이 월간이 아닌 경우, 올바른 월간 값으로 변환
|
if (type === 'monthly') {
|
||||||
if (type === 'daily') {
|
// 월간 예산이 직접 입력된 경우
|
||||||
// 일일 예산이 입력된 경우: 일일 * 30 = 월간
|
monthlyAmount = amount;
|
||||||
monthlyAmount = amount * 30;
|
dailyAmount = Math.round(monthlyAmount / 30);
|
||||||
console.log(`일일 예산 ${amount}원 → 월간 예산 ${monthlyAmount}원으로 변환`);
|
weeklyAmount = Math.round(monthlyAmount / 4.3);
|
||||||
} else if (type === 'weekly') {
|
} else if (type === 'weekly') {
|
||||||
// 주간 예산이 입력된 경우: 주간 * 4.3 = 월간
|
// 주간 예산이 직접 입력된 경우
|
||||||
monthlyAmount = Math.round(amount * 4.3);
|
weeklyAmount = amount;
|
||||||
console.log(`주간 예산 ${amount}원 → 월간 예산 ${monthlyAmount}원으로 변환`);
|
monthlyAmount = Math.round(weeklyAmount * 4.3);
|
||||||
|
dailyAmount = Math.round(weeklyAmount / 7);
|
||||||
|
} else { // 'daily'
|
||||||
|
// 일일 예산이 직접 입력된 경우
|
||||||
|
dailyAmount = amount;
|
||||||
|
weeklyAmount = dailyAmount * 7;
|
||||||
|
monthlyAmount = dailyAmount * 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 월간 예산을 기준으로 일일, 주간 예산 계산
|
|
||||||
const dailyAmount = Math.round(monthlyAmount / 30);
|
|
||||||
const weeklyAmount = Math.round(monthlyAmount / 4.3);
|
|
||||||
|
|
||||||
console.log(`최종 예산 계산: 월간=${monthlyAmount}원, 주간=${weeklyAmount}원, 일일=${dailyAmount}원`);
|
console.log(`최종 예산 계산: 월간=${monthlyAmount}원, 주간=${weeklyAmount}원, 일일=${dailyAmount}원`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import { useState, useEffect, useCallback } from 'react';
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
import { BudgetData, BudgetPeriod } from '../types';
|
import { BudgetData, BudgetPeriod } from '../types';
|
||||||
import {
|
import {
|
||||||
@@ -92,7 +91,7 @@ export const useBudgetDataState = (transactions: Transaction[]) => {
|
|||||||
}
|
}
|
||||||
}, [transactions, budgetData, isInitialized]);
|
}, [transactions, budgetData, isInitialized]);
|
||||||
|
|
||||||
// 예산 목표 업데이트 함수
|
// 예산 목표 업데이트 함수 - 수정됨
|
||||||
const handleBudgetGoalUpdate = useCallback((
|
const handleBudgetGoalUpdate = useCallback((
|
||||||
type: BudgetPeriod,
|
type: BudgetPeriod,
|
||||||
amount: number,
|
amount: number,
|
||||||
@@ -112,7 +111,7 @@ export const useBudgetDataState = (transactions: Transaction[]) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 예산 업데이트 (카테고리 예산이 있든 없든 무조건 실행)
|
// 예산 데이터 업데이트 - 일간, 주간, 월간 예산이 모두 자동으로 계산됨
|
||||||
const updatedBudgetData = calculateUpdatedBudgetData(budgetData, type, amount);
|
const updatedBudgetData = calculateUpdatedBudgetData(budgetData, type, amount);
|
||||||
console.log('새 예산 데이터:', updatedBudgetData);
|
console.log('새 예산 데이터:', updatedBudgetData);
|
||||||
|
|
||||||
@@ -122,6 +121,12 @@ export const useBudgetDataState = (transactions: Transaction[]) => {
|
|||||||
|
|
||||||
// 저장 시간 업데이트
|
// 저장 시간 업데이트
|
||||||
localStorage.setItem('lastBudgetSaveTime', new Date().toISOString());
|
localStorage.setItem('lastBudgetSaveTime', new Date().toISOString());
|
||||||
|
|
||||||
|
// 성공 메시지 표시
|
||||||
|
toast({
|
||||||
|
title: "예산 설정 완료",
|
||||||
|
description: `${type === 'daily' ? '일일' : type === 'weekly' ? '주간' : '월간'} 예산이 ${amount.toLocaleString()}원으로 설정되었습니다.`,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('예산 목표 업데이트 중 오류:', error);
|
console.error('예산 목표 업데이트 중 오류:', error);
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
@@ -27,10 +27,12 @@ export const useExtendedBudgetUpdate = (
|
|||||||
const totalAmount = Object.values(newCategoryBudgets).reduce((sum, val) => sum + val, 0);
|
const totalAmount = Object.values(newCategoryBudgets).reduce((sum, val) => sum + val, 0);
|
||||||
console.log('카테고리 총액:', totalAmount);
|
console.log('카테고리 총액:', totalAmount);
|
||||||
|
|
||||||
// 월간 예산 금액으로 예산 데이터 업데이트 (type에 관계없이 월간으로 처리)
|
// 월간 예산 금액으로 예산 데이터 업데이트
|
||||||
|
// 월간 예산을 설정하면 자동으로 일간/주간 예산도 계산되도록 수정
|
||||||
handleBudgetGoalUpdate('monthly', totalAmount);
|
handleBudgetGoalUpdate('monthly', totalAmount);
|
||||||
} else {
|
} else {
|
||||||
// 카테고리 예산이 없는 경우, 선택된 기간 유형에 따라 예산 설정
|
// 카테고리 예산이 없는 경우, 선택된 기간 유형에 맞게 예산 설정
|
||||||
|
// 이 경우에도 다른 기간의 예산이 자동으로 계산됨
|
||||||
handleBudgetGoalUpdate(type, amount);
|
handleBudgetGoalUpdate(type, amount);
|
||||||
}
|
}
|
||||||
}, [categoryBudgets, handleBudgetGoalUpdate, updateCategoryBudgets]);
|
}, [categoryBudgets, handleBudgetGoalUpdate, updateCategoryBudgets]);
|
||||||
|
|||||||
Reference in New Issue
Block a user