feat(actuals): implement full Cartesian grid with filters and pagination
Backend: - Add ActualController with Cartesian product query (all projects × members) - Add ActualsService for variance calculations (∞% when actual>0, allocated=0) - Add ActualResource for API response formatting - Add migration for notes column on actuals table - Add global config for inactive project logging (ALLOW_ACTUALS_ON_INACTIVE_PROJECTS) - Implement filters: project_ids[], team_member_ids[], include_inactive, search - Add pagination support (25 per page default) - Register /api/actuals routes Frontend: - Create MultiSelect component with portal rendering (z-index fix for sidebar) - Compact trigger mode to prevent badge overflow - SSR-safe with browser guards - Keyboard navigation and accessibility - Create Pagination component with smart ellipsis - Rebuild actuals page with: - Full Cartesian matrix (shows all projects × members, not just allocations) - Filter section with project/member multi-select - Active filters display area with badge wrapping - URL persistence for all filter state - Month navigation with arrows - Variance display (GREEN ≤5%, YELLOW 5-20%, RED >20%, ∞% for zero allocation) - Read-only cells for inactive projects - Modal for incremental hours logging with notes - Add actualsService with unwrap:false to preserve pagination meta - Add comprehensive TypeScript types for grid items and pagination OpenSpec: - Update actuals-tracking spec with clarified requirements - Mark Capability 6: Actuals Tracking as complete in tasks.md - Update test count: 157 backend tests passing Fixes: - SSR error: Add browser guards to portal rendering - Z-index: Use portal to escape stacking context (sidebar z-30) - Filter overlap: Separate badge display from dropdown triggers - Member filter: Derive visible members from API response data - Pagination meta: Disable auto-unwrap to preserve response structure
This commit is contained in:
62
backend/app/Services/ActualsService.php
Normal file
62
backend/app/Services/ActualsService.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Actual;
|
||||
use App\Models\Allocation;
|
||||
|
||||
class ActualsService
|
||||
{
|
||||
public function calculateVariance(string $projectId, string $teamMemberId, string $month): array
|
||||
{
|
||||
$monthDate = $month.'-01';
|
||||
|
||||
$allocated = (float) Allocation::where('project_id', $projectId)
|
||||
->where('team_member_id', $teamMemberId)
|
||||
->where('month', $monthDate)
|
||||
->sum('allocated_hours');
|
||||
|
||||
$actual = (float) Actual::where('project_id', $projectId)
|
||||
->where('team_member_id', $teamMemberId)
|
||||
->where('month', $monthDate)
|
||||
->sum('hours_logged');
|
||||
|
||||
if ($allocated <= 0) {
|
||||
$variancePercentage = $actual === 0 ? 0.0 : 100.0;
|
||||
} else {
|
||||
$variancePercentage = (($actual - $allocated) / $allocated) * 100;
|
||||
}
|
||||
|
||||
return [
|
||||
'allocated' => $allocated,
|
||||
'actual' => $actual,
|
||||
'variance_percentage' => $variancePercentage,
|
||||
'indicator' => $this->getIndicator($variancePercentage),
|
||||
];
|
||||
}
|
||||
|
||||
public function getInactiveProjectStatuses(): array
|
||||
{
|
||||
return ['Done', 'Cancelled'];
|
||||
}
|
||||
|
||||
public function canLogToInactiveProjects(): bool
|
||||
{
|
||||
return (bool) config('actuals.allow_actuals_on_inactive_projects', false);
|
||||
}
|
||||
|
||||
private function getIndicator(float $variancePercentage): string
|
||||
{
|
||||
$absolute = abs($variancePercentage);
|
||||
|
||||
if ($absolute <= 5) {
|
||||
return 'green';
|
||||
}
|
||||
|
||||
if ($absolute <= 20) {
|
||||
return 'yellow';
|
||||
}
|
||||
|
||||
return 'red';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user