Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use company_working_plan hours instead of hardcoded hours #1503

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions application/language/arabic/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/bulgarian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/catalan/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/chinese/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/croatian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/czech/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/danish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/dutch/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/english/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/estonian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/finnish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Työsuunnitelman poikkeuksen alkamisajan on oltava ennen päättymisaikaa.';
// End
1 change: 1 addition & 0 deletions application/language/french/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/german/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/greek/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/hebrew/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/hindi/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/hungarian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/italian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/japanese/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/luxembourgish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/marathi/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/persian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/polish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/portuguese-br/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/portuguese/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/romanian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/russian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/serbian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/slovak/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/spanish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/swedish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/thai/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,5 @@
$lang['caldav_server'] = 'เซิร์ฟเวอร์ CalDAV';
$lang['caldav_connection_info_prompt'] = 'โปรดป้อนข้อมูลการเชื่อมต่อของเซิร์ฟเวอร์ CalDAV เป้าหมาย';
$lang['connect'] = 'เชื่อมต่อ';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
1 change: 1 addition & 0 deletions application/language/turkish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@
$lang['webhook_deleted'] = 'Webhook deleted successfully.';
$lang['delete_webhook'] = 'Delete Webhook';
$lang['contact_info'] = 'Contact Info';
$lang['working_plan_exception_start_before_end'] = 'Working plan exception start date must be before the end date.';
// End
2 changes: 1 addition & 1 deletion application/models/Providers_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public function save_working_plan_exception(int $provider_id, string $date, arra
$end = date('H:i', strtotime($working_plan_exception['end']));

if ($start > $end) {
throw new InvalidArgumentException('Working plan exception start date must be before the end date.');
throw new InvalidArgumentException(lang('working_plan_exception_start_before_end'));
}

// Make sure the provider record exists.
Expand Down
38 changes: 33 additions & 5 deletions assets/js/components/working_plan_exceptions_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,26 @@ App.Components.WorkingPlanExceptionsModal = (function () {
}

function resetTimeSelection() {
App.Utils.UI.setDateTimePickerValue($start, moment('08:00', 'HH:mm').toDate());
App.Utils.UI.setDateTimePickerValue($end, moment('20:00', 'HH:mm').toDate());
const dateTimeObject = App.Utils.UI.getDateTimePickerValue($date);
const plannedHours = getWeekdaysPlannedHours(App.Utils.Date.getWeekdayName(moment(dateTimeObject).day()));
App.Utils.UI.setDateTimePickerValue($start, moment(plannedHours['start'], 'HH:mm').toDate());
App.Utils.UI.setDateTimePickerValue($end, moment(plannedHours['end'], 'HH:mm').toDate());
}

function getWeekdaysPlannedHours(weekDay) {
hours = {};
const company_working_plan = JSON.parse(vars('company_working_plan'));
if (company_working_plan[weekDay]) {
hours["start"] = company_working_plan[weekDay]['start'];
hours["end"] = company_working_plan[weekDay]['end'];
} else {
hours["start"] = '08:00';
hours["end"] = '20:00';
}
return hours;
}


/**
* Open the modal and start adding a new working plan exception.
*
Expand Down Expand Up @@ -272,8 +288,9 @@ App.Components.WorkingPlanExceptionsModal = (function () {
$breaks.find('tbody .working-plan-exceptions-break-start, tbody .working-plan-exceptions-break-end'),
);
} else {
App.Utils.UI.setDateTimePickerValue($start, moment('08:00', 'HH:mm').toDate());
App.Utils.UI.setDateTimePickerValue($end, moment('20:00', 'HH:mm').toDate());
const plannedHours = getWeekdaysPlannedHours(App.Utils.Date.getWeekdayName(moment(date).day()));
App.Utils.UI.setDateTimePickerValue($start, moment(plannedHours['start'], 'HH:mm').toDate());
App.Utils.UI.setDateTimePickerValue($end, moment(plannedHours['end'], 'HH:mm').toDate());
$breaks.find('tbody').html(renderNoBreaksRow());
}

Expand Down Expand Up @@ -454,6 +471,16 @@ App.Components.WorkingPlanExceptionsModal = (function () {
$addBreak.prop('disabled', false);
}

/**
* Event: Edit Date "Change"
*/
function onEditDateChange() {
const dateTimeObject = App.Utils.UI.getDateTimePickerValue($date);
const plannedHours = getWeekdaysPlannedHours(App.Utils.Date.getWeekdayName(moment(dateTimeObject).day()));
App.Utils.UI.setDateTimePickerValue($start, moment(plannedHours['start'], 'HH:mm').toDate());
App.Utils.UI.setDateTimePickerValue($end, moment(plannedHours['end'], 'HH:mm').toDate());
}

/**
* Event: Is Non-Working Day "Change"
*/
Expand All @@ -477,7 +504,8 @@ App.Components.WorkingPlanExceptionsModal = (function () {
.on('click', '.working-plan-exceptions-edit-break', onEditBreakClick)
.on('click', '.working-plan-exceptions-delete-break', onDeleteBreakClick)
.on('click', '.working-plan-exceptions-save-break', onSaveBreakClick)
.on('click', '.working-plan-exceptions-cancel-break', onCancelBreakClick);
.on('click', '.working-plan-exceptions-cancel-break', onCancelBreakClick)
.on('change', '#working-plan-exceptions-date', onEditDateChange);

$save.on('click', onSaveClick);

Expand Down
41 changes: 28 additions & 13 deletions assets/js/utils/calendar_default_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ App.Utils.CalendarDefaultView = (function () {
let $popoverTarget;
let fullCalendar = null;
let lastFocusedEventData; // Contains event data for later use.
let backupExceptionDate = undefined;

/**
* Add the utility event listeners.
Expand Down Expand Up @@ -91,6 +92,7 @@ App.Utils.CalendarDefaultView = (function () {

if (data.hasOwnProperty('workingPlanException')) {
const date = lastFocusedEventData.extendedProps.data.date;
backupExceptionDate = date;
const workingPlanException = lastFocusedEventData.extendedProps.data.workingPlanException;
const provider = lastFocusedEventData.extendedProps.data.provider;

Expand All @@ -116,6 +118,13 @@ App.Utils.CalendarDefaultView = (function () {
$reloadAppointments.trigger('click'); // Update the calendar.
};

if (backupExceptionDate != date) {
// if date has changed, delete the old working plan exception before saving on the new date
deleteWorkingPlanExceptionsData(provider, backupExceptionDate);
App.Http.Calendar.deleteWorkingPlanException(backupExceptionDate, provider.id, successCallback);
backupExceptionDate = undefined;
}

App.Http.Calendar.saveWorkingPlanException(
date,
workingPlanException,
Expand Down Expand Up @@ -224,19 +233,7 @@ App.Utils.CalendarDefaultView = (function () {

const successCallback = () => {
App.Layouts.Backend.displayNotification(lang('working_plan_exception_deleted'));

const workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions) || {};
delete workingPlanExceptions[date];

for (const index in vars('available_providers')) {
const availableProvider = vars('available_providers')[index];

if (Number(availableProvider.id) === Number(providerId)) {
availableProvider.settings.working_plan_exceptions = JSON.stringify(workingPlanExceptions);
break;
}
}

deleteWorkingPlanExceptionsData(provider, date);
$reloadAppointments.trigger('click'); // Update the calendar.
};

Expand Down Expand Up @@ -371,6 +368,24 @@ App.Utils.CalendarDefaultView = (function () {
return notes.length > 100 ? notes.substring(0, 100) + '...' : notes;
}

/**
* Delete working plan exception data.
*
*/
function deleteWorkingPlanExceptionsData(provider, deleteDate) {
const workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions) || {};
delete workingPlanExceptions[deleteDate];

for (const index in vars('available_providers')) {
const availableProvider = vars('available_providers')[index];

if (Number(availableProvider.id) === Number(provider.id)) {
availableProvider.settings.working_plan_exceptions = JSON.stringify(workingPlanExceptions);
break;
}
}
}

/**
* Calendar Event "Click" Callback
*
Expand Down