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 : [];
|
||||
|
||||
// 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
|
||||
$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);
|
||||
}
|
||||
};
|
||||
|
||||
$SQL = "select count(*) as count
|
||||
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
|
||||
$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 r.permit_project_type = :permit_project_type
|
||||
and r.permit_county in
|
||||
(select county_serial
|
||||
from view_counties
|
||||
where county_area = :permit_area)";
|
||||
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);
|
||||
|
||||
@@ -204,8 +204,6 @@ $(document).ready(function () {
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
// ====================
|
||||
// Autocomplete Searches
|
||||
// ====================
|
||||
@@ -529,6 +527,23 @@ $(document).ready(function () {
|
||||
|
||||
});
|
||||
|
||||
// // ------------------------
|
||||
// // Export All Permits - PDF
|
||||
// // ------------------------
|
||||
//
|
||||
// $(".btnExportAllPDF").on("click", function (e) {
|
||||
//
|
||||
// e.preventDefault();
|
||||
//
|
||||
// window.open("", "PrintTab");
|
||||
//
|
||||
// $("input[name = 'action']", "#PrintAllPermitsBySubdivisionPDFForm").val("print");
|
||||
// $("input[name = 'subscription_serial']", "#PrintAllPermitsBySubdivisionPDFForm").val($sessionStorage.subscription_serial);
|
||||
// $("input[name = 'subscription_serial']", "#PrintAllPermitsBySubdivisionPDFForm").val($sessionStorage.subscription_serial);
|
||||
// $("#PrintAllPermitsBySubdivisionPDFForm").submit();
|
||||
//
|
||||
// });
|
||||
|
||||
// ------------------------
|
||||
// Export All Permits - PDF
|
||||
// ------------------------
|
||||
@@ -537,13 +552,54 @@ $(document).ready(function () {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
window.open("", "PrintTab");
|
||||
const $printForm = $("#PrintAllPermitsBySubdivisionPDFForm");
|
||||
const $searchForm = $("#searchPermitsBySubdivision");
|
||||
|
||||
$("input[name = 'action']", "#PrintAllPermitsBySubdivisionPDFForm").val("print");
|
||||
$("input[name = 'subscription_serial']", "#PrintAllPermitsBySubdivisionPDFForm").val($sessionStorage.subscription_serial);
|
||||
$("#PrintAllPermitsBySubdivisionPDFForm").submit();
|
||||
// Remove fields added by a previous PDF export.
|
||||
$printForm.find(".print-search-field").remove();
|
||||
|
||||
// Copy populated search criteria into the PDF form.
|
||||
$searchForm.find(":input[name]").not(":button, :submit, :reset").not("[name='action']").not("[name='subscription_serial']").each(function () {
|
||||
|
||||
const $input = $(this);
|
||||
const fieldName = $input.attr("name");
|
||||
|
||||
// Ignore unchecked checkboxes and radio buttons.
|
||||
if (($input.is(":checkbox") || $input.is(":radio")) && !$input.is(":checked")) {
|
||||
return;
|
||||
}
|
||||
|
||||
let values = $input.val();
|
||||
|
||||
if (values === null || values === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Supports multiple-select inputs.
|
||||
if (!Array.isArray(values)) {
|
||||
values = [values];
|
||||
}
|
||||
|
||||
$.each(values, function (_, value) {
|
||||
|
||||
value = String(value).trim();
|
||||
|
||||
if (value === "") {
|
||||
return;
|
||||
}
|
||||
|
||||
$("<input>", {type: "hidden", name: fieldName, value: value, class: "print-search-field"}).appendTo($printForm);
|
||||
});
|
||||
});
|
||||
|
||||
$printForm.find("[name='action']").val("print");
|
||||
$printForm.find("[name='subscription_serial']").val($sessionStorage.subscription_serial);
|
||||
|
||||
window.open("", "PrintTab");
|
||||
$printForm.trigger("submit");
|
||||
});
|
||||
|
||||
|
||||
|
||||
// --------------------------
|
||||
// Export All Permits - Excel
|
||||
|
||||
@@ -47,17 +47,17 @@ class Export_AllPermitsBySubdivision_CSV extends Base {
|
||||
|
||||
foreach ($permits as $permit) {
|
||||
|
||||
$county_name = $permit->rdi_county_name_verbose;
|
||||
$subdivision = $permit->rdi_sub_div_name;
|
||||
$address = "{$permit->rdi_address} {$permit->rdi_city} {$permit->rdi_state} {$permit->rdi_zip}";
|
||||
$city = $permit->rdi_city;
|
||||
$builder = $permit->rdi_company;
|
||||
$permit_date = $permit->rdi_permit_date_verbose;
|
||||
$square_footage = $permit->rdi_size_verbose;
|
||||
$value = $permit->rdi_value_verbose;
|
||||
$county_name = $permit->county_name_verbose;
|
||||
$subdivision = $permit->permit_sub_div_name;
|
||||
$address = "{$permit->permit_address} {$permit->permit_city} {$permit->permit_state} {$permit->permit_zip}";
|
||||
$city = $permit->permit_city;
|
||||
$builder = $permit->permit_company;
|
||||
$permit_date = $permit->permit_permit_date_verbose;
|
||||
$square_footage = $permit->permit_size_verbose;
|
||||
$value = $permit->permit_value_verbose;
|
||||
|
||||
$permit_ytd_value = "$" . number_format((int) $permit->rdi_ytd_value, 2);
|
||||
$permit_value = "$" . number_format((int) $permit->rdi_value, 2);
|
||||
$permit_ytd_value = "$" . number_format((int) $permit->permit_ytd_value, 2);
|
||||
$permit_value = "$" . number_format((int) $permit->permit_value, 2);
|
||||
|
||||
$permit_data = array($county_name, $subdivision, $address, $city, $builder, $permit_date, $square_footage, $value);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class Export_AllPermitsBySubdivision_Excel extends Base {
|
||||
$permit_area = $subscription->record->subscription_area;
|
||||
$projecttype = $subscription->record->subscription_projecttype;
|
||||
|
||||
$permits = (new PermitsBySubdivision())->getAllPermitsBySubdivision($permit_area, $projecttype);
|
||||
$permits = (new PermitsBySubdivision())->getAllPermitsBySubdivision($permit_area, $projecttype, $_POST);
|
||||
|
||||
// Create the Spreadsheet.
|
||||
|
||||
@@ -89,16 +89,16 @@ class Export_AllPermitsBySubdivision_Excel extends Base {
|
||||
|
||||
foreach ($permits as $permit) {
|
||||
|
||||
$address = "{$permit->rdi_address} {$permit->rdi_city}, {$permit->rdi_state} {$permit->rdi_zip}";
|
||||
$address = "{$permit->permit_address} {$permit->permit_city}, {$permit->permit_state} {$permit->permit_zip}";
|
||||
|
||||
$spreadsheet->getActiveSheet()->setCellValue("A" . $row, (string) $permit->rdi_county_name_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("B" . $row, (string) $permit->rdi_sub_div_name);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("A" . $row, (string) $permit->county_name_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("B" . $row, (string) $permit->permit_sub_div_name);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("C" . $row, (string) $address);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("D" . $row, (string) $permit->rdi_city);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("E" . $row, (string) $permit->rdi_company);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("F" . $row, (string) $permit->rdi_permit_date_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("G" . $row, (string) $permit->rdi_size_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("H" . $row, (string) $permit->rdi_value_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("D" . $row, (string) $permit->permit_city);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("E" . $row, (string) $permit->permit_company);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("F" . $row, (string) $permit->permit_permit_date_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("G" . $row, (string) $permit->permit_size_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("H" . $row, (string) $permit->permit_value_verbose);
|
||||
|
||||
$row++;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ class AllPermitsBySubdivision_Print extends TCPDF {
|
||||
|
||||
// Get the data for the report
|
||||
|
||||
$permits = (new PermitsBySubdivision())->getAllPermitsBySubdivision($permit_area, $projecttype);
|
||||
$permits = (new PermitsBySubdivision())->getAllPermitsBySubdivision($permit_area, $projecttype, $_POST);
|
||||
|
||||
// -------
|
||||
// Permits
|
||||
@@ -141,16 +141,16 @@ class AllPermitsBySubdivision_Print extends TCPDF {
|
||||
$this->stripeLine($rowCount, 268);
|
||||
$rowCount++;
|
||||
|
||||
$address = "{$permit->rdi_address} {$permit->rdi_city}, {$permit->rdi_state} {$permit->rdi_zip}";
|
||||
$address = "{$permit->permit_address} {$permit->permit_city}, {$permit->permit_state} {$permit->permit_zip}";
|
||||
|
||||
$permit_value = "$" . number_format((int) $permit->rdi_value, 2);
|
||||
$permit_value = "$" . number_format((int) $permit->permit_value, 2);
|
||||
|
||||
$this->Cell(15, 0, $permit->rdi_county_name_verbose, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(40, 0, $permit->rdi_sub_div_name, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(15, 0, $permit->county_name_verbose, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(40, 0, $permit->permit_sub_div_name, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(85, 0, $address, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(60, 0, $permit->rdi_company, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(20, 0, $permit->rdi_permit_date_verbose, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(15, 0, $permit->rdi_size, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(60, 0, $permit->permit_company, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(20, 0, $permit->permit_permit_date_verbose, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(15, 0, $permit->permit_size_verbose, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(20, 0, $permit_value, 0, 0, "L", false, "", 3);
|
||||
|
||||
$this->Ln(4);
|
||||
|
||||
@@ -24,11 +24,15 @@ $SQL = "create view view_permits as
|
||||
trends.permits_trend,
|
||||
|
||||
trends.prev_ytd_value as previous_ytd_value,
|
||||
trends.ytd_value
|
||||
trends.ytd_value,
|
||||
|
||||
counties.county_name as county_name_verbose
|
||||
|
||||
from permits
|
||||
|
||||
join view_company_permit_trends as trends
|
||||
on permits.permit_company = trends.permit_company";
|
||||
on permits.permit_company = trends.permit_company
|
||||
|
||||
join counties
|
||||
on permits.permit_county = counties.county_serial";
|
||||
?>
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
<div class="col-lg-4 mb-3">
|
||||
<label class="form-label" for="permit_county">County</label>
|
||||
<select class="form-control form-control-sm multiple-dropdown" multiple="multiple" name="permit_county" id="permit_county" size="1">
|
||||
<select class="form-control form-control-sm multiple-dropdown" multiple="multiple" name="permit_county[]" id="permit_county" size="1">
|
||||
<xsl:apply-templates select="//counties"/>
|
||||
</select>
|
||||
</div>
|
||||
@@ -364,7 +364,7 @@
|
||||
|
||||
<input type="hidden" name="action" value="print"/>
|
||||
<input type="hidden" name="report" value="Print_All_PermitsBySubdivision"/>
|
||||
<input type="hidden" name="subscription_serial" value="{{//subscriptions/record/subscription_serial}}"/>
|
||||
<input type="hidden" name="subscription_serial" value="{//subscriptions/record/subscription_serial}"/>
|
||||
|
||||
</form>
|
||||
|
||||
@@ -375,7 +375,7 @@
|
||||
<input type="hidden" name="action" value="print"/>
|
||||
<input type="hidden" name="report" value="Print_Selected_PermitsBySubdivision"/>
|
||||
<input type="hidden" name="selected_permits" value=""/>
|
||||
<input type="hidden" name="subscription_serial" value="{{//subscriptions/record/subscription_serial}}"/>
|
||||
<input type="hidden" name="subscription_serial" value="{//subscriptions/record/subscription_serial}"/>
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user