Refactor booking notifications and product restriction logic
- Enable department notification for new bookings. - Enhance Slack notification details for bookings, including customer, vehicle, and items. - Replace `isGuest` with `isProductDetailsRestricted` for better clarity in `productsRoute`. - Adjust product parsing to handle restricted product details consistently.
This commit is contained in:
@@ -100,7 +100,7 @@ class order_bookings_o extends db
|
||||
public function notifyNewBooking(): void
|
||||
{
|
||||
self::requireSelected();
|
||||
$department_notification = false;
|
||||
$department_notification = true;
|
||||
$customer_notification = true;
|
||||
/**
|
||||
* Get the department, branding and customer
|
||||
@@ -130,8 +130,31 @@ class order_bookings_o extends db
|
||||
if ($deliverSlack) {
|
||||
// Construct email
|
||||
$message = "*" . $branding->name->value() . "*\n";
|
||||
$message .= "_New Booking Created (TEST)_\n\n";
|
||||
$message .= "*Customer:* " . $customer->getCustomerName($customer_array['customer_number']) . " (`" . $customer_array['customer_number'] . "`)\n";
|
||||
$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
|
||||
$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());
|
||||
if (!empty($items)) {
|
||||
$message .= "Ydelser:\n" . implode("\n", array_filter($items)) . "\n";
|
||||
}
|
||||
// Send a notification to the department
|
||||
$slack = new slack();
|
||||
$slack->send_department_booking_notification($department->id, $message);
|
||||
|
||||
Reference in New Issue
Block a user