```php
<?php

require_once '../../core/api_bootstrap.php';
require_once '../../core/employee_auth.php';
EmployeeAuth::check('view_analytics');
try {

$db = new Database();
$conn = $db->connect();

$query="

SELECT

c.id,
c.name AS service,
COUNT(l.id) AS total_leads

FROM customer_leads l

JOIN categories c
ON l.category_id = c.id

GROUP BY l.category_id

ORDER BY total_leads DESC

";

$stmt = $conn->prepare($query);
$stmt->execute();

$data = $stmt->fetchAll();

Response::success($data);

}
catch(Exception $e){

Logger::log("system.log",$e->getMessage());

Response::error("Server error",500);

}