updating appointments
This commit is contained in:
parent
68751660aa
commit
5e776c9e2b
@ -193,11 +193,7 @@ function toggleAddressField() {
|
||||
}
|
||||
|
||||
function validateHolidayFrontend() {
|
||||
if (!calendar) return; // Calendar not initialized yet
|
||||
|
||||
var btnSave = document.getElementById('btnSaveApt');
|
||||
|
||||
// Reset state first to avoid getting stuck
|
||||
$('#holidayWarning').remove();
|
||||
if (btnSave) btnSave.disabled = false;
|
||||
|
||||
@ -208,38 +204,49 @@ function validateHolidayFrontend() {
|
||||
var startTimeStr = $('#apt_start_time').val();
|
||||
|
||||
if (!docId || !startTimeStr) return;
|
||||
|
||||
// Use API to check for holiday definitively (independent of calendar view)
|
||||
if (btnSave) btnSave.disabled = true; // Disable while checking
|
||||
|
||||
var datePrefix = startTimeStr.split('T')[0];
|
||||
var events = calendar.getEvents();
|
||||
var isHoliday = false;
|
||||
|
||||
for (var i = 0; i < events.length; i++) {
|
||||
var ev = events[i];
|
||||
// Check for doctor holiday events matching the selected doctor
|
||||
if (ev.extendedProps && ev.extendedProps.type === 'doctor_holiday' && ev.extendedProps.doctor_id == docId) {
|
||||
var evStartStr = ev.startStr ? ev.startStr.split('T')[0] : '';
|
||||
var evEndStr = ev.end ? ev.endStr.split('T')[0] : evStartStr;
|
||||
|
||||
if (ev.allDay) {
|
||||
// All day event: check if datePrefix is within range [start, end)
|
||||
if (datePrefix >= evStartStr && datePrefix < evEndStr) {
|
||||
isHoliday = true;
|
||||
break;
|
||||
fetch('api/doctor_holidays.php?doctor_id=' + docId)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
// Re-check current values to ensure they haven't changed while fetching
|
||||
var currentDocId = $('#apt_doctor_id').val();
|
||||
var currentStartTimeStr = $('#apt_start_time').val();
|
||||
if (currentDocId != docId || currentStartTimeStr != startTimeStr) return;
|
||||
|
||||
// Remove any existing warning to prevent duplication (especially from rapid successive calls)
|
||||
$('#holidayWarning').remove();
|
||||
|
||||
if (data.success && data.holidays) {
|
||||
var isHoliday = false;
|
||||
var datePrefix = startTimeStr.split('T')[0];
|
||||
|
||||
// Check if date is in any holiday range
|
||||
for (var i = 0; i < data.holidays.length; i++) {
|
||||
var h = data.holidays[i];
|
||||
// h.start_date and h.end_date are YYYY-MM-DD
|
||||
if (datePrefix >= h.start_date && datePrefix <= h.end_date) {
|
||||
isHoliday = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isHoliday) {
|
||||
$('<div id="holidayWarning" class="alert alert-warning mt-3 mb-0 small"><i class="bi bi-exclamation-triangle"></i> Selected doctor is on holiday on this date.</div>').appendTo('#appointmentDetailsModal .modal-body');
|
||||
if (btnSave) btnSave.disabled = true;
|
||||
} else {
|
||||
if (btnSave) btnSave.disabled = false;
|
||||
}
|
||||
} else {
|
||||
// Daily block or single time point
|
||||
if (datePrefix === evStartStr) {
|
||||
isHoliday = true;
|
||||
break;
|
||||
}
|
||||
if (btnSave) btnSave.disabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isHoliday) {
|
||||
$('<div id="holidayWarning" class="alert alert-warning mt-3 mb-0 small"><i class="bi bi-exclamation-triangle"></i> Selected doctor is on holiday on this date.</div>').appendTo('#appointmentDetailsModal .modal-body');
|
||||
if (btnSave) btnSave.disabled = true;
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Error checking holiday:', err);
|
||||
if (btnSave) btnSave.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
function toggleProviderField() {
|
||||
@ -388,8 +395,16 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
calendar = new FullCalendar.Calendar(calendarEl, {
|
||||
initialView: 'timeGridWeek',
|
||||
customButtons: {
|
||||
customToday: {
|
||||
text: '<?php echo __('today'); ?>',
|
||||
click: function() {
|
||||
calendar.today();
|
||||
}
|
||||
}
|
||||
},
|
||||
headerToolbar: {
|
||||
left: 'prev,next today',
|
||||
left: 'prev,next customToday',
|
||||
center: 'title',
|
||||
right: 'dayGridMonth,timeGridWeek,timeGridDay'
|
||||
},
|
||||
|
||||
2
lang.php
2
lang.php
@ -197,6 +197,7 @@ $translations = [
|
||||
// Dashboard & Common Missing Keys
|
||||
'total_patients' => 'Total Patients',
|
||||
'today_appointments' => 'Today\'s Appointments',
|
||||
'today' => 'Today',
|
||||
'revenue' => 'Revenue',
|
||||
'pending' => 'Pending',
|
||||
'add_patient' => 'Add Patient',
|
||||
@ -425,6 +426,7 @@ $translations = [
|
||||
// Dashboard & Common Missing Keys - Arabic
|
||||
'total_patients' => 'إجمالي المرضى',
|
||||
'today_appointments' => 'مواعيد اليوم',
|
||||
'today' => 'اليوم',
|
||||
'revenue' => 'الإيرادات',
|
||||
'pending' => 'معلق',
|
||||
'add_patient' => 'إضافة مريض',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user