src/Entity/PurchaseOrder.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PurchaseOrderRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassPurchaseOrderRepository::class)]
  9. #[ORM\HasLifecycleCallbacks]
  10. class PurchaseOrder extends BaseEntity
  11. {
  12.     public const STATUS_DRAFT 'DRAFT';
  13.     public const STATUS_SENT 'SENT';
  14.     public const STATUS_PARTIAL_RECEIVED 'PARTIAL_RECEIVED';
  15.     public const STATUS_COMPLETED 'COMPLETED';
  16.     public const STATUS_CANCELLED 'CANCELLED';
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column]
  20.     private ?int $id null;
  21.     #[ORM\Column(length255uniquetrue)]
  22.     private ?string $poNumber null;
  23.     #[ORM\ManyToOne(inversedBy'purchaseOrders')]
  24.     #[ORM\JoinColumn(nullablefalse)]
  25.     private ?Supplier $supplier null;
  26.     #[ORM\ManyToOne]
  27.     #[ORM\JoinColumn(nullablefalse)]
  28.     private ?Warehouse $warehouse null;
  29.     #[ORM\Column(length50)]
  30.     private ?string $status self::STATUS_DRAFT;
  31.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  32.     private ?\DateTimeInterface $orderDate null;
  33.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  34.     private ?\DateTimeInterface $expectedDate null;
  35.     #[ORM\Column(typeTypes::DECIMALprecision19scale4)]
  36.     private ?string $totalAmount '0.00';
  37.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  38.     private ?string $note null;
  39.     public const DELIVERY_TERM_FACTORY 'FABRIKA_TESLIM';
  40.     public const DELIVERY_TERM_PORT 'LIMAN_TESLIM';
  41.     #[ORM\Column(length50nullabletrue)]
  42.     private ?string $deliveryTerm null;
  43.     #[ORM\OneToMany(mappedBy'purchaseOrder'targetEntityPurchaseOrderItem::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  44.     private Collection $items;
  45.     #[ORM\OneToMany(mappedBy'purchaseOrder'targetEntityPurchaseOrderNote::class, cascade: ['persist''remove'])]
  46.     private Collection $notes;
  47.     #[ORM\ManyToOne(targetEntityCompany::class)]
  48.     #[ORM\JoinColumn(nullabletrue)]
  49.     private ?Company $company null;
  50.     #[ORM\ManyToMany(targetEntityUser::class)]
  51.     private Collection $assignedUsers;
  52.     public function __construct()
  53.     {
  54.         $this->items = new ArrayCollection();
  55.         $this->notes = new ArrayCollection();
  56.         $this->assignedUsers = new ArrayCollection();
  57.         $this->orderDate = new \DateTime();
  58.     }
  59.     public function getId(): ?int
  60.     {
  61.         return $this->id;
  62.     }
  63.     public function getPoNumber(): ?string
  64.     {
  65.         return $this->poNumber;
  66.     }
  67.     public function setPoNumber(string $poNumber): self
  68.     {
  69.         $this->poNumber $poNumber;
  70.         return $this;
  71.     }
  72.     public function getSupplier(): ?Supplier
  73.     {
  74.         return $this->supplier;
  75.     }
  76.     public function setSupplier(?Supplier $supplier): self
  77.     {
  78.         $this->supplier $supplier;
  79.         return $this;
  80.     }
  81.     public function getWarehouse(): ?Warehouse
  82.     {
  83.         return $this->warehouse;
  84.     }
  85.     public function setWarehouse(?Warehouse $warehouse): self
  86.     {
  87.         $this->warehouse $warehouse;
  88.         return $this;
  89.     }
  90.     public function getStatus(): ?string
  91.     {
  92.         return $this->status;
  93.     }
  94.     public function setStatus(string $status): self
  95.     {
  96.         $this->status $status;
  97.         return $this;
  98.     }
  99.     public function getOrderDate(): ?\DateTimeInterface
  100.     {
  101.         return $this->orderDate;
  102.     }
  103.     public function setOrderDate(\DateTimeInterface $orderDate): self
  104.     {
  105.         $this->orderDate $orderDate;
  106.         return $this;
  107.     }
  108.     public function getExpectedDate(): ?\DateTimeInterface
  109.     {
  110.         return $this->expectedDate;
  111.     }
  112.     public function setExpectedDate(?\DateTimeInterface $expectedDate): self
  113.     {
  114.         $this->expectedDate $expectedDate;
  115.         return $this;
  116.     }
  117.     public function getTotalAmount(): ?string
  118.     {
  119.         return $this->totalAmount;
  120.     }
  121.     public function setTotalAmount(string $totalAmount): self
  122.     {
  123.         $this->totalAmount $totalAmount;
  124.         return $this;
  125.     }
  126.     public function getNote(): ?string
  127.     {
  128.         return $this->note;
  129.     }
  130.     public function setNote(?string $note): self
  131.     {
  132.         $this->note $note;
  133.         return $this;
  134.     }
  135.     /**
  136.      * @return Collection<int, PurchaseOrderItem>
  137.      */
  138.     public function getItems(): Collection
  139.     {
  140.         return $this->items;
  141.     }
  142.     public function addItem(PurchaseOrderItem $item): self
  143.     {
  144.         if (!$this->items->contains($item)) {
  145.             $this->items->add($item);
  146.             $item->setPurchaseOrder($this);
  147.             $this->calculateTotal();
  148.         }
  149.         return $this;
  150.     }
  151.     public function removeItem(PurchaseOrderItem $item): self
  152.     {
  153.         if ($this->items->removeElement($item)) {
  154.             // set the owning side to null (unless already changed)
  155.             if ($item->getPurchaseOrder() === $this) {
  156.                 $item->setPurchaseOrder(null);
  157.             }
  158.             $this->calculateTotal();
  159.         }
  160.         return $this;
  161.     }
  162.     /**
  163.      * @return Collection<int, PurchaseOrderNote>
  164.      */
  165.     public function getNotes(): Collection
  166.     {
  167.         return $this->notes;
  168.     }
  169.     public function addNote(PurchaseOrderNote $note): self
  170.     {
  171.         if (!$this->notes->contains($note)) {
  172.             $this->notes->add($note);
  173.             $note->setPurchaseOrder($this);
  174.         }
  175.         return $this;
  176.     }
  177.     public function removeNote(PurchaseOrderNote $note): self
  178.     {
  179.         if ($this->notes->removeElement($note)) {
  180.             if ($note->getPurchaseOrder() === $this) {
  181.                 $note->setPurchaseOrder(null);
  182.             }
  183.         }
  184.         return $this;
  185.     }
  186.     /**
  187.      * @return Collection<int, User>
  188.      */
  189.     public function getAssignedUsers(): Collection
  190.     {
  191.         return $this->assignedUsers;
  192.     }
  193.     public function addAssignedUser(User $user): self
  194.     {
  195.         if (!$this->assignedUsers->contains($user)) {
  196.             $this->assignedUsers->add($user);
  197.         }
  198.         return $this;
  199.     }
  200.     public function removeAssignedUser(User $user): self
  201.     {
  202.         $this->assignedUsers->removeElement($user);
  203.         return $this;
  204.     }
  205.     #[ORM\OneToOne(mappedBy'purchaseOrder'targetEntityExportProcess::class, cascade: ['persist''remove'])]
  206.     private ?ExportProcess $exportProcess null;
  207.     public function getExportProcess(): ?ExportProcess
  208.     {
  209.         return $this->exportProcess;
  210.     }
  211.     public function setExportProcess(ExportProcess $exportProcess): self
  212.     {
  213.         // set the owning side of the relation if necessary
  214.         if ($exportProcess->getPurchaseOrder() !== $this) {
  215.             $exportProcess->setPurchaseOrder($this);
  216.         }
  217.         $this->exportProcess $exportProcess;
  218.         return $this;
  219.     }
  220.     public function getDeliveryTerm(): ?string
  221.     {
  222.         return $this->deliveryTerm;
  223.     }
  224.     public function setDeliveryTerm(?string $deliveryTerm): self
  225.     {
  226.         $this->deliveryTerm $deliveryTerm;
  227.         return $this;
  228.     }
  229.     public function calculateTotal(): void
  230.     {
  231.         $total 0.0;
  232.         foreach ($this->items as $item) {
  233.             $total += (float) $item->getTotalPrice();
  234.         }
  235.         $this->totalAmount = (string) $total;
  236.     }
  237.     public function getCompany(): ?Company
  238.     {
  239.         return $this->company;
  240.     }
  241.     public function setCompany(?Company $company): self
  242.     {
  243.         $this->company $company;
  244.         return $this;
  245.     }
  246. }