reports.php 11 KB

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