pricedetails = new ArrayCollection(); } /** * Returns the ID as an string, defined by the element class. * This should have a form like P000014, for a part with ID 14. * * @return string The ID as a string; */ public function getIDString(): string { return 'O'.sprintf('%06d', $this->getID()); } /******************************************************************************** * * Getters * *********************************************************************************/ /** * Get the part. * * @return Part the part of this orderdetails */ public function getPart(): Part { return $this->part; } /** * Get the supplier. * * @return Supplier the supplier of this orderdetails */ public function getSupplier(): ?Supplier { return $this->supplier; } /** * Get the supplier part-nr. * * @return string the part-nr. */ public function getSupplierPartNr(): string { return $this->supplierpartnr; } /** * Get if this orderdetails is obsolete. * * "Orderdetails is obsolete" means that the part with that supplier-part-nr * is no longer available from the supplier of that orderdetails. * * @return bool * true if this part is obsolete at that supplier * * false if this part isn't obsolete at that supplier */ public function getObsolete(): bool { return (bool) $this->obsolete; } /** * Get the link to the website of the article on the suppliers website. * * @param $no_automatic_url bool Set this to true, if you only want to get the local set product URL for this Orderdetail * and not a automatic generated one, based from the Supplier * * @return string the link to the article */ public function getSupplierProductUrl(bool $no_automatic_url = false): string { if ($no_automatic_url || '' !== $this->supplier_product_url) { return $this->supplier_product_url; } if ($this->getSupplier() === null) { return ''; } return $this->getSupplier()->getAutoProductUrl($this->supplierpartnr); // maybe an automatic url is available... } /** * Get all pricedetails. * * @return Pricedetail[]|Collection all pricedetails as a one-dimensional array of Pricedetails objects, * sorted by minimum discount quantity */ public function getPricedetails(): Collection { return $this->pricedetails; } /** * Adds an pricedetail to this orderdetail * @param Pricedetail $pricedetail The pricedetail to add * @return Orderdetail */ public function addPricedetail(Pricedetail $pricedetail) : Orderdetail { $pricedetail->setOrderdetail($this); $this->pricedetails->add($pricedetail); return $this; } /** * Removes an pricedetail from this orderdetail * @param Pricedetail $pricedetail * @return Orderdetail */ public function removePricedetail(Pricedetail $pricedetail) : Orderdetail { $this->pricedetails->removeElement($pricedetail); return $this; } /** * Get the pricedetail for a specific quantity. * @param float $quantity this is the quantity to choose the correct pricedetails * * @return Pricedetail|null: the price as a bcmath string. Null if there are no orderdetails for the given quantity */ public function getPrice(float $quantity = 1) : ?Pricedetail { if ($quantity <= 0) { return null; } $all_pricedetails = $this->getPricedetails(); $correct_pricedetail = null; foreach ($all_pricedetails as $pricedetail) { // choose the correct pricedetails for the choosed quantity ($quantity) if ($quantity < $pricedetail->getMinDiscountQuantity()) { break; } $correct_pricedetail = $pricedetail; } return $correct_pricedetail; } /******************************************************************************** * * Setters * *********************************************************************************/ /** * Sets a new part with which this orderdetail is associated * @param Part $part * @return Orderdetail */ public function setPart(Part $part) : Orderdetail { $this->part = $part; return $this; } /** * Sets the new supplier associated with this orderdetail. * @param Supplier $new_supplier * @return Orderdetail */ public function setSupplier(Supplier $new_supplier) : Orderdetail { $this->supplier = $new_supplier; return $this; } /** * Set the supplier part-nr. * @param string $new_supplierpartnr the new supplier-part-nr * @return Orderdetail * @return Orderdetail */ public function setSupplierpartnr(string $new_supplierpartnr): self { $this->supplierpartnr = $new_supplierpartnr; return $this; } /** * Set if the part is obsolete at the supplier of that orderdetails. * @param bool $new_obsolete true means that this part is obsolete * @return Orderdetail * @return Orderdetail */ public function setObsolete(bool $new_obsolete): self { $this->obsolete = $new_obsolete; return $this; } /** * Sets the custom product supplier URL for this order detail. * Set this to "", if the function getSupplierProductURL should return the automatic generated URL. * @param $new_url string The new URL for the supplier URL. * @return Orderdetail */ public function setSupplierProductUrl(string $new_url) : Orderdetail { //Only change the internal URL if it is not the auto generated one if ($new_url === $this->supplier->getAutoProductUrl($this->getSupplierPartNr())) { return $this; } $this->supplier_product_url = $new_url; return $this; } }