diff --git a/app/Http/Controllers/Finance/DailyFundController.php b/app/Http/Controllers/Finance/DailyFundController.php index e5da019f..4f1f3200 100644 --- a/app/Http/Controllers/Finance/DailyFundController.php +++ b/app/Http/Controllers/Finance/DailyFundController.php @@ -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(); // 오버라이드 데이터 병합 (수정된 적요/내용)