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; }
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; }