Add 'barred' status to customer and vehicle data
Introduced the 'barred' property to identify barred customers and vehicles. Updated relevant classes, methods, and API endpoints to handle this new field. Enhanced plate scans to include the barred status for vehicles based on customer association.
This commit is contained in:
@@ -18,6 +18,7 @@ class economic_customer_mo
|
||||
public null|string $mobilePhone;
|
||||
public null|string $currency;
|
||||
public null|string $country;
|
||||
public bool $barred;
|
||||
|
||||
public function getCustomerByCustomerNumber(int $customer_number): static
|
||||
{
|
||||
@@ -46,6 +47,7 @@ class economic_customer_mo
|
||||
$this->mobilePhone = ($customer->mobilePhone ?? null);
|
||||
$this->currency = ($customer->currency ?? null);
|
||||
$this->country = ($customer->country ?? null);
|
||||
$this->barred = (isset($customer->barred) ? (bool)$customer->barred : false);
|
||||
$users_o = new users_o();
|
||||
$user = $users_o->getUserByCustomerNumber($this->customer_number);
|
||||
|
||||
@@ -75,6 +77,7 @@ class economic_customer_mo
|
||||
'mobilePhone' => $this->mobilePhone,
|
||||
'currency' => $this->currency,
|
||||
'country' => $this->country,
|
||||
'barred' => $this->barred,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -46,15 +46,17 @@ class customer_vehicles_o extends db
|
||||
self::getAvailableAddons()
|
||||
);
|
||||
$last_order_id = self::getLastOrderId();
|
||||
$customer_number = (int)$this->customer_id->value();
|
||||
return [
|
||||
'id' => (int)$this->id,
|
||||
'user_id' => (int)(new users_o())->getUserIdFromEconomic((int)$this->customer_id->value()),
|
||||
'user_id' => (int)(new users_o())->getUserIdFromEconomic((int)$customer_number),
|
||||
'customer_id' => (int)$this->customer_id->value(),
|
||||
'customer_name' => (string)(new users_o())->getCustomerName((int)$this->customer_id->value()),
|
||||
'customer_name' => (string)(new users_o())->getCustomerName((int)$customer_number),
|
||||
'type' => (int)$this->type->value(),
|
||||
'reg' => (string)$this->reg->value(),
|
||||
'reference' => ($this->reference->value() ? (string)$this->reference->value() : null),
|
||||
'wash_subscription' => $wash_subscription,
|
||||
'barred' => (bool)(new users_o())->isCustomerBarred((int)$customer_number),
|
||||
'addons' => [
|
||||
'enabled' => count($addons),
|
||||
'available' => count($available_addons),
|
||||
@@ -197,5 +199,27 @@ class customer_vehicles_o extends db
|
||||
$this->deleted_at = new object_property($this->table, $this->id, 'deleted_at', 'timestamp', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the customer object for the vehicle
|
||||
* @param string $reg The registration number of the vehicle
|
||||
* @return int|null The customer number for the vehicle, or null if the vehicle is not registered to a customer
|
||||
* @throws Exception If the customer_id does not exist
|
||||
*/
|
||||
public function getPlateCustomerNumber(string $reg): int|null
|
||||
{
|
||||
// Get the customer id from the vehicle
|
||||
$result = self::getFieldsWhere([
|
||||
'reg' => $reg,
|
||||
], [
|
||||
'customer_id',
|
||||
]);
|
||||
// If the customer id is not found, return null
|
||||
if (count($result) === 0) {
|
||||
return null;
|
||||
}
|
||||
// If the customer id is found, return it
|
||||
return (int)$result[0]['customer_id'];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1078,4 +1078,24 @@ class users_o extends db
|
||||
// Set the email
|
||||
$this->email->set($email);
|
||||
}
|
||||
|
||||
public function isCustomerBarred(int $customer_number): bool
|
||||
{
|
||||
if ($customer_number === 0) {
|
||||
return false;
|
||||
}
|
||||
// Create a temporary user object
|
||||
$tmp_user = new users_o();
|
||||
$tmp_user->getUserByCustomerNumber($customer_number);
|
||||
// Get the customer name (Check cache first)
|
||||
$cached = $tmp_user->getCached('economic_customer');
|
||||
if (!$cached) {
|
||||
$tmp_user->getCustomerEcocomicData($customer_number);
|
||||
$cached = $tmp_user->getCached('economic_customer');
|
||||
}
|
||||
if ($cached) {
|
||||
return (isset($cached->barred) && $cached->barred);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,10 @@
|
||||
namespace routes;
|
||||
|
||||
use classes\authentication;
|
||||
use objects\customer_vehicles_o;
|
||||
use objects\logs_o;
|
||||
use objects\plate_scans_o;
|
||||
use objects\users_o;
|
||||
use traits\route_t;
|
||||
|
||||
class plateScansRoute
|
||||
@@ -81,7 +83,26 @@ class plateScansRoute
|
||||
if ($user) {
|
||||
// Get the number plate scans
|
||||
$number_plate_scans = (new plate_scans_o());
|
||||
$result = $number_plate_scans->listObjectsWithPaginationIfSet(null,
|
||||
$result = $number_plate_scans->listObjectsWithPaginationIfSet(
|
||||
function ($scan) {
|
||||
$tmp_scan_customer = [
|
||||
'barred' => false,
|
||||
'customer_number' => null,
|
||||
];
|
||||
// Check if the vehicle is registered to a customer
|
||||
$vehicle_customer_number = (new customer_vehicles_o())->getPlateCustomerNumber((string)$scan['plate']);
|
||||
if ($vehicle_customer_number) {
|
||||
$tmp_scan_customer = [
|
||||
'barred' => (new users_o())->isCustomerBarred($vehicle_customer_number),
|
||||
'customer_number' => (int)$vehicle_customer_number,
|
||||
];
|
||||
}
|
||||
// Return the object as an array
|
||||
return [
|
||||
...$scan,
|
||||
...$tmp_scan_customer,
|
||||
];
|
||||
},
|
||||
$number_plate_scans->forceRestrictFilters(
|
||||
[
|
||||
'department_id' => $user->getGroup()->getDepartments()
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace routes;
|
||||
|
||||
use classes\authentication;
|
||||
use customers\economic_customer_mo;
|
||||
use objects\customer_vehicles_o;
|
||||
use objects\logs_o;
|
||||
use objects\orders_o;
|
||||
@@ -387,6 +388,7 @@ class vehiclesRoute
|
||||
'id' => (int)$customer->id,
|
||||
'customer_name' => (string)$customer->getCustomerName((int)$customer_number),
|
||||
'customer_number' => (int)$customer_number,
|
||||
'barred' => (new economic_customer_mo())->getCustomerByCustomerNumber((int)$customer_number)->asArray()['barred'],
|
||||
];
|
||||
}, $customers)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user