Exemplo n.º 1
0
 *   Execute actions
 *
 *********************************************************************************/
if (!$fatal_error) {
    switch ($action) {
        case 'apply_changes':
            // save new "selected_supplier" + "order_quantity", and delete or change "instock"
            for ($i = 0; $i < $table_rowcount; $i++) {
                $part_id = isset($_REQUEST['id_' . $i]) ? (int) $_REQUEST['id_' . $i] : 0;
                $order_orderdetails_id = isset($_REQUEST['orderdetails_' . $i]) ? (int) $_REQUEST['orderdetails_' . $i] : 0;
                $order_quantity = isset($_REQUEST['order_quantity_' . $i]) ? max(0, (int) $_REQUEST['order_quantity_' . $i]) : 0;
                try {
                    $part = new Part($database, $current_user, $log, $part_id);
                    $part->set_order_orderdetails_id($order_orderdetails_id);
                    $part->set_order_quantity($order_quantity);
                    if (isset($_REQUEST['remove_' . $i]) && $part->get_manual_order()) {
                        $part->set_manual_order(false);
                    }
                    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 {
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 $html->set_variable('name', $part->get_name(), 'string');
 $html->set_variable('manufacturer_product_url', $part->get_manufacturer_product_url(), 'string');
 $html->set_variable('description', $part->get_description(), 'string');
 $html->set_variable('category_full_path', $part->get_category()->get_full_path(), 'string');
 $html->set_variable('instock', $part->get_instock(), 'integer');
 $html->set_variable('mininstock', $part->get_mininstock(), 'integer');
 $html->set_variable('visible', $part->get_visible(), 'boolean');
 $html->set_variable('comment', nl2br($part->get_comment()), 'string');
 $html->set_variable('footprint_full_path', is_object($footprint) ? $footprint->get_full_path() : '-', 'string');
 $html->set_variable('footprint_filename', is_object($footprint) ? str_replace(BASE, BASE_RELATIVE, $footprint->get_filename()) : '', 'string');
 $html->set_variable('storelocation_full_path', is_object($storelocation) ? $storelocation->get_full_path() : '-', 'string');
 $html->set_variable('storelocation_is_full', is_object($storelocation) ? $storelocation->get_is_full() : false, 'boolean');
 $html->set_variable('manufacturer_full_path', is_object($manufacturer) ? $manufacturer->get_full_path() : '-', 'string');
 $html->set_variable('category_full_path', is_object($category) ? $category->get_full_path() : '-', 'string');
 $html->set_variable('auto_order_exists', $part->get_instock() < $part->get_mininstock(), 'boolean');
 $html->set_variable('manual_order_exists', $part->get_manual_order() && $part->get_instock() >= $part->get_mininstock(), 'boolean');
 // build orderdetails loop
 $orderdetails_loop = array();
 $row_odd = true;
 foreach ($all_orderdetails as $orderdetails) {
     $pricedetails_loop = array();
     foreach ($orderdetails->get_pricedetails() as $pricedetails) {
         $pricedetails_loop[] = array('min_discount_quantity' => $pricedetails->get_min_discount_quantity(), 'price' => $pricedetails->get_price(true, $pricedetails->get_price_related_quantity()), 'price_related_quantity' => $pricedetails->get_price_related_quantity(), 'single_price' => $pricedetails->get_price(true, 1));
     }
     $orderdetails_loop[] = array('row_odd' => $row_odd, 'supplier_full_path' => $orderdetails->get_supplier()->get_full_path(), 'supplierpartnr' => $orderdetails->get_supplierpartnr(), 'supplier_product_url' => $orderdetails->get_supplier_product_url(), 'obsolete' => $orderdetails->get_obsolete(), 'pricedetails' => count($pricedetails_loop) > 0 ? $pricedetails_loop : NULL);
     $row_odd = !$row_odd;
 }
 $html->set_loop('orderdetails', $orderdetails_loop);
 if ($part->get_average_price(false, 1) > 0) {
     $html->set_variable('average_price', $part->get_average_price(true, 1), 'string');
 }