Enhance vehiclesRoute to include customer status checks for known vehicles

- Added logic to determine if a known vehicle has been assigned to a specific customer and retrieve the customer name.
- Integrated checks to handle barred customers by resetting vehicle status to `unknown` and clearing customer details.
- Ensured support for scenarios with multiple known customers, marking vehicles accordingly.
This commit is contained in:
Jeppe Bundgaard
2025-09-18 10:13:29 +02:00
parent e1a5618888
commit 94bbf0a106
@@ -831,6 +831,26 @@ class vehiclesRoute
}
} elseif ($isKnown) {
$status = 'known';
// Check if the vehicle previously only has been set to a specific customer, and if so, get the customer name
$orders_o = new orders_o();
$order = $orders_o->getFieldsWhere([
'reg_1' => $reg,
'deleted_at' => null, // Only consider non-deleted orders
], ['customer_id']);
$customer_ids = array_unique(array_map(function ($row) {
return (int)$row['customer_id'];
}, $order));
if (count($customer_ids) === 1) {
$customer_number = $customer_ids[0];
// Check if the customer is barred (only if known)
if ($customer_number && (new users_o())->isCustomerBarred((int)$customer_number)) {
$status = 'unknown'; // If the customer is barred, we set the status to unknown (as we don't need to know about barred known vehicles)
$customer_number = null; // Clear the customer number as well
}
} else {
// Set the customer name to multiple known customers
$customer_name = 'Multiple known customers';
}
} elseif ($isUnknown) {
$status = 'unknown';
}