diff --git a/src/application/controllers/appointments.php b/src/application/controllers/appointments.php index 0cd0b7bf..b0821277 100644 --- a/src/application/controllers/appointments.php +++ b/src/application/controllers/appointments.php @@ -480,7 +480,7 @@ class Appointments extends CI_Controller { $working_plan = json_decode($this->providers_model->get_setting('working_plan', $provider_id), true); $where_clause = array( - 'DATE(start_datetime)' => date('Y-m-d', strtotime($selected_date)), + //'DATE(start_datetime)' => date('Y-m-d', strtotime($selected_date)), 'id_users_provider' => $provider_id ); @@ -542,10 +542,10 @@ class Appointments extends CI_Controller { foreach($reserved_appointments as $appointment) { foreach($available_periods_with_appointments as $index => &$period) { - $a_start = date('H:i', strtotime($appointment['start_datetime'])); - $a_end = date('H:i', strtotime($appointment['end_datetime'])); - $p_start = date('H:i', strtotime($period['start'])); - $p_end = date('H:i', strtotime($period['end'])); + $a_start = strtotime($appointment['start_datetime']); + $a_end = strtotime($appointment['end_datetime']); + $p_start = strtotime($selected_date . ' ' . $period['start']); + $p_end = strtotime($selected_date . ' ' .$period['end']); if ($a_start <= $p_start && $a_end <= $p_end && $a_end <= $p_start) { // The appointment does not belong in this time period, so we @@ -553,25 +553,25 @@ class Appointments extends CI_Controller { } else if ($a_start <= $p_start && $a_end <= $p_end && $a_end >= $p_start) { // The appointment starts before the period and finishes somewhere inside. // We will need to break this period and leave the available part. - $period['start'] = $a_end; + $period['start'] = date('H:i', $a_end); } else if ($a_start >= $p_start && $a_end <= $p_end) { // The appointment is inside the time period, so we will split the period // into two new others. unset($available_periods_with_appointments[$index]); $available_periods_with_appointments[] = array( - 'start' => $p_start, - 'end' => $a_start + 'start' => date('H:i', $p_start), + 'end' => date('H:i', $a_start) ); $available_periods_with_appointments[] = array( - 'start' => $a_end, - 'end' => $p_end + 'start' => date('H:i', $a_end), + 'end' => date('H:i', $p_end) ); } else if ($a_start >= $p_start && $a_end >= $p_start && $a_start <= $p_end) { // The appointment starts in the period and finishes out of it. We will // need to remove the time that is taken from the appointment. - $period['end'] = $a_start; + $period['end'] = date('H:i', $a_start); } else if ($a_start >= $p_start && $a_end >= $p_end && $a_start >= $p_end) { // The appointment does not belong in the period so do not change anything. diff --git a/src/application/controllers/backend_api.php b/src/application/controllers/backend_api.php index 1ee5d184..42cc1b5b 100644 --- a/src/application/controllers/backend_api.php +++ b/src/application/controllers/backend_api.php @@ -48,13 +48,13 @@ class Backend_api extends CI_Controller { $where_id = 'id_users_provider'; } else { $where_id = 'id_services'; - } - + } + // Get appointments $where_clause = array( $where_id => $_POST['record_id'], - 'start_datetime >=' => $_POST['start_date'], - 'end_datetime <=' => $_POST['end_date'], + //'start_datetime >=' => $_POST['start_date'], + //'end_datetime <=' => $_POST['end_date'], 'is_unavailable' => FALSE ); @@ -70,8 +70,8 @@ class Backend_api extends CI_Controller { if ($_POST['filter_type'] == FILTER_TYPE_PROVIDER) { $where_clause = array( $where_id => $_POST['record_id'], - 'start_datetime >=' => $_POST['start_date'], - 'end_datetime <=' => $_POST['end_date'], + //'start_datetime >=' => $_POST['start_date'], + //'end_datetime <=' => $_POST['end_date'], 'is_unavailable' => TRUE ); diff --git a/src/assets/js/backend_calendar.js b/src/assets/js/backend_calendar.js index b0164eb1..24ffe9a2 100644 --- a/src/assets/js/backend_calendar.js +++ b/src/assets/js/backend_calendar.js @@ -989,7 +989,7 @@ var BackendCalendar = { * @param {object} $calendar The calendar jQuery object. * @param {int} recordId The selected record id. * @param {string} filterType The filter type, could be either FILTER_TYPE_PROVIDER - * or FILTER_TYPE_SERVICE + * or FILTER_TYPE_SERVICE. * @param {date} startDate Visible start date of the calendar. * @param {type} endDate Visible end date of the calendar. */ @@ -1045,7 +1045,37 @@ var BackendCalendar = { var selDayName = $calendar.fullCalendar('getView') .start.toString('dddd').toLowerCase(); - if (workingPlan[selDayName] == null) return; // go to next loop + // Add custom unavailable periods. + $.each(response.unavailables, function(index, unavailable) { + var unavailablePeriod = { + 'title': EALang['unavailable'] + '
' + ((unavailable.notes.length > 30) + ? unavailable.notes.substring(0, 30) + '...' + : unavailable.notes) + '', + 'start': Date.parse(unavailable.start_datetime), + 'end': Date.parse(unavailable.end_datetime), + 'allDay': false, + 'color': '#879DB4', + 'editable': true, + 'className': 'fc-unavailable fc-custom', + 'data': unavailable + }; + $calendar.fullCalendar('renderEvent', unavailablePeriod, false); + }); + + // non working day + if (workingPlan[selDayName] == null) { + unavailablePeriod = { + 'title': EALang['not_working'], + 'start': GeneralFunctions.clone($calendar.fullCalendar('getView').start), + 'end': GeneralFunctions.clone($calendar.fullCalendar('getView').end), + 'allDay': false, + 'color': '#BEBEBE', + 'editable': false, + 'className': 'fc-unavailable' + }; + $calendar.fullCalendar('renderEvent', unavailablePeriod, true); + return; // go to next loop + } // Add unavailable period before work starts. var calendarDateStart = $calendar.fullCalendar('getView').start; @@ -1105,50 +1135,34 @@ var BackendCalendar = { $calendar.fullCalendar('renderEvent', unavailablePeriod, false); }); - // Add custom unavailable periods. - $.each(response.unavailables, function(index, unavailable) { - var unavailablePeriod = { - 'title': EALang['unavailable'] + '
' + ((unavailable.notes.length > 30) - ? unavailable.notes.substring(0, 30) + '...' - : unavailable.notes) + '', - 'start': Date.parse(unavailable.start_datetime), - 'end': Date.parse(unavailable.end_datetime), - 'allDay': false, - 'color': '#879DB4', - 'editable': true, - 'className': 'fc-unavailable fc-custom', - 'data': unavailable - }; - $calendar.fullCalendar('renderEvent', unavailablePeriod, false); - }); - break; case 'agendaWeek': var currDateStart = GeneralFunctions.clone($calendar.fullCalendar('getView').start); var currDateEnd = GeneralFunctions.clone(currDateStart).addDays(1); + // Add custom unavailable periods (they are always displayed + // on the calendar, even if the provider won't work on that day). + $.each(response.unavailables, function(index, unavailable) { + //if (currDateStart.toString('dd/MM/yyyy') + // === Date.parse(unavailable.start_datetime).toString('dd/MM/yyyy')) { + unavailablePeriod = { + 'title': EALang['unavailable'] + '
' + ((unavailable.notes.length > 30) + ? unavailable.notes.substring(0, 30) + '...' + : unavailable.notes) + '', + 'start': Date.parse(unavailable.start_datetime), + 'end': Date.parse(unavailable.end_datetime), + 'allDay': false, + 'color': '#879DB4', + 'editable': true, + 'className': 'fc-unavailable fc-custom', + 'data': unavailable + }; + $calendar.fullCalendar('renderEvent', unavailablePeriod, false); + //} + }); + $.each(workingPlan, function(index, workingDay) { - // Add custom unavailable periods (they are always displayed - // on the calendar, even if the provider won't work on that day). - $.each(response.unavailables, function(index, unavailable) { - if (currDateStart.toString('dd/MM/yyyy') - === Date.parse(unavailable.start_datetime).toString('dd/MM/yyyy')) { - var unavailablePeriod = { - 'title': EALang['unavailable'] + '
' + ((unavailable.notes.length > 30) - ? unavailable.notes.substring(0, 30) + '...' - : unavailable.notes) + '', - 'start': Date.parse(unavailable.start_datetime), - 'end': Date.parse(unavailable.end_datetime), - 'allDay': false, - 'color': '#879DB4', - 'editable': true, - 'className': 'fc-unavailable fc-custom', - 'data': unavailable - }; - $calendar.fullCalendar('renderEvent', unavailablePeriod, false); - } - }); if (workingDay == null) { // Add a full day unavailable event.