/**
  * Delete customer appointment.
  */
 public function executeDeleteCustomerAppointment()
 {
     $customer_appointment = new AB_CustomerAppointment();
     $customer_appointment->load($this->getParameter('id'));
     $appointment = new AB_Appointment();
     $appointment->load($customer_appointment->get('appointment_id'));
     $customer_appointment->delete();
     // Delete appointment, if there aren't customers.
     $count = AB_CustomerAppointment::query()->where('appointment_id', $customer_appointment->get('appointment_id'))->count();
     if (!$count) {
         $appointment->delete();
     } else {
         $appointment->handleGoogleCalendar();
     }
     wp_send_json_success();
 }
Пример #2
0
 /**
  * Cancel Appointment using token.
  */
 public function executeCancelAppointment()
 {
     $customer_appointment = new AB_CustomerAppointment();
     if ($customer_appointment->loadBy(array('token' => $this->getParameter('token')))) {
         // Send email.
         AB_NotificationSender::send(AB_NotificationSender::INSTANT_CANCELLED_APPOINTMENT, $customer_appointment);
         $customer_appointment->delete();
         $appointment = new AB_Appointment();
         $appointment->load($customer_appointment->get('appointment_id'));
         // Delete appointment, if there aren't customers.
         $count = AB_CustomerAppointment::query('ca')->where('ca.appointment_id', $customer_appointment->get('appointment_id'))->count();
         if (!$count) {
             $appointment->delete();
         } else {
             $appointment->handleGoogleCalendar();
         }
         if ($this->url = get_option('ab_settings_cancel_page_url')) {
             wp_redirect($this->url);
             $this->render('cancel_appointment');
             exit(0);
         }
     }
     $this->url = home_url();
     if (isset($_SERVER['HTTP_REFERER'])) {
         if (parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) == parse_url($this->url, PHP_URL_HOST)) {
             // Redirect back if user came from our site.
             $this->url = $_SERVER['HTTP_REFERER'];
         }
     }
     wp_redirect($this->url);
     $this->render('cancel_appointment');
     exit(0);
 }
Пример #3
0
 /**
  * Prepare data for email.
  *
  * @param AB_CustomerAppointment $ca
  * @return array
  */
 private static function _prepareData(AB_CustomerAppointment $ca)
 {
     $appointment = new AB_Appointment();
     $appointment->load($ca->get('appointment_id'));
     $customer = new AB_Customer();
     $customer->load($ca->get('customer_id'));
     $staff = new AB_Staff();
     $staff->load($appointment->get('staff_id'));
     $service = new AB_Service();
     $service->load($appointment->get('service_id'));
     $staff_service = new AB_StaffService();
     $staff_service->loadBy(array('staff_id' => $staff->get('id'), 'service_id' => $service->get('id')));
     $price = $staff_service->get('price');
     if ($ca->get('coupon_discount') or $ca->get('coupon_deduction')) {
         $coupon = new AB_Coupon();
         $coupon->set('discount', $ca->get('coupon_discount'));
         $coupon->set('deduction', $ca->get('coupon_deduction'));
         $price = $coupon->apply($price);
     }
     $codes = new AB_NotificationCodes();
     $codes->set('appointment_datetime', $appointment->get('start_date'));
     $codes->set('appointment_token', $ca->get('token'));
     $codes->set('category_name', $service->getCategoryName());
     $codes->set('client_name', $customer->get('name'));
     $codes->set('client_phone', $customer->get('phone'));
     $codes->set('client_email', $customer->get('email'));
     $codes->set('custom_fields', $ca->getFormattedCustomFields('text'));
     $codes->set('custom_fields_2c', $ca->getFormattedCustomFields('html'));
     $codes->set('number_of_persons', $ca->get('number_of_persons'));
     $codes->set('service_name', $service->getTitle());
     $codes->set('service_price', $price);
     $codes->set('staff_name', $staff->get('full_name'));
     $codes->set('staff_email', $staff->get('email'));
     $codes->set('staff_phone', $staff->get('phone'));
     $codes->set('staff_photo', $staff->get('avatar_url'));
     return array($codes, $staff, $appointment, $customer);
 }
 /**
  * Cancel Appointment using token.
  */
 public function executeCancelAppointment()
 {
     $customer_appointment = new AB_Customer_Appointment();
     if ($customer_appointment->loadByToken($this->getParameter('token'))) {
         $customer_appointment->delete();
         // Delete appointment, if there aren't customers
         $current_capacity = $this->getWpdb()->get_var($this->getWpdb()->prepare('SELECT count(*) from `ab_customer_appointment` WHERE appointment_id = %d', $customer_appointment->get('appointment_id')));
         if (!$current_capacity) {
             $appointment = new AB_Appointment();
             $appointment->load($customer_appointment->get('appointment_id'));
             $appointment->delete();
         }
         if (get_option('ab_settings_cancel_page_url')) {
             exit(wp_redirect(get_option('ab_settings_cancel_page_url')));
         }
     }
     exit(wp_redirect(home_url()));
 }
 public function executeDeleteAppointment()
 {
     $appointment = new AB_Appointment();
     $appointment->load($this->getParameter('appointment_id'));
     $appointment->delete();
     exit;
 }
 /**
  * @return AB_Appointment
  */
 public function save()
 {
     /** @var wpdb $wpdb */
     global $wpdb;
     // #11094: if customer with such name & e-mail exists, append new booking to him, otherwise - create new customer
     $customer_exists = $wpdb->get_row($wpdb->prepare('SELECT * FROM ab_customer WHERE name = %s AND email = %s', $this->name, $this->email));
     $customer = new AB_Customer();
     if ($customer_exists) {
         $customer->set('id', $customer_exists->id);
         $customer->set('name', $customer_exists->name);
         $customer->set('email', $customer_exists->email);
         $customer->set('phone', $customer_exists->phone);
     } else {
         $customer->set('name', $this->name);
         $customer->set('email', $this->email);
         $customer->set('phone', $this->phone);
         $customer->save();
     }
     $this->customer_id = $customer->get('id');
     $service = new AB_Service();
     $service->load($this->service_id);
     $category = new AB_Category();
     $category->load($service->get('category_id'));
     /**
      * Get appointment, with same params.
      * If it is -> create connection to this appointment,
      * otherwise create appointment and connect customer to new appointment
      */
     $booking = $wpdb->get_row($wpdb->prepare("SELECT * from ab_appointment a WHERE a.staff_id = %d and a.service_id = %d and a.start_date = %s LIMIT 1;", $this->getStaffId(), $this->service_id, $this->booked_datetime));
     $appointment = new AB_Appointment();
     if ($booking) {
         $appointment->load($booking->id);
     } else {
         $appointment->set('staff_id', $this->getStaffId());
         $appointment->set('service_id', $this->service_id);
         $appointment->set('start_date', date('Y-m-d H:i:s', strtotime($this->booked_datetime)));
         $endDate = new DateTime($this->booked_datetime);
         $di = "+ {$service->get('duration')} sec";
         $endDate->modify($di);
         $appointment->set('end_date', $endDate->format('Y-m-d H:i:s'));
         $appointment->save();
     }
     $customer_appointment = new AB_Customer_Appointment();
     $customer_appointment->set('appointment_id', $appointment->get('id'));
     $customer_appointment->set('customer_id', $customer->get('id'));
     $customer_appointment->set('token', md5($this->form_id));
     $customer_appointment->set('notes', $this->notes);
     $customer_appointment->save();
     $staff = new AB_Staff();
     $staff->load($this->getStaffId());
     return $appointment;
 }