diff --git a/app/Services/LoanService.php b/app/Services/LoanService.php index 1fac7b5..40e290c 100644 --- a/app/Services/LoanService.php +++ b/app/Services/LoanService.php @@ -483,8 +483,10 @@ private function getCategoryBreakdown(int $tenantId, ?string $startDate = null, $query->where('loan_date', '<=', $endDate); } + // NOTE: SQL alias를 'cat_outstanding'으로 사용 — Loan 모델의 + // getOutstandingAmountAttribute() accessor와 이름 충돌 방지 $stats = $query - ->selectRaw('category, COUNT(*) as total_count, SUM(amount - COALESCE(settlement_amount, 0)) as outstanding_amount') + ->selectRaw('category, COUNT(*) as total_count, SUM(amount - COALESCE(settlement_amount, 0)) as cat_outstanding') ->selectRaw('SUM(CASE WHEN purpose IS NULL OR purpose = \'\' THEN 1 ELSE 0 END) as unverified_count') ->groupBy('category') ->get(); @@ -493,7 +495,7 @@ private function getCategoryBreakdown(int $tenantId, ?string $startDate = null, $cat = $stat->category ?? Loan::CATEGORY_CARD; if (isset($breakdown[$cat])) { $breakdown[$cat] = [ - 'outstanding_amount' => (float) $stat->outstanding_amount, + 'outstanding_amount' => (float) $stat->cat_outstanding, 'total_count' => (int) $stat->total_count, 'unverified_count' => (int) $stat->unverified_count, ];