mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
person: create a person with address (and household without position (remove required position for household member)
This commit is contained in:
parent
c214c2f4a4
commit
bad5506b98
@ -82,14 +82,13 @@ class HouseholdMember
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=Position::class)
|
||||
* @Serializer\Groups({"read", "docgen:read"})
|
||||
* @Assert\NotNull(groups={"household_memberships_created"})
|
||||
*/
|
||||
private ?Position $position = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", name="sharedhousehold")
|
||||
*/
|
||||
private bool $shareHousehold = false;
|
||||
private bool $shareHousehold = true;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
|
||||
@ -201,7 +200,7 @@ class HouseholdMember
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPosition(Position $position): self
|
||||
public function setPosition(?Position $position): self
|
||||
{
|
||||
if ($this->position instanceof Position) {
|
||||
throw new LogicException('The position is already set. You cannot change ' .
|
||||
@ -209,7 +208,9 @@ class HouseholdMember
|
||||
}
|
||||
|
||||
$this->position = $position;
|
||||
$this->shareHousehold = $position->getShareHousehold();
|
||||
if (null !== $position){
|
||||
$this->shareHousehold = $position->getShareHousehold();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class MembersEditor
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
public function addMovement(DateTimeImmutable $date, Person $person, Position $position, ?bool $holder = false, ?string $comment = null): self
|
||||
public function addMovement(DateTimeImmutable $date, Person $person, ?Position $position, ?bool $holder = false, ?string $comment = null): self
|
||||
{
|
||||
if (null === $this->household) {
|
||||
throw new LogicException('You must define a household first');
|
||||
@ -69,72 +69,75 @@ class MembersEditor
|
||||
->setComment($comment);
|
||||
$this->household->addMember($membership);
|
||||
|
||||
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 (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);
|
||||
|
||||
$counter = 0;
|
||||
$counter = 0;
|
||||
|
||||
foreach ($person->getHouseholdParticipationsShareHousehold() as $participation) {
|
||||
if ($participation === $membership) {
|
||||
continue;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($participation->getStartDate() > $membership->getStartDate()) {
|
||||
continue;
|
||||
// send also the event if there was no participation before
|
||||
if (0 === $counter) {
|
||||
$this->events[] = $event;
|
||||
}
|
||||
|
||||
++$counter;
|
||||
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 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);
|
||||
}
|
||||
|
||||
if ($participation->getEndDate() === null || $participation->getEndDate() > $date) {
|
||||
$participation->setEndDate($date);
|
||||
$this->membershipsAffected[] = $participation;
|
||||
$this->oldMembershipsHashes[] = spl_object_hash($participation);
|
||||
// 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) {
|
||||
$event->setPreviousMembership($participation);
|
||||
$this->events[] = $event;
|
||||
if ($participation->getHousehold() === $this->household
|
||||
&& ($participation->getEndDate() === null || $participation->getEndDate() > $membership->getStartDate())
|
||||
&& $participation->getStartDate() <= $membership->getStartDate()
|
||||
) {
|
||||
$participation->setEndDate($membership->getStartDate());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 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);
|
||||
}
|
||||
|
||||
// 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;
|
||||
$this->persistables[] = $membership;
|
||||
|
||||
|
@ -302,14 +302,10 @@ export default {
|
||||
'type': 'person',
|
||||
'id': responsePerson.id
|
||||
},
|
||||
'position': {
|
||||
"type": "household_position",
|
||||
"id": 4 //TODO, which position?
|
||||
},
|
||||
'start_date': {
|
||||
'datetime': `${new Date().toISOString().split('T')[0]}T00:00:00+02:00`
|
||||
},
|
||||
'holder': false, //TODO true or false?
|
||||
'holder': false,
|
||||
'comment': null
|
||||
}
|
||||
],
|
||||
|
@ -146,6 +146,7 @@
|
||||
<label class="form-check-label">{{ $t('person.address.show_address_form') }}</label>
|
||||
</div>
|
||||
<div v-if="action === 'create' && showAddressFormValue" class="form-floating mb-3">
|
||||
<p>{{ $t('person.address.warning') }}</p>
|
||||
<add-address
|
||||
:context="addAddress.context"
|
||||
:options="addAddress.options"
|
||||
|
@ -45,7 +45,8 @@ const personMessages = {
|
||||
},
|
||||
address: {
|
||||
create_address: "Ajouter une adresse",
|
||||
show_address_form: "Créer un ménage et ajouter une adresse"
|
||||
show_address_form: "Créer un ménage et ajouter une adresse",
|
||||
warning: "Un nouveau ménage va être créé. L'usager sera membre de ce ménage."
|
||||
}
|
||||
},
|
||||
error_only_one_person: "Une seule personne peut être sélectionnée !"
|
||||
|
@ -111,6 +111,7 @@
|
||||
{{ form_row(form.addressForm) }}
|
||||
</div>
|
||||
<div id=address>
|
||||
<p>{{ 'A new household will be created. The person will be member of this household.'|trans }}</p>
|
||||
{{ form_row(form.address) }}
|
||||
</div>
|
||||
|
||||
|
@ -116,12 +116,18 @@ class MembersEditorNormalizer implements DenormalizerAwareInterface, Denormalize
|
||||
$format,
|
||||
$context
|
||||
);
|
||||
$position = $this->denormalizer->denormalize(
|
||||
$concerned['position'] ?? null,
|
||||
Position::class,
|
||||
$format,
|
||||
$context
|
||||
);
|
||||
|
||||
if (\array_key_exists('position', $concerned)) {
|
||||
$position = $this->denormalizer->denormalize(
|
||||
$concerned['position'] ?? null,
|
||||
Position::class,
|
||||
$format,
|
||||
$context
|
||||
);
|
||||
} else {
|
||||
$position = null;
|
||||
}
|
||||
|
||||
$startDate = $this->denormalizer->denormalize(
|
||||
$concerned['start_date'] ?? null,
|
||||
DateTimeImmutable::class,
|
||||
|
@ -87,6 +87,7 @@ choose civility: --
|
||||
All genders: tous les genres
|
||||
Any person selected: Aucune personne sélectionnée
|
||||
Create a household and add an address: Créer un ménage et ajouter une adresse
|
||||
A new household will be created. The person will be member of this household.: Un nouveau ménage va être créé. L'usager sera membre de ce ménage.
|
||||
|
||||
# dédoublonnage
|
||||
Old person: Doublon
|
||||
|
Loading…
x
Reference in New Issue
Block a user