reports.php 14 KB

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