'decimal:2', 'cumulative_man_hours' => 'decimal:2', 'logistics_km' => 'decimal:2', ]; } public function report(): BelongsTo { return $this->belongsTo(WeeklyStatusReport::class, 'weekly_status_report_id'); } /** * Calculate cumulative man-hours from all previous approved reports + current period. */ public static function calculateCumulative(int $projectId, string $periodStart, float $currentPeriodHours, ?int $excludeReportId = null): float { $query = self::whereHas('report', fn ($q) => $q ->where('project_id', $projectId) ->where('status', 'approved') ->where('period_end', '<', $periodStart) ); if ($excludeReportId) { $query->where('weekly_status_report_id', '!=', $excludeReportId); } $previousTotal = $query->sum('period_man_hours'); return (float) $previousTotal + $currentPeriodHours; } }