Refactor booking logic and table references for order_bookings
- Updated booking-related queries to use `order_bookings_o` for improved consistency and clarity. - Replaced `regNrTraekker`/`regNrTrailer` with `reg_1`/`reg_2` in queries and results. - Added `NULL` condition handling in `db_object_t` to support filtering by null field values. - Enhanced booking data extraction with renamed fields (`reference_number` → `reference`, `notes` → `note`).
This commit is contained in:
@@ -8,6 +8,7 @@ use objects\bookings_o;
|
||||
use objects\customer_vehicles_o;
|
||||
use objects\departments_o;
|
||||
use objects\logs_o;
|
||||
use objects\order_bookings_o;
|
||||
use objects\orders_o;
|
||||
use objects\plate_scans_o;
|
||||
use objects\products_o;
|
||||
@@ -794,23 +795,37 @@ class vehiclesRoute
|
||||
// Set the status based on priority: booked > verified > known > unknown
|
||||
if ($isBooked) {
|
||||
$status = 'booked';
|
||||
/**
|
||||
* // Get the booking
|
||||
* $booking = (new bookings_o())->getFieldsWhere([
|
||||
* 'regNrTraekker' => $reg,
|
||||
* 'status' => 'pending',
|
||||
* ], ['id', 'customer_number', 'reference_number', 'notes']);
|
||||
* // If there is no booking with the tractor reg, check the trailer reg
|
||||
* if (!$booking) {
|
||||
* $booking = (new bookings_o())->getFieldsWhere([
|
||||
* 'regNrTrailer' => $reg,
|
||||
* 'status' => 'pending',
|
||||
* ], ['id', 'customer_number', 'reference_number', 'notes']);
|
||||
* }
|
||||
*/
|
||||
// Get the booking
|
||||
$booking = (new bookings_o())->getFieldsWhere([
|
||||
'regNrTraekker' => $reg,
|
||||
'status' => 'pending',
|
||||
], ['id', 'customer_number', 'reference_number', 'notes']);
|
||||
$booking = (new order_bookings_o())->getFieldsWhere([
|
||||
'reg_1' => $reg,
|
||||
'order_id' => null,
|
||||
], ['id', 'customer_number', 'reference', 'note']);
|
||||
// If there is no booking with the tractor reg, check the trailer reg
|
||||
if (!$booking) {
|
||||
$booking = (new bookings_o())->getFieldsWhere([
|
||||
'regNrTrailer' => $reg,
|
||||
'status' => 'pending',
|
||||
], ['id', 'customer_number', 'reference_number', 'notes']);
|
||||
$booking = (new order_bookings_o())->getFieldsWhere([
|
||||
'reg_2' => $reg,
|
||||
'order_id' => null,
|
||||
], ['id', 'customer_number', 'reference', 'note']);
|
||||
}
|
||||
// Populate other variables
|
||||
$booking_id = $booking ? (int)$booking[0]['id'] : null;
|
||||
$customer_number = $booking ? (int)$booking[0]['customer_number'] : null;
|
||||
$reference = $booking ? (string)$booking[0]['reference_number'] : null;
|
||||
$notes = $booking ? (string)$booking[0]['notes'] : null;
|
||||
$reference = $booking ? (string)$booking[0]['reference'] : null;
|
||||
$notes = $booking ? (string)$booking[0]['note'] : null;
|
||||
// If the booking has a customer number, check if the customer is barred
|
||||
if ($customer_number && (new users_o())->isCustomerBarred((int)$customer_number)) {
|
||||
$status = 'card';
|
||||
@@ -917,29 +932,49 @@ class vehiclesRoute
|
||||
|
||||
private static function getBookedRegs(string $search, array $options = ['limit' => null]): array
|
||||
{
|
||||
$bookings_o = new bookings_o();
|
||||
$bookings_o = new order_bookings_o();
|
||||
/**
|
||||
* $bookings_o = new bookings_o();
|
||||
*
|
||||
* $results1 = $bookings_o->getFieldsWhereContaining(
|
||||
* [
|
||||
* 'regNrTraekker' => $search,
|
||||
* 'status' => 'pending',
|
||||
* ],
|
||||
* ['regNrTraekker'],
|
||||
* $options
|
||||
* );
|
||||
* $results2 = $bookings_o->getFieldsWhereContaining(
|
||||
* [
|
||||
* 'regNrTrailer' => $search,
|
||||
* 'status' => 'pending',
|
||||
* ],
|
||||
* ['regNrTrailer'],
|
||||
* $options
|
||||
* );
|
||||
*/
|
||||
$results1 = $bookings_o->getFieldsWhereContaining(
|
||||
[
|
||||
'regNrTraekker' => $search,
|
||||
'status' => 'pending',
|
||||
'reg_1' => $search,
|
||||
'order_id' => null,
|
||||
],
|
||||
['regNrTraekker'],
|
||||
['reg_1'],
|
||||
$options
|
||||
);
|
||||
$results2 = $bookings_o->getFieldsWhereContaining(
|
||||
[
|
||||
'regNrTrailer' => $search,
|
||||
'status' => 'pending',
|
||||
'reg_2' => $search,
|
||||
'order_id' => null,
|
||||
],
|
||||
['regNrTrailer'],
|
||||
['reg_2'],
|
||||
$options
|
||||
);
|
||||
return array_unique(array_merge(
|
||||
array_map(function ($row) {
|
||||
return (string)$row['regNrTraekker'];
|
||||
return (string)$row['reg_1'];
|
||||
}, $results1),
|
||||
array_map(function ($row) {
|
||||
return (string)$row['regNrTrailer'];
|
||||
return (string)$row['reg_2'];
|
||||
}, $results2)
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user