/** * Delete an appointment forever * * @param $app_id * * @return bool|false|int */ function appointments_delete_appointment($app_id) { global $wpdb; $app = appointments_get_appointment($app_id); if (!$app) { return false; } $table = appointments_get_table('appointments'); $result = $wpdb->query($wpdb->prepare("DELETE FROM {$table} WHERE ID = %d", $app_id)); appointments_clear_appointment_cache($app_id); return (bool) $result; }
?> </td> <td class="column-user"> <?php echo $appointments->get_client_name($transaction->transaction_app_ID); ?> </td> <td class="column-date"> <?php echo date_i18n($appointments->datetime_format, $transaction->transaction_stamp); ?> </td> <td class="column-service"> <?php $app = appointments_get_appointment($transaction->transaction_app_ID); if ($app) { $service_id = $app->service; } echo $appointments->get_service_name($service_id); ?> </td> <td class="column-amount"> <?php $amount = $transaction->transaction_total_amount / 100; echo $transaction->transaction_currency; echo " " . number_format($amount, 2, '.', ','); ?> </td> <td class="column-transid"> <?php
function inline_edit_save() { global $appointments, $wpdb, $current_user; $app_id = absint($_POST["app_id"]); $app = appointments_get_appointment($app_id); $data = array(); $data['user'] = $_POST['user']; $data['email'] = !empty($_POST['email']) && is_email($_POST['email']) ? $_POST['email'] : ''; $data['name'] = $_POST['name']; $data['phone'] = $_POST['phone']; $data['address'] = $_POST['address']; $data['city'] = $_POST['city']; $data['service'] = $_POST['service']; $data['worker'] = $_POST['worker']; $data['price'] = $_POST['price']; $data['note'] = $_POST['note']; $data['status'] = $_POST['status']; $data['date'] = $_POST['date']; $data['time'] = $_POST['time']; $resend = $_POST["resend"]; $data = apply_filters('app-appointment-inline_edit-save_data', $data); $update_result = $insert_result = false; if ($app) { // Update $update_result = appointments_update_appointment($app_id, $data); if ($update_result) { if (('pending' == $data['status'] || 'removed' == $data['status'] || 'completed' == $data['status']) && is_object($appointments->gcal_api)) { $appointments->gcal_api->delete($app_id); } else { if (is_object($appointments->gcal_api) && $appointments->gcal_api->is_syncable_status($data['status'])) { $appointments->gcal_api->update($app_id); // This also checks for event insert } } } if ($resend && 'removed' != $data['status']) { appointments_send_confirmation($app_id); } } else { // Insert $app_id = appointments_insert_appointment($data); if ($app_id) { $insert_result = true; if ($resend) { appointments_send_confirmation($app_id); } $appointments->sms_new_appointment($app_id); } } do_action('app-appointment-inline_edit-after_save', $app_id, $data); do_action('app-appointment-inline_edit-before_response', $app_id, $data); $app = appointments_get_appointment($app_id); if (!$app) { $insert_result = false; $update_result = false; } // Move mail sending here so the fields can expand if ($insert_result && is_object($appointments->gcal_api) && $appointments->gcal_api->is_syncable_status($data['status'])) { $appointments->gcal_api->insert($app->ID); } $result = array('app_id' => 0, 'message' => ''); if ($update_result) { // Log change of status if ($data['status'] != $app->status) { $appointments->log(sprintf(__('Status changed from %s to %s by %s for appointment ID:%d', 'appointments'), $app->status, $data["status"], $current_user->user_login, $app->ID)); } $result = array('app_id' => $app->ID, 'message' => __('<span style="color:green;font-weight:bold">Changes saved.</span>', 'appointments')); } else { if ($insert_result) { $result = array('app_id' => $app->ID, 'message' => __('<span style="color:green;font-weight:bold">Changes saved.</span>', 'appointments')); } else { $message = $resend && !empty($data['status']) && 'removed' != $data['status'] ? sprintf('<span style="color:green;font-weight:bold">%s</span>', __('Confirmation message (re)sent', 'appointments')) : sprintf('<span style="color:red;font-weight:bold">%s</span>', __('Record could not be saved OR you did not make any changes!', 'appointments')); $result = array('app_id' => $app_id, 'message' => $message); } } $result = apply_filters('app-appointment-inline_edit-result', $result, $app_id, $data); die(json_encode($result)); }
function test_delete_appointment() { $worker_id = $this->factory->user->create_object($this->factory->user->generate_args()); $user_id = $this->factory->user->create_object($this->factory->user->generate_args()); $service_args = array('name' => 'My Service', 'duration' => 90); $service_id = appointments_insert_service($service_args); $worker_args = array('ID' => $worker_id, 'services_provided' => array($service_id)); appointments_insert_worker($worker_args); $args = array('user' => $user_id, 'email' => '*****@*****.**', 'name' => 'Tester', 'phone' => '667788', 'address' => 'An address', 'city' => 'Madrid', 'service' => $service_id, 'worker' => $worker_id, 'price' => '90', 'date' => 'December 18, 2024', 'time' => '07:30', 'note' => 'It\'s a note', 'status' => 'paid', 'location' => 5); $app_id = appointments_insert_appointment($args); $app = appointments_get_appointment($app_id); appointments_delete_appointment($app_id); $app = appointments_get_appointment($app_id); $this->assertFalse($app); }