/** * Get color of service * * @param string $default * @return string */ public function getColor($default = '#DDDDDD') { if (!$this->isLoaded()) { return $default; } $service = new AB_Service(); if ($service->load($this->get('service_id'))) { return $service->get('color'); } return $default; }
/** * Get service. * * @return AB_Service */ public function getService() { $service = new AB_Service(); $service->load($this->get('service_id')); return $service; }
public function executeAssignStaff() { $service_id = $this->getParameter('service_id', 0); $staff_ids = $this->getParameter('staff_ids', array()); if ($service_id) { $this->getWpdb()->delete(AB_StaffService::getTableName(), array('service_id' => $service_id), array('%d')); $service = new AB_Service(); if (!empty($staff_ids) && $service->load($service_id)) { foreach ($staff_ids as $staff_id) { $staff_service = new AB_StaffService(); $staff_service->set('staff_id', $staff_id); $staff_service->set('service_id', $service_id); $staff_service->set('price', $service->get('price')); $staff_service->save(); } } wp_send_json_success(count($staff_ids)); } wp_send_json_error(); }
public function executeAssignStaff() { $service_id = $this->getParameter('service_id', 0); $staff_ids = $this->getParameter('staff_ids', array()); if ($service_id) { $this->getWpdb()->delete('ab_staff_service', array('service_id' => $service_id), array('%d')); $service = new AB_Service(); if (!empty($staff_ids) && $service->load($service_id)) { foreach ($staff_ids as $staff_id) { $staff_service = new AB_StaffService(); $staff_service->set('staff_id', $staff_id); $staff_service->set('service_id', $service_id); $staff_service->set('price', $service->get('price')); $staff_service->save(); } } echo count($staff_ids); exit; } }
/** * 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); }
/** * Get item data for cart. * * @param $other_data * @param $cart_item * * @return array */ function getItemData($other_data, $cart_item) { if (isset($cart_item['bookly'])) { $info_name = get_option('ab_woocommerce_cart_info_name'); $info_value = get_option('ab_woocommerce_cart_info_value'); $staff = new AB_Staff(); $staff->load($cart_item['bookly']['staff_ids'][0]); $service = new AB_Service(); $service->load($cart_item['bookly']['service_id']); $info_value = strtr($info_value, array('[[APPOINTMENT_TIME]]' => AB_DateTimeUtils::formatTime($cart_item['bookly']['appointment_datetime']), '[[APPOINTMENT_DATE]]' => AB_DateTimeUtils::formatDate($cart_item['bookly']['appointment_datetime']), '[[CATEGORY_NAME]]' => $service->getCategoryName(), '[[SERVICE_NAME]]' => $service->getTitle(), '[[SERVICE_PRICE]]' => $service->get('price'), '[[STAFF_NAME]]' => $staff->get('full_name'))); $other_data[] = array('name' => $info_name, 'value' => $info_value); } return $other_data; }
public function executeRenderPayment() { $form_id = $this->getParameter('form_id'); $response = null; if ($form_id) { $payment_disabled = AB_BookingConfiguration::isPaymentDisabled(); $this->userData = new AB_UserBookingData($form_id); $this->userData->load(); if ($this->userData->hasData()) { if ($this->userData->getServicePrice() <= 0) { $payment_disabled = true; } } if ($payment_disabled == false) { $this->form_id = $form_id; $this->info_text = nl2br(esc_html(get_option('ab_appearance_text_info_fourth_step'))); $this->info_text_coupon = $this->_prepareInfoText(4, $this->userData); if ($this->userData->hasData()) { $employee = new AB_Staff(); $employee->load($this->userData->getStaffId()); $service = new AB_Service(); $service->load($this->userData->getServiceId()); $price = $this->getWpdb()->get_var($this->getWpdb()->prepare(' SELECT price FROM ab_staff_service WHERE staff_id = %d AND service_id = %d', $employee->get('id'), $service->get('id'))); $this->_prepareProgressTracker(4, $price); // Set response. $response = array('status' => 'success', 'html' => $this->render('payment', array(), false)); } else { if (isset($_SESSION['tmp_booking_data'])) { $tmp_booking_data = AB_CommonUtils::getTemporaryBookingData(); if (!empty($tmp_booking_data)) { $tmp_form_id = $tmp_booking_data['form_id']; if (isset($_SESSION['appointment_booking'][$tmp_form_id]) && $_SESSION['appointment_booking'][$tmp_form_id]['cancelled'] === true) { $employee = new AB_Staff(); $employee->load($tmp_booking_data['staff_id'][0]); $service = new AB_Service(); $service->load($tmp_booking_data['service_id']); $price = $this->getWpdb()->get_var($this->getWpdb()->prepare(' SELECT price FROM ab_staff_service WHERE staff_id = %d AND service_id = %d', $employee->get('id'), $service->get('id'))); // create a paypal object $paypal = new PayPal(); $product = new stdClass(); $product->name = $service->get('title'); $product->desc = $service->getTitleWithDuration(); $product->price = $price; $product->qty = 1; $paypal->addProduct($product); // get the products information from the $_POST and create the Product objects $this->paypal = $paypal; $this->_prepareProgressTracker(4, $price); $error_msg = isset($_SESSION['appointment_booking'][$tmp_form_id]['paypal_error']) ? $_SESSION['appointment_booking'][$tmp_form_id]['paypal_error'] : ""; unset($_SESSION['appointment_booking'][$tmp_form_id]['paypal_error']); // Set response. $response = array('status' => 'success', 'html' => $this->render('payment', array('form_id' => $tmp_form_id, 'error_msg' => $error_msg), false)); } } } } } } // Output JSON response. if ($response === null) { $response = array('status' => 'no-data'); } header('Content-Type: application/json'); echo json_encode($response); exit(0); }
public function executeCheckAppointmentDateSelection() { $start_date = $this->getParameter('start_date'); $end_date = $this->getParameter('end_date'); $staff_id = $this->getParameter('staff_id'); $service_id = $this->getParameter('service_id'); $appointment_id = $this->getParameter('appointment_id'); $timestamp_diff = strtotime($end_date) - strtotime($start_date); $result = array('date_interval_not_available' => false, 'date_interval_warning' => false); if (!$this->dateIntervalIsAvailableForAppointment($start_date, $end_date, $staff_id, $appointment_id)) { $result['date_interval_not_available'] = true; } if ($service_id) { $service = new AB_Service(); $service->load($service_id); $duration = $service->get('duration'); // service duration interval is not equal to $result['date_interval_warning'] = $timestamp_diff != $duration; } echo json_encode($result); 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; }
/** * @param AB_Appointment $appointment */ private function handleEventData(AB_Appointment $appointment) { $start_datetime = new Google_Service_Calendar_EventDateTime(); $start_datetime->setDateTime(DateTime::createFromFormat('Y-m-d H:i:s', $appointment->get('start_date'), new DateTimeZone(AB_Utils::getTimezoneString()))->format(DateTime::RFC3339)); $end_datetime = new Google_Service_Calendar_EventDateTime(); $end_datetime->setDateTime(DateTime::createFromFormat('Y-m-d H:i:s', $appointment->get('end_date'), new DateTimeZone(AB_Utils::getTimezoneString()))->format(DateTime::RFC3339)); $service = new AB_Service(); $service->load($appointment->get('service_id')); $description = __('Service', 'bookly') . ": " . $service->get('title') . PHP_EOL; $client_names = array(); foreach ($appointment->getCustomerAppointments() as $ca) { $description .= sprintf("%s: %s\n%s: %s\n%s: %s\n", __('Name', 'bookly'), $ca->customer->get('name'), __('Email', 'bookly'), $ca->customer->get('email'), __('Phone', 'bookly'), $ca->customer->get('phone')); $description .= $ca->getFormattedCustomFields('text'); $description .= PHP_EOL; $client_names[] = $ca->customer->get('name'); } $staff = new AB_Staff(); $staff->load($appointment->get('staff_id')); $title = strtr(get_option('ab_settings_google_event_title', '[[SERVICE_NAME]]'), array('[[SERVICE_NAME]]' => $service->get('title'), '[[CLIENT_NAMES]]' => implode(', ', $client_names), '[[STAFF_NAME]]' => $staff->get('full_name'))); $this->event->setStart($start_datetime); $this->event->setEnd($end_datetime); $this->event->setSummary($title); $this->event->setDescription($description); $extended_property = new Google_Service_Calendar_EventExtendedProperties(); $extended_property->setPrivate(array('customers' => json_encode(array_map(function ($ca) { return $ca->customer->get('id'); }, $appointment->getCustomerAppointments())), 'service_id' => $service->get('id'), 'appointment_id' => $appointment->get('id'))); $this->event->setExtendedProperties($extended_property); }