1
0

performance.php 11 KB

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