reports.php 26 KB

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