feat : ajout des suspensions et des jours de présence
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
This commit is contained in:
20
src/Repository/ContractSuspensionRepository.php
Normal file
20
src/Repository/ContractSuspensionRepository.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\ContractSuspension;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<ContractSuspension>
|
||||
*/
|
||||
class ContractSuspensionRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, ContractSuspension::class);
|
||||
}
|
||||
}
|
||||
@@ -138,6 +138,48 @@ final class WorkHourRepository extends ServiceEntityRepository implements WorkHo
|
||||
return $qb->getQuery()->getOneOrNullResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, float> YYYY-MM => presence day count (0.5 for half-days)
|
||||
*/
|
||||
public function countPresenceDaysByMonth(Employee $employee, DateTimeImmutable $from, DateTimeImmutable $to): array
|
||||
{
|
||||
$sql = <<<'SQL'
|
||||
SELECT TO_CHAR(work_date, 'YYYY-MM') AS month,
|
||||
SUM(
|
||||
CASE
|
||||
WHEN (morning_from IS NOT NULL OR is_present_morning = true)
|
||||
AND (afternoon_from IS NOT NULL OR is_present_afternoon = true)
|
||||
THEN 1.0
|
||||
WHEN (morning_from IS NOT NULL OR is_present_morning = true)
|
||||
OR (afternoon_from IS NOT NULL OR is_present_afternoon = true)
|
||||
THEN 0.5
|
||||
ELSE 0
|
||||
END
|
||||
) AS cnt
|
||||
FROM work_hours
|
||||
WHERE employee_id = :employee
|
||||
AND work_date >= :from
|
||||
AND work_date <= :to
|
||||
AND (morning_from IS NOT NULL OR is_present_morning = true
|
||||
OR afternoon_from IS NOT NULL OR is_present_afternoon = true)
|
||||
GROUP BY month
|
||||
SQL;
|
||||
|
||||
$conn = $this->getEntityManager()->getConnection();
|
||||
$rows = $conn->fetchAllAssociative($sql, [
|
||||
'employee' => $employee->getId(),
|
||||
'from' => $from->format('Y-m-d'),
|
||||
'to' => $to->format('Y-m-d'),
|
||||
]);
|
||||
|
||||
$result = [];
|
||||
foreach ($rows as $row) {
|
||||
$result[(string) $row['month']] = (float) $row['cnt'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function hasPendingSiteValidationForSiteAndDate(int $siteId, DateTimeInterface $date): bool
|
||||
{
|
||||
$workDate = DateTimeImmutable::createFromInterface($date);
|
||||
|
||||
Reference in New Issue
Block a user