reports.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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) {
  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><?=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. <?php
  361. };
  362. ?>
  363. <section class="mb-4">
  364. <table class="table table-sm table-bordered mb-0">
  365. <colgroup>
  366. <col style="width: 30%"/>
  367. <col style="width: 14%"/>
  368. <col style="width: 14%"/>
  369. <col style="width: 14%"/>
  370. <col style="width: 14%"/>
  371. <col style="width: 14%"/>
  372. </colgroup>
  373. <thead>
  374. <tr>
  375. <th><?=htmlspecialchars(__("Type"))?></th>
  376. <th><?=htmlspecialchars(__("Total"))?></th>
  377. <th><?=htmlspecialchars(__("Passes"))?></th>
  378. <th><?=htmlspecialchars(__("Fails"))?></th>
  379. <th><?=htmlspecialchars(__("Pass Rate"))?></th>
  380. <th><?=htmlspecialchars(__("Voids"))?></th>
  381. </tr>
  382. </thead>
  383. <tbody>
  384. <tr>
  385. <th><?=htmlspecialchars(__("Venue Tests"))?></th>
  386. <td class="text-right"><?=htmlspecialchars($total_data->testCount)?></td>
  387. <td></td>
  388. <td></td>
  389. <td></td>
  390. <td class="text-right"><?=htmlspecialchars($total_data->voidCount)?></td>
  391. </tr>
  392. <?php
  393. if(isset($total_data->passCount)) {
  394. $render_pass_fail_row(__("Gaming Tests"), $total_data->passCount, $total_data->failCount, $total_data->gamingCounts["void"] ?? 0);
  395. }
  396. if(isset($total_data->barCounts)) {
  397. $render_pass_fail_row(__("Alcohol Tests"), $total_data->barCounts["pass"], $total_data->barCounts["fail"], $total_data->barCounts["void"] ?? 0);
  398. }
  399. ?>
  400. <tr>
  401. <th class="bg-light" colspan="6"><?=htmlspecialchars(__("Aggregate Counts"))?></th>
  402. </tr>
  403. <?php
  404. if(isset($total_data->combinedCounts)) {
  405. $render_pass_fail_row(__("Gaming and Alcohol"), $total_data->combinedCounts["pass"], $total_data->combinedCounts["fail"], $total_data->combinedCounts["void"] ?? 0);
  406. }
  407. if(isset($total_data->blendedCounts)) {
  408. $render_pass_fail_row(__("Gaming and Assumed Alcohol"), $total_data->blendedCounts["pass"], $total_data->blendedCounts["fail"], $total_data->blendedCounts["void"] ?? 0);
  409. }
  410. if(isset($total_data->mergedCounts)) {
  411. $render_pass_fail_row(__("Gaming or Alcohol Pass"), $total_data->mergedCounts["pass"], $total_data->mergedCounts["fail"], $total_data->mergedCounts["void"] ?? 0);
  412. }
  413. ?>
  414. </tbody>
  415. </table>
  416. </section>
  417. <div class="row mb-4">
  418. <div class="col-md-4 d-print-none" style="position: relative;">
  419. <h3>Chart List</h3>
  420. <div class="list-group limit-height-2" style="position: sticky; top: 7rem;">
  421. <?php
  422. foreach($charts as $index => $chart) {
  423. if($project_id && $chart->isPeriodic()) {
  424. continue;
  425. }
  426. ?>
  427. <a class="list-group-item list-group-item-action" href="#chart-<?=$index?>">
  428. <?=htmlspecialchars($chart->getTitle())?>
  429. </a>
  430. <?php
  431. }
  432. ?>
  433. </div>
  434. </div>
  435. <div class="col-md-8">
  436. <?php
  437. foreach($charts as $index => $chart) {
  438. if($project_id && $chart->isPeriodic()) {
  439. continue;
  440. }
  441. if($index > 0) {
  442. ?>
  443. <br />
  444. <?php
  445. }
  446. if($chart->beforeHtml) {
  447. echo $chart->beforeHtml;
  448. }
  449. ?>
  450. <a id="chart-<?=$index?>" style="display: block; position: relative; top: -7rem; visibility: hidden;"></a>
  451. <canvas id="<?=$chart->getID()?>" data-chart="<?=htmlspecialchars($chart->getJSON())?>" width="400" height="300">
  452. </canvas>
  453. <?php
  454. if($chart->print) {
  455. $chart->printDataTable();
  456. }
  457. if($chart->afterHtml) {
  458. echo $chart->afterHtml;
  459. }
  460. }
  461. ?>
  462. </div>
  463. </div>
  464. <?php
  465. foreach(["pptx", "odp"] as $format) {
  466. ?>
  467. <form id="form-<?=$format?>" method="post" action="/account/reports/export-<?=$format?>" data-rendered="0">
  468. <input type="hidden" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>" />
  469. <input type="hidden" name="customer_id" value="<?=$customer->id?>" />
  470. <input type="hidden" name="project_id" value="<?=$project_id?>" />
  471. <input type="hidden" name="date_range" value="<?=htmlspecialchars($date_range)?>" />
  472. <input type="hidden" name="date_start" id="date-start" value="<?=htmlspecialchars($date_start)?>" />
  473. <input type="hidden" name="date_end" id="date-end" value="<?=htmlspecialchars($date_end)?>" />
  474. <input type="hidden" name="date_resolution" value="<?=htmlspecialchars($date_resolution)?>" />
  475. <input type="hidden" name="retests" value="<?=htmlspecialchars($retests)?>" />
  476. <?php
  477. foreach($exclude_project_ids as $exclude_project_id) {
  478. ?>
  479. <input type="hidden" name="exclude_project_ids[]" value="<?=$exclude_project_id?>" />
  480. <?php
  481. }
  482. foreach($exclude_categories as $exclude_category) {
  483. ?>
  484. <input type="hidden" name="exclude_categories[]" value="<?=$exclude_category?>" />
  485. <?php
  486. }
  487. ?>
  488. <input type="submit" value="Submit" class="d-none" />
  489. </form>
  490. <?php
  491. }
  492. if($has_pass_fail) {
  493. $tables = [
  494. (object) [
  495. "name" => $customer->getRegionLabel(1),
  496. "data" => $region_data
  497. ],
  498. (object) [
  499. "name" => $customer->getAreaManagerLabel(1),
  500. "data" => $area_manager_data
  501. ],
  502. (object) [
  503. "name" => $customer->getOperationsManagerLabel(1),
  504. "data" => $operations_manager_data
  505. ],
  506. (object) [
  507. "name" => $customer->getBrandLabel(1),
  508. "data" => $brand_data
  509. ],
  510. ]
  511. ?>
  512. <div class="d-print-none">
  513. <h2>Extra Information</h2>
  514. <?php
  515. foreach($tables as $table) {
  516. $title = $table->name . " Data";
  517. $entity_type = $table->name;
  518. // Calculate totals
  519. $totals = [];
  520. foreach($table->data as $entity_name => $rows) {
  521. $totals[] = [
  522. "name" => $entity_name,
  523. "testCount" => array_sum(array_column($rows, "testCount")),
  524. "passCount" => array_sum(array_column($rows, "passCount")),
  525. "failCount" => array_sum(array_column($rows, "failCount")),
  526. ];
  527. }
  528. if(!$totals) {
  529. continue;
  530. }
  531. ?>
  532. <h3><?=htmlspecialchars($title)?></h3>
  533. <h4><?=htmlspecialchars($entity_type)?>: Totals</h4>
  534. <?php
  535. usort($totals, static function($a, $b) {
  536. return strnatcasecmp($a["name"], $b["name"]);
  537. });
  538. $total_test_count = 0;
  539. $total_pass_count = 0;
  540. $total_fail_count = 0;
  541. ?>
  542. <table class="table table-sm table-bordered">
  543. <colgroup>
  544. <col style="width: 20%" />
  545. <col style="width: 20%" />
  546. <col style="width: 20%" />
  547. <col style="width: 20%" />
  548. <col style="width: 20%" />
  549. </colgroup>
  550. <thead>
  551. <tr>
  552. <th><?=htmlspecialchars($title)?></th>
  553. <th>Tests</th>
  554. <th>Passes</th>
  555. <th>Fails</th>
  556. <th>Rate</th>
  557. </tr>
  558. </thead>
  559. <tbody>
  560. <?php
  561. foreach($totals as $data) {
  562. $total_test_count += $data["testCount"];
  563. $total_pass_count += $data["passCount"];
  564. $total_fail_count += $data["failCount"];
  565. $rate = ($data["testCount"] === 0) ? "0.00" : number_format(($data["passCount"] * 100) / $data["testCount"], 2);
  566. ?>
  567. <tr>
  568. <td><?=htmlspecialchars($data["name"])?></td>
  569. <td class="text-right"><?=number_format($data["testCount"])?></td>
  570. <td class="text-right"><?=number_format($data["passCount"])?></td>
  571. <td class="text-right"><?=number_format($data["failCount"])?></td>
  572. <td class="text-right"><?=$rate?>%</td>
  573. </tr>
  574. <?php
  575. }
  576. $total_rate = ($total_test_count === 0) ? "0.00" : number_format(($total_pass_count * 100) / $total_test_count, 2);
  577. ?>
  578. </tbody>
  579. <tfoot>
  580. <tr class="table-active">
  581. <th>
  582. Total
  583. </th>
  584. <th class="text-right">
  585. <?=number_format($total_test_count)?>
  586. </th>
  587. <th class="text-right">
  588. <?=number_format($total_pass_count)?>
  589. </th>
  590. <th class="text-right">
  591. <?=number_format($total_fail_count)?>
  592. </th>
  593. <th class="text-right"><?=$total_rate?>%</th>
  594. </tr>
  595. </tfoot>
  596. </table>
  597. <?php
  598. foreach($table->data as $entity_name => $rows) {
  599. ?>
  600. <h4><?=htmlspecialchars($entity_type)?>: <?=htmlspecialchars($entity_name)?></h4>
  601. <table class="table table-sm table-bordered">
  602. <colgroup>
  603. <col style="width: 20%" />
  604. <col style="width: 20%" />
  605. <col style="width: 20%" />
  606. <col style="width: 20%" />
  607. <col style="width: 20%" />
  608. </colgroup>
  609. <thead>
  610. <tr>
  611. <th>Period</th>
  612. <th>Tests</th>
  613. <th>Passes</th>
  614. <th>Fails</th>
  615. <th>Rate</th>
  616. </tr>
  617. </thead>
  618. <tbody>
  619. <?php
  620. $index = 0;
  621. foreach($rows as $key => $data) {
  622. $rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
  623. $label = $key_labels[$index];
  624. ?>
  625. <tr>
  626. <td><?=htmlspecialchars($label)?></td>
  627. <td class="text-right"><?=number_format($data->testCount)?></td>
  628. <td class="text-right"><?=number_format($data->passCount)?></td>
  629. <td class="text-right"><?=number_format($data->failCount)?></td>
  630. <td class="text-right"><?=$rate?>%</td>
  631. </tr>
  632. <?php
  633. $index++;
  634. }
  635. ?>
  636. </tbody>
  637. </table>
  638. <?php
  639. }
  640. }
  641. ?>
  642. </div>
  643. <?php
  644. }
  645. }
  646. ?>
  647. </div>