Files
api/services/nginx/app/statistics/bookings_s.php
T
Jepp9350 bcbb4c0164 Add order statistics functionality
Introduced functionality to calculate and retrieve order statistics, including monthly counts per department. Updated statistics interface, routes, and supporting logic to handle new "orders" data type alongside bookings. Refactored code to streamline label generation by year and month ranges.
2025-01-31 16:17:34 +01:00

43 lines
1.5 KiB
PHP

<?php
namespace statistics;
use traits\statistic_t;
class bookings_s
{
use statistic_t;
public function get_new_bookings(): self
{
// Get the departments
$departments_o = new \objects\departments_o();
// Get the bookings
$bookings_o = new \objects\bookings_o();
// Get the bookings
$bookings = $bookings_o->getFields(['id', 'department', 'date']);
// Get the departments
$departments = $departments_o->getFields(['id', 'name']);
// For each year, add the months covered
$this->add_monthly_labels();
// Add the counts for each department, for each month in each year
foreach ( $departments as $department ) {
$department_data_set = [];
foreach ( $this->get_yearly_months_covered() as $year => $months ) {
foreach ( $months as $month ) {
$count = 0;
foreach ( $bookings as $booking ) {
if ($booking['department'] == $department['id'] && date('F', strtotime($booking['date'])) == $month && date('Y', strtotime($booking['date'])) == $year) {
$count++;
}
}
$department_data_set[$month . ' ' . $year] = $count;
}
}
// Add the department data set
$this->add_data_set($department['name'], $department_data_set);
}
return $this;
}
}