mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
household editor: handle case when the person is repositionned in the
same household, and the person is already in a position "without household"
This commit is contained in:
parent
c477996acf
commit
83dfe530e9
@ -119,6 +119,20 @@ class MembersEditor
|
||||
if ($person->getCurrentHousehold($date) === $this->household) {
|
||||
$this->leaveMovement($date, $person);
|
||||
}
|
||||
|
||||
// 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()
|
||||
) {
|
||||
$participation->setEndDate($membership->getStartDate());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->membershipsAffected[] = $membership;
|
||||
|
@ -40,6 +40,40 @@ final class MembersEditorTest extends TestCase
|
||||
$this->factory = $this->buildMembersEditorFactory();
|
||||
}
|
||||
|
||||
public function testAddingParticipationNotSharingHouseholdCloseTheOldOnes()
|
||||
{
|
||||
$person = new Person();
|
||||
$position = (new Position())->setShareHousehold(false);
|
||||
$household = new Household();
|
||||
|
||||
// set a first time the person in position
|
||||
$factory = $this->buildMembersEditorFactory();
|
||||
$editor = $factory->createEditor($household);
|
||||
|
||||
$editor->addMovement($aMonthAgo = new DateTimeImmutable('1 month ago'), $person, $position);
|
||||
|
||||
// set a second time the person in position
|
||||
$factory = $this->buildMembersEditorFactory();
|
||||
$editor = $factory->createEditor($household);
|
||||
|
||||
$editor->addMovement($yesterday = new DateTimeImmutable('yesterday'), $person, $position);
|
||||
|
||||
$this->assertCount(2, $person->getHouseholdParticipationsNotShareHousehold());
|
||||
|
||||
$startDates = [];
|
||||
$endDates = [];
|
||||
|
||||
foreach ($person->getHouseholdParticipationsNotShareHousehold() as $participation) {
|
||||
$startDates[] = $participation->getStartDate();
|
||||
$endDates[] = $participation->getEndDate();
|
||||
}
|
||||
|
||||
$this->assertContains($aMonthAgo, $startDates);
|
||||
$this->assertContains($yesterday, $startDates);
|
||||
$this->assertContains($yesterday, $endDates);
|
||||
$this->assertContains(null, $endDates);
|
||||
}
|
||||
|
||||
/**
|
||||
* We test here a move for a person:.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user