/** * @brief Get the price for a specific quantity * * @param boolean $as_money_string @li if true, this method returns a money string incl. currency * @li if false, this method returns the price as float * @param integer $quantity this is the quantity to choose the correct pricedetails * @param integer|NULL $multiplier @li This is the multiplier which will be applied to every single price * @li If you pass NULL, the number from $quantity will be used * * @retval float the price as a float number (if "$as_money_string == false") * @retval NULL if there are no prices and "$as_money_string == false" * @retval string the price as a string incl. currency (if "$as_money_string == true") * * @throws Exception if there are no pricedetails for the choosed quantity * (for example, there are only one pricedetails with the minimum discount quantity '10', * but the choosed quantity is '5' --> the price for 5 parts is not defined!) * @throws Exception if there was an error * * @see float_to_money_string() */ public function get_price($as_money_string = false, $quantity = 1, $multiplier = NULL) { if ($quantity == 0 && $multiplier === NULL) { if ($as_money_string) { return float_to_money_string(0); } else { return 0; } } $all_pricedetails = $this->get_pricedetails(); if (count($all_pricedetails) == 0) { if ($as_money_string) { return float_to_money_string(NULL); } else { return NULL; } } foreach ($all_pricedetails as $pricedetails) { // choose the correct pricedetails for the choosed quantity ($quantity) if ($quantity < $pricedetails->get_min_discount_quantity()) { break; } $correct_pricedetails = $pricedetails; } if (!isset($correct_pricedetails) || !is_object($correct_pricedetails)) { throw new Exception('Es sind keine Preisinformationen für die angegebene Bestellmenge vorhanden!'); } if ($multiplier === NULL) { $multiplier = $quantity; } return $correct_pricedetails->get_price($as_money_string, $multiplier); }
/** * @brief Get the price * * @param boolean $as_money_string @li if true, this method returns a money string incl. currency * @li if false, this method returns the price as float * @param integer $multiplier The returned price (float or string) will be multiplied * with this multiplier. * * @note 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. * * @retval float the price as a float number (if "$as_money_string == false") * @retval string the price as a string incl. currency (if "$as_money_string == true") * * @see float_to_money_string() */ public function get_price($as_money_string = false, $multiplier = 1) { $price = $this->db_data['price'] * $multiplier / $this->db_data['price_related_quantity']; if ($as_money_string) { return float_to_money_string($price); } else { return $price; } }
$parts = Part::get_order_parts($database, $current_user, $log, array($selected_supplier_id)); } else { $parts = Part::get_order_parts($database, $current_user, $log); } // parts from ALL suppliers $sum_price = 0; foreach ($parts as $part) { $orderdetails = $part->get_order_orderdetails(); if (is_object($orderdetails)) { $sum_price += $orderdetails->get_price(false, $part->get_order_quantity()); } } $table_loop = Part::build_template_table_array($parts, 'order_parts'); $html->set_loop('table', $table_loop); $html->set_variable('table_rowcount', count($parts), 'integer'); $html->set_variable('sum_price', float_to_money_string($sum_price), 'string'); } catch (Exception $e) { $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red'); $fatal_error = true; } } /******************************************************************************** * * Generate "Devices to order"-Table * *********************************************************************************/ if (!$fatal_error) { try { $order_devices = Device::get_order_devices($database, $current_user, $log); $order_devices_loop = array(); $row_odd = true;
/** * @brief Get the sum price of all parts in stock * * This method is used in statistics.php. * * @param Database &$database reference to the database object * @param User &$current_user reference to the user which is logged in * @param Log &$log reference to the Log-object * @param boolean $as_money_string @li if true, the price will be returned as a money string * (with currency) * @li if false, the price will be returned as a float * * @retval string sum price as a money string with currency (if "$as_money_string == true") * @retval float sum price as a float (if "$as_money_string == false") * * @throws Exception if there was an error */ public static function get_sum_price_instock(&$database, &$current_user, &$log, $as_money_string = true) { if (get_class($database) != 'Database') { throw new Exception('$database ist kein Database-Objekt!'); } $query = 'SELECT part_id, min_discount_quantity, price_related_quantity, price, instock FROM pricedetails ' . 'LEFT JOIN orderdetails ON pricedetails.orderdetails_id=orderdetails.id ' . 'LEFT JOIN parts ON orderdetails.part_id=parts.id ' . 'WHERE min_discount_quantity <= instock ' . 'ORDER BY part_id ASC, min_discount_quantity DESC'; $query_data = $database->query($query); $price_sum = 0.0; $id = -1; $instock = 0; foreach ($query_data as $row) { if ($id != $row['part_id']) { $id = $row['part_id']; $instock = $row['instock']; } if ($instock == 0) { continue; } $price_per_piece = $row['price'] / $row['price_related_quantity']; $taken_parts = $row['min_discount_quantity'] * (int) ($instock / $row['min_discount_quantity']); $price_sum += $price_per_piece * $taken_parts; $instock = $instock - $taken_parts; } $price_sum = round($price_sum, 2); if ($as_money_string) { return float_to_money_string($price_sum); } else { return $price_sum; } }
/** * @brief Get the total price of all parts in this device (counted with their mount quantity) * * @note To calculate the price, the average prices of the parts will be used. * More details: Part::get_average_price() * * @warning If some parts don't have a price, they will be ignored! * Only parts with at least one price will be counted. * * @param boolean $as_money_string @li if true, this method will return the price as a string incl. currency * @li if false, this method will return the price as a float * @param boolean $recursive if true, the parts of all subdevicess will be counted too * * @retval string the price as a formatted string with currency (if "$as_money_string == true") * @retval float the price as a float (if "$as_money_string == false") * * @see float_to_money_string() * * @throws Exception if there was an error */ public function get_total_price($as_money_string = true, $recursive = false) { $price = 0; $device_parts = $this->get_parts($recursive); foreach ($device_parts as $device_part) { $price += $device_part->get_part()->get_average_price(false, $device_part->get_mount_quantity()); } if ($as_money_string) { return float_to_money_string($price); } else { return $price; } }