style: Pint 포맷팅 적용
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
use App\Models\Sales\SalesCommission;
|
||||
use App\Models\Sales\SalesCommissionDetail;
|
||||
use App\Models\Sales\SalesContractProduct;
|
||||
use App\Models\Sales\SalesPartner;
|
||||
use App\Models\Sales\SalesTenantManagement;
|
||||
use Carbon\Carbon;
|
||||
@@ -18,8 +17,11 @@ class SalesCommissionService
|
||||
* 기본 수당률
|
||||
*/
|
||||
const DEFAULT_PARTNER_RATE = 20.00;
|
||||
|
||||
const DEFAULT_GROUP_RATE = 30.00; // 단체 파트너 수당률
|
||||
|
||||
const DEFAULT_INDIVIDUAL_REFERRER_RATE = 5.00; // 개인 유치수당률
|
||||
|
||||
const DEFAULT_GROUP_REFERRER_RATE = 3.00; // 단체 유치수당률
|
||||
|
||||
// =========================================================================
|
||||
@@ -42,44 +44,44 @@ public function getCommissions(array $filters = [], int $perPage = 20): LengthAw
|
||||
]);
|
||||
|
||||
// 상태 필터
|
||||
if (!empty($filters['status'])) {
|
||||
if (! empty($filters['status'])) {
|
||||
$query->where('status', $filters['status']);
|
||||
}
|
||||
|
||||
// 입금구분 필터
|
||||
if (!empty($filters['payment_type'])) {
|
||||
if (! empty($filters['payment_type'])) {
|
||||
$query->where('payment_type', $filters['payment_type']);
|
||||
}
|
||||
|
||||
// 영업파트너 필터
|
||||
if (!empty($filters['partner_id'])) {
|
||||
if (! empty($filters['partner_id'])) {
|
||||
$query->where('partner_id', $filters['partner_id']);
|
||||
}
|
||||
|
||||
// 매니저 필터
|
||||
if (!empty($filters['manager_user_id'])) {
|
||||
if (! empty($filters['manager_user_id'])) {
|
||||
$query->where('manager_user_id', $filters['manager_user_id']);
|
||||
}
|
||||
|
||||
// 지급예정 기간 범위 필터
|
||||
if (!empty($filters['scheduled_start_year']) && !empty($filters['scheduled_start_month'])
|
||||
&& !empty($filters['scheduled_end_year']) && !empty($filters['scheduled_end_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'])) {
|
||||
elseif (! empty($filters['scheduled_year']) && ! empty($filters['scheduled_month'])) {
|
||||
$query->forScheduledMonth((int) $filters['scheduled_year'], (int) $filters['scheduled_month']);
|
||||
}
|
||||
|
||||
// 입금일 기간 필터
|
||||
if (!empty($filters['payment_start_date']) && !empty($filters['payment_end_date'])) {
|
||||
if (! empty($filters['payment_start_date']) && ! empty($filters['payment_end_date'])) {
|
||||
$query->paymentDateBetween($filters['payment_start_date'], $filters['payment_end_date']);
|
||||
}
|
||||
|
||||
// 수당유형 필터
|
||||
if (!empty($filters['commission_type'])) {
|
||||
if (! empty($filters['commission_type'])) {
|
||||
$commissionType = $filters['commission_type'];
|
||||
if ($commissionType === 'partner') {
|
||||
$query->where('partner_commission', '>', 0);
|
||||
@@ -92,7 +94,7 @@ public function getCommissions(array $filters = [], int $perPage = 20): LengthAw
|
||||
}
|
||||
|
||||
// 고객사 검색 (management → tenant 또는 tenantProspect)
|
||||
if (!empty($filters['search'])) {
|
||||
if (! empty($filters['search'])) {
|
||||
$search = $filters['search'];
|
||||
$query->whereHas('management', function ($q) use ($search) {
|
||||
$q->where(function ($sub) use ($search) {
|
||||
@@ -144,10 +146,10 @@ public function createCommission(int $managementId, string $paymentType, float $
|
||||
|
||||
// 영업파트너 resolve (fallback: tenantProspect → registeredBy → salesPartner)
|
||||
$partner = $management->salesPartner;
|
||||
if (!$partner) {
|
||||
if (! $partner) {
|
||||
$partner = $management->tenantProspect?->registeredBy?->salesPartner;
|
||||
}
|
||||
if (!$partner) {
|
||||
if (! $partner) {
|
||||
throw new \Exception('영업파트너가 지정되지 않았습니다.');
|
||||
}
|
||||
|
||||
@@ -271,7 +273,7 @@ public function approve(int $commissionId, int $approverId): SalesCommission
|
||||
$this->recalculateCommission($commission);
|
||||
}
|
||||
|
||||
if (!$commission->approve($approverId)) {
|
||||
if (! $commission->approve($approverId)) {
|
||||
throw new \Exception('승인할 수 없는 상태입니다.');
|
||||
}
|
||||
|
||||
@@ -311,7 +313,7 @@ public function markAsPaid(int $commissionId, ?string $bankReference = null): Sa
|
||||
{
|
||||
$commission = SalesCommission::findOrFail($commissionId);
|
||||
|
||||
if (!$commission->markAsPaid($bankReference)) {
|
||||
if (! $commission->markAsPaid($bankReference)) {
|
||||
throw new \Exception('지급완료 처리할 수 없는 상태입니다.');
|
||||
}
|
||||
|
||||
@@ -357,7 +359,7 @@ public function unapprove(int $commissionId): SalesCommission
|
||||
{
|
||||
$commission = SalesCommission::findOrFail($commissionId);
|
||||
|
||||
if (!$commission->unapprove()) {
|
||||
if (! $commission->unapprove()) {
|
||||
throw new \Exception('승인취소할 수 없는 상태입니다.');
|
||||
}
|
||||
|
||||
@@ -371,7 +373,7 @@ public function cancel(int $commissionId): SalesCommission
|
||||
{
|
||||
$commission = SalesCommission::findOrFail($commissionId);
|
||||
|
||||
if (!$commission->cancel()) {
|
||||
if (! $commission->cancel()) {
|
||||
throw new \Exception('취소할 수 없는 상태입니다.');
|
||||
}
|
||||
|
||||
@@ -401,7 +403,7 @@ public function getPartnerCommissionSummary(int $partnerId): array
|
||||
// 이번 달 지급예정 (승인 완료된 건)
|
||||
'scheduled_this_month' => $commissions
|
||||
->where('status', SalesCommission::STATUS_APPROVED)
|
||||
->filter(fn($c) => $c->scheduled_payment_date->format('Y-m') === $thisMonth)
|
||||
->filter(fn ($c) => $c->scheduled_payment_date->format('Y-m') === $thisMonth)
|
||||
->sum('partner_commission'),
|
||||
|
||||
// 누적 수령 수당
|
||||
@@ -416,7 +418,7 @@ public function getPartnerCommissionSummary(int $partnerId): array
|
||||
|
||||
// 이번 달 신규 계약 건수
|
||||
'contracts_this_month' => $commissions
|
||||
->filter(fn($c) => $c->payment_date >= $thisMonthStart && $c->payment_date <= $thisMonthEnd)
|
||||
->filter(fn ($c) => $c->payment_date >= $thisMonthStart && $c->payment_date <= $thisMonthEnd)
|
||||
->count(),
|
||||
|
||||
// 1차 수당 상세
|
||||
@@ -485,7 +487,7 @@ public function getManagerCommissionSummary(int $managerUserId): array
|
||||
// 이번 달 지급예정 (승인 완료된 건)
|
||||
'scheduled_this_month' => $commissions
|
||||
->where('status', SalesCommission::STATUS_APPROVED)
|
||||
->filter(fn($c) => $c->scheduled_payment_date->format('Y-m') === $thisMonth)
|
||||
->filter(fn ($c) => $c->scheduled_payment_date->format('Y-m') === $thisMonth)
|
||||
->sum('manager_commission'),
|
||||
|
||||
// 누적 수령 수당
|
||||
@@ -616,16 +618,16 @@ private function recalculateCommission(SalesCommission $commission): void
|
||||
'tenantProspect.registeredBy.salesPartner',
|
||||
])->find($commission->management_id);
|
||||
|
||||
if (!$management) {
|
||||
if (! $management) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 파트너 resolve (fallback: tenantProspect → registeredBy → salesPartner)
|
||||
$partner = $management->salesPartner;
|
||||
if (!$partner) {
|
||||
if (! $partner) {
|
||||
$partner = $management->tenantProspect?->registeredBy?->salesPartner;
|
||||
}
|
||||
if (!$partner) {
|
||||
if (! $partner) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user