src/Entity/ProviderOrderItem.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\PaperStock;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Entity\Helpers\BaseEntity;
  6. use App\Entity\Helpers\TraitStock;
  7. use App\Entity\Helpers\TraitPriceUnity;
  8. use App\Entity\Helpers\TraitOrderTracking;
  9. use Doctrine\Common\Collections\Collection;
  10. use App\Repository\ProviderOrderItemRepository;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. #[ORM\Entity(repositoryClassProviderOrderItemRepository::class)]
  13. class ProviderOrderItem extends BaseEntity
  14. {
  15.     use TraitOrderTracking;
  16.     use TraitPriceUnity;
  17.     use TraitStock;
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column(type'integer')]
  21.     private $id;
  22.     #[ORM\Column(type'boolean')]
  23.     private $priceUnityUpdated;
  24.     #[ORM\ManyToOne(targetEntityProviderOrder::class, inversedBy'providerOrderItems')]
  25.     #[ORM\JoinColumn(nullablefalse)]
  26.     private $providerOrder;
  27.     #[ORM\ManyToOne(targetEntityPaper::class)]
  28.     #[ORM\JoinColumn(nullablefalse)]
  29.     private $paper;
  30.     #[ORM\OneToMany(mappedBy'providerOrderItem'targetEntityPaperProduct::class)]
  31.     private $paperProducts;
  32.     #[ORM\Column(type'boolean')]
  33.     private $completed false;
  34.     #[ORM\Column(type'text'nullabletrue)]
  35.     private $comment;
  36.     #[ORM\Column(type'boolean')]
  37.     private $deliveryEdited false;
  38.     public function __construct()
  39.     {
  40.         parent::__construct();
  41.         $this->setType(PaperStock::TYPE_ORDER_PROVIDER);
  42.         $this->paperProducts = new ArrayCollection();
  43.     }
  44.     public function getStockDate(): \DateTimeImmutable
  45.     {
  46.         return $this->getDeliveredAt();
  47.     }
  48.     public function updateProviderOrderItemDelivery(): self
  49.     {   
  50.         $productCount 0;
  51.         $productDeliveredCount 0;
  52.         foreach ($this->getPaperProducts() as $paperProduct) {
  53.             if($paperProduct->getDismissed()) continue;
  54.             $productCount++;
  55.             if ($paperProduct->getDelivered()) $productDeliveredCount++;
  56.         }
  57.         $this->setProductCount($productCount);
  58.         $this->setProductDeliveredCount($productDeliveredCount);
  59.         $this->updateDeliveryProgress();
  60.         return $this;
  61.     }
  62.     public function updateProviderOrderItemDifference()
  63.     {
  64.         $productPrice 0;
  65.         $productQuantity 0;
  66.         
  67.         foreach ($this->getPaperProducts() as $paperProduct) {
  68.             if($paperProduct->getDismissed()) continue;
  69.             $productPrice += $paperProduct->getPriceInitial();
  70.             $productQuantity += $paperProduct->getQuantityInitial();
  71.         }
  72.         $this->setPrice($this->getQuantity() * $this->getPriceUnity());
  73.         $this->setProductPrice($productPrice);
  74.         $this->setProductQuantity($productQuantity);
  75.         $this->updateDifference();
  76.         $this->setCompleted$this->quantityDifference >= );
  77.         $this->updateStock();
  78.     }
  79.     public function updateStock(): self
  80.     {   
  81.         $quantityMovement 0;
  82.         $priceMovement 0;
  83.         if (!$this->getDelivered()) {
  84.             foreach ($this->getPaperProducts() as $product) {
  85.                 if($product->getDelivered() || $product->getDismissed()) continue;
  86.                 $quantityMovement += $product->getQuantityInitial();
  87.                 $priceMovement += $product->getPriceInitial();
  88.             }
  89.             
  90.         }
  91.         if (!$this->getCompleted()) {
  92.             $quantityMovement += $this->getQuantityDifference() * -1;
  93.             $priceMovement += $this->getPriceDifference() * -1;
  94.         }
  95.         $this->setQuantityMovement($quantityMovement);
  96.         $this->setPriceMovement($priceMovement);
  97.         return $this;
  98.     }
  99.     public function setProviderOrder(?ProviderOrder $providerOrder): self
  100.     {
  101.         $this->providerOrder $providerOrder;
  102.         return $this;
  103.     }
  104.     // ##################################################################### //
  105.     // ##################################################################### //
  106.     // ##################################################################### //
  107.     public function getId(): ?int
  108.     {
  109.         return $this->id;
  110.     }
  111.     public function getPriceUnityUpdated(): ?bool
  112.     {
  113.         return $this->priceUnityUpdated;
  114.     }
  115.     public function setPriceUnityUpdated(bool $priceUnityUpdated): self
  116.     {
  117.         $this->priceUnityUpdated $priceUnityUpdated;
  118.         return $this;
  119.     }
  120.     public function getProviderOrder(): ?ProviderOrder
  121.     {
  122.         return $this->providerOrder;
  123.     }
  124.     public function getPaper(): ?Paper
  125.     {
  126.         return $this->paper;
  127.     }
  128.     public function setPaper(?Paper $paper): self
  129.     {
  130.         $this->paper $paper;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return Collection|PaperProduct[]
  135.      */
  136.     public function getPaperProducts(): Collection
  137.     {
  138.         return $this->paperProducts;
  139.     }
  140.     public function addPaperProduct(PaperProduct $paperProduct): self
  141.     {
  142.         if (!$this->paperProducts->contains($paperProduct)) {
  143.             $this->paperProducts[] = $paperProduct;
  144.             $paperProduct->setProviderOrderItem($this);
  145.         }
  146.         return $this;
  147.     }
  148.     public function removePaperProduct(PaperProduct $paperProduct): self
  149.     {
  150.         if ($this->paperProducts->removeElement($paperProduct)) {
  151.             // set the owning side to null (unless already changed)
  152.             if ($paperProduct->getProviderOrderItem() === $this) {
  153.                 $paperProduct->setProviderOrderItem(null);
  154.             }
  155.         }
  156.         return $this;
  157.     }
  158.     public function getCompleted(): ?bool
  159.     {
  160.         return $this->completed;
  161.     }
  162.     public function setCompleted(bool $completed): self
  163.     {
  164.         $this->completed $completed;
  165.         return $this;
  166.     }
  167.     public function getComment(): ?string
  168.     {
  169.         return $this->comment;
  170.     }
  171.     public function setComment(?string $comment): self
  172.     {
  173.         $this->comment $comment;
  174.         return $this;
  175.     }
  176.     public function getDeliveryEdited(): ?bool
  177.     {
  178.         return $this->deliveryEdited;
  179.     }
  180.     public function setDeliveryEdited(bool $deliveryEdited): self
  181.     {
  182.         $this->deliveryEdited $deliveryEdited;
  183.         return $this;
  184.     }
  185. }