feat(capacity): Implement Capacity Planning capability (4.1-4.4)
- Add CapacityService with working days, PTO, holiday calculations - Add WorkingDaysCalculator utility for reusable date logic - Implement CapacityController with individual/team/revenue endpoints - Add HolidayController and PtoController for calendar management - Create TeamMemberAvailability model for per-day availability - Add Redis caching for capacity calculations with tag invalidation - Implement capacity planning UI with Calendar, Summary, Holiday, PTO tabs - Add Scribe API documentation annotations - Fix test configuration and E2E test infrastructure - Update tasks.md with completion status Backend Tests: 63 passed Frontend Unit: 32 passed E2E Tests: 134 passed, 20 fixme (capacity UI rendering) API Docs: Generated successfully
This commit is contained in:
49
backend/app/Utilities/WorkingDaysCalculator.php
Normal file
49
backend/app/Utilities/WorkingDaysCalculator.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utilities;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonPeriod;
|
||||
|
||||
class WorkingDaysCalculator
|
||||
{
|
||||
public static function calculate(string $month, array $holidays = []): int
|
||||
{
|
||||
$start = Carbon::createFromFormat('Y-m', $month)->startOfMonth();
|
||||
$end = $start->copy()->endOfMonth();
|
||||
|
||||
return self::getWorkingDaysInRange($start->toDateString(), $end->toDateString(), $holidays);
|
||||
}
|
||||
|
||||
public static function getWorkingDaysInRange(string $start, string $end, array $holidays = []): int
|
||||
{
|
||||
$period = CarbonPeriod::create(Carbon::create($start), Carbon::create($end));
|
||||
$holidayLookup = array_flip($holidays);
|
||||
$workingDays = 0;
|
||||
|
||||
foreach ($period as $day) {
|
||||
$date = $day->toDateString();
|
||||
|
||||
if (self::isWorkingDay($date, $holidayLookup)) {
|
||||
$workingDays++;
|
||||
}
|
||||
}
|
||||
|
||||
return $workingDays;
|
||||
}
|
||||
|
||||
public static function isWorkingDay(string $date, array $holidays = []): bool
|
||||
{
|
||||
$carbonDate = Carbon::create($date);
|
||||
|
||||
if ($carbonDate->isWeekend()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($holidays[$carbonDate->toDateString()])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user