reports.php 12 KB

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