feat: [journal] 카드/은행 출처 전표 읽기 전용 적용
- update() 메서드에 source_type 가드 추가 (403 반환) - 통합 목록에서 카드/은행 분개완료 행에 잠금 아이콘 표시 - handleEditEntry에 출처 전표 방어 가드 추가 - show() 응답에 source_type 필드 추가
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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">
|
||||
분개
|
||||
</button>
|
||||
) : row.hasJournal ? (
|
||||
<button onClick={() => row.type === 'bank' ? handleJournal(row.bankTx) : row.type === 'card' ? handleCardJournal(row.cardTx) : onEdit(row.journalId)}
|
||||
) : (row.type === 'bank' || row.type === 'card') && row.hasJournal ? (
|
||||
<span className="p-1 text-stone-300" title="카드/은행 출처 전표는 원본에서 수정하세요">
|
||||
<Lock className="w-4 h-4" />
|
||||
</span>
|
||||
) : row.type === 'manual' && row.hasJournal ? (
|
||||
<button onClick={() => onEdit(row.journalId)}
|
||||
className="p-1 text-stone-300 group-hover:text-emerald-500 hover:bg-emerald-50 rounded transition-colors" title="수정">
|
||||
<Edit3 className="w-4 h-4" />
|
||||
</button>
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user