fix: [ecard] 분개 모달에서 수정된 카드 금액 자동 반영

- 기존 분개 로드 시 카드 금액과 불일치하면 자동으로 새 금액 기준 라인 갱신
- 불일치 경고를 자동 갱신 안내 메시지로 변경
This commit is contained in:
김보곤
2026-03-04 10:12:35 +09:00
parent 38484c464d
commit 706393ea4b

View File

@@ -796,12 +796,19 @@ className={`px-3 py-1.5 text-sm cursor-pointer ${index === highlightIndex ? 'bg-
if (!isOpen || !log) return;
setAmountMismatch(null);
const checkMismatch = (journalLines) => {
// 금액 불일치 감지 → 불일치 시 카드 데이터 기준으로 자동 갱신
const checkAndAutoSync = (journalLines, journalId) => {
const journalTotal = journalLines.reduce((sum, l) => sum + (parseInt(l.debit_amount) || 0), 0);
const expectedTotal = getExpectedCardAmount();
if (Math.abs(journalTotal - expectedTotal) > 0) {
// 카드 금액이 변경됨 → 새 카드 금액 기준으로 라인 자동 갱신
setLines(getDefaultLines());
setAmountMismatch({ journalTotal, expectedTotal, diff: expectedTotal - journalTotal });
setIsEditMode(true);
setJournalId(journalId);
return true;
}
return false;
};
if (log._journalData) {
@@ -815,10 +822,11 @@ className={`px-3 py-1.5 text-sm cursor-pointer ${index === highlightIndex ? 'bg-
trading_partner_name: l.trading_partner_name || '',
description: l.description || '',
}));
setLines(mappedLines);
setIsEditMode(true);
setJournalId(log._journalData.id);
checkMismatch(mappedLines);
if (!checkAndAutoSync(mappedLines, log._journalData.id)) {
setLines(mappedLines);
setIsEditMode(true);
setJournalId(log._journalData.id);
}
} else if (log._hasJournal) {
setLoadingJournal(true);
fetch(`${API.journalShow}?source_key=${encodeURIComponent(uniqueKey)}`)
@@ -835,10 +843,11 @@ className={`px-3 py-1.5 text-sm cursor-pointer ${index === highlightIndex ? 'bg-
trading_partner_name: l.trading_partner_name || '',
description: l.description || '',
}));
setLines(mappedLines);
setIsEditMode(true);
setJournalId(data.data.id);
checkMismatch(mappedLines);
if (!checkAndAutoSync(mappedLines, data.data.id)) {
setLines(mappedLines);
setIsEditMode(true);
setJournalId(data.data.id);
}
} else {
setLines(getDefaultLines());
setIsEditMode(false);
@@ -965,26 +974,20 @@ className={`px-3 py-1.5 text-sm cursor-pointer ${index === highlightIndex ? 'bg-
)}
</div>
{/* 카드 금액 ↔ 분개 금액 불일치 경고 */}
{/* 카드 금액 변경으로 분개 자동 갱신 안내 */}
{amountMismatch && (
<div className="bg-red-50 border border-red-200 rounded-xl p-4">
<div className="bg-amber-50 border border-amber-200 rounded-xl p-4">
<div className="flex items-start gap-3">
<svg className="w-5 h-5 text-red-500 mt-0.5 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z" />
<svg className="w-5 h-5 text-amber-500 mt-0.5 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<div className="flex-1">
<p className="text-sm font-bold text-red-700">카드 금액 분개 금액 일치하지 습니다</p>
<p className="text-sm font-bold text-amber-700">카드 금액 변경되어 분개 라인 자동 갱신되었습니다</p>
<div className="mt-2 grid grid-cols-3 gap-2 text-sm">
<div><span className="text-red-500">카드 금액: </span><span className="font-bold text-red-700">{formatCurrency(amountMismatch.expectedTotal)}</span></div>
<div><span className="text-red-500">분개 금액: </span><span className="font-bold text-red-700">{formatCurrency(amountMismatch.journalTotal)}</span></div>
<div><span className="text-red-500">차이: </span><span className="font-bold text-red-700">{formatCurrency(Math.abs(amountMismatch.diff))}</span></div>
<div><span className="text-amber-600">현재 카드 금액: </span><span className="font-bold text-amber-700">{formatCurrency(amountMismatch.expectedTotal)}</span></div>
<div><span className="text-amber-600">이전 분개 금액: </span><span className="font-bold text-amber-700">{formatCurrency(amountMismatch.journalTotal)}</span></div>
<div><span className="text-amber-600">차이: </span><span className="font-bold text-amber-700">{formatCurrency(Math.abs(amountMismatch.diff))}</span></div>
</div>
<button
onClick={handleSyncFromCard}
className="mt-3 px-4 py-1.5 bg-red-600 text-white rounded-lg text-xs font-bold hover:bg-red-700 transition-colors"
>
카드 데이터로 갱신
</button>
</div>
</div>
</div>