function remove_from_waiter($order_id, $new_quantity)
 {
     $order_id = (int) $order_id;
     $order = new order($order_id);
     $dish_id = $order->data['dishid'];
     if ($dish_id == MOD_ID) {
         $arr_ingreds[] = $order->data['ingredid'];
         $diffquantity = $order->data['quantity'] - $new_quantity;
         $order_id = (int) $order->data['associated_id'];
         $order = new order($order_id);
         $dish_id = $order->data['dishid'];
     } else {
         $order->ingredients_arrays();
         $arr_ingreds = $order->ingredients['contained'];
         $diffquantity = $order->data['quantity'] - $new_quantity;
     }
     if (!$diffquantity) {
         return 0;
     }
     // movements for all the contained ingredients
     foreach ($arr_ingreds as $ingred_id) {
         $stock_id = $this->find_external($ingred_id, TYPE_INGREDIENT);
         // object not found in stock
         if (!$stock_id) {
             continue;
         }
         $mov = new stock_movement();
         $mov_data['obj_id'] = $stock_id;
         $mov_data['dish_id'] = $dish_id;
         $mov_data['dish_quantity'] = $diffquantity;
         $stock = new stock_object($stock_id);
         $ingred_quantity = $stock->get_ingredient_quantity($dish_id);
         $mov_data['quantity'] = $mov_data['dish_quantity'] * $ingred_quantity;
         $mov_data['value'] = $stock->data['value'] * $mov_data['quantity'];
         $mov_data['unit_type'] = $stock->data['unit_type'];
         $mov->silent = true;
         if ($err = $mov->insert($mov_data)) {
             return $err;
         }
     }
     return 0;
 }