fix:전표 저장 에러 처리 개선 (Accept 헤더, 중복 전표번호 재시도)
This commit is contained in:
@@ -164,52 +164,68 @@ public function store(Request $request): JsonResponse
|
||||
], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
$entry = DB::transaction(function () use ($tenantId, $request, $lines, $totalDebit, $totalCredit) {
|
||||
$entryNo = JournalEntry::generateEntryNo($tenantId, $request->entry_date);
|
||||
$maxRetries = 3;
|
||||
$lastError = null;
|
||||
|
||||
$entry = JournalEntry::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'entry_no' => $entryNo,
|
||||
'entry_date' => $request->entry_date,
|
||||
'description' => $request->description,
|
||||
'total_debit' => $totalDebit,
|
||||
'total_credit' => $totalCredit,
|
||||
'status' => 'draft',
|
||||
'created_by_name' => auth()->user()?->name ?? '시스템',
|
||||
'attachment_note' => $request->attachment_note,
|
||||
]);
|
||||
for ($attempt = 0; $attempt < $maxRetries; $attempt++) {
|
||||
try {
|
||||
$entry = DB::transaction(function () use ($tenantId, $request, $lines, $totalDebit, $totalCredit) {
|
||||
$entryNo = JournalEntry::generateEntryNo($tenantId, $request->entry_date);
|
||||
|
||||
foreach ($lines as $i => $line) {
|
||||
JournalEntryLine::create([
|
||||
$entry = JournalEntry::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'journal_entry_id' => $entry->id,
|
||||
'line_no' => $i + 1,
|
||||
'dc_type' => $line['dc_type'],
|
||||
'account_code' => $line['account_code'],
|
||||
'account_name' => $line['account_name'],
|
||||
'trading_partner_id' => $line['trading_partner_id'] ?? null,
|
||||
'trading_partner_name' => $line['trading_partner_name'] ?? null,
|
||||
'debit_amount' => $line['debit_amount'],
|
||||
'credit_amount' => $line['credit_amount'],
|
||||
'description' => $line['description'] ?? null,
|
||||
'entry_no' => $entryNo,
|
||||
'entry_date' => $request->entry_date,
|
||||
'description' => $request->description,
|
||||
'total_debit' => $totalDebit,
|
||||
'total_credit' => $totalCredit,
|
||||
'status' => 'draft',
|
||||
'created_by_name' => auth()->user()?->name ?? '시스템',
|
||||
'attachment_note' => $request->attachment_note,
|
||||
]);
|
||||
|
||||
foreach ($lines as $i => $line) {
|
||||
JournalEntryLine::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'journal_entry_id' => $entry->id,
|
||||
'line_no' => $i + 1,
|
||||
'dc_type' => $line['dc_type'],
|
||||
'account_code' => $line['account_code'],
|
||||
'account_name' => $line['account_name'],
|
||||
'trading_partner_id' => $line['trading_partner_id'] ?? null,
|
||||
'trading_partner_name' => $line['trading_partner_name'] ?? null,
|
||||
'debit_amount' => $line['debit_amount'],
|
||||
'credit_amount' => $line['credit_amount'],
|
||||
'description' => $line['description'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
return $entry;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '전표가 저장되었습니다.',
|
||||
'data' => ['id' => $entry->id, 'entry_no' => $entry->entry_no],
|
||||
]);
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
$lastError = $e;
|
||||
if ($e->errorInfo[1] === 1062) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $entry;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '전표가 저장되었습니다.',
|
||||
'data' => ['id' => $entry->id, 'entry_no' => $entry->entry_no],
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '전표 저장 실패: ' . $e->getMessage(),
|
||||
], 500);
|
||||
break;
|
||||
} catch (\Throwable $e) {
|
||||
$lastError = $e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Log::error('전표 저장 실패', ['error' => $lastError->getMessage()]);
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '전표 저장 실패: ' . $lastError->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -544,54 +560,69 @@ public function storeFromBank(Request $request): JsonResponse
|
||||
], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
$entry = DB::transaction(function () use ($tenantId, $request, $lines, $totalDebit, $totalCredit) {
|
||||
$entryNo = JournalEntry::generateEntryNo($tenantId, $request->entry_date);
|
||||
$maxRetries = 3;
|
||||
$lastError = null;
|
||||
|
||||
$entry = JournalEntry::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'entry_no' => $entryNo,
|
||||
'entry_date' => $request->entry_date,
|
||||
'description' => $request->description,
|
||||
'total_debit' => $totalDebit,
|
||||
'total_credit' => $totalCredit,
|
||||
'status' => 'draft',
|
||||
'source_type' => 'bank_transaction',
|
||||
'source_key' => $request->source_key,
|
||||
'created_by_name' => auth()->user()?->name ?? '시스템',
|
||||
]);
|
||||
for ($attempt = 0; $attempt < $maxRetries; $attempt++) {
|
||||
try {
|
||||
$entry = DB::transaction(function () use ($tenantId, $request, $lines, $totalDebit, $totalCredit) {
|
||||
$entryNo = JournalEntry::generateEntryNo($tenantId, $request->entry_date);
|
||||
|
||||
foreach ($lines as $i => $line) {
|
||||
JournalEntryLine::create([
|
||||
$entry = JournalEntry::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'journal_entry_id' => $entry->id,
|
||||
'line_no' => $i + 1,
|
||||
'dc_type' => $line['dc_type'],
|
||||
'account_code' => $line['account_code'],
|
||||
'account_name' => $line['account_name'],
|
||||
'trading_partner_id' => $line['trading_partner_id'] ?? null,
|
||||
'trading_partner_name' => $line['trading_partner_name'] ?? null,
|
||||
'debit_amount' => $line['debit_amount'],
|
||||
'credit_amount' => $line['credit_amount'],
|
||||
'description' => $line['description'] ?? null,
|
||||
'entry_no' => $entryNo,
|
||||
'entry_date' => $request->entry_date,
|
||||
'description' => $request->description,
|
||||
'total_debit' => $totalDebit,
|
||||
'total_credit' => $totalCredit,
|
||||
'status' => 'draft',
|
||||
'source_type' => 'bank_transaction',
|
||||
'source_key' => $request->source_key,
|
||||
'created_by_name' => auth()->user()?->name ?? '시스템',
|
||||
]);
|
||||
|
||||
foreach ($lines as $i => $line) {
|
||||
JournalEntryLine::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'journal_entry_id' => $entry->id,
|
||||
'line_no' => $i + 1,
|
||||
'dc_type' => $line['dc_type'],
|
||||
'account_code' => $line['account_code'],
|
||||
'account_name' => $line['account_name'],
|
||||
'trading_partner_id' => $line['trading_partner_id'] ?? null,
|
||||
'trading_partner_name' => $line['trading_partner_name'] ?? null,
|
||||
'debit_amount' => $line['debit_amount'],
|
||||
'credit_amount' => $line['credit_amount'],
|
||||
'description' => $line['description'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
return $entry;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '분개가 저장되었습니다.',
|
||||
'data' => ['id' => $entry->id, 'entry_no' => $entry->entry_no],
|
||||
]);
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
$lastError = $e;
|
||||
if ($e->errorInfo[1] === 1062) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $entry;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '분개가 저장되었습니다.',
|
||||
'data' => ['id' => $entry->id, 'entry_no' => $entry->entry_no],
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('은행거래 분개 저장 오류: ' . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '분개 저장 실패: ' . $e->getMessage(),
|
||||
], 500);
|
||||
break;
|
||||
} catch (\Throwable $e) {
|
||||
$lastError = $e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Log::error('은행거래 분개 저장 오류: ' . $lastError->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '분개 저장 실패: ' . $lastError->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user