diff --git a/CHANGELOG.md b/CHANGELOG.md index 48e2ad7dd..b7b8409ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,9 +33,10 @@ and this project adheres to * [Household]: Add end date in HouseholdMember form for 'enfant hors menage' (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/434) * [homepage_widget]: If no sender then display as 'notification automatique' (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/435) * [parcours]: Order social activities and only display most recent three in parcours resumé (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/481) -* [3party]: 3party: redirect to parent when contact (child) is opened in view page +* [3party]: 3party: redirect to parent when contact (child) is opened in view page * [parcours / addresses]: launch an event when a person change address (either through changing household or because the household is associated to a new address). If the person is localising a course, the course location go back to a temporarily address. * Creation of PickCivilityType, and implementation in PersonType and ThirdpartyType +* [budget]: budget enabled for persons and households (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/469) ### test release 2022-02-14 diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 53cbb904b..300eae927 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -12,6 +12,8 @@ declare(strict_types=1); namespace Chill\PersonBundle\Entity; use ArrayIterator; +use Chill\BudgetBundle\Entity\Charge; +use Chill\BudgetBundle\Entity\Resource; use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; use Chill\MainBundle\Entity\Address; @@ -29,8 +31,6 @@ use Chill\PersonBundle\Entity\Person\PersonCurrentAddress; use Chill\PersonBundle\Validator\Constraints\Household\HouseholdMembershipSequential; use Chill\PersonBundle\Validator\Constraints\Person\Birthdate; use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenter; -use Chill\BudgetBundle\Entity\Charge; -use Chill\BudgetBundle\Entity\Resource; use DateTime; use DateTimeImmutable; use DateTimeInterface; @@ -38,7 +38,6 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping as ORM; -use Doctrine\ORM\PersistentCollection; use Exception; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Validator\Constraints as Assert; @@ -158,6 +157,26 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI */ private $birthdate; + /** + * Read-only field, computed by the database. + * + * @ORM\OneToMany( + * targetEntity=Charge::class, + * mappedBy="person" + * ) + */ + private Collection $budgetCharges; + + /** + * Read-only field, computed by the database. + * + * @ORM\OneToMany( + * targetEntity=Resource::class, + * mappedBy="person" + * ) + */ + private Collection $budgetResources; + /** * The person's center. * @@ -486,26 +505,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI */ private $updatedBy; - /** - * Read-only field, computed by the database. - * - * @ORM\OneToMany( - * targetEntity=Resource::class, - * mappedBy="person" - * ) - */ - private Collection $budgetResources; - - /** - * Read-only field, computed by the database. - * - * @ORM\OneToMany( - * targetEntity=Charge::class, - * mappedBy="person" - * ) - */ - private Collection $budgetCharges; - /** * Person constructor. */ @@ -564,16 +563,16 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this; } - public function addBudgetResource(Resource $budgetResource): self + public function addBudgetCharge(Charge $budgetCharge): self { - $this->budgetResources[] = $budgetResource; + $this->budgetCharges[] = $budgetCharge; return $this; } - public function addBudgetCharge(Charge $budgetCharge): self + public function addBudgetResource(Resource $budgetResource): self { - $this->budgetCharges[] = $budgetCharge; + $this->budgetResources[] = $budgetResource; return $this; } @@ -669,7 +668,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * * Used in template, to find the participation when iterating on a list * of period. - * */ public function findParticipationForPeriod(AccompanyingPeriod $period): ?AccompanyingPeriodParticipation { @@ -851,22 +849,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this->addresses; } - /** - * @return Collection|BudgetResources[] - */ - public function getBudgetResources(): Collection - { - return $this->budgetResources; - } - - /** - * @return Collection|BudgetCharges[] - */ - public function getBudgetCharges(): Collection - { - return $this->budgetCharges; - } - /** * Return the age of a person, calculated at the date 'now'. * @@ -897,6 +879,22 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this->birthdate; } + /** + * @return Collection|BudgetCharges[] + */ + public function getBudgetCharges(): Collection + { + return $this->budgetCharges; + } + + /** + * @return Collection|BudgetResources[] + */ + public function getBudgetResources(): Collection + { + return $this->budgetResources; + } + public function getCenter(): ?Center { return $this->center; @@ -1426,9 +1424,12 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI $this->addresses->removeElement($address); } - public function removeBudgetResource(Resource $budgetResource): self + public function removeAltName(PersonAltName $altName): self { - $this->budgetResources->removeElement($budgetResource); + if ($this->altNames->contains($altName)) { + $altName->setPerson(null); + $this->altNames->removeElement($altName); + } return $this; } @@ -1440,12 +1441,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this; } - public function removeAltName(PersonAltName $altName): self + public function removeBudgetResource(Resource $budgetResource): self { - if ($this->altNames->contains($altName)) { - $altName->setPerson(null); - $this->altNames->removeElement($altName); - } + $this->budgetResources->removeElement($budgetResource); return $this; } diff --git a/src/Bundle/ChillPersonBundle/config/services/doctrineEventListener.yaml b/src/Bundle/ChillPersonBundle/config/services/doctrineEventListener.yaml index f75243d02..f7015c454 100644 --- a/src/Bundle/ChillPersonBundle/config/services/doctrineEventListener.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/doctrineEventListener.yaml @@ -7,6 +7,11 @@ services: event: 'prePersist' entity: 'Chill\PersonBundle\Entity\Person' method: 'prePersistPerson' + - + name: 'doctrine.orm.entity_listener' + event: 'preUpdate' + entity: 'Chill\PersonBundle\Entity\Person' + method: 'prePersistPerson' - name: 'doctrine.orm.entity_listener' event: 'prePersist'