refactor:은행거래 조회를 바로빌 API → DB 직접 조회로 변경
- bankTransactions()를 barobill_bank_transactions 테이블 직접 조회로 변경 - EaccountController 의존성 제거 - 계좌 목록을 DB distinct 조회로 제공 (별도 API 불필요) - 프론트엔드 계좌 드롭다운 필드명 수정 (camelCase → snake_case) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
namespace App\Http\Controllers\Finance;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Barobill\EaccountController;
|
||||
use App\Models\Barobill\BankTransaction;
|
||||
use App\Models\Finance\JournalEntry;
|
||||
use App\Models\Finance\JournalEntryLine;
|
||||
use App\Models\Finance\TradingPartner;
|
||||
@@ -367,23 +367,48 @@ public function tradingPartners(Request $request): JsonResponse
|
||||
// ================================================================
|
||||
|
||||
/**
|
||||
* 은행거래 목록 조회 (EaccountController 재사용 + 분개상태 병합)
|
||||
* 은행거래 목록 조회 (DB 직접 조회 + 분개상태 병합)
|
||||
*/
|
||||
public function bankTransactions(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$tenantId = session('selected_tenant_id', 1);
|
||||
$startDate = $request->input('startDate', date('Ymd'));
|
||||
$endDate = $request->input('endDate', date('Ymd'));
|
||||
$accountNum = $request->input('accountNum', '');
|
||||
|
||||
// EaccountController의 transactions 메서드 호출하여 은행거래 조회
|
||||
$eaccountController = app(EaccountController::class);
|
||||
$transResponse = $eaccountController->transactions($request);
|
||||
$transData = json_decode($transResponse->getContent(), true);
|
||||
// barobill_bank_transactions 테이블에서 직접 조회
|
||||
$query = BankTransaction::where('tenant_id', $tenantId)
|
||||
->whereBetween('trans_date', [$startDate, $endDate])
|
||||
->orderByDesc('trans_date')
|
||||
->orderByDesc('trans_time');
|
||||
|
||||
if (!($transData['success'] ?? false)) {
|
||||
return response()->json($transData);
|
||||
if (!empty($accountNum)) {
|
||||
$query->where('bank_account_num', str_replace('-', '', $accountNum));
|
||||
}
|
||||
|
||||
$logs = $transData['data']['logs'] ?? [];
|
||||
$transactions = $query->get();
|
||||
|
||||
// 로그 데이터 변환
|
||||
$logs = $transactions->map(function ($tx) {
|
||||
return [
|
||||
'uniqueKey' => $tx->unique_key,
|
||||
'transDate' => $tx->trans_date,
|
||||
'transTime' => $tx->trans_time,
|
||||
'bankAccountNum' => $tx->bank_account_num,
|
||||
'bankName' => $tx->bank_name,
|
||||
'deposit' => (int) $tx->deposit,
|
||||
'withdraw' => (int) $tx->withdraw,
|
||||
'balance' => (int) $tx->balance,
|
||||
'summary' => $tx->summary,
|
||||
'cast' => $tx->cast,
|
||||
'memo' => $tx->memo,
|
||||
'transOffice' => $tx->trans_office,
|
||||
'accountCode' => $tx->account_code,
|
||||
'accountName' => $tx->account_name,
|
||||
'isManual' => $tx->is_manual,
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
// 각 거래의 uniqueKey 수집
|
||||
$uniqueKeys = array_column($logs, 'uniqueKey');
|
||||
@@ -414,17 +439,35 @@ public function bankTransactions(Request $request): JsonResponse
|
||||
}
|
||||
unset($log);
|
||||
|
||||
// 분개 통계
|
||||
$journaledCount = count($journaledKeys);
|
||||
// 통계
|
||||
$totalCount = count($logs);
|
||||
$depositSum = array_sum(array_column($logs, 'deposit'));
|
||||
$withdrawSum = array_sum(array_column($logs, 'withdraw'));
|
||||
$journaledCount = count($journaledKeys);
|
||||
|
||||
$transData['data']['logs'] = $logs;
|
||||
$transData['data']['journalStats'] = [
|
||||
'journaledCount' => $journaledCount,
|
||||
'unjournaledCount' => $totalCount - $journaledCount,
|
||||
];
|
||||
// 계좌 목록 (드롭다운용)
|
||||
$accounts = BankTransaction::where('tenant_id', $tenantId)
|
||||
->select('bank_account_num', 'bank_name')
|
||||
->distinct()
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
return response()->json($transData);
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'logs' => $logs,
|
||||
'accounts' => $accounts,
|
||||
'summary' => [
|
||||
'totalCount' => $totalCount,
|
||||
'depositSum' => $depositSum,
|
||||
'withdrawSum' => $withdrawSum,
|
||||
],
|
||||
'journalStats' => [
|
||||
'journaledCount' => $journaledCount,
|
||||
'unjournaledCount' => $totalCount - $journaledCount,
|
||||
],
|
||||
],
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('은행거래 목록 조회 오류: ' . $e->getMessage());
|
||||
return response()->json([
|
||||
|
||||
Reference in New Issue
Block a user