reports.php 12 KB

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