| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- /**
- * @var Customer $customer
- * @var Chart[] $charts
- * @var string[] $key_labels
- * @var bool $has_pass_fail
- *
- * @var array $exclude_categories
- * @var object $template_config
- *
- * @var int $project_id
- *
- * @var string $date_range
- * @var string $date_resolution
- * @var string $date_start
- * @var string $date_end
- *
- * @var int[] $location_ids
- * @var int $retests
- * @var int[] $exclude_project_ids
- *
- * @var array $project_table_data
- * @var Location[] $locations_missing_region
- * @var Location[] $locations_missing_area_manager
- * @var Location[] $locations_missing_brand
- * @var Location[] $locations_missing_operations_manager
- *
- * @var array $total_data
- * @var array $region_data
- * @var array $area_manager_data
- * @var array $brand_data
- * @var array $operations_manager_data
- */
- $user = Core::$user;
- $date_resolutions = [
- "quarterly" => "Quarterly",
- "monthly" => "Monthly",
- ];
- $date_ranges = [
- "ytd" => "Year to Date",
- //"unbound" => "Unbound",
- "custom" => "Custom",
- ];
- $retests_options = [
- 0 => "Exclude",
- 1 => "Retests Only"
- ];
- $years = range(2018, date("Y"));
- $date_range_custom_style = ($date_range === "custom") ? "" : "display: none";
- $date_range_value = "";
- if($date_start && $date_end) {
- [$min_year, $min_month, $min_day] = explode("-", $date_start);
- [$max_year, $max_month, $max_day] = explode("-", $date_end);
- $date_range_value = "$min_day/$min_month/$min_year - $max_day/$max_month/$max_year";
- }
- $collator = new Collator("en_GB");
- if($charts) {
- $brands = array_keys($brand_data);
- $regions = array_keys($region_data);
- $area_managers = array_keys($area_manager_data);
- $operations_managers = array_keys($operations_manager_data);
- }
- else {
- $brands = $customer->getBrands();
- $regions = $customer->getRegions();
- $area_managers = $customer->getAreaManagerNames();
- $operations_managers = $customer->getOperationsManagerNames();
- }
- $gaming_managers = $customer->getGamingManagerNames();
- $senior_gaming_managers = $customer->getSeniorGamingManagerNames();
- $collator->sort($brands);
- $collator->sort($regions);
- $collator->sort($area_managers);
- $collator->sort($operations_managers);
- $project_options = [];
- foreach($project_table_data as $project_data) {
- $project_options[$project_data["id"]] = $project_data["name"];
- }
- ?>
- <script>
- let selectedProjectIds = <?=json_encode($exclude_project_ids)?>;
- let projectData = <?=json_encode($project_table_data)?>;
- </script>
- <div class="container mt-3 py-4">
- <div class="row d-print-none">
- <div class="col">
- <h2><?=htmlspecialchars($customer->name)?> Reports</h2>
- </div>
- <div class="col-auto">
- <?php
- if($charts) {
- ?>
- <div class="dropdown">
- <button type="button" class="btn btn-secondary dropdown-toggle" id="actions-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
- Actions
- </button>
- <div class="dropdown-menu" aria-labelledby="actions-button">
- <a class="dropdown-item" href="#" id="export-pptx-action">Export PPTX</a>
- </div>
- </div>
- <?php
- }
- ?>
- </div>
- </div>
- <form class="mb-4 d-print-none" method="post">
- <input type="hidden" name="customer_id" value="<?=htmlspecialchars($customer->id)?>" />
- <div class="row">
- <div class="col-md">
- <div class="form-group">
- <label for="project"><?=htmlspecialchars(__("Project"))?></label>
- <select class="form-control" name="project_id" id="project">
- <option value=""><?=htmlspecialchars(__("Select Project"))?></option>
- <?php
- HtmlHelper::renderOptions($project_options, $project_id);
- ?>
- </select>
- </div>
- <div class="form-group">
- <label class="form-label" for="date-range">
- Date Range
- </label><br />
- <?php
- foreach($date_ranges as $value => $display) {
- $checked = ($value === $date_range) ? "checked" : "";
- ?>
- <div class="form-check form-check-inline">
- <input class="form-check-input" type="radio" name="date_range" id="date-range-<?=htmlspecialchars($value)?>" value="<?=htmlspecialchars($value)?>" <?=$checked?> data-date-range-radio-input />
- <label class="form-check-label" for="date-range-<?=htmlspecialchars($value)?>"><?=htmlspecialchars($display)?></label>
- </div>
- <?php
- }
- ?>
- <div class="row mt-1" id="date-range-custom-fields" style="<?=$date_range_custom_style?>">
- <div class="col-lg">
- <input class="form-control" type="text" id="date-range" value="<?=htmlspecialchars($date_range_value)?>" />
- <input type="hidden" name="date_start" id="date-start" value="<?=htmlspecialchars($date_start)?>" />
- <input type="hidden" name="date_end" id="date-end" value="<?=htmlspecialchars($date_end)?>" />
- </div>
- </div>
- </div>
- <div class="form-group">
- <label for="date-resolution">
- Date Resolution
- </label>
- <select class="form-control" name="date_resolution" id="date-resolution">
- <?php
- foreach($date_resolutions as $value => $display) {
- $selected = ($value === $date_resolution) ? "selected" : "";
- ?>
- <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
- <?php
- }
- ?>
- </select>
- </div>
- <div class="form-group">
- <label for="location-ids">
- Location IDs
- </label>
- <input class="form-control" name="location_ids" type="text" id="location-ids" value="<?=htmlspecialchars(implode(" ", $location_ids))?>" placeholder="Enter location IDs" />
- <small class="form-text text-muted">Separate each location ID with a space.<br />Leave blank to generate a report for all locations.</small>
- </div>
- <div class="form-group">
- <label for="retests">Retests</label>
- <select name="retests" id="retests" class="form-control">
- <option value="">Include</option>
- <?php
- foreach($retests_options as $value => $display) {
- $selected = $value === $retests ? "selected" : "";
- ?>
- <option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
- <?php
- }
- ?>
- </select>
- </div>
- <?php
- $categories = $template_config->reports->categories ?? [];
- if($total_data && $categories) {
- ?>
- <div class="form-group">
- <label><?=htmlspecialchars(__("Exclude Categories"))?></label><br />
- <?php
- foreach($categories as $category) {
- $id = sprintf("exclude-category-%s", strtolower($category));
- $checked = in_array($category, $exclude_categories) ? "checked" : "";
- ?>
- <div class="custom-control custom-switch">
- <input class="custom-control-input" id="<?=$id?>" name="exclude_categories[]" type="checkbox" value="<?=htmlspecialchars($category)?>" <?=$checked?> />
- <label class="custom-control-label" for="<?=$id?>"><?=htmlspecialchars($category)?></label>
- </div>
- <?php
- }
- ?>
- <input type="hidden" name="exclude_categories[]" value="none" />
- </div>
- <?php
- }
- /**
- * @param string $name
- * @param string $id
- * @param string $label
- * @param array $values
- * @return void
- * @throws Exception
- */
- $render_location_entity_filter = static function(string $name, string $id, string $label, array $values): void {
- if(!$values) {
- return;
- }
- $request_name = preg_replace("/\[]/", "", $name);
- $selected_values = http::value($request_name, "trim") ?? [];
- ?>
- <div class="form-group">
- <label for="<?=$id?>"><?=htmlspecialchars($label)?></label>
- <select class="form-control" name="<?=$name?>" id="<?=$id?>" data-toggle="select2" data-placeholder="<?=htmlspecialchars(__("All"))?>" multiple>
- <?php
- foreach($values as $value) {
- $selected = in_array($value, $selected_values) ? "selected" : ""
- ?>
- <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($value)?></option>
- <?php
- }
- ?>
- </select>
- </div>
- <?php
- };
- ?>
- </div>
- <div class="col-md">
- <?php
- $render_location_entity_filter("brands[]", "brands", $customer->getBrandLabel(2), $brands);
- $render_location_entity_filter("operations_managers[]", "operation_managers", $customer->getOperationsManagerLabel(2), $operations_managers);
- $render_location_entity_filter("regions[]", "regions", $customer->getRegionLabel(2), $regions);
- $render_location_entity_filter("area_managers[]", "area_managers", $customer->getAreaManagerLabel(2), $area_managers);
- $render_location_entity_filter("senior_gaming_managers[]", "senior_gaming_managers", $customer->getSeniorGamingManagerLabel(2), $senior_gaming_managers);
- $render_location_entity_filter("gaming_managers[]", "gaming_managers", $customer->getGamingManagerLabel(2), $gaming_managers);
- ?>
- <div class="form-group">
- <label class="d-block">
- Exclude Projects
- </label>
- <button id="show-projects-list-button" type="button" class="btn btn-secondary">
- <?=htmlspecialchars(__("Show project list"))?>
- </button>
- <div id="projects-table-wrapper" style="display: none;">
- <table class="table table-sm table-sm-text table-hover table-pointer" id="projects-table">
- <thead>
- <tr>
- <th>
- <label for="exclude-projects-header-checkbox" class="sr-only">
- <?=htmlspecialchars(__("Exclude All"))?>
- </label>
- <input id="exclude-projects-header-checkbox" type="checkbox" />
- </th>
- <th>ID</th>
- <th>Name</th>
- <th><span title="Time of Day" data-toggle="tooltip">TOD</span></th>
- <th>Tests</th>
- <th>Report Month</th>
- </tr>
- </thead>
- </table>
- </div>
- </div>
- </div>
- </div>
- <button class="btn btn-primary" type="submit" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">
- Submit
- </button>
- </form>
- <?php
- if($user->canSeeMissingData()) {
- /**
- * @param string $field
- * @param Location[] $locations
- * @return void
- */
- $render_locations_missing_data = static function(string $field, array $locations): void {
- ?>
- <div class="alert alert-warning limit-height-1 d-print-none">
- There are some locations that are missing "<?=htmlspecialchars($field)?>" information:
- <ul class="mb-0">
- <?php
- foreach($locations as $location) {
- $url = (Core::$user->canAdmin()) ? "/account/locations/$location->id/edit" : "#";
- ?>
- <li>
- <a href="<?=htmlspecialchars($url)?>"><?=htmlspecialchars($location->name)?></a>
- <?php
- if($location->internal_id) {
- ?>
- <small class="text-info">(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
- <?php
- }
- ?>
- </li>
- <?php
- }
- ?>
- </ul>
- </div>
- <?php
- };
- if($locations_missing_region) {
- $render_locations_missing_data("region", $locations_missing_region);
- }
- if($locations_missing_area_manager) {
- $render_locations_missing_data("area manager", $locations_missing_area_manager);
- }
- if($locations_missing_operations_manager) {
- $render_locations_missing_data("operations manager", $locations_missing_operations_manager);
- }
- if($locations_missing_brand) {
- $render_locations_missing_data("brand", $locations_missing_brand);
- }
- }
- if($charts) {
- ?>
- <h2>
- Report
- </h2>
- <p>
- <?php
- if($retests === 0) {
- ?>
- <span class="badge badge-warning">Retests Excluded</span>
- <?php
- }
- else if($retests === 1) {
- ?>
- <span class="badge badge-warning">Retests Only</span>
- <?php
- }
- else {
- ?>
- <span class="badge badge-success">Retests Included</span>
- <?php
- }
- ?>
- </p>
- <?php
- $render_pass_fail_row = static function(string $title, $pass, $fail, $void) {
- $total = $pass + $fail;
- $pass_percentage = 0;
- if($total > 0) {
- $pass_percentage = number_format(($pass * 100) / $total, 2);
- }
- ?>
- <tr>
- <th><?=htmlspecialchars($title)?></th>
- <td class="text-right"><?=$pass?></td>
- <td class="text-right"><?=$pass_percentage?>%</td>
- <td class="text-right"><?=$fail?></td>
- <td class="text-right"><?=$total?></td>
- <td class="text-right"><?=$void?></td>
- </tr>
- <?php
- };
- ?>
- <table class="table table-sm table-bordered">
- <colgroup>
- <col style="width: 16%"/>
- <col style="width: 16%"/>
- <col style="width: 16%"/>
- <col style="width: 16%"/>
- <col style="width: 16%"/>
- </colgroup>
- <thead>
- <tr>
- <th></th>
- <th><?=htmlspecialchars(__("Passes"))?></th>
- <th><?=htmlspecialchars(__("Pass Rate"))?></th>
- <th><?=htmlspecialchars(__("Fails"))?></th>
- <th><?=htmlspecialchars(__("Total"))?></th>
- <th><?=htmlspecialchars(__("Voids"))?></th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <th><?=htmlspecialchars(__("Venue Tests"))?></th>
- <td colspan="3"></td>
- <td class="text-right"><?=htmlspecialchars($total_data->testCount)?></td>
- <td class="text-right"><?=htmlspecialchars($total_data->voidCount)?></td>
- </tr>
- <?php
- if(isset($total_data->passCount)) {
- $render_pass_fail_row("Gaming Tests", $total_data->passCount, $total_data->failCount, $total_data->gamingCounts["void"] ?? 0);
- }
- if(isset($total_data->barCounts)) {
- $render_pass_fail_row("Alcohol Tests", $total_data->barCounts["pass"], $total_data->barCounts["fail"], $total_data->barCounts["void"] ?? 0);
- }
- if(isset($total_data->combinedCounts)) {
- $render_pass_fail_row("Combined Tests", $total_data->combinedCounts["pass"], $total_data->combinedCounts["fail"], $total_data->combinedCounts["void"] ?? 0);
- }
- if(isset($total_data->blendedCounts)) {
- $render_pass_fail_row("Blended Tests", $total_data->blendedCounts["pass"], $total_data->blendedCounts["fail"], $total_data->blendedCounts["void"] ?? 0);
- }
- ?>
- </tbody>
- </table>
- <div class="row mb-4">
- <div class="col-md-4 d-print-none" style="position: relative;">
- <h3>Chart List</h3>
- <div class="list-group limit-height-2" style="position: sticky; top: 7rem;">
- <?php
- foreach($charts as $index => $chart) {
- if($project_id && $chart->isPeriodic()) {
- continue;
- }
- ?>
- <a class="list-group-item list-group-item-action" href="#chart-<?=$index?>">
- <?=htmlspecialchars($chart->getTitle())?>
- </a>
- <?php
- }
- ?>
- </div>
- </div>
- <div class="col-md-8">
- <?php
- foreach($charts as $index => $chart) {
- if($project_id && $chart->isPeriodic()) {
- continue;
- }
- if($index > 0) {
- ?>
- <br />
- <?php
- }
- if($chart->beforeHtml) {
- echo $chart->beforeHtml;
- }
- ?>
- <a id="chart-<?=$index?>" style="display: block; position: relative; top: -7rem; visibility: hidden;"></a>
- <canvas id="<?=$chart->getID()?>" data-chart="<?=htmlspecialchars($chart->getJSON())?>" width="400" height="300">
- </canvas>
- <?php
- if($chart->print) {
- $chart->printDataTable();
- }
- if($chart->afterHtml) {
- echo $chart->afterHtml;
- }
- }
- ?>
- </div>
- </div>
- <?php
- foreach(["pptx", "odp"] as $format) {
- ?>
- <form id="form-<?=$format?>" method="post" action="/account/reports/export-<?=$format?>" data-rendered="0">
- <input type="hidden" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>" />
- <input type="hidden" name="customer_id" value="<?=$customer->id?>" />
- <input type="hidden" name="project_id" value="<?=$project_id?>" />
- <input type="hidden" name="date_range" value="<?=htmlspecialchars($date_range)?>" />
- <input type="hidden" name="date_start" id="date-start" value="<?=htmlspecialchars($date_start)?>" />
- <input type="hidden" name="date_end" id="date-end" value="<?=htmlspecialchars($date_end)?>" />
- <input type="hidden" name="date_resolution" value="<?=htmlspecialchars($date_resolution)?>" />
- <input type="hidden" name="retests" value="<?=htmlspecialchars($retests)?>" />
- <?php
- foreach($exclude_project_ids as $exclude_project_id) {
- ?>
- <input type="hidden" name="exclude_project_ids[]" value="<?=$exclude_project_id?>" />
- <?php
- }
- foreach($exclude_categories as $exclude_category) {
- ?>
- <input type="hidden" name="exclude_categories[]" value="<?=$exclude_category?>" />
- <?php
- }
- ?>
- <input type="submit" value="Submit" class="d-none" />
- </form>
- <?php
- }
- if($has_pass_fail) {
- $tables = [
- (object) [
- "name" => $customer->getRegionLabel(1),
- "data" => $region_data
- ],
- (object) [
- "name" => $customer->getAreaManagerLabel(1),
- "data" => $area_manager_data
- ],
- (object) [
- "name" => $customer->getOperationsManagerLabel(1),
- "data" => $operations_manager_data
- ],
- (object) [
- "name" => $customer->getBrandLabel(1),
- "data" => $brand_data
- ],
- ]
- ?>
- <div class="d-print-none">
- <h2>Extra Information</h2>
- <?php
- foreach($tables as $table) {
- $title = $table->name . " Data";
- $entity_type = $table->name;
- // Calculate totals
- $totals = [];
- foreach($table->data as $entity_name => $rows) {
- $totals[] = [
- "name" => $entity_name,
- "testCount" => array_sum(array_column($rows, "testCount")),
- "passCount" => array_sum(array_column($rows, "passCount")),
- "failCount" => array_sum(array_column($rows, "failCount")),
- ];
- }
- if(!$totals) {
- continue;
- }
- ?>
- <h3><?=htmlspecialchars($title)?></h3>
- <h4><?=htmlspecialchars($entity_type)?>: Totals</h4>
- <?php
- usort($totals, static function($a, $b) {
- return strnatcasecmp($a["name"], $b["name"]);
- });
- $total_test_count = 0;
- $total_pass_count = 0;
- $total_fail_count = 0;
- ?>
- <table class="table table-sm table-bordered">
- <colgroup>
- <col style="width: 20%" />
- <col style="width: 20%" />
- <col style="width: 20%" />
- <col style="width: 20%" />
- <col style="width: 20%" />
- </colgroup>
- <thead>
- <tr>
- <th><?=htmlspecialchars($title)?></th>
- <th>Tests</th>
- <th>Passes</th>
- <th>Fails</th>
- <th>Rate</th>
- </tr>
- </thead>
- <tbody>
- <?php
- foreach($totals as $data) {
- $total_test_count += $data["testCount"];
- $total_pass_count += $data["passCount"];
- $total_fail_count += $data["failCount"];
- $rate = ($data["testCount"] === 0) ? "0.00" : number_format(($data["passCount"] * 100) / $data["testCount"], 2);
- ?>
- <tr>
- <td><?=htmlspecialchars($data["name"])?></td>
- <td class="text-right"><?=number_format($data["testCount"])?></td>
- <td class="text-right"><?=number_format($data["passCount"])?></td>
- <td class="text-right"><?=number_format($data["failCount"])?></td>
- <td class="text-right"><?=$rate?>%</td>
- </tr>
- <?php
- }
- $total_rate = ($total_test_count === 0) ? "0.00" : number_format(($total_pass_count * 100) / $total_test_count, 2);
- ?>
- </tbody>
- <tfoot>
- <tr class="table-active">
- <th>
- Total
- </th>
- <th class="text-right">
- <?=number_format($total_test_count)?>
- </th>
- <th class="text-right">
- <?=number_format($total_pass_count)?>
- </th>
- <th class="text-right">
- <?=number_format($total_fail_count)?>
- </th>
- <th class="text-right"><?=$total_rate?>%</th>
- </tr>
- </tfoot>
- </table>
- <?php
- foreach($table->data as $entity_name => $rows) {
- ?>
- <h4><?=htmlspecialchars($entity_type)?>: <?=htmlspecialchars($entity_name)?></h4>
- <table class="table table-sm table-bordered">
- <colgroup>
- <col style="width: 20%" />
- <col style="width: 20%" />
- <col style="width: 20%" />
- <col style="width: 20%" />
- <col style="width: 20%" />
- </colgroup>
- <thead>
- <tr>
- <th>Period</th>
- <th>Tests</th>
- <th>Passes</th>
- <th>Fails</th>
- <th>Rate</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $index = 0;
- foreach($rows as $key => $data) {
- $rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
- $label = $key_labels[$index];
- ?>
- <tr>
- <td><?=htmlspecialchars($label)?></td>
- <td class="text-right"><?=number_format($data->testCount)?></td>
- <td class="text-right"><?=number_format($data->passCount)?></td>
- <td class="text-right"><?=number_format($data->failCount)?></td>
- <td class="text-right"><?=$rate?>%</td>
- </tr>
- <?php
- $index++;
- }
- ?>
- </tbody>
- </table>
- <?php
- }
- }
- ?>
- </div>
- <?php
- }
- }
- ?>
- </div>
|