performance.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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">
  16. <div class="col-auto">
  17. <h2><?=htmlspecialchars($customer->name)?> Performance</h2>
  18. </div>
  19. <div class="col">
  20. </div>
  21. </div>
  22. <form class="mb-4" method="post">
  23. <input type="hidden" name="customer_id" value="<?=htmlspecialchars($customer->id)?>" />
  24. <div class="row">
  25. <div class="col-md">
  26. <div class="row mb-1">
  27. <label class="col-sm-4 col-form-label text-sm-right">
  28. Date Range
  29. </label>
  30. <div class="col-sm">
  31. <?php
  32. foreach($date_ranges as $value => $display) {
  33. $checked = ($value == $date_range) ? "checked" : "";
  34. ?>
  35. <div class="form-check form-check-inline">
  36. <input class="form-check-input" type="radio" name="date_range" id="date-range-<?=htmlspecialchars($value)?>" value="<?=htmlspecialchars($value)?>" <?=$checked?> data-date-range-radio-input />
  37. <label class="form-check-label" for="date-range-<?=htmlspecialchars($value)?>"><?=htmlspecialchars($display)?></label>
  38. </div>
  39. <?php
  40. }
  41. ?>
  42. <div class="row mt-1" id="date-range-custom-fields" style="<?=$date_range_custom_style?>">
  43. <div class="col-lg">
  44. <div class="input-group">
  45. <div class="input-group-prepend">
  46. <span class="input-group-text">
  47. From
  48. </span>
  49. </div>
  50. <select class="form-control" name="from_quarter">
  51. <?php
  52. foreach($years as $year) {
  53. foreach(range(1, 4) as $quarter) {
  54. $value = "$year-$quarter";
  55. $selected = ($value == $from_quarter) ? "selected" : "";
  56. switch($quarter) {
  57. case 1: $quarter_text = "Q1 (Jan-Mar)"; break;
  58. case 2: $quarter_text = "Q2 (Apr-Jun)"; break;
  59. case 3: $quarter_text = "Q3 (Jul-Sep)"; break;
  60. case 4: $quarter_text = "Q4 (Oct-Dec)"; break;
  61. }
  62. ?>
  63. <option value="<?=$value?>" <?=$selected?>><?=$year?> <?=$quarter_text?></option>
  64. <?php
  65. }
  66. }
  67. ?>
  68. </select>
  69. </div>
  70. </div>
  71. <div class="col-lg">
  72. <div class="input-group">
  73. <div class="input-group-prepend">
  74. <span class="input-group-text">
  75. To
  76. </span>
  77. </div>
  78. <select class="form-control" name="to_quarter">
  79. <?php
  80. foreach($years as $year) {
  81. foreach(range(1, 4) as $quarter) {
  82. $value = "$year-$quarter";
  83. $selected = ($value == $to_quarter) ? "selected" : "";
  84. switch($quarter) {
  85. case 1: $quarter_text = "Q1 (Jan-Mar)"; break;
  86. case 2: $quarter_text = "Q2 (Apr-Jun)"; break;
  87. case 3: $quarter_text = "Q3 (Jul-Sep)"; break;
  88. case 4: $quarter_text = "Q4 (Oct-Dec)"; break;
  89. }
  90. ?>
  91. <option value="<?=$value?>" <?=$selected?>><?=$year?> <?=$quarter_text?></option>
  92. <?php
  93. }
  94. }
  95. ?>
  96. </select>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. <div class="row mb-1">
  103. <label class="col-sm-4 col-form-label text-sm-right" for="date-resolution">
  104. Date Resolution
  105. </label>
  106. <div class="col-sm">
  107. <select class="form-control" name="date_resolution" id="date-resolution">
  108. <?php
  109. foreach($date_resolutions as $value => $display) {
  110. $selected = ($value == $date_resolution) ? "selected" : "";
  111. ?>
  112. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  113. <?php
  114. }
  115. ?>
  116. </select>
  117. </div>
  118. </div>
  119. <div class="row mb-1">
  120. <label class="col-sm-4 col-form-label text-sm-right" for="project-ids">
  121. Projects
  122. </label>
  123. <div class="col-sm">
  124. <select class="form-control" name="project_ids[]" id="project-ids" multiple size="8">
  125. <?php
  126. foreach($all_projects as $project) {
  127. $selected = in_array($project->id, $project_ids) ? "selected" : "";
  128. ?>
  129. <option value="<?=$project->id?>" <?=$selected?>><?=htmlspecialchars($project->name)?></option>
  130. <?php
  131. }
  132. ?>
  133. </select>
  134. <small class="form-text text-muted">Hint: Ctrl+Click / Cmd+Click to select multiple projects.</small>
  135. </div>
  136. </div>
  137. <div class="row">
  138. <div class="col-sm offset-sm-4">
  139. <button class="btn btn-primary" type="submit" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">
  140. Submit
  141. </button>
  142. </div>
  143. </div>
  144. </div>
  145. </div>
  146. </form>
  147. <?php
  148. if($locations_missing_region) {
  149. ?>
  150. <div class="alert alert-warning">
  151. There are some locations that are missing "region" information:
  152. <ul class="mb-0">
  153. <?php
  154. foreach($locations_missing_region 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. <?php
  176. if($locations_missing_area_manager) {
  177. ?>
  178. <div class="alert alert-warning">
  179. There are some locations that are missing "area manager" information:
  180. <ul class="mb-0">
  181. <?php
  182. foreach($locations_missing_area_manager as $location) {
  183. $url = (Core::$user->canAdmin()) ? "/account/locations/$location->id/edit" : "#";
  184. ?>
  185. <li>
  186. <a href="<?=htmlspecialchars($url)?>"><?=htmlspecialchars($location->name)?></a>
  187. <?php
  188. if($location->internal_id) {
  189. ?>
  190. <small class="text-info">(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
  191. <?php
  192. }
  193. ?>
  194. </li>
  195. <?php
  196. }
  197. ?>
  198. </ul>
  199. </div>
  200. <?php
  201. }
  202. ?>
  203. <?php
  204. if($charts) {
  205. ?>
  206. <h2>Charts / Statistics</h2>
  207. <div class="row">
  208. <div class="col-md-6">
  209. <div class="card card-body mb-3">
  210. Test Count
  211. <div class="stat">
  212. <?=$total_data->testCount?>
  213. </div>
  214. </div>
  215. </div>
  216. <div class="col-md-6">
  217. <div class="card card-body mb-3">
  218. Pass/Fail Count
  219. <div class="stat">
  220. <?=$total_data->passCount?> /
  221. <?=$total_data->failCount?>
  222. </div>
  223. </div>
  224. </div>
  225. </div>
  226. <div class="row mb-4">
  227. <div class="col-md-4" style="position: relative;">
  228. <h3>Chart List</h3>
  229. <div class="list-group" style="position: sticky; top: 7rem;">
  230. <?php
  231. foreach($charts as $index => $chart) {
  232. ?>
  233. <a class="list-group-item list-group-item-action" href="#chart-<?=$index?>">
  234. <?=htmlspecialchars($chart->getTitle())?>
  235. </a>
  236. <?php
  237. }
  238. ?>
  239. </div>
  240. </div>
  241. <div class="col-md">
  242. <?php
  243. foreach($charts as $index => $chart) {
  244. if($index > 0) {
  245. ?>
  246. <br />
  247. <?php
  248. }
  249. ?>
  250. <a id="chart-<?=$index?>" style="display: block; position: relative; top: -7rem; visibility: hidden;"></a>
  251. <canvas id="<?=$chart->getID()?>" data-chart="<?=htmlspecialchars($chart->getJSON())?>" width="400" height="300">
  252. </canvas>
  253. <?php
  254. if($chart->print) {
  255. $chart->printDataTable();
  256. }
  257. }
  258. ?>
  259. </div>
  260. </div>
  261. <?php
  262. if(PRODUCTION == false) {
  263. ?>
  264. <h2>Debug Information</h2>
  265. <h3>Region Data</h3>
  266. <?php
  267. foreach($region_data as $region => $rows) {
  268. ?>
  269. <h4>Region: <?=htmlspecialchars($region)?></h4>
  270. <table class="table">
  271. <col style="width: 20%" />
  272. <col style="width: 20%" />
  273. <col style="width: 20%" />
  274. <col style="width: 20%" />
  275. <col style="width: 20%" />
  276. <thead>
  277. <tr>
  278. <th>Key</th>
  279. <th>Tests</th>
  280. <th>Passes</th>
  281. <th>Fails</th>
  282. <th>Rate</th>
  283. </tr>
  284. </thead>
  285. <tbody>
  286. <?php
  287. foreach($rows as $key => $data) {
  288. $rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
  289. ?>
  290. <tr>
  291. <td><?=htmlspecialchars($key)?></td>
  292. <td><?=number_format($data->testCount)?></td>
  293. <td><?=number_format($data->passCount)?></td>
  294. <td><?=number_format($data->failCount)?></td>
  295. <td><?=$rate?>%</td>
  296. </tr>
  297. <?php
  298. }
  299. ?>
  300. </tbody>
  301. </table>
  302. <?php
  303. }
  304. ?>
  305. <h3>Area Manager Data</h3>
  306. <?php
  307. foreach($area_manager_data as $area_manager => $rows) {
  308. ?>
  309. <h4>Area Manager: <?=htmlspecialchars($area_manager)?></h4>
  310. <table class="table">
  311. <col style="width: 20%" />
  312. <col style="width: 20%" />
  313. <col style="width: 20%" />
  314. <col style="width: 20%" />
  315. <col style="width: 20%" />
  316. <thead>
  317. <tr>
  318. <th>Key</th>
  319. <th>Tests</th>
  320. <th>Passes</th>
  321. <th>Fails</th>
  322. <th>Rate</th>
  323. </tr>
  324. </thead>
  325. <tbody>
  326. <?php
  327. foreach($rows as $key => $data) {
  328. $rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
  329. ?>
  330. <tr>
  331. <td><?=htmlspecialchars($key)?></td>
  332. <td><?=number_format($data->testCount)?></td>
  333. <td><?=number_format($data->passCount)?></td>
  334. <td><?=number_format($data->failCount)?></td>
  335. <td><?=$rate?>%</td>
  336. </tr>
  337. <?php
  338. }
  339. ?>
  340. </tbody>
  341. </table>
  342. <?php
  343. }
  344. }
  345. }
  346. ?>
  347. </div>