src/Entity/ProviderOrder.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Entity\Helpers\BaseEntity;
  7. use App\Entity\Helpers\TraitOrderTracking;
  8. use App\Repository\ProviderOrderRepository;
  9. #[ORM\Entity(repositoryClassProviderOrderRepository::class)]
  10. class ProviderOrder extends BaseEntity
  11. {
  12.     use TraitOrderTracking;
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column(type'integer')]
  16.     private $id;
  17.     #[ORM\Column(type'string'length255)]
  18.     private $reference;
  19.     #[ORM\Column(type'date_immutable')]
  20.     private $orderedAt;
  21.     #[ORM\Column(type'datetime_immutable')]
  22.     private $deliveredEstimationAt;
  23.     #[ORM\Column(type'boolean')]
  24.     private $completed false;
  25.     #[ORM\ManyToOne(targetEntityProvider::class)]
  26.     #[ORM\JoinColumn(nullablefalse)]
  27.     private $provider;
  28.     #[ORM\OneToMany(mappedBy'providerOrder'targetEntityProviderOrderItem::class, orphanRemovaltruecascade: ['all'])]
  29.     private $providerOrderItems;
  30.     public function __construct()
  31.     {   
  32.         parent::__construct();
  33.         $this->providerOrderItems = new ArrayCollection();
  34.     }
  35.     public function getName(): string
  36.     {
  37.         return $this->reference;
  38.     }
  39.     public function getPriceUnities(): array
  40.     {   
  41.         $priceUnities = [];
  42.         foreach ($this->getProvider()->getPapers() as $paper) {
  43.             $priceUnities[$paper->getId()] = $paper->getPriceUnity();
  44.         }
  45.         return $priceUnities;
  46.     }
  47.     public function hasDeliveryDatePassed(): bool
  48.     {
  49.         return $this->getDeliveredEstimationAt() <= new \DateTimeImmutable();
  50.     }
  51.     public function updatePapersPriceUnity(): self
  52.     {   
  53.         foreach ($this->getProviderOrderItems() as $item) {
  54.             if($item->getPriceUnityUpdated()) continue;
  55.             $item->getPaper()->setPriceUnity($item->getPriceUnity());
  56.             $item->setPriceUnityUpdated(true);
  57.         }
  58.         return $this;
  59.     }
  60.     public function updateProviderOrderDelivery(): self
  61.     {
  62.         $productCount 0;
  63.         $productDeliveredCount 0;
  64.         foreach ($this->getProviderOrderItems() as $item) {
  65.             // Update provider order items
  66.             if (!$item->getDeliveryEdited()) $item->setDeliveredAt($this->getDeliveredEstimationAt());
  67.             $item->updateProviderOrderItemDelivery();
  68.             $productCount += $item->getProductCount();
  69.             $productDeliveredCount += $item->getProductDeliveredCount();
  70.         }
  71.         $this->setProductCount($productCount);
  72.         $this->setProductDeliveredCount($productDeliveredCount);
  73.         $this->updateDeliveryProgress();
  74.         return $this;
  75.     }
  76.     public function updateProviderOrderDifference()
  77.     {
  78.         $price 0;
  79.         $productPrice 0;
  80.         $quantity 0;
  81.         $productQuantity 0;
  82.         
  83.         foreach ($this->getProviderOrderItems() as $item) {
  84.             $item->updateProviderOrderItemDifference();
  85.             $price += $item->getPrice();
  86.             $productPrice += $item->getProductPrice();
  87.             $quantity += $item->getQuantity();
  88.             $productQuantity += $item->getProductQuantity();
  89.         }
  90.         $this->setPrice($price);
  91.         $this->setProductPrice($productPrice);
  92.         $this->setQuantity($quantity);
  93.         $this->setProductQuantity($productQuantity);
  94.         $this->updateDifference();
  95.         $this->setCompleted$this->quantityDifference >= );
  96.     }
  97.     public function setDeliveredEstimationAt(\DateTimeImmutable $deliveredEstimationAt): self
  98.     {
  99.         $deliveredEstimationAt $deliveredEstimationAt->setTime(120);
  100.         $this->deliveredEstimationAt $deliveredEstimationAt;
  101.         return $this;
  102.     }
  103.     // ##################################################################### //
  104.     // ##################################################################### //
  105.     // ##################################################################### //
  106.     public function getId(): ?int
  107.     {
  108.         return $this->id;
  109.     }
  110.     public function getReference(): ?string
  111.     {
  112.         return $this->reference;
  113.     }
  114.     public function setReference(string $reference): self
  115.     {
  116.         $this->reference $reference;
  117.         return $this;
  118.     }
  119.     public function getOrderedAt(): ?\DateTimeImmutable
  120.     {
  121.         return $this->orderedAt;
  122.     }
  123.     public function setOrderedAt(\DateTimeImmutable $orderedAt): self
  124.     {
  125.         $this->orderedAt $orderedAt;
  126.         return $this;
  127.     }
  128.     public function getDeliveredEstimationAt(): ?\DateTimeImmutable
  129.     {
  130.         return $this->deliveredEstimationAt;
  131.     }
  132.     public function getCompleted(): ?bool
  133.     {
  134.         return $this->completed;
  135.     }
  136.     public function setCompleted(bool $completed): self
  137.     {
  138.         $this->completed $completed;
  139.         return $this;
  140.     }
  141.     public function getProvider(): ?Provider
  142.     {
  143.         return $this->provider;
  144.     }
  145.     public function setProvider(?Provider $provider): self
  146.     {
  147.         $this->provider $provider;
  148.         return $this;
  149.     }
  150.     /**
  151.      * @return Collection|ProviderOrderItem[]
  152.      */
  153.     public function getProviderOrderItems(): Collection
  154.     {
  155.         return $this->providerOrderItems;
  156.     }
  157.     public function addProviderOrderItem(ProviderOrderItem $providerOrderItem): self
  158.     {
  159.         if (!$this->providerOrderItems->contains($providerOrderItem)) {
  160.             $this->providerOrderItems[] = $providerOrderItem;
  161.             $providerOrderItem->setProviderOrder($this);
  162.         }
  163.         return $this;
  164.     }
  165.     public function removeProviderOrderItem(ProviderOrderItem $providerOrderItem): self
  166.     {
  167.         if ($this->providerOrderItems->removeElement($providerOrderItem)) {
  168.             // set the owning side to null (unless already changed)
  169.             if ($providerOrderItem->getProviderOrder() === $this) {
  170.                 $providerOrderItem->setProviderOrder(null);
  171.             }
  172.         }
  173.         return $this;
  174.     }
  175. }