fix: [loan] dashboard summary/목록에서도 used/disposed 상품권 제외

- dashboard summary 쿼리에 excludeUsedGiftCert 조건 적용
- 가지급금 목록 쿼리에도 동일 조건 적용

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
유병철
2026-03-05 21:39:17 +09:00
parent 03f86f375e
commit 652ac3d1ec

View File

@@ -525,9 +525,18 @@ public function dashboard(?string $startDate = null, ?string $endDate = null): a
return $query;
};
// 상품권 중 used/disposed 제외 조건 (접대비로 전환됨)
$excludeUsedGiftCert = function ($query) {
$query->whereNot(function ($q) {
$q->where('category', Loan::CATEGORY_GIFT_CERTIFICATE)
->whereIn('status', [Loan::STATUS_USED, Loan::STATUS_DISPOSED]);
});
};
// 1. Summary 데이터 (날짜 필터 적용)
$summaryQuery = Loan::query()->where('tenant_id', $tenantId);
$applyDateFilter($summaryQuery);
$excludeUsedGiftCert($summaryQuery);
$stats = $summaryQuery->selectRaw('
COUNT(*) as total_count,
@@ -544,11 +553,12 @@ public function dashboard(?string $startDate = null, ?string $endDate = null): a
// 3. 카테고리별 집계 (날짜 필터 적용)
$categoryBreakdown = $this->getCategoryBreakdown($tenantId, $startDate, $endDate);
// 4. 가지급금 목록 (미정산 우선, 날짜 필터 적용)
// 4. 가지급금 목록 (미정산 우선, 날짜 필터 적용, used/disposed 상품권 제외)
$loansQuery = Loan::query()
->where('tenant_id', $tenantId)
->with(['user:id,name,email', 'withdrawal']);
$applyDateFilter($loansQuery);
$excludeUsedGiftCert($loansQuery);
$loans = $loansQuery
->orderByRaw('CASE WHEN status = ? THEN 0 WHEN status = ? THEN 1 ELSE 2 END', [