|
|
@@ -19,7 +19,9 @@ $page_title = "$customer->name Reports";
|
|
|
Core::addBreadcrumb("/account/reports?customer_id=$customer->id", $page_title);
|
|
|
|
|
|
$date_range = http::value("date_range");
|
|
|
-if(!$date_range) $date_range = "ytd";
|
|
|
+if(!$date_range) {
|
|
|
+ $date_range = "ytd";
|
|
|
+}
|
|
|
|
|
|
$date_resolution = http::value("date_resolution");
|
|
|
|
|
|
@@ -27,7 +29,9 @@ $date_start = http::value("date_start");
|
|
|
$date_end = http::value("date_end");
|
|
|
|
|
|
$exclude_project_ids = http::value("exclude_project_ids", "int");
|
|
|
-if(!is_array($exclude_project_ids)) $exclude_project_ids = [];
|
|
|
+if(!is_array($exclude_project_ids)) {
|
|
|
+ $exclude_project_ids = [];
|
|
|
+}
|
|
|
|
|
|
$location_ids = http::value("location_ids");
|
|
|
if(!empty($location_ids)) {
|
|
|
@@ -38,6 +42,15 @@ if(!empty($location_ids)) {
|
|
|
|
|
|
$retests = http::value("retests", "int");
|
|
|
|
|
|
+$location_filters = [
|
|
|
+ ["field" => "region", "values" => http::value("regions", "trim")],
|
|
|
+ ["field" => "area_manager", "values" => http::value("area_managers", "trim")],
|
|
|
+ ["field" => "operations_manager_name", "values" => http::value("operations_managers", "trim")],
|
|
|
+ ["field" => "gaming_manager_name", "values" => http::value("gaming_managers", "trim")],
|
|
|
+ ["field" => "senior_gaming_manager_name", "values" => http::value("senior_gaming_managers", "trim")],
|
|
|
+ ["field" => "brand", "values" => http::value("brands", "trim")],
|
|
|
+];
|
|
|
+
|
|
|
if(!is_array($location_ids)) {
|
|
|
$location_ids = [];
|
|
|
}
|
|
|
@@ -87,21 +100,27 @@ if($submit) {
|
|
|
// Get all projects
|
|
|
$projects = Project::query([
|
|
|
"customer_id" => $customer->id,
|
|
|
- "id" => (new Constraint("NOT_IN"))->setValues(...$exclude_project_ids)
|
|
|
+ "id" => Constraint::notIn($exclude_project_ids)
|
|
|
]);
|
|
|
|
|
|
$project_ids = array_intersect($all_project_ids, array_column($projects, "id"));
|
|
|
|
|
|
// Enforce unique template ID in selection
|
|
|
$template_ids = array_unique(array_column($projects, "template_id"));
|
|
|
- if(count($template_ids) > 1) $form_exception->addError("Projects with different templates have been selected.");
|
|
|
+ if(count($template_ids) > 1) {
|
|
|
+ $form_exception->addError("Projects with different templates have been selected.");
|
|
|
+ }
|
|
|
|
|
|
// Check template exists
|
|
|
$template_id = array_shift($template_ids);
|
|
|
$template = Template::get($template_id);
|
|
|
- if(!$template) $form_exception->addError("Template cannot be found.");
|
|
|
+ if(!$template) {
|
|
|
+ $form_exception->addError("Template cannot be found.");
|
|
|
+ }
|
|
|
|
|
|
- if($form_exception->hasErrors()) throw $form_exception;
|
|
|
+ if($form_exception->hasErrors()) {
|
|
|
+ throw $form_exception;
|
|
|
+ }
|
|
|
|
|
|
// Get all completed tests
|
|
|
$test_nvp = [
|
|
|
@@ -182,6 +201,24 @@ if($submit) {
|
|
|
|
|
|
$tests = $test_result_set->filterByDateRange($min_dts, $max_dts);
|
|
|
|
|
|
+ // Load locations
|
|
|
+ $locations = Location::load(array_column($tests, "location_id"));
|
|
|
+
|
|
|
+ // Filter by location fields
|
|
|
+ $tests = array_filter($tests, static function(Test $test) use ($location_filters) {
|
|
|
+ $location = $test->getLocation();
|
|
|
+ foreach($location_filters as $filter) {
|
|
|
+ $field = $filter["field"];
|
|
|
+ $values = $filter["values"];
|
|
|
+
|
|
|
+ if($values && !in_array($location->$field, $values)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
// Get test values
|
|
|
$test_ids = array_column($tests, "id");
|
|
|
$test_values = TestValue::query([
|
|
|
@@ -203,9 +240,6 @@ if($submit) {
|
|
|
// Load users
|
|
|
User::load(array_column($tests, "tester_id"));
|
|
|
|
|
|
- // Load locations
|
|
|
- $locations = Location::load(array_column($tests, "location_id"));
|
|
|
-
|
|
|
// Get region and area manager IDs
|
|
|
$regions = array_filter(array_column($locations, "region"));
|
|
|
$area_managers = array_filter(array_column($locations, "area_manager"));
|