reports.php 27 KB

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