order_orderdetail; } /** * Get the order quantity of this part. * * @return int the order quantity */ public function getOrderQuantity(): int { return $this->order_quantity; } /** * Check if this part is marked for manual ordering. * * @return bool the "manual_order" attribute */ public function isMarkedForManualOrder(): bool { return $this->manual_order; } /** * Get all orderdetails of this part. * * @param bool $hide_obsolete If true, obsolete orderdetails will NOT be returned * * @return Collection|Orderdetail[] * all orderdetails as a one-dimensional array of Orderdetails objects * (empty array if there are no ones) * * the array is sorted by the suppliers names / minimum order quantity */ public function getOrderdetails(bool $hide_obsolete = false): Collection { //If needed hide the obsolete entries if ($hide_obsolete) { $orderdetails = $this->orderdetails; foreach ($orderdetails as $key => $details) { if ($details->getObsolete()) { unset($orderdetails[$key]); } } return $orderdetails; } return $this->orderdetails; } /** * Adds the given orderdetail to list of orderdetails. * The orderdetail is assigned to this part. * * @param Orderdetail $orderdetail the orderdetail that should be added */ public function addOrderdetail(Orderdetail $orderdetail): self { $orderdetail->setPart($this); $this->orderdetails->add($orderdetail); return $this; } /** * Removes the given orderdetail from the list of orderdetails. * * @return OrderTrait */ public function removeOrderdetail(Orderdetail $orderdetail): self { $this->orderdetails->removeElement($orderdetail); return $this; } /** * Set the "manual_order" attribute. * * @param bool $new_manual_order the new "manual_order" attribute * @param int $new_order_quantity the new order quantity * @param Orderdetail|null $new_order_orderdetail * the ID of the new order orderdetails * * or Zero for "no order orderdetails" * * or NULL for automatic order orderdetails * (if the part has exactly one orderdetails, * set this orderdetails as order orderdetails. * Otherwise, set "no order orderdetails") */ public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, ?Orderdetail $new_order_orderdetail = null): self { //Assert::greaterThan($new_order_quantity, 0, 'The new order quantity must be greater zero. Got %s!'); $this->manual_order = $new_manual_order; //TODO; $this->order_orderdetail = $new_order_orderdetail; $this->order_quantity = $new_order_quantity; return $this; } /** * Check if this part is obsolete. * * A Part is marked as "obsolete" if all their orderdetails are marked as "obsolete". * If a part has no orderdetails, the part isn't marked as obsolete. * * @return bool true, if this part is obsolete. false, if this part isn't obsolete */ public function isObsolete(): bool { $all_orderdetails = $this->getOrderdetails(); if (0 === count($all_orderdetails)) { return false; } foreach ($all_orderdetails as $orderdetails) { if (! $orderdetails->getObsolete()) { return false; } } return true; } }