src/Entity/Purchasing/Order.php line 57

  1. <?php
  2. namespace App\Entity\Purchasing;
  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\Patch;
  9. use ApiPlatform\Metadata\Post;
  10. use ApiPlatform\Metadata\Put;
  11. use App\Doctrine\Type\Purchasing\PurchaseOrderStatus;
  12. use App\Doctrine\Type\Sales\Incoterm;
  13. use App\Dto\Purchasing\CurrencyInput;
  14. use App\Entity\Common as Common;
  15. use App\Entity\Common\Company;
  16. use App\Entity\Expediting\Freight;
  17. use App\Entity\File\Parsable;
  18. use App\Entity\Identity\User;
  19. use App\Processor\Purchasing\CurrencyInputProcessor;
  20. use App\Validator\IsValidEnum\IsValidEnum;
  21. use DateTimeInterface;
  22. use Doctrine\Common\Collections\ArrayCollection;
  23. use Doctrine\Common\Collections\Collection;
  24. use Doctrine\DBAL\Types\Types;
  25. use Doctrine\ORM\Mapping as ORM;
  26. use Gedmo\Mapping\Annotation as Gedmo;
  27. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  28. use Symfony\Component\Uid\Ulid;
  29. use Symfony\Component\Validator\Constraints as Assert;
  30. #[ORM\Table(name'purchasing_order')]
  31. #[ORM\Index(columns: ['customer_id'], name'purchasing_order_customer_id_idx')]
  32. #[ORM\Index(columns: ['supplier_id'], name'purchasing_order_supplier_id_idx')]
  33. #[ORM\Index(columns: ['source_id'], name'purchasing_order_source_id_idx')]
  34. #[ORM\Index(columns: ['issued_by'], name'purchasing_order_issued_by_idx')]
  35. #[ORM\Index(columns: ['created_by'], name'purchasing_order_created_by_idx')]
  36. #[ORM\Index(columns: ['updated_by'], name'purchasing_order_updated_by_idx')]
  37. #[ORM\UniqueConstraint(name'purchasing_order_identifier_key'columns: ['identifier'])]
  38. #[ORM\UniqueConstraint(name'purchasing_order_customer_id_number_key'columns: ['customer_id''number'])]
  39. #[ORM\UniqueConstraint(name'purchasing_order_slug_key'columns: ['slug'])]
  40. #[ORM\Entity]
  41. #[UniqueEntity(fields: ['customer''number'])]
  42. #[ApiResource(routePrefix'/purchasing')]
  43. #[ApiResource(
  44.     operations: [
  45.         new Get(),
  46.         new GetCollection(),
  47.         new Post(uriTemplate'/orders/currencies'inputCurrencyInput::class, providerCurrencyInputProcessor::class),
  48.         new Patch(),
  49.         new Put(),
  50.         new Delete(),
  51.     ],
  52.     routePrefix'/purchasing',
  53. )]
  54. class Order
  55. {
  56.     use Common\Blameable;
  57.     use Common\Trackable;
  58.     #[ORM\Id]
  59.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  60.     #[ORM\SequenceGenerator(sequenceName'purchasing_order_id_seq')]
  61.     #[ORM\Column(typeTypes::INTEGER)]
  62.     #[ApiProperty(identifierfalse)]
  63.     private ?int $id null;
  64.     #[Assert\Ulid]
  65.     #[Assert\NotNull]
  66.     #[ORM\Column(type'ulid'uniquetrue)]
  67.     private ?Ulid $identifier null;
  68.     #[ORM\Column(typeTypes::STRING)]
  69.     #[Gedmo\Slug(fields: ['number'])]
  70.     #[ApiProperty(identifiertrue)]
  71.     private ?string $slug null;
  72.     #[Assert\NotNull]
  73.     #[ORM\ManyToOne(targetEntityCompany::class)]
  74.     #[ORM\JoinColumn(name'customer_id')]
  75.     #[ApiProperty(readableLinktrue)]
  76.     private ?Company $customer null;
  77.     #[ORM\ManyToOne(targetEntityCompany::class)]
  78.     #[ORM\JoinColumn(name'supplier_id')]
  79.     #[ApiProperty(readableLinktrue)]
  80.     private ?Company $supplier null;
  81.     #[ORM\ManyToOne(targetEntityUser::class)]
  82.     #[ORM\JoinColumn(name'issued_by')]
  83.     private ?User $issuedBy null;
  84.     #[Assert\Type(typeParsable::class)]
  85.     #[ORM\ManyToOne(targetEntityParsable::class, inversedBy'orders')]
  86.     #[ORM\JoinColumn(name'source_id')]
  87.     private ?Parsable $source null;
  88.     #[Assert\NotBlank]
  89.     #[Assert\Type(typeTypes::STRING)]
  90.     #[ORM\Column(typeTypes::STRING)]
  91.     private ?string $number null;
  92.     #[Assert\Type(typeTypes::STRING)]
  93.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  94.     private ?string $groupNumber null;
  95.     #[Assert\Type(typeTypes::STRING)]
  96.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  97.     private ?string $trackingNumber null;
  98.     #[Assert\NotNull]
  99.     #[Assert\Type(typeTypes::BOOLEAN)]
  100.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  101.     private ?bool $highValue false;
  102.     #[Assert\NotNull]
  103.     #[Assert\Type(typeTypes::BOOLEAN)]
  104.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  105.     private ?bool $highVolume false;
  106.     #[Assert\NotNull]
  107.     #[Assert\Type(typeTypes::BOOLEAN)]
  108.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  109.     private ?bool $highRisk false;
  110.     #[Assert\NotNull]
  111.     #[Assert\Type(typeTypes::BOOLEAN)]
  112.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  113.     private ?bool $delayed false;
  114.     #[Assert\Type(typeTypes::DATE_MUTABLE)]
  115.     #[ORM\Column(typeTypes::DATE_MUTABLEoptions: ['default' => 'CURRENT_DATE'])]
  116.     private ?DateTimeInterface $placedOn null;
  117.     #[IsValidEnum(enumIncoterm::class)]
  118.     #[ORM\Column(typeTypes::STRINGnullabletrueenumTypeIncoterm::class)]
  119.     private ?Incoterm $incoterm null;
  120.     #[Assert\Length(exactly3)]
  121.     #[Assert\Type(typeTypes::STRING)]
  122.     #[ORM\Column(typeTypes::STRINGlength3nullabletrue)]
  123.     private ?string $currency null;
  124.     /** @var Collection<int, LineItem> */
  125.     #[ORM\OneToMany(mappedBy'order'targetEntityLineItem::class, cascade: ['persist''remove'])]
  126.     private Collection $lineItems;
  127.     /** @var Collection<int, Freight> */
  128.     #[ORM\OneToMany(mappedBy'order'targetEntityFreight::class)]
  129.     private Collection $freights;
  130.     #[Assert\NotNull]
  131.     #[IsValidEnum(enumPurchaseOrderStatus::class)]
  132.     #[ORM\Column(typeTypes::STRINGenumTypePurchaseOrderStatus::class, options: ['default' => 'PLACED'])]
  133.     private ?PurchaseOrderStatus $status PurchaseOrderStatus::PLACED;
  134.     public function __construct()
  135.     {
  136.         $this->identifier = new Ulid();
  137.         $this->lineItems = new ArrayCollection();
  138.         $this->freights = new ArrayCollection();
  139.     }
  140.     public function getId(): ?int
  141.     {
  142.         return $this->id;
  143.     }
  144.     public function getIdentifier(): ?Ulid
  145.     {
  146.         return $this->identifier;
  147.     }
  148.     public function setIdentifier(Ulid $identifier): self
  149.     {
  150.         $this->identifier $identifier;
  151.         return $this;
  152.     }
  153.     public function getSlug(): ?string
  154.     {
  155.         return $this->slug;
  156.     }
  157.     public function setSlug(string $slug): self
  158.     {
  159.         $this->slug $slug;
  160.         return $this;
  161.     }
  162.     public function getNumber(): ?string
  163.     {
  164.         return $this->number;
  165.     }
  166.     public function setNumber(string $number): self
  167.     {
  168.         $this->number $number;
  169.         return $this;
  170.     }
  171.     public function getGroupNumber(): ?string
  172.     {
  173.         return $this->groupNumber;
  174.     }
  175.     public function setGroupNumber(?string $groupNumber): self
  176.     {
  177.         $this->groupNumber $groupNumber;
  178.         return $this;
  179.     }
  180.     public function getTrackingNumber(): ?string
  181.     {
  182.         return $this->trackingNumber;
  183.     }
  184.     public function setTrackingNumber(?string $trackingNumber): self
  185.     {
  186.         $this->trackingNumber $trackingNumber;
  187.         return $this;
  188.     }
  189.     public function isHighValue(): ?bool
  190.     {
  191.         return $this->highValue;
  192.     }
  193.     public function setHighValue(bool $highValue): self
  194.     {
  195.         $this->highValue $highValue;
  196.         return $this;
  197.     }
  198.     public function isHighVolume(): ?bool
  199.     {
  200.         return $this->highVolume;
  201.     }
  202.     public function setHighVolume(bool $highVolume): self
  203.     {
  204.         $this->highVolume $highVolume;
  205.         return $this;
  206.     }
  207.     public function isHighRisk(): ?bool
  208.     {
  209.         return $this->highRisk;
  210.     }
  211.     public function setHighRisk(bool $highRisk): self
  212.     {
  213.         $this->highRisk $highRisk;
  214.         return $this;
  215.     }
  216.     public function isDelayed(): ?bool
  217.     {
  218.         return $this->delayed;
  219.     }
  220.     public function setDelayed(bool $delayed): self
  221.     {
  222.         $this->delayed $delayed;
  223.         return $this;
  224.     }
  225.     public function getPlacedOn(): ?DateTimeInterface
  226.     {
  227.         return $this->placedOn;
  228.     }
  229.     public function setPlacedOn(?DateTimeInterface $placedOn): self
  230.     {
  231.         $this->placedOn $placedOn;
  232.         return $this;
  233.     }
  234.     public function getIncoterm(): ?Incoterm
  235.     {
  236.         return $this->incoterm;
  237.     }
  238.     public function setIncoterm(?Incoterm $incoterm): self
  239.     {
  240.         $this->incoterm $incoterm;
  241.         return $this;
  242.     }
  243.     public function getCurrency(): ?string
  244.     {
  245.         return $this->currency;
  246.     }
  247.     public function setCurrency(?string $currency): self
  248.     {
  249.         $this->currency $currency;
  250.         return $this;
  251.     }
  252.     public function getStatus(): ?PurchaseOrderStatus
  253.     {
  254.         return $this->status;
  255.     }
  256.     public function setStatus(?PurchaseOrderStatus $status): self
  257.     {
  258.         $this->status $status;
  259.         return $this;
  260.     }
  261.     public function getCustomer(): ?Company
  262.     {
  263.         return $this->customer;
  264.     }
  265.     public function setCustomer(?Company $customer): self
  266.     {
  267.         $this->customer $customer;
  268.         return $this;
  269.     }
  270.     public function getSupplier(): ?Company
  271.     {
  272.         return $this->supplier;
  273.     }
  274.     public function setSupplier(?Company $supplier): self
  275.     {
  276.         $this->supplier $supplier;
  277.         return $this;
  278.     }
  279.     public function getIssuedBy(): ?User
  280.     {
  281.         return $this->issuedBy;
  282.     }
  283.     public function setIssuedBy(?User $issuedBy): self
  284.     {
  285.         $this->issuedBy $issuedBy;
  286.         return $this;
  287.     }
  288.     public function getSource(): ?Parsable
  289.     {
  290.         return $this->source;
  291.     }
  292.     public function setSource(?Parsable $source): self
  293.     {
  294.         $this->source $source;
  295.         return $this;
  296.     }
  297.     /**
  298.      * @return Collection<int, LineItem>
  299.      */
  300.     public function getLineItems(): Collection
  301.     {
  302.         return $this->lineItems;
  303.     }
  304.     public function addLineItem(LineItem $lineItem): self
  305.     {
  306.         if (!$this->lineItems->contains($lineItem)) {
  307.             $this->lineItems->add($lineItem);
  308.             $lineItem->setOrder($this);
  309.         }
  310.         return $this;
  311.     }
  312.     public function removeLineItem(LineItem $lineItem): self
  313.     {
  314.         if ($this->lineItems->removeElement($lineItem)) {
  315.             // set the owning side to null (unless already changed)
  316.             if ($lineItem->getOrder() === $this) {
  317.                 $lineItem->setOrder(null);
  318.             }
  319.         }
  320.         return $this;
  321.     }
  322.     /**
  323.      * @return Collection<int, Freight>
  324.      */
  325.     public function getFreights(): Collection
  326.     {
  327.         return $this->freights;
  328.     }
  329.     public function addFreight(Freight $freight): self
  330.     {
  331.         if (!$this->freights->contains($freight)) {
  332.             $this->freights->add($freight);
  333.             $freight->setOrder($this);
  334.         }
  335.         return $this;
  336.     }
  337.     public function removeFreight(Freight $freight): self
  338.     {
  339.         if ($this->freights->removeElement($freight)) {
  340.             // set the owning side to null (unless already changed)
  341.             if ($freight->getOrder() === $this) {
  342.                 $freight->setOrder(null);
  343.             }
  344.         }
  345.         return $this;
  346.     }
  347. }