reports.php 11 KB

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