/** * @brief Create a new orderdetails record * * @param Database &$database reference to the database onject * @param User &$current_user reference to the current user which is logged in * @param Log &$log reference to the Log-object * @param integer $part_id the ID of the part with that the orderdetails is associated * @param integer $supplier_id the ID of the supplier (see Orderdetails::set_supplier_id()) * @param string $supplierpartnr the supplier-part-nr (see Orderdetails::set_supplierpartnr()) * @param boolean $obsolete the obsolete attribute of the new orderdetails (see Orderdetails::set_obsolete()) * * @retval Orderdetails the new orderdetails object * * @throws Exception if (this combination of) values is not valid * @throws Exception if there was an error * * @see DBElement::add() */ public static function add(&$database, &$current_user, &$log, $part_id, $supplier_id, $supplierpartnr = '', $obsolete = false) { return parent::add($database, $current_user, $log, 'orderdetails', array('part_id' => $part_id, 'id_supplier' => $supplier_id, 'supplierpartnr' => $supplierpartnr, 'obsolete' => $obsolete)); }
/** * @copydoc DBElement::check_values_validity() */ public static function check_values_validity(&$database, &$current_user, &$log, &$values, $is_new, &$element = NULL) { // first, we let all parent classes to check the values parent::check_values_validity($database, $current_user, $log, $values, $is_new, $element); // we trim the name (spaces at the begin or at the end of a name are ugly, so we remove them) $values['name'] = trim($values['name']); if (empty($values['name'])) { // empty names are not allowed! throw new Exception('Der neue Name ist leer, das ist nicht erlaubt!'); } }
/** * @brief Create a new orderdetails record * * @param Database &$database reference to the database onject * @param User &$current_user reference to the current user which is logged in * @param Log &$log reference to the Log-object * @param integer $orderdetails_id the ID of the orderdetails with that the pricedetails is associated * @param float $price the price of the part (see Pricedetails::set_price()) * @param integer $price_related_quantity the price related quantity (see Pricedetails::set_price_related_quantity()) * @param integer $min_discount_quantity the minimum discount quantity (see Pricedetails::set_min_discount_quantity()) * * @note The database column "last_update" will be filled automatically * in Pricedetails::check_values_validity(). * * @warning The attribute "min_discount_quantity" must be "1" if there are no other * pricedetails in the selected orderdetails yet! * * @retval Pricedetails the new Pricedetails object * * @throws Exception if (this combination of) values is not valid * @throws Exception if there was an error * * @see DBElement::add() */ public static function add(&$database, &$current_user, &$log, $orderdetails_id, $price, $price_related_quantity = 1, $min_discount_quantity = 1) { return parent::add($database, $current_user, $log, 'pricedetails', array('orderdetails_id' => $orderdetails_id, 'manual_input' => true, 'price' => $price, 'price_related_quantity' => $price_related_quantity, 'min_discount_quantity' => $min_discount_quantity)); }
/** * @brief Create a new device-part * * @param Database &$database reference to the database object * @param User &$current_user reference to the current user which is logged in * @param Log &$log reference to the Log-object * @param integer $device_id the ID of the device * @param integer $part_id the ID of the part * @param integer $quantity the mount quantity (see DevicePart::set_mount_quantity()) * @param string $mountnames the mountname(s) (see DevicePart::set_mount_name()) * @param boolean $increase_if_exist @li if true, and there is already a DevicePart with the same * part ID + device ID, the mount quantity of the existing * DevicePart will be incremented by $quantity. In addition, * the new mount name ($mountname) will be attached (with a * comma) at the end of the mount name of the existing DevicePart. * @li if false, and there is already a DevicePart with the same * part ID + device ID, this method will throw an exception. * * @retval DevicePart the new device-part * @retval DevicePart the existing device-part, if there is already a DevicePart with * the same part ID + device ID and "$increment_if_exist == true" * * @throws Exception if (this combination of) values is not valid * @throws Exception if there was an error * * @see DBElement::add() */ public static function add(&$database, &$current_user, &$log, $device_id, $part_id, $quantity, $mountnames = '', $increase_if_exist = false) { $existing_devicepart = DevicePart::get_device_part($database, $current_user, $log, $device_id, $part_id); if (is_object($existing_devicepart)) { if ($increase_if_exist) { if (!is_int($quantity) && !ctype_digit($quantity) || $quantity < 0) { debug('error', 'quantity = "' . $quantity . '"', __FILE__, __LINE__, __METHOD__); throw new Exception('Die Bestückungs-Anzahl ist ungültig!'); } $quantity = $existing_devicepart->get_mount_quantity() + $quantity; $old_mountnames = $existing_devicepart->get_mount_names(); if (strlen($mountnames) > 0) { if (strlen($old_mountnames) > 0) { $mountnames = $old_mountnames . ', ' . $mountnames; } } else { $mountnames = $old_mountnames; } $existing_devicepart->set_attributes(array('quantity' => $quantity, 'mountnames' => $mountnames)); return $existing_devicepart; } else { $device = new Device($database, $current_user, $log, $device_id); $part = new Part($database, $current_user, $log, $part_id); throw new Exception('Die Baugruppe "' . $device->get_name() . '" enthält bereits das Bauteil "' . $part->get_name() . '"!'); } } // there is no such DevicePart, so we will create it return parent::add($database, $current_user, $log, 'device_parts', array('id_device' => $device_id, 'id_part' => $part_id, 'quantity' => $quantity, 'mountnames' => $mountnames)); }