From 2d41f181a1f2348819809e6f72c4764047a725b3 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Mon, 27 May 2024 16:46:38 +0200 Subject: [PATCH] Fixed save working plan exception handling for calendar page and non working days (#1548) --- application/controllers/Calendar.php | 2 +- application/models/Providers_model.php | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/application/controllers/Calendar.php b/application/controllers/Calendar.php index 54003c42..3675e235 100644 --- a/application/controllers/Calendar.php +++ b/application/controllers/Calendar.php @@ -480,7 +480,7 @@ class Calendar extends EA_Controller $this->providers_model->save_working_plan_exception($provider_id, $date, $working_plan_exception); - if ($date !== $original_date) { + if ($original_date && $date !== $original_date) { $this->providers_model->delete_working_plan_exception($provider_id, $original_date); } diff --git a/application/models/Providers_model.php b/application/models/Providers_model.php index a6012b62..5f3fa9da 100755 --- a/application/models/Providers_model.php +++ b/application/models/Providers_model.php @@ -525,18 +525,23 @@ class Providers_model extends EA_Model ): void { // Validate the working plan exception data. - if (empty($working_plan_exception['start']) || empty($working_plan_exception['end'])) { + if ( + !empty($working_plan_exception) && + (empty($working_plan_exception['start']) || empty($working_plan_exception['end'])) + ) { throw new InvalidArgumentException( 'Empty start and/or end time provided: ' . json_encode($working_plan_exception), ); } - $start = date('H:i', strtotime($working_plan_exception['start'])); + if (!empty($working_plan_exception['start']) && !empty($working_plan_exception['end'])) { + $start = date('H:i', strtotime($working_plan_exception['start'])); - $end = date('H:i', strtotime($working_plan_exception['end'])); + $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.'); + if ($start > $end) { + throw new InvalidArgumentException('Working plan exception start date must be before the end date.'); + } } // Make sure the provider record exists.