fix:일반전표 은행거래 목록 잔액 차이로 인한 중복 표시 제거
This commit is contained in:
@@ -378,16 +378,23 @@ public function bankTransactions(Request $request): JsonResponse
|
||||
$accountNum = $request->input('accountNum', '');
|
||||
|
||||
// barobill_bank_transactions 테이블에서 직접 조회
|
||||
$query = BankTransaction::where('tenant_id', $tenantId)
|
||||
->whereBetween('trans_date', [$startDate, $endDate])
|
||||
->orderByDesc('trans_date')
|
||||
->orderByDesc('trans_time');
|
||||
// 같은 거래가 잔액(balance)만 다르게 중복 저장된 경우 최신 건만 사용
|
||||
$dedupQuery = BankTransaction::where('tenant_id', $tenantId)
|
||||
->whereBetween('trans_date', [$startDate, $endDate]);
|
||||
|
||||
if (!empty($accountNum)) {
|
||||
$query->where('bank_account_num', str_replace('-', '', $accountNum));
|
||||
$dedupQuery->where('bank_account_num', str_replace('-', '', $accountNum));
|
||||
}
|
||||
|
||||
$transactions = $query->get();
|
||||
$latestIds = $dedupQuery
|
||||
->selectRaw('MAX(id) as id')
|
||||
->groupBy('bank_account_num', 'trans_dt', 'deposit', 'withdraw')
|
||||
->pluck('id');
|
||||
|
||||
$transactions = BankTransaction::whereIn('id', $latestIds)
|
||||
->orderByDesc('trans_date')
|
||||
->orderByDesc('trans_time')
|
||||
->get();
|
||||
|
||||
// 로그 데이터 변환
|
||||
$logs = $transactions->map(function ($tx) {
|
||||
|
||||
Reference in New Issue
Block a user