join('report_duties as rd', 'rd.id', '=', 'e.report_duty_id') ->where('rd.rf_department_id', $query->department->department_id) ->where('rd.status_id', 2) ->where('rd.period_start', '>=', $query->dateRange->startSql()) ->where('rd.period_end', '<=', $query->dateRange->endSql()); } public function dimensions(): array { return [ new Dimension('event_title', 'Событие', 'string', 'e.title'), new Dimension('created_date', 'Дата', 'date', 'CAST(e.created_at AS date)'), new Dimension( 'department', 'Отделение', 'string', 'rd.rf_department_id', labels: fn (array $ids) => Department::whereIn('department_id', $ids)->get() ->mapWithKeys(fn ($d) => [$d->department_id => $d->name_full ?? $d->name_short]) ->all(), ), ]; } public function measures(): array { return [ new Measure('events_count', 'Количество событий', 'count', 'COUNT(*)'), ]; } }