Skip to content

Instantly share code, notes, and snippets.

@clrockwell
Created July 8, 2016 12:54
Show Gist options
  • Save clrockwell/a116080363bfc6e739f80e25b4816084 to your computer and use it in GitHub Desktop.
Save clrockwell/a116080363bfc6e739f80e25b4816084 to your computer and use it in GitHub Desktop.
<?php
/**
* Room Report
* @see cela_reports.room_utilization.inc
*/
function cela_reports__report_tables__rooms($type = ['phs_event', 'stp_event']) {
$working_hours = cela_reports__working_hours__monthly_report();
$used_rooms = cela_reports__room_utilization__get_rooms([$type], cela_reports__utilization__report_dates());
$event_rooms = cela_reports__room_utilization__get_event_data($used_rooms);
$data = cela_reports__room_utilization__get_room_utilization($event_rooms);
$all_rooms = cela_reports__room_utilization__get_all_rooms();
$all_rooms_count = count($all_rooms);
$header = [];
array_walk($all_rooms, function ($room) use (&$header) {
$header[] = $room->title;
});
array_unshift($header, 'Month');
$header[] = 'Total hours per month (all rooms)';
$header[] = 'Total working hours';
$header[] = 'Percent use per month (per room)';
foreach ($data['months'] as $month => $d) {
$rows[$month] = array_fill(1, $all_rooms_count, (int)0);
array_unshift($rows[$month], $month);
$total_hours = 0;
foreach ($d as $room_name => $room_duration) {
$index = array_search($room_name, $header);
$rows[$month][$index] += __nf($room_duration/3600);
$total_hours += __nf($room_duration/3600);
}
array_push($rows[$month], $total_hours);
array_push($rows[$month], $working_hours[$month]['total working hours']);
array_push($rows[$month], sprintf("%.2f%%", ($total_hours/$working_hours[$month]['total working hours']) * 100));
}
return cela_reports__reports_tables__table(
[
'header' => $header,
'rows' => $rows,
'caption' => 'Total Hours Per Month Per Room',
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment