reports.php 11 KB

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