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.
This commit is contained in:
Jeppe Bundgaard
2025-12-09 10:58:34 +01:00
parent 68e93fdd9d
commit 3cbce2a68f
@@ -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