Add email and notification improvements for bookings
Refactored notification methods to handle Slack, SMS, and email delivery logic more effectively. Introduced `sendBookingNotification` email functionality and a new template for booking notifications. Improved handling of booking data for emails and centralized logic for retrieving booking details.
This commit is contained in:
@@ -283,6 +283,7 @@ class bookings_o extends db
|
||||
/**
|
||||
* Notify the department about a new booking
|
||||
* @throws Exception If the object is not selected
|
||||
* @throws ClientExceptionInterface If the request to the API fails
|
||||
*/
|
||||
public function notifyNewBooking(): void
|
||||
{
|
||||
@@ -301,8 +302,19 @@ class bookings_o extends db
|
||||
$customer = (new users_o())->getUserByCustomerNumber((int)$this->customer_number->value());
|
||||
$department_array = $department->asArray();
|
||||
$customer_array = $customer->asArray();
|
||||
// Define delivery methods
|
||||
$deliverSlack = !empty($department->slack_webhook->value());
|
||||
$deliverSMS = (
|
||||
!empty($branding->phone_country_code->value()) &&
|
||||
!empty($branding->phone->value()) &&
|
||||
!$deliverSlack // Only send SMS if slack is not available
|
||||
);
|
||||
$deliverEmail = (
|
||||
!empty($this->contact_email->value()) &&
|
||||
!$deliverSlack // Only send email if slack is not available
|
||||
);
|
||||
// Check if the department has a slack webhook
|
||||
if (!empty($department->slack_webhook->value())) {
|
||||
if ($deliverSlack) {
|
||||
// Send a notification to the department
|
||||
$slack = new slack();
|
||||
$slack->send_department_booking_notification($department->id, $slack->format_new_booking(
|
||||
@@ -322,7 +334,9 @@ class bookings_o extends db
|
||||
$this->washCertificateUrl->value(),
|
||||
$this->status->value()
|
||||
));
|
||||
} elseif (!empty($branding->phone_country_code->value()) && !empty($branding->phone->value())) {
|
||||
}
|
||||
|
||||
if (!$deliverSMS) {
|
||||
// Send an SMS notification to the department
|
||||
$gatewayapi = new gatewayapi();
|
||||
$gatewayapi->send(
|
||||
@@ -330,6 +344,12 @@ class bookings_o extends db
|
||||
'New booking from ' . $customer->getCustomerName($customer_array['customer_number']) . ' (' . $this->id . ')',
|
||||
);
|
||||
}
|
||||
|
||||
if ($deliverEmail) {
|
||||
// Send an email notification to the department
|
||||
$email = new email();
|
||||
$email->sendBookingNotification($this->id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user