Files
api/services/nginx/app/routes/statisticsRoute.php
T
Jepp9350 6ebea5504e Add endpoints and routes for economic statistics management
Implemented economic-related classes, endpoints, and routes to support fetching invoice totals, sent invoices, and department data. These changes enhance functionality by exposing APIs for economic statistics and integrating them into the statistics module.
2025-02-04 08:36:05 +01:00

138 lines
5.3 KiB
PHP

<?php
namespace routes;
use classes\authentication;
use classes\response;
use classes\statistics;
use objects\logs_o;
use traits\route_t;
class statisticsRoute
{
use route_t;
public function run(): void
{
/** Statistics >> Bookings >> New bookings */
$this->get('/statistics/bookings/new', function () {
// Require the user to be logged in
global
/** @var response $response */
$EMAIL_WASH_CERTIFICATE_TOKEN,
$response;
$this->requirePermission('statistics_bookings_new');
// Get the user object
$user = (new authentication())->get_user();
// Check if the request was successful
if ($user) {
// Log the incident
(new logs_o())->add('statistics', 'global', 1, $user->id, 'NEW_BOOKINGS', 'User requested new bookings');
$statics = new statistics();
// Return the list of bookings
$response->success(
$statics
->bookings()
->get_new_bookings()
->get_response()
);
} else {
// Log the incident
(new logs_o())->add('statistics', 'global', 0, 0, 'NEW_BOOKINGS', 'User requested new bookings');
// Return an error
$response->error('Invalid session', 400);
}
});
/** Statistics >> Orders >> New orders */
$this->get('/statistics/orders/new', function () {
// Require the user to be logged in
global
/** @var response $response */
$EMAIL_WASH_CERTIFICATE_TOKEN,
$response;
$this->requirePermission('statistics_orders_new');
// Get the user object
$user = (new authentication())->get_user();
// Check if the request was successful
if ($user) {
// Log the incident
(new logs_o())->add('statistics', 'global', 1, $user->id, 'NEW_ORDERS', 'User requested new orders');
$statics = new statistics();
// Return the list of orders
$response->success(
$statics
->orders()
->get_new_orders()
->get_response()
);
} else {
// Log the incident
(new logs_o())->add('statistics', 'global', 0, 0, 'NEW_ORDERS', 'User requested new orders');
// Return an error
$response->error('Invalid session', 400);
}
});
/** Statistics >> Economic >> Total income */
$this->get('/statistics/economic/totals', function () {
// Require the user to be logged in
global
/** @var response $response */
$EMAIL_WASH_CERTIFICATE_TOKEN,
$response;
$this->requirePermission('statistics_economic_income');
// Get the user object
$user = (new authentication())->get_user();
// Check if the request was successful
if ($user) {
// Log the incident
(new logs_o())->add('statistics', 'global', 1, $user->id, 'TOTAL_INCOME', 'User requested total income');
$statics = new statistics();
// Return the total income
$response->success(
$statics
->economic()
->get_totals()
->get_response()
);
} else {
// Log the incident
(new logs_o())->add('statistics', 'global', 0, 0, 'TOTAL_INCOME', 'User requested total income');
// Return an error
$response->error('Invalid session', 400);
}
});
/** Statistics >> Economic >> Department sent invoice totals */
$this->get('/statistics/economic/totals/department_sent_invoice_totals', function () {
// Require the user to be logged in
global
/** @var response $response */
$EMAIL_WASH_CERTIFICATE_TOKEN,
$response;
$this->requirePermission('statistics_economic_department_sent_invoice_totals');
// Get the user object
$user = (new authentication())->get_user();
// Check if the request was successful
if ($user) {
// Log the incident
(new logs_o())->add('statistics', 'global', 1, $user->id, 'DEPARTMENT_SENT_INVOICE_TOTALS', 'User requested department sent invoice totals');
$statics = new statistics();
// Return the department sent invoice totals
$response->success(
$statics
->economic()
->get_department_sent_invoice_totals()
->get_response()
);
} else {
// Log the incident
(new logs_o())->add('statistics', 'global', 0, 0, 'DEPARTMENT_SENT_INVOICE_TOTALS', 'User requested department sent invoice totals');
// Return an error
$response->error('Invalid session', 400);
}
});
}
}