diff --git a/services/nginx/app/routes/vehiclesRoute.php b/services/nginx/app/routes/vehiclesRoute.php index 8bf3fe37..94084d96 100644 --- a/services/nginx/app/routes/vehiclesRoute.php +++ b/services/nginx/app/routes/vehiclesRoute.php @@ -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) )); } diff --git a/services/nginx/app/traits/db_object_t.php b/services/nginx/app/traits/db_object_t.php index ecee8913..893ad950 100644 --- a/services/nginx/app/traits/db_object_t.php +++ b/services/nginx/app/traits/db_object_t.php @@ -191,6 +191,11 @@ trait db_object_t $table = $this->table; $where = []; foreach ( $fieldsAndValues as $field => $value ) { + // Check if the value is null + if ($value === null) { + $where[] = "$field IS NULL"; + continue; + } // Escape the value to prevent SQL injection $value = $db->escape_string($value); $where[] = "$field LIKE '%$value%'";