toBase() ->whereNotNull('decided_at') ->whereBetween('decided_at', [$range->from, $range->to]) ->whereIn('approval_status', ApprovalStatusEnum::decidedValues()) ->selectRaw( 'DATE(decided_at) as bucket, COUNT(*) as total, SUM(CASE WHEN approval_status = ? THEN 1 ELSE 0 END) as approved', [ApprovalStatusEnum::APPROVED->value], ) ->groupBy('bucket') ->get() ->keyBy('bucket'); $values = array_map( function (string $day) use ($decisions): ?float { $decision = $decisions->get($day); if ($decision === null || (int) $decision->total === 0) { return null; } return round(((int) $decision->approved / (int) $decision->total) * 100, 1); }, $days, ); return new SeriesResult($days, [ new Series('Approval Rate', $values, zeroIsMeaningful: true), ]); } }