mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 22:35:01 +00:00
[test][household] add a test to check if leaveMovement write an enddate when member startdate is today
This commit is contained in:
@@ -55,6 +55,14 @@ class MembersEditor
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a person to the household
|
||||
*
|
||||
* The person is added to the household associated with this editor's instance.
|
||||
*
|
||||
* If the person is also a member of another household, or the same household at the same position, the person
|
||||
* is not associated any more with the previous household.
|
||||
*/
|
||||
public function addMovement(DateTimeImmutable $date, Person $person, ?Position $position, ?bool $holder = false, ?string $comment = null): self
|
||||
{
|
||||
if (null === $this->household) {
|
||||
@@ -69,68 +77,66 @@ class MembersEditor
|
||||
->setComment($comment);
|
||||
$this->household->addMember($membership);
|
||||
|
||||
if (null !== $position) {
|
||||
if ($position->getShareHousehold()) {
|
||||
// launch event only if moving to a "share household" position,
|
||||
// and if the destination household is different than the previous one
|
||||
$event = new PersonAddressMoveEvent($person);
|
||||
$event->setNextMembership($membership);
|
||||
if ($membership->getShareHousehold()) {
|
||||
// launch event only if moving to a "share household" position,
|
||||
// and if the destination household is different than the previous one
|
||||
$event = new PersonAddressMoveEvent($person);
|
||||
$event->setNextMembership($membership);
|
||||
|
||||
$counter = 0;
|
||||
$counter = 0;
|
||||
|
||||
foreach ($person->getHouseholdParticipationsShareHousehold() as $participation) {
|
||||
if ($participation === $membership) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($participation->getStartDate() > $membership->getStartDate()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
++$counter;
|
||||
|
||||
if ($participation->getEndDate() === null || $participation->getEndDate() > $date) {
|
||||
$participation->setEndDate($date);
|
||||
$this->membershipsAffected[] = $participation;
|
||||
$this->oldMembershipsHashes[] = spl_object_hash($participation);
|
||||
|
||||
if ($participation->getHousehold() !== $this->household) {
|
||||
$event->setPreviousMembership($participation);
|
||||
$this->events[] = $event;
|
||||
}
|
||||
}
|
||||
foreach ($person->getHouseholdParticipationsShareHousehold() as $participation) {
|
||||
if ($participation === $membership) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// send also the event if there was no participation before
|
||||
if (0 === $counter) {
|
||||
$this->events[] = $event;
|
||||
if ($participation->getStartDate() > $membership->getStartDate()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($person->getHouseholdParticipationsNotShareHousehold() as $participation) {
|
||||
if ($participation->getHousehold() === $this->household
|
||||
&& $participation->getEndDate() === null || $participation->getEndDate() > $membership->getStartDate()
|
||||
&& $participation->getStartDate() <= $membership->getStartDate()
|
||||
) {
|
||||
$participation->setEndDate($membership->getStartDate());
|
||||
++$counter;
|
||||
|
||||
if ($participation->getEndDate() === null || $participation->getEndDate() > $date) {
|
||||
$participation->setEndDate($date);
|
||||
$this->membershipsAffected[] = $participation;
|
||||
$this->oldMembershipsHashes[] = spl_object_hash($participation);
|
||||
|
||||
if ($participation->getHousehold() !== $this->household) {
|
||||
$event->setPreviousMembership($participation);
|
||||
$this->events[] = $event;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if a members is moved to the same household than the one he belongs to,
|
||||
// we should make it leave the household
|
||||
if ($person->getCurrentHousehold($date) === $this->household) {
|
||||
$this->leaveMovement($date, $person);
|
||||
}
|
||||
|
||||
// send also the event if there was no participation before
|
||||
if (0 === $counter) {
|
||||
$this->events[] = $event;
|
||||
}
|
||||
|
||||
foreach ($person->getHouseholdParticipationsNotShareHousehold() as $participation) {
|
||||
if ($participation->getHousehold() === $this->household
|
||||
&& $participation->getEndDate() === null || $participation->getEndDate() > $membership->getStartDate()
|
||||
&& $participation->getStartDate() <= $membership->getStartDate()
|
||||
) {
|
||||
$participation->setEndDate($membership->getStartDate());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if there are multiple belongings not sharing household, close the others
|
||||
foreach ($person->getHouseholdParticipations() as $participation) {
|
||||
if ($participation === $membership) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// if there are multiple belongings not sharing household, close the others
|
||||
foreach ($person->getHouseholdParticipationsNotShareHousehold() as $participation) {
|
||||
if ($participation === $membership) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($participation->getHousehold() === $this->household
|
||||
&& ($participation->getEndDate() === null || $participation->getEndDate() > $membership->getStartDate())
|
||||
&& $participation->getStartDate() <= $membership->getStartDate()
|
||||
) {
|
||||
if ($participation->getHousehold() === $this->household
|
||||
&& ($participation->getEndDate() === null || $participation->getEndDate() > $membership->getStartDate())
|
||||
&& $participation->getStartDate() <= $membership->getStartDate()
|
||||
) {
|
||||
if ($participation->getShareHousehold()) {
|
||||
// if a members is moved to the same household than the one he belongs to,
|
||||
// we should make it leave the household
|
||||
$this->leaveMovement($date, $person);
|
||||
} else {
|
||||
$participation->setEndDate($membership->getStartDate());
|
||||
}
|
||||
}
|
||||
@@ -158,6 +164,15 @@ class MembersEditor
|
||||
return null !== $this->household;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a person leave the household.
|
||||
*
|
||||
* Makes a person leave the household **associated with this editor**.
|
||||
*
|
||||
* @param DateTimeImmutable $date
|
||||
* @param Person $person
|
||||
* @return $this
|
||||
*/
|
||||
public function leaveMovement(
|
||||
DateTimeImmutable $date,
|
||||
Person $person
|
||||
@@ -168,7 +183,8 @@ class MembersEditor
|
||||
$criteria->where(
|
||||
$expr->andX(
|
||||
$expr->lte('startDate', $date),
|
||||
$expr->isNull('endDate')
|
||||
$expr->isNull('endDate'),
|
||||
$expr->eq('shareHousehold', true)
|
||||
)
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user