orderdetail; } /** * Returns the price associated with this pricedetail. * It is given in current currency and for the price related quantity. * * @return string the price as string, like returned raw from DB */ public function getPrice(): string { return $this->price; } /** * Get the price for a single unit in the currency associated with this price detail. * * @param float|string $multiplier The returned price (float or string) will be multiplied * with this multiplier. * * You will get the price for $multiplier parts. If you want the price which is stored * in the database, you have to pass the "price_related_quantity" count as $multiplier. * * @return string the price as a bcmath string */ public function getPricePerUnit($multiplier = 1.0): string { $multiplier = (string) $multiplier; $tmp = bcmul($this->price, $multiplier, static::PRICE_PRECISION); return bcdiv($tmp, (string) $this->price_related_quantity, static::PRICE_PRECISION); //return ($this->price * $multiplier) / $this->price_related_quantity; } /** * Get the price related quantity. * * This is the quantity, for which the price is valid. * The amount is measured in part unit. * * @return float the price related quantity * * @see Pricedetail::setPriceRelatedQuantity() */ public function getPriceRelatedQuantity(): float { if ($this->orderdetail && $this->orderdetail->getPart() && ! $this->orderdetail->getPart()->useFloatAmount()) { $tmp = round($this->price_related_quantity); return $tmp < 1 ? 1 : $tmp; } return $this->price_related_quantity; } /** * Get the minimum discount quantity. * * "Minimum discount quantity" means the minimum order quantity for which the price * of this orderdetails is valid. * * The amount is measured in part unit. * * @return float the minimum discount quantity * * @see Pricedetail::setMinDiscountQuantity() */ public function getMinDiscountQuantity(): float { if ($this->orderdetail && $this->orderdetail->getPart() && ! $this->orderdetail->getPart()->useFloatAmount()) { $tmp = round($this->min_discount_quantity); return $tmp < 1 ? 1 : $tmp; } return $this->min_discount_quantity; } /** * Returns the currency associated with this price information. * Returns null, if no specific currency is selected and the global base currency should be assumed. */ public function getCurrency(): ?Currency { return $this->currency; } /******************************************************************************** * * Setters * *********************************************************************************/ /** * Sets the orderdetail to which this pricedetail belongs to. * * @param Orderdetail $orderdetail * @return $this */ public function setOrderdetail(Orderdetail $orderdetail): self { $this->orderdetail = $orderdetail; return $this; } /** * Sets the currency associated with the price informations. * Set to null, to use the global base currency. * * @param Currency|null $currency * @return Pricedetail */ public function setCurrency(?Currency $currency): self { $this->currency = $currency; return $this; } /** * Set the price. * * @param string $new_price the new price as a float number * * * This is the price for "price_related_quantity" parts!! * * Example: if "price_related_quantity" is '10', * you have to set here the price for 10 parts! * @return $this */ public function setPrice(string $new_price): self { //Assert::natural($new_price, 'The new price must be positive! Got %s!'); $this->price = $new_price; return $this; } /** * Set the price related quantity. * * This is the quantity, for which the price is valid. * * Example: * If 100pcs costs 20$, you have to set the price to 20$ and the price related * quantity to 100. The single price (20$/100 = 0.2$) will be calculated automatically. * * @param float $new_price_related_quantity the price related quantity * * @return $this */ public function setPriceRelatedQuantity(float $new_price_related_quantity): self { $this->price_related_quantity = $new_price_related_quantity; return $this; } /** * Set the minimum discount quantity. * * "Minimum discount quantity" means the minimum order quantity for which the price * of this orderdetails is valid. This way, you're able to use different prices * for different order quantities (quantity discount!). * * Example: * - 1-9pcs costs 10$: set price to 10$/pcs and minimum discount quantity to 1 * - 10-99pcs costs 9$: set price to 9$/pcs and minimum discount quantity to 10 * - 100pcs or more costs 8$: set price/pcs to 8$ and minimum discount quantity to 100 * * (Each of this examples would be an own Pricedetails-object. * So the orderdetails would have three Pricedetails for one supplier.) * * @param float $new_min_discount_quantity the minimum discount quantity * @return $this */ public function setMinDiscountQuantity(float $new_min_discount_quantity): self { $this->min_discount_quantity = $new_min_discount_quantity; return $this; } /** * 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 'PD'.sprintf('%06d', $this->getID()); } }