From 6efa414251361a03d1457c7fcf6e881f3655768a Mon Sep 17 00:00:00 2001 From: Jepp9350 <2jepp9350@gmail.com> Date: Mon, 14 Apr 2025 09:58:25 +0200 Subject: [PATCH] Refactor SMS and notification logic; add email template. Updated the SMS sending logic to improve validation and handling of recipients in `gatewayapi.php`. Refactored notification conditions in `bookings_o.php` to ensure proper fallback mechanisms. Additionally, included a new booking notification email template in `email.php`. --- services/nginx/app/classes/email.php | 1 + services/nginx/app/classes/gatewayapi.php | 2 +- services/nginx/app/objects/bookings_o.php | 11 +++++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/services/nginx/app/classes/email.php b/services/nginx/app/classes/email.php index d3e4bb9e..3853cc7a 100644 --- a/services/nginx/app/classes/email.php +++ b/services/nginx/app/classes/email.php @@ -8,6 +8,7 @@ require_once WD . '/modules/email/templates/email_template_footer.php'; require_once WD . '/modules/email/templates/email_template_head.php'; require_once WD . '/modules/email/templates/email_template_stripe_invoice.php'; require_once WD . '/modules/email/templates/email_template_booking_confirmation.php'; +require_once WD . '/modules/email/templates/email_template_booking_notification.php'; require_once WD . '/modules/email/templates/email_template_wash_certificate.php'; use email\email_c; diff --git a/services/nginx/app/classes/gatewayapi.php b/services/nginx/app/classes/gatewayapi.php index ed130144..7bad0856 100644 --- a/services/nginx/app/classes/gatewayapi.php +++ b/services/nginx/app/classes/gatewayapi.php @@ -36,7 +36,7 @@ class gatewayapi implements gatewayapi_i $data = [ "recipients" => array_map(function ($recipient) { return [ - 'msisdn' => (int)$recipient, + 'msisdn' => $recipient, ]; }, $to), 'message' => $message, diff --git a/services/nginx/app/objects/bookings_o.php b/services/nginx/app/objects/bookings_o.php index 0729e505..6e43e27f 100644 --- a/services/nginx/app/objects/bookings_o.php +++ b/services/nginx/app/objects/bookings_o.php @@ -303,11 +303,11 @@ class bookings_o extends db $department_array = $department->asArray(); $customer_array = $customer->asArray(); // Define delivery methods - $deliverSlack = !empty($department->slack_webhook->value()); + $deliverSlack = (boolean)!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 + ((int)$branding->phone->value() > 0) ); $deliverEmail = ( !empty($this->contact_email->value()) && @@ -336,11 +336,14 @@ class bookings_o extends db )); } - if (!$deliverSMS) { + if ($deliverSMS) { // Send an SMS notification to the department $gatewayapi = new gatewayapi(); + $phone = '' . $branding->phone_country_code->value() . $branding->phone->value(); $gatewayapi->send( - [$branding->phone_country_code->value() . $branding->phone->value()], + [ + $phone, + ], 'New booking from ' . $customer->getCustomerName($customer_array['customer_number']) . ' (' . $this->id . ')', ); }