feat: [dashboard] 달력에 승인된 휴가/근태 표시 기능 추가
- Leave 모델에서 승인된 휴가 데이터 조회 - 달력에 [연차] 홍길동 형태로 휴가 표시 - 휴가 유형별 색상 구분 (연차/반차: amber, 병가/경조사: pink, 출장/외근: blue 등)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Boards\File;
|
||||
use App\Models\HR\Leave;
|
||||
use App\Models\System\Holiday;
|
||||
use App\Models\System\Schedule;
|
||||
use App\Services\GoogleCloudStorageService;
|
||||
@@ -40,8 +41,11 @@ public function calendar(Request $request): View
|
||||
|
||||
$holidayMap = $this->getHolidayMap($tenantId, $year, $month);
|
||||
|
||||
// 승인된 휴가/근태신청 데이터 (날짜별 그룹화)
|
||||
$leaveData = $this->getLeaveMap($tenantId, $startOfWeek->toDateString(), $endOfWeek->toDateString());
|
||||
|
||||
return view('dashboard.partials.calendar', compact(
|
||||
'year', 'month', 'calendarData', 'holidayMap'
|
||||
'year', 'month', 'calendarData', 'holidayMap', 'leaveData'
|
||||
));
|
||||
}
|
||||
|
||||
@@ -286,6 +290,37 @@ private function determineFileType(string $mimeType): string
|
||||
return 'document';
|
||||
}
|
||||
|
||||
/**
|
||||
* 승인된 휴가를 날짜별로 펼쳐서 맵 생성
|
||||
* 반환: ['Y-m-d' => [['type_label' => '연차', 'user_name' => '홍길동', ...], ...]]
|
||||
*/
|
||||
private function getLeaveMap(int $tenantId, string $startDate, string $endDate): array
|
||||
{
|
||||
$leaves = Leave::forTenant($tenantId)
|
||||
->where('status', 'approved')
|
||||
->betweenDates($startDate, $endDate)
|
||||
->with('user:id,name')
|
||||
->orderBy('start_date')
|
||||
->get();
|
||||
|
||||
$map = [];
|
||||
foreach ($leaves as $leave) {
|
||||
$start = $leave->start_date->copy();
|
||||
$end = $leave->end_date->copy();
|
||||
|
||||
for ($d = $start; $d->lte($end); $d->addDay()) {
|
||||
$key = $d->format('Y-m-d');
|
||||
$map[$key][] = [
|
||||
'type_label' => $leave->type_label,
|
||||
'leave_type' => $leave->leave_type,
|
||||
'user_name' => $leave->user?->name ?? '(미지정)',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 해당 월의 휴일 맵 생성 (날짜 => 휴일명)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user