src/Entity/Demand.php line 92

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use ApiPlatform\Core\Annotation\ApiFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. // use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  9. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  11. use App\Trait\TimestampableEntity;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Serializer\Annotation\MaxDepth;
  18. #[ORM\Entity]
  19. #[ApiResource(
  20.     iri'Demand',
  21.     itemOperations: [
  22.         'get' => [
  23.             // 'security' => "is_granted('ROLE_USER')",
  24.             'normalization_context' => [
  25.                 'groups' => 'demand:item:get',
  26.                 'enable_max_depth' => true
  27.             ]
  28.         ],
  29.         'put' => [
  30.             // 'security' => "is_granted('ROLE_USER')",
  31.             'normalization_context' => [
  32.                 'groups' => 'demand:item:put',
  33.                 'enable_max_depth' => true
  34.             ],
  35.             'denormalization_context' => [
  36.                 'groups' => 'demand:item:put',
  37.                 'enable_max_depth' => true
  38.             ]
  39.         ],
  40.         'delete' => [
  41.             // 'security' => "is_granted('ROLE_USER')",
  42.         ]
  43.     ],
  44.     collectionOperations: [
  45.         'get' => [
  46.             // 'security' => "is_granted('ROLE_USER')",
  47.             'normalization_context' => [
  48.                 'groups' => ['demand:collection:get''endTime'],
  49.                 'enable_max_depth' => true
  50.             ]
  51.         ],
  52.         'post' => [
  53.             // 'security' => "is_granted('ROLE_USER')",
  54.             'normalization_context' => [
  55.                 'groups' => 'demand:collection:post',
  56.                 'enable_max_depth' => true
  57.             ],
  58.             'denormalization_context' => [
  59.                 'groups' => 'demand:collection:post',
  60.                 'enable_max_depth' => true
  61.             ]
  62.         ],
  63.     ]
  64. )]
  65. #[ApiFilter(SearchFilter::class, properties: [
  66.     'insured' => 'exact',
  67.     'status' => 'exact',
  68.     'insured.name' => 'partial',
  69.     'insured.taxID' => 'start',
  70.     'processNumber' => 'start',
  71.     'limitValue' => 'start',
  72.     'policy.eligibleQuantity' => 'start',
  73.     'endTime' => 'start',
  74. ])]
  75. // #[ApiFilter(DateFilter::class, properties: ['createdAt'])]
  76. #[ApiFilter(ExistsFilter::class, properties: ['policy'])]
  77. #[ApiFilter(OrderFilter::class, properties: [
  78.     'processNumber'
  79.     'status'
  80.     'endTime'
  81.     'insured.name'
  82.     'limitValue',
  83.     'policy.eligibleQuantity',
  84.     'insured.taxID',
  85.     'comissionRate',
  86.     'insurancePremium',
  87.     'prize',
  88. ])]
  89. class Demand
  90. {
  91.     use TimestampableEntity;
  92.     
  93.     #[ORM\Id]
  94.     #[ORM\GeneratedValue(strategy'AUTO')]
  95.     #[ORM\Column(type'integer')]
  96.     #[Groups([
  97.         'demand:collection:get',
  98.         'demand:item:get',
  99.     ])]
  100.     private ?int $id null;
  101.     #[ORM\Column(type'string')]
  102.     #[ApiProperty(iri'https://schema.org/Number')]
  103.     #[Assert\Type('string')]
  104.     #[Groups([
  105.         'import:demand',
  106.         'demand:collection:get',
  107.         'demand:collection:post',
  108.         'demand:item:get',
  109.         'demand:item:put',
  110.         'policy:item:get',
  111.     ])]
  112.     private ?string $processNumber null;
  113.     /**
  114.      * The name of the item.
  115.      *
  116.      * @see https://schema.org/name
  117.      */
  118.     #[ORM\Column(type'string'nullabletrue)]
  119.     #[ApiProperty(iri'https://schema.org/name')]
  120.     #[Assert\Type('string')]
  121.     #[Groups([
  122.         'import:demand',
  123.         'demand:collection:get',
  124.         'demand:collection:post',
  125.         'demand:item:get',
  126.         'demand:item:put',
  127.     ])]
  128.     private ?string $holderName null;
  129.     #[ORM\Column(type'string')]
  130.     #[ApiProperty()]
  131.     #[Assert\Type('string')]
  132.     #[Groups([
  133.         'import:demand',
  134.         'demand:collection:post',
  135.         'demand:item:get',
  136.         'demand:item:put',
  137.     ])]
  138.     private ?string $holderZipcode null;
  139.     #[ORM\Column(type'string'nullabletrue)]
  140.     #[ApiProperty()]
  141.     #[Assert\Type('string')]
  142.     #[Groups([
  143.         'import:demand',
  144.         'demand:collection:post',
  145.         'demand:item:get',
  146.         'demand:item:put',
  147.     ])]
  148.     private ?string $holderAddress null;
  149.     #[ORM\Column(type'string'nullabletrue)]
  150.     #[ApiProperty()]
  151.     #[Assert\Type('string')]
  152.     #[Groups([
  153.         'import:demand',
  154.         'demand:collection:post',
  155.         'demand:item:get',
  156.         'demand:item:put',
  157.     ])]
  158.     private ?string $holderComplement null;
  159.     #[ORM\Column(type'string'nullabletrue)]
  160.     #[ApiProperty()]
  161.     #[Assert\Type('string')]
  162.     #[Groups([
  163.         'import:demand',
  164.         'demand:collection:post',
  165.         'demand:item:get',
  166.         'demand:item:put',
  167.     ])]
  168.     private ?string $holderNeighborhood null;
  169.     #[ORM\Column(type'string'nullabletrue)]
  170.     #[ApiProperty()]
  171.     #[Assert\Type('string')]
  172.     #[Groups([
  173.         'import:demand',
  174.         'demand:collection:post',
  175.         'demand:item:get',
  176.         'demand:item:put',
  177.     ])]
  178.     private ?string $holderCity null;
  179.     #[ORM\Column(type'string'nullabletrue)]
  180.     #[ApiProperty()]
  181.     #[Assert\Type('string')]
  182.     #[Groups([
  183.         'import:demand',
  184.         'demand:collection:post',
  185.         'demand:item:get',
  186.         'demand:item:put',
  187.     ])]
  188.     private ?string $holderState null;
  189.     
  190.     #[ORM\Column(type'string')]
  191.     #[ApiProperty()]
  192.     #[Assert\Type('string')]
  193.     #[Groups([
  194.         'import:demand',
  195.         'demand:collection:post',
  196.         'demand:item:get',
  197.         'demand:item:put',
  198.     ])]
  199.     private ?string $holderTaxIDType null;
  200.     /**
  201.      * The Tax / Fiscal ID of the organization or person, e.g. the TIN in the US or the CIF/NIF in Spain.
  202.      *
  203.      * @see https://schema.org/taxID
  204.      */
  205.     #[ORM\Column(type'string'nullabletrue)]
  206.     #[ApiProperty(iri'https://schema.org/taxID')]
  207.     #[Assert\Type('string')]
  208.     #[Groups([
  209.         'import:demand',
  210.         'demand:collection:get',
  211.         'demand:collection:post',
  212.         'demand:item:get',
  213.         'demand:item:put',
  214.     ])]
  215.     private ?string $holderTaxID null;
  216.     #[ORM\Column(type'float'nullabletrue)]
  217.     #[ApiProperty(iri'https://schema.org/Number')]
  218.     #[Groups([
  219.         'import:demand',
  220.         'demand:collection:post',
  221.         'demand:item:get',
  222.         'demand:item:put',
  223.     ])]
  224.     private ?float $interestFee null;
  225.     #[ORM\Column(type'float'nullabletrue)]
  226.     #[ApiProperty(iri'https://schema.org/Number')]
  227.     #[Groups([
  228.         'import:demand',
  229.         'import:demand',
  230.         'demand:collection:get',
  231.         'demand:collection:post',
  232.         'demand:item:get',
  233.         'demand:item:put',
  234.     ])]
  235.     private ?float $comissionRate null;
  236.     #[ORM\Column(type'float')]
  237.     #[ApiProperty(iri'https://schema.org/Number')]
  238.     #[Groups([
  239.         'import:demand',
  240.         'demand:collection:get',
  241.         'demand:collection:post',
  242.         'demand:item:get',
  243.         'demand:item:put',
  244.     ])]
  245.     private ?float $limitValue null;
  246.     #[ORM\Column(type'float'nullabletrue)]
  247.     #[ApiProperty(iri'https://schema.org/Number')]
  248.     #[Groups([
  249.         'import:demand',
  250.         'import:demand',
  251.         'demand:collection:get',
  252.         'demand:collection:post',
  253.         'demand:item:get',
  254.         'demand:item:put',
  255.     ])]
  256.     private ?float $insurancePremium null;
  257.     #[ORM\Column(type'float'nullabletrue)]
  258.     #[ApiProperty(iri'https://schema.org/Number')]
  259.     #[Groups([
  260.         'import:demand',
  261.         'import:demand',
  262.         'demand:collection:get',
  263.         'demand:collection:post',
  264.         'demand:item:get',
  265.         'demand:item:put',
  266.     ])]
  267.     private ?float $prize null;
  268.     #[ORM\Column(type'text'nullabletrue)]
  269.     #[ApiProperty(iri'https://schema.org/Text')]
  270.     #[Assert\Type('string')]
  271.     #[Groups([
  272.         'import:demand',
  273.         'demand:collection:post',
  274.         'demand:item:get',
  275.         'demand:item:put',
  276.     ])]
  277.     private ?string $pendingInformation null;
  278.     #[ORM\Column(type'string'nullablefalse)]
  279.     #[ApiProperty(iri'https://schema.org/Text')]
  280.     #[Assert\Type('string')]
  281.     #[Groups([
  282.         'import:demand',
  283.         'demand:collection:get',
  284.         'demand:collection:post',
  285.         'demand:item:get',
  286.         'demand:item:put',
  287.     ])]
  288.     private ?string $status null;
  289.     #[ApiProperty(iri'https://schema.org/startTime')]
  290.     #[ORM\Column(type'datetime'nullabletrue)]
  291.     #[Groups([
  292.         'import:demand',
  293.         'demand:collection:post',
  294.         'demand:item:get',
  295.         'demand:item:put',
  296.     ])]
  297.     private $startTime;
  298.     #[ApiProperty(iri'https://schema.org/endTime')]
  299.     #[ORM\Column(type'datetime')]
  300.     #[Groups([
  301.         'import:demand',
  302.         'demand:collection:post',
  303.         'demand:item:get',
  304.         'demand:item:put',
  305.     ])]
  306.     private $endTime;
  307.     #[ORM\ManyToOne(targetEntityInsured::class, inversedBy'demands')]
  308.     #[Groups([
  309.         'demand:collection:get',
  310.         'demand:collection:post',
  311.         'demand:item:get',
  312.         'demand:item:put',
  313.     ])]
  314.     #[MaxDepth(1)]
  315.     private $insured;
  316.     #[ApiProperty()]
  317.     #[Groups([
  318.         'import:demand',
  319.     ])]
  320.     private $insuredTaxID;
  321.     #[ApiProperty()]
  322.     #[Groups([
  323.         'demand:collection:get',
  324.         'demand:item:get',
  325.     ])]
  326.     #[MaxDepth(1)]
  327.     private $modality;
  328.     #[ApiProperty()]
  329.     #[Groups([
  330.         'import:demand',
  331.     ])]
  332.     private $modalityName;
  333.     #[ORM\ManyToOne(targetEntitySubmodality::class)]
  334.     #[ORM\OrderBy(["name" => "ASC"])]
  335.     #[Groups([
  336.         'demand:collection:get',
  337.         'demand:collection:post',
  338.         'demand:item:get',
  339.         'demand:item:put',
  340.         'policy:collection:get',
  341.     ])]
  342.     #[MaxDepth(1)]
  343.     private $submodality;
  344.     #[ApiProperty()]
  345.     #[Groups([
  346.         'import:demand',
  347.     ])]
  348.     private $submodalityName;
  349.     #[ORM\ManyToMany(targetEntityInsurer::class, inversedBy'demands'cascade: ['persist'])]
  350.     #[Groups([
  351.         'import:demand',
  352.         'demand:collection:post',
  353.         'demand:item:get',
  354.         'demand:item:put',
  355.     ])]
  356.     #[MaxDepth(1)]
  357.     private $insurers;
  358.     #[ORM\OneToMany(mappedBy'demand'targetEntityDemandUpload::class, cascade: ["remove"], orphanRemovaltrue)]
  359.     #[Groups([
  360.         'demand:item:get',
  361.     ])]
  362.     #[MaxDepth(1)]
  363.     private $uploads;
  364.     #[ORM\OneToOne(inversedBy'demand'targetEntityPolicy::class)]
  365.     #[Groups([
  366.         'demand:item:get',
  367.         'demand:collection:get',
  368.     ])]
  369.     #[MaxDepth(1)]
  370.     private $policy null;
  371.     public function __construct()
  372.     {
  373.         $this->insurers = new ArrayCollection();
  374.         $this->uploads = new ArrayCollection();
  375.     }
  376.     public function getId(): ?int
  377.     {
  378.         return $this->id;
  379.     }
  380.     /**
  381.      * @param string|null $processNumber
  382.      */
  383.     public function setProcessNumber($processNumber): void
  384.     {
  385.         $this->processNumber $processNumber;
  386.     }
  387.     public function getProcessNumber(): ?string
  388.     {
  389.         return $this->processNumber;
  390.     }
  391.     public function setHolderName(?string $holderName): void
  392.     {
  393.         $this->holderName $holderName;
  394.     }
  395.     public function getHolderName(): ?string
  396.     {
  397.         return $this->holderName;
  398.     }
  399.     public function getHolderZipcode(): ?string
  400.     {
  401.         return $this->holderZipcode;
  402.     }
  403.     public function setHolderZipcode(?string $holderZipcode): self
  404.     {
  405.         $this->holderZipcode $holderZipcode;
  406.         return $this;
  407.     }
  408.     public function setHolderAddress(?string $holderAddress): void
  409.     {
  410.         $this->holderAddress $holderAddress;
  411.     }
  412.     public function getHolderAddress(): ?string
  413.     {
  414.         return $this->holderAddress;
  415.     }
  416.     public function getHolderComplement(): ?string
  417.     {
  418.         return $this->holderComplement;
  419.     }
  420.     public function setHolderComplement(?string $holderComplement): self
  421.     {
  422.         $this->holderComplement $holderComplement;
  423.         return $this;
  424.     }
  425.     public function getHolderNeighborhood(): ?string
  426.     {
  427.         return $this->holderNeighborhood;
  428.     }
  429.     public function setHolderNeighborhood(?string $holderNeighborhood): self
  430.     {
  431.         $this->holderNeighborhood $holderNeighborhood;
  432.         return $this;
  433.     }
  434.     public function getHolderCity(): ?string
  435.     {
  436.         return $this->holderCity;
  437.     }
  438.     public function setHolderCity(?string $holderCity): self
  439.     {
  440.         $this->holderCity $holderCity;
  441.         return $this;
  442.     }
  443.     public function getHolderState(): ?string
  444.     {
  445.         return $this->holderState;
  446.     }
  447.     public function setHolderState(?string $holderState): self
  448.     {
  449.         $this->holderState $holderState;
  450.         return $this;
  451.     }
  452.     public function setHolderTaxID(?string $holderTaxID): void
  453.     {
  454.         $this->holderTaxID $holderTaxID;
  455.     }
  456.     public function getHolderTaxID(): ?string
  457.     {
  458.         return $this->holderTaxID;
  459.     }
  460.     public function setHolderTaxIDType(?string $holderTaxIDType): void
  461.     {
  462.         $this->holderTaxIDType $holderTaxIDType;
  463.     }
  464.     public function getHolderTaxIDType(): ?string
  465.     {
  466.         return $this->holderTaxIDType;
  467.     }
  468.     /**
  469.      * @param float|null $interestFee
  470.      */
  471.     public function setInterestFee($interestFee): void
  472.     {
  473.         $this->interestFee $interestFee;
  474.     }
  475.     public function getInterestFee(): ?float
  476.     {
  477.         return $this->interestFee;
  478.     }
  479.     /**
  480.      * @param string|null $status
  481.      */
  482.     public function setStatus($status): void
  483.     {
  484.         $this->status $status;
  485.     }
  486.     public function getStatus(): ?string
  487.     {
  488.         return $this->status;
  489.     }
  490.     public function getInsured(): ?Insured
  491.     {
  492.         return $this->insured;
  493.     }
  494.     public function setInsured(?Insured $insured): self
  495.     {
  496.         $this->insured $insured;
  497.         return $this;
  498.     }
  499.     public function getInsuredTaxID(): ?string
  500.     {
  501.         return $this->getInsured()->getTaxID();
  502.     }
  503.     public function getModality(): ?Modality
  504.     {
  505.         return $this->submodality?->getModality();
  506.     }
  507.     public function getModalityName(): ?string
  508.     {
  509.         return $this->getSubmodality()->getModality()->getName();
  510.     }
  511.     public function getSubmodality(): ?Submodality
  512.     {
  513.         return $this->submodality;
  514.     }
  515.     public function setSubmodality(?Submodality $submodality): self
  516.     {
  517.         $this->submodality $submodality;
  518.         return $this;
  519.     }
  520.     public function getSubmodalityName(): ?string
  521.     {
  522.         return $this->getSubmodality()->getName();
  523.     }
  524.     /**
  525.      * @return Collection|Insurer[]
  526.      */
  527.     public function getInsurers(): Collection
  528.     {
  529.         return $this->insurers;
  530.     }
  531.     public function addInsurer(Insurer $insurer): self
  532.     {
  533.         if (!$this->insurers->contains($insurer)) {
  534.             $this->insurers[] = $insurer;
  535.         }
  536.         return $this;
  537.     }
  538.     public function removeInsurer(Insurer $insurer): self
  539.     {
  540.         $this->insurers->removeElement($insurer);
  541.         return $this;
  542.     }
  543.     /**
  544.      * @return Collection|DemandUpload[]
  545.      */
  546.     public function getUploads(): Collection
  547.     {
  548.         return $this->uploads;
  549.     }
  550.     public function addUpload(DemandUpload $upload): self
  551.     {
  552.         if (!$this->uploads->contains($upload)) {
  553.             $this->uploads[] = $upload;
  554.             $upload->setDemand($this);
  555.         }
  556.         return $this;
  557.     }
  558.     public function removeUpload(DemandUpload $upload): self
  559.     {
  560.         if ($this->uploads->removeElement($upload)) {
  561.             // set the owning side to null (unless already changed)
  562.             if ($upload->getDemand() === $this) {
  563.                 $upload->setDemand(null);
  564.             }
  565.         }
  566.         return $this;
  567.     }
  568.     public function getStartTime(): ?\DateTimeInterface
  569.     {
  570.         return $this->startTime;
  571.     }
  572.     public function setStartTime(\DateTimeInterface $startTime): self
  573.     {
  574.         $this->startTime $startTime;
  575.         return $this;
  576.     }
  577.     public function getEndTime(): ?\DateTimeInterface
  578.     {
  579.         return $this->endTime;
  580.     }
  581.     public function setEndTime(?\DateTimeInterface $endTime): self
  582.     {
  583.         $this->endTime $endTime;
  584.         return $this;
  585.     }
  586.     public function getPolicy(): ?Policy
  587.     {
  588.         return $this->policy;
  589.     }
  590.     public function setPolicy(?Policy $policy): self
  591.     {
  592.         $this->policy $policy;
  593.         return $this;
  594.     }
  595.     public function getComissionRate(): ?float
  596.     {
  597.         return $this->comissionRate;
  598.     }
  599.     public function setComissionRate(?float $comissionRate): self
  600.     {
  601.         $this->comissionRate $comissionRate;
  602.         return $this;
  603.     }
  604.     public function getLimitValue(): ?float
  605.     {
  606.         return $this->limitValue;
  607.     }
  608.     public function setLimitValue(?float $limitValue): self
  609.     {
  610.         $this->limitValue $limitValue;
  611.         return $this;
  612.     }
  613.     public function getInsurancePremium(): ?float
  614.     {
  615.         return $this->insurancePremium;
  616.     }
  617.     public function setInsurancePremium(?float $insurancePremium): self
  618.     {
  619.         $this->insurancePremium $insurancePremium;
  620.         return $this;
  621.     }
  622.     public function getPrize(): ?float
  623.     {
  624.         return $this->prize;
  625.     }
  626.     public function setPrize(?float $prize): self
  627.     {
  628.         $this->prize $prize;
  629.         return $this;
  630.     }
  631.     public function getPendingInformation(): ?string
  632.     {
  633.         return $this->pendingInformation;
  634.     }
  635.     public function setPendingInformation(?string $pendingInformation): self
  636.     {
  637.         $this->pendingInformation $pendingInformation;
  638.         return $this;
  639.     }
  640. }