reports.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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></th>
  154. <th>ID</th>
  155. <th>Name</th>
  156. <th><span title="Time of Day" data-toggle="tooltip">TOD</span></th>
  157. <th>Tests</th>
  158. <th>Report Month</th>
  159. </tr>
  160. </thead>
  161. </table>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. </form>
  167. <?php
  168. if($user->canSeeMissingData()) {
  169. if($locations_missing_region) {
  170. ?>
  171. <div class="alert alert-warning limit-height-1 d-print-none">
  172. There are some locations that are missing "region" information:
  173. <ul class="mb-0">
  174. <?php
  175. foreach($locations_missing_region as $location) {
  176. $url = (Core::$user->canAdmin()) ? "/account/locations/$location->id/edit" : "#";
  177. ?>
  178. <li>
  179. <a href="<?=htmlspecialchars($url)?>"><?=htmlspecialchars($location->name)?></a>
  180. <?php
  181. if($location->internal_id) {
  182. ?>
  183. <small class="text-info">(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
  184. <?php
  185. }
  186. ?>
  187. </li>
  188. <?php
  189. }
  190. ?>
  191. </ul>
  192. </div>
  193. <?php
  194. }
  195. if($locations_missing_area_manager) {
  196. ?>
  197. <div class="alert alert-warning limit-height-1 d-print-none">
  198. There are some locations that are missing "area manager" information:
  199. <ul class="mb-0">
  200. <?php
  201. foreach($locations_missing_area_manager as $location) {
  202. $url = (Core::$user->canAdmin()) ? "/account/locations/$location->id/edit" : "#";
  203. ?>
  204. <li>
  205. <a href="<?=htmlspecialchars($url)?>"><?=htmlspecialchars($location->name)?></a>
  206. <?php
  207. if($location->internal_id) {
  208. ?>
  209. <small class="text-info">(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
  210. <?php
  211. }
  212. ?>
  213. </li>
  214. <?php
  215. }
  216. ?>
  217. </ul>
  218. </div>
  219. <?php
  220. }
  221. }
  222. if($charts) {
  223. ?>
  224. <h2>
  225. Report
  226. </h2>
  227. <p>
  228. <?php
  229. if($retests === 0) {
  230. ?>
  231. <span class="badge badge-warning">Retests Excluded</span>
  232. <?php
  233. }
  234. else if($retests === 1) {
  235. ?>
  236. <span class="badge badge-warning">Retests Only</span>
  237. <?php
  238. }
  239. else {
  240. ?>
  241. <span class="badge badge-success">Retests Included</span>
  242. <?php
  243. }
  244. ?>
  245. </p>
  246. <div class="row">
  247. <div class="col-md-6">
  248. <div class="card card-body mb-3">
  249. Test Count
  250. <div class="stat">
  251. <?=$total_data->testCount?>
  252. </div>
  253. </div>
  254. </div>
  255. <div class="col-md-6">
  256. <?php
  257. if(isset($total_data->passCount)) {
  258. $pass_percentage = 0;
  259. if($total_data->testCount > 0) {
  260. $pass_percentage = number_format(($total_data->passCount * 100) / $total_data->testCount, 2);
  261. }
  262. ?>
  263. <div class="card card-body mb-3">
  264. Pass/Fail Count
  265. <div class="stat">
  266. <?=$total_data->passCount?> /
  267. <?=$total_data->failCount?> (<?=$pass_percentage?>%)
  268. </div>
  269. </div>
  270. <?php
  271. }
  272. ?>
  273. </div>
  274. </div>
  275. <div class="row mb-4">
  276. <div class="col-md-4 d-print-none" style="position: relative;">
  277. <h3>Chart List</h3>
  278. <div class="list-group limit-height-2" style="position: sticky; top: 7rem;">
  279. <?php
  280. foreach($charts as $index => $chart) {
  281. ?>
  282. <a class="list-group-item list-group-item-action" href="#chart-<?=$index?>">
  283. <?=htmlspecialchars($chart->getTitle())?>
  284. </a>
  285. <?php
  286. }
  287. ?>
  288. </div>
  289. </div>
  290. <div class="col-md-8">
  291. <?php
  292. foreach($charts as $index => $chart) {
  293. if($index > 0) {
  294. ?>
  295. <br />
  296. <?php
  297. }
  298. if($chart->beforeHtml) {
  299. echo $chart->beforeHtml;
  300. }
  301. ?>
  302. <a id="chart-<?=$index?>" style="display: block; position: relative; top: -7rem; visibility: hidden;"></a>
  303. <canvas id="<?=$chart->getID()?>" data-chart="<?=htmlspecialchars($chart->getJSON())?>" width="400" height="300">
  304. </canvas>
  305. <?php
  306. if($chart->print) {
  307. $chart->printDataTable();
  308. }
  309. if($chart->afterHtml) {
  310. echo $chart->afterHtml;
  311. }
  312. }
  313. ?>
  314. </div>
  315. </div>
  316. <?php
  317. foreach(["pptx", "odp"] as $format) {
  318. ?>
  319. <form id="form-<?=$format?>" method="post" action="/account/reports/export-<?=$format?>" data-rendered="0">
  320. <input type="hidden" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>" />
  321. <input type="hidden" name="customer_id" value="<?=intval($customer->id)?>" />
  322. <input type="hidden" name="date_range" value="<?=htmlspecialchars($date_range)?>" />
  323. <input type="hidden" name="date_start" id="date-start" value="<?=htmlspecialchars($date_start)?>" />
  324. <input type="hidden" name="date_end" id="date-end" value="<?=htmlspecialchars($date_end)?>" />
  325. <input type="hidden" name="date_resolution" value="<?=htmlspecialchars($date_resolution)?>" />
  326. <input type="hidden" name="retests" value="<?=htmlspecialchars($retests)?>" />
  327. <?php
  328. foreach($exclude_project_ids as $project_id) {
  329. ?>
  330. <input type="hidden" name="exclude_project_ids[]" value="<?=intval($project_id)?>" />
  331. <?php
  332. }
  333. ?>
  334. <input type="submit" value="Submit" class="d-none" />
  335. </form>
  336. <?php
  337. }
  338. if($has_pass_fail) {
  339. $tables = [
  340. (object) [
  341. "name" => "Region",
  342. "data" => $region_data
  343. ],
  344. (object) [
  345. "name" => "Area Manager",
  346. "data" => $area_manager_data
  347. ],
  348. ]
  349. ?>
  350. <div class="d-print-none">
  351. <h2>Extra Information</h2>
  352. <?php
  353. foreach($tables as $table) {
  354. $title = $table->name . " Data";
  355. $entity_type = $table->name;
  356. ?>
  357. <h3><?=htmlspecialchars($title)?></h3>
  358. <?php
  359. foreach($table->data as $entity_name => $rows) {
  360. ?>
  361. <h4><?=htmlspecialchars($entity_type)?>: <?=htmlspecialchars($entity_name)?></h4>
  362. <table class="table">
  363. <colgroup>
  364. <col style="width: 20%" />
  365. <col style="width: 20%" />
  366. <col style="width: 20%" />
  367. <col style="width: 20%" />
  368. <col style="width: 20%" />
  369. </colgroup>
  370. <thead>
  371. <tr>
  372. <th>Period</th>
  373. <th>Tests</th>
  374. <th>Passes</th>
  375. <th>Fails</th>
  376. <th>Rate</th>
  377. </tr>
  378. </thead>
  379. <tbody>
  380. <?php
  381. $index = 0;
  382. foreach($rows as $key => $data) {
  383. $rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
  384. $label = $key_labels[$index];
  385. ?>
  386. <tr>
  387. <td><?=htmlspecialchars($label)?></td>
  388. <td><?=number_format($data->testCount)?></td>
  389. <td><?=number_format($data->passCount)?></td>
  390. <td><?=number_format($data->failCount)?></td>
  391. <td><?=$rate?>%</td>
  392. </tr>
  393. <?php
  394. $index++;
  395. }
  396. ?>
  397. </tbody>
  398. </table>
  399. <?php
  400. }
  401. }
  402. ?>
  403. ?>
  404. </div>
  405. <?php
  406. }
  407. ?>
  408. <?php
  409. }
  410. ?>
  411. </div>