diff --git a/.changes/unreleased/Fixed-20250120-130410.yaml b/.changes/unreleased/Fixed-20250120-130410.yaml new file mode 100644 index 000000000..e1e326b07 --- /dev/null +++ b/.changes/unreleased/Fixed-20250120-130410.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: '[export] Fix aggregation of referrer''s scope and job: fix the date range comparison' +time: 2025-01-20T13:04:10.856929843+01:00 +custom: + Issue: "348" diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php index c5f274cc4..30ac95027 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php @@ -50,18 +50,9 @@ readonly class ReferrerScopeAggregator implements AggregatorInterface, DataTrans Join::WITH, $qb->expr()->andX( $qb->expr()->eq("{$p}_userHistory.accompanyingPeriod", 'acp.id'), - $qb->expr()->andX( - // check that the user is referrer when the accompanying period is opened - $qb->expr()->gte('COALESCE(acp.closingDate, CURRENT_TIMESTAMP())', "{$p}_userHistory.startDate"), - $qb->expr()->orX( - $qb->expr()->isNull("{$p}_userHistory.endDate"), - $qb->expr()->lt('COALESCE(acp.openingDate, CURRENT_TIMESTAMP())', "{$p}_userHistory.endDate") - ) - ), - $qb->expr()->andX( - "{$p}_userHistory.startDate <= :{$p}_endDate", - "COALESCE({$p}_userHistory.endDate, CURRENT_TIMESTAMP()) > :{$p}_startDate" - ) + // check that the user is referrer when the accompanying period is opened + "OVERLAPSI (acp.openingDate, acp.closingDate), ({$p}_userHistory.startDate, {$p}_userHistory.endDate) = TRUE", + "OVERLAPSI (:{$p}_startDate, :{$p}_endDate), ({$p}_userHistory.startDate, {$p}_userHistory.endDate) = TRUE" ) ) ->leftJoin( @@ -69,18 +60,9 @@ readonly class ReferrerScopeAggregator implements AggregatorInterface, DataTrans "{$p}_scopeHistory", Join::WITH, $qb->expr()->andX( - $qb->expr()->eq("{$p}_scopeHistory.user", "{$p}_userHistory.user"), - $qb->expr()->andX( - $qb->expr()->lte("{$p}_scopeHistory.startDate", "{$p}_userHistory.startDate"), - $qb->expr()->orX( - $qb->expr()->isNull("{$p}_scopeHistory.endDate"), - $qb->expr()->gt("{$p}_scopeHistory.endDate", "{$p}_userHistory.startDate") - ) - ), - $qb->expr()->andX( - "{$p}_scopeHistory.startDate <= :{$p}_endDate", - "COALESCE({$p}_scopeHistory.endDate, CURRENT_TIMESTAMP()) > :{$p}_startDate" - ) + "{$p}_scopeHistory.user = {$p}_userHistory.user", + "OVERLAPSI ({$p}_scopeHistory.startDate, {$p}_scopeHistory.endDate), ({$p}_userHistory.startDate, {$p}_userHistory.endDate) = TRUE", + "OVERLAPSI (:{$p}_startDate, :{$p}_endDate), ({$p}_userHistory.startDate, {$p}_userHistory.endDate) = TRUE" ) ) ->setParameter("{$p}_startDate", $this->rollingDateConverter->convert($data['start_date'])) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php index b5d6566e7..903d3c9f4 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php @@ -50,17 +50,9 @@ final readonly class UserJobAggregator implements AggregatorInterface, DataTrans Join::WITH, $qb->expr()->andX( $qb->expr()->eq("{$p}_userHistory.accompanyingPeriod", 'acp.id'), - $qb->expr()->andX( - $qb->expr()->gte('COALESCE(acp.closingDate, CURRENT_TIMESTAMP())', "{$p}_userHistory.startDate"), - $qb->expr()->orX( - $qb->expr()->isNull("{$p}_userHistory.endDate"), - $qb->expr()->lt('COALESCE(acp.closingDate, CURRENT_TIMESTAMP())', "{$p}_userHistory.endDate") - ) - ), - $qb->expr()->andX( - "{$p}_userHistory.startDate <= :{$p}_endDate", - "COALESCE({$p}_userHistory.endDate, CURRENT_TIMESTAMP()) > :{$p}_startDate" - ) + // check that the user is referrer when the accompanying period is opened + "OVERLAPSI (acp.openingDate, acp.closingDate), ({$p}_userHistory.startDate, {$p}_userHistory.endDate) = TRUE", + "OVERLAPSI (:{$p}_startDate, :{$p}_endDate), ({$p}_userHistory.startDate, {$p}_userHistory.endDate) = TRUE" ) ) ->leftJoin( @@ -68,18 +60,9 @@ final readonly class UserJobAggregator implements AggregatorInterface, DataTrans "{$p}_jobHistory", Join::WITH, $qb->expr()->andX( - $qb->expr()->eq("{$p}_jobHistory.user", "{$p}_userHistory.user"), - $qb->expr()->andX( - $qb->expr()->lte("{$p}_jobHistory.startDate", "{$p}_userHistory.startDate"), - $qb->expr()->orX( - $qb->expr()->isNull("{$p}_jobHistory.endDate"), - $qb->expr()->gt("{$p}_jobHistory.endDate", "{$p}_userHistory.startDate") - ) - ), - $qb->expr()->andX( - "{$p}_jobHistory.startDate <= :{$p}_endDate", - "COALESCE({$p}_jobHistory.endDate, CURRENT_TIMESTAMP()) > :{$p}_startDate" - ) + "{$p}_jobHistory.user = {$p}_userHistory.user", + "OVERLAPSI ({$p}_jobHistory.startDate, {$p}_jobHistory.endDate), ({$p}_userHistory.startDate, {$p}_userHistory.endDate) = TRUE", + "OVERLAPSI (:{$p}_startDate, :{$p}_endDate), ({$p}_jobHistory.startDate, {$p}_jobHistory.endDate) = TRUE" ) ) ->setParameter("{$p}_startDate", $this->rollingDateConverter->convert($data['start_date'])) diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregatorTest.php index 37100110a..7b0996c3c 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregatorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregatorTest.php @@ -73,7 +73,7 @@ final class UserJobAggregatorTest extends AbstractAggregatorTest public static function getFormData(): array { return [ - ['start_date' => new RollingDate(RollingDate::T_WEEK_CURRENT_START), 'end_date' => new RollingDate(RollingDate::T_TODAY)], + ['start_date' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), 'end_date' => new RollingDate(RollingDate::T_TODAY)], ]; } @@ -86,7 +86,7 @@ final class UserJobAggregatorTest extends AbstractAggregatorTest $em->createQueryBuilder() ->select('count(acp.id)') ->from(AccompanyingPeriod::class, 'acp') - ->join('acp.job', 'acpjob'), + ->leftJoin('acp.job', 'acpjob'), $em->createQueryBuilder() ->select('count(acp.id)') ->from(AccompanyingPeriod::class, 'acp'),