reports.php 25 KB

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