reports.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. /**
  3. * @var Customer $customer
  4. * @var Chart[] $charts
  5. * @var string[] $key_labels
  6. * @var bool $has_pass_fail
  7. *
  8. * @var array $exclude_categories
  9. * @var object $template_config
  10. *
  11. * @var int $project_id
  12. *
  13. * @var string $date_range
  14. * @var string $date_resolution
  15. * @var string $date_start
  16. * @var string $date_end
  17. *
  18. * @var int[] $location_ids
  19. * @var int $retests
  20. * @var int[] $exclude_project_ids
  21. *
  22. * @var array $project_table_data
  23. * @var Location[] $locations_missing_region
  24. * @var Location[] $locations_missing_area_manager
  25. * @var Location[] $locations_missing_brand
  26. * @var Location[] $locations_missing_operations_manager
  27. *
  28. * @var array $total_data
  29. * @var array $region_data
  30. * @var array $area_manager_data
  31. * @var array $brand_data
  32. * @var array $operations_manager_data
  33. */
  34. $user = Core::$user;
  35. $date_resolutions = [
  36. "quarterly" => "Quarterly",
  37. "monthly" => "Monthly",
  38. ];
  39. $date_ranges = [
  40. "ytd" => "Year to Date",
  41. //"unbound" => "Unbound",
  42. "custom" => "Custom",
  43. ];
  44. $retests_options = [
  45. 0 => "Exclude",
  46. 1 => "Retests Only"
  47. ];
  48. $years = range(2018, date("Y"));
  49. $date_range_custom_style = ($date_range === "custom") ? "" : "display: none";
  50. $date_range_value = "";
  51. if($date_start && $date_end) {
  52. [$min_year, $min_month, $min_day] = explode("-", $date_start);
  53. [$max_year, $max_month, $max_day] = explode("-", $date_end);
  54. $date_range_value = "$min_day/$min_month/$min_year - $max_day/$max_month/$max_year";
  55. }
  56. $collator = new Collator("en_GB");
  57. if($charts) {
  58. $brands = array_keys($brand_data);
  59. $regions = array_keys($region_data);
  60. $area_managers = array_keys($area_manager_data);
  61. $operations_managers = array_keys($operations_manager_data);
  62. }
  63. else {
  64. $brands = $customer->getBrands();
  65. $regions = $customer->getRegions();
  66. $area_managers = $customer->getAreaManagerNames();
  67. $operations_managers = $customer->getOperationsManagerNames();
  68. }
  69. $gaming_managers = $customer->getGamingManagerNames();
  70. $senior_gaming_managers = $customer->getSeniorGamingManagerNames();
  71. $collator->sort($brands);
  72. $collator->sort($regions);
  73. $collator->sort($area_managers);
  74. $collator->sort($operations_managers);
  75. $project_options = [];
  76. foreach($project_table_data as $project_data) {
  77. $project_options[$project_data["id"]] = $project_data["name"];
  78. }
  79. ?>
  80. <script>
  81. let selectedProjectIds = <?=json_encode($exclude_project_ids)?>;
  82. let projectData = <?=json_encode($project_table_data)?>;
  83. </script>
  84. <div class="container mt-3 py-4">
  85. <div class="row d-print-none">
  86. <div class="col">
  87. <h2><?=htmlspecialchars($customer->name)?> Reports</h2>
  88. </div>
  89. <div class="col-auto">
  90. <?php
  91. if($charts) {
  92. ?>
  93. <div class="dropdown">
  94. <button type="button" class="btn btn-secondary dropdown-toggle" id="actions-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  95. Actions
  96. </button>
  97. <div class="dropdown-menu" aria-labelledby="actions-button">
  98. <a class="dropdown-item" href="#" id="export-pptx-action">Export PPTX</a>
  99. </div>
  100. </div>
  101. <?php
  102. }
  103. ?>
  104. </div>
  105. </div>
  106. <form class="mb-4 d-print-none" method="post">
  107. <input type="hidden" name="customer_id" value="<?=htmlspecialchars($customer->id)?>" />
  108. <div class="row">
  109. <div class="col-md">
  110. <div class="form-group">
  111. <label for="project"><?=htmlspecialchars(__("Project"))?></label>
  112. <select class="form-control" name="project_id" id="project">
  113. <option value=""><?=htmlspecialchars(__("Select Project"))?></option>
  114. <?php
  115. HtmlHelper::renderOptions($project_options, $project_id);
  116. ?>
  117. </select>
  118. </div>
  119. <div class="form-group">
  120. <label class="form-label" for="date-range">
  121. Date Range
  122. </label><br />
  123. <?php
  124. foreach($date_ranges as $value => $display) {
  125. $checked = ($value === $date_range) ? "checked" : "";
  126. ?>
  127. <div class="form-check form-check-inline">
  128. <input class="form-check-input" type="radio" name="date_range" id="date-range-<?=htmlspecialchars($value)?>" value="<?=htmlspecialchars($value)?>" <?=$checked?> data-date-range-radio-input />
  129. <label class="form-check-label" for="date-range-<?=htmlspecialchars($value)?>"><?=htmlspecialchars($display)?></label>
  130. </div>
  131. <?php
  132. }
  133. ?>
  134. <div class="row mt-1" id="date-range-custom-fields" style="<?=$date_range_custom_style?>">
  135. <div class="col-lg">
  136. <input class="form-control" type="text" id="date-range" value="<?=htmlspecialchars($date_range_value)?>" />
  137. <input type="hidden" name="date_start" id="date-start" value="<?=htmlspecialchars($date_start)?>" />
  138. <input type="hidden" name="date_end" id="date-end" value="<?=htmlspecialchars($date_end)?>" />
  139. </div>
  140. </div>
  141. </div>
  142. <div class="form-group">
  143. <label for="date-resolution">
  144. Date Resolution
  145. </label>
  146. <select class="form-control" name="date_resolution" id="date-resolution">
  147. <?php
  148. foreach($date_resolutions as $value => $display) {
  149. $selected = ($value === $date_resolution) ? "selected" : "";
  150. ?>
  151. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  152. <?php
  153. }
  154. ?>
  155. </select>
  156. </div>
  157. <div class="form-group">
  158. <label for="location-ids">
  159. Location IDs
  160. </label>
  161. <input class="form-control" name="location_ids" type="text" id="location-ids" value="<?=htmlspecialchars(implode(" ", $location_ids))?>" placeholder="Enter location IDs" />
  162. <small class="form-text text-muted">Separate each location ID with a space.<br />Leave blank to generate a report for all locations.</small>
  163. </div>
  164. <div class="form-group">
  165. <label for="retests">Retests</label>
  166. <select name="retests" id="retests" class="form-control">
  167. <option value="">Include</option>
  168. <?php
  169. foreach($retests_options as $value => $display) {
  170. $selected = $value === $retests ? "selected" : "";
  171. ?>
  172. <option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  173. <?php
  174. }
  175. ?>
  176. </select>
  177. </div>
  178. <?php
  179. $categories = $template_config->reports->categories ?? [];
  180. if($total_data && $categories) {
  181. ?>
  182. <div class="form-group">
  183. <label><?=htmlspecialchars(__("Exclude Categories"))?></label><br />
  184. <?php
  185. foreach($categories as $category) {
  186. $id = sprintf("exclude-category-%s", strtolower($category));
  187. $checked = in_array($category, $exclude_categories) ? "checked" : "";
  188. ?>
  189. <div class="custom-control custom-switch">
  190. <input class="custom-control-input" id="<?=$id?>" name="exclude_categories[]" type="checkbox" value="<?=htmlspecialchars($category)?>" <?=$checked?> />
  191. <label class="custom-control-label" for="<?=$id?>"><?=htmlspecialchars($category)?></label>
  192. </div>
  193. <?php
  194. }
  195. ?>
  196. <input type="hidden" name="exclude_categories[]" value="none" />
  197. </div>
  198. <?php
  199. }
  200. /**
  201. * @param string $name
  202. * @param string $id
  203. * @param string $label
  204. * @param array $values
  205. * @return void
  206. * @throws Exception
  207. */
  208. $render_location_entity_filter = static function(string $name, string $id, string $label, array $values): void {
  209. if(!$values) {
  210. return;
  211. }
  212. $request_name = preg_replace("/\[]/", "", $name);
  213. $selected_values = http::value($request_name, "trim") ?? [];
  214. ?>
  215. <div class="form-group">
  216. <label for="<?=$id?>"><?=htmlspecialchars($label)?></label>
  217. <select class="form-control" name="<?=$name?>" id="<?=$id?>" data-toggle="select2" data-placeholder="<?=htmlspecialchars(__("All"))?>" multiple>
  218. <?php
  219. foreach($values as $value) {
  220. $selected = in_array($value, $selected_values) ? "selected" : ""
  221. ?>
  222. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($value)?></option>
  223. <?php
  224. }
  225. ?>
  226. </select>
  227. </div>
  228. <?php
  229. };
  230. ?>
  231. </div>
  232. <div class="col-md">
  233. <?php
  234. $render_location_entity_filter("brands[]", "brands", $customer->getBrandLabel(2), $brands);
  235. $render_location_entity_filter("operations_managers[]", "operation_managers", $customer->getOperationsManagerLabel(2), $operations_managers);
  236. $render_location_entity_filter("regions[]", "regions", $customer->getRegionLabel(2), $regions);
  237. $render_location_entity_filter("area_managers[]", "area_managers", $customer->getAreaManagerLabel(2), $area_managers);
  238. $render_location_entity_filter("senior_gaming_managers[]", "senior_gaming_managers", $customer->getSeniorGamingManagerLabel(2), $senior_gaming_managers);
  239. $render_location_entity_filter("gaming_managers[]", "gaming_managers", $customer->getGamingManagerLabel(2), $gaming_managers);
  240. ?>
  241. <div class="form-group">
  242. <label class="d-block">
  243. Exclude Projects
  244. </label>
  245. <button id="show-projects-list-button" type="button" class="btn btn-secondary">
  246. <?=htmlspecialchars(__("Show project list"))?>
  247. </button>
  248. <div id="projects-table-wrapper" style="display: none;">
  249. <table class="table table-sm table-sm-text table-hover table-pointer" id="projects-table">
  250. <thead>
  251. <tr>
  252. <th>
  253. <label for="exclude-projects-header-checkbox" class="sr-only">
  254. <?=htmlspecialchars(__("Exclude All"))?>
  255. </label>
  256. <input id="exclude-projects-header-checkbox" type="checkbox" />
  257. </th>
  258. <th>ID</th>
  259. <th>Name</th>
  260. <th><span title="Time of Day" data-toggle="tooltip">TOD</span></th>
  261. <th>Tests</th>
  262. <th>Report Month</th>
  263. </tr>
  264. </thead>
  265. </table>
  266. </div>
  267. </div>
  268. </div>
  269. </div>
  270. <button class="btn btn-primary" type="submit" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">
  271. Submit
  272. </button>
  273. </form>
  274. <?php
  275. if($user->canSeeMissingData()) {
  276. /**
  277. * @param string $field
  278. * @param Location[] $locations
  279. * @return void
  280. */
  281. $render_locations_missing_data = static function(string $field, array $locations): void {
  282. ?>
  283. <div class="alert alert-warning limit-height-1 d-print-none">
  284. There are some locations that are missing "<?=htmlspecialchars($field)?>" information:
  285. <ul class="mb-0">
  286. <?php
  287. foreach($locations as $location) {
  288. $url = (Core::$user->canAdmin()) ? "/account/locations/$location->id/edit" : "#";
  289. ?>
  290. <li>
  291. <a href="<?=htmlspecialchars($url)?>"><?=htmlspecialchars($location->name)?></a>
  292. <?php
  293. if($location->internal_id) {
  294. ?>
  295. <small class="text-info">(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
  296. <?php
  297. }
  298. ?>
  299. </li>
  300. <?php
  301. }
  302. ?>
  303. </ul>
  304. </div>
  305. <?php
  306. };
  307. if($locations_missing_region) {
  308. $render_locations_missing_data("region", $locations_missing_region);
  309. }
  310. if($locations_missing_area_manager) {
  311. $render_locations_missing_data("area manager", $locations_missing_area_manager);
  312. }
  313. if($locations_missing_operations_manager) {
  314. $render_locations_missing_data("operations manager", $locations_missing_operations_manager);
  315. }
  316. if($locations_missing_brand) {
  317. $render_locations_missing_data("brand", $locations_missing_brand);
  318. }
  319. }
  320. if($charts) {
  321. ?>
  322. <h2>
  323. Report
  324. </h2>
  325. <p>
  326. <?php
  327. if($retests === 0) {
  328. ?>
  329. <span class="badge badge-warning">Retests Excluded</span>
  330. <?php
  331. }
  332. else if($retests === 1) {
  333. ?>
  334. <span class="badge badge-warning">Retests Only</span>
  335. <?php
  336. }
  337. else {
  338. ?>
  339. <span class="badge badge-success">Retests Included</span>
  340. <?php
  341. }
  342. ?>
  343. </p>
  344. <?php
  345. $render_pass_fail_row = static function(string $title, $pass, $fail, $void, $explainer = "") {
  346. $total = $pass + $fail;
  347. $pass_percentage = 0;
  348. if($total > 0) {
  349. $pass_percentage = number_format(($pass * 100) / $total, 2);
  350. }
  351. ?>
  352. <tr>
  353. <th rowspan="2"><?=htmlspecialchars($title)?></th>
  354. <td class="text-right"><?=$total?></td>
  355. <td class="text-right"><?=$pass?></td>
  356. <td class="text-right"><?=$fail?></td>
  357. <td class="text-right"><?=$pass_percentage?>%</td>
  358. <td class="text-right"><?=$void?></td>
  359. </tr>
  360. <tr>
  361. <td colspan="5">
  362. <?=htmlspecialchars($explainer)?>
  363. </td>
  364. </tr>
  365. <?php
  366. };
  367. ?>
  368. <section class="mb-4">
  369. <table class="table table-sm table-bordered mb-0">
  370. <colgroup>
  371. <col style="width: 30%"/>
  372. <col style="width: 14%"/>
  373. <col style="width: 14%"/>
  374. <col style="width: 14%"/>
  375. <col style="width: 14%"/>
  376. <col style="width: 14%"/>
  377. </colgroup>
  378. <thead>
  379. <tr>
  380. <th><?=htmlspecialchars(__("Type"))?></th>
  381. <th><?=htmlspecialchars(__("Total"))?></th>
  382. <th><?=htmlspecialchars(__("Passes"))?></th>
  383. <th><?=htmlspecialchars(__("Fails"))?></th>
  384. <th><?=htmlspecialchars(__("Pass Rate"))?></th>
  385. <th><?=htmlspecialchars(__("Voids"))?></th>
  386. </tr>
  387. </thead>
  388. <tbody>
  389. <tr>
  390. <th rowspan="2"><?=htmlspecialchars(__("Venue Tests"))?></th>
  391. <td class="text-right"><?=htmlspecialchars($total_data->testCount)?></td>
  392. <td></td>
  393. <td></td>
  394. <td></td>
  395. <td class="text-right"><?=htmlspecialchars($total_data->voidCount)?></td>
  396. </tr>
  397. <tr>
  398. <td colspan="5">
  399. <?=htmlspecialchars(__("There were %d tests of which %d were voids resulting in %d gaming tests being carried out.", $total_data->testCount + $total_data->voidCount, $total_data->voidCount, $total_data->testCount))?>
  400. </td>
  401. </tr>
  402. <?php
  403. if(isset($total_data->passCount)) {
  404. $pass_count = $total_data->passCount;
  405. $fail_count = $total_data->failCount;
  406. $void_count = $total_data->gamingCounts["void"] ?? 0;
  407. $explainer = __("There were %d gaming tests of which there were %d passes and %d fails and %d voids.", ($pass_count + $fail_count + $void_count), $pass_count, $fail_count, $void_count);
  408. $render_pass_fail_row(__("Gaming Tests"), $pass_count, $fail_count, $void_count, $explainer);
  409. }
  410. if(isset($total_data->barCounts)) {
  411. $gaming_stage_5 = $total_data->stage5Count ?? 0;
  412. $gaming_void_count = $total_data->gamingCounts["void"] ?? 0;
  413. $pass_count = $total_data->barCounts["pass"];
  414. $fail_count = $total_data->barCounts["fail"];
  415. $void_count = $total_data->barCounts["void"] ?? 0;
  416. $explainer = __("There were %d alcohol tests which come from %d gaming tests that ended up in Stage 5 plus %d gaming tests that were void. Of these alcohol tests there were %d passes and %d fails and %d voids.", ($pass_count + $fail_count + $void_count), $gaming_stage_5, $gaming_void_count, $pass_count, $fail_count, $void_count);
  417. $render_pass_fail_row(__("Alcohol Tests"), $pass_count, $fail_count, $void_count, $explainer);
  418. }
  419. ?>
  420. <tr>
  421. <th class="bg-light" colspan="6"><?=htmlspecialchars(__("Aggregate Counts"))?></th>
  422. </tr>
  423. <?php
  424. if(isset($total_data->combinedCounts)) {
  425. $render_pass_fail_row(__("Gaming and Alcohol"), $total_data->combinedCounts["pass"], $total_data->combinedCounts["fail"], $total_data->combinedCounts["void"] ?? 0, __("The gaming and alcohol tests added together."));
  426. }
  427. if(isset($total_data->blendedCounts)) {
  428. $render_pass_fail_row(__("Gaming and Assumed Alcohol"), $total_data->blendedCounts["pass"], $total_data->blendedCounts["fail"], $total_data->blendedCounts["void"] ?? 0, __("The gaming and alcohol tests added together but also assuming that any gaming test pass is also an alcohol test pass. %d passes were added.", $total_data->passCount));
  429. }
  430. if(isset($total_data->mergedCounts)) {
  431. $pass_count = $total_data->mergedCounts["pass"];
  432. $fail_count = $total_data->mergedCounts["fail"];
  433. $void_count = $total_data->mergedCounts["void"] ?? 0;
  434. $gaming_stage_3 = $total_data->stage3Count ?? 0;
  435. $gaming_stage_4 = $total_data->stage4Count ?? 0;
  436. $render_pass_fail_row(__("Gaming or Alcohol Pass"), $pass_count, $fail_count, $void_count, __("The gaming and alcohol passes added together. %d tests either passed the gaming test or alcohol test. There were %d outright fails: %d were caught at Stage 3, %d were caught at Stage 4 and %d failed the alcohol test.", $pass_count, $total_data->mergedCounts["fail"], $gaming_stage_3, $gaming_stage_4, $total_data->barCounts["fail"]));
  437. }
  438. ?>
  439. </tbody>
  440. </table>
  441. </section>
  442. <div class="row mb-4">
  443. <div class="col-md-4 d-print-none" style="position: relative;">
  444. <h3>Chart List</h3>
  445. <div class="list-group limit-height-2" style="position: sticky; top: 7rem;">
  446. <?php
  447. foreach($charts as $index => $chart) {
  448. if($project_id && $chart->isPeriodic()) {
  449. continue;
  450. }
  451. ?>
  452. <a class="list-group-item list-group-item-action" href="#chart-<?=$index?>">
  453. <?=htmlspecialchars($chart->getTitle())?>
  454. </a>
  455. <?php
  456. }
  457. ?>
  458. </div>
  459. </div>
  460. <div class="col-md-8">
  461. <?php
  462. foreach($charts as $index => $chart) {
  463. if($project_id && $chart->isPeriodic()) {
  464. continue;
  465. }
  466. if($index > 0) {
  467. ?>
  468. <br />
  469. <?php
  470. }
  471. if($chart->beforeHtml) {
  472. echo $chart->beforeHtml;
  473. }
  474. ?>
  475. <a id="chart-<?=$index?>" style="display: block; position: relative; top: -7rem; visibility: hidden;"></a>
  476. <canvas id="<?=$chart->getID()?>" data-chart="<?=htmlspecialchars($chart->getJSON())?>" width="400" height="300">
  477. </canvas>
  478. <?php
  479. if($chart->print) {
  480. $chart->printDataTable();
  481. }
  482. if($chart->afterHtml) {
  483. echo $chart->afterHtml;
  484. }
  485. }
  486. ?>
  487. </div>
  488. </div>
  489. <?php
  490. foreach(["pptx", "odp"] as $format) {
  491. ?>
  492. <form id="form-<?=$format?>" method="post" action="/account/reports/export-<?=$format?>" data-rendered="0">
  493. <input type="hidden" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>" />
  494. <input type="hidden" name="customer_id" value="<?=$customer->id?>" />
  495. <input type="hidden" name="project_id" value="<?=$project_id?>" />
  496. <input type="hidden" name="date_range" value="<?=htmlspecialchars($date_range)?>" />
  497. <input type="hidden" name="date_start" id="date-start" value="<?=htmlspecialchars($date_start)?>" />
  498. <input type="hidden" name="date_end" id="date-end" value="<?=htmlspecialchars($date_end)?>" />
  499. <input type="hidden" name="date_resolution" value="<?=htmlspecialchars($date_resolution)?>" />
  500. <input type="hidden" name="retests" value="<?=htmlspecialchars($retests)?>" />
  501. <?php
  502. foreach($exclude_project_ids as $exclude_project_id) {
  503. ?>
  504. <input type="hidden" name="exclude_project_ids[]" value="<?=$exclude_project_id?>" />
  505. <?php
  506. }
  507. foreach($exclude_categories as $exclude_category) {
  508. ?>
  509. <input type="hidden" name="exclude_categories[]" value="<?=$exclude_category?>" />
  510. <?php
  511. }
  512. ?>
  513. <input type="submit" value="Submit" class="d-none" />
  514. </form>
  515. <?php
  516. }
  517. if($has_pass_fail) {
  518. $tables = [
  519. (object) [
  520. "name" => $customer->getRegionLabel(1),
  521. "data" => $region_data
  522. ],
  523. (object) [
  524. "name" => $customer->getAreaManagerLabel(1),
  525. "data" => $area_manager_data
  526. ],
  527. (object) [
  528. "name" => $customer->getOperationsManagerLabel(1),
  529. "data" => $operations_manager_data
  530. ],
  531. (object) [
  532. "name" => $customer->getBrandLabel(1),
  533. "data" => $brand_data
  534. ],
  535. ]
  536. ?>
  537. <div class="d-print-none">
  538. <h2>Extra Information</h2>
  539. <?php
  540. foreach($tables as $table) {
  541. $title = $table->name . " Data";
  542. $entity_type = $table->name;
  543. // Calculate totals
  544. $totals = [];
  545. foreach($table->data as $entity_name => $rows) {
  546. $totals[] = [
  547. "name" => $entity_name,
  548. "testCount" => array_sum(array_column($rows, "testCount")),
  549. "passCount" => array_sum(array_column($rows, "passCount")),
  550. "failCount" => array_sum(array_column($rows, "failCount")),
  551. ];
  552. }
  553. if(!$totals) {
  554. continue;
  555. }
  556. ?>
  557. <h3><?=htmlspecialchars($title)?></h3>
  558. <h4><?=htmlspecialchars($entity_type)?>: Totals</h4>
  559. <?php
  560. usort($totals, static function($a, $b) {
  561. return strnatcasecmp($a["name"], $b["name"]);
  562. });
  563. $total_test_count = 0;
  564. $total_pass_count = 0;
  565. $total_fail_count = 0;
  566. ?>
  567. <table class="table table-sm table-bordered">
  568. <colgroup>
  569. <col style="width: 20%" />
  570. <col style="width: 20%" />
  571. <col style="width: 20%" />
  572. <col style="width: 20%" />
  573. <col style="width: 20%" />
  574. </colgroup>
  575. <thead>
  576. <tr>
  577. <th><?=htmlspecialchars($title)?></th>
  578. <th>Tests</th>
  579. <th>Passes</th>
  580. <th>Fails</th>
  581. <th>Rate</th>
  582. </tr>
  583. </thead>
  584. <tbody>
  585. <?php
  586. foreach($totals as $data) {
  587. $total_test_count += $data["testCount"];
  588. $total_pass_count += $data["passCount"];
  589. $total_fail_count += $data["failCount"];
  590. $rate = ($data["testCount"] === 0) ? "0.00" : number_format(($data["passCount"] * 100) / $data["testCount"], 2);
  591. ?>
  592. <tr>
  593. <td><?=htmlspecialchars($data["name"])?></td>
  594. <td class="text-right"><?=number_format($data["testCount"])?></td>
  595. <td class="text-right"><?=number_format($data["passCount"])?></td>
  596. <td class="text-right"><?=number_format($data["failCount"])?></td>
  597. <td class="text-right"><?=$rate?>%</td>
  598. </tr>
  599. <?php
  600. }
  601. $total_rate = ($total_test_count === 0) ? "0.00" : number_format(($total_pass_count * 100) / $total_test_count, 2);
  602. ?>
  603. </tbody>
  604. <tfoot>
  605. <tr class="table-active">
  606. <th>
  607. Total
  608. </th>
  609. <th class="text-right">
  610. <?=number_format($total_test_count)?>
  611. </th>
  612. <th class="text-right">
  613. <?=number_format($total_pass_count)?>
  614. </th>
  615. <th class="text-right">
  616. <?=number_format($total_fail_count)?>
  617. </th>
  618. <th class="text-right"><?=$total_rate?>%</th>
  619. </tr>
  620. </tfoot>
  621. </table>
  622. <?php
  623. foreach($table->data as $entity_name => $rows) {
  624. ?>
  625. <h4><?=htmlspecialchars($entity_type)?>: <?=htmlspecialchars($entity_name)?></h4>
  626. <table class="table table-sm table-bordered">
  627. <colgroup>
  628. <col style="width: 20%" />
  629. <col style="width: 20%" />
  630. <col style="width: 20%" />
  631. <col style="width: 20%" />
  632. <col style="width: 20%" />
  633. </colgroup>
  634. <thead>
  635. <tr>
  636. <th>Period</th>
  637. <th>Tests</th>
  638. <th>Passes</th>
  639. <th>Fails</th>
  640. <th>Rate</th>
  641. </tr>
  642. </thead>
  643. <tbody>
  644. <?php
  645. $index = 0;
  646. foreach($rows as $key => $data) {
  647. $rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
  648. $label = $key_labels[$index];
  649. ?>
  650. <tr>
  651. <td><?=htmlspecialchars($label)?></td>
  652. <td class="text-right"><?=number_format($data->testCount)?></td>
  653. <td class="text-right"><?=number_format($data->passCount)?></td>
  654. <td class="text-right"><?=number_format($data->failCount)?></td>
  655. <td class="text-right"><?=$rate?>%</td>
  656. </tr>
  657. <?php
  658. $index++;
  659. }
  660. ?>
  661. </tbody>
  662. </table>
  663. <?php
  664. }
  665. }
  666. ?>
  667. </div>
  668. <?php
  669. }
  670. }
  671. ?>
  672. </div>