Пример #1
0
 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;
 }
Пример #2
0
function mods_update_ingred_qty($ordid, $ingredid, $value)
{
    $query = "SELECT * FROM `orders` WHERE `associated_id`='" . $ordid . "' AND `ingredid` = '" . $ingredid . "'";
    $res = common_query($query, __FILE__, __LINE__);
    if (!$res) {
        return mysql_errno();
    }
    $arr = mysql_fetch_array($res);
    if (!$arr && $value == 0) {
        return 0;
    } elseif (!$arr && $value != 0) {
        $ord = new order($ordid);
        $ord->ingredients_arrays();
        if (in_array($ingredid, $ord->ingredients['nominal'])) {
            $ord = new order($ordid);
            $operation = 0;
            $err = mods_create_ingreds($ord, $ingredid, $operation);
            if ($err) {
                return ERR_MOD_NOT_CREATED;
            }
            $query = "SELECT * FROM `orders` WHERE `associated_id`='" . $ordid . "' AND `ingredid` = '" . $ingredid . "'";
            $res = common_query($query, __FILE__, __LINE__);
            if (!$res) {
                return mysql_errno();
            }
            $arr = mysql_fetch_array($res);
        }
    }
    $id = (int) $arr['associated_id'];
    $ord = new order($id);
    $ord->ingredients_arrays();
    if ($value == 0 && $arr['operation'] == 0) {
        $query = "DELETE FROM `orders` WHERE `id`='" . $arr['id'] . "'";
        $res = common_query($query, __FILE__, __LINE__);
        if (!$res) {
            return mysql_errno();
        }
    } elseif ($arr['operation'] != -1) {
        $query = "UPDATE `orders` SET `ingred_qty`='" . $value . "' WHERE `id`='" . $arr['id'] . "'";
        $res = common_query($query, __FILE__, __LINE__);
        if (!$res) {
            return mysql_errno();
        }
    }
    return 0;
}