function orders_delete($start_data)
{
    global $tpl;
    $id = (int) $start_data['id'];
    $ord = new order($id);
    if (!$ord->data['deleted'] && $ord->data['printed'] && $ord->data['dishid'] != SERVICE_ID) {
        if ($err = print_ticket($id, true)) {
            return $err;
        }
    }
    if (CONF_DEBUG_DONT_DELETE) {
        return 0;
    }
    // was as follows, but it's better to never delete an order if the table is still open
    if ($ord->data['dishid'] != SERVICE_ID) {
        $start_data['deleted'] = 1;
        $start_data['paid'] = 1;
        $start_data['suspend'] = 0;
        $start_data['printed'] = '0000-00-00 00:00:00';
        $start_data['price'] = 0;
        $err = orders_update($start_data);
    } else {
        // insert all the modules interfaces for order creation here
        toplist_delete($ord->data['dishid'], $ord->data['quantity']);
        if (class_exists('stock_object')) {
            $stock = new stock_object();
            $stock->silent = true;
            $stock->remove_from_waiter($id, 0);
        }
        $err = $ord->delete();
    }
    unset($ord);
    return $err;
}
Esempio n. 2
0
function mods_create_ingreds($ord, $ingredid, $operation)
{
    $query = "SELECT * FROM `orders` WHERE `associated_id`='" . $ord->id . "' AND `ingredid` = '" . $ingredid . "'";
    $res = common_query($query, __FILE__, __LINE__);
    if (!$res) {
        return mysql_errno();
    }
    $antiop = $operation * -1;
    // if order is found and is opposite to the wanted one, we simply delete it,
    // otherwise we create the wanted order
    if (mysql_num_rows($res)) {
        $arr = mysql_fetch_array($res);
        if ($arr['operation'] == $antiop) {
            $ord_ingid = (int) $arr['id'];
            $ord_ing = new order($ord_ingid);
            if (class_exists('stock_object')) {
                $stock = new stock_object();
                $stock->silent = true;
                $stock->remove_from_waiter($ord_ing->id, 0);
            }
            if ($err = $ord_ing->delete()) {
                return $err;
            }
        }
    } else {
        $ord_ing = new order();
        $ord_ing->data = $ord->data;
        // now unsets some vars that we don't want to copy
        unset($ord_ing->data['id']);
        unset($ord_ing->data['associated_id']);
        unset($ord_ing->data['price']);
        unset($ord_ing->data['timestamp']);
        // set quantity to 0 to start with empty order (for stock function)
        $ord_ing->data['quantity'] = 0;
        $ord_ing->data['dishid'] = MOD_ID;
        $ord_ing->data['ingredid'] = $ingredid;
        $ord_ing->data['associated_id'] = $ord->id;
        $err = $ord_ing->create();
        $ord_ing->data['operation'] = $operation;
        $ord_ing->data['quantity'] = $ord->data['quantity'];
        if (class_exists('stock_object')) {
            $stock = new stock_object();
            $stock->silent = true;
            $stock->remove_from_waiter($ord_ing->id, $ord->data['quantity']);
        }
        $err += $ord_ing->set();
        if ($err) {
            return 1;
        }
    }
    return 0;
}