PHP Code:
<?php
namespace Espo\Custom\Reports;
use \Espo\ORM\Entity;
use \Espo\Core\Exceptions\Error;
use \Espo\Core\Exceptions\NotFound;
class BirthdaysUsers extends \Espo\Modules\Advanced\Reports\Base
{
public function run($where = null, array $params = null)
{
$sql = "
SELECT
id,
DATE_ADD(
date_of_birth,
INTERVAL TIMESTAMPDIFF(YEAR, DATE_ADD(date_of_birth,INTERVAL 1 DAY), curdate())+1 YEAR
) upcoming_birthday
FROM
user
HAVING
upcoming_birthday BETWEEN curdate() AND DATE_ADD(curdate(), INTERVAL 14 DAY)";
$pdo = $this->getEntityManager()->getPDO();
$sth = $pdo->prepare($sql);
$sth->execute();
$rows = $sth->fetchAll();
$ids = [];
foreach ($rows as $row) {
$ids[] = $row['id'];
}
$collection = $this->getEntityManager()->getRepository('User')
->where([
'id' => $ids,
'isActive' => True,
])
->order('name','ASC')
->find(['name','dateOfBirth']);
return array(
'collection' => $collection,
'total' => count($collection)
);
}
}The only issue I've found is with dashlets. The report works just fine, but dashlets show "Error" (note: I increased the period to 90 days to make the report show results because no one in my organization has a birthday within 14 days of today):

Leave a comment: