diff --git a/application/controllers/Pages.php b/application/controllers/Pages.php index 86e8046..e8ebda3 100755 --- a/application/controllers/Pages.php +++ b/application/controllers/Pages.php @@ -210,7 +210,12 @@ class Pages extends CI_Controller { } if(isset($_POST['action']) && $_POST['action'] == 'getAvailableTimes' && isset($_POST['selectedDate'])){ - $results = $this->Service_model->getAvailableTimes($_POST['worker_id'], $_POST['selectedDate'], $_POST['servicelength'].':00'); + $excludeBookingId = null; + if(!empty($_POST['manage_token'])){ + $existingBooking = $this->Service_model->getBookingByToken($_POST['manage_token']); + if($existingBooking) $excludeBookingId = $existingBooking->booking_id; + } + $results = $this->Service_model->getAvailableTimes($_POST['worker_id'], $_POST['selectedDate'], $_POST['servicelength'].':00', $excludeBookingId); $rowIndex = 1; if(!empty($results)){ @@ -820,10 +825,8 @@ class Pages extends CI_Controller { return; } - // Slot availability (temporarily exclude current booking) - $this->Service_model->updateBooking($booking->booking_id, ['booking_date' => '1970-01-01']); - $available = $this->Service_model->getAvailableTimes($newWorkerId, $newBookingDate, $servicelength); - $this->Service_model->updateBooking($booking->booking_id, ['booking_date' => $booking->booking_date]); + // Slot availability (exclude current booking from conflict check) + $available = $this->Service_model->getAvailableTimes($newWorkerId, $newBookingDate, $servicelength, $booking->booking_id); if(!is_array($available) || !in_array($newStartTime, $available)){ $this->output->set_status_header(409)->set_content_type('application/json') @@ -921,40 +924,61 @@ class Pages extends CI_Controller { $subject = '[studiobeve] Din bestilling er oppdatert'; $content = 'Kjære gjest,
Din bestilling er oppdatert.

'; $content .= ''; + $content .= ''; + $content .= ''; + $content .= ''; $content .= ''; $content .= ''; $content .= ''; $content .= '
Navn: '.$booking->guest_name.'
E-post: '.$booking->guest_email.'
Telefon: '.$booking->guest_phone.'
Arbeider: '.$worker->worker_name.'
Dato: '.$newBookingDate.'
Tid: '.$newStartTime.' - '.$finishTime.'
Tjenester: '; foreach($serviceArray as $s){ $content .= ''; } - $content .= '
'.$s->service_name_no.''.$s->service_price.' kr
Totalpris: '.$totalServicePrice.' kr
'; - $content .= '

Administrer bestilling'; - $content .= '

STUDIOBEVE'; + $content .= ''; + $content .= 'Totalpris: '.$totalServicePrice.' kr'; + $content .= ''; + $content .= '

Administrer bestilling
'; + $content .= '
Dersom noe skulle dukke opp og du ikke kan komme til avtalen din, vennligst gi oss beskjed minst 24 timer i forveien, slik at vi kan gi timen videre til en annen kunde og våre kollegers tid ikke blir stående ubrukt; avbestillinger innen 24 timer, eller manglende oppmøte, vil bli belastet med full pris for behandlingen; avbestilling kan gjøres via e-post til info@studiobeve.no eller ved å sende oss en melding på Instagram eller Facebook. Takk for forståelsen og samarbeidet!'; + $content .= '
'; + $content .= '
STUDIOBEVE'; break; case 'hu': $subject = '[studiobeve] A foglalásod módosítva lett'; $content = 'Kedves Vendégünk,
A foglalásod módosítva lett.

'; $content .= ''; + $content .= ''; + $content .= ''; + $content .= ''; $content .= ''; $content .= ''; $content .= ''; $content .= '
Név: '.$booking->guest_name.'
Email: '.$booking->guest_email.'
Telefon: '.$booking->guest_phone.'
Dolgozó: '.$worker->worker_name.'
Dátum: '.$newBookingDate.'
Időpont: '.$newStartTime.' - '.$finishTime.'
Szolgáltatás(ok): '; foreach($serviceArray as $s){ $content .= ''; } - $content .= '
'.$s->service_name_hu.''.$s->service_price.' kr
Összesen: '.$totalServicePrice.' kr
'; - $content .= '

Foglalás kezelése'; - $content .= '

STUDIOBEVE'; + $content .= ''; + $content .= 'Összesen fizetendő: '.$totalServicePrice.' kr'; + $content .= ''; + $content .= '

Foglalás kezelése
'; + $content .= '
Kérünk, ha valami közbejön, és mégsem tudsz eljönni a lefoglalt időpontodra, jelezd nekünk legalább 24 órával előre, így más vendégnek is tudunk szabad időpontot biztosítani, és kollégáink ideje sem marad kihasználatlanul; 24 órán belüli lemondás, illetve meg nem jelenés esetén a szolgáltatás teljes díja felszámításra kerül; a lemondást az info@studiobeve.no e-mail címen, vagy Instagram- és Facebook-üzenetben tudod megtenni. Köszönjük a megértést és az együttműködést!'; + $content .= '
'; + $content .= '
STUDIOBEVE'; break; default: $subject = '[studiobeve] Your booking has been updated'; $content = 'Dear Guest,
Your booking has been updated.

'; $content .= ''; + $content .= ''; + $content .= ''; + $content .= ''; $content .= ''; $content .= ''; $content .= ''; $content .= '
Name: '.$booking->guest_name.'
Email: '.$booking->guest_email.'
Phone: '.$booking->guest_phone.'
Worker: '.$worker->worker_name.'
Date: '.$newBookingDate.'
Time: '.$newStartTime.' - '.$finishTime.'
Services: '; foreach($serviceArray as $s){ $content .= ''; } - $content .= '
'.$s->service_name_en.''.$s->service_price.' kr
Total price: '.$totalServicePrice.' kr
'; - $content .= '

Manage booking'; - $content .= '

STUDIOBEVE'; + $content .= ''; + $content .= 'Total price: '.$totalServicePrice.' kr'; + $content .= ''; + $content .= '

Manage booking
'; + $content .= '
If something comes up and you can’t make it to your booked appointment, please let us know at least 24 hours in advance so we can offer the time slot to another guest and our colleagues’ time won’t remain unused; cancellations within 24 hours or no-shows will be charged the full service fee; you can cancel by emailing info@studiobeve.no, or by sending us a message on Instagram or Facebook. Thank you for your understanding and cooperation!'; + $content .= '
'; + $content .= '
STUDIOBEVE'; } $emailArray = array(array( diff --git a/application/models/Service_model.php b/application/models/Service_model.php index d568b04..70b64e7 100755 --- a/application/models/Service_model.php +++ b/application/models/Service_model.php @@ -396,7 +396,7 @@ class Service_model extends CI_Model { } - public function getAvailableTimes($worker_id, $selectedDate, $servicelength) { + public function getAvailableTimes($worker_id, $selectedDate, $servicelength, $exclude_booking_id = null) { $this->load->database(); // múltbeli napra ne lehessen foglalni @@ -490,10 +490,17 @@ class Service_model extends CI_Model { $allBookings = []; if ($lunchRequired) { - $allBookings = $this->db->query(" - SELECT booking_start_time, booking_finish_time FROM bookings - WHERE booking_date = ? AND worker_id = ? - ", array($selectedDate, $worker_id))->result(); + if ($exclude_booking_id !== null) { + $allBookings = $this->db->query(" + SELECT booking_start_time, booking_finish_time FROM bookings + WHERE booking_date = ? AND worker_id = ? AND booking_id != ? + ", array($selectedDate, $worker_id, $exclude_booking_id))->result(); + } else { + $allBookings = $this->db->query(" + SELECT booking_start_time, booking_finish_time FROM bookings + WHERE booking_date = ? AND worker_id = ? + ", array($selectedDate, $worker_id))->result(); + } } $interval = new DateInterval('PT15M'); @@ -508,12 +515,22 @@ class Service_model extends CI_Model { $startTimeStr = $current->format('H:i:s'); $endTimeStr = $slotEnd->format('H:i:s'); - $bookingQuery = $this->db->query(" - SELECT * FROM bookings - WHERE booking_date = ? - AND worker_id = ? - AND booking_start_time < ? AND booking_finish_time > ? - ", array($selectedDate, $worker_id, $endTimeStr, $startTimeStr)); + if ($exclude_booking_id !== null) { + $bookingQuery = $this->db->query(" + SELECT * FROM bookings + WHERE booking_date = ? + AND worker_id = ? + AND booking_id != ? + AND booking_start_time < ? AND booking_finish_time > ? + ", array($selectedDate, $worker_id, $exclude_booking_id, $endTimeStr, $startTimeStr)); + } else { + $bookingQuery = $this->db->query(" + SELECT * FROM bookings + WHERE booking_date = ? + AND worker_id = ? + AND booking_start_time < ? AND booking_finish_time > ? + ", array($selectedDate, $worker_id, $endTimeStr, $startTimeStr)); + } if ($bookingQuery->num_rows() > 0) continue; // already booked diff --git a/application/views/pages/manage-booking.php b/application/views/pages/manage-booking.php index 06c6769..6e7af53 100755 --- a/application/views/pages/manage-booking.php +++ b/application/views/pages/manage-booking.php @@ -562,7 +562,8 @@ action: 'getAvailableTimes', worker_id: $('#worker_id').val(), servicelength: $('#servicelength').val(), - selectedDate: selectedDate + selectedDate: selectedDate, + manage_token: '' }, }).done(function(result){ if(result != 0){