reports.php 12 KB

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