Exemple #1
0
 /**
  * @brief Get all parts which should be ordered
  *
  * "parts which should be ordered" means:
  * ((("instock" is less than "mininstock") AND (Part isn't already ordered))
  *  OR (Part was manually marked as "should be ordered"))
  *
  * @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 array     $supplier_ids       @li array of all supplier IDs which will be listed
  *                                      @li an empty array means, the parts from ALL suppliers will be listed
  * @param boolean   $with_devices       if true, parts which are in devices, marked as "to order", will be listed too
  *
  * @retval array    all parts as a one-dimensional array of Part objects, sorted by their names
  *
  * @throws Exception if there was an error
  */
 public static function get_order_parts(&$database, &$current_user, &$log, $supplier_ids = array(), $with_devices = true)
 {
     if (get_class($database) != 'Database') {
         throw new Exception('$database ist kein Database-Objekt!');
     }
     $parts = array();
     $query = 'SELECT parts.id FROM parts ' . 'LEFT JOIN orderdetails ON orderdetails.id = parts.order_orderdetails_id ' . 'WHERE (parts.instock < parts.mininstock ' . 'OR parts.manual_order = true ' . 'OR parts.id IN ' . '(SELECT device_parts.id_part FROM device_parts ' . 'LEFT JOIN devices ON devices.id = device_parts.id_device ' . 'WHERE devices.order_quantity > 0)) ';
     if (count($supplier_ids) > 0) {
         $query .= 'AND ((false) OR ';
         foreach ($supplier_ids as $id) {
             $query .= '(orderdetails.id_supplier <=> ?) ';
         }
         $query .= ') ';
     }
     $query .= 'ORDER BY parts.name ASC';
     $query_data = $database->query($query, $supplier_ids);
     foreach ($query_data as $row) {
         $part = new Part($database, $current_user, $log, $row['id']);
         if ($part->get_manual_order() || $part->get_min_order_quantity() > 0) {
             $parts[] = $part;
         }
     }
     return $parts;
 }
             }
             if (isset($_REQUEST['tostock_' . $i])) {
                 $part->set_instock($part->get_instock() + $order_quantity);
             }
         } catch (Exception $e) {
             $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
         }
     }
     $reload_site = true;
     break;
 case 'autoset_quantities':
     for ($i = 0; $i < $table_rowcount; $i++) {
         $part_id = isset($_REQUEST['id_' . $i]) ? (int) $_REQUEST['id_' . $i] : 0;
         try {
             $part = new Part($database, $current_user, $log, $part_id);
             $part->set_order_quantity($part->get_min_order_quantity());
         } catch (Exception $e) {
             $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
         }
     }
     $reload_site = true;
     break;
 case 'remove_device':
     try {
         $device = new Device($database, $current_user, $log, $device_id);
         $device->set_order_quantity(0);
         $reload_site = true;
     } catch (Exception $e) {
         $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
     }
     break;