From 9c7ae5dfdc88a656e48b6211f4702eb90c4a25c9 Mon Sep 17 00:00:00 2001 From: Andrea Date: Thu, 12 Apr 2018 15:03:46 +0200 Subject: [PATCH 1/5] Extra working days outside default working plan Add function to add extra working days outside the default working plan. --- src/application/config/migration.php | 2 +- src/application/controllers/Appointments.php | 11 + src/application/controllers/Backend.php | 1 + src/application/controllers/Backend_api.php | 95 +++++++ .../language/arabic/translations_lang.php | 7 + .../language/bulgarian/translations_lang.php | 7 + .../language/chinese/translations_lang.php | 7 + .../language/danish/translations_lang.php | 7 + .../language/dutch/translations_lang.php | 7 + .../language/english/translations_lang.php | 7 + .../language/finnish/translations_lang.php | 7 + .../language/french/translations_lang.php | 7 + .../language/german/translations_lang.php | 7 + .../language/greek/translations_lang.php | 7 + .../language/hindi/translations_lang.php | 7 + .../language/hungarian/translations_lang.php | 7 + .../language/italian/translations_lang.php | 7 + .../language/japanese/translations_lang.php | 7 + .../luxembourgish/translations_lang.php | 7 + .../language/polish/translations_lang.php | 7 + .../portuguese-br/translations_lang.php | 7 + .../language/portuguese/translations_lang.php | 7 + .../language/romanian/translations_lang.php | 7 + .../language/russian/translations_lang.php | 7 + .../language/slovak/translations_lang.php | 7 + .../language/spanish/translations_lang.php | 7 + .../language/turkish/translations_lang.php | 7 + .../011_add_user_extra_working_plan.php | 37 +++ src/application/models/Providers_model.php | 87 ++++++ src/application/views/backend/calendar.php | 47 ++++ src/application/views/backend/users.php | 30 +++ src/assets/css/backend.css | 9 + src/assets/js/backend_calendar.js | 1 + src/assets/js/backend_calendar_api.js | 24 +- .../js/backend_calendar_default_view.js | 139 ++++++++-- .../backend_calendar_extra_periods_modal.js | 253 ++++++++++++++++++ src/assets/js/backend_users_providers.js | 14 +- src/assets/js/general_functions.js | 31 +++ src/assets/js/working_plan.js | 238 ++++++++++++++++ src/assets/sql/data.sql | 2 +- src/assets/sql/structure.sql | 1 + 41 files changed, 1162 insertions(+), 21 deletions(-) mode change 100644 => 100755 src/application/config/migration.php create mode 100644 src/application/migrations/011_add_user_extra_working_plan.php mode change 100644 => 100755 src/application/models/Providers_model.php mode change 100644 => 100755 src/assets/js/backend_calendar.js mode change 100644 => 100755 src/assets/js/backend_calendar_api.js create mode 100644 src/assets/js/backend_calendar_extra_periods_modal.js mode change 100644 => 100755 src/assets/js/backend_users_providers.js mode change 100644 => 100755 src/assets/sql/structure.sql diff --git a/src/application/config/migration.php b/src/application/config/migration.php old mode 100644 new mode 100755 index 1546ae4d..98964bd8 --- a/src/application/config/migration.php +++ b/src/application/config/migration.php @@ -37,7 +37,7 @@ $config['migration_table'] = 'ea_migrations'; | be upgraded / downgraded to. | */ -$config['migration_version'] = 10; // current +$config['migration_version'] = 11; // current /* diff --git a/src/application/controllers/Appointments.php b/src/application/controllers/Appointments.php index c6d5976e..3f758e80 100755 --- a/src/application/controllers/Appointments.php +++ b/src/application/controllers/Appointments.php @@ -790,6 +790,9 @@ class Appointments extends CI_Controller { // Get the service, provider's working plan and provider appointments. $working_plan = json_decode($this->providers_model->get_setting('working_plan', $provider_id), TRUE); + // Get the provider's extra working plan. + $extra_working_plan = json_decode($this->providers_model->get_setting('extra_working_plan', $provider_id), TRUE); + $provider_appointments = $this->appointments_model->get_batch([ 'id_users_provider' => $provider_id, ]); @@ -811,6 +814,14 @@ class Appointments extends CI_Controller { // every reserved appointment is considered to be a taken space in the plan. $selected_date_working_plan = $working_plan[strtolower(date('l', strtotime($selected_date)))]; + // Search if the $selected_date is an extra date added outside the normal working plan + if ($selected_date_working_plan == null) { + if (isset($extra_working_plan[strtolower(date('Y-m-d', strtotime($selected_date)))])){ + $selected_date_working_plan = $extra_working_plan[strtolower(date('Y-m-d', strtotime($selected_date)))]; + } + } + + $periods = []; if (isset($selected_date_working_plan['breaks'])) diff --git a/src/application/controllers/Backend.php b/src/application/controllers/Backend.php index 2db56b7d..e89bae1c 100755 --- a/src/application/controllers/Backend.php +++ b/src/application/controllers/Backend.php @@ -212,6 +212,7 @@ class Backend extends CI_Controller { $view['secretaries'] = $this->secretaries_model->get_batch(); $view['services'] = $this->services_model->get_batch(); $view['working_plan'] = $this->settings_model->get_setting('company_working_plan'); + $view['extra_working_plan'] = "{}"; $this->set_user_data($view); $this->load->view('backend/header', $view); diff --git a/src/application/controllers/Backend_api.php b/src/application/controllers/Backend_api.php index d7588eae..fd32ca1d 100755 --- a/src/application/controllers/Backend_api.php +++ b/src/application/controllers/Backend_api.php @@ -798,6 +798,101 @@ class Backend_api extends CI_Controller { } } + /** + * [AJAX] Insert of update extra working plan time period to database. + * + * Required POST Parameters: + * + * - array $_POST['extra_period'] JSON encoded array that contains the unavailable period data. + */ + public function ajax_save_extra_period() + { + try + { + // Check privileges + $extra_period = json_decode($this->input->post('extra_period'), TRUE); + + $REQUIRED_PRIV = ( ! isset($extra_period['id'])) + ? $this->privileges[PRIV_APPOINTMENTS]['add'] + : $this->privileges[PRIV_APPOINTMENTS]['edit']; + if ($REQUIRED_PRIV == FALSE) + { + throw new Exception('You do not have the required privileges for this task.'); + } + + $this->load->model('providers_model'); + + $success = $this->providers_model->set_extra_working_day($extra_period, $extra_period['id_users_provider']); + + if ( ! $success) + { + $this->output + ->set_content_type('application/json') + ->set_output(json_encode(['warnings' => 'Error on saving extra period.'])); + } + else + { + $this->output + ->set_content_type('application/json') + ->set_output(json_encode(AJAX_SUCCESS)); + } + } + catch (Exception $exc) + { + $this->output + ->set_content_type('application/json') + ->set_output(json_encode(['exceptions' => [exceptionToJavaScript($exc)]])); + } + } + + /** + * [AJAX] Delete an extra working plan time period to database. + * + * Required POST Parameters: + * + * - String $_POST['extra_period'] Date to be deleted. + * - int $_POST['provider_id'] Record id to be deleted. + */ + public function ajax_delete_extra_period() + { + try + { + if ($this->privileges[PRIV_APPOINTMENTS]['delete'] == FALSE) + { + throw new Exception('You do not have the required privileges for this task.'); + } + + // Check privileges + $extra_period = $this->input->post('extra_period'); + $provider_id = $this->input->post('provider_id'); + + $this->load->model('providers_model'); + + // Delete unavailable + $success = $this->providers_model->delete_extra_working_day($extra_period, $provider_id); + + if ( ! $success) + { + $this->output + ->set_content_type('application/json') + ->set_output(json_encode(['warnings' => 'Error on deleting extra working day'])); + } + else + { + $this->output + ->set_content_type('application/json') + ->set_output(json_encode(AJAX_SUCCESS)); + } + + } // + catch (Exception $exc) // + { // + $this->output // + ->set_content_type('application/json') // + ->set_output(json_encode(['exceptions' => [exceptionToJavaScript($exc)]])); // + }// + } // + /** * [AJAX] Save (insert or update) a customer record. * diff --git a/src/application/language/arabic/translations_lang.php b/src/application/language/arabic/translations_lang.php index bfc7e818..368965c7 100755 --- a/src/application/language/arabic/translations_lang.php +++ b/src/application/language/arabic/translations_lang.php @@ -281,3 +281,10 @@ $lang['availabilities_type'] = 'نوع التوفر أو الإتاحة'; $lang['flexible'] = 'مرن'; $lang['fixed'] = 'ثابت'; $lang['attendants_number'] = 'عدد الحاضرين'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/bulgarian/translations_lang.php b/src/application/language/bulgarian/translations_lang.php index 04adb985..52fd77d8 100755 --- a/src/application/language/bulgarian/translations_lang.php +++ b/src/application/language/bulgarian/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Гъвкав'; $lang['fixed'] = 'Фиксиран'; $lang['attendants_number'] = 'Брой Посетители'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/chinese/translations_lang.php b/src/application/language/chinese/translations_lang.php index 71135caf..782c19f3 100755 --- a/src/application/language/chinese/translations_lang.php +++ b/src/application/language/chinese/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/danish/translations_lang.php b/src/application/language/danish/translations_lang.php index f460aaca..48cbdf3f 100755 --- a/src/application/language/danish/translations_lang.php +++ b/src/application/language/danish/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/dutch/translations_lang.php b/src/application/language/dutch/translations_lang.php index 9f9c177e..f76d2c71 100755 --- a/src/application/language/dutch/translations_lang.php +++ b/src/application/language/dutch/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexibel'; $lang['fixed'] = 'Vast'; $lang['attendants_number'] = 'Aantal deelnemers'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/english/translations_lang.php b/src/application/language/english/translations_lang.php index 066223ca..f2d7a84f 100755 --- a/src/application/language/english/translations_lang.php +++ b/src/application/language/english/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = 'Extra working day'; +$lang['extra_periods'] = 'Extra working days'; +$lang['extra_periods_hint'] = 'Add a working day outside the working plan.'; +$lang['new_extra_period_title'] = 'New working day'; +$lang['extra_period_saved'] = 'New working day saved successfully!'; +$lang['add_extra_periods_during_each_day'] = 'Add working days outside the working plan.'; +$lang['add_extra_period'] = 'Add a working day'; \ No newline at end of file diff --git a/src/application/language/finnish/translations_lang.php b/src/application/language/finnish/translations_lang.php index 7ec7e8e3..95348b0c 100755 --- a/src/application/language/finnish/translations_lang.php +++ b/src/application/language/finnish/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/french/translations_lang.php b/src/application/language/french/translations_lang.php index 0be876db..9d81812f 100755 --- a/src/application/language/french/translations_lang.php +++ b/src/application/language/french/translations_lang.php @@ -280,3 +280,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/german/translations_lang.php b/src/application/language/german/translations_lang.php index 365022bb..dbe077db 100755 --- a/src/application/language/german/translations_lang.php +++ b/src/application/language/german/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexibel'; $lang['fixed'] = 'Fest'; $lang['attendants_number'] = 'Begleiternummer'; $lang['reset_working_plan'] = 'Setzen Sie das Arbeitsplan zu die Standard Werte.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/greek/translations_lang.php b/src/application/language/greek/translations_lang.php index 741a6ad4..5f6cd527 100755 --- a/src/application/language/greek/translations_lang.php +++ b/src/application/language/greek/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Ευέλικτος'; $lang['fixed'] = 'Σταθερός'; $lang['attendants_number'] = 'Αριθμός Παραστατών'; $lang['reset_working_plan'] = 'Επαναρυθμήστε το πλάνο εργασίας στις αρχικές του τιμές.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/hindi/translations_lang.php b/src/application/language/hindi/translations_lang.php index a69e2b4e..b7a1f232 100755 --- a/src/application/language/hindi/translations_lang.php +++ b/src/application/language/hindi/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/hungarian/translations_lang.php b/src/application/language/hungarian/translations_lang.php index fb55ae82..002ad83a 100755 --- a/src/application/language/hungarian/translations_lang.php +++ b/src/application/language/hungarian/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/italian/translations_lang.php b/src/application/language/italian/translations_lang.php index 5203bd2f..d190717e 100755 --- a/src/application/language/italian/translations_lang.php +++ b/src/application/language/italian/translations_lang.php @@ -288,3 +288,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = 'Giorno extra'; +$lang['extra_periods'] = 'Giorno Extra'; +$lang['extra_periods_hint'] = 'Aggiungi una giornata lavorativa al di fuori del piano di lavoro.'; +$lang['new_extra_period_title'] = 'Nuova giornata lavorativa'; +$lang['extra_period_saved'] = 'Giornata lavorativa salvata con successo!'; +$lang['add_extra_periods_during_each_day'] = 'Aggiungi giornate lavorative al di fuori del piano di lavoro.'; +$lang['add_extra_period'] = 'Aggiungi giornata lavorativa'; \ No newline at end of file diff --git a/src/application/language/japanese/translations_lang.php b/src/application/language/japanese/translations_lang.php index 78b5e48a..c39601a7 100755 --- a/src/application/language/japanese/translations_lang.php +++ b/src/application/language/japanese/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/luxembourgish/translations_lang.php b/src/application/language/luxembourgish/translations_lang.php index ab116abe..526f9eb6 100755 --- a/src/application/language/luxembourgish/translations_lang.php +++ b/src/application/language/luxembourgish/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/polish/translations_lang.php b/src/application/language/polish/translations_lang.php index bcdb5d62..4cf17336 100755 --- a/src/application/language/polish/translations_lang.php +++ b/src/application/language/polish/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/portuguese-br/translations_lang.php b/src/application/language/portuguese-br/translations_lang.php index 5d47d75a..a9019e1f 100755 --- a/src/application/language/portuguese-br/translations_lang.php +++ b/src/application/language/portuguese-br/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/portuguese/translations_lang.php b/src/application/language/portuguese/translations_lang.php index df836058..767203fc 100755 --- a/src/application/language/portuguese/translations_lang.php +++ b/src/application/language/portuguese/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/romanian/translations_lang.php b/src/application/language/romanian/translations_lang.php index aba0ad53..4aab1f4f 100755 --- a/src/application/language/romanian/translations_lang.php +++ b/src/application/language/romanian/translations_lang.php @@ -288,3 +288,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/russian/translations_lang.php b/src/application/language/russian/translations_lang.php index d51c2c9e..a158cef0 100755 --- a/src/application/language/russian/translations_lang.php +++ b/src/application/language/russian/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/slovak/translations_lang.php b/src/application/language/slovak/translations_lang.php index 18a9499f..96de7308 100755 --- a/src/application/language/slovak/translations_lang.php +++ b/src/application/language/slovak/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexibilný'; $lang['fixed'] = 'Fixný'; $lang['attendants_number'] = 'Počet účastníkov'; $lang['reset_working_plan'] = 'Obnovte pracovný plán späť na predvolené hodnoty.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/spanish/translations_lang.php b/src/application/language/spanish/translations_lang.php index 237401e9..f500e46a 100755 --- a/src/application/language/spanish/translations_lang.php +++ b/src/application/language/spanish/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Número de Atenciones'; $lang['reset_working_plan'] = 'Reinicia el plan de trabajo a los valores por defecto.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/language/turkish/translations_lang.php b/src/application/language/turkish/translations_lang.php index 2d78e152..b5a4881a 100755 --- a/src/application/language/turkish/translations_lang.php +++ b/src/application/language/turkish/translations_lang.php @@ -282,3 +282,10 @@ $lang['flexible'] = 'Flexible'; $lang['fixed'] = 'Fixed'; $lang['attendants_number'] = 'Attendants Number'; $lang['reset_working_plan'] = 'Reset the working plan back to the default values.'; +$lang['extra_period'] = ''; +$lang['extra_periods'] = ''; +$lang['extra_periods_hint'] = ''; +$lang['new_extra_period_title'] = ''; +$lang['extra_period_saved'] = ''; +$lang['add_extra_periods_during_each_day'] = ''; +$lang['add_extra_period'] = ''; \ No newline at end of file diff --git a/src/application/migrations/011_add_user_extra_working_plan.php b/src/application/migrations/011_add_user_extra_working_plan.php new file mode 100644 index 00000000..24226714 --- /dev/null +++ b/src/application/migrations/011_add_user_extra_working_plan.php @@ -0,0 +1,37 @@ + + * @copyright Copyright (c) 2013 - 2017, Alex Tselegidis + * @license http://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link http://easyappointments.org + * @since v1.2.0 + * ---------------------------------------------------------------------------- */ + +class Migration_Add_user_extra_working_plan extends CI_Migration { + public function up() + { + if (!$this->db->field_exists('extra_working_plan', 'ea_user_settings')) { + $fields = [ + 'extra_working_plan' => [ + 'type' => 'TEXT', + 'null' => TRUE, + 'default' => '', + 'after' => 'working_plan' + ] + ]; + + $this->dbforge->add_column('ea_user_settings', $fields); + } + } + + public function down() + { + if (!$this->db->field_exists('extra_working_plan', 'ea_user_settings')) { + $this->dbforge->drop_column('ea_user_settings', 'extra_working_plan'); + } + } +} diff --git a/src/application/models/Providers_model.php b/src/application/models/Providers_model.php old mode 100644 new mode 100755 index 9697978e..d1d9a09b --- a/src/application/models/Providers_model.php +++ b/src/application/models/Providers_model.php @@ -600,6 +600,13 @@ class Providers_Model extends CI_Model { foreach ($settings as $name => $value) { + // Sort in descending order the extra working plan days + if ($name == 'extra_working_plan') { + $value = json_decode($value, true); + // Sort the array and put in reverse order + krsort($value); + $value = json_encode($value); + } $this->set_setting($name, $value, $provider_id); } } @@ -638,6 +645,86 @@ class Providers_Model extends CI_Model { } } + /** + * Save the provider extra working plan days. + * + * @param array $extra_period Contains the date and the hours of the extra working plan day. + * @param int $provider_id The selected provider record id. + * + * @return bool Return if the new extra working plan is correctly saved to DB. + * + * @throws Exception If start time is after the end time. + * @throws Exception If $provider_id argument is invalid. + */ + public function set_extra_working_day($extra_period, $provider_id) + { + // Validate period + $dateStart = date('Y-m-d', strtotime($extra_period['start_datetime'])); + $start = date('H:i',strtotime($extra_period['start_datetime'])); + $end = date('H:i',strtotime($extra_period['end_datetime'])); + if ($start > $end) + { + throw new Exception('Unavailable period start must be prior to end.'); + } + + // Validate provider record + $where_clause = [ + 'id' => $provider_id, + 'id_roles' => $this->db->get_where('ea_roles', ['slug' => DB_SLUG_PROVIDER])->row()->id + ]; + + if ($this->db->get_where('ea_users', $where_clause)->num_rows() == 0) + { + throw new Exception('Provider id was not found in database.'); + } + + // Add record to database. + $extra_working_plan = json_decode($this->get_setting('extra_working_plan', $provider_id), true); + + $extra_working_plan[$dateStart] = [ + 'start' => $start, + 'end' => $end, + 'breaks' => [] + ]; + + $success = $this->set_setting('extra_working_plan', json_encode($extra_working_plan), $provider_id); + + return $success; + } + + /** + * Delete a provider extra working plan day. + * + * @param string $extra_period Contains the date to be deleted from the extra working plan. + * @param int $provider_id The selected provider record id. + * + * @return bool Return if the new extra working plan is correctly deleted from DB. + * + * @throws Exception If $provider_id argument is invalid. + */ + public function delete_extra_working_day($extra_period, $provider_id) + { + // Validate provider record + $where_clause = [ + 'id' => $provider_id, + 'id_roles' => $this->db->get_where('ea_roles', ['slug' => DB_SLUG_PROVIDER])->row()->id + ]; + + if ($this->db->get_where('ea_users', $where_clause)->num_rows() == 0) + { + throw new Exception('Provider id was not found in database.'); + } + + // Add record to database. + $extra_working_plan = json_decode($this->get_setting('extra_working_plan', $provider_id), true); + + unset($extra_working_plan[$extra_period]); + + $success = $this->set_setting('extra_working_plan', json_encode($extra_working_plan), $provider_id); + + return $success; + } + /** * Validate Records Username * diff --git a/src/application/views/backend/calendar.php b/src/application/views/backend/calendar.php index b0e0afe6..4e799d2d 100755 --- a/src/application/views/backend/calendar.php +++ b/src/application/views/backend/calendar.php @@ -10,6 +10,7 @@ +