Compare commits

...

6 Commits

9 changed files with 224 additions and 88 deletions
+1 -1
View File
@@ -128,7 +128,7 @@ class Base {
$host = 'localhost'; $host = 'localhost';
} else { } else {
$host = '192.168.1.190'; $host = '192.168.1.190';
$host = '100.67.215.67'; // $host = '100.67.215.67';
} }
try { try {
+1 -1
View File
@@ -102,7 +102,7 @@ class PermitsByBuilder extends Base {
// Ensure valid order by column // Ensure valid order by column
$allowed_order_columns = ["permit_permit_number", "permit_entry_date", "permit_permit_date", "permit_company", "permit_permit_count"]; $allowed_order_columns = ["permit_permit_number", "permit_entry_date", "permit_permit_date", "permit_company", "permit_permit_count"];
if (!in_array($permits_order_by, $allowed_order_columns)) { if (!in_array($permits_order_by, $allowed_order_columns)) {
$permits_order_by = "order by view_permits.permit_company"; $permits_order_by = " view_permits.permit_company";
} }
// Connect to DB // Connect to DB
+97 -26
View File
@@ -340,9 +340,6 @@ class PermitsBySubdivision extends Base {
$statement->bindValue(":limit", $this->pagination_size, PDO::PARAM_INT); $statement->bindValue(":limit", $this->pagination_size, PDO::PARAM_INT);
$statement->bindValue(":offset", $offset, PDO::PARAM_INT); $statement->bindValue(":offset", $offset, PDO::PARAM_INT);
// echo $projecttype;
// die();
$statement->execute(); $statement->execute();
$permits = $this->getTableXML("permits", $statement); $permits = $this->getTableXML("permits", $statement);
@@ -368,44 +365,118 @@ class PermitsBySubdivision extends Base {
// Fetch All Permits for Exports // Fetch All Permits for Exports
// ============================= // =============================
public function getAllPermitsBySubDivision($permit_area, $projecttype) { public function getAllPermitsBySubdivision($permit_area, $projecttype, $searchcriteria = array()) {
$connection = $this->connect(); $connection = $this->connect();
$searchcriteria = is_array($searchcriteria) ? $searchcriteria : [];
// Count Query $conditions = ["r.permit_project_type = :permit_project_type"];
$SQL = "select count(*) as count $parameters = [":permit_project_type" => [$projecttype, PDO::PARAM_STR]];
from view_permits r
join counties c on r.permit_county = c.county_serial // County can be posted as [6, 7] or as a comma-separated string
where r.permit_project_type = :permit_project_type $countyValues = $searchcriteria["permit_county"] ?? [];
and r.permit_county in if (!is_array($countyValues)) {
(select county_serial $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 from view_counties
where county_area = :permit_area )"; 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 = $connection->prepare($SQL);
$bindParameters($statement);
$statement->bindValue(":permit_project_type", $projecttype, PDO::PARAM_STR);
$statement->bindValue(":permit_area", $permit_area, PDO::PARAM_STR);
$statement->execute(); $statement->execute();
$recordset = $statement->fetch(PDO::FETCH_ASSOC); $recordset = $statement->fetch(PDO::FETCH_ASSOC);
$count = $recordset ? (int) $recordset["count"] : 0; $count = $recordset ? (int) $recordset["count"] : 0;
// === DATA QUERY === $SQL = "select r.*, c.county_name as county_name_verbose
$SQL = "select r.*, c.county_name as permit_county_name_verbose
from view_permits r from view_permits r
join counties c on r.permit_county = c.county_serial join counties c on r.permit_county = c.county_serial
where r.permit_project_type = :permit_project_type where {$where}
and r.permit_county in order by c.county_name, r.permit_sub_div_name";
(select county_serial
from view_counties
where county_area = :permit_area)";
$statement = $connection->prepare($SQL); $statement = $connection->prepare($SQL);
$bindParameters($statement);
$statement->bindValue(":permit_project_type", $projecttype, PDO::PARAM_STR);
$statement->bindValue(":permit_area", $permit_area, PDO::PARAM_STR);
$statement->execute(); $statement->execute();
$permits = $this->getTableXML("permits", $statement); $permits = $this->getTableXML("permits", $statement);
+62 -6
View File
@@ -204,8 +204,6 @@ $(document).ready(function () {
}); });
// ==================== // ====================
// Autocomplete Searches // 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 // Export All Permits - PDF
// ------------------------ // ------------------------
@@ -537,13 +552,54 @@ $(document).ready(function () {
e.preventDefault(); e.preventDefault();
window.open("", "PrintTab"); const $printForm = $("#PrintAllPermitsBySubdivisionPDFForm");
const $searchForm = $("#searchPermitsBySubdivision");
$("input[name = 'action']", "#PrintAllPermitsBySubdivisionPDFForm").val("print"); // Remove fields added by a previous PDF export.
$("input[name = 'subscription_serial']", "#PrintAllPermitsBySubdivisionPDFForm").val($sessionStorage.subscription_serial); $printForm.find(".print-search-field").remove();
$("#PrintAllPermitsBySubdivisionPDFForm").submit();
// 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 // Export All Permits - Excel
+11 -11
View File
@@ -32,7 +32,7 @@ class Export_AllPermitsBySubdivision_CSV extends Base {
$permit_area = $subscription->record->subscription_area; $permit_area = $subscription->record->subscription_area;
$projecttype = $subscription->record->subscription_projecttype; $projecttype = $subscription->record->subscription_projecttype;
$permits = (new PermitsBySubdivision())->getAllPermitsBySubdivision($permit_area, $projecttype); $permits = (new PermitsBySubdivision())->getAllPermitsBySubdivision($permit_area, $projecttype, $_POST);
header('Content-Type: text/csv'); header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="All_PermitsBySubdivision.csv"'); header('Content-Disposition: attachment; filename="All_PermitsBySubdivision.csv"');
@@ -47,17 +47,17 @@ class Export_AllPermitsBySubdivision_CSV extends Base {
foreach ($permits as $permit) { foreach ($permits as $permit) {
$county_name = $permit->rdi_county_name_verbose; $county_name = $permit->county_name_verbose;
$subdivision = $permit->rdi_sub_div_name; $subdivision = $permit->permit_sub_div_name;
$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}";
$city = $permit->rdi_city; $city = $permit->permit_city;
$builder = $permit->rdi_company; $builder = $permit->permit_company;
$permit_date = $permit->rdi_permit_date_verbose; $permit_date = $permit->permit_permit_date_verbose;
$square_footage = $permit->rdi_size_verbose; $square_footage = $permit->permit_size_verbose;
$value = $permit->rdi_value_verbose; $value = $permit->permit_value_verbose;
$permit_ytd_value = "$" . number_format((int) $permit->rdi_ytd_value, 2); $permit_ytd_value = "$" . number_format((int) $permit->permit_ytd_value, 2);
$permit_value = "$" . number_format((int) $permit->rdi_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); $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; $permit_area = $subscription->record->subscription_area;
$projecttype = $subscription->record->subscription_projecttype; $projecttype = $subscription->record->subscription_projecttype;
$permits = (new PermitsBySubdivision())->getAllPermitsBySubdivision($permit_area, $projecttype); $permits = (new PermitsBySubdivision())->getAllPermitsBySubdivision($permit_area, $projecttype, $_POST);
// Create the Spreadsheet. // Create the Spreadsheet.
@@ -89,16 +89,16 @@ class Export_AllPermitsBySubdivision_Excel extends Base {
foreach ($permits as $permit) { 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("A" . $row, (string) $permit->county_name_verbose);
$spreadsheet->getActiveSheet()->setCellValue("B" . $row, (string) $permit->rdi_sub_div_name); $spreadsheet->getActiveSheet()->setCellValue("B" . $row, (string) $permit->permit_sub_div_name);
$spreadsheet->getActiveSheet()->setCellValue("C" . $row, (string) $address); $spreadsheet->getActiveSheet()->setCellValue("C" . $row, (string) $address);
$spreadsheet->getActiveSheet()->setCellValue("D" . $row, (string) $permit->rdi_city); $spreadsheet->getActiveSheet()->setCellValue("D" . $row, (string) $permit->permit_city);
$spreadsheet->getActiveSheet()->setCellValue("E" . $row, (string) $permit->rdi_company); $spreadsheet->getActiveSheet()->setCellValue("E" . $row, (string) $permit->permit_company);
$spreadsheet->getActiveSheet()->setCellValue("F" . $row, (string) $permit->rdi_permit_date_verbose); $spreadsheet->getActiveSheet()->setCellValue("F" . $row, (string) $permit->permit_permit_date_verbose);
$spreadsheet->getActiveSheet()->setCellValue("G" . $row, (string) $permit->rdi_size_verbose); $spreadsheet->getActiveSheet()->setCellValue("G" . $row, (string) $permit->permit_size_verbose);
$spreadsheet->getActiveSheet()->setCellValue("H" . $row, (string) $permit->rdi_value_verbose); $spreadsheet->getActiveSheet()->setCellValue("H" . $row, (string) $permit->permit_value_verbose);
$row++; $row++;
} }
+13 -8
View File
@@ -57,6 +57,7 @@ class AllPermitsBySubdivision_Print extends TCPDF {
public $subscription_serial = 0; public $subscription_serial = 0;
public $first_page = true; public $first_page = true;
public $output_type = "normal"; public $output_type = "normal";
public $record_count = 0;
// ================ // ================
// Debug an Object. // Debug an Object.
@@ -99,7 +100,9 @@ class AllPermitsBySubdivision_Print extends TCPDF {
// Get the data for the report // Get the data for the report
$permits = (new PermitsBySubdivision())->getAllPermitsBySubdivision($permit_area, $projecttype); $permits = (new PermitsBySubdivision())->getAllPermitsBySubdivision($permit_area, $projecttype, $_POST);
$this->record_count = count($permits);
// ------- // -------
// Permits // Permits
@@ -141,16 +144,16 @@ class AllPermitsBySubdivision_Print extends TCPDF {
$this->stripeLine($rowCount, 268); $this->stripeLine($rowCount, 268);
$rowCount++; $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(15, 0, $permit->county_name_verbose, 0, 0, "L", false, "", 3);
$this->Cell(40, 0, $permit->rdi_sub_div_name, 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(85, 0, $address, 0, 0, "L", false, "", 3);
$this->Cell(60, 0, $permit->rdi_company, 0, 0, "L", false, "", 3); $this->Cell(60, 0, $permit->permit_company, 0, 0, "L", false, "", 3);
$this->Cell(20, 0, $permit->rdi_permit_date_verbose, 0, 0, "L", false, "", 3); $this->Cell(20, 0, $permit->permit_permit_date_verbose, 0, 0, "L", false, "", 3);
$this->Cell(15, 0, $permit->rdi_size, 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->Cell(20, 0, $permit_value, 0, 0, "L", false, "", 3);
$this->Ln(4); $this->Ln(4);
@@ -186,6 +189,8 @@ class AllPermitsBySubdivision_Print extends TCPDF {
} }
} }
} }
$this->Ln(6);
$this->Cell(0, 0, "Records Returned: " . $this->record_count, "", 0, "R", false, "", 3);
// -------------- // --------------
// Return the pdf // Return the pdf
+6 -2
View File
@@ -24,11 +24,15 @@ $SQL = "create view view_permits as
trends.permits_trend, trends.permits_trend,
trends.prev_ytd_value as previous_ytd_value, trends.prev_ytd_value as previous_ytd_value,
trends.ytd_value trends.ytd_value,
counties.county_name as county_name_verbose
from permits from permits
join view_company_permit_trends as trends 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";
?> ?>
+3 -3
View File
@@ -47,7 +47,7 @@
<div class="col-lg-4 mb-3"> <div class="col-lg-4 mb-3">
<label class="form-label" for="permit_county">County</label> <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"/> <xsl:apply-templates select="//counties"/>
</select> </select>
</div> </div>
@@ -364,7 +364,7 @@
<input type="hidden" name="action" value="print"/> <input type="hidden" name="action" value="print"/>
<input type="hidden" name="report" value="Print_All_PermitsBySubdivision"/> <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> </form>
@@ -375,7 +375,7 @@
<input type="hidden" name="action" value="print"/> <input type="hidden" name="action" value="print"/>
<input type="hidden" name="report" value="Print_Selected_PermitsBySubdivision"/> <input type="hidden" name="report" value="Print_Selected_PermitsBySubdivision"/>
<input type="hidden" name="selected_permits" value=""/> <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> </form>