diff --git a/application/controllers/Appointments.php b/application/controllers/Appointments.php index 5489b2c762..38b8421db1 100755 --- a/application/controllers/Appointments.php +++ b/application/controllers/Appointments.php @@ -35,6 +35,7 @@ public function __construct() $this->load->model('services_model'); $this->load->model('customers_model'); $this->load->model('settings_model'); + $this->load->model('host_model'); $this->load->library('timezones'); $this->load->library('synchronization'); $this->load->library('notifications'); @@ -79,6 +80,14 @@ public function index($appointment_hash = '') $privacy_policy_content = $this->settings_model->get_setting('privacy_policy_content'); $display_any_provider = $this->settings_model->get_setting('display_any_provider'); $timezones = $this->timezones->to_array(); + $chinese_name = $this->host_model->get_host('chinese_name'); + $english_name = $this->host_model->get_host('english_name'); + $url = $this->host_model->get_host('url'); + $logo = $this->host_model->get_host('logo'); + $description = $this->host_model->get_host('description'); + $main_color = $this->host_model->get_host('main_color'); + $secondary_color = $this->host_model->get_host('secondary_color'); + $text_color = $this->host_model->get_host('text_color'); // Remove the data that are not needed inside the $available_providers array. foreach ($available_providers as $index => $provider) @@ -182,6 +191,14 @@ public function index($appointment_hash = '') 'privacy_policy_content' => $privacy_policy_content, 'timezones' => $timezones, 'display_any_provider' => $display_any_provider, + 'chinese_name' => $chinese_name, + 'english_name' => $english_name, + 'url' => $url, + 'logo' => $logo, + 'description' => $description, + 'main_color' => $main_color, + 'secondary_color' => $secondary_color, + 'text_color' => $text_color ]; } catch (Exception $exception) @@ -711,5 +728,45 @@ protected function search_providers_by_service($service_id) return $provider_list; } + /** + * + */ + public function book_record() + { + try + { + $company_name = $this->settings_model->get_setting('company_name'); + $company_address = $this->settings_model->get_setting('company_address'); + $company_logo = $this->settings_model->get_setting('company_logo'); + $company_banner = $this->settings_model->get_setting('company_banner'); + $timezones = $this->timezones->to_array(); + $chinese_name = $this->host_model->get_host('chinese_name'); + $english_name = $this->host_model->get_host('english_name'); + $url = $this->host_model->get_host('url'); + $logo = $this->host_model->get_host('logo'); + $description = $this->host_model->get_host('description'); + $main_color = $this->host_model->get_host('main_color'); + + // Load the book appointment view. + $variables = [ + 'company_name' => $company_name, + 'company_address' => $company_address, + 'company_logo' => $company_logo, + 'company_banner' => $company_banner, + 'timezones' => $timezones, + 'chinese_name' => $chinese_name, + 'english_name' => $english_name, + 'url' => $url, + 'logo' => $logo, + 'description' => $description, + 'main_color' => $main_color, + ]; + } + catch (Exception $exception) + { + $variables['exceptions'][] = $exception; + } + $this->load->view('appointments/book_record', $variables); + } } diff --git a/application/controllers/Backend.php b/application/controllers/Backend.php index aad1c408dd..68cea95514 100755 --- a/application/controllers/Backend.php +++ b/application/controllers/Backend.php @@ -34,6 +34,7 @@ public function __construct() $this->load->model('roles_model'); $this->load->model('user_model'); $this->load->model('secretaries_model'); + $this->load->model('host_model'); $this->load->model('admins_model'); $this->load->library('timezones'); $this->load->library('migration'); @@ -79,6 +80,14 @@ public function index($appointment_hash = '') $view['customers'] = $this->customers_model->get_batch(); $view['calendar_view'] = ! empty($calendar_view_query_param) ? $calendar_view_query_param : $user['settings']['calendar_view']; $view['timezones'] = $this->timezones->to_array(); + $view['chinese_name'] = $this->host_model->get_host('chinese_name'); + $view['english_name'] = $this->host_model->get_host('english_name'); + $view['url'] = $this->host_model->get_host('url'); + $view['logo'] = $this->host_model->get_host('logo'); + $view['description'] = $this->host_model->get_host('description'); + $view['main_color'] = $this->host_model->get_host('main_color'); + $view['secondary_color'] = $this->host_model->get_host('secondary_color'); + $view['text_color'] = $this->host_model->get_host('text_color'); $this->set_user_data($view); if ($this->session->userdata('role_slug') === DB_SLUG_SECRETARY) @@ -199,6 +208,14 @@ public function customers() $view['available_providers'] = $this->providers_model->get_available_providers(); $view['available_services'] = $this->services_model->get_available_services(); $view['timezones'] = $this->timezones->to_array(); + $view['chinese_name'] = $this->host_model->get_host('chinese_name'); + $view['english_name'] = $this->host_model->get_host('english_name'); + $view['url'] = $this->host_model->get_host('url'); + $view['logo'] = $this->host_model->get_host('logo'); + $view['description'] = $this->host_model->get_host('description'); + $view['main_color'] = $this->host_model->get_host('main_color'); + $view['secondary_color'] = $this->host_model->get_host('secondary_color'); + $view['text_color'] = $this->host_model->get_host('text_color'); if ($this->session->userdata('role_slug') === DB_SLUG_SECRETARY) { @@ -245,6 +262,14 @@ public function services() $view['services'] = $this->services_model->get_batch(); $view['categories'] = $this->services_model->get_all_categories(); $view['timezones'] = $this->timezones->to_array(); + $view['chinese_name'] = $this->host_model->get_host('chinese_name'); + $view['english_name'] = $this->host_model->get_host('english_name'); + $view['url'] = $this->host_model->get_host('url'); + $view['logo'] = $this->host_model->get_host('logo'); + $view['description'] = $this->host_model->get_host('description'); + $view['main_color'] = $this->host_model->get_host('main_color'); + $view['secondary_color'] = $this->host_model->get_host('secondary_color'); + $view['text_color'] = $this->host_model->get_host('text_color'); $this->set_user_data($view); $this->load->view('backend/header', $view); @@ -282,6 +307,14 @@ public function users() $view['working_plan'] = $this->settings_model->get_setting('company_working_plan'); $view['timezones'] = $this->timezones->to_array(); $view['working_plan_exceptions'] = '{}'; + $view['chinese_name'] = $this->host_model->get_host('chinese_name'); + $view['english_name'] = $this->host_model->get_host('english_name'); + $view['url'] = $this->host_model->get_host('url'); + $view['logo'] = $this->host_model->get_host('logo'); + $view['description'] = $this->host_model->get_host('description'); + $view['main_color'] = $this->host_model->get_host('main_color'); + $view['secondary_color'] = $this->host_model->get_host('secondary_color'); + $view['text_color'] = $this->host_model->get_host('text_color'); $this->set_user_data($view); $this->load->view('backend/header', $view); @@ -319,6 +352,14 @@ public function settings() $view['system_settings'] = $this->settings_model->get_settings(); $view['user_settings'] = $this->user_model->get_user($user_id); $view['timezones'] = $this->timezones->to_array(); + $view['chinese_name'] = $this->host_model->get_host('chinese_name'); + $view['english_name'] = $this->host_model->get_host('english_name'); + $view['url'] = $this->host_model->get_host('url'); + $view['logo'] = $this->host_model->get_host('logo'); + $view['description'] = $this->host_model->get_host('description'); + $view['main_color'] = $this->host_model->get_host('main_color'); + $view['secondary_color'] = $this->host_model->get_host('secondary_color'); + $view['text_color'] = $this->host_model->get_host('text_color'); // book_advance_timeout preview $book_advance_timeout = $this->settings_model->get_setting('book_advance_timeout'); diff --git a/application/controllers/Backend_api.php b/application/controllers/Backend_api.php index e346b42d95..54471bcc24 100755 --- a/application/controllers/Backend_api.php +++ b/application/controllers/Backend_api.php @@ -313,7 +313,10 @@ public function ajax_save_appointment() $response = AJAX_SUCCESS; //send appointment change line message - line_message_change($settings, $customer, $service, $appointment); + $is_notification = $this->input->post('is_notification'); + if($is_notification == 1){ + line_message_change($settings, $customer, $service, $appointment); + } } catch (Exception $exception) @@ -474,7 +477,10 @@ public function ajax_delete_appointment() } //send appointment delet line message - line_message_delete($settings, $customer, $service, $appointment); + $is_notification = $this->input->post('is_notification'); + if($is_notification == 1){ + line_message_delete($settings, $customer, $service, $appointment); + } } catch (Exception $exception) diff --git a/application/controllers/Cronjob.php b/application/controllers/Cronjob.php new file mode 100644 index 0000000000..44450c3d72 --- /dev/null +++ b/application/controllers/Cronjob.php @@ -0,0 +1,41 @@ +load->helper('line_message'); + $this->load->model('appointments_model'); + $this->load->model('providers_model'); + $this->load->model('services_model'); + $this->load->model('customers_model'); + $this->load->model('settings_model'); + $this->load->library('timezones'); + } + + public function send_notify_to_appoiment() + { + $appointment = []; + $remind_time = $this->settings_model->get_setting('remind_time'); + $day_start = $remind_time; + $day_end = $remind_time +1; + $appointments = $this->appointments_model->get_scheduled_appointments($day_start, $day_end); + + if(count($appointments) > 0){ + $settings = [ + 'company_name' => $this->settings_model->get_setting('company_name'), + 'company_address' => $this->settings_model->get_setting('company_address'), + ]; + foreach ($appointments as $appointment) { + $provider = $this->providers_model->get_row($appointment['id_users_provider']); + $service = $this->services_model->get_row($appointment['id_services']); + $customer = $this->customers_model->get_row($appointment['id_users_customer']); + line_message_cronjob($settings, $provider, $service, $customer, $appointment); + } + } + print_r($appointments); + // echo json_encode($datetime); + } +} \ No newline at end of file diff --git a/application/controllers/Customer.php b/application/controllers/Customer.php new file mode 100644 index 0000000000..66eddaaa82 --- /dev/null +++ b/application/controllers/Customer.php @@ -0,0 +1,31 @@ +load->model('customers_model'); + } + + public function send_customer_to_appoiment() + { + $lineUserId = $this->input->post('lineUserId'); + + if (empty($lineUserId)) + { + $response = ['warnings' => 'Error line user id is required']; + } + else + { + $lineUserId_customerData = $this->customers_model->get_data_from_line_id($lineUserId); + $response = $lineUserId_customerData; + } + + $this->output + ->set_content_type('application/json') + ->set_output(json_encode($response)); + + } +} \ No newline at end of file diff --git a/application/controllers/Record.php b/application/controllers/Record.php new file mode 100644 index 0000000000..13396741dd --- /dev/null +++ b/application/controllers/Record.php @@ -0,0 +1,39 @@ +load->model('appointments_model'); + $this->load->model('providers_model'); + $this->load->model('services_model'); + $this->load->model('customers_model'); + $this->load->model('settings_model'); + } + + public function get_appointments_from_line_id() + { + $lineUserId = $this->input->post('lineUserId'); + + if (empty($lineUserId)) + { + $response = ['warnings' => 'Error line user id is required']; + } + else + { + $customer_id = $this->customers_model->get_value_from_line_id('id', $lineUserId); + $appointments = $this->appointments_model->get_appointments_from_customer($customer_id); + + foreach($appointments as $id_services => $appointments) + { + $service = $this->services_model->get_row($appointments['id_services']); + $response[] = $appointments + $service; + } + } + $this->output + ->set_content_type('application/json') + ->set_output(json_encode($response)); + } +} \ No newline at end of file diff --git a/application/helpers/line_message_helper.php b/application/helpers/line_message_helper.php index b405a221f5..f311c62349 100644 --- a/application/helpers/line_message_helper.php +++ b/application/helpers/line_message_helper.php @@ -148,6 +148,25 @@ function line_message_appointment($settings, $customer, $service, $appointment){ 'flex' => 0 ] ] + ], + [ + 'type' => 'box', + 'layout' => 'horizontal', + 'margin' => 'md', + 'contents' => [ + [ + 'type' => 'text', + 'text' => '查詢我的預約', + 'size' => 'xs', + 'color' => '#0080FF', + 'flex' => 0, + 'action' => [ + 'type' => 'uri', + 'label' => 'action', + 'uri' => base_url('/index.php/appointments/book_record') + ], + ] + ] ] ] ], @@ -315,6 +334,25 @@ function line_message_change($settings, $customer, $service, $appointment){ 'flex' => 0 ] ] + ], + [ + 'type' => 'box', + 'layout' => 'horizontal', + 'margin' => 'md', + 'contents' => [ + [ + 'type' => 'text', + 'text' => '查詢我的預約', + 'size' => 'xs', + 'color' => '#0080FF', + 'flex' => 0, + 'action' => [ + 'type' => 'uri', + 'label' => 'action', + 'uri' => base_url('/index.php/appointments/book_record') + ], + ] + ] ] ] ], @@ -466,12 +504,31 @@ function line_message_delete($settings, $customer, $service, $appointment){ 'contents' => [ [ 'type' => 'text', - 'text' => '預約審核通過,拒絕才會收到此訊息,如有疑問請洽店家', + 'text' => '預約已刪除,如有疑問請洽店家', 'size' => 'xs', 'color' => '#aaaaaa', 'flex' => 0 ] ] + ], + [ + 'type' => 'box', + 'layout' => 'horizontal', + 'margin' => 'md', + 'contents' => [ + [ + 'type' => 'text', + 'text' => '查詢我的預約', + 'size' => 'xs', + 'color' => '#0080FF', + 'flex' => 0, + 'action' => [ + 'type' => 'uri', + 'label' => 'action', + 'uri' => base_url('/index.php/appointments/book_record') + ], + ] + ] ] ] ], @@ -485,3 +542,181 @@ function line_message_delete($settings, $customer, $service, $appointment){ $bot->pushMessage($customer['lineUserId'], $RawMessageBuilder); } } + +function line_message_cronjob($provider, $settings, $customer, $service, $appointment){ + if (!empty($provider['lineuserid'])){ + $httpClient = new \LINE\LINEBot\HTTPClient\CurlHTTPClient(config('line_access_token')); + $bot = new \LINE\LINEBot($httpClient, ['channelSecret' => config('line_secret')]); + + $RawMessageBuilder = new \LINE\LINEBot\MessageBuilder\RawMessageBuilder( + [ + 'type' => 'flex', + 'altText' => '預約服務提醒訊息', + 'contents' => [ + 'type' => 'bubble', + 'body' => [ + 'type' => 'box', + 'layout' => 'vertical', + 'contents' => [ + [ + 'type' => 'text', + 'text' => '預約日期即將到達', + 'weight' => 'bold', + 'color' => '#1DB446', + 'size' => 'sm' + ], + [ + 'type' => 'text', + 'text' => $settings['company_name'], + 'weight' => 'bold', + 'size' => 'xxl', + 'margin' => 'md' + ], + [ + 'type' => 'text', + 'text' => $settings['company_address'], + 'size' => 'xs', + 'color' => '#aaaaaa', + 'wrap' => true + ], + [ + 'type' => 'separator', + 'margin' => 'xxl' + ], + [ + 'type' => 'box', + 'layout' => 'vertical', + 'margin' => 'xxl', + 'spacing' => 'sm', + 'contents' => [ + [ + 'type' => 'box', + 'layout' => 'horizontal', + 'contents' => [ + [ + 'type' => 'text', + 'text' => '姓名', + 'size' => 'sm', + 'color' => '#555555', + 'flex' => 0 + ], + [ + 'type' => 'text', + 'text' => $customer['last_name'] . $customer['first_name'], + 'size' => 'sm', + 'color' => '#111111', + 'align' => 'end' + ] + ] + ], + [ + 'type' => 'box', + 'layout' => 'horizontal', + 'contents' => [ + [ + 'type' => 'text', + 'text' => '預約日期', + 'size' => 'sm', + 'color' => '#555555', + 'flex' => 0 + ], + [ + 'type' => 'text', + 'text' => $appointment['start_datetime'], + 'size' => 'sm', + "color" => '#111111', + 'align' => 'end' + ] + ] + ], + [ + 'type' => 'box', + 'layout' => 'horizontal', + 'contents' => [ + [ + 'type'=> 'text', + 'text' => '預約時間', + 'size' => 'sm', + 'color' => '#555555', + 'flex' => 0 + ], + [ + 'type' => 'text', + 'text' => $appointment['end_datetime'], + 'size' => 'sm', + 'color' => '#111111', + 'align' => 'end' + ] + ] + ], + [ + 'type' => 'box', + 'layout' => 'horizontal', + 'contents' => [ + [ + 'type' => 'text', + 'text' => '預約服務', + 'size' => 'sm', + 'color' => '#555555' + ], + [ + 'type' => 'text', + 'text' => $service['name'], + 'size' => 'sm', + 'color' => '#111111', + 'align' => 'end' + ] + ] + ] + ] + ], + [ + 'type' => 'separator', + 'margin' => 'xxl' + ], + [ + 'type' => 'box', + 'layout' => 'horizontal', + 'margin' => 'md', + 'contents' => [ + [ + 'type' => 'text', + 'text' => '預約服務日期即將到達', + 'size' => 'xs', + 'color' => '#aaaaaa', + 'flex' => 0 + ] + ] + ], + [ + 'type' => 'box', + 'layout' => 'horizontal', + 'margin' => 'md', + 'contents' => [ + [ + 'type' => 'text', + 'text' => '查詢我的預約', + 'size' => 'xs', + 'color' => '#0080FF', + 'flex' => 0, + 'action' => [ + 'type' => 'uri', + 'label' => 'action', + 'uri' => base_url('/index.php/appointments/book_record') + ], + ] + ] + ] + ] + ], + 'styles' => [ + 'footer' => [ + 'separator' => true + ] + ] + ] + ]); + + $bot->pushMessage($provider['lineuserid'], $RawMessageBuilder); + } +} diff --git a/application/language/chinese/translations_lang.php b/application/language/chinese/translations_lang.php index f17f9e9926..5c7bf83bcc 100755 --- a/application/language/chinese/translations_lang.php +++ b/application/language/chinese/translations_lang.php @@ -1,6 +1,8 @@ row() ->attendants_number; } + + /** + * + */ + public function get_scheduled_appointments($day_start, $day_end) + { + + $today = date("Y-m-d"); + + $interval_start = date("Y-m-d", strtotime($today) + $day_start * 24 * 3600); + $interval_end = date("Y-m-d", strtotime($today) + $day_end * 24 * 3600); + + $result = $this->db + ->get_where('appointments',[ + 'start_datetime >=' => $interval_start . " 00:00:00", + 'start_datetime <=' => $interval_end . " 00:00:00", + 'situation' => 1, + ])->result_array(); + + return $result; + } + + /** + * + */ + public function get_appointments_from_customer($customer_id) + { + $situation_refuse = 2; + $result = $this->db + ->get_where('appointments', [ + 'id_users_customer' => $customer_id, + 'situation !=' => $situation_refuse, + ])->result_array(); + + return $result; + } + } diff --git a/application/models/Customers_model.php b/application/models/Customers_model.php index 0f39f410d8..b33a4f06d7 100644 --- a/application/models/Customers_model.php +++ b/application/models/Customers_model.php @@ -380,4 +380,25 @@ public function get_customers_role_id() { return $this->db->get_where('roles', ['slug' => DB_SLUG_CUSTOMER])->row()->id; } + + /** + * Get have lineUserId customers from the database. + */ + public function get_data_from_line_id($lineUserId) + { + $result = $this->db->get_where('users', ['lineUserId' => $lineUserId])->row_array(); + return $result; + } + + /** + * + */ + public function get_value_from_line_id($field_name, $lineUserId) + { + $customer = $this->db->get_where('users', ['lineUserId' => $lineUserId])->row_array(); + + return $customer[$field_name]; + } + + } diff --git a/application/models/Host_model.php b/application/models/Host_model.php new file mode 100644 index 0000000000..d838de0e25 --- /dev/null +++ b/application/models/Host_model.php @@ -0,0 +1,65 @@ +db->get_where('host', ['name' => $name])->num_rows() == 0) + { + // Check if host exists in db. + throw new Exception('$name host does not exist in database: ' . $name); + } + + $query = $this->db->get_where('host', ['name' => $name]); + $host = $query->num_rows() > 0 ? $query->row() : ''; + return $host->value; + } + + public function set_host($name, $value) + { + if ( ! is_string($name)) + { + throw new Exception('$name argument is not a string: ' . $name); + } + + $query = $this->db->get_where('host', ['name' => $name]); + + if ($query->num_rows() > 0) + { + // Update host + if ( ! $this->db->update('host', ['value' => $value], ['name' => $name])) + { + throw new Exception('Could not update database host.'); + } + $host_id = (int)$this->db->get_where('host', ['name' => $name])->row()->id; + } + else + { + // Insert host + $insert_data = [ + 'name' => $name, + 'value' => $value + ]; + + if ( ! $this->db->insert('host', $insert_data)) + { + throw new Exception('Could not insert database host'); + } + + $host_id = (int)$this->db->insert_id(); + } + + return $host_id; + } + + public function get_hosts() + { + return $this->db->get('hosts')->result_array(); + } +} \ No newline at end of file diff --git a/application/views/appointments/book.php b/application/views/appointments/book.php index b0918f1aa0..334e2b9797 100755 --- a/application/views/appointments/book.php +++ b/application/views/appointments/book.php @@ -338,7 +338,8 @@ class="btn btn-danger btn-sm">
- @@ -350,11 +351,11 @@ class="btn btn-danger btn-sm"> -