diff --git a/app/Http/Controllers/Api/V1/WelfareController.php b/app/Http/Controllers/Api/V1/WelfareController.php index 64795f48..055bfcdd 100644 --- a/app/Http/Controllers/Api/V1/WelfareController.php +++ b/app/Http/Controllers/Api/V1/WelfareController.php @@ -61,14 +61,18 @@ public function detail(Request $request): JsonResponse : 0.05; $year = $request->query('year') ? (int) $request->query('year') : null; $quarter = $request->query('quarter') ? (int) $request->query('quarter') : null; + $startDate = $request->query('start_date'); + $endDate = $request->query('end_date'); - return ApiResponse::handle(function () use ($calculationType, $fixedAmountPerMonth, $ratio, $year, $quarter) { + return ApiResponse::handle(function () use ($calculationType, $fixedAmountPerMonth, $ratio, $year, $quarter, $startDate, $endDate) { return $this->welfareService->getDetail( $calculationType, $fixedAmountPerMonth, $ratio, $year, - $quarter + $quarter, + $startDate, + $endDate ); }, __('message.fetched')); } diff --git a/app/Services/WelfareService.php b/app/Services/WelfareService.php index 6231f9f2..683ba0d5 100644 --- a/app/Services/WelfareService.php +++ b/app/Services/WelfareService.php @@ -498,7 +498,9 @@ public function getDetail( ?int $fixedAmountPerMonth = 200000, ?float $ratio = 0.05, ?int $year = null, - ?int $quarter = null + ?int $quarter = null, + ?string $startDate = null, + ?string $endDate = null ): array { $tenantId = $this->tenantId(); $now = Carbon::now(); @@ -562,8 +564,10 @@ public function getDetail( // 3. 항목별 분포 $categoryDistribution = $this->getCategoryDistribution($tenantId, $annualStartDate, $annualEndDate); - // 4. 일별 사용 내역 - $transactions = $this->getTransactions($tenantId, $quarterStartDate, $quarterEndDate); + // 4. 일별 사용 내역 (커스텀 날짜 범위가 있으면 해당 범위, 없으면 분기 기준) + $txStartDate = $startDate ?? $quarterStartDate; + $txEndDate = $endDate ?? $quarterEndDate; + $transactions = $this->getTransactions($tenantId, $txStartDate, $txEndDate); // 5. 계산 정보 $calculation = [