reports.php 11 KB

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