Fix filtres and scopes to take into account job and scope when the refferrer is add to the accompanying period work

This commit is contained in:
2023-10-16 10:58:41 +02:00
parent 63e9d1a96f
commit 68d28f3e28
24 changed files with 352 additions and 173 deletions

View File

@@ -11,13 +11,16 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User\UserJobHistory;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Repository\UserJobRepository;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkReferrerHistory;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
@@ -29,7 +32,6 @@ final readonly class JobAggregator implements AggregatorInterface
private const PREFIX = 'acp_work_action_agg_user_job';
public function __construct(
private RollingDateConverter $rollingDateConverter,
private UserJobRepository $jobRepository,
private TranslatableStringHelper $translatableStringHelper
) {}
@@ -44,27 +46,16 @@ final readonly class JobAggregator implements AggregatorInterface
$p = self::PREFIX;
$qb
->leftJoin("acpw.referrers", "{$p}_user")
->leftJoin(
UserJobHistory::class,
"{$p}_history",
UserJob::class,
"{$p}_job",
Expr\Join::WITH,
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
)
->andWhere(
$qb->expr()->andX(
$qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"),
$qb->expr()->orX(
$qb->expr()->isNull("{$p}_history.endDate"),
$qb->expr()->gt("{$p}_history.endDate", ":{$p}_at")
)
)
)
->addSelect("IDENTITY({$p}_history.job) as {$p}_select")
->setParameter(
"{$p}_at",
$this->rollingDateConverter->convert($data['job_at'])
'EXISTS (SELECT 1 FROM ' . AccompanyingPeriodWorkReferrerHistory::class . " {$p}_ref_history
JOIN {$p}_ref_history.user {$p}_ref_history_user JOIN {$p}_ref_history_user.jobHistories {$p}_job_history
WHERE {$p}_ref_history.accompanyingPeriodWork = acpw AND IDENTITY({$p}_job_history.job) = {$p}_job.id AND {$p}_job_history.startDate <= {$p}_ref_history.startDate
AND ({$p}_job_history.endDate IS NULL or {$p}_job_history.endDate >= {$p}_ref_history.startDate))"
)
->addSelect("{$p}_job.id as {$p}_select")
->addGroupBy("{$p}_select");
}
@@ -73,17 +64,11 @@ final readonly class JobAggregator implements AggregatorInterface
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('job_at', PickRollingDateType::class, [
'label' => 'export.aggregator.course_work.by_agent_job.Calc date',
'required' => true
]);
}
public function buildForm(FormBuilderInterface $builder) {}
public function getFormDefaultData(): array
{
return ['job_at' => new RollingDate(RollingDate::T_TODAY)];
return [];
}
public function getLabels($key, array $values, $data)

View File

@@ -65,7 +65,7 @@ final readonly class ReferrerAggregator implements AggregatorInterface
$r = $this->userRepository->find($value);
return $this->userRender->renderString($r, []);
return $this->userRender->renderString($r, ['absence' => false, 'user_job' => false, 'main_scope' => false]);
};
}

View File

@@ -11,13 +11,16 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User\UserScopeHistory;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Repository\ScopeRepository;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkReferrerHistory;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
@@ -29,7 +32,6 @@ final readonly class ScopeAggregator implements AggregatorInterface
private const PREFIX = 'acp_work_action_agg_user_scope';
public function __construct(
private RollingDateConverter $rollingDateConverter,
private ScopeRepository $scopeRepository,
private TranslatableStringHelper $translatableStringHelper
) {}
@@ -44,27 +46,16 @@ final readonly class ScopeAggregator implements AggregatorInterface
$p = self::PREFIX;
$qb
->leftJoin("acpw.referrers", "{$p}_user")
->leftJoin(
UserScopeHistory::class,
"{$p}_history",
Scope::class,
"{$p}_scope",
Expr\Join::WITH,
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
)
->andWhere(
$qb->expr()->andX(
$qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"),
$qb->expr()->orX(
$qb->expr()->isNull("{$p}_history.endDate"),
$qb->expr()->gt("{$p}_history.endDate", ":{$p}_at")
)
)
)
->addSelect("IDENTITY({$p}_history.scope) as {$p}_select")
->setParameter(
"{$p}_at",
$this->rollingDateConverter->convert($data['scope_at'])
'EXISTS (SELECT 1 FROM ' . AccompanyingPeriodWorkReferrerHistory::class . " {$p}_ref_history
JOIN {$p}_ref_history.user {$p}_ref_history_user JOIN {$p}_ref_history_user.scopeHistories {$p}_scope_history
WHERE {$p}_ref_history.accompanyingPeriodWork = acpw AND IDENTITY({$p}_scope_history.scope) = {$p}_scope.id AND {$p}_scope_history.startDate <= {$p}_ref_history.startDate
AND ({$p}_scope_history.endDate IS NULL or {$p}_scope_history.endDate >= {$p}_ref_history.startDate))"
)
->addSelect("{$p}_scope.id as {$p}_select")
->addGroupBy("{$p}_select");
}
@@ -73,17 +64,11 @@ final readonly class ScopeAggregator implements AggregatorInterface
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('scope_at', PickRollingDateType::class, [
'label' => 'export.aggregator.course_work.by_agent_scope.Calc date',
'required' => true,
]);
}
public function buildForm(FormBuilderInterface $builder) {}
public function getFormDefaultData(): array
{
return ['scope_at' => new RollingDate(RollingDate::T_TODAY)];
return [];
}
public function getLabels($key, array $values, $data)

View File

@@ -132,7 +132,7 @@ class ListEvaluation implements ListInterface, GroupedExportInterface
);
},
'createdBy', 'updatedBy', 'acpw_acp_user' => $this->userHelper->getLabel($key, $values, 'export.list.eval.' . $key),
'acpw_referrers' => $this->userHelper->getLabel($key, $values, 'export.list.eval.' . $key),
'acpw_referrers' => $this->userHelper->getLabelMulti($key, $values, 'export.list.eval.' . $key),
'acpw_persons_id' => $this->aggregateStringHelper->getLabelMulti($key, $values, 'export.list.eval.' . $key),
'acpw_persons' => $this->personHelper->getLabelMulti($key, $values, 'export.list.eval.' . $key),
'eval_title' => $this->translatableStringExportLabelHelper
@@ -252,8 +252,8 @@ class ListEvaluation implements ListInterface, GroupedExportInterface
// referrers => at date XXXX
$qb
->addSelect('(SELECT IDENTITY(history.user) FROM ' . UserHistory::class . ' history ' .
'WHERE history.accompanyingPeriod = acp AND history.startDate <= :calc_date AND (history.endDate IS NULL OR history.endDate > :calc_date)) AS acpw_referrers');
->addSelect('(SELECT JSON_BUILD_OBJECT(\'uid\', IDENTITY(history.user), \'d\', history.startDate) FROM ' . UserHistory::class . ' history ' .
'WHERE history.accompanyingPeriod = acp AND history.startDate <= :calc_date AND (history.endDate IS NULL OR history.endDate > :calc_date)) AS referrers');
// persons
$qb

View File

@@ -18,6 +18,7 @@ use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkReferrerHistory;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Expr\Andx;
@@ -32,7 +33,6 @@ class JobFilter implements FilterInterface
private const PREFIX = 'acp_work_action_filter_user_job';
public function __construct(
private readonly RollingDateConverter $rollingDateConverter,
protected TranslatorInterface $translator,
private readonly TranslatableStringHelper $translatableStringHelper
) {}
@@ -46,30 +46,14 @@ class JobFilter implements FilterInterface
{
$p = self::PREFIX;
$qb
->leftJoin("acpw.referrers", "{$p}_user")
->leftJoin(
UserJobHistory::class,
"{$p}_history",
Expr\Join::WITH,
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
)
->andWhere(
$qb->expr()->andX(
$qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"),
$qb->expr()->orX(
$qb->expr()->isNull("{$p}_history.endDate"),
$qb->expr()->gt("{$p}_history.endDate", ":{$p}_at")
)
)
)
->andWhere(
$qb->expr()->in("{$p}_history.job", ":{$p}_job")
)
->setParameters([
"{$p}_job" => $data["job"],
"{$p}_at" => $this->rollingDateConverter->convert($data['job_at'])
]);
$qb->andWhere(
'EXISTS (SELECT 1 FROM ' . AccompanyingPeriodWorkReferrerHistory::class . " {$p}_ref_history
JOIN {$p}_ref_history.user {$p}_ref_history_user JOIN {$p}_ref_history_user.jobHistories {$p}_job_history
WHERE {$p}_ref_history.accompanyingPeriodWork = acpw AND {$p}_job_history.job IN (:{$p}_job) AND {$p}_job_history.startDate <= {$p}_ref_history.startDate
AND ({$p}_job_history.endDate IS NULL or {$p}_job_history.endDate >= {$p}_ref_history.startDate))"
);
$qb->setParameter("{$p}_job", $data["job"]);
}
public function applyOn(): string
@@ -88,10 +72,6 @@ class JobFilter implements FilterInterface
'multiple' => true,
'expanded' => true,
])
->add('job_at', PickRollingDateType::class, [
'label' => 'export.filter.work.by_user_job.Calc date',
'required' => true,
])
;
}

View File

@@ -18,6 +18,7 @@ use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkReferrerHistory;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
@@ -30,7 +31,6 @@ class ScopeFilter implements FilterInterface
private const PREFIX = 'acp_work_action_filter_user_scope';
public function __construct(
private readonly RollingDateConverter $rollingDateConverter,
protected TranslatorInterface $translator,
private readonly TranslatableStringHelper $translatableStringHelper
) {}
@@ -44,30 +44,13 @@ class ScopeFilter implements FilterInterface
{
$p = self::PREFIX;
$qb
->leftJoin("acpw.referrers", "{$p}_user")
->leftJoin(
UserScopeHistory::class,
"{$p}_history",
Expr\Join::WITH,
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
)
->andWhere(
$qb->expr()->andX(
$qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"),
$qb->expr()->orX(
$qb->expr()->isNull("{$p}_history.endDate"),
$qb->expr()->gt("{$p}_history.endDate", ":{$p}_at")
)
)
)
->andWhere(
$qb->expr()->in("{$p}_history.scope", ":{$p}_scope")
)
->setParameters([
"{$p}_scope" => $data["scope"],
"{$p}_at" => $this->rollingDateConverter->convert($data['scope_at'])
]);
$qb->andWhere(
'EXISTS (SELECT 1 FROM ' . AccompanyingPeriodWorkReferrerHistory::class . " {$p}_ref_history
JOIN {$p}_ref_history.user {$p}_ref_history_user JOIN {$p}_ref_history_user.scopeHistories {$p}_scope_history
WHERE {$p}_ref_history.accompanyingPeriodWork = acpw AND {$p}_scope_history.scope IN (:{$p}_scope) AND {$p}_scope_history.startDate <= {$p}_ref_history.startDate
AND ({$p}_scope_history.endDate IS NULL or {$p}_scope_history.endDate >= {$p}_ref_history.startDate))"
)
->setParameter("{$p}_scope", $data["scope"]);
}
public function applyOn()
@@ -86,10 +69,6 @@ class ScopeFilter implements FilterInterface
'multiple' => true,
'expanded' => true,
])
->add('scope_at', PickRollingDateType::class, [
'label' => 'export.filter.work.by_user_scope.Calc date',
'required' => true,
])
;
}

View File

@@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Export\Helper\DateTimeHelper;
use Chill\MainBundle\Export\Helper\ExportAddressHelper;
use Chill\MainBundle\Export\Helper\UserHelper;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
@@ -59,8 +60,10 @@ final readonly class ListAccompanyingPeriodHelper
'scopes',
'socialIssues',
'acpCreatedAt',
'acpCreatedBy_id',
'acpCreatedBy',
'acpUpdatedAt',
'acpUpdatedBy_id',
'acpUpdatedBy',
];
@@ -75,6 +78,7 @@ final readonly class ListAccompanyingPeriodHelper
private SocialIssueRender $socialIssueRender,
private TranslatableStringHelperInterface $translatableStringHelper,
private TranslatorInterface $translator,
private UserHelper $userHelper,
) {}
public function getQueryKeys($data)
@@ -104,6 +108,7 @@ final readonly class ListAccompanyingPeriodHelper
return $this->translatableStringHelper->localize(json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR));
},
'acpCreatedBy', 'acpUpdatedBy', 'referrer' => $this->userHelper->getLabel($key, $values, 'export.list.acp.' . $key),
'locationPersonName', 'requestorPerson' => function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
@@ -204,11 +209,11 @@ final readonly class ListAccompanyingPeriodHelper
// add the field which are simple association
$qb
->leftJoin('acp.createdBy', "acp_created_by_t")
->addSelect('acp_created_by_t.label AS acpCreatedBy');
->addSelect('IDENTITY(acp.createdBy) AS acpCreatedBy_id')
->addSelect('JSON_BUILD_OBJECT(\'uid\', IDENTITY(acp.createdBy), \'d\', acp.createdAt) AS acpCreatedBy');
$qb
->leftJoin('acp.updatedBy', "acp_updated_by_t")
->addSelect('acp_updated_by_t.label AS acpUpdatedBy');
->addSelect('IDENTITY(acp.updatedBy) AS acpUpdatedBy_id')
->addSelect('JSON_BUILD_OBJECT(\'uid\', IDENTITY(acp.updatedBy), \'d\', acp.updatedAt) AS acpUpdatedBy');
foreach (['origin' => 'label', 'closingMotive' => 'name', 'job' => 'label', 'administrativeLocation' => 'name'] as $entity => $field) {
$qb
@@ -230,7 +235,7 @@ final readonly class ListAccompanyingPeriodHelper
// referree at date
$qb
->addSelect('referrer_t.label AS referrer')
->addSelect('JSON_BUILD_OBJECT(\'uid\', IDENTITY(userHistory.user), \'d\', userHistory.startDate) AS referrer')
->addSelect('userHistory.startDate AS referrerSince')
->leftJoin('acp.userHistories', 'userHistory')
->leftJoin('userHistory.user', 'referrer_t')