/** * @brief Get the minimum quantity which should be ordered * * @param boolean $with_devices @li if true, all parts from devices which are marked as "to order" will be included in the calculation * @li if false, only max(mininstock - instock, 0) will be returned * * @retval integer the minimum order quantity */ public function get_min_order_quantity($with_devices = true) { if ($with_devices) { $count_must_order = 0; // for devices with "order_only_missing_parts == false" $count_should_order = 0; // for devices with "order_only_missing_parts == true" $deviceparts = DevicePart::get_order_device_parts($this->database, $this->current_user, $this->log, $this->get_id()); foreach ($deviceparts as $devicepart) { $device = $devicepart->get_device(); if ($device->get_order_only_missing_parts()) { $count_should_order += $device->get_order_quantity() * $devicepart->get_mount_quantity(); } else { $count_must_order += $device->get_order_quantity() * $devicepart->get_mount_quantity(); } } return $count_must_order + max(0, $this->get_mininstock() - $this->get_instock() + $count_should_order); } else { return max(0, $this->get_mininstock() - $this->get_instock()); } }