src/Entity/Participation/Odr.php line 116

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Participation;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Controller\Api\Participation\Odr\GetParticipationOdrsByUser;
  5. use App\Controller\Api\Participation\Odr\GetParticipationOdrsByUserByOperation;
  6. use App\Controller\Api\Participation\Odr\GetParticipationOdrsById;
  7. use App\Controller\Api\Participation\Odr\GetReParticipationOdrsById;
  8. use App\Controller\Api\Participation\Odr\CreateParticipationOdrByUser;
  9. use App\Controller\Api\Participation\Odr\ConfirmationParticipationOdrByUser;
  10. use App\Controller\Api\Participation\Odr\GetNbParticipationByOperationOdrId;
  11. use App\Entity\Details\Participation\DetailsParticipationOdr;
  12. use App\Entity\Ean\Participation\EanParticipation;
  13. use App\Entity\Ean\Participation\EanOdr;
  14. use App\Repository\Participation\OdrRepository;
  15. use App\Entity\OperationCode\OdrCode;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\ORM\Mapping as ORM;
  19. use JMS\Serializer\Annotation as Serializer;
  20. use JMS\Serializer\Annotation\ExclusionPolicy;
  21. use Symfony\Component\Serializer\Annotation\Groups;
  22. use Symfony\Component\Serializer\Annotation\SerializedName;
  23. use Symfony\Component\Validator\Constraints as Assert;
  24. /**
  25.  * @ORM\Entity(repositoryClass=OdrRepository::class)
  26.  * @ExclusionPolicy("all")
  27.  * @ApiResource(
  28.  *     messenger=true,
  29.  *     shortName="participation-odr",
  30.  *     attributes={
  31.  *          "force_eager"=false,
  32.  *          "normalization_context"={
  33.  *              "groups"={
  34.  *                  "ParticipationOdr:output",
  35.  *                  "ParticipationOdr:io",
  36.  *                  "get_participation_odrs_by_user",
  37.  *                  "get_participation_odrs_by_id",
  38.  *               },
  39.  *              "enable_max_depth"=true
  40.  *          },
  41.  *          "denormalization_context"={
  42.  *              "groups"={
  43.  *                  "ParticipationOdr:input",
  44.  *                  "ParticipationOdr:io",
  45.  *              },
  46.  *              "enable_max_depth"=true
  47.  *          }
  48.  *      },
  49.  *     collectionOperations={
  50.  *          "get",
  51.  *          "post",
  52.  *          "get-by-user"={
  53.  *              "method"="GET",
  54.  *              "path"="/participation-odrs/user",
  55.  *              "access_control"="is_granted('ROLE_USER')",
  56.  *              "validation_groups"={"get_participation_odrs_by_user"},
  57.  *              "controller"=GetParticipationOdrsByUser::class,
  58.  *              "defaults"={"_api_receive"=false},
  59.  *          },
  60.  *          "get-by-user-by-operation"={
  61.  *              "method"="GET",
  62.  *              "path"="/participation-odrs/user/operation/{operationId}",
  63.  *              "access_control"="is_granted('ROLE_USER')",
  64.  *              "validation_groups"={"get_participation_odrs_by_user"},
  65.  *              "controller"=GetParticipationOdrsByUserByOperation::class,
  66.  *              "defaults"={"_api_receive"=false},
  67.  *          },
  68.  *          "create-participation-odr-post"={
  69.  *              "method"="POST",
  70.  *              "path"="/participation-odrs/create-participation",
  71.  *              "access_control"="is_granted('ROLE_USER')",
  72.  *              "controller"=CreateParticipationOdrByUser::class,
  73.  *              "defaults"={"_api_receive"=false},
  74.  *          },
  75.  *          "confirmation-participation-odr-post"={
  76.  *              "method"="POST",
  77.  *              "path"="/participation-odrs/smp/{participationId}/{userId}",
  78.  *              "access_control"="is_granted('ROLE_USER')",
  79.  *              "controller"=ConfirmationParticipationOdrByUser::class,
  80.  *              "defaults"={"_api_receive"=false},
  81.  *          },
  82.  *     },
  83.  *     itemOperations={
  84.  *          "get"={
  85.  *              "method"="GET",
  86.  *              "path"="/participation-odrs/{id}",
  87.  *              "access_control"="is_granted('ROLE_USER')",
  88.  *              "validation_groups"={"get_participation_odrs_by_id"},
  89.  *              "controller"=GetParticipationOdrsById::class,
  90.  *              "defaults"={"_api_receive"=false},
  91.  *          },
  92.  *          "get-reparticipation"={
  93.  *              "method"="GET",
  94.  *              "path"="/participation-odrs/reparticipation/{id}",
  95.  *              "access_control"="is_granted('ROLE_USER')",
  96.  *              "validation_groups"={"get_reparticipation_odrs_by_id"},
  97.  *              "controller"=GetReParticipationOdrsById::class,
  98.  *              "defaults"={"_api_receive"=false},
  99.  *          },
  100.  *          "put"={
  101.  *              "validation_groups"={"Default", "Edit"}
  102.  *          },
  103.  *          "public-get-nbr-participation-odr"={
  104.  *               "method"="GET",
  105.  *               "access_control"="is_granted('ROLE_PUBLIC')",
  106.  *               "path"="/public/get-nb-participation-odr/{id}",
  107.  *               "controller"=GetNbParticipationByOperationOdrId::class,
  108.  *               "defaults"={"_api_receive"=false},
  109.  *          }
  110.  *     },
  111.  * )
  112.  */
  113. class Odr extends Participation
  114. {
  115.     const CHANNEL_CASH_BACK "cash-back";
  116.     const PAYMENT_TYPE_IBAN "transfer";
  117.     const PAYMENT_TYPE_PAYPAL "paypal";
  118.     /**
  119.      * @ORM\OneToMany(targetEntity=OdrCode::class, mappedBy="participation")
  120.      * @SerializedName("operation_codes")
  121.      * @Groups({
  122.      *     "OdrCode:output",
  123.      * })
  124.      */
  125.     protected Collection $operationCodes;
  126.     /**
  127.      * @ORM\Column(name="code", type="string", nullable=true)
  128.      * @SerializedName("code")
  129.      * @Groups({
  130.      *     "ParticipationOdr:io",
  131.      *     "get_odrs_by_user_department",
  132.      *     "get_participation_odrs_by_user",
  133.      *     "get_participation_odrs_by_id",
  134.      *     "get_reparticipation_odrs_by_id",
  135.      * })
  136.      */
  137.     private ?string $code null;
  138.     /**
  139.      * @var Collection<EanParticipation>|EanParticipation[]
  140.      * @ORM\OneToMany(targetEntity=EanOdr::class, mappedBy="participation")
  141.      * @SerializedName("ean_odrs")
  142.      * @Groups({
  143.      *     "ParticipationOdr:io",
  144.      *     "get_odrs_by_user_department",
  145.      *     "get_participation_odrs_by_user",
  146.      *     "get_participation_odrs_by_id",
  147.      *     "get_reparticipation_odrs_by_id",
  148.      * })
  149.      */
  150.     private $eanParticipations;
  151.     /**
  152.      * @ORM\Column(name="amount", type="float")
  153.      * @SerializedName("amount")
  154.      * @Groups({
  155.      *     "ParticipationOdr:io",
  156.      *     "get_odrs_by_user_department",
  157.      *     "get_participation_odrs_by_user",
  158.      *     "get_participation_odrs_by_id",
  159.      *     "get_reparticipation_odrs_by_id",
  160.      * })
  161.      */
  162.     private ?float $amount null;
  163.     /**
  164.      * @ORM\Column(type="string", nullable=true)
  165.      * @SerializedName("date_of_purchase")
  166.      * @Groups({
  167.      *     "ParticipationOdr:io",
  168.      *     "get_odrs_by_user_department",
  169.      *     "get_participation_odrs_by_user",
  170.      *     "get_participation_odrs_by_id",
  171.      *     "get_reparticipation_odrs_by_id",
  172.      * })
  173.      */
  174.     private ?string $dateOfPurchase null;
  175.     /**
  176.      * @ORM\OneToOne(targetEntity=DetailsParticipationOdr::class, mappedBy="participation", cascade={"persist", "remove"})
  177.      * @SerializedName("details_participation_odr")
  178.      * @Groups({
  179.      *     "ParticipationOdr:io",
  180.      *     "get_odrs_by_user_department",
  181.      *     "get_participation_odrs_by_user",
  182.      *     "get_participation_odrs_by_id",
  183.      *     "get_reparticipation_odrs_by_id",
  184.      * })
  185.      */
  186.     private ?DetailsParticipationOdr $details null;
  187.     /**
  188.      * @var string|null
  189.      * @ORM\Column(type="string", nullable=true)
  190.      * @SerializedName("iban")
  191.      * @Groups({
  192.      *     "ParticipationOdr:io",
  193.      *     "get_odrs_by_user_department",
  194.      *     "get_participation_odrs_by_user",
  195.      *     "get_participation_odrs_by_id",
  196.      *     "get_reparticipation_odrs_by_id",
  197.      * })
  198.      */
  199.     private ?string $iban null;
  200.     /**
  201.      * @var string|null
  202.      * @ORM\Column(type="string", nullable=true)
  203.      * @SerializedName("bic")
  204.      * @Groups({
  205.      *     "ParticipationOdr:io",
  206.      *     "get_odrs_by_user_department",
  207.      *     "get_participation_odrs_by_user",
  208.      *     "get_participation_odrs_by_id",
  209.      *     "get_reparticipation_odrs_by_id",
  210.      * })
  211.      * @Assert\Bic()
  212.      */
  213.     private ?string $bic null;
  214.     /**
  215.      * @ORM\Column(type="string", length=180, nullable=true)
  216.      * @SerializedName("paypal")
  217.      * @Groups({
  218.      *     "ParticipationOdr:io",
  219.      *     "get_participation_odrs_by_user",
  220.      *     "get_participation_odrs_by_id",
  221.      *     "get_reparticipation_odrs_by_id",
  222.      * })
  223.      */
  224.     private ?string $paypal null;
  225.     /**
  226.      * @return string|null
  227.      */
  228.     public function getPaypal(): ?string
  229.     {
  230.         return $this->paypal;
  231.     }
  232.     /**
  233.      * @param string|null $paypal
  234.      * @return Odr
  235.      */
  236.     public function setPaypal(?string $paypal): Odr
  237.     {
  238.         $this->paypal $paypal;
  239.         return $this;
  240.     }
  241.     /**
  242.      * @var string|null
  243.      * @ORM\Column(type="string", nullable=true)
  244.      * @SerializedName("id_billy")
  245.      * @Groups({
  246.      *     "ParticipationOdr:io",
  247.      *     "get_odrs_by_user_department",
  248.      *     "get_participation_odrs_by_user",
  249.      *     "get_participation_odrs_by_id",
  250.      *     "get_reparticipation_odrs_by_id",
  251.      * })
  252.      */
  253.     private ?string $idBilly null;
  254.     /**
  255.      * @ORM\Column(type="boolean", options={"default": 0})
  256.      */
  257.     private bool $mailSuccess false;
  258.     public function __construct()
  259.     {
  260.         parent::__construct();
  261.         $this->eanParticipations = new ArrayCollection();
  262.         $this->operationCodes = new ArrayCollection();
  263.     }
  264.     public function getCode(): ?string
  265.     {
  266.         return $this->code;
  267.     }
  268.     public function setCode(?string $code)
  269.     {
  270.         $this->code $code;
  271.         return $this;
  272.     }
  273.     /**
  274.      * @param array $filter
  275.      * @return int
  276.      */
  277.     public function getEanParticipationsQuantityByStatus(array $filter = []): int
  278.     {
  279.         $eanParts $this->eanParticipations ?? [];
  280.         if (!$eanParts instanceof Collection) {
  281.             $eanParts = new ArrayCollection($eanParts);
  282.         }
  283.         if (!empty($filter))
  284.         {
  285.             $eanParts =  $eanParts->filter(function(EanParticipation $eanParticipation) use ($filter)
  286.             {
  287.                 return in_array($eanParticipation->getBarcodeStatus(), $filter);
  288.             });
  289.         }
  290.         $quantity 0;
  291.         foreach ($eanParts as $eanParticipation) {
  292.             $quantity += ((int)$eanParticipation->getQuantity() * (int)$eanParticipation->getEan()->getQuantity());
  293.         }
  294.         return $quantity;
  295.     }
  296.     /**
  297.      * @return Collection|EanOdr[]
  298.      */
  299.     public function getEanParticipations(): ?Collection
  300.     {
  301.         return $this->eanParticipations;
  302.     }
  303.     public function addEanParticipations(EanOdr $eanOdr): self
  304.     {
  305.         if (!$this->eanParticipations->contains($eanOdr)) {
  306.             $this->eanParticipations[] = $eanOdr;
  307.             $eanOdr->setParticipation($this);
  308.         }
  309.         return $this;
  310.     }
  311.     public function removeEanParticipations(EanOdr $eanOdr): self
  312.     {
  313.         if ($this->eanParticipations->removeElement($eanOdr)) {
  314.             // set the owning side to null (unless already changed)
  315.             if ($eanOdr->getParticipation() === $this) {
  316.                 $eanOdr->setParticipation(null);
  317.             }
  318.         }
  319.         return $this;
  320.     }
  321.     public function getDetails(): ?DetailsParticipationOdr
  322.     {
  323.         return $this->details;
  324.     }
  325.     public function setDetails(?DetailsParticipationOdr $details): self
  326.     {
  327.         $this->details $details;
  328.         return $this;
  329.     }
  330.     /**
  331.      * @return float|null
  332.      */
  333.     public function getAmount() : ?float
  334.     {
  335.         return $this->amount;
  336.     }
  337.     /**
  338.      * @param float|null $amount
  339.      *
  340.      * @return Odr
  341.      */
  342.     public function setAmount(?float $amount) : Odr
  343.     {
  344.         $this->amount $amount;
  345.         return $this;
  346.     }
  347.     /**
  348.      * @return string
  349.      */
  350.     public function getIban(): ?string
  351.     {
  352.         return $this->iban;
  353.     }
  354.     /**
  355.      * @param string|null $iban
  356.      * @return Odr
  357.      */
  358.     public function setIban(?string $iban): Odr
  359.     {
  360.         $this->iban $iban;
  361.         return $this;
  362.     }
  363.     /**
  364.      * @return string
  365.      */
  366.     public function getBic(): ?string
  367.     {
  368.         return $this->bic;
  369.     }
  370.     /**
  371.      * @param string|null $bic
  372.      * @return Odr
  373.      */
  374.     public function setBic(?string $bic): Odr
  375.     {
  376.         $this->bic $bic;
  377.         return $this;
  378.     }
  379.     /**
  380.      * @return string
  381.      */
  382.     public function getIdBilly(): ?string
  383.     {
  384.         return $this->idBilly;
  385.     }
  386.     /**
  387.      * @param string|null $idBilly
  388.      * @return Odr
  389.      */
  390.     public function setIdBilly(?string $idBilly): Odr
  391.     {
  392.         $this->idBilly $idBilly;
  393.         return $this;
  394.     }
  395.     public function getApiCode(): ?string
  396.     {
  397.         return $this->getValidationExport() instanceof ValidationExport $this->getValidationExport()->getAPIParticpationId() : null;
  398.     }
  399.     public function getMailSuccess(): bool
  400.     {
  401.         return (bool) $this->mailSuccess;
  402.     }
  403.     public function setMailSuccess(bool $mailSuccess): self
  404.     {
  405.         $this->mailSuccess $mailSuccess;
  406.         return $this;
  407.     }
  408.     public function getDateOfPurchase(): ?string
  409.     {
  410.         return $this->dateOfPurchase;
  411.     }
  412.     public function setDateOfPurchase(?string $dateOfPurchase): self
  413.     {
  414.         $this->dateOfPurchase $dateOfPurchase;
  415.         return $this;
  416.     }
  417.     public function getOperationCodes(): Collection
  418.     {
  419.         return $this->operationCodes;
  420.     }
  421.     public function addOperationCode(OdrCode $operationCode): self
  422.     {
  423.         if (!$this->operationCodes->contains($operationCode)) {
  424.             $this->operationCodes[] = $operationCode;
  425.         }
  426.         return $this;
  427.     }
  428.     public function removeOperationCode(OdrCode $operationCode): self
  429.     {
  430.         $this->operationCodes->removeElement($operationCode);
  431.         return $this;
  432.     }
  433. }