From 01c9d5fca0520559b71ea6813b9bb73ef3f93162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Thu, 19 Mar 2026 17:17:41 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20[loan]=20=EB=8C=80=EC=8B=9C=EB=B3=B4?= =?UTF-8?q?=EB=93=9C=20API=EC=97=90=20=EA=B2=BD=EC=A1=B0=EC=82=AC=EB=B9=84?= =?UTF-8?q?=20=EC=9A=94=EC=95=BD=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - condolence_expenses 테이블에서 경조사비 통계를 조회하여 dashboard 응답에 포함 - condolence_summary: total_count, total_amount, congratulation_amount, condolence_amount - 대시보드 날짜 필터(start_date, end_date)를 event_date 기준으로 적용 --- app/Services/LoanService.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/app/Services/LoanService.php b/app/Services/LoanService.php index 87cb509e..ab6bf9c0 100644 --- a/app/Services/LoanService.php +++ b/app/Services/LoanService.php @@ -2,6 +2,7 @@ namespace App\Services; +use App\Models\Tenants\CondolenceExpense; use App\Models\Tenants\ExpenseAccount; use App\Models\Tenants\Loan; use App\Models\Tenants\Withdrawal; @@ -313,7 +314,7 @@ private function syncGiftCertificateExpense(Loan $loan): void 'sub_type' => ExpenseAccount::SUB_TYPE_GIFT_CERTIFICATE, 'expense_date' => $loan->settlement_date ?? $loan->loan_date, 'amount' => $loan->amount, - 'description' => ($metadata['cert_name'] ?? '상품권') . ' 접대비 전환', + 'description' => ($metadata['cert_name'] ?? '상품권').' 접대비 전환', 'receipt_no' => $metadata['serial_number'] ?? null, 'vendor_name' => $metadata['vendor_name'] ?? null, 'vendor_id' => ! empty($metadata['vendor_id']) ? (int) $metadata['vendor_id'] : null, @@ -534,6 +535,7 @@ public function dashboard(?string $startDate = null, ?string $endDate = null): a if ($endDate) { $query->where('loan_date', '<=', $endDate); } + return $query; }; @@ -565,7 +567,25 @@ public function dashboard(?string $startDate = null, ?string $endDate = null): a // 3. 카테고리별 집계 (날짜 필터 적용) $categoryBreakdown = $this->getCategoryBreakdown($tenantId, $startDate, $endDate); - // 4. 가지급금 목록 (미정산 우선, 날짜 필터 적용, used/disposed 상품권 제외) + // 4. 경조사비 요약 (condolence_expenses 테이블, 날짜 필터 적용) + $condolenceQuery = CondolenceExpense::query()->where('tenant_id', $tenantId); + if ($startDate) { + $condolenceQuery->where('event_date', '>=', $startDate); + } + if ($endDate) { + $condolenceQuery->where('event_date', '<=', $endDate); + } + $condolenceStats = $condolenceQuery->selectRaw(' + COUNT(*) as total_count, + COALESCE(SUM(total_amount), 0) as total_amount, + COALESCE(SUM(CASE WHEN category = ? THEN total_amount ELSE 0 END), 0) as congratulation_amount, + COALESCE(SUM(CASE WHEN category = ? THEN total_amount ELSE 0 END), 0) as condolence_amount + ', [ + CondolenceExpense::CATEGORY_CONGRATULATION, + CondolenceExpense::CATEGORY_CONDOLENCE, + ])->first(); + + // 5. 가지급금 목록 (미정산 우선, 날짜 필터 적용, used/disposed 상품권 제외) $loansQuery = Loan::query() ->where('tenant_id', $tenantId) ->with(['user:id,name,email', 'withdrawal']); @@ -600,6 +620,12 @@ public function dashboard(?string $startDate = null, ?string $endDate = null): a 'outstanding_count' => (int) ($stats->outstanding_count ?? 0), ], 'category_breakdown' => $categoryBreakdown, + 'condolence_summary' => [ + 'total_count' => (int) $condolenceStats->total_count, + 'total_amount' => (int) $condolenceStats->total_amount, + 'congratulation_amount' => (int) $condolenceStats->congratulation_amount, + 'condolence_amount' => (int) $condolenceStats->condolence_amount, + ], 'loans' => $loans, ]; }