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.
This commit is contained in:
Jepp9350
2025-01-31 16:17:34 +01:00
parent e09eedb010
commit bcbb4c0164
6 changed files with 227 additions and 25 deletions
+16 -9
View File
@@ -19,18 +19,25 @@ class bookings_s
$bookings = $bookings_o->getFields(['id', 'department', 'date']);
// Get the departments
$departments = $departments_o->getFields(['id', 'name']);
// Add the labels (months)
$this->labels = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
// Add the labels, and the data sets
// 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 ) {
$tmp_department_monthly = [];
foreach ( $this->labels as $label ) {
$tmp_department_monthly[$label] = 0;
$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;
}
}
$this->add_data_set($department['name'], $tmp_department_monthly, ['backgroundColor' => '#FF0000']);
// Add the department data set
$this->add_data_set($department['name'], $department_data_set);
}
return $this;
}
}