diff --git a/app/Http/Controllers/Finance/JournalEntryController.php b/app/Http/Controllers/Finance/JournalEntryController.php index fd6fea52..fc672a83 100644 --- a/app/Http/Controllers/Finance/JournalEntryController.php +++ b/app/Http/Controllers/Finance/JournalEntryController.php @@ -113,6 +113,7 @@ public function show(int $id): JsonResponse 'total_debit' => $entry->total_debit, 'total_credit' => $entry->total_credit, 'status' => $entry->status, + 'source_type' => $entry->source_type, 'created_by_name' => $entry->created_by_name, 'attachment_note' => $entry->attachment_note, 'lines' => $entry->lines->map(function ($line) { @@ -235,6 +236,17 @@ public function store(Request $request): JsonResponse */ public function update(Request $request, int $id): JsonResponse { + $tenantId = session('selected_tenant_id', 1); + $entry = JournalEntry::forTenant($tenantId)->findOrFail($id); + + // 출처 연결 전표는 수정 불가 (카드/은행/홈택스 등) + if ($entry->source_type && $entry->source_type !== 'manual') { + return response()->json([ + 'success' => false, + 'message' => '카드/은행/홈택스 출처 전표는 직접 수정할 수 없습니다. 원본 거래에서 분개를 수정해주세요.', + ], 403); + } + $request->validate([ 'entry_date' => 'required|date', 'description' => 'nullable|string|max:500', @@ -250,7 +262,6 @@ public function update(Request $request, int $id): JsonResponse 'lines.*.description' => 'nullable|string|max:300', ]); - $tenantId = session('selected_tenant_id', 1); $lines = $request->lines; $totalDebit = collect($lines)->sum('debit_amount'); @@ -263,9 +274,7 @@ public function update(Request $request, int $id): JsonResponse ], 422); } - DB::transaction(function () use ($tenantId, $id, $request, $lines, $totalDebit, $totalCredit) { - $entry = JournalEntry::forTenant($tenantId)->findOrFail($id); - + DB::transaction(function () use ($tenantId, $entry, $request, $lines, $totalDebit, $totalCredit) { $entry->update([ 'entry_date' => $request->entry_date, 'description' => $request->description, diff --git a/resources/views/finance/journal-entries.blade.php b/resources/views/finance/journal-entries.blade.php index e8aefaf3..63d9cab4 100644 --- a/resources/views/finance/journal-entries.blade.php +++ b/resources/views/finance/journal-entries.blade.php @@ -58,6 +58,7 @@ const Settings = createIcon('settings'); const Calendar = createIcon('calendar'); const CreditCard = createIcon('credit-card'); +const Lock = createIcon('lock'); const CSRF_TOKEN = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content'); @@ -1325,8 +1326,12 @@ className={`px-2.5 py-1 text-xs rounded-full font-medium transition-colors ${vie className="px-2.5 py-1 text-xs font-medium bg-amber-100 text-amber-700 rounded-full hover:bg-amber-200 transition-colors"> 분개 - ) : row.hasJournal ? ( - @@ -2604,7 +2609,18 @@ function App() { refreshJournalList(); }; - const handleEditEntry = (entryId) => { + const handleEditEntry = async (entryId) => { + // 출처 연결 전표인지 확인 (UI에서 이미 차단하지만 방어 코드) + try { + const res = await fetch(`/finance/journal-entries/${entryId}`); + const data = await res.json(); + if (data.success && data.data.source_type && data.data.source_type !== 'manual') { + notify('카드/은행/홈택스 출처 전표는 원본에서 수정해주세요.', 'warning'); + return; + } + } catch (e) { + // 조회 실패 시에도 모달 열기 허용 (서버에서 update 시 재검증) + } setEditEntryId(entryId); setShowManualModal(true); };