|
@@ -41,38 +41,44 @@ $include_closed = (int) http::value("include_closed");
|
|
|
|
|
|
|
|
$filter_count = 0;
|
|
$filter_count = 0;
|
|
|
|
|
|
|
|
|
|
+$where_strings = [];
|
|
|
|
|
+
|
|
|
if($id) {
|
|
if($id) {
|
|
|
- $nvp["id"] = $id;
|
|
|
|
|
|
|
+ $where_strings[] = "`location`.`id`='$id'";
|
|
|
$filter_count++;
|
|
$filter_count++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if($ids) {
|
|
if($ids) {
|
|
|
- $nvp["id"] = $ids;
|
|
|
|
|
|
|
+ $where_strings[] = sprintf("`location`.`id` IN (%s)", implode(",", $ids));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if($internal_id) {
|
|
if($internal_id) {
|
|
|
- $nvp["internal_id"] = Constraint::contains($internal_id);
|
|
|
|
|
|
|
+ $where_strings[] = sprintf("`location`.`internal_id` LIKE '%%%s%%'", DB::escape($internal_id));
|
|
|
$filter_count++;
|
|
$filter_count++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if($name) {
|
|
if($name) {
|
|
|
- $nvp["name"] = Constraint::contains($name);
|
|
|
|
|
|
|
+ $where_strings[] = sprintf("`location`.`name` LIKE '%%%s%%'", DB::escape($name));
|
|
|
$filter_count++;
|
|
$filter_count++;
|
|
|
}
|
|
}
|
|
|
if($legal_entity_name) {
|
|
if($legal_entity_name) {
|
|
|
- $nvp["legal_entity_name"] = Constraint::contains($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) {
|
|
|
- unset($nvp["archived"]);
|
|
|
|
|
$filter_count++;
|
|
$filter_count++;
|
|
|
}
|
|
}
|
|
|
|
|
+else {
|
|
|
|
|
+ $where_strings[] = "`location`.`archived`='0'";
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
if($include_closed) {
|
|
if($include_closed) {
|
|
|
- unset($nvp["closed"]);
|
|
|
|
|
$filter_count++;
|
|
$filter_count++;
|
|
|
}
|
|
}
|
|
|
|
|
+else {
|
|
|
|
|
+ $where_strings[] = "`location`.`closed`='0'";
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
$sort = http::value("sort");
|
|
$sort = http::value("sort");
|
|
|
switch($sort) {
|
|
switch($sort) {
|
|
@@ -97,12 +103,18 @@ switch($sort) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+$where_string = "";
|
|
|
|
|
+if($where_strings) {
|
|
|
|
|
+ $where_string = "AND " . implode(" AND ", $where_strings);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
[$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' GROUP BY `location`.`id`
|
|
|
|
|
|
|
+ WHERE `customer_id`='$customer->id' $where_string GROUP BY `location`.`id`
|
|
|
ORDER BY $query_sort $order
|
|
ORDER BY $query_sort $order
|
|
|
";
|
|
";
|
|
|
|
|
|