src/Entity/Mandate.php line 102

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Domain\ESignature\Adapters\Gateway\Doctrine\ESignatureEntity;
  4. use App\Entity\Reference\ReferencePropertyServiceType;
  5. use App\Entity\Reference\VatReference;
  6. use App\Exception\MandateException;
  7. use Exception;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use ApiPlatform\Core\Annotation\ApiResource;
  11. use ApiPlatform\Core\Annotation\ApiSubresource;
  12. use App\Controller\Manager\Mandate\RefuseMandateController;
  13. use ApiPlatform\Core\Annotation\ApiFilter;
  14. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  15. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\ORM\Mapping as ORM;
  19. use App\Controller\Manager\Mandate\ValidateMandateController;
  20. use App\Entity\Reference\ReferenceTransactionStatus;
  21. use App\Entity\Reference\ReferenceMandateStatus;
  22. use App\Entity\Reference\ReferencePropertyType;
  23. use App\Entity\Reference\ReferenceMandateType;
  24. use App\Repository\MandateRepository;
  25. use App\Traits\TimeStampTrait;
  26. /**
  27.  * @ApiResource(
  28.  *     normalizationContext={"groups"={"mandate:read"}, "swagger_definition_name"="Read"},
  29.  *     denormalizationContext={"groups"={"mandate:write"}, "swagger_definition_name"="Write"},
  30.  *
  31.  *     itemOperations={
  32.  *           "get"={
  33.  *                  "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  34.  *                  "security_message" = "Vous n'avez pas le droit de visualiser ce mandat ."
  35.  *                  },
  36.  *           "put" = {
  37.  *              "security"="is_granted('PUT', object)",
  38.  *              "denormalization_context"={"groups"={"mandate:put"}},
  39.  *              },
  40.  *           "validate_mandate" = {
  41.  *              "denormalization_context"={"groups"= {"mandate:validate"} },
  42.  *              "security"="is_granted('ROLE_MANAGER')",
  43.  *              "method"="PATCH",
  44.  *              "path"="/mandate/{id}/validate",
  45.  *              "controller"=ValidateMandateController::class,
  46.  *              "read"=true,
  47.  *              "write"=false,
  48.  *           },
  49.  *           "refuse_mandate"={
  50.  *              "denormalization_context"={"groups"= {"mandate:refuse"} },
  51.  *              "security"="is_granted('ROLE_MANAGER')",
  52.  *              "method"="PATCH",
  53.  *              "path"="/mandate/{id}/refuse",
  54.  *              "controller"=RefuseMandateController::class,
  55.  *              "read"=true,
  56.  *              "write"=true,
  57.  *           },
  58.  *     },
  59.  *
  60.  *     collectionOperations={
  61.  *         "get"={
  62.  *            "access_control"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')"
  63.  *         },
  64.  *         "post"={
  65.  *             "access_control" = "is_granted('POST', object)",
  66.  *         },
  67.  *     },
  68.  *     attributes={
  69.  *          "pagination_items_per_page"=10,
  70.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} },
  71.  *          "order"={"id":"DESC"}
  72.  *     },
  73.  * )
  74.  * @ApiFilter(OrderFilter::class, properties={"id"} , arguments= {"orderParameterName" : "order"})
  75.  * @ApiFilter(SearchFilter::class, properties={
  76.  *          "id": "exact",
  77.  *          "property.collaborator.id": "exact",
  78.  *          "property.collaborator.firstName": "ipartial",
  79.  *          "property.collaborator.lastName": "ipartial",
  80.  *          "property.collaborator.professionalEmail": "partial",
  81.  *          "referenceMandateType.id":"exact",
  82.  *          "referenceMandateStatus.id": "exact",
  83.  *          "referenceMandateStatus.code": "exact",
  84.  *          "referencePropertyType.id": "exact",
  85.  *          "property.referenceServiceType.code": "exact",
  86.  *          "property.referenceServiceType.id": "exact",
  87.  *          "property.id": "exact",
  88.  *          "key": "partial",
  89.  *          "property.contact.id": "exact"
  90.  *
  91.  *  })
  92.  * @ORM\Entity(repositoryClass=MandateRepository::class)
  93.  * @ORM\HasLifecycleCallbacks()
  94.  * @ORM\EntityListeners({"App\EventListener\MandateListener"})
  95.  */
  96. class Mandate implements Loggable
  97. {
  98.     use TimeStampTrait;
  99.     public const DEFAULT_VALIDATION_PERIOD 3;
  100.     public const SECOND_VALIDATION_PERIOD 6;
  101.     public const THIRD_VALIDATION_PERIOD 9;
  102.     public const FOURTH_VALIDATION_PERIOD 12;
  103.     public const ALL_VALIDATION_PERIOD = [
  104.         self::DEFAULT_VALIDATION_PERIOD,
  105.         self::SECOND_VALIDATION_PERIOD,
  106.         self::THIRD_VALIDATION_PERIOD,
  107.         self::FOURTH_VALIDATION_PERIOD
  108.     ];
  109.     public const DEFAULT_AFTER_VALIDATION_PERIOD 6;
  110.     public const SECOND_AFTER_VALIDATION_PERIOD 9;
  111.     public const THIRD_AFTER_VALIDATION_PERIOD 12;
  112.     public const ALL_AFTER_VALIDATION_PERIOD = [
  113.         self::DEFAULT_AFTER_VALIDATION_PERIOD,
  114.         self::SECOND_AFTER_VALIDATION_PERIOD,
  115.         self::THIRD_AFTER_VALIDATION_PERIOD
  116.     ];
  117.     public const REFERENCE_MANDATE_STATUS_CODE_INVALID = [
  118.         ReferenceMandateStatus::REFERENCE_CODE_MANDATE_STATUS_ARCHIVED,
  119.         ReferenceMandateStatus::REFERENCE_CODE_MANDATE_STATUS_REFUSE
  120.     ];
  121.     /**
  122.      * @ORM\Id
  123.      * @ORM\GeneratedValue
  124.      * @ORM\Column(type="integer")
  125.      *
  126.      * @Groups({
  127.      *   "mandate:read",
  128.      *   "property:read",
  129.      *   "transaction:collection:read",
  130.      *   "business-indication:item:read",
  131.      *   "business-indication:collection:read",
  132.      *   "business-indication:item:read",
  133.      *   "transaction-item:read", "business-indication:item:read",
  134.      *   "property-visit:read"
  135.      * })
  136.      */
  137.     private ?int $id;
  138.     /**
  139.      * @ORM\ManyToOne(targetEntity=Property::class, inversedBy="mandates")
  140.      * @Assert\NotBlank
  141.      *
  142.      * @Groups({
  143.      *  "mandate:read","mandate:write",
  144.      *  "transaction-item:read",
  145.      *  "business-indication:item:read","business-indication:collection:read",
  146.      *  "property-visit:read",
  147.      *  "contact:read",
  148.      * })
  149.      *
  150.      */
  151.     private ?Property $property;
  152.     /**
  153.      * @ORM\Column(type="float",nullable=true)
  154.      *
  155.      * @Groups({"mandate:read","transaction-item:read", "business-indication:item:read"})
  156.      */
  157.     private ?float $maximumPrice;
  158.     /**
  159.      * @ORM\Column(type="float", nullable=true)
  160.      *
  161.      * @Groups({"mandate:read","transaction-item:read", "business-indication:item:read"})
  162.      *
  163.      */
  164.     private ?float $minimalArea;
  165.     /**
  166.      * @ORM\Column(type="float", nullable=true)
  167.      *
  168.      * @Groups({"mandate:read","transaction-item:read", "business-indication:item:read"})
  169.      *
  170.      */
  171.     private ?float $maximalArea;
  172.     /**
  173.      * @ORM\ManyToOne(targetEntity=ReferenceMandateType::class, inversedBy="mandates")
  174.      * @ORM\JoinColumn(nullable=false)
  175.      *
  176.      * @Assert\NotBlank
  177.      * @Groups({"mandate:read","mandate:write","mandate:put",
  178.      *         "transaction-item:read", "business-indication:item:read"
  179.      * })
  180.      */
  181.     private ?ReferenceMandateType $referenceMandateType;
  182.     /**
  183.      * @ORM\ManyToOne(targetEntity=ReferenceMandateStatus::class)
  184.      * @ORM\JoinColumn(nullable=false)
  185.      *
  186.      * @Groups({"mandate:read","transaction-item:read", "business-indication:item:read","property:read"})
  187.      */
  188.     private ?ReferenceMandateStatus $referenceMandateStatus;
  189.     /**
  190.      * @ORM\ManyToOne(targetEntity=ReferencePropertyType::class)
  191.      *
  192.      * @Groups({"mandate:read"})
  193.      */
  194.     private ?ReferencePropertyType $referencePropertyType;
  195.     /**
  196.      * @ORM\Column(type="string",nullable=true)
  197.      *
  198.      * @Groups({
  199.      *     "mandate:read","property-visit:read", "property:read",
  200.      *     "transaction:collection:read","transaction-item:read", "business-indication:item:read",
  201.      *     "business-indication:collection:read","business-indication:item:read"
  202.      * })
  203.      */
  204.     private ?string $key;
  205.     /**
  206.      * @ORM\Column(type="float", nullable=true)
  207.      *
  208.      * @Groups({"mandate:read","mandate:write","mandate:put"})
  209.      */
  210.     private ?float $commission 0;
  211.     /**
  212.      * @ORM\Column(type="boolean", nullable=true)
  213.      *
  214.      * @Groups({"mandate:read","mandate:write","mandate:put"})
  215.      */
  216.     private ?bool $isFreeEntry null;
  217.     /**
  218.      * @ORM\ManyToMany(targetEntity=PropertyVisitVoucher::class, inversedBy="mandates")
  219.      */
  220.     private $propertyVisitVouchers;
  221.     /**
  222.      * @ORM\OneToMany(targetEntity=Transaction::class, mappedBy="mandate")
  223.      */
  224.     private ?Collection $transactions null;
  225.     /**
  226.      * @Groups({
  227.      *     "mandate:read","mandate:put","mandate:write",
  228.      *     "transaction:collection:read","transaction-item:read",
  229.      *     "business-indication:collection:read","business-indication:item:read","business-indication:item:read",
  230.      *     "property-visit:read",
  231.      * })
  232.      *
  233.      * @ORM\Column(type="float", nullable=true)
  234.      */
  235.     private ?float $commissionPercent null;
  236.     /**
  237.      * @ORM\Column(type="integer",nullable=true)
  238.      *
  239.      * @Groups({
  240.      *     "mandate:read","mandate:put"
  241.      * })
  242.      */
  243.     private ?int $duration self::DEFAULT_VALIDATION_PERIOD;
  244.     /**
  245.      * @ORM\Column(type="integer", nullable=true)
  246.      *
  247.      * @Groups({
  248.      *     "mandate:read","mandate:put"
  249.      * })
  250.      */
  251.     private ?int $exclusiveDuration self::DEFAULT_AFTER_VALIDATION_PERIOD;
  252.     /**
  253.      * @ORM\ManyToMany(targetEntity=Property::class)
  254.      * @Groups({
  255.      *     "mandate:read","mandate:put"
  256.      * })
  257.      * @ApiSubresource()
  258.      */
  259.     private ?Collection $additionalProperties null;
  260.     /**
  261.      * @ORM\ManyToMany(targetEntity=Contact::class)
  262.      * @Groups({
  263.      *     "mandate:read","mandate:put"
  264.      * })
  265.      * @ApiSubresource()
  266.      */
  267.     private ?Collection $additionalContacts null;
  268.     /**
  269.      * @ORM\Column(type="boolean", nullable=true, options={"default"=false})
  270.      *
  271.      * @Groups({
  272.      *    "mandate:read"
  273.      * })
  274.      */
  275.     private ?bool $isAdditionalProperty false;
  276.     /**
  277.      * @ORM\Column(type="string", nullable=true)
  278.      * @Assert\NotBlank
  279.      * @Groups({
  280.      *    "mandate:read","mandate:put","mandate:write"
  281.      * })
  282.      */
  283.     private ?string $referenceVat null;
  284.     /**
  285.      * @ORM\Column(type="float", nullable=true)
  286.      * @Groups({"mandate:read","mandate:put","mandate:write",
  287.      *          "property:read","property:write","property:put"
  288.      * })
  289.      */
  290.     private $commissionRecommenderPercent;
  291.     /**
  292.      * @ORM\Column(type="string", nullable=true)
  293.      * @Groups({"mandate:read"})
  294.      */
  295.     private ?string $esign ;
  296.     public function __construct()
  297.     {
  298.         $this->propertyVisitVouchers = new ArrayCollection();
  299.         $this->transactions = new ArrayCollection();
  300.         $this->additionalProperties = new ArrayCollection();
  301.         $this->additionalContacts = new ArrayCollection();
  302.     }
  303.     public function getId(): ?int
  304.     {
  305.         return $this->id;
  306.     }
  307.     /**
  308.      * @return string|null
  309.      */
  310.     public function getEsign(): ?string
  311.     {
  312.         return $this->esign;
  313.     }
  314.     /**
  315.      * @param string|null $esign
  316.      */
  317.     public function setEsign(?string $esign): void
  318.     {
  319.         $this->esign $esign;
  320.     }
  321.     public function getMaximumPrice(): ?float
  322.     {
  323.         return $this->maximumPrice;
  324.     }
  325.     public function setMaximumPrice(?float $maximumPrice): self
  326.     {
  327.         $this->maximumPrice $maximumPrice;
  328.         return $this;
  329.     }
  330.     public function getMaximalArea(): ?float
  331.     {
  332.         return $this->maximalArea;
  333.     }
  334.     public function setMaximalArea(?float $maximalArea): self
  335.     {
  336.         $this->maximalArea $maximalArea;
  337.         return $this;
  338.     }
  339.     public function getMinimalArea(): ?float
  340.     {
  341.         return $this->minimalArea;
  342.     }
  343.     public function setMinimalArea(?float $minimalArea): self
  344.     {
  345.         $this->minimalArea $minimalArea;
  346.         return $this;
  347.     }
  348.     public function getReferenceMandateType(): ?ReferenceMandateType
  349.     {
  350.         return $this->referenceMandateType;
  351.     }
  352.     public function setReferenceMandateType(?ReferenceMandateType $referenceMandateType): self
  353.     {
  354.         $this->referenceMandateType $referenceMandateType;
  355.         return $this;
  356.     }
  357.     public function getProperty(): ?Property
  358.     {
  359.         return $this->property;
  360.     }
  361.     public function setProperty(?Property $property): self
  362.     {
  363.         $this->property $property;
  364.         return $this;
  365.     }
  366.     public function getReferenceMandateStatus(): ?ReferenceMandateStatus
  367.     {
  368.         return $this->referenceMandateStatus;
  369.     }
  370.     public function setReferenceMandateStatus(?ReferenceMandateStatus $referenceMandateStatus): self
  371.     {
  372.         $this->referenceMandateStatus $referenceMandateStatus;
  373.         return $this;
  374.     }
  375.     public function getReferencePropertyType(): ?ReferencePropertyType
  376.     {
  377.         return $this->referencePropertyType;
  378.     }
  379.     public function setReferencePropertyType(?ReferencePropertyType $referencePropertyType): self
  380.     {
  381.         $this->referencePropertyType $referencePropertyType;
  382.         return $this;
  383.     }
  384.     public function getKey(): ?string
  385.     {
  386.         return $this->key;
  387.     }
  388.     public function setKey(?string $key): self
  389.     {
  390.         $this->key $key;
  391.         return $this;
  392.     }
  393.     public function getCommission(): ?float
  394.     {
  395.         return $this->commission;
  396.     }
  397.     public function setCommission(?float $commission): self
  398.     {
  399.         $this->commission $commission;
  400.         return $this;
  401.     }
  402.     public function getIsFreeEntry(): ?bool
  403.     {
  404.         return $this->isFreeEntry;
  405.     }
  406.     public function setIsFreeEntry(?bool $isFreeEntry): self
  407.     {
  408.         $this->isFreeEntry $isFreeEntry;
  409.         return $this;
  410.     }
  411.     /**
  412.      * @return Collection<int, PropertyVisitVoucher>
  413.      */
  414.     public function getPropertyVisitVouchers(): Collection
  415.     {
  416.         return $this->propertyVisitVouchers;
  417.     }
  418.     public function addPropertyVisitVoucher(PropertyVisitVoucher $propertyVisitVoucher): self
  419.     {
  420.         if (!$this->propertyVisitVouchers->contains($propertyVisitVoucher)) {
  421.             $this->propertyVisitVouchers[] = $propertyVisitVoucher;
  422.         }
  423.         return $this;
  424.     }
  425.     public function removePropertyVisitVoucher(PropertyVisitVoucher $propertyVisitVoucher): self
  426.     {
  427.         $this->propertyVisitVouchers->removeElement($propertyVisitVoucher);
  428.         return $this;
  429.     }
  430.     /**
  431.      * @return Collection|Transaction[]
  432.      */
  433.     public function getTransactions(): Collection
  434.     {
  435.         return $this->transactions;
  436.     }
  437.     /**
  438.      * @param Transaction $transaction
  439.      *
  440.      * @return $this
  441.      */
  442.     public function addTransaction(Transaction $transaction): self
  443.     {
  444.         if (!$this->transactions->contains($transaction)) {
  445.             $this->transactions[] = $transaction;
  446.             $transaction->setMandate($this);
  447.         }
  448.         return $this;
  449.     }
  450.     /**
  451.      * @param Transaction $transaction
  452.      *
  453.      * @return $this
  454.      */
  455.     public function removeTransaction(Transaction $transaction): self
  456.     {
  457.         // set the owning side to null (unless already changed)
  458.         if ($this->transactions->removeElement($transaction) && $transaction->getMandate() === $this) {
  459.             $transaction->setMandate(null);
  460.         }
  461.         return $this;
  462.     }
  463.     /**
  464.      * check if agent has an already generated property visit
  465.      *
  466.      * @param int $agentId
  467.      *
  468.      * @return bool
  469.      */
  470.     public function agentHasAlreadyPropertyVisitGenerated(int $agentId): bool
  471.     {
  472.         foreach ($this->getPropertyVisitVouchers() as $visitVoucher) {
  473.             if ($visitVoucher->getCreatedBy() === $agentId) {
  474.                 return true;
  475.             }
  476.         }
  477.         return false;
  478.     }
  479.     /**
  480.      * Check if mandate had already a valid transaction
  481.      *
  482.      * @param int $agentId
  483.      *
  484.      * @return bool
  485.      */
  486.     public function hasValidTransaction(int $agentId): bool
  487.     {
  488.         return $this->transactions->filter(function (Transaction $transaction) use ($agentId) {
  489.                 return
  490.                     $transaction->getOutputAgent()->getId() === $agentId &&
  491.                     in_array(
  492.                         $transaction->getReferenceTransactionStatus()->getCode(),
  493.                         ReferenceTransactionStatus::ALL_TRANSACTION_VALID_CODE_STATUS,
  494.                         true
  495.                     );
  496.         })->count() > 0;
  497.     }
  498.     /**
  499.      * Check if agent can generate transaction for the current mandate
  500.      *
  501.      * @return bool
  502.      */
  503.     public function canGenerateTransaction(): bool
  504.     {
  505.         return $this->transactions->filter(function (Transaction $transaction) {
  506.                 return
  507.                     in_array(
  508.                         $transaction->getReferenceTransactionStatus()->getCode(),
  509.                         ReferenceTransactionStatus::ALL_TRANSACTION_RESERVED_CODE_STATUS,
  510.                         true
  511.                     );
  512.         })->count() <= &&
  513.             in_array($this->referenceMandateStatus->getCode(), [
  514.                 ReferenceMandateStatus::REFERENCE_CODE_MANDATE_STATUS_VALID,
  515.                 ReferenceMandateStatus::REFERENCE_CODE_MANDATE_STATUS_RESERVED,
  516.             ], true) &&
  517.             !$this->isBusinessIndicationMandate();
  518.     }
  519.     /**
  520.      * Check if the agent can generate visit voucher for the current mandate
  521.      *
  522.      * @return bool
  523.      */
  524.     public function canGenerateVisitVoucher(): bool
  525.     {
  526.         return ($this->transactions->filter(function (Transaction $transaction) {
  527.                     return
  528.                         in_array(
  529.                             $transaction->getReferenceTransactionStatus()->getCode(),
  530.                             ReferenceTransactionStatus::ALL_TRANSACTION_RESERVED_CODE_STATUS,
  531.                             true
  532.                         );
  533.         })->count() <= 0) &&
  534.             ($this->isValid() || $this->isReserved()) &&
  535.             (!in_array($this->property->getReferenceServiceType()->getCode(), [
  536.                 ReferencePropertyServiceType::REFERENCE_CODE_PROPERTY_SERVICE_TYPE_SEARCH_BUY,
  537.                 ReferencePropertyServiceType::REFERENCE_CODE_PROPERTY_SERVICE_TYPE_SEARCH_RENT
  538.             ]));
  539.     }
  540.     /**
  541.      * check if the mandate has valid status
  542.      *
  543.      * @return bool
  544.      */
  545.     public function isValid(): bool
  546.     {
  547.         return $this->getReferenceMandateStatus()->getCode() ===
  548.             ReferenceMandateStatus::REFERENCE_CODE_MANDATE_STATUS_VALID;
  549.     }
  550.     /**
  551.      * check if the mandate has reserved status
  552.      *
  553.      * @return bool
  554.      */
  555.     public function isReserved(): bool
  556.     {
  557.         return $this->getReferenceMandateStatus()->getCode() ===
  558.             ReferenceMandateStatus::REFERENCE_CODE_MANDATE_STATUS_RESERVED;
  559.     }
  560.     public function getCommissionPercent(): ?float
  561.     {
  562.         return $this->commissionPercent;
  563.     }
  564.     public function setCommissionPercent(?float $commissionPercent): self
  565.     {
  566.         $this->commissionPercent $commissionPercent;
  567.         return $this;
  568.     }
  569.     public function getDuration(): ?int
  570.     {
  571.         return $this->duration;
  572.     }
  573.     public function setDuration(int $duration): self
  574.     {
  575.         if (!in_array($durationself::ALL_VALIDATION_PERIODtrue)) {
  576.             throw new \InvalidArgumentException("Invalid  period  for mandate");
  577.         }
  578.         $this->duration $duration;
  579.         return $this;
  580.     }
  581.     public function getExclusiveDuration(): ?int
  582.     {
  583.         return $this->exclusiveDuration;
  584.     }
  585.     public function setExclusiveDuration(int $exclusiveDuration): self
  586.     {
  587.         if (!in_array($exclusiveDurationself::ALL_AFTER_VALIDATION_PERIODtrue)) {
  588.             throw new \InvalidArgumentException("Invalid exclusive duration for mandate");
  589.         }
  590.         $this->exclusiveDuration $exclusiveDuration;
  591.         return $this;
  592.     }
  593.     /**
  594.      * @return Collection<int, Property>
  595.      */
  596.     public function getAdditionalProperties(): Collection
  597.     {
  598.         return $this->additionalProperties;
  599.     }
  600.     public function addAdditionalProperty(Property $additionalProperty): self
  601.     {
  602.         if (!$this->additionalProperties->contains($additionalProperty)) {
  603.             $this->additionalProperties[] = $additionalProperty;
  604.         }
  605.         return $this;
  606.     }
  607.     public function removeAdditionalProperty(Property $additionalProperty): self
  608.     {
  609.         $this->additionalProperties->removeElement($additionalProperty);
  610.         return $this;
  611.     }
  612.     public function getAdditionalContacts(): Collection
  613.     {
  614.         return $this->additionalContacts;
  615.     }
  616.     public function addAdditionalContact(Contact $additionalContact): self
  617.     {
  618.         if (!$this->additionalContacts->contains($additionalContact)) {
  619.             $this->additionalContacts[] = $additionalContact;
  620.         }
  621.         return $this;
  622.     }
  623.     public function removeAdditionalContact(Contact $additionalContact): self
  624.     {
  625.         $this->additionalContacts->removeElement($additionalContact);
  626.         return $this;
  627.     }
  628.     /**
  629.      * @return bool|null
  630.      */
  631.     public function getIsAdditionalProperty(): ?bool
  632.     {
  633.         return $this->isAdditionalProperty;
  634.     }
  635.     /**
  636.      * @param bool $isAdditionalProperty
  637.      *
  638.      * @return $this
  639.      */
  640.     public function setIsAdditionalProperty(bool $isAdditionalProperty): self
  641.     {
  642.         $this->isAdditionalProperty $isAdditionalProperty;
  643.         return $this;
  644.     }
  645.     public function isInvalid(): bool
  646.     {
  647.         return in_array(
  648.             $this->getReferenceMandateStatus()->getCode(),
  649.             self::REFERENCE_MANDATE_STATUS_CODE_INVALID,
  650.             true
  651.         );
  652.     }
  653.     /**
  654.      * check if the mandate is inProgress
  655.      *
  656.      * @return bool
  657.      */
  658.     public function isInProgress(): bool
  659.     {
  660.         if (null === $status $this->getReferenceMandateStatus()) {
  661.             return false;
  662.         }
  663.         return $status->isInProgress();
  664.     }
  665.     /**
  666.      * check if we can display the action "% share" or not
  667.      *
  668.      * @return bool
  669.      */
  670.     public function canShareCommission(): bool
  671.     {
  672.         return $this->getReferenceMandateStatus()->getCode() ===
  673.             ReferenceMandateStatus::REFERENCE_CODE_MANDATE_STATUS_IN_PROGRESS;
  674.     }
  675.     /**
  676.      * @return bool
  677.      */
  678.     public function isBusinessIndicationMandate(): bool
  679.     {
  680.         $contact $this->property->getContact();
  681.         return $contact->getIsBusinessIndication()
  682.             && $contact->isCompany()
  683.             && $this->property->isNew()
  684.             && $this->property->isSale();
  685.     }
  686.     public function getReferenceVat(): ?string
  687.     {
  688.         return $this->referenceVat;
  689.     }
  690.     /**
  691.      * @param string $referenceVat
  692.      * @return $this
  693.      */
  694.     public function setReferenceVat(string $referenceVat): self
  695.     {
  696.         $this->referenceVat $referenceVat;
  697.         return $this;
  698.     }
  699.     /**
  700.      * @throws Exception
  701.      */
  702.     public function calculateCommission(): void
  703.     {
  704.         $property $this->getProperty();
  705.         if ($this->getIsFreeEntry()) {
  706.             return;
  707.         }
  708.         $commissionPercent $this->getCommissionPercent();
  709.         $price $property->getPrice();
  710.         if ($this->getReferenceVat() === VatReference::REFERENCE_CODE_VAT_TAXINCLUDED) {
  711.             $price *= VatReference::VAT_RATE;
  712.         }
  713.         if ($property->isRent() && $commissionPercent 100) {
  714.             throw new Exception("Merci de saisir un pourcentage inférieur à 100");
  715.         }
  716.         $commission $price * ($commissionPercent 100);
  717.         $this->setCommission($commission);
  718.     }
  719.     /**
  720.      * @return array
  721.      */
  722.     public function getFields(): array
  723.     {
  724.         return [
  725.             'referenceMandateStatus' => 'referenceMandateStatus',
  726.             'commission' => 'commission',
  727.             'commissionPercent' => 'commissionPercent',
  728.             'isFreeEntry' => 'isFreeEntry',
  729.             'additionalProperties' => 'additionalProperties'
  730.         ];
  731.     }
  732.     public static function isOwner(Mandate $mandateAbstractCollaborator $currentUser): bool
  733.     {
  734.         $property $mandate->getProperty();
  735.         $collaborator $property->getCollaborator();
  736.         return $collaborator->getId() === $currentUser->getId();
  737.     }
  738.     public function getCommissionRecommenderPercent(): ?float
  739.     {
  740.         return $this->commissionRecommenderPercent ?? 12;
  741.     }
  742.     public function setCommissionRecommenderPercent(?float $commissionRecommenderPercent): self
  743.     {
  744.         $this->commissionRecommenderPercent $commissionRecommenderPercent;
  745.         return $this;
  746.     }
  747.     /**
  748.      * check if we can display the action "% share" or not
  749.      *
  750.      * @return bool
  751.      */
  752.     public function canUpdateMandate(): bool
  753.     {
  754.         return $this->getReferenceMandateStatus()->getCode() ===
  755.             ReferenceMandateStatus::REFERENCE_CODE_MANDATE_STATUS_IN_PROGRESS;
  756.     }
  757.     /**
  758.      *
  759.      * @return bool
  760.      */
  761.     public function canShowESignature(): bool
  762.     {
  763.         return $this->getEsign() == null  &&   $this->getReferenceMandateStatus()->getCode() === ReferenceMandateStatus::REFERENCE_CODE_MANDATE_STATUS_IN_PROGRESS;
  764.     }
  765. }