From fb47badb181f35e7523689617c94bfa93a69fa6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Fri, 20 Feb 2026 14:11:21 +0900 Subject: [PATCH] =?UTF-8?q?feat:=EC=A0=95=EC=82=B0=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=EA=B8=B0=EA=B0=84=EC=84=A4=EC=A0=95=20=EC=B2=B4=ED=81=AC?= =?UTF-8?q?=EB=B0=95=EC=8A=A4=20=ED=95=84=ED=84=B0=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(=EC=8B=9C=EC=9E=91~=EB=81=9D=20=EB=85=84=EC=9B=94=20=EB=B2=94?= =?UTF-8?q?=EC=9C=84=20=EC=A1=B0=ED=9A=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- .../Finance/SettlementController.php | 38 +++++++- app/Services/SalesCommissionService.php | 46 +++++++++- .../partials/commission/filters.blade.php | 92 ++++++++++++++++--- 3 files changed, 155 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/Finance/SettlementController.php b/app/Http/Controllers/Finance/SettlementController.php index 90fb14ac..c33ce375 100644 --- a/app/Http/Controllers/Finance/SettlementController.php +++ b/app/Http/Controllers/Finance/SettlementController.php @@ -35,19 +35,38 @@ public function index(Request $request): View|Response // 수당 정산 탭 데이터 (기본 탭이므로 즉시 로드) $year = $request->input('year', now()->year); $month = $request->input('month', now()->month); + $dateRange = $request->boolean('date_range'); $filters = [ - 'scheduled_year' => $year, - 'scheduled_month' => $month, 'status' => $request->input('status'), 'payment_type' => $request->input('payment_type'), 'partner_id' => $request->input('partner_id'), 'commission_type' => $request->input('commission_type'), 'search' => $request->input('search'), + 'date_range' => $dateRange, ]; + if ($dateRange) { + $filters['scheduled_start_year'] = (int) $request->input('start_year', $year); + $filters['scheduled_start_month'] = (int) $request->input('start_month', $month); + $filters['scheduled_end_year'] = (int) $request->input('end_year', $year); + $filters['scheduled_end_month'] = (int) $request->input('end_month', $month); + $filters['start_year'] = $filters['scheduled_start_year']; + $filters['start_month'] = $filters['scheduled_start_month']; + $filters['end_year'] = $filters['scheduled_end_year']; + $filters['end_month'] = $filters['scheduled_end_month']; + } else { + $filters['scheduled_year'] = $year; + $filters['scheduled_month'] = $month; + } + $commissions = $this->service->getCommissions($filters); - $stats = $this->service->getSettlementStats($year, $month); + $stats = $dateRange + ? $this->service->getSettlementStatsForRange( + $filters['scheduled_start_year'], $filters['scheduled_start_month'], + $filters['scheduled_end_year'], $filters['scheduled_end_month'] + ) + : $this->service->getSettlementStats($year, $month); $partners = SalesPartner::with('user') ->active() @@ -91,10 +110,9 @@ public function commissionTable(Request $request): View { $year = $request->input('year', now()->year); $month = $request->input('month', now()->month); + $dateRange = $request->boolean('date_range'); $filters = [ - 'scheduled_year' => $year, - 'scheduled_month' => $month, 'status' => $request->input('status'), 'payment_type' => $request->input('payment_type'), 'partner_id' => $request->input('partner_id'), @@ -102,6 +120,16 @@ public function commissionTable(Request $request): View 'search' => $request->input('search'), ]; + if ($dateRange) { + $filters['scheduled_start_year'] = (int) $request->input('start_year', $year); + $filters['scheduled_start_month'] = (int) $request->input('start_month', $month); + $filters['scheduled_end_year'] = (int) $request->input('end_year', $year); + $filters['scheduled_end_month'] = (int) $request->input('end_month', $month); + } else { + $filters['scheduled_year'] = $year; + $filters['scheduled_month'] = $month; + } + $commissions = $this->service->getCommissions($filters); return view('finance.settlement.partials.commission.table', compact('commissions')); diff --git a/app/Services/SalesCommissionService.php b/app/Services/SalesCommissionService.php index ed161dcf..464550ae 100644 --- a/app/Services/SalesCommissionService.php +++ b/app/Services/SalesCommissionService.php @@ -61,8 +61,15 @@ public function getCommissions(array $filters = [], int $perPage = 20): LengthAw $query->where('manager_user_id', $filters['manager_user_id']); } - // 지급예정 년/월 필터 - if (!empty($filters['scheduled_year']) && !empty($filters['scheduled_month'])) { + // 지급예정 기간 범위 필터 + if (!empty($filters['scheduled_start_year']) && !empty($filters['scheduled_start_month']) + && !empty($filters['scheduled_end_year']) && !empty($filters['scheduled_end_month'])) { + $startDate = \Carbon\Carbon::create($filters['scheduled_start_year'], $filters['scheduled_start_month'], 1)->startOfMonth(); + $endDate = \Carbon\Carbon::create($filters['scheduled_end_year'], $filters['scheduled_end_month'], 1)->endOfMonth(); + $query->whereBetween('scheduled_payment_date', [$startDate, $endDate]); + } + // 지급예정 년/월 필터 (단일) + elseif (!empty($filters['scheduled_year']) && !empty($filters['scheduled_month'])) { $query->forScheduledMonth((int) $filters['scheduled_year'], (int) $filters['scheduled_month']); } @@ -530,6 +537,41 @@ public function getSettlementStats(int $year, int $month): array ]; } + /** + * 정산 통계 (기간 범위) + */ + public function getSettlementStatsForRange(int $startYear, int $startMonth, int $endYear, int $endMonth): array + { + $startDate = \Carbon\Carbon::create($startYear, $startMonth, 1)->startOfMonth(); + $endDate = \Carbon\Carbon::create($endYear, $endMonth, 1)->endOfMonth(); + + $commissions = SalesCommission::whereBetween('scheduled_payment_date', [$startDate, $endDate])->get(); + + return [ + 'pending' => [ + 'count' => $commissions->where('status', SalesCommission::STATUS_PENDING)->count(), + 'partner_total' => $commissions->where('status', SalesCommission::STATUS_PENDING)->sum('partner_commission'), + 'manager_total' => $commissions->where('status', SalesCommission::STATUS_PENDING)->sum('manager_commission'), + ], + 'approved' => [ + 'count' => $commissions->where('status', SalesCommission::STATUS_APPROVED)->count(), + 'partner_total' => $commissions->where('status', SalesCommission::STATUS_APPROVED)->sum('partner_commission'), + 'manager_total' => $commissions->where('status', SalesCommission::STATUS_APPROVED)->sum('manager_commission'), + ], + 'paid' => [ + 'count' => $commissions->where('status', SalesCommission::STATUS_PAID)->count(), + 'partner_total' => $commissions->where('status', SalesCommission::STATUS_PAID)->sum('partner_commission'), + 'manager_total' => $commissions->where('status', SalesCommission::STATUS_PAID)->sum('manager_commission'), + ], + 'total' => [ + 'count' => $commissions->count(), + 'base_amount' => $commissions->sum('base_amount'), + 'partner_commission' => $commissions->sum('partner_commission'), + 'manager_commission' => $commissions->sum('manager_commission'), + ], + ]; + } + /** * 입금 대기 중인 테넌트 목록 */ diff --git a/resources/views/finance/settlement/partials/commission/filters.blade.php b/resources/views/finance/settlement/partials/commission/filters.blade.php index 2d7c306f..3903b63a 100644 --- a/resources/views/finance/settlement/partials/commission/filters.blade.php +++ b/resources/views/finance/settlement/partials/commission/filters.blade.php @@ -3,22 +3,72 @@
-
- - + {{-- 기간설정 체크박스 --}} +
+
-
- - + {{-- 단일 년/월 (기본) --}} +
+
+ + +
+
+ + +
+
+ + {{-- 기간 범위 (체크 시 표시) --}} +
+
+ + +
+
+ + +
+ ~ +
+ + +
+
+ + +
@@ -66,3 +116,17 @@ class="px-3 py-2 bg-gray-200 hover:bg-gray-300 text-gray-700 text-sm rounded-lg
+ +