<?phpnamespace App\Entity;use App\Entity\PaperStock;use Doctrine\ORM\Mapping as ORM;use App\Entity\Helpers\BaseEntity;use App\Entity\Helpers\TraitStock;use App\Entity\Helpers\TraitPriceUnity;use App\Entity\Helpers\TraitOrderTracking;use Doctrine\Common\Collections\Collection;use App\Repository\ProviderOrderItemRepository;use Doctrine\Common\Collections\ArrayCollection;#[ORM\Entity(repositoryClass: ProviderOrderItemRepository::class)]class ProviderOrderItem extends BaseEntity{ use TraitOrderTracking; use TraitPriceUnity; use TraitStock; #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: 'integer')] private $id; #[ORM\Column(type: 'boolean')] private $priceUnityUpdated; #[ORM\ManyToOne(targetEntity: ProviderOrder::class, inversedBy: 'providerOrderItems')] #[ORM\JoinColumn(nullable: false)] private $providerOrder; #[ORM\ManyToOne(targetEntity: Paper::class)] #[ORM\JoinColumn(nullable: false)] private $paper; #[ORM\OneToMany(mappedBy: 'providerOrderItem', targetEntity: PaperProduct::class)] private $paperProducts; #[ORM\Column(type: 'boolean')] private $completed = false; #[ORM\Column(type: 'text', nullable: true)] private $comment; #[ORM\Column(type: 'boolean')] private $deliveryEdited = false; public function __construct() { parent::__construct(); $this->setType(PaperStock::TYPE_ORDER_PROVIDER); $this->paperProducts = new ArrayCollection(); } public function getStockDate(): \DateTimeImmutable { return $this->getDeliveredAt(); } public function updateProviderOrderItemDelivery(): self { $productCount = 0; $productDeliveredCount = 0; foreach ($this->getPaperProducts() as $paperProduct) { if($paperProduct->getDismissed()) continue; $productCount++; if ($paperProduct->getDelivered()) $productDeliveredCount++; } $this->setProductCount($productCount); $this->setProductDeliveredCount($productDeliveredCount); $this->updateDeliveryProgress(); return $this; } public function updateProviderOrderItemDifference() { $productPrice = 0; $productQuantity = 0; foreach ($this->getPaperProducts() as $paperProduct) { if($paperProduct->getDismissed()) continue; $productPrice += $paperProduct->getPriceInitial(); $productQuantity += $paperProduct->getQuantityInitial(); } $this->setPrice($this->getQuantity() * $this->getPriceUnity()); $this->setProductPrice($productPrice); $this->setProductQuantity($productQuantity); $this->updateDifference(); $this->setCompleted( $this->quantityDifference >= 0 ); $this->updateStock(); } public function updateStock(): self { $quantityMovement = 0; $priceMovement = 0; if (!$this->getDelivered()) { foreach ($this->getPaperProducts() as $product) { if($product->getDelivered() || $product->getDismissed()) continue; $quantityMovement += $product->getQuantityInitial(); $priceMovement += $product->getPriceInitial(); } } if (!$this->getCompleted()) { $quantityMovement += $this->getQuantityDifference() * -1; $priceMovement += $this->getPriceDifference() * -1; } $this->setQuantityMovement($quantityMovement); $this->setPriceMovement($priceMovement); return $this; } public function setProviderOrder(?ProviderOrder $providerOrder): self { $this->providerOrder = $providerOrder; return $this; } // ##################################################################### // // ##################################################################### // // ##################################################################### // public function getId(): ?int { return $this->id; } public function getPriceUnityUpdated(): ?bool { return $this->priceUnityUpdated; } public function setPriceUnityUpdated(bool $priceUnityUpdated): self { $this->priceUnityUpdated = $priceUnityUpdated; return $this; } public function getProviderOrder(): ?ProviderOrder { return $this->providerOrder; } public function getPaper(): ?Paper { return $this->paper; } public function setPaper(?Paper $paper): self { $this->paper = $paper; return $this; } /** * @return Collection|PaperProduct[] */ public function getPaperProducts(): Collection { return $this->paperProducts; } public function addPaperProduct(PaperProduct $paperProduct): self { if (!$this->paperProducts->contains($paperProduct)) { $this->paperProducts[] = $paperProduct; $paperProduct->setProviderOrderItem($this); } return $this; } public function removePaperProduct(PaperProduct $paperProduct): self { if ($this->paperProducts->removeElement($paperProduct)) { // set the owning side to null (unless already changed) if ($paperProduct->getProviderOrderItem() === $this) { $paperProduct->setProviderOrderItem(null); } } return $this; } public function getCompleted(): ?bool { return $this->completed; } public function setCompleted(bool $completed): self { $this->completed = $completed; return $this; } public function getComment(): ?string { return $this->comment; } public function setComment(?string $comment): self { $this->comment = $comment; return $this; } public function getDeliveryEdited(): ?bool { return $this->deliveryEdited; } public function setDeliveryEdited(bool $deliveryEdited): self { $this->deliveryEdited = $deliveryEdited; return $this; }}