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