diff --git a/app/Services/CalendarService.php b/app/Services/CalendarService.php index bdd87ae..9d44415 100644 --- a/app/Services/CalendarService.php +++ b/app/Services/CalendarService.php @@ -4,6 +4,7 @@ use App\Models\Construction\Contract; use App\Models\Production\WorkOrder; +use App\Models\Tenants\Bill; use App\Models\Tenants\Leave; use App\Models\Tenants\Schedule; use Illuminate\Support\Collection; @@ -16,6 +17,7 @@ * - 계약(Contract): 시공 일정 * - 휴가(Leave): 직원 휴가 일정 * - 일정(Schedule): 본사 공통 일정 + 테넌트 일정 (세금 신고, 공휴일 등) + * - 어음(Bill): 어음 만기일 일정 */ class CalendarService extends Service { @@ -24,7 +26,7 @@ class CalendarService extends Service * * @param string $startDate 조회 시작일 (Y-m-d) * @param string $endDate 조회 종료일 (Y-m-d) - * @param string|null $type 일정 타입 필터 (schedule|order|construction|other|null=전체) + * @param string|null $type 일정 타입 필터 (schedule|order|construction|other|bill|null=전체) * @param string|null $departmentFilter 부서 필터 (all|department|personal) */ public function getSchedules( @@ -64,6 +66,13 @@ public function getSchedules( ); } + // 어음 만기일 + if ($type === null || $type === 'bill') { + $schedules = $schedules->merge( + $this->getBillSchedules($tenantId, $startDate, $endDate) + ); + } + // startDate 기준 정렬 $sortedSchedules = $schedules ->sortBy('startDate') @@ -331,4 +340,46 @@ private function getGeneralSchedules( ]; }); } + + /** + * 어음 만기일 일정 조회 + */ + private function getBillSchedules( + int $tenantId, + string $startDate, + string $endDate + ): Collection { + $excludedStatuses = [ + 'paymentComplete', + 'dishonored', + ]; + + $bills = Bill::query() + ->where('tenant_id', $tenantId) + ->whereNotNull('maturity_date') + ->where('maturity_date', '>=', $startDate) + ->where('maturity_date', '<=', $endDate) + ->whereNotIn('status', $excludedStatuses) + ->orderBy('maturity_date') + ->limit(100) + ->get(); + + return $bills->map(function ($bill) { + $clientName = $bill->display_client_name ?? $bill->client_name ?? ''; + + return [ + 'id' => 'bill_'.$bill->id, + 'title' => '[만기] '.$clientName.' '.number_format($bill->amount).'원', + 'startDate' => $bill->maturity_date->format('Y-m-d'), + 'endDate' => $bill->maturity_date->format('Y-m-d'), + 'startTime' => null, + 'endTime' => null, + 'isAllDay' => true, + 'type' => 'bill', + 'department' => null, + 'personName' => null, + 'color' => null, + ]; + }); + } }