reports.php 12 KB

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