Skip to content

Commit

Permalink
Fixed save working plan exception handling for calendar page and non …
Browse files Browse the repository at this point in the history
…working days (#1548)
  • Loading branch information
alextselegidis committed May 27, 2024
1 parent 3bc2e69 commit 2d41f18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion application/controllers/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ public function save_working_plan_exception(): void

$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);
}

Expand Down
15 changes: 10 additions & 5 deletions application/models/Providers_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,18 +525,23 @@ public function save_working_plan_exception(
): 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.
Expand Down

0 comments on commit 2d41f18

Please sign in to comment.