Add getOrderBooking method to fetch linked booking object for orders

This commit is contained in:
Jeppe Bundgaard
2026-01-02 11:18:06 +01:00
parent e5c728f703
commit bcca9dd319
+17
View File
@@ -4,6 +4,7 @@ namespace objects;
use attachments\helpers\attachment_content;
use classes\db;
use classes\email;
use classes\pdf_generator;
use classes\motorapi;
use classes\object_property;
@@ -1497,4 +1498,20 @@ class orders_o extends db
self::requireSelected();
return !(new departments_o())->select((int)$this->department_id->value())->isExcludedFromInvoicing();
}
/**
* If the order is linked to a booking, get the booking object
* @return order_bookings_o|null The booking object if linked, null otherwise
* @throws Exception
*/
public function getOrderBooking(): order_bookings_o|null
{
self::requireSelected();
if ((int)$this->booking_id->value() <= 0) {
return null;
}
$booking = new order_bookings_o();
$booking->select((int)$this->booking_id->value());
return $booking->exists() ? $booking : null;
}
}