Fixed Subdivision Exports
This commit is contained in:
+1
-1
@@ -128,7 +128,7 @@ class Base {
|
||||
$host = 'localhost';
|
||||
} else {
|
||||
$host = '192.168.1.190';
|
||||
$host = '100.67.215.67';
|
||||
// $host = '100.67.215.67';
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -340,9 +340,6 @@ class PermitsBySubdivision extends Base {
|
||||
$statement->bindValue(":limit", $this->pagination_size, PDO::PARAM_INT);
|
||||
$statement->bindValue(":offset", $offset, PDO::PARAM_INT);
|
||||
|
||||
// echo $projecttype;
|
||||
// die();
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$permits = $this->getTableXML("permits", $statement);
|
||||
@@ -368,44 +365,118 @@ class PermitsBySubdivision extends Base {
|
||||
// Fetch All Permits for Exports
|
||||
// =============================
|
||||
|
||||
public function getAllPermitsBySubDivision($permit_area, $projecttype) {
|
||||
public function getAllPermitsBySubdivision($permit_area, $projecttype, $searchcriteria = array()) {
|
||||
|
||||
$connection = $this->connect();
|
||||
$searchcriteria = is_array($searchcriteria) ? $searchcriteria : [];
|
||||
|
||||
$conditions = ["r.permit_project_type = :permit_project_type"];
|
||||
$parameters = [":permit_project_type" => [$projecttype, PDO::PARAM_STR]];
|
||||
|
||||
// County can be posted as [6, 7] or as a comma-separated string
|
||||
$countyValues = $searchcriteria["permit_county"] ?? [];
|
||||
if (!is_array($countyValues)) {
|
||||
$countyValues = explode(",", (string) $countyValues);
|
||||
}
|
||||
|
||||
$countyIds = [];
|
||||
foreach ($countyValues as $countyValue) {
|
||||
$countyValue = trim((string) $countyValue);
|
||||
if ($countyValue !== "" && ctype_digit($countyValue)) {
|
||||
$countyIds[] = (int) $countyValue;
|
||||
}
|
||||
}
|
||||
$countyIds = array_values(array_unique($countyIds));
|
||||
|
||||
if ($permit_area != "All") {
|
||||
$conditions[] = "r.permit_county in (
|
||||
select county_serial
|
||||
from view_counties
|
||||
where county_area = :permit_area )";
|
||||
$parameters[":permit_area"] = [$permit_area, PDO::PARAM_STR];
|
||||
}
|
||||
|
||||
if ($countyIds) {
|
||||
$countyPlaceholders = [];
|
||||
foreach ($countyIds as $index => $countyId) {
|
||||
$placeholder = ":permit_county_{$index}";
|
||||
$countyPlaceholders[] = $placeholder;
|
||||
$parameters[$placeholder] = [$countyId, PDO::PARAM_INT];
|
||||
}
|
||||
$conditions[] = "r.permit_county in (" . implode(", ", $countyPlaceholders) . ")";
|
||||
}
|
||||
|
||||
$textFilters = [
|
||||
"permit_company" => "permit_company",
|
||||
"permit_sub_div_name" => "permit_sub_div_name",
|
||||
"permit_project_city" => "permit_project_city",
|
||||
"permit_project_addr" => "permit_project_addr"
|
||||
];
|
||||
|
||||
foreach ($textFilters as $criteriaKey => $column) {
|
||||
$value = trim((string) ($searchcriteria[$criteriaKey] ?? ""));
|
||||
if ($value !== "") {
|
||||
$placeholder = ":{$criteriaKey}";
|
||||
$conditions[] = "r.{$column} like {$placeholder}";
|
||||
$parameters[$placeholder] = ["%{$value}%", PDO::PARAM_STR];
|
||||
}
|
||||
}
|
||||
|
||||
$normalizeDate = static function ($value) {
|
||||
$value = trim((string) $value);
|
||||
if ($value === "") {
|
||||
return null;
|
||||
}
|
||||
$timestamp = strtotime($value);
|
||||
return $timestamp === false ? null : date("Y-m-d", $timestamp);
|
||||
};
|
||||
|
||||
$dateRanges = [
|
||||
["permit_entry_date", "permit_entry_start_date", "permit_entry_end_date"],
|
||||
["permit_permit_date", "permit_permit_start_date", "permit_permit_end_date"]
|
||||
];
|
||||
|
||||
foreach ($dateRanges as [$column, $startKey, $endKey]) {
|
||||
$startDate = $normalizeDate($searchcriteria[$startKey] ?? "");
|
||||
$endDate = $normalizeDate($searchcriteria[$endKey] ?? "");
|
||||
|
||||
if ($startDate !== null) {
|
||||
$conditions[] = "r.{$column} >= :{$startKey}";
|
||||
$parameters[":{$startKey}"] = [$startDate, PDO::PARAM_STR];
|
||||
}
|
||||
if ($endDate !== null) {
|
||||
$conditions[] = "r.{$column} <= :{$endKey}";
|
||||
$parameters[":{$endKey}"] = [$endDate, PDO::PARAM_STR];
|
||||
}
|
||||
}
|
||||
|
||||
$where = implode(" and ", $conditions);
|
||||
|
||||
$bindParameters = static function ($statement) use ($parameters) {
|
||||
foreach ($parameters as $placeholder => [$value, $type]) {
|
||||
$statement->bindValue($placeholder, $value, $type);
|
||||
}
|
||||
};
|
||||
|
||||
// Count Query
|
||||
$SQL = "select count(*) as count
|
||||
from view_permits r
|
||||
join counties c on r.permit_county = c.county_serial
|
||||
where r.permit_project_type = :permit_project_type
|
||||
and r.permit_county in
|
||||
(select county_serial
|
||||
from view_counties
|
||||
where county_area = :permit_area)";
|
||||
from view_permits r
|
||||
where {$where}";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":permit_project_type", $projecttype, PDO::PARAM_STR);
|
||||
$statement->bindValue(":permit_area", $permit_area, PDO::PARAM_STR);
|
||||
|
||||
$bindParameters($statement);
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
$count = $recordset ? (int) $recordset["count"] : 0;
|
||||
|
||||
// === DATA QUERY ===
|
||||
$SQL = "select r.*, c.county_name as permit_county_name_verbose
|
||||
from view_permits r
|
||||
join counties c on r.permit_county = c.county_serial
|
||||
where r.permit_project_type = :permit_project_type
|
||||
and r.permit_county in
|
||||
(select county_serial
|
||||
from view_counties
|
||||
where county_area = :permit_area)";
|
||||
$SQL = "select r.*, c.county_name as county_name_verbose
|
||||
from view_permits r
|
||||
join counties c on r.permit_county = c.county_serial
|
||||
where {$where}
|
||||
order by r.permit_sub_div_name, r.permit_project_addr";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":permit_project_type", $projecttype, PDO::PARAM_STR);
|
||||
$statement->bindValue(":permit_area", $permit_area, PDO::PARAM_STR);
|
||||
|
||||
$bindParameters($statement);
|
||||
$statement->execute();
|
||||
|
||||
$permits = $this->getTableXML("permits", $statement);
|
||||
|
||||
Reference in New Issue
Block a user