From 3cbce2a68f7683525b81e5a4c1f11520d32fff6f Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Tue, 9 Dec 2025 10:58:34 +0100 Subject: [PATCH] Add detailed customer booking notifications with message formatting - Enhanced booking notifications to include comprehensive customer and booking details. - Implemented message formatting for clarity: customer info, date, vehicle(s), items, references, PO, and pickup status. - Improved notification structure by integrating branding name into messages. --- .../nginx/app/objects/order_bookings_o.php | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/services/nginx/app/objects/order_bookings_o.php b/services/nginx/app/objects/order_bookings_o.php index e4bd7377..a531cdd4 100644 --- a/services/nginx/app/objects/order_bookings_o.php +++ b/services/nginx/app/objects/order_bookings_o.php @@ -119,6 +119,39 @@ class order_bookings_o extends db $customer = (new users_o())->getUserByCustomerNumber((int)$this->customer_number->value()); $department_array = $department->asArray(); $customer_array = $customer->asArray(); + $message = ""; + $message .= "Ny booking fra {$customer->getCustomerName($customer_array['customer_number'])} (Kundenr: {$customer_array['customer_number']}, Bookingnr: {$this->id})\n"; + $message .= "Dato: " . date('d-m-Y H:i', strtotime($this->datetime->value())) . "\n"; + $message .= "Køretøj: " . $this->reg_1->value() . (!empty($this->reg_2->value()) ? ", " . $this->reg_2->value() : "") . ( + !empty($this->reg_3->value()) ? ", " . $this->reg_3->value() : "" + ) ."\n"; + // If the booking has a note, add it to the message + if (!empty($this->note->value())) $message .= "Note: " . $this->note->value() . "\n"; + // If the booking has items, add them to the message + if (!empty($this->items->value())) { + $items = array_map(function ($item) { + // Get the product name + $product = (new products_o())->select((int)$item['id']); + if (!$product->exists()) { + return null; + } + $item['name'] = $product->name->value(); + if (!isset($item['quantity'])) { + $item['quantity'] = 1; + } + return "- " . $item['quantity'] . " x " . $item['name']; + }, $this->items->value()); + $message .= "Ydelser:\n" . implode("\n", array_filter($items)) . "\n"; + } + // If the booking has a reference, add it to the message + if (!empty($this->reference->value())) $message .= "Reference: " . $this->reference->value() . "\n"; + // If the booking has a PO, add it to the message + if (!empty($this->po->value())) $message .= "PO: " . $this->po->value() . "\n"; + if ($this->pickup->value()) $message .= "Afhentning: Ja\n"; else $message .= "Afhentning: Nej\n"; + // If the booking has a note, add it to the message + if (!empty($this->note->value())) $message .= "Note: " . $this->note->value() . "\n"; + // Add the branding name + $message = "*" . $branding->name->value() . "*\n" . $message; /** * Department booking notification */ @@ -169,7 +202,8 @@ class order_bookings_o extends db // Add all the phone numbers from the department ...$department->notificationSmsPhoneNumbers() ], - 'New booking from ' . $customer->getCustomerName($customer_array['customer_number']) . ' (' . $this->id . ')', + $message, + true ); } catch (Exception $e) { // Log the error