Add support for invoicing period retrieval and enhanced filtering options for wash subscription transactions

This commit is contained in:
Jepp9350
2025-06-02 14:08:57 +02:00
parent dcc6a56009
commit 27ca81ba8f
4 changed files with 175 additions and 3 deletions
@@ -417,6 +417,49 @@ class vehiclesRoute
'list_vehicle_customer_suggestions' => 'List customer suggestions for a vehicle',
]
);
$this->get('/superuser/users-with-vehicle-subscriptions', function () {
// Require the user to be logged in
global $response;
$this->requirePermission('list_users_with_vehicle_subscriptions');
// Get the user object
$user = (new authentication())->get_user();
// Check if the request was successful
if ($user) {
// Log the incident
(new logs_o())->add('vehicles', 'global', 1, $user->id, 'LIST_USERS_WITH_VEHICLE_SUBSCRIPTIONS', 'Successfully listed users with vehicle subscriptions');
// Return the list of users with vehicle subscriptions
$vehicles_o = new customer_vehicles_o();
$customer_ids = $vehicles_o->getFieldsWhere(
[
'wash_subscription' => 1,
],
['customer_id']
);
// Get all the customer_ids that has vehicle subscriptions
$customer_ids = array_map(function ($customer_id) {
return (int)$customer_id['customer_id'];
}, $customer_ids);
// Remove duplicates
$customer_ids = array_unique($customer_ids);
$response->success(
$customer_ids ? array_map(function ($customer_id) {
$tmp_user = new users_o();
$tmp_user->getUserByCustomerNumber((int)$customer_id);
return [...$tmp_user->asArray()];
}, $customer_ids) : []
);
} else {
// Log the incident
(new logs_o())->add('vehicles', 'global', 1, 0, 'LIST_USERS_WITH_VEHICLE_SUBSCRIPTIONS', 'No user found, or invalid session');
// Return an error
$response->error('Invalid session', 400);
}
},
[
'list_users_with_vehicle_subscriptions' => 'List users with vehicle subscriptions',
]
);
}
private function getData(mixed $data, $response)