src/Entity/Participation/Refund.php line 72

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Participation;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Controller\Api\Participation\Refund\GetParticipationRefundsByUser;
  5. use App\Controller\Api\Participation\Refund\RefundPurseExpiringByUser;
  6. use App\Entity\Purse\ItemStep as Item;
  7. use App\Repository\Participation\RefundRepository;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use JMS\Serializer\Annotation as Serializer;
  12. use JMS\Serializer\Annotation\ExclusionPolicy;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Serializer\Annotation\SerializedName;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. /**
  17.  * @ORM\Entity(repositoryClass=RefundRepository::class)
  18.  * @ExclusionPolicy("all")
  19.  * @ApiResource(
  20.  *     messenger=true,
  21.  *     shortName="participation-refund",
  22.  *     attributes={
  23.  *          "normalization_context"={
  24.  *              "groups"={
  25.  *                  "ParticipationRefund:output",
  26.  *                  "ParticipationRefund:io",
  27.  *               }
  28.  *          },
  29.  *          "denormalization_context"={
  30.  *              "groups"={
  31.  *                  "ParticipationRefund:input",
  32.  *                  "ParticipationRefund:io",
  33.  *              }
  34.  *          }
  35.  *      },
  36.  *     collectionOperations={
  37.  *          "post"={
  38.  *              "method"="POST",
  39.  *              "access_control"="is_granted('ROLE_USER')"
  40.  *          },
  41.  *          "get"={
  42.  *              "method"="GET",
  43.  *              "access_control"="is_granted('ROLE_USER')",
  44.  *          },
  45.  *          "get-by-user"={
  46.  *              "method"="GET",
  47.  *              "path"="/participation-refunds/user",
  48.  *              "access_control"="is_granted('ROLE_USER')",
  49.  *              "validation_groups"={"get_participation-refunds_by_user"},
  50.  *              "controller"=GetParticipationRefundsByUser::class,
  51.  *              "defaults"={"_api_receive"=false},
  52.  *          },
  53.  *          "refund-purse-expiring-post"={
  54.  *              "method"="POST",
  55.  *              "path"="/participation-refunds/purse-expiring",
  56.  *              "access_control"="is_granted('ROLE_USER')",
  57.  *              "controller"=RefundPurseExpiringByUser::class,
  58.  *              "defaults"={"_api_receive"=false},
  59.  *          },
  60.  *     },
  61.  *     itemOperations={
  62.  *          "get"={
  63.  *              "method"="GET",
  64.  *              "access_control"="is_granted('ROLE_USER')",
  65.  *          },
  66.  *     },
  67.  * )
  68.  */
  69. class Refund extends Participation
  70. {
  71.     /**
  72.      * @ORM\Column(name="amount", type="float")
  73.      * @SerializedName("amount")
  74.      * @Groups({
  75.      *     "ParticipationRefund:output"
  76.      * })
  77.      * @Assert\NotBlank(groups={"refund_process"})
  78.      * @Assert\Positive(groups={"refund_process"})
  79.      * @Assert\GreaterThan(value="0", groups={"refund_process"})
  80.      * @Assert\LessThanOrEqual(value="200", groups={"refund_process"})
  81.      */
  82.     private ?float $amount null;
  83.     /**
  84.      * @var string
  85.      * @ORM\Column(type="string")
  86.      * @Groups({
  87.      *     "ParticipationRefund:io"
  88.      * })
  89.      * @Assert\NotBlank()
  90.      *
  91.      * @Serializer\Expose()
  92.      * @Serializer\Groups({"shannon_refund"})
  93.      */
  94.     private $iban;
  95.     /**
  96.      * @var string
  97.      * @ORM\Column(type="string")
  98.      * @Groups({
  99.      *     "ParticipationRefund:io"
  100.      * })
  101.      * @Assert\NotBlank()
  102.      * @Assert\Bic()
  103.      *
  104.      * @Serializer\Expose()
  105.      * @Serializer\Groups({"shannon_refund"})
  106.      */
  107.     private $bic;
  108.     /**
  109.      * @ORM\OneToMany(targetEntity=Item::class, mappedBy="refund")
  110.      */
  111.     private $items;
  112.     public function __construct()
  113.     {
  114.         parent::__construct();
  115.         $this->items = new ArrayCollection();
  116.     }
  117.     /**
  118.      * @return float|null
  119.      */
  120.     public function getAmount() : ?float
  121.     {
  122.         return $this->amount;
  123.     }
  124.     /**
  125.      * @param float|null $amount
  126.      *
  127.      * @return Refund
  128.      */
  129.     public function setAmount(?float $amount) : Refund
  130.     {
  131.         $this->amount $amount;
  132.         return $this;
  133.     }
  134.     /**
  135.      * @return string
  136.      */
  137.     public function getIban(): string
  138.     {
  139.         return $this->iban;
  140.     }
  141.     /**
  142.      * @param string $iban
  143.      * @return Refund
  144.      */
  145.     public function setIban(string $iban): Refund
  146.     {
  147.         $this->iban $iban;
  148.         return $this;
  149.     }
  150.     /**
  151.      * @return string
  152.      */
  153.     public function getBic(): string
  154.     {
  155.         return $this->bic;
  156.     }
  157.     /**
  158.      * @param string $bic
  159.      * @return Refund
  160.      */
  161.     public function setBic(string $bic): Refund
  162.     {
  163.         $this->bic $bic;
  164.         return $this;
  165.     }
  166.     /**
  167.      * @return Collection|Item[]
  168.      */
  169.     public function getItems(): Collection
  170.     {
  171.         return $this->items;
  172.     }
  173.     public function addItem(Item $item): self
  174.     {
  175.         if (!$this->items->contains($item)) {
  176.             $this->items[] = $item;
  177.             $item->setRefund($this);
  178.         }
  179.         return $this;
  180.     }
  181.     public function removeItem(Item $item): self
  182.     {
  183.         if ($this->items->removeElement($item)) {
  184.             // set the owning side to null (unless already changed)
  185.             if ($item->getRefund() === $this) {
  186.                 $item->setRefund(null);
  187.             }
  188.         }
  189.         return $this;
  190.     }
  191.     /**
  192.      * @Serializer\VirtualProperty
  193.      * @Serializer\Groups({"shannon"})
  194.      * @Serializer\SerializedName("participation_id")
  195.      * @return string
  196.      */
  197.     public function getParticipationId(): string
  198.     {
  199.         return $this->id;
  200.     }
  201.     /**
  202.      * Get opt-in RGPD.
  203.      *
  204.      * @Serializer\VirtualProperty
  205.      * @Serializer\Groups({"shannon"})
  206.      * @Serializer\SerializedName("optin_rgpd")
  207.      * @return int
  208.      */
  209.     public function intOptInRGPD(): int
  210.     {
  211.         return true;
  212.     }
  213.     /**
  214.      * @Serializer\VirtualProperty
  215.      * @Serializer\Groups({"shannon"})
  216.      * @Serializer\SerializedName("action")
  217.      * @return string
  218.      */
  219.     public function getAction(): string
  220.     {
  221.         return 'create';
  222.     }
  223.     /**
  224.      * @Serializer\VirtualProperty
  225.      * @Serializer\Groups({"shannon"})
  226.      * @Serializer\SerializedName("channel")
  227.      * @return string
  228.      */
  229.     public function getChannel(): string
  230.     {
  231.         return 'FI';
  232.     }
  233.     /**
  234.      * @Serializer\VirtualProperty
  235.      * @Serializer\Groups({"shannon"})
  236.      * @Serializer\SerializedName("date_participation")
  237.      * @return string
  238.      */
  239.     public function getDateParticipation(): string
  240.     {
  241.         return $this->getCreatedAt()->format('Y-m-d H:i:s');
  242.     }
  243.     public function getApiCode(): ?string
  244.     {
  245.         return $this->getValidationExport() instanceof ValidationExport $this->getValidationExport()->getAPIParticpationId() : null;
  246.     }
  247. }