/**
  * Do replacements.
  *
  * @param $text
  * @param string $type
  *
  * @return string
  */
 public function replace($text, $type = 'email')
 {
     // Company logo as <img> tag.
     $company_logo = '';
     if (get_option('ab_settings_company_logo_url') != '') {
         $company_logo = sprintf('<img src="%s" alt="%s" />', esc_attr(get_option('ab_settings_company_logo_url')), esc_attr(get_option('ab_settings_company_name')));
     }
     // Staff photo as <img> tag.
     $staff_photo = '';
     if ($this->data['staff_photo'] != '') {
         $staff_photo = sprintf('<img src="%s" alt="%s" />', esc_attr($this->get('staff_photo')), esc_attr($this->get('staff_name')));
     }
     // Cancel appointment URL and <a> tag.
     $cancel_appointment_url = admin_url('admin-ajax.php') . '?action=ab_cancel_appointment&token=' . $this->get('appointment_token');
     $cancel_appointment = sprintf('<a href="%1$s">%1$s</a>', $cancel_appointment_url);
     // Codes.
     $codes = array('[[APPOINTMENT_TIME]]' => AB_DateTimeUtils::formatTime($this->get('appointment_datetime')), '[[APPOINTMENT_DATE]]' => AB_DateTimeUtils::formatDate($this->get('appointment_datetime')), '[[CUSTOM_FIELDS]]' => $this->get('custom_fields'), '[[CUSTOM_FIELDS_2C]]' => $this->get('custom_fields_2c'), '[[CLIENT_NAME]]' => $this->get('client_name'), '[[CLIENT_PHONE]]' => $this->get('client_phone'), '[[CLIENT_EMAIL]]' => $this->get('client_email'), '[[SERVICE_NAME]]' => $this->get('service_name'), '[[SERVICE_PRICE]]' => AB_Utils::formatPrice($this->get('service_price')), '[[STAFF_EMAIL]]' => $this->get('staff_email'), '[[STAFF_NAME]]' => $this->get('staff_name'), '[[STAFF_PHONE]]' => $this->get('staff_phone'), '[[STAFF_PHOTO]]' => $staff_photo, '[[CANCEL_APPOINTMENT]]' => $cancel_appointment, '[[CANCEL_APPOINTMENT_URL]]' => $cancel_appointment_url, '[[CATEGORY_NAME]]' => $this->get('category_name'), '[[COMPANY_ADDRESS]]' => $type == 'email' ? nl2br(get_option('ab_settings_company_address')) : get_option('ab_settings_company_address'), '[[COMPANY_LOGO]]' => $company_logo, '[[COMPANY_NAME]]' => get_option('ab_settings_company_name'), '[[COMPANY_PHONE]]' => get_option('ab_settings_company_phone'), '[[COMPANY_WEBSITE]]' => get_option('ab_settings_company_website'), '[[NEXT_DAY_AGENDA]]' => $this->get('next_day_agenda'), '[[TOMORROW_DATE]]' => date_i18n(get_option('date_format'), strtotime($this->get('appointment_datetime'))), '[[TOTAL_PRICE]]' => AB_Utils::formatPrice($this->get('service_price') * $this->get('number_of_persons')), '[[NUMBER_OF_PERSONS]]' => $this->get('number_of_persons'), '[[SITE_ADDRESS]]' => $this->get('site_address'), '[[NEW_USERNAME]]' => $this->get('new_username'), '[[NEW_PASSWORD]]' => $this->get('new_password'));
     return strtr($text, $codes);
 }
 /**
  * Get list of customers.
  */
 public function executeGetCustomers()
 {
     $wpdb = $this->getWpdb();
     $response = array('customers' => array(), 'total' => 0, 'pages' => 0, 'active_page' => 0);
     $page = intval($this->getParameter('page'));
     $sort = in_array($this->getParameter('sort'), array('name', 'phone', 'email', 'notes', 'last_appointment', 'total_appointments', 'payments', 'wp_user')) ? $this->getParameter('sort') : 'name';
     $order = in_array($this->getParameter('order'), array('asc', 'desc')) ? $this->getParameter('order') : 'asc';
     $filter = $wpdb->_real_escape($this->getParameter('filter'));
     $items_per_page = 20;
     $total = AB_Customer::query()->count();
     $pages = ceil($total / $items_per_page);
     if ($page < 1 || $page > $pages) {
         $page = 1;
     }
     if ($total) {
         $query = AB_Customer::query('c')->select('c.*, MAX(a.start_date) AS last_appointment,
                 COUNT(a.id) AS total_appointments,
                 COALESCE(SUM(p.total),0) AS payments,
                 wpu.display_name AS wp_user')->leftJoin('AB_CustomerAppointment', 'ca', 'ca.customer_id = c.id')->leftJoin('AB_Appointment', 'a', 'a.id = ca.appointment_id')->leftJoin('AB_Payment', 'p', 'p.customer_appointment_id = ca.id')->tableJoin($wpdb->users, 'wpu', 'wpu.ID = c.wp_user_id');
         // WHERE
         if ($filter !== '') {
             $query->whereLike('c.name', "%{$filter}%")->whereLike('c.phone', "%{$filter}%", 'OR')->whereLike('c.email', "%{$filter}%", 'OR');
         }
         $data = $query->groupBy('c.id')->sortBy($sort)->order($order)->limit($items_per_page)->offset(($page - 1) * $items_per_page)->fetchArray();
         array_walk($data, function (&$row) {
             if ($row['last_appointment']) {
                 $row['last_appointment'] = AB_DateTimeUtils::formatDateTime($row['last_appointment']);
             }
             $row['payments'] = AB_Utils::formatPrice($row['payments']);
         });
         // Populate response.
         $response['customers'] = $data;
         $response['total'] = $total;
         $response['pages'] = $pages;
         $response['active_page'] = $page;
     }
     wp_send_json_success($response);
 }
 /**
  * Export Appointment to CSV
  */
 public function executeExportToCSV()
 {
     $start_date = new DateTime($this->getParameter('date_start'));
     $start_date = $start_date->format('Y-m-d H:i:s');
     $end_date = new DateTime($this->getParameter('date_end'));
     $end_date = $end_date->modify('+1 day')->format('Y-m-d H:i:s');
     $delimiter = $this->getParameter('delimiter', ',');
     header('Content-Type: text/csv; charset=utf-8');
     header('Content-Disposition: attachment; filename=Appointments.csv');
     $header = array(__('Booking Time', 'bookly'), __('Staff Member', 'bookly'), __('Service', 'bookly'), __('Duration', 'bookly'), __('Price', 'bookly'), __('Customer', 'bookly'), __('Phone', 'bookly'), __('Email', 'bookly'));
     $custom_fields = array();
     $fields_data = json_decode(get_option('ab_custom_fields'));
     foreach ($fields_data as $field_data) {
         $custom_fields[$field_data->id] = '';
         $header[] = $field_data->label;
     }
     $output = fopen('php://output', 'w');
     fwrite($output, pack("CCC", 0xef, 0xbb, 0xbf));
     fputcsv($output, $header, $delimiter);
     $rows = AB_CustomerAppointment::query()->select('r.id,
            r.number_of_persons,
            r.coupon_discount,
            r.coupon_deduction,
            st.full_name  AS staff_name,
            s.title       AS service_title,
            s.duration    AS service_duration,
            c.name        AS customer_name,
            c.phone       AS customer_phone,
            c.email       AS customer_email,
            ss.price,
            a.start_date')->leftJoin('AB_Appointment', 'a', 'a.id = r.appointment_id')->leftJoin('AB_Service', 's', 's.id = a.service_id')->leftJoin('AB_Staff', 'st', 'st.id = a.staff_id')->leftJoin('AB_Customer', 'c', 'c.id = r.customer_id')->leftJoin('AB_StaffService', 'ss', 'ss.staff_id = st.id AND ss.service_id = s.id')->whereBetween('a.start_date', $start_date, $end_date)->sortBy('a.start_date')->order(AB_Query::ORDER_DESCENDING)->fetchArray();
     foreach ($rows as $row) {
         if ($row['coupon_discount'] or $row['coupon_deduction']) {
             $coupon = new AB_Coupon();
             $coupon->set('discount', $row['coupon_discount']);
             $coupon->set('deduction', $row['coupon_deduction']);
             $row['price'] = $coupon->apply($row['price']);
         }
         $row['price'] *= $row['number_of_persons'];
         $row_data = array($row['start_date'], $row['staff_name'], $row['service_title'], AB_Service::durationToString($row['service_duration']), AB_Utils::formatPrice($row['price']), $row['customer_name'], $row['customer_phone'], $row['customer_email']);
         $customer_appointment = new AB_CustomerAppointment();
         $customer_appointment->load($row['id']);
         foreach ($customer_appointment->getCustomFields() as $custom_field) {
             $custom_fields[$custom_field['id']] = $custom_field['value'];
         }
         fputcsv($output, array_merge($row_data, $custom_fields), $delimiter);
         $custom_fields = array_map(function () {
             return '';
         }, $custom_fields);
     }
     fclose($output);
     exit;
 }
 /**
  * Render info text into a variable.
  *
  * @param string $text
  * @param AB_UserBookingData $userData
  * @param int $preset_price
  *
  * @return string
  */
 private function _prepareInfoText($text, $userData, $preset_price = null)
 {
     if (empty($this->replacement)) {
         $service = $userData->getService();
         $category_name = $service->getCategoryName();
         $staff_name = $userData->getStaffName();
         $price = $preset_price === null ? $userData->getServicePrice() : $preset_price;
         $number_of_persons = $userData->get('number_of_persons');
         $service_date = AB_DateTimeUtils::formatDate($userData->get('appointment_datetime'));
         if (get_option('ab_settings_use_client_time_zone')) {
             $service_time = AB_DateTimeUtils::formatTime(AB_DateTimeUtils::applyTimeZoneOffset($userData->get('appointment_datetime'), $userData->get('time_zone_offset')));
         } else {
             $service_time = AB_DateTimeUtils::formatTime($userData->get('appointment_datetime'));
         }
         $this->replacement = array('[[STAFF_NAME]]' => '<b>' . $staff_name . '</b>', '[[SERVICE_NAME]]' => '<b>' . $service->get('title') . '</b>', '[[CATEGORY_NAME]]' => '<b>' . $category_name . '</b>', '[[NUMBER_OF_PERSONS]]' => '<b>' . $number_of_persons . '</b>', '[[SERVICE_TIME]]' => '<b>' . $service_time . '</b>', '[[SERVICE_DATE]]' => '<b>' . $service_date . '</b>', '[[SERVICE_PRICE]]' => '<b>' . AB_Utils::formatPrice($price) . '</b>', '[[TOTAL_PRICE]]' => '<b>' . AB_Utils::formatPrice($price * $number_of_persons) . '</b>', '[[LOGIN_FORM]]' => get_current_user_id() == 0 ? $this->render('_login_form', array(), false) : '');
     }
     return strtr(nl2br($text), $this->replacement);
 }
示例#5
0
<td class="ab-column-date"><?php 
                            echo AB_DateTimeUtils::formatDate($a['start_date']);
                            ?>
</td><?php 
                            break;
                        case 'time':
                            ?>
<td class="ab-column-time"><?php 
                            echo AB_DateTimeUtils::formatTime($a['start_date']);
                            ?>
</td><?php 
                            break;
                        case 'price':
                            ?>
<td class="ab-column-price"><?php 
                            echo AB_Utils::formatPrice($a['price']);
                            ?>
</td><?php 
                            break;
                        case 'cancel':
                            ?>
<td class="ab-column-cancel">
                                            <?php 
                            if ($a['start_date'] > current_time('mysql')) {
                                ?>
                                                <a class="ab-btn orange" href="<?php 
                                echo esc_attr(admin_url('admin-ajax.php') . '?action=ab_cancel_appointment&token=' . $a['token']);
                                ?>
">
                                                    <span class="ab_label"><?php 
                                _e('Cancel', 'bookly');
 /**
  * Constructor.
  */
 public function __construct()
 {
     global $wpdb;
     // Select all services (with categories and staff members)
     // which have at least one staff member assigned.
     $rows = $wpdb->get_results($wpdb->prepare('
         SELECT
             IFNULL(`c`.`id`,0)    AS `category_id`,
             IFNULL(`c`.`name`,%s) AS `category_name`,
             `c`.`position`        AS `category_position`,
             `s`.`id`              AS `service_id`,
             `s`.`position`        AS `service_position`,
             `s`.`title`           AS `service_name`,
             `st`.`id`             AS `staff_id`,
             `st`.`position`       AS `staff_position`,
             `st`.`full_name`      AS `staff_name`,
             `ss`.`capacity`       AS `capacity`,
             `ss`.`price`          AS `price`
         FROM `' . AB_Service::getTableName() . '` `s`
             INNER JOIN `' . AB_StaffService::getTableName() . '` `ss` ON `s`.`id` = `ss`.`service_id`
             LEFT JOIN `' . AB_Category::getTableName() . '` `c`        ON `s`.`category_id` = `c`.`id`
             LEFT JOIN `' . AB_Staff::getTableName() . '` `st`          ON `ss`.`staff_id` = `st`.`id`
         ORDER BY `service_name`
     ', __('Uncategorized', 'bookly')), ARRAY_A);
     foreach ($rows as $row) {
         if (!isset($this->services[$row['service_id']])) {
             $this->services[$row['service_id']] = array('id' => $row['service_id'], 'name' => AB_Utils::getTranslatedString('service_' . $row['service_id'], $row['service_name']), 'category_id' => $row['category_id'], 'staff' => array(), 'max_capacity' => $row['capacity'], 'position' => $row['service_position']);
         } else {
             if ($this->services[$row['service_id']]['max_capacity'] < $row['capacity']) {
                 // Detect the max capacity for each service
                 //(it is the max capacity from all staff members who provides this service).
                 $this->services[$row['service_id']]['max_capacity'] = $row['capacity'];
             }
         }
         if (!isset($this->staff[$row['staff_id']])) {
             $this->staff[$row['staff_id']] = array('id' => $row['staff_id'], 'name' => AB_Utils::getTranslatedString('staff_' . $row['staff_id'], $row['staff_name']), 'services' => array(), 'position' => $row['staff_position']);
         }
         if ($row['category_id'] != '' && !isset($this->categories[$row['category_id']])) {
             $this->categories[$row['category_id']] = array('id' => $row['category_id'], 'name' => AB_Utils::getTranslatedString('category_' . $row['category_id'], $row['category_name']), 'services' => array(), 'position' => $row['category_position']);
         }
         if (!isset($this->services[$row['service_id']]['staff'][$row['staff_id']])) {
             $staff_member = $this->staff[$row['staff_id']];
             unset($staff_member['services']);
             if (self::isPaymentDisabled() == false) {
                 $staff_member['name'] .= ' (' . AB_Utils::formatPrice($row['price']) . ')';
             }
             $this->services[$row['service_id']]['staff'][$row['staff_id']] = $staff_member;
         }
         if (!isset($this->staff[$row['staff_id']]['services'][$row['service_id']])) {
             $service = $this->services[$row['service_id']];
             unset($service['staff']);
             $service['max_capacity'] = $row['capacity'];
             $this->staff[$row['staff_id']]['services'][$row['service_id']] = $service;
         }
         if (!isset($this->categories[intval($row['category_id'])]['staff'][$row['staff_id']])) {
             $staff_member = $this->staff[$row['staff_id']];
             unset($staff_member['services']);
             $this->categories[intval($row['category_id'])]['staff'][$row['staff_id']] = $staff_member;
         }
         if (!isset($this->categories[intval($row['category_id'])]['services'][$row['service_id']])) {
             $service = $this->services[$row['service_id']];
             unset($service['staff']);
             $this->categories[intval($row['category_id'])]['services'][$row['service_id']] = $service;
         }
     }
 }