Updated RDI Consolidation Function to use permits table

This commit is contained in:
James Richie
2026-04-04 19:34:51 -04:00
parent a24bcfbae7
commit da832f82fc
2 changed files with 101 additions and 230 deletions
+1 -1
View File
@@ -245,7 +245,7 @@ class Consolidation extends Base {
public function getRdiTable() { public function getRdiTable() {
$SQL = "SELECT * FROM rdis"; $SQL = "SELECT * FROM permits";
return $this->getTable("rdis", $SQL); return $this->getTable("rdis", $SQL);
} }
+100 -229
View File
@@ -142,125 +142,116 @@ class Import extends Base {
$County = (new Counties())->getCountiesByName($County)->record->county_serial; $County = (new Counties())->getCountiesByName($County)->record->county_serial;
$SQL = "INSERT INTO rdis ( $SQL = "INSERT INTO permits (
rdi_permit_facts_id, permit_permit_facts_id,
rdi_entry_date, permit_entry_date,
rdi_permit_number, permit_permit_number,
rdi_permit_date, permit_permit_date,
rdi_project_addr, permit_project_addr,
rdi_sub_div_name, permit_sub_div_name,
rdi_project_type, permit_project_type,
rdi_company, permit_company,
rdi_address, permit_address,
rdi_city, permit_city,
rdi_state, permit_state,
rdi_zip, permit_zip,
rdi_phone, permit_phone,
rdi_project_city, permit_project_city,
rdi_project_state, permit_project_state,
rdi_size, permit_size,
rdi_units, permit_units,
rdi_building_type, permit_building_type,
rdi_value, permit_value,
rdi_work_type, permit_work_type,
rdi_county, permit_county,
rdi_lot, permit_lot,
rdi_dist_ll, permit_dist_ll,
rdi_ct1, permit_ct1,
rdi_owner_name, permit_owner_name,
rdi_owner_address, permit_owner_address,
rdi_owner_city, permit_owner_city,
rdi_owner_state, permit_owner_state,
rdi_owner_zip, permit_owner_zip,
rdi_owner_phone, permit_owner_phone,
rdi_ytd_permits, permit_ytd_permits,
rdi_ytd_value, permit_ytd_value,
rdi_12mth_prev_permits ) permit_12mth_prev_permits )
VALUES ( VALUES (
:rdi_permit_facts_id, :permit_permit_facts_id,
:rdi_entry_date, :permit_entry_date,
:rdi_permit_number, :permit_permit_number,
:rdi_permit_date, :permit_permit_date,
:rdi_project_addr, :permit_project_addr,
:rdi_sub_div_name, :permit_sub_div_name,
:rdi_project_type, :permit_project_type,
:rdi_company, :permit_company,
:rdi_address, :permit_address,
:rdi_city, :permit_city,
:rdi_state, :permit_state,
:rdi_zip, :permit_zip,
:rdi_phone, :permit_phone,
:rdi_project_city, :permit_project_city,
:rdi_project_state, :permit_project_state,
:rdi_size, :permit_size,
:rdi_units, :permit_units,
:rdi_building_type, :permit_building_type,
:rdi_value, :permit_value,
:rdi_work_type, :permit_work_type,
:rdi_county, :permit_county,
:rdi_lot, :permit_lot,
:rdi_dist_ll, :permit_dist_ll,
:rdi_ct1, :permit_ct1,
:rdi_owner_name, :permit_owner_name,
:rdi_owner_address, :permit_owner_address,
:rdi_owner_city, :permit_owner_city,
:rdi_owner_state, :permit_owner_state,
:rdi_owner_zip, :permit_owner_zip,
:rdi_owner_phone, :permit_owner_phone,
:rdi_ytd_permits, :permit_ytd_permits,
:rdi_ytd_value, :permit_ytd_value,
:rdi_12mth_prev_permits )"; :permit_12mth_prev_permits )";
$statement = $connection->prepare($SQL); $statement = $connection->prepare($SQL);
$statement->bindValue(":rdi_permit_facts_id", $PermitFactsId); $statement->bindValue(":permit_permit_facts_id", $PermitFactsId);
$statement->bindValue(":rdi_permit_number", $PermitNumber); $statement->bindValue(":permit_permit_number", $PermitNumber);
$statement->bindValue(":rdi_entry_date", $EntryDate); $statement->bindValue(":permit_entry_date", $EntryDate);
$statement->bindValue(":rdi_permit_date", $PermitDate); $statement->bindValue(":permit_permit_date", $PermitDate);
$statement->bindValue(":rdi_project_addr", $ProjectAddress); $statement->bindValue(":permit_project_addr", $ProjectAddress);
$statement->bindValue(":rdi_sub_div_name", $SubdivisionName); $statement->bindValue(":permit_sub_div_name", $SubdivisionName);
$statement->bindValue(":rdi_project_type", $ProjectType); $statement->bindValue(":permit_project_type", $ProjectType);
$statement->bindValue(":rdi_company", $Company); $statement->bindValue(":permit_company", $Company);
$statement->bindValue(":rdi_address", $Address); $statement->bindValue(":permit_address", $Address);
$statement->bindValue(":rdi_city", $City); $statement->bindValue(":permit_city", $City);
$statement->bindValue(":rdi_state", $State); $statement->bindValue(":permit_state", $State);
$statement->bindValue(":rdi_zip", $Zip); $statement->bindValue(":permit_zip", $Zip);
$statement->bindValue(":rdi_phone", $Phone); $statement->bindValue(":permit_phone", $Phone);
$statement->bindValue(":rdi_project_city", $ProjectCity); $statement->bindValue(":permit_project_city", $ProjectCity);
$statement->bindValue(":rdi_project_state", $ProjectState); $statement->bindValue(":permit_project_state", $ProjectState);
$statement->bindValue(":rdi_size", $Size); $statement->bindValue(":permit_size", $Size);
$statement->bindValue(":rdi_units", $Units); $statement->bindValue(":permit_units", $Units);
$statement->bindValue(":rdi_building_type", $BuildingType); $statement->bindValue(":permit_building_type", $BuildingType);
$statement->bindValue(":rdi_value", $Value); $statement->bindValue(":permit_value", $Value);
$statement->bindValue(":rdi_work_type", $WorkType); $statement->bindValue(":permit_work_type", $WorkType);
$statement->bindValue(":rdi_county", $County); $statement->bindValue(":permit_county", $County);
$statement->bindValue(":rdi_lot", $Lot); $statement->bindValue(":permit_lot", $Lot);
$statement->bindValue(":rdi_dist_ll", $DistrictLL); $statement->bindValue(":permit_dist_ll", $DistrictLL);
$statement->bindValue(":rdi_ct1", $Ctl); $statement->bindValue(":permit_ct1", $Ctl);
$statement->bindValue(":rdi_owner_name", $OwnerName); $statement->bindValue(":permit_owner_name", $OwnerName);
$statement->bindValue(":rdi_owner_address", $OwnerAddress); $statement->bindValue(":permit_owner_address", $OwnerAddress);
$statement->bindValue(":rdi_owner_city", $OwnerCity); $statement->bindValue(":permit_owner_city", $OwnerCity);
$statement->bindValue(":rdi_owner_state", $OwnerState); $statement->bindValue(":permit_owner_state", $OwnerState);
$statement->bindValue(":rdi_owner_zip", $OwnerZip); $statement->bindValue(":permit_owner_zip", $OwnerZip);
$statement->bindValue(":rdi_owner_phone", $OwnerPhone); $statement->bindValue(":permit_owner_phone", $OwnerPhone);
$statement->bindValue(":rdi_ytd_permits", $YTDPermits); $statement->bindValue(":permit_ytd_permits", $YTDPermits);
$statement->bindValue(":rdi_ytd_value", $YTDValue); $statement->bindValue(":permit_ytd_value", $YTDValue);
$statement->bindValue(":rdi_12mth_prev_permits", $TwelveMonthPreviousPermits); $statement->bindValue(":permit_12mth_prev_permits", $TwelveMonthPreviousPermits);
$statement->execute(); $statement->execute();
$RecordCount++; $RecordCount++;
} }
// Run Updates on rdi joining 12 month tables
// $this->update1();
// $this->update2();
// $this->update3();
// $this->update4();
// $this->update5();
// $this->update6();
return true; return true;
} }
@@ -274,126 +265,6 @@ class Import extends Base {
return $formattedDate; return $formattedDate;
} }
// ========
// Update 1
// ========
public function update1() {
$sql = "UPDATE rdis AS r
INNER JOIN vw_ytd_permits_by_builder_sf v_ytd
ON r.rdi_company = v_ytd.company
AND r.rdi_city = v_ytd.city
AND r.rdi_state = v_ytd.state
AND r.rdi_zip = v_ytd.zip
SET r.rdi_ytd_permits = v_ytd.ytd_permits,
r.rdi_ytd_value = v_ytd.ytd_value
WHERE r.rdi_project_type
LIKE 'SINGLE%'";
$this->executeSQL($sql);
}
// ========
// Update 2
// ========
public function update2() {
$sql = "UPDATE rdis AS r
LEFT JOIN vw_ytd_permits_by_builder_sf v_ytd
ON r.rdi_company = v_ytd.company
AND r.rdi_city = v_ytd.city
AND r.rdi_state = v_ytd.state
AND r.rdi_zip = v_ytd.zip
SET r.rdi_ytd_permits = 0,
r.rdi_ytd_value = 0
WHERE v_ytd.company IS NULL
AND r.rdi_project_type
LIKE 'SINGLE%';";
$this->executeSQL($sql);
}
// ========
// Update 3
// ========
public function update3() {
$sql = "UPDATE rdis AS r
INNER JOIN vw_12mth_prev_permits_by_builder_sf v_12p
on r.rdi_company = v_12p.company
AND r.rdi_city = v_12p.city
AND r.rdi_state = v_12p.state
AND r.rdi_zip = v_12p.zip
SET r.rdi_12mth_prev_permits = v_12p.12mth_prev_permits
WHERE r.rdi_project_type
LIKE 'SINGLE%';";
$this->executeSQL($sql);
}
// ========
// Update 4
// ========
public function update4() {
$sql = "UPDATE rdis AS r
INNER JOIN vw_ytd_permits_by_builder_mf v_ytd
ON r.rdi_company = v_ytd.company
AND r.rdi_city = v_ytd.city
AND r.rdi_state = v_ytd.state
AND r.rdi_zip = v_ytd.zip
SET r.rdi_ytd_permits = v_ytd.ytd_permits,
r.rdi_ytd_value = v_ytd.ytd_value
WHERE r.rdi_project_type
LIKE 'MULTI%';";
$this->executeSQL($sql);
}
// ========
// Update 5
// ========
public function update5() {
$sql = "UPDATE rdis AS r
LEFT JOIN vw_ytd_permits_by_builder_mf v_ytd
ON r.rdi_company = v_ytd.company
AND r.rdi_city = v_ytd.city
AND r.rdi_state = v_ytd.state
AND r.rdi_zip = v_ytd.zip
SET r.rdi_ytd_permits = 0,
r.rdi_ytd_value = 0
WHERE v_ytd.company IS NULL
AND r.rdi_project_type
LIKE 'MULTI%';";
$this->executeSQL($sql);
}
// ========
// Update 6
// ========
public function update6() {
$sql = "UPDATE rdis AS r
INNER JOIN vw_12mth_prev_permits_by_builder_mf v_12p
on r.rdi_company = v_12p.company
AND r.rdi_city = v_12p.city
AND r.rdi_state = v_12p.state
AND r.rdi_zip = v_12p.zip
SET r.rdi_12mth_prev_permits = v_12p.12mth_prev_permits
WHERE r.rdi_project_type
LIKE 'MULTI%';";
$this->executeSQL($sql);
}
} }
?> ?>