/** * Get array with appointments data for customer profile. * * @return array */ public function getAppointmentsForProfile() { $records = array(); if ($this->get('id')) { $result = $this->wpdb->get_results($this->wpdb->prepare('SELECT `c`.`name` `category`, `sv`.`title` `service`, `s`.`full_name` `staff`, `a`.`start_date` `start_date`, `ss`.`price` `price`, `ca`.`number_of_persons` `number_of_persons`, `ca`.`coupon_discount` `coupon_discount`, `ca`.`coupon_deduction` `coupon_deduction`, `ca`.`time_zone_offset` `time_zone_offset`, `ca`.`token` `token` FROM `' . AB_Appointment::getTableName() . '` `a` LEFT JOIN `' . AB_Staff::getTableName() . '` `s` ON `s`.`id` = `a`.`staff_id` LEFT JOIN `' . AB_Service::getTableName() . '` `sv` ON `sv`.`id` = `a`.`service_id` LEFT JOIN `' . AB_Category::getTableName() . '` `c` ON `c`.`id` = `sv`.`category_id` LEFT JOIN `' . AB_StaffService::getTableName() . '` `ss` ON `ss`.`staff_id` = `a`.`staff_id` AND `ss`.`service_id` = `a`.`service_id` INNER JOIN `' . AB_CustomerAppointment::getTableName() . '` `ca` ON `ca`.`appointment_id` = `a`.`id` AND `ca`.`customer_id` = %d', $this->get('id')), ARRAY_A); if ($result) { foreach ($result as $row) { if ($row['time_zone_offset'] !== null) { $row['start_date'] = AB_DateTimeUtils::applyTimeZoneOffset($row['start_date'], $row['time_zone_offset']); } 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']; unset($row['time_zone_offset'], $row['coupon_discount'], $row['coupon_deduction'], $row['number_of_persons']); $records[] = $row; } } } return $records; }
/** * Send scheduled notifications. * * @param int $type (C_NEXT_DAY_APPOINTMENT|C_FOLLOW_UP_ACTION) * @param AB_Notification $notification * @param AB_CustomerAppointment $ca * @return bool */ public static function sendFromCron($type, AB_Notification $notification, AB_CustomerAppointment $ca) { $result = false; list($codes, $staff, $appointment, $customer) = self::_prepareData($ca); switch ($type) { case self::CRON_NEXT_DAY_APPOINTMENT: // Client time zone offset. if ($ca->get('time_zone_offset') !== null) { $codes->set('appointment_datetime', AB_DateTimeUtils::applyTimeZoneOffset($appointment->get('start_date'), $ca->get('time_zone_offset'))); } // Send email notification to client. $result = self::_send($notification, $codes, $customer->get('email'), $customer->get('phone')); break; case self::CRON_FOLLOW_UP_EMAIL: // Client time zone offset. if ($ca->get('time_zone_offset') !== null) { $codes->set('appointment_datetime', AB_DateTimeUtils::applyTimeZoneOffset($appointment->get('start_date'), $ca->get('time_zone_offset'))); } // Send email notification to client. $result = self::_send($notification, $codes, $customer->get('email'), $customer->get('phone')); break; } return $result; }
/** * 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); }
public function executeGetSmsList() { $sms = new AB_SMS(); if ($this->hasParameter('range')) { $dates = explode(' - ', $this->getParameter('range'), 2); $start = AB_DateTimeUtils::applyTimeZoneOffset($dates[0], 0); $end = AB_DateTimeUtils::applyTimeZoneOffset(date('Y-m-d', strtotime('+1 day', strtotime($dates[1]))), 0); } else { $start = AB_DateTimeUtils::applyTimeZoneOffset(date('Y-m-d', strtotime('first day of this month')), 0); $end = AB_DateTimeUtils::applyTimeZoneOffset(date('Y-m-d', strtotime('first day of next month')), 0); } $list = $sms->getSmsList($start, $end); if (empty($list)) { wp_send_json_error(); } else { wp_send_json($list); } }