|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
use Exports\LocationCsvExport;
|
|
use Exports\LocationCsvExport;
|
|
|
use Exports\LocationKmlExport;
|
|
use Exports\LocationKmlExport;
|
|
|
|
|
+use Searches\LocationSearch;
|
|
|
|
|
|
|
|
Core::addScript("public/js/app-locations.js");
|
|
Core::addScript("public/js/app-locations.js");
|
|
|
|
|
|
|
@@ -9,7 +10,9 @@ Core::addBreadcrumb("/account", "Account");
|
|
|
Core::addBreadcrumb("/account/locations", "Locations");
|
|
Core::addBreadcrumb("/account/locations", "Locations");
|
|
|
|
|
|
|
|
$customer = Customer::getForAdmin();
|
|
$customer = Customer::getForAdmin();
|
|
|
-if(!$customer) throw new Exception("You do not have permission to access this page.");
|
|
|
|
|
|
|
+if(!$customer) {
|
|
|
|
|
+ throw new Exception("You do not have permission to access this page.");
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
$customer_slug = Util::slug($customer->name);
|
|
$customer_slug = Util::slug($customer->name);
|
|
|
|
|
|
|
@@ -31,59 +34,64 @@ $nvp = [
|
|
|
"closed" => 0,
|
|
"closed" => 0,
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
|
|
+$search = new LocationSearch($customer);
|
|
|
|
|
+
|
|
|
$id = http::value("id", "int");
|
|
$id = http::value("id", "int");
|
|
|
|
|
+$search->setId($id);
|
|
|
|
|
+
|
|
|
$ids = http::value("ids", "int");
|
|
$ids = http::value("ids", "int");
|
|
|
|
|
+$search->setIds($ids);
|
|
|
|
|
+
|
|
|
$internal_id = http::value("internal_id", "trim");
|
|
$internal_id = http::value("internal_id", "trim");
|
|
|
|
|
+$search->setInternalId($internal_id);
|
|
|
|
|
+
|
|
|
$name = http::value("name", "trim");
|
|
$name = http::value("name", "trim");
|
|
|
|
|
+$search->setName($name);
|
|
|
|
|
+
|
|
|
$legal_entity_name = http::value("legal_entity_name", "trim");
|
|
$legal_entity_name = http::value("legal_entity_name", "trim");
|
|
|
|
|
+$search->setLegalEntityName($legal_entity_name);
|
|
|
|
|
|
|
|
$min_date = http::value("min_date");
|
|
$min_date = http::value("min_date");
|
|
|
|
|
+$search->setMinTestDate($min_date);
|
|
|
|
|
+
|
|
|
$max_date = http::value("max_date");
|
|
$max_date = http::value("max_date");
|
|
|
|
|
+$search->setMaxTestDate($max_date);
|
|
|
|
|
|
|
|
$include_archived = (int) http::value("include_archived");
|
|
$include_archived = (int) http::value("include_archived");
|
|
|
|
|
+$search->setIncludeArchived($include_archived);
|
|
|
|
|
+
|
|
|
$include_closed = (int) http::value("include_closed");
|
|
$include_closed = (int) http::value("include_closed");
|
|
|
|
|
+$search->setIncludeClosed($include_closed);
|
|
|
|
|
+
|
|
|
$hide_tested = (int) http::value("hide_tested");
|
|
$hide_tested = (int) http::value("hide_tested");
|
|
|
|
|
+$search->setIncludeTested(!$hide_tested);
|
|
|
|
|
|
|
|
$filter_count = 0;
|
|
$filter_count = 0;
|
|
|
|
|
|
|
|
$where_strings = [];
|
|
$where_strings = [];
|
|
|
|
|
|
|
|
if($id) {
|
|
if($id) {
|
|
|
- $where_strings[] = "`location`.`id`='$id'";
|
|
|
|
|
$filter_count++;
|
|
$filter_count++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-if($ids) {
|
|
|
|
|
- $where_strings[] = sprintf("`location`.`id` IN (%s)", implode(",", $ids));
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
if($internal_id) {
|
|
if($internal_id) {
|
|
|
- $where_strings[] = sprintf("`location`.`internal_id` LIKE '%%%s%%'", DB::escape($internal_id));
|
|
|
|
|
$filter_count++;
|
|
$filter_count++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if($name) {
|
|
if($name) {
|
|
|
- $where_strings[] = sprintf("`location`.`name` LIKE '%%%s%%'", DB::escape($name));
|
|
|
|
|
$filter_count++;
|
|
$filter_count++;
|
|
|
}
|
|
}
|
|
|
if($legal_entity_name) {
|
|
if($legal_entity_name) {
|
|
|
- $where_strings[] = sprintf("`location`.`legal_entity_name` LIKE '%%%s%%'", DB::escape($legal_entity_name));
|
|
|
|
|
$filter_count++;
|
|
$filter_count++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if($include_archived) {
|
|
if($include_archived) {
|
|
|
$filter_count++;
|
|
$filter_count++;
|
|
|
}
|
|
}
|
|
|
-else {
|
|
|
|
|
- $where_strings[] = "`location`.`archived`='0'";
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
if($include_closed) {
|
|
if($include_closed) {
|
|
|
$filter_count++;
|
|
$filter_count++;
|
|
|
}
|
|
}
|
|
|
-else {
|
|
|
|
|
- $where_strings[] = "`location`.`closed`='0'";
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
if($min_date) {
|
|
if($min_date) {
|
|
|
$filter_count++;
|
|
$filter_count++;
|
|
@@ -120,17 +128,18 @@ switch($sort) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-$where_string = "";
|
|
|
|
|
-if($where_strings) {
|
|
|
|
|
- $where_string = "AND " . implode(" AND ", $where_strings);
|
|
|
|
|
-}
|
|
|
|
|
|
|
+
|
|
|
|
|
+$locations = $search->run();
|
|
|
|
|
+
|
|
|
|
|
+$location_ids = array_column($locations, "id") ?: [0];
|
|
|
|
|
+$location_ids_csv = implode(", ", $location_ids);
|
|
|
|
|
|
|
|
[$date_start, $date_end] = $customer->getYearCycleDates();
|
|
[$date_start, $date_end] = $customer->getYearCycleDates();
|
|
|
|
|
|
|
|
$sql = "SELECT `location`.*, COUNT(`test`.`id`) AS `test_count`, SUM(IF(`test`.`retest` = 1, 1, 0)) AS `retest_count`
|
|
$sql = "SELECT `location`.*, COUNT(`test`.`id`) AS `test_count`, SUM(IF(`test`.`retest` = 1, 1, 0)) AS `retest_count`
|
|
|
FROM `location`
|
|
FROM `location`
|
|
|
LEFT JOIN `test` ON `test`.`location_id`=`location`.`id` AND `dts_start` BETWEEN '$date_start' AND '$date_end'
|
|
LEFT JOIN `test` ON `test`.`location_id`=`location`.`id` AND `dts_start` BETWEEN '$date_start' AND '$date_end'
|
|
|
- WHERE `customer_id`='$customer->id' $where_string GROUP BY `location`.`id`
|
|
|
|
|
|
|
+ WHERE `customer_id`='$customer->id' AND `location`.`id` IN ($location_ids_csv) GROUP BY `location`.`id`
|
|
|
ORDER BY $query_sort $order
|
|
ORDER BY $query_sort $order
|
|
|
";
|
|
";
|
|
|
|
|
|