Пример #1
0
 function pre_delete($input_data)
 {
     if (!$this->id) {
         return 1;
     }
     if (!$this->exists()) {
         return 2;
     }
     if ($lang_del = $this->translations_delete($this->id)) {
         return $lang_del;
     }
     $stock = new stock_object();
     if ($stock_id = $stock->find_external($this->id, TYPE_DISH)) {
         $stock = new stock_object($stock_id);
         $stock->silent = true;
         if ($err = $stock->delete()) {
             return $err;
         }
     }
     return $input_data;
 }
Пример #2
0
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;
}
Пример #3
0
function mods_create_order($start_data)
{
    $id = (int) $start_data['id'];
    $old = new order($id);
    // requantify the old order
    $old->data['quantity'] = $old->data['quantity'] - $start_data['quantity'];
    if (class_exists('stock_object')) {
        $stock = new stock_object();
        $stock->silent = true;
        $stock->remove_from_waiter($old->id, $old->data['quantity']);
    }
    $err = $old->set();
    if ($err) {
        return 1;
    }
    // quantity set error
    // creates the new order;
    $arr['quantity'] = 0;
    $newid = orders_create($ord->data['dishid'], $arr);
    if ($newid == 0) {
        return 1;
    }
    // order not created
    $newid = (int) $newid;
    $new = new order($newid);
    $olddata = $old->data;
    // copies old order's data
    // now unsets some vars that we don't want to copy
    unset($olddata['id']);
    unset($olddata['associated_id']);
    unset($olddata['price']);
    unset($olddata['timestamp']);
    $new->data = $olddata;
    //first set() without quantity for stock function
    $new->data['quantity'] = 0;
    $err = $new->set();
    $new->data['quantity'] = $start_data['quantity'];
    if (class_exists('stock_object')) {
        $stock = new stock_object();
        $stock->silent = true;
        $stock->remove_from_waiter($new->id, $new->data['quantity']);
    }
    $err = $new->set();
    if ($err) {
        return 1;
    }
    // Now we set $start_data[id] to the new order, because we're going to work on it, and leave the old one
    $GLOBALS['start_data']['id'] = $new->id;
    return 0;
}
Пример #4
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;
 }
Пример #5
0
 function post_insert($input_data)
 {
     if (empty($input_data['obj_id'])) {
         return ERR_NO_STOCK_OBJECT_CHOSEN;
     }
     $stock = new stock_object($input_data['obj_id']);
     $stock_data = array();
     $stock_data['id'] = $input_data['obj_id'];
     $stock_data['value'] = $this->unitary_value($input_data);
     $stock_data['quantity'] = $stock->data['quantity'] + $input_data['quantity'];
     $stock_data['name'] = $stock->data['name'];
     $stock_data['ref_type'] = $stock->data['ref_type'];
     $stock_data['ref_id'] = $stock->data['ref_id'];
     $stock_data['deleted'] = $stock->data['deleted'];
     $stock_data['unit_type'] = $input_data['unit_type'];
     $stock_data['from'] = 'movement';
     $stock->silent = true;
     if ($err = $stock->update($stock_data)) {
         return $err;
     }
     $this->last_updated_stock_object = $input_data['obj_id'];
     return 0;
 }