src/Entity/Sales/CallOffOrder.php line 58

  1. <?php
  2. namespace App\Entity\Sales;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Link;
  9. use ApiPlatform\Metadata\Patch;
  10. use ApiPlatform\Metadata\Put;
  11. use App\Dto\Sales\CallOffOrderInput;
  12. use App\Entity\Common as Common;
  13. use App\Entity\Common\Company;
  14. use App\Entity\File\Upload;
  15. use App\Entity\Identity\User;
  16. use App\Processor\Sales\CallOffOrderInputProcessor;
  17. use DateTimeInterface;
  18. use Doctrine\Common\Collections\ArrayCollection;
  19. use Doctrine\Common\Collections\Collection;
  20. use Doctrine\DBAL\Types\Types;
  21. use Doctrine\ORM\Mapping as ORM;
  22. use Gedmo\Mapping\Annotation as Gedmo;
  23. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  24. use Symfony\Component\Validator\Constraints as Assert;
  25. #[ORM\Table(name'contract_call_off_order')]
  26. #[ORM\Index(columns: ['file_id'], name'contract_call_off_order_file_id_idx')]
  27. #[ORM\Index(columns: ['client_id'], name'contract_call_off_order_client_id_idx')]
  28. #[ORM\Index(columns: ['created_by'], name'contract_call_off_order_created_by_idx')]
  29. #[ORM\Index(columns: ['updated_by'], name'contract_call_off_order_updated_by_idx')]
  30. #[ORM\UniqueConstraint(name'contract_call_off_order_slug_key'columns: ['slug'])]
  31. #[ORM\UniqueConstraint(name'contract_call_off_order_number_key'columns: ['client_id''number'])]
  32. #[ORM\Entity]
  33. #[UniqueEntity('number')]
  34. #[GetCollection(
  35.     uriTemplate'/sales/clients/{client}/call_off_orders',
  36.     uriVariables: [
  37.         'client' => new Link(toProperty'client'fromClassCompany::class),
  38.     ],
  39. )]
  40. #[ApiResource(
  41.     uriTemplate'/sales/clients/{client}/call_off_orders/{slug}',
  42.     operations: [
  43.         new Get(),
  44.         new Delete(),
  45.         new Patch(inputFormats: ['json' => ['application/merge-patch+json'], 'multipart' => ['multipart/form-data']]),
  46.         new Put(inputFormats: ['json' => ['application/json'], 'multipart' => ['multipart/form-data']]),
  47.     ],
  48.     uriVariables: [
  49.         'client' => new Link(toProperty'client'fromClassCompany::class),
  50.         'slug' => new Link(fromClassCallOffOrder::class),
  51.     ],
  52.     inputCallOffOrderInput::class,
  53.     processorCallOffOrderInputProcessor::class,
  54. )]
  55. class CallOffOrder
  56. {
  57.     use Common\Blameable;
  58.     use Common\Trackable;
  59.     #[ORM\Id]
  60.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  61.     #[ORM\SequenceGenerator(sequenceName'contract_call_off_order_id_seq')]
  62.     #[ORM\Column(typeTypes::INTEGER)]
  63.     #[ApiProperty(identifierfalse)]
  64.     private ?int $id null;
  65.     #[Gedmo\Slug(fields: ['number'])]
  66.     #[ORM\Column(typeTypes::STRING)]
  67.     #[ApiProperty(identifiertrue)]
  68.     private string $slug;
  69.     #[Assert\NotNull]
  70.     #[Assert\Length(min5)]
  71.     #[ORM\Column(typeTypes::STRING)]
  72.     private ?string $number null;
  73.     #[Assert\NotNull]
  74.     #[ORM\ManyToOne(targetEntityCompany::class)]
  75.     #[ORM\JoinColumn(name'client_id'nullablefalse)]
  76.     private ?Company $client null;
  77.     /** @var Collection<int, Contract> */
  78.     #[ORM\ManyToMany(targetEntityContract::class, inversedBy'callOffOrders')]
  79.     #[ORM\JoinTable(name'contract_call_off_order_contract_map')]
  80.     #[ORM\JoinColumn(name'call_off_order_id')]
  81.     #[ORM\InverseJoinColumn(name'contract_id')]
  82.     private Collection $contracts;
  83.     #[ORM\ManyToOne(targetEntityUpload::class, cascade: ['persist''remove'])]
  84.     #[ORM\JoinColumn(name'file_id'referencedColumnName'id')]
  85.     private ?Upload $file null;
  86.     #[Assert\NotNull]
  87.     #[ORM\Column(typeTypes::DATE_MUTABLEoptions: ['default' => 'CURRENT_DATE'])]
  88.     private ?DateTimeInterface $receivedOn null;
  89.     #[Assert\GreaterThanOrEqual(propertyPath'receivedOn')]
  90.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  91.     private ?DateTimeInterface $exhaustedOn null;
  92.     #[Assert\Type(typeUpload::class)]
  93.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  94.     private ?bool $expired false;
  95.     #[Gedmo\Blameable(on'create')]
  96.     #[ORM\ManyToOne(targetEntityUser::class)]
  97.     #[ORM\JoinColumn(name'created_by'nullablefalse)]
  98.     protected ?User $createdBy null;
  99.     public function __construct()
  100.     {
  101.         $this->contracts = new ArrayCollection();
  102.     }
  103.     public function getId(): ?int
  104.     {
  105.         return $this->id;
  106.     }
  107.     public function getSlug(): ?string
  108.     {
  109.         return $this->slug;
  110.     }
  111.     public function setSlug(string $slug): self
  112.     {
  113.         $this->slug $slug;
  114.         return $this;
  115.     }
  116.     public function getNumber(): ?string
  117.     {
  118.         return $this->number;
  119.     }
  120.     public function setNumber(string $number): self
  121.     {
  122.         $this->number $number;
  123.         return $this;
  124.     }
  125.     public function getClient(): ?Company
  126.     {
  127.         return $this->client;
  128.     }
  129.     public function setClient(?Company $contract): self
  130.     {
  131.         $this->client $contract;
  132.         return $this;
  133.     }
  134.     /**
  135.      * @return Collection<int, Contract>
  136.      */
  137.     public function getContracts(): Collection
  138.     {
  139.         return $this->contracts;
  140.     }
  141.     public function addContract(Contract $contract): self
  142.     {
  143.         if (!$this->contracts->contains($contract)) {
  144.             $this->contracts->add($contract);
  145.         }
  146.         return $this;
  147.     }
  148.     public function removeContract(Contract $contract): self
  149.     {
  150.         $this->contracts->removeElement($contract);
  151.         return $this;
  152.     }
  153.     public function getFile(): ?Upload
  154.     {
  155.         return $this->file;
  156.     }
  157.     public function setFile(?Upload $file): self
  158.     {
  159.         $this->file $file;
  160.         return $this;
  161.     }
  162.     public function getReceivedOn(): ?DateTimeInterface
  163.     {
  164.         return $this->receivedOn;
  165.     }
  166.     public function setReceivedOn(DateTimeInterface $receivedOn): self
  167.     {
  168.         $this->receivedOn $receivedOn;
  169.         return $this;
  170.     }
  171.     public function getExhaustedOn(): ?DateTimeInterface
  172.     {
  173.         return $this->exhaustedOn;
  174.     }
  175.     public function setExhaustedOn(?DateTimeInterface $exhaustedOn): self
  176.     {
  177.         $this->exhaustedOn $exhaustedOn;
  178.         return $this;
  179.     }
  180.     public function isExpired(): ?bool
  181.     {
  182.         return $this->expired;
  183.     }
  184.     public function setExpired(bool $expired): self
  185.     {
  186.         $this->expired $expired;
  187.         return $this;
  188.     }
  189. }