reports.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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>
  60. Exclude Projects
  61. </label>
  62. <table class="table table-sm table-sm-text table-hover table-pointer" id="projects-table">
  63. <thead>
  64. <tr>
  65. <th></th>
  66. <th>ID</th>
  67. <th>Name</th>
  68. <th><span title="Time of Day" data-toggle="tooltip">TOD</span></th>
  69. <th>Tests</th>
  70. <th>Report Month</th>
  71. </tr>
  72. </thead>
  73. </table>
  74. </div>
  75. </div>
  76. <div class="col-md">
  77. <div class="form-group">
  78. <label class="form-label" for="date-range">
  79. Date Range
  80. </label><br / >
  81. <?php
  82. foreach($date_ranges as $value => $display) {
  83. $checked = ($value == $date_range) ? "checked" : "";
  84. ?>
  85. <div class="form-check form-check-inline">
  86. <input class="form-check-input" type="radio" name="date_range" id="date-range-<?=htmlspecialchars($value)?>" value="<?=htmlspecialchars($value)?>" <?=$checked?> data-date-range-radio-input />
  87. <label class="form-check-label" for="date-range-<?=htmlspecialchars($value)?>"><?=htmlspecialchars($display)?></label>
  88. </div>
  89. <?php
  90. }
  91. ?>
  92. <div class="row mt-1" id="date-range-custom-fields" style="<?=$date_range_custom_style?>">
  93. <div class="col-lg">
  94. <input class="form-control" type="text" id="date-range" value="<?=htmlspecialchars($date_range_value)?>" />
  95. <input type="hidden" name="date_start" id="date-start" value="<?=htmlspecialchars($date_start)?>" />
  96. <input type="hidden" name="date_end" id="date-end" value="<?=htmlspecialchars($date_end)?>" />
  97. </div>
  98. </div>
  99. </div>
  100. <div class="form-group">
  101. <label for="date-resolution">
  102. Date Resolution
  103. </label>
  104. <select class="form-control" name="date_resolution" id="date-resolution">
  105. <?php
  106. foreach($date_resolutions as $value => $display) {
  107. $selected = ($value == $date_resolution) ? "selected" : "";
  108. ?>
  109. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  110. <?php
  111. }
  112. ?>
  113. </select>
  114. </div>
  115. <div class="form-group">
  116. <label for="location-ids">
  117. Location IDs
  118. </label>
  119. <input class="form-control" name="location_ids" type="text" id="location-ids" value="<?=htmlspecialchars(implode(" ", $location_ids))?>" placeholder="Enter location IDs" />
  120. <small class="form-text text-muted">Separate each location ID with a space.<br />Leave blank to generate a report for all locations.</small>
  121. </div>
  122. <div class="form-group">
  123. <label for="retests">Retests</label>
  124. <select name="retests" id="retests" class="form-control">
  125. <option value="">Include</option>
  126. <?php
  127. foreach($retests_options as $value => $display) {
  128. $selected = $value === $retests ? "selected" : "";
  129. ?>
  130. <option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  131. <?php
  132. }
  133. ?>
  134. </select>
  135. </div>
  136. <button class="btn btn-primary" type="submit" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">
  137. Submit
  138. </button>
  139. </div>
  140. </div>
  141. </form>
  142. <?php
  143. if(Core::$user->isAdmin()) {
  144. if($locations_missing_region) {
  145. ?>
  146. <div class="alert alert-warning limit-height-1 d-print-none">
  147. There are some locations that are missing "region" information:
  148. <ul class="mb-0">
  149. <?php
  150. foreach($locations_missing_region as $location) {
  151. $url = (Core::$user->canAdmin()) ? "/account/locations/$location->id/edit" : "#";
  152. ?>
  153. <li>
  154. <a href="<?=htmlspecialchars($url)?>"><?=htmlspecialchars($location->name)?></a>
  155. <?php
  156. if($location->internal_id) {
  157. ?>
  158. <small class="text-info">(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
  159. <?php
  160. }
  161. ?>
  162. </li>
  163. <?php
  164. }
  165. ?>
  166. </ul>
  167. </div>
  168. <?php
  169. }
  170. if($locations_missing_area_manager) {
  171. ?>
  172. <div class="alert alert-warning limit-height-1 d-print-none">
  173. There are some locations that are missing "area manager" information:
  174. <ul class="mb-0">
  175. <?php
  176. foreach($locations_missing_area_manager as $location) {
  177. $url = (Core::$user->canAdmin()) ? "/account/locations/$location->id/edit" : "#";
  178. ?>
  179. <li>
  180. <a href="<?=htmlspecialchars($url)?>"><?=htmlspecialchars($location->name)?></a>
  181. <?php
  182. if($location->internal_id) {
  183. ?>
  184. <small class="text-info">(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
  185. <?php
  186. }
  187. ?>
  188. </li>
  189. <?php
  190. }
  191. ?>
  192. </ul>
  193. </div>
  194. <?php
  195. }
  196. }
  197. if($charts) {
  198. ?>
  199. <h2>
  200. Report
  201. </h2>
  202. <p>
  203. <?php
  204. if($retests === 0) {
  205. ?>
  206. <span class="badge badge-warning">Retests Excluded</span>
  207. <?php
  208. }
  209. else if($retests === 1) {
  210. ?>
  211. <span class="badge badge-warning">Retests Only</span>
  212. <?php
  213. }
  214. else {
  215. ?>
  216. <span class="badge badge-success">Retests Included</span>
  217. <?php
  218. }
  219. ?>
  220. </p>
  221. <div class="row">
  222. <div class="col-md-6">
  223. <div class="card card-body mb-3">
  224. Test Count
  225. <div class="stat">
  226. <?=$total_data->testCount?>
  227. </div>
  228. </div>
  229. </div>
  230. <div class="col-md-6">
  231. <?php
  232. if(isset($total_data->passCount)) {
  233. $pass_percentage = 0;
  234. if($total_data->testCount > 0) {
  235. $pass_percentage = number_format(($total_data->passCount * 100) / $total_data->testCount, 2);
  236. }
  237. ?>
  238. <div class="card card-body mb-3">
  239. Pass/Fail Count
  240. <div class="stat">
  241. <?=$total_data->passCount?> /
  242. <?=$total_data->failCount?> (<?=$pass_percentage?>%)
  243. </div>
  244. </div>
  245. <?php
  246. }
  247. ?>
  248. </div>
  249. </div>
  250. <div class="row mb-4">
  251. <div class="col-md-4 d-print-none" style="position: relative;">
  252. <h3>Chart List</h3>
  253. <div class="list-group limit-height-2" style="position: sticky; top: 7rem;">
  254. <?php
  255. foreach($charts as $index => $chart) {
  256. ?>
  257. <a class="list-group-item list-group-item-action" href="#chart-<?=$index?>">
  258. <?=htmlspecialchars($chart->getTitle())?>
  259. </a>
  260. <?php
  261. }
  262. ?>
  263. </div>
  264. </div>
  265. <div class="col-md-8">
  266. <?php
  267. foreach($charts as $index => $chart) {
  268. if($index > 0) {
  269. ?>
  270. <br />
  271. <?php
  272. }
  273. if($chart->beforeHtml) {
  274. echo $chart->beforeHtml;
  275. }
  276. ?>
  277. <a id="chart-<?=$index?>" style="display: block; position: relative; top: -7rem; visibility: hidden;"></a>
  278. <canvas id="<?=$chart->getID()?>" data-chart="<?=htmlspecialchars($chart->getJSON())?>" width="400" height="300">
  279. </canvas>
  280. <?php
  281. if($chart->print) {
  282. $chart->printDataTable();
  283. }
  284. if($chart->afterHtml) {
  285. echo $chart->afterHtml;
  286. }
  287. }
  288. ?>
  289. </div>
  290. </div>
  291. <?php
  292. foreach(["pptx", "odp"] as $format) {
  293. ?>
  294. <form id="form-<?=$format?>" method="post" action="/account/reports/export-<?=$format?>" data-rendered="0">
  295. <input type="hidden" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>" />
  296. <input type="hidden" name="customer_id" value="<?=intval($customer->id)?>" />
  297. <input type="hidden" name="date_range" value="<?=htmlspecialchars($date_range)?>" />
  298. <input type="hidden" name="date_start" id="date-start" value="<?=htmlspecialchars($date_start)?>" />
  299. <input type="hidden" name="date_end" id="date-end" value="<?=htmlspecialchars($date_end)?>" />
  300. <input type="hidden" name="date_resolution" value="<?=htmlspecialchars($date_resolution)?>" />
  301. <input type="hidden" name="retests" value="<?=htmlspecialchars($retests)?>" />
  302. <?php
  303. foreach($exclude_project_ids as $project_id) {
  304. ?>
  305. <input type="hidden" name="exclude_project_ids[]" value="<?=intval($project_id)?>" />
  306. <?php
  307. }
  308. ?>
  309. <input type="submit" value="Submit" class="d-none" />
  310. </form>
  311. <?php
  312. }
  313. if($has_pass_fail) {
  314. ?>
  315. <div class="d-print-none">
  316. <h2>Extra Information</h2>
  317. <h3>Region Data</h3>
  318. <?php
  319. foreach($region_data as $region => $rows) {
  320. ?>
  321. <h4>Region: <?=htmlspecialchars($region)?></h4>
  322. <table class="table">
  323. <colgroup>
  324. <col style="width: 20%" />
  325. <col style="width: 20%" />
  326. <col style="width: 20%" />
  327. <col style="width: 20%" />
  328. <col style="width: 20%" />
  329. </colgroup>
  330. <thead>
  331. <tr>
  332. <th>Period</th>
  333. <th>Tests</th>
  334. <th>Passes</th>
  335. <th>Fails</th>
  336. <th>Rate</th>
  337. </tr>
  338. </thead>
  339. <tbody>
  340. <?php
  341. $index = 0;
  342. foreach($rows as $key => $data) {
  343. $rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
  344. $label = $key_labels[$index];
  345. ?>
  346. <tr>
  347. <td><?=htmlspecialchars($label)?></td>
  348. <td><?=number_format($data->testCount)?></td>
  349. <td><?=number_format($data->passCount)?></td>
  350. <td><?=number_format($data->failCount)?></td>
  351. <td><?=$rate?>%</td>
  352. </tr>
  353. <?php
  354. $index++;
  355. }
  356. ?>
  357. </tbody>
  358. </table>
  359. <?php
  360. }
  361. ?>
  362. <h3>Area Manager Data</h3>
  363. <?php
  364. foreach($area_manager_data as $area_manager => $rows) {
  365. ?>
  366. <h4>Area Manager: <?=htmlspecialchars($area_manager)?></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. </div>
  408. <?php
  409. }
  410. ?>
  411. <?php
  412. }
  413. ?>
  414. </div>