fix:일일자금일보 중복 제거 시 최신 레코드(정확한 잔액) 유지

- orderBy id DESC로 먼저 정렬하여 unique() 시 최신 ID 유지
- 중복 제거 후 날짜+시간 기준으로 재정렬

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
김보곤
2026-02-06 18:01:44 +09:00
parent eaa3490c9a
commit a30489f1a8

View File

@@ -174,13 +174,14 @@ public function periodReport(Request $request): JsonResponse
$startDateYmd = str_replace('-', '', $startDate);
$endDateYmd = str_replace('-', '', $endDate);
// 기간 내 거래내역 조회 (중복 제거: 동일 trans_dt + 금액 조합이면 최신 id만 사용)
// 기간 내 거래내역 조회 (중복 제거: 동일 trans_dt + 금액 조합이면 최신 id(정확한 잔액)만 사용)
$transactions = BarobillBankTransaction::where('tenant_id', $tenantId)
->whereBetween('trans_date', [$startDateYmd, $endDateYmd])
->orderBy('trans_date', 'desc')
->orderBy('trans_time', 'desc')
->orderBy('id', 'desc') // 최신 ID 우선 (올바른 잔액)
->get()
->unique(fn($tx) => $tx->bank_account_num . '|' . $tx->trans_dt . '|' . (int)$tx->deposit . '|' . (int)$tx->withdraw)
->sortByDesc('trans_date')
->sortByDesc(fn($tx) => $tx->trans_date . $tx->trans_time)
->values();
// 오버라이드 데이터 병합 (수정된 적요/내용)