reports.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <?php
  2. /**
  3. * @var Customer $customer
  4. * @var Chart[] $charts
  5. * @var string[] $key_labels
  6. * @var bool $has_pass_fail
  7. *
  8. * @var string $date_range
  9. * @var string $date_resolution
  10. * @var string $date_start
  11. * @var string $date_end
  12. *
  13. * @var int[] $location_ids
  14. * @var int $retests
  15. * @var int[] $exclude_project_ids
  16. *
  17. * @var array $project_table_data
  18. * @var Location[] $locations_missing_region
  19. * @var Location[] $locations_missing_area_manager
  20. *
  21. * @var array $total_data
  22. * @var array $region_data
  23. * @var array $area_manager_data
  24. */
  25. $user = Core::$user;
  26. $date_resolutions = [
  27. "quarterly" => "Quarterly",
  28. "monthly" => "Monthly",
  29. ];
  30. $date_ranges = [
  31. "ytd" => "Year to Date",
  32. //"unbound" => "Unbound",
  33. "custom" => "Custom",
  34. ];
  35. $retests_options = [
  36. 0 => "Exclude",
  37. 1 => "Retests Only"
  38. ];
  39. $years = range(2018, date("Y"));
  40. $date_range_custom_style = ($date_range === "custom") ? "" : "display: none";
  41. $date_range_value = "";
  42. if($date_start && $date_end) {
  43. list($min_year, $min_month, $min_day) = explode("-", $date_start);
  44. list($max_year, $max_month, $max_day) = explode("-", $date_end);
  45. $date_range_value = "$min_day/$min_month/$min_year - $max_day/$max_month/$max_year";
  46. }
  47. ?>
  48. <script>
  49. let selectedProjectIds = <?=json_encode($exclude_project_ids)?>;
  50. let projectData = <?=json_encode($project_table_data)?>;
  51. </script>
  52. <div class="container mt-3 py-4">
  53. <div class="row d-print-none">
  54. <div class="col">
  55. <h2><?=htmlspecialchars($customer->name)?> Reports</h2>
  56. </div>
  57. <div class="col-auto">
  58. <?php
  59. if($charts) {
  60. ?>
  61. <div class="dropdown">
  62. <button type="button" class="btn btn-secondary dropdown-toggle" id="actions-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  63. Actions
  64. </button>
  65. <div class="dropdown-menu" aria-labelledby="actions-button">
  66. <a class="dropdown-item" href="#" id="export-pptx-action">Export PPTX</a>
  67. </div>
  68. </div>
  69. <?php
  70. }
  71. ?>
  72. </div>
  73. </div>
  74. <form class="mb-4 d-print-none" method="post">
  75. <input type="hidden" name="customer_id" value="<?=htmlspecialchars($customer->id)?>" />
  76. <div class="row">
  77. <div class="col-md">
  78. <div class="form-group">
  79. <label class="form-label" for="date-range">
  80. Date Range
  81. </label><br / >
  82. <?php
  83. foreach($date_ranges as $value => $display) {
  84. $checked = ($value === $date_range) ? "checked" : "";
  85. ?>
  86. <div class="form-check form-check-inline">
  87. <input class="form-check-input" type="radio" name="date_range" id="date-range-<?=htmlspecialchars($value)?>" value="<?=htmlspecialchars($value)?>" <?=$checked?> data-date-range-radio-input />
  88. <label class="form-check-label" for="date-range-<?=htmlspecialchars($value)?>"><?=htmlspecialchars($display)?></label>
  89. </div>
  90. <?php
  91. }
  92. ?>
  93. <div class="row mt-1" id="date-range-custom-fields" style="<?=$date_range_custom_style?>">
  94. <div class="col-lg">
  95. <input class="form-control" type="text" id="date-range" value="<?=htmlspecialchars($date_range_value)?>" />
  96. <input type="hidden" name="date_start" id="date-start" value="<?=htmlspecialchars($date_start)?>" />
  97. <input type="hidden" name="date_end" id="date-end" value="<?=htmlspecialchars($date_end)?>" />
  98. </div>
  99. </div>
  100. </div>
  101. <div class="form-group">
  102. <label for="date-resolution">
  103. Date Resolution
  104. </label>
  105. <select class="form-control" name="date_resolution" id="date-resolution">
  106. <?php
  107. foreach($date_resolutions as $value => $display) {
  108. $selected = ($value === $date_resolution) ? "selected" : "";
  109. ?>
  110. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  111. <?php
  112. }
  113. ?>
  114. </select>
  115. </div>
  116. <div class="form-group">
  117. <label for="location-ids">
  118. Location IDs
  119. </label>
  120. <input class="form-control" name="location_ids" type="text" id="location-ids" value="<?=htmlspecialchars(implode(" ", $location_ids))?>" placeholder="Enter location IDs" />
  121. <small class="form-text text-muted">Separate each location ID with a space.<br />Leave blank to generate a report for all locations.</small>
  122. </div>
  123. <div class="form-group">
  124. <label for="retests">Retests</label>
  125. <select name="retests" id="retests" class="form-control">
  126. <option value="">Include</option>
  127. <?php
  128. foreach($retests_options as $value => $display) {
  129. $selected = $value === $retests ? "selected" : "";
  130. ?>
  131. <option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  132. <?php
  133. }
  134. ?>
  135. </select>
  136. </div>
  137. <button class="btn btn-primary" type="submit" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">
  138. Submit
  139. </button>
  140. </div>
  141. <div class="col-md">
  142. <div class="form-group">
  143. <label class="d-block">
  144. Exclude Projects
  145. </label>
  146. <button id="show-projects-list-button" type="button" class="btn btn-secondary">
  147. <?=htmlspecialchars(__("Show project list"))?>
  148. </button>
  149. <div id="projects-table-wrapper" style="display: none;">
  150. <table class="table table-sm table-sm-text table-hover table-pointer" id="projects-table">
  151. <thead>
  152. <tr>
  153. <th>
  154. <label for="exclude-projects-header-checkbox" class="sr-only">
  155. <?=htmlspecialchars(__("Exclude All"))?>
  156. </label>
  157. <input id="exclude-projects-header-checkbox" type="checkbox" />
  158. </th>
  159. <th>ID</th>
  160. <th>Name</th>
  161. <th><span title="Time of Day" data-toggle="tooltip">TOD</span></th>
  162. <th>Tests</th>
  163. <th>Report Month</th>
  164. </tr>
  165. </thead>
  166. </table>
  167. </div>
  168. </div>
  169. </div>
  170. </div>
  171. </form>
  172. <?php
  173. if($user->canSeeMissingData()) {
  174. if($locations_missing_region) {
  175. ?>
  176. <div class="alert alert-warning limit-height-1 d-print-none">
  177. There are some locations that are missing "region" information:
  178. <ul class="mb-0">
  179. <?php
  180. foreach($locations_missing_region as $location) {
  181. $url = (Core::$user->canAdmin()) ? "/account/locations/$location->id/edit" : "#";
  182. ?>
  183. <li>
  184. <a href="<?=htmlspecialchars($url)?>"><?=htmlspecialchars($location->name)?></a>
  185. <?php
  186. if($location->internal_id) {
  187. ?>
  188. <small class="text-info">(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
  189. <?php
  190. }
  191. ?>
  192. </li>
  193. <?php
  194. }
  195. ?>
  196. </ul>
  197. </div>
  198. <?php
  199. }
  200. if($locations_missing_area_manager) {
  201. ?>
  202. <div class="alert alert-warning limit-height-1 d-print-none">
  203. There are some locations that are missing "area manager" information:
  204. <ul class="mb-0">
  205. <?php
  206. foreach($locations_missing_area_manager as $location) {
  207. $url = (Core::$user->canAdmin()) ? "/account/locations/$location->id/edit" : "#";
  208. ?>
  209. <li>
  210. <a href="<?=htmlspecialchars($url)?>"><?=htmlspecialchars($location->name)?></a>
  211. <?php
  212. if($location->internal_id) {
  213. ?>
  214. <small class="text-info">(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
  215. <?php
  216. }
  217. ?>
  218. </li>
  219. <?php
  220. }
  221. ?>
  222. </ul>
  223. </div>
  224. <?php
  225. }
  226. }
  227. if($charts) {
  228. ?>
  229. <h2>
  230. Report
  231. </h2>
  232. <p>
  233. <?php
  234. if($retests === 0) {
  235. ?>
  236. <span class="badge badge-warning">Retests Excluded</span>
  237. <?php
  238. }
  239. else if($retests === 1) {
  240. ?>
  241. <span class="badge badge-warning">Retests Only</span>
  242. <?php
  243. }
  244. else {
  245. ?>
  246. <span class="badge badge-success">Retests Included</span>
  247. <?php
  248. }
  249. ?>
  250. </p>
  251. <div class="row">
  252. <div class="col-md-6">
  253. <div class="card card-body mb-3">
  254. Test Count
  255. <div class="stat">
  256. <?=$total_data->testCount?>
  257. </div>
  258. </div>
  259. </div>
  260. <div class="col-md-6">
  261. <?php
  262. if(isset($total_data->passCount)) {
  263. $pass_percentage = 0;
  264. if($total_data->testCount > 0) {
  265. $pass_percentage = number_format(($total_data->passCount * 100) / $total_data->testCount, 2);
  266. }
  267. ?>
  268. <div class="card card-body mb-3">
  269. Pass/Fail Count
  270. <div class="stat">
  271. <?=$total_data->passCount?> /
  272. <?=$total_data->failCount?> (<?=$pass_percentage?>%)
  273. </div>
  274. </div>
  275. <?php
  276. }
  277. ?>
  278. </div>
  279. </div>
  280. <div class="row mb-4">
  281. <div class="col-md-4 d-print-none" style="position: relative;">
  282. <h3>Chart List</h3>
  283. <div class="list-group limit-height-2" style="position: sticky; top: 7rem;">
  284. <?php
  285. foreach($charts as $index => $chart) {
  286. ?>
  287. <a class="list-group-item list-group-item-action" href="#chart-<?=$index?>">
  288. <?=htmlspecialchars($chart->getTitle())?>
  289. </a>
  290. <?php
  291. }
  292. ?>
  293. </div>
  294. </div>
  295. <div class="col-md-8">
  296. <?php
  297. foreach($charts as $index => $chart) {
  298. if($index > 0) {
  299. ?>
  300. <br />
  301. <?php
  302. }
  303. if($chart->beforeHtml) {
  304. echo $chart->beforeHtml;
  305. }
  306. ?>
  307. <a id="chart-<?=$index?>" style="display: block; position: relative; top: -7rem; visibility: hidden;"></a>
  308. <canvas id="<?=$chart->getID()?>" data-chart="<?=htmlspecialchars($chart->getJSON())?>" width="400" height="300">
  309. </canvas>
  310. <?php
  311. if($chart->print) {
  312. $chart->printDataTable();
  313. }
  314. if($chart->afterHtml) {
  315. echo $chart->afterHtml;
  316. }
  317. }
  318. ?>
  319. </div>
  320. </div>
  321. <?php
  322. foreach(["pptx", "odp"] as $format) {
  323. ?>
  324. <form id="form-<?=$format?>" method="post" action="/account/reports/export-<?=$format?>" data-rendered="0">
  325. <input type="hidden" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>" />
  326. <input type="hidden" name="customer_id" value="<?=intval($customer->id)?>" />
  327. <input type="hidden" name="date_range" value="<?=htmlspecialchars($date_range)?>" />
  328. <input type="hidden" name="date_start" id="date-start" value="<?=htmlspecialchars($date_start)?>" />
  329. <input type="hidden" name="date_end" id="date-end" value="<?=htmlspecialchars($date_end)?>" />
  330. <input type="hidden" name="date_resolution" value="<?=htmlspecialchars($date_resolution)?>" />
  331. <input type="hidden" name="retests" value="<?=htmlspecialchars($retests)?>" />
  332. <?php
  333. foreach($exclude_project_ids as $project_id) {
  334. ?>
  335. <input type="hidden" name="exclude_project_ids[]" value="<?=intval($project_id)?>" />
  336. <?php
  337. }
  338. ?>
  339. <input type="submit" value="Submit" class="d-none" />
  340. </form>
  341. <?php
  342. }
  343. if($has_pass_fail) {
  344. $tables = [
  345. (object) [
  346. "name" => "Region",
  347. "data" => $region_data
  348. ],
  349. (object) [
  350. "name" => "Area Manager",
  351. "data" => $area_manager_data
  352. ],
  353. ]
  354. ?>
  355. <div class="d-print-none">
  356. <h2>Extra Information</h2>
  357. <?php
  358. foreach($tables as $table) {
  359. $title = $table->name . " Data";
  360. $entity_type = $table->name;
  361. ?>
  362. <h3><?=htmlspecialchars($title)?></h3>
  363. <?php
  364. foreach($table->data as $entity_name => $rows) {
  365. ?>
  366. <h4><?=htmlspecialchars($entity_type)?>: <?=htmlspecialchars($entity_name)?></h4>
  367. <table class="table">
  368. <colgroup>
  369. <col style="width: 20%" />
  370. <col style="width: 20%" />
  371. <col style="width: 20%" />
  372. <col style="width: 20%" />
  373. <col style="width: 20%" />
  374. </colgroup>
  375. <thead>
  376. <tr>
  377. <th>Period</th>
  378. <th>Tests</th>
  379. <th>Passes</th>
  380. <th>Fails</th>
  381. <th>Rate</th>
  382. </tr>
  383. </thead>
  384. <tbody>
  385. <?php
  386. $index = 0;
  387. foreach($rows as $key => $data) {
  388. $rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
  389. $label = $key_labels[$index];
  390. ?>
  391. <tr>
  392. <td><?=htmlspecialchars($label)?></td>
  393. <td><?=number_format($data->testCount)?></td>
  394. <td><?=number_format($data->passCount)?></td>
  395. <td><?=number_format($data->failCount)?></td>
  396. <td><?=$rate?>%</td>
  397. </tr>
  398. <?php
  399. $index++;
  400. }
  401. ?>
  402. </tbody>
  403. </table>
  404. <?php
  405. }
  406. }
  407. ?>
  408. ?>
  409. </div>
  410. <?php
  411. }
  412. ?>
  413. <?php
  414. }
  415. ?>
  416. </div>