First git push to github
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
// ====================
|
||||
// Export Permits - CSV
|
||||
// ====================
|
||||
|
||||
class Export_AllPermitFactsToCSV extends Base {
|
||||
|
||||
// Variables
|
||||
|
||||
private $current_user_serial = 0;
|
||||
private $current_user_id = "";
|
||||
private $current_user_name = "";
|
||||
private $current_user_email = "";
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct() {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
|
||||
$this->current_user_serial = $_SESSION[self::USER_SERIAL] ?? 0;
|
||||
$this->current_user_id = $_SESSION[self::USER_ID] ?? "";
|
||||
$this->current_user_name = $_SESSION[self::USER_NAME] ?? "";
|
||||
$this->current_user_email = $_SESSION[self::USER_EMAIL] ?? "";
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Export the Data
|
||||
// ===============
|
||||
|
||||
public function export() {
|
||||
|
||||
$subscription_serial = $_SESSION['subscription_serial'];
|
||||
$usersubscription_serial = $_SESSION['usersubscription_serial'];
|
||||
|
||||
$subscription = (new Subscriptions())->getSubscription($subscription_serial);
|
||||
|
||||
if ($subscription->count() === 0) {
|
||||
$this->logError("Invalid Subscription ({$subscription_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$userssubscription = (new Users())->getUserSubscription($usersubscription_serial);
|
||||
|
||||
$user_subscription_start_date = $userssubscription->record->usersubscription_start_date;
|
||||
$user_subscription_end_date = $userssubscription->record->usersubscription_end_date;
|
||||
|
||||
$permits = (new PermitFacts())->getPermitFactsFullDataset($user_subscription_start_date, $user_subscription_end_date);
|
||||
|
||||
$filename = str_replace($subscription->record->subscription_full_title, ' ', '_') . "all_records.csv";
|
||||
|
||||
header('Content-Type: text/csv');
|
||||
header("Content-Disposition: attachment; filename=\"{$filename}\"");
|
||||
|
||||
$output = fopen('php://output', 'w');
|
||||
|
||||
// Add CSV headers
|
||||
|
||||
$header_array = [
|
||||
'permitfact_serial', 'permitfact_entry_date_verbose', 'permitfact_permit_number', 'permitfact_permit_date_verbose', 'permitfact_project_address', 'permitfact_project_name',
|
||||
'permitfact_project_type_verbose', 'project_city_verbose', 'permitfact_project_state', 'permitfact_project_zip', 'permitfact_company', 'permitfact_address',
|
||||
'permitfact_city_verbose', 'permitfact_state', 'permitfact_zip', 'permitfact_phone', 'permitfact_size', 'permitfact_value', 'permitfact_work_type_verbose',
|
||||
'permitfact_building_type_verbose', 'permitfact_county_name_verbose', 'permitfact_lot_block', 'permitfact_dist_ll', 'permitfact_owner_name', 'permitfact_owner_address',
|
||||
'owner_city_verbose', 'permitfact_owner_state', 'permitfact_owner_zip', 'permitfact_owner_phone'
|
||||
];
|
||||
|
||||
fputcsv($output, $header_array, ',', '"', '\\');
|
||||
|
||||
foreach ($permits->record as $permit) {
|
||||
|
||||
$row = [];
|
||||
|
||||
foreach ($header_array as $field) {
|
||||
|
||||
// Cast SimpleXML nodes safely; empty nodes become ""
|
||||
$row[] = isset($permit->$field) ? trim((string) $permit->$field) : '';
|
||||
}
|
||||
|
||||
fputcsv($output, $row, ',', '"', '\\');
|
||||
}
|
||||
|
||||
fclose($output);
|
||||
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
// ===========================
|
||||
// Export Business Facts - CSV
|
||||
// ===========================
|
||||
|
||||
class Export_BusinessFactsToCSV extends Base {
|
||||
|
||||
// Variables
|
||||
|
||||
private $current_user_serial = 0;
|
||||
private $current_user_id = "";
|
||||
private $current_user_name = "";
|
||||
private $current_user_email = "";
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct() {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
|
||||
$this->current_user_serial = $_SESSION[self::USER_SERIAL] ?? 0;
|
||||
$this->current_user_id = $_SESSION[self::USER_ID] ?? "";
|
||||
$this->current_user_name = $_SESSION[self::USER_NAME] ?? "";
|
||||
$this->current_user_email = $_SESSION[self::USER_EMAIL] ?? "";
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Export the Data
|
||||
// ===============
|
||||
|
||||
public function export() {
|
||||
|
||||
$subscription_serial = $_SESSION['subscription_serial'];
|
||||
$usersubscription_serial = $_SESSION['usersubscription_serial'];
|
||||
|
||||
$subscription = (new Subscriptions())->getSubscription($subscription_serial);
|
||||
|
||||
if ($subscription->count() === 0) {
|
||||
$this->logError("Invalid Subscription ({$subscription_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$userssubscription = (new Users())->getUserSubscription($usersubscription_serial);
|
||||
|
||||
$user_subscription_start_date = $userssubscription->record->usersubscription_start_date;
|
||||
$user_subscription_end_date = $userssubscription->record->usersubscription_end_date;
|
||||
|
||||
$businessfacts = (new BusinessFacts())->getBusinessFactsPage($user_subscription_start_date, $user_subscription_end_date);
|
||||
|
||||
$filename = "{$subscription->record->subscription_full_title}.csv";
|
||||
|
||||
header('Content-Type: text/csv');
|
||||
header("Content-Disposition: attachment; filename=\"{$filename}\"");
|
||||
|
||||
$output = fopen('php://output', 'w');
|
||||
|
||||
// Add CSV headers
|
||||
|
||||
$header_array = [
|
||||
'BusinessFactID', 'Company', 'Address1', 'Address2', 'City', 'State',
|
||||
'Zip', 'County', 'Phone', 'Fax', 'EmailAddress', 'BusinessClass',
|
||||
'Action', 'ES', 'Inception', 'SIC', 'SIC_Description', 'ContactName',
|
||||
'ContactTitle', 'LicenseDate', 'HomeBasedBusiness', 'YearEstablished', 'EntryDate'
|
||||
];
|
||||
|
||||
fputcsv($output, $header_array, ',', '"', '\\');
|
||||
|
||||
$header_array = [
|
||||
'businessfact_legacy_id', 'businessfact_company', 'businessfact_address_one', 'businessfact_address_two', 'businessfact_city_verbose', 'businessfact_state',
|
||||
'businessfact_zip', 'businessfact_county_name_verbose', 'businessfact_phone', 'businessfact_fax', 'businessfact_email_address', 'businessfact_business_class_verbose',
|
||||
'businessfact_action_verbose', 'businessfact_employee_count', 'businessfact_inception', 'businessfact_sic_code', 'businessfact_siccode_description_verbose', 'businessfact_contact_name',
|
||||
'businessfact_contact_title', 'businessfact_license_date_verbose', 'businessfact_home_based_business', 'businessfact_year_established', 'businessfact_entry_date_verbose'
|
||||
];
|
||||
|
||||
foreach ($businessfacts->record as $businessfact) {
|
||||
|
||||
$row = [];
|
||||
|
||||
foreach ($header_array as $field) {
|
||||
|
||||
// Cast SimpleXML nodes safely; empty nodes become ""
|
||||
$row[] = isset($businessfact->$field) ? trim((string) $businessfact->$field) : '';
|
||||
}
|
||||
|
||||
fputcsv($output, $row, ',', '"', '\\');
|
||||
}
|
||||
|
||||
fclose($output);
|
||||
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
// ============================
|
||||
// Export Business Facts to Excel
|
||||
// ============================
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
|
||||
class Export_BusinessFactsToExcel extends Base {
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct() {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Export the Data
|
||||
// ===============
|
||||
|
||||
public function export() {
|
||||
|
||||
$subscription_serial = $_SESSION['subscription_serial'];
|
||||
$usersubscription_serial = $_SESSION['usersubscription_serial'];
|
||||
|
||||
$subscription = (new Subscriptions())->getSubscription($subscription_serial);
|
||||
|
||||
if ($subscription->count() === 0) {
|
||||
$this->logError("Invalid Subscription ({$subscription_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$userssubscription = (new Users())->getUserSubscription($usersubscription_serial);
|
||||
|
||||
$user_subscription_start_date = $userssubscription->record->usersubscription_start_date;
|
||||
$user_subscription_end_date = $userssubscription->record->usersubscription_end_date;
|
||||
|
||||
$businessfacts = (new BusinessFacts())->getBusinessFactsPage($user_subscription_start_date, $user_subscription_end_date);
|
||||
|
||||
// Create the Spreadsheet.
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
|
||||
$spreadsheet->getProperties()->setCreator("DEC International")->setTitle("BusinessFacts")->setSubject("BusinessFacts")
|
||||
->setDescription("BusinessFacts")->setKeywords("BusinessFacts")->setCategory("BusinessFacts");
|
||||
|
||||
// Create the Base Sheet.
|
||||
|
||||
$spreadsheet->setActiveSheetIndex(0);
|
||||
$spreadsheet->getActiveSheet()->setTitle("BusinessFacts");
|
||||
|
||||
// Format the Cells and Create the Headings.
|
||||
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("A")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("B")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("C")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("D")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("E")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("F")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("G")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("H")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("I")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("J")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("K")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("L")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("M")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("N")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("O")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("P")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("Q")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("R")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("S")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("T")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("U")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("V")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("W")->setAutoSize(true);
|
||||
|
||||
$spreadsheet->getActiveSheet()->getStyle("A1:W1")->getFont()->setBold(true);
|
||||
$spreadsheet->getActiveSheet()->getStyle("A1:W1")->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB("D3D3D3");
|
||||
|
||||
$spreadsheet->setActiveSheetIndex(0)->setCellValue("A1", "BusinessFactID")
|
||||
->setCellValue("B1", "Company")
|
||||
->setCellValue("C1", "Address1")
|
||||
->setCellValue("D1", "Address2")
|
||||
->setCellValue("E1", "City")
|
||||
->setCellValue("F1", "State")
|
||||
->setCellValue("G1", "Zip")
|
||||
->setCellValue("H1", "County")
|
||||
->setCellValue("I1", "Phone")
|
||||
->setCellValue("J1", "Fax")
|
||||
->setCellValue("K1", "EmailAddress")
|
||||
->setCellValue("L1", "BC")
|
||||
->setCellValue("M1", "Description")
|
||||
->setCellValue("N1", "ES")
|
||||
->setCellValue("O1", "BusinessInception")
|
||||
->setCellValue("P1", "SIC")
|
||||
->setCellValue("Q1", "SIC_Description")
|
||||
->setCellValue("R1", "ContactName")
|
||||
->setCellValue("S1", "ContactTitle")
|
||||
->setCellValue("T1", "LicenseDate")
|
||||
->setCellValue("U1", "HomeBasedBusiness")
|
||||
->setCellValue("V1", "YearEstablished")
|
||||
->setCellValue("W1", "EntryDate");
|
||||
|
||||
$spreadsheet->getActiveSheet()->getStyle("A:A")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER);
|
||||
$spreadsheet->getActiveSheet()->getStyle("C:C")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("D:D")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("E:E")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("F:F")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("G:G")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("H:H")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("I:I")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("J:J")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("K:K")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("L:L")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("M:M")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("N:N")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("O:O")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("P:P")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("Q:Q")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("R:R")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("S:S")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("T:T")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("U:U")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("V:V")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("W:W")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
|
||||
$spreadsheet->getActiveSheet()->freezePane("A2");
|
||||
|
||||
// Create the Detail Rows.
|
||||
|
||||
$row = 2;
|
||||
|
||||
foreach ($businessfacts as $businessfact) {
|
||||
|
||||
$spreadsheet->getActiveSheet()->setCellValue("A" . $row, (string) $businessfact->businessfact_legacy_id);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("B" . $row, (string) $businessfact->businessfact_company);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("C" . $row, (string) $businessfact->businessfact_address_one);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("D" . $row, (string) $businessfact->businessfact_address_two);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("E" . $row, (string) $businessfact->businessfact_city_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("F" . $row, (string) $businessfact->businessfact_state);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("G" . $row, (string) $businessfact->businessfact_zip);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("H" . $row, (string) $businessfact->businessfact_county_name_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("I" . $row, (string) $this->formatPhoneNumber($businessfact->businessfact_phone));
|
||||
$spreadsheet->getActiveSheet()->setCellValue("J" . $row, (string) $this->formatPhoneNumber($businessfact->businessfact_fax));
|
||||
$spreadsheet->getActiveSheet()->setCellValue("K" . $row, (string) $businessfact->businessfact_email_address);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("L" . $row, (string) $businessfact->businessfact_business_class_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("M" . $row, (string) $businessfact->businessfact_action_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("N" . $row, (string) $businessfact->businessfact_employee_count);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("O" . $row, (string) $businessfact->businessfact_inception);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("P" . $row, (string) $businessfact->businessfact_sic_code);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("Q" . $row, (string) $businessfact->businessfact_siccode_description_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("R" . $row, (string) $businessfact->businessfact_contact_name);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("S" . $row, (string) $businessfact->businessfact_contact_title);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("T" . $row, (string) $businessfact->businessfact_license_date_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("U" . $row, (string) $businessfact->businessfact_home_based_business);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("V" . $row, (string) $businessfact->businessfact_year_established);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("W" . $row, (string) $businessfact->businessfact_entry_date_verbose);
|
||||
|
||||
$row++;
|
||||
}
|
||||
|
||||
$spreadsheet->setActiveSheetIndex(0);
|
||||
|
||||
$filename = str_replace(' ', '_', $subscription->record->subscription_full_title) . "_" . date("Y-m-d_h:i:s");
|
||||
|
||||
// Download the spreadsheet
|
||||
|
||||
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
header("Content-disposition: attachment; filename={$filename}.xlsx");
|
||||
header("Cache-Control: max-age=0");
|
||||
|
||||
$excelWriter = new Xlsx($spreadsheet);
|
||||
|
||||
@ob_clean();
|
||||
|
||||
$excelWriter->save('php://output');
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Debug an Object
|
||||
// ===============
|
||||
|
||||
public function debug($object = "") {
|
||||
|
||||
echo "<pre>";
|
||||
print_r($object);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
// =====================
|
||||
// Export PZ Facts - CSV
|
||||
// =====================
|
||||
|
||||
class Export_PZFactsToCSV extends Base {
|
||||
|
||||
// Variables
|
||||
|
||||
private $current_user_serial = 0;
|
||||
private $current_user_id = "";
|
||||
private $current_user_name = "";
|
||||
private $current_user_email = "";
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct() {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
|
||||
$this->current_user_serial = $_SESSION[self::USER_SERIAL] ?? 0;
|
||||
$this->current_user_id = $_SESSION[self::USER_ID] ?? "";
|
||||
$this->current_user_name = $_SESSION[self::USER_NAME] ?? "";
|
||||
$this->current_user_email = $_SESSION[self::USER_EMAIL] ?? "";
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Export the Data
|
||||
// ===============
|
||||
|
||||
public function export() {
|
||||
|
||||
$subscription_serial = $_SESSION['subscription_serial'];
|
||||
$usersubscription_serial = $_SESSION['usersubscription_serial'];
|
||||
|
||||
$subscription = (new Subscriptions())->getSubscription($subscription_serial);
|
||||
|
||||
if ($subscription->count() === 0) {
|
||||
$this->logError("Invalid Subscription ({$subscription_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$userssubscription = (new Users())->getUserSubscription($usersubscription_serial);
|
||||
|
||||
$user_subscription_start_date = $userssubscription->record->usersubscription_start_date;
|
||||
$user_subscription_end_date = $userssubscription->record->usersubscription_end_date;
|
||||
|
||||
$planningzoningfacts = (new PlanningAndZoningFacts())->getPZFactsPage($user_subscription_start_date, $user_subscription_end_date);
|
||||
|
||||
$filename = "{$subscription->record->subscription_full_title}.csv";
|
||||
|
||||
header('Content-Type: text/csv');
|
||||
header("Content-Disposition: attachment; filename=\"{$filename}\"");
|
||||
|
||||
$output = fopen('php://output', 'w');
|
||||
|
||||
// Add CSV headers
|
||||
|
||||
$header_array = [
|
||||
'pzfact_legacy_id', 'pzfact_county', 'pzfact_owner_name', 'pzfact_owner_state', 'pzfact_owner_address', 'pzfact_owner_phone',
|
||||
'pzfact_owner_fax', 'pzfact_professional_name', 'pzfact_professional_state', 'pzfact_professional_address', 'pzfact_professional_phone', 'pzfact_professional_fax',
|
||||
'pzfact_project_type_verbose', 'pzfact_project_name', 'pzfact_project_description', 'pzfact_project_address', 'pzfact_project_city', 'pzfact_action_code_verbose',
|
||||
'pzfact_district', 'pzfact_land_lot', 'pzfact_block', 'pzfact_parcel_number', 'pzfact_lot', 'pzfact_action_date_verbose',
|
||||
'pzfact_acres', 'pzfact_status', 'pzfact_entry_date_verbose'
|
||||
];
|
||||
|
||||
fputcsv($output, $header_array, ',', '"', '\\');
|
||||
|
||||
foreach ($planningzoningfacts->record as $pzfact) {
|
||||
|
||||
$row = [];
|
||||
|
||||
foreach ($header_array as $field) {
|
||||
|
||||
// Cast SimpleXML nodes safely; empty nodes become ""
|
||||
$row[] = isset($pzfact->$field) ? trim((string) $pzfact->$field) : '';
|
||||
}
|
||||
|
||||
fputcsv($output, $row, ',', '"', '\\');
|
||||
}
|
||||
|
||||
fclose($output);
|
||||
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
// =====================================
|
||||
// Export Planning/Zoning Facts to Excel
|
||||
// =====================================
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
|
||||
class Export_PZFactsToExcel extends Base {
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct() {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Export the Data
|
||||
// ===============
|
||||
|
||||
public function export() {
|
||||
|
||||
$subscription_serial = $_SESSION['subscription_serial'];
|
||||
$usersubscription_serial = $_SESSION['usersubscription_serial'];
|
||||
|
||||
$subscription = (new Subscriptions())->getSubscription($subscription_serial);
|
||||
|
||||
if ($subscription->count() === 0) {
|
||||
$this->logError("Invalid Subscription ({$subscription_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$userssubscription = (new Users())->getUserSubscription($usersubscription_serial);
|
||||
|
||||
$user_subscription_start_date = $userssubscription->record->usersubscription_start_date;
|
||||
$user_subscription_end_date = $userssubscription->record->usersubscription_end_date;
|
||||
|
||||
$planningzoningfacts = (new PlanningAndZoningFacts())->getPZFactsPage($user_subscription_start_date, $user_subscription_end_date);
|
||||
|
||||
// Create the Spreadsheet
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
|
||||
$spreadsheet->getProperties()->setCreator("DEC International")->setTitle("PlanningAndZoningFacts")->setSubject("PlanningAndZoningFacts")
|
||||
->setDescription("PlanningAndZoningFacts")->setKeywords("PlanningAndZoningFacts")->setCategory("PlanningAndZoningFacts");
|
||||
|
||||
// Create the Base Sheet.
|
||||
|
||||
$spreadsheet->setActiveSheetIndex(0);
|
||||
$spreadsheet->getActiveSheet()->setTitle("PlanningAndZoningFacts");
|
||||
|
||||
// Format the Cells and Create the Headings.
|
||||
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("A")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("B")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("C")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("D")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("E")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("F")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("G")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("H")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("I")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("J")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("K")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("L")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("M")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("N")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("O")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("P")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("Q")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("R")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("S")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("T")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("U")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("V")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("W")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("X")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("Y")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("Z")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("AA")->setAutoSize(true);
|
||||
|
||||
$spreadsheet->getActiveSheet()->getStyle("A1:AA1")->getFont()->setBold(true);
|
||||
$spreadsheet->getActiveSheet()->getStyle("A1:AA1")->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB("D3D3D3");
|
||||
|
||||
$spreadsheet->setActiveSheetIndex(0)->setCellValue("A1", "PZ_ID")
|
||||
->setCellValue("B1", "County")
|
||||
->setCellValue("C1", "OwnerName")
|
||||
->setCellValue("D1", "OwnerState")
|
||||
->setCellValue("E1", "OwnerAddress")
|
||||
->setCellValue("F1", "OwnerPhone")
|
||||
->setCellValue("G1", "OwnerFax")
|
||||
->setCellValue("H1", "ProfessionalName")
|
||||
->setCellValue("I1", "ProfessionalState")
|
||||
->setCellValue("J1", "ProfessionalAddress")
|
||||
->setCellValue("K1", "ProfessionalPhone")
|
||||
->setCellValue("L1", "ProfessionalFax")
|
||||
->setCellValue("M1", "ProjectType")
|
||||
->setCellValue("N1", "ProjectName")
|
||||
->setCellValue("O1", "ProjectDescription")
|
||||
->setCellValue("P1", "ProjectAddress")
|
||||
->setCellValue("Q1", "ProjectCity")
|
||||
->setCellValue("R1", "ActionCode")
|
||||
->setCellValue("S1", "District")
|
||||
->setCellValue("T1", "LandLot")
|
||||
->setCellValue("U1", "Block")
|
||||
->setCellValue("V1", "Parcel")
|
||||
->setCellValue("W1", "Lot")
|
||||
->setCellValue("X1", "ActionDate")
|
||||
->setCellValue("Y1", "Acres")
|
||||
->setCellValue("Z1", "Status")
|
||||
->setCellValue("AA1", "EntryDate");
|
||||
|
||||
$spreadsheet->getActiveSheet()->getStyle("A:A")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER);
|
||||
$spreadsheet->getActiveSheet()->getStyle("C:C")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("D:D")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("E:E")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("F:F")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("G:G")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("H:H")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("I:I")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("J:J")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("K:K")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("L:L")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("M:M")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("N:N")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("O:O")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("P:P")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("Q:Q")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("R:R")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("S:S")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("T:T")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("U:U")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("V:V")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("W:W")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("X:X")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("Y:Y")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("Z:Z")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("AA:AA")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
|
||||
$spreadsheet->getActiveSheet()->freezePane("A2");
|
||||
|
||||
// Create the Detail Rows.
|
||||
|
||||
$row = 2;
|
||||
|
||||
foreach ($planningzoningfacts as $planningzoningfact) {
|
||||
|
||||
$spreadsheet->getActiveSheet()->setCellValue("A" . $row, (string) $planningzoningfact->pzfact_legacy_id);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("B" . $row, (string) $planningzoningfact->pzfact_county_name_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("C" . $row, (string) $planningzoningfact->pzfact_owner_name);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("D" . $row, (string) $planningzoningfact->pzfact_owner_state);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("E" . $row, (string) $planningzoningfact->pzfact_owner_address);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("F" . $row, $this->formatPhoneNumber((string) $planningzoningfact->pzfact_owner_phone));
|
||||
$spreadsheet->getActiveSheet()->setCellValue("G" . $row, $this->formatPhoneNumber((string) $planningzoningfact->pzfact_owner_fax));
|
||||
$spreadsheet->getActiveSheet()->setCellValue("H" . $row, (string) $planningzoningfact->pzfact_professional_name);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("I" . $row, (string) $planningzoningfact->pzfact_professional_state);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("J" . $row, (string) $planningzoningfact->pzfact_professional_address);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("K" . $row, $this->formatPhoneNumber((string) $planningzoningfact->pzfact_professional_phone));
|
||||
$spreadsheet->getActiveSheet()->setCellValue("L" . $row, $this->formatPhoneNumber((string) $planningzoningfact->pzfact_professional_fax));
|
||||
$spreadsheet->getActiveSheet()->setCellValue("M" . $row, (string) $planningzoningfact->pzfact_project_type_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("N" . $row, (string) $planningzoningfact->pzfact_project_name);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("O" . $row, (string) $planningzoningfact->pzfact_project_description);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("P" . $row, (string) $planningzoningfact->pzfact_project_address);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("Q" . $row, (string) $planningzoningfact->project_city_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("R" . $row, (string) $planningzoningfact->pzfact_action_code_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("S" . $row, (string) $planningzoningfact->pzfact_district);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("T" . $row, (string) $planningzoningfact->pzfact_land_lot);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("U" . $row, (string) $planningzoningfact->pzfact_block);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("V" . $row, (string) $planningzoningfact->pzfact_parcel_number);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("W" . $row, (string) $planningzoningfact->pzfact_lot);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("X" . $row, (string) $planningzoningfact->pzfact_action_date_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("Y" . $row, (string) $planningzoningfact->pzfact_acres);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("Z" . $row, (string) $planningzoningfact->pzfact_status);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("AA" . $row, (string) $planningzoningfact->pzfact_entry_date_verbose);
|
||||
|
||||
$row++;
|
||||
}
|
||||
|
||||
$spreadsheet->setActiveSheetIndex(0);
|
||||
|
||||
$filename = str_replace(' ', '_', $subscription->record->subscription_full_title) . "_" . date("Y-m-d_h:i:s");
|
||||
|
||||
// Download the spreadsheet
|
||||
|
||||
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
header("Content-disposition: attachment; filename={$filename}.xlsx");
|
||||
header("Cache-Control: max-age=0");
|
||||
|
||||
$excelWriter = new Xlsx($spreadsheet);
|
||||
|
||||
@ob_clean();
|
||||
|
||||
$excelWriter->save('php://output');
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Debug an Object
|
||||
// ===============
|
||||
|
||||
public function debug($object = "") {
|
||||
|
||||
echo "<pre>";
|
||||
print_r($object);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
// ====================
|
||||
// Export Permits - CSV
|
||||
// ====================
|
||||
|
||||
class Export_PermitFactsToCSV extends Base {
|
||||
|
||||
// Variables
|
||||
|
||||
private $current_user_serial = 0;
|
||||
private $current_user_id = "";
|
||||
private $current_user_name = "";
|
||||
private $current_user_email = "";
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct() {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
|
||||
$this->current_user_serial = $_SESSION[self::USER_SERIAL] ?? 0;
|
||||
$this->current_user_id = $_SESSION[self::USER_ID] ?? "";
|
||||
$this->current_user_name = $_SESSION[self::USER_NAME] ?? "";
|
||||
$this->current_user_email = $_SESSION[self::USER_EMAIL] ?? "";
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Export the Data
|
||||
// ===============
|
||||
|
||||
public function export() {
|
||||
|
||||
$subscription_serial = $_SESSION['subscription_serial'];
|
||||
$usersubscription_serial = $_SESSION['usersubscription_serial'];
|
||||
|
||||
$subscription = (new Subscriptions())->getSubscription($subscription_serial);
|
||||
|
||||
if ($subscription->count() === 0) {
|
||||
$this->logError("Invalid Subscription ({$subscription_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$userssubscription = (new Users())->getUserSubscription($usersubscription_serial);
|
||||
|
||||
$user_subscription_start_date = $userssubscription->record->usersubscription_start_date;
|
||||
$user_subscription_end_date = $userssubscription->record->usersubscription_end_date;
|
||||
|
||||
$permits = (new PermitFacts())->getPermitFactsPage($user_subscription_start_date, $user_subscription_end_date);
|
||||
|
||||
$filename = "{$subscription->record->subscription_full_title}.csv";
|
||||
|
||||
header('Content-Type: text/csv');
|
||||
header("Content-Disposition: attachment; filename=\"{$filename}\"");
|
||||
|
||||
$output = fopen('php://output', 'w');
|
||||
|
||||
// Add CSV headers
|
||||
|
||||
$header_array = [
|
||||
'permitfact_serial', 'permitfact_entry_date_verbose', 'permitfact_permit_number', 'permitfact_permit_date_verbose', 'permitfact_project_address', 'permitfact_project_name',
|
||||
'permitfact_project_type_verbose', 'project_city_verbose', 'permitfact_project_state', 'permitfact_project_zip', 'permitfact_company', 'permitfact_address',
|
||||
'permitfact_city_verbose', 'permitfact_state', 'permitfact_zip', 'permitfact_phone', 'permitfact_size', 'permitfact_value', 'permitfact_work_type_verbose',
|
||||
'permitfact_building_type_verbose', 'permitfact_county_name_verbose', 'permitfact_lot_block', 'permitfact_dist_ll', 'permitfact_owner_name', 'permitfact_owner_address',
|
||||
'owner_city_verbose', 'permitfact_owner_state', 'permitfact_owner_zip', 'permitfact_owner_phone'
|
||||
];
|
||||
|
||||
fputcsv($output, $header_array, ',', '"', '\\');
|
||||
|
||||
foreach ($permits->record as $permit) {
|
||||
|
||||
$row = [];
|
||||
|
||||
foreach ($header_array as $field) {
|
||||
|
||||
// Cast SimpleXML nodes safely; empty nodes become ""
|
||||
$row[] = isset($permit->$field) ? trim((string) $permit->$field) : '';
|
||||
}
|
||||
|
||||
fputcsv($output, $row, ',', '"', '\\');
|
||||
}
|
||||
|
||||
fclose($output);
|
||||
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
// ============================
|
||||
// Export Permit Facts to Excel
|
||||
// ============================
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
|
||||
class Export_PermitFactsToExcel extends Base {
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct() {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Export the Data
|
||||
// ===============
|
||||
|
||||
public function export() {
|
||||
|
||||
$subscription_serial = $_SESSION['subscription_serial'];
|
||||
$usersubscription_serial = $_SESSION['usersubscription_serial'];
|
||||
|
||||
$subscription = (new Subscriptions())->getSubscription($subscription_serial);
|
||||
|
||||
if ($subscription->count() === 0) {
|
||||
$this->logError("Invalid Subscription ({$subscription_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$userssubscription = (new Users())->getUserSubscription($usersubscription_serial);
|
||||
|
||||
$user_subscription_start_date = $userssubscription->record->usersubscription_start_date;
|
||||
$user_subscription_end_date = $userssubscription->record->usersubscription_end_date;
|
||||
|
||||
$permitfacts = (new PermitFacts())->getPermitFactsPage($user_subscription_start_date, $user_subscription_end_date);
|
||||
|
||||
// Create the Spreadsheet.
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
|
||||
$spreadsheet->getProperties()->setCreator("DEC International")->setTitle("PermitFacts")->setSubject("PermitFacts")
|
||||
->setDescription("PermitFacts")->setKeywords("PermitFacts")->setCategory("PermitFacts");
|
||||
|
||||
// Create the Base Sheet.
|
||||
|
||||
$spreadsheet->setActiveSheetIndex(0);
|
||||
$spreadsheet->getActiveSheet()->setTitle("Permits");
|
||||
|
||||
// Format the Cells and Create the Headings.
|
||||
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("A")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("B")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("C")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("D")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("E")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("F")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("G")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("H")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("I")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("J")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("K")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("L")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("M")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("N")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("O")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("P")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("Q")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("R")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("S")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("T")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("U")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("V")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("W")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("X")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("Y")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("Z")->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension("AA")->setAutoSize(true);
|
||||
|
||||
$spreadsheet->getActiveSheet()->getStyle("A1:AA1")->getFont()->setBold(true);
|
||||
$spreadsheet->getActiveSheet()->getStyle("A1:AA1")->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB("D3D3D3");
|
||||
|
||||
$spreadsheet->setActiveSheetIndex(0)->setCellValue("A1", "permitfact_serial")
|
||||
->setCellValue("B1", "Entry Date")
|
||||
->setCellValue("C1", "Permit Number")
|
||||
->setCellValue("D1", "Permit Date")
|
||||
->setCellValue("E1", "Project Address")
|
||||
->setCellValue("F1", "Project Name")
|
||||
->setCellValue("G1", "Project Type")
|
||||
->setCellValue("H1", "Project City")
|
||||
->setCellValue("I1", "Project State")
|
||||
->setCellValue("J1", "Project Zip")
|
||||
->setCellValue("K1", "Company")
|
||||
->setCellValue("L1", "Address")
|
||||
->setCellValue("M1", "City")
|
||||
->setCellValue("N1", "State")
|
||||
->setCellValue("O1", "Zip")
|
||||
->setCellValue("P1", "Phone Number")
|
||||
->setCellValue("Q1", "Size")
|
||||
->setCellValue("R1", "Value")
|
||||
->setCellValue("S1", "Work Type")
|
||||
->setCellValue("T1", "Building Type")
|
||||
->setCellValue("U1", "County")
|
||||
->setCellValue("V1", "Owner Name")
|
||||
->setCellValue("W1", "Owner Address")
|
||||
->setCellValue("X1", "Owner City")
|
||||
->setCellValue("Y1", "Owner State")
|
||||
->setCellValue("Z1", "Owner Zip")
|
||||
->setCellValue("AA1", "Owner Phone");
|
||||
|
||||
$spreadsheet->getActiveSheet()->getStyle("A:A")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER);
|
||||
$spreadsheet->getActiveSheet()->getStyle("C:C")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("D:D")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("E:E")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("F:F")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("G:G")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("H:H")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("I:I")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("J:J")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("K:K")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("L:L")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("M:M")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("N:N")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("O:O")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("P:P")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("Q:Q")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("R:R")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("S:S")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("T:T")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("U:U")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("V:V")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("W:W")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("X:X")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("Y:Y")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("Z:Z")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
$spreadsheet->getActiveSheet()->getStyle("AA:AA")->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
|
||||
|
||||
$spreadsheet->getActiveSheet()->freezePane("A2");
|
||||
|
||||
// Create the Detail Rows.
|
||||
|
||||
$row = 2;
|
||||
|
||||
foreach ($permitfacts as $permitfact) {
|
||||
|
||||
$spreadsheet->getActiveSheet()->setCellValue("A" . $row, (string) $permitfact->permitfact_serial);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("B" . $row, (string) $permitfact->permitfact_entry_date_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("C" . $row, (string) $permitfact->permitfact_permit_number);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("D" . $row, (string) $permitfact->permitfact_permit_date_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("E" . $row, (string) $permitfact->permitfact_project_address);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("F" . $row, (string) $permitfact->permitfact_project_name);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("G" . $row, (string) $permitfact->permitfact_project_type_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("H" . $row, (string) $permitfact->project_city_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("U" . $row, (string) $permitfact->permitfact_project_state);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("J" . $row, (string) $permitfact->permitfact_project_zip);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("K" . $row, (string) $permitfact->permitfact_company);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("L" . $row, (string) $permitfact->permitfact_address);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("M" . $row, (string) $permitfact->permitfact_city_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("N" . $row, (string) $permitfact->permitfact_state);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("O" . $row, (string) $permitfact->permitfact_zip);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("P" . $row, $this->formatPhoneNumber((string) $permitfact->permitfact_phone));
|
||||
$spreadsheet->getActiveSheet()->setCellValue("Q" . $row, (string) $permitfact->permitfact_size);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("R" . $row, (string) $permitfact->permitfact_value);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("S" . $row, (string) $permitfact->permitfact_work_type_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("T" . $row, (string) $permitfact->permitfact_building_type_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("U" . $row, (string) $permitfact->permitfact_county_name_verbose);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("V" . $row, (string) $permitfact->permitfact_owner_name);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("W" . $row, (string) $permitfact->permitfact_owner_address);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("X" . $row, (string) $permitfact->permitfact_owner_city);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("Y" . $row, (string) $permitfact->permitfact_owner_state);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("Z" . $row, (string) $permitfact->permitfact_owner_zip);
|
||||
$spreadsheet->getActiveSheet()->setCellValue("AA" . $row, $this->formatPhoneNumber((string) $permitfact->permitfact_owner_phone));
|
||||
|
||||
$row++;
|
||||
}
|
||||
|
||||
$spreadsheet->setActiveSheetIndex(0);
|
||||
|
||||
$filename = str_replace(' ', '_', $subscription->record->subscription_full_title) . "_" . date("Y-m-d_h:i:s");
|
||||
|
||||
// Download the spreadsheet
|
||||
|
||||
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
header("Content-disposition: attachment; filename={$filename}.xlsx");
|
||||
header("Cache-Control: max-age=0");
|
||||
|
||||
$excelWriter = new Xlsx($spreadsheet);
|
||||
|
||||
@ob_clean();
|
||||
|
||||
$excelWriter->save('php://output');
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Debug an Object
|
||||
// ===============
|
||||
|
||||
public function debug($object = "") {
|
||||
|
||||
echo "<pre>";
|
||||
print_r($object);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,307 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$basePath = realpath(__DIR__ . '/..');
|
||||
require_once $basePath . '/tcpdf/tcpdf.php';
|
||||
|
||||
// ======================
|
||||
// Print Business Facts PDF
|
||||
// ======================
|
||||
|
||||
class Print_BusinessFactsPDF {
|
||||
|
||||
// Variables.
|
||||
|
||||
private $output_type = "file";
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct($output_type = "normal") {
|
||||
|
||||
|
||||
date_default_timezone_set("America/New_York");
|
||||
|
||||
$this->output_type = $output_type;
|
||||
}
|
||||
|
||||
// ================
|
||||
// Print the Report
|
||||
// ================
|
||||
|
||||
public function print($businessfacts, $subscription, $exportjob_base_directory, $exportjob_file_name) {
|
||||
|
||||
$report = new BusinessFacts_Print();
|
||||
|
||||
$exportjob_base_directory = str_replace('../exports/', './exports/', $exportjob_base_directory);
|
||||
|
||||
$report->subscription_serial = $subscription[0]['subscription_serial'];
|
||||
$report->subscription_full_title = $subscription[0]['subscription_full_title'];
|
||||
$report->exportjob_file_name = $exportjob_file_name;
|
||||
$report->exportjob_base_directory = $exportjob_base_directory;
|
||||
$report->businessfacts_array = $businessfacts;
|
||||
$report->output_type = $this->output_type;
|
||||
|
||||
$report->render();
|
||||
|
||||
return $exportjob_file_name;
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================
|
||||
// Class to Generate the .pdf
|
||||
// ==========================
|
||||
|
||||
class BusinessFacts_Print extends TCPDF {
|
||||
|
||||
// Variables
|
||||
|
||||
public $subscription_serial = 0;
|
||||
public $businessfacts_array = array();
|
||||
public $subscription_full_title = array();
|
||||
public $exportjob_file_name = "";
|
||||
public $exportjob_base_directory = "";
|
||||
public $report_header_title = "";
|
||||
public $first_page = true;
|
||||
public $output_type = "normal";
|
||||
|
||||
// =================
|
||||
// Render the Report
|
||||
// =================
|
||||
|
||||
public function render() {
|
||||
|
||||
// Set report defaults
|
||||
$this->report_header_title = $this->subscription_full_title;
|
||||
$this->title = $this->report_header_title;
|
||||
|
||||
$this->SetFont("Calibri");
|
||||
$this->SetMargins(2, 26, 10);
|
||||
$this->SetHeaderMargin(10);
|
||||
$this->SetFooterMargin(10);
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
$card = function (float $x, float $y, float $w, float $h, array $d) {
|
||||
|
||||
// Card background + border
|
||||
$this->SetDrawColor(210, 210, 210);
|
||||
$this->SetFillColor(250, 250, 250);
|
||||
$this->Rect($x, $y, $w, $h, 'DF');
|
||||
|
||||
// Header bar
|
||||
$headerH = 10;
|
||||
$this->SetFillColor(30, 93, 168); // Bootstrap-ish primary
|
||||
$this->Rect($x, $y, $w, $headerH, 'F');
|
||||
|
||||
// Header text
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('helvetica', 'B', 11);
|
||||
$this->SetXY($x + 3, $y + 2.5);
|
||||
$this->Cell($w - 6, 0, "Company Name: {$d['businessfact_company']}", 0, 0, 'L', false);
|
||||
|
||||
// Body
|
||||
$this->SetTextColor(20, 20, 20);
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
|
||||
$padX = 3;
|
||||
$padY = 3;
|
||||
|
||||
$curY = $y + $headerH + $padY;
|
||||
|
||||
$bodyX = $x + $padX;
|
||||
$bodyW = $w - ($padX * 2);
|
||||
|
||||
$colGap = 6;
|
||||
$colW = ($bodyW - $colGap) / 2;
|
||||
|
||||
$leftX = $bodyX;
|
||||
$rightX = $bodyX + $colW + $colGap;
|
||||
|
||||
$labelW = 37; // tweak to taste
|
||||
|
||||
$row2 = function (string $l1, string $v1, string $l2, string $v2) use (&$curY, $leftX, $rightX, $colW, $labelW) {
|
||||
$yStart = $curY;
|
||||
|
||||
// LEFT cell
|
||||
$this->SetXY($leftX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $l1, 0, 0, 'L');
|
||||
$this->Cell(2, 0, '', 0, 0); // spacer
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($colW - $labelW, 0, $v1, 0, 'L', false, 1);
|
||||
$yAfterLeft = $this->GetY();
|
||||
|
||||
// RIGHT cell (reset to same starting Y)
|
||||
$this->SetXY($rightX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $l2, 0, 0, 'L');
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($colW - $labelW, 0, $v2, 0, 'L', false, 1);
|
||||
$yAfterRight = $this->GetY();
|
||||
|
||||
// Advance cursor to max height used
|
||||
$curY = max($yAfterLeft, $yAfterRight) + 1;
|
||||
};
|
||||
|
||||
// Two-column rows (swap these however you like)
|
||||
$row2('Contact Name: ', $d['businessfact_contact_name'], 'Business Classification:', $d['businessfact_business_class']);
|
||||
$row2('Title: ', $d['businessfact_contact_title'], 'Action:', $d['businessfact_action']);
|
||||
$row2('Phone:', $d['businessfact_company_phone'], 'Employee Count:', $d['businessfact_employee_count']);
|
||||
$row2('Fax:', $d['businessfact_company_fax'], 'Inception:', $d['businessfact_inception']);
|
||||
$row2('Email Address:', $d['businessfact_email_address'], 'SIC Code:', $d['businessfact_sic_code']);
|
||||
$row2('Address:', $d['businessfact_address_one'], 'License Date:', $d['businessfact_license_date']);
|
||||
$row2('City/State/Zip:', $d['businessfact_city_state_zip'], 'Home Based Business:', $d['businessfact_home_based_business']);
|
||||
$row2('County:', $d['businessfact_county_name'], 'Year Established:', $d['businessfact_year_established']);
|
||||
$row2('','', '','' );
|
||||
$row2('','', 'Business Fact ID:', $d['businessfact_legacy_id']);
|
||||
$row2('','', 'Entry Date:', $d['businessfact_entry_date']);
|
||||
};
|
||||
|
||||
// Get the data for the report
|
||||
|
||||
$businessfacts = $this->businessfacts_array;
|
||||
|
||||
$this->AddPage('L', 'LETTER');
|
||||
|
||||
$marginL = 10;
|
||||
$marginT = 20; // below header area
|
||||
$pageW = $this->getPageWidth();
|
||||
$pageH = $this->getPageHeight();
|
||||
|
||||
$usableW = $pageW - ($marginL * 2);
|
||||
$usableH = $pageH - $marginT - 12; // leave footer space
|
||||
|
||||
$gapY = 6;
|
||||
|
||||
// Two rows per page
|
||||
$cardW = $usableW;
|
||||
$cardH = ($usableH - $gapY) / 2;
|
||||
|
||||
$index = 0;
|
||||
|
||||
foreach ($businessfacts as $businessfact) {
|
||||
|
||||
// Add a new page every 2 cards
|
||||
if ($index > 0 && $index % 2 === 0) {
|
||||
$this->AddPage('L', 'LETTER');
|
||||
}
|
||||
|
||||
$slot = $index % 2;
|
||||
|
||||
$x = $marginL;
|
||||
$y = $marginT + ($slot * ($cardH + $gapY));
|
||||
|
||||
$d = [
|
||||
// Card Header
|
||||
'businessfact_company' => trim((string) $businessfact['businessfact_company']),
|
||||
|
||||
// Left Side of Card
|
||||
|
||||
'businessfact_contact_name' => trim((string) $businessfact['businessfact_contact_name']),
|
||||
'businessfact_contact_title' => trim((string) $businessfact['businessfact_contact_title']),
|
||||
'businessfact_company_phone' => $this->formatPhoneNumber(trim((string) $businessfact['businessfact_phone'])),
|
||||
'businessfact_company_fax' => $this->formatPhoneNumber(trim((string) $businessfact['businessfact_fax'])),
|
||||
'businessfact_email_address' => trim((string) $businessfact['businessfact_email_address']),
|
||||
'businessfact_address_one' => trim((string) $businessfact['businessfact_address_one']),
|
||||
'businessfact_city_state_zip' => trim((string) $businessfact['businessfact_city_verbose']) . ', ' . trim((string) $businessfact['businessfact_state']) . ' ' . trim((string) $businessfact['businessfact_zip']),
|
||||
'businessfact_county_name' => trim((string) $businessfact['businessfact_county_name_verbose']),
|
||||
|
||||
// Right Side of Card
|
||||
'businessfact_business_class' => trim((string) $businessfact['businessfact_business_class_verbose']),
|
||||
'businessfact_action' => trim((string) $businessfact['businessfact_action_verbose']),
|
||||
'businessfact_employee_count' => trim((string) $businessfact['businessfact_employee_count']),
|
||||
'businessfact_inception' => trim((string) $businessfact['businessfact_inception']),
|
||||
'businessfact_sic_code' => trim((string) $businessfact['businessfact_sic_code']). ' - ' .trim((string) $businessfact['businessfact_siccode_description_verbose']),
|
||||
'businessfact_license_date' => trim((string) $businessfact['businessfact_license_date_verbose']),
|
||||
'businessfact_home_based_business' => trim((string) $businessfact['businessfact_home_based_business']),
|
||||
'businessfact_year_established' => trim((string) $businessfact['businessfact_year_established']),
|
||||
'businessfact_legacy_id' => trim((string) $businessfact['businessfact_legacy_id']),
|
||||
'businessfact_entry_date' => trim((string) $businessfact['businessfact_entry_date_verbose'])
|
||||
];
|
||||
|
||||
$card($x, $y, $cardW, $cardH, $d);
|
||||
|
||||
$index++;
|
||||
}
|
||||
// -----------------
|
||||
// Render the Report
|
||||
// -----------------
|
||||
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
|
||||
// --------------
|
||||
// Return the pdf
|
||||
// --------------
|
||||
while (ob_get_level() > 0) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
$absPath = __DIR__ . "/../{$this->exportjob_base_directory}/{$this->exportjob_file_name}";
|
||||
|
||||
$this->Output($absPath, "F");
|
||||
|
||||
return $absPath;
|
||||
}
|
||||
|
||||
// ======
|
||||
// Header
|
||||
// ======
|
||||
|
||||
public function Header() {
|
||||
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
$basePath = realpath(__DIR__ . '/..');
|
||||
|
||||
$this->Image($basePath . "/images/dec-international-logo.png", 250, 8, 20, 8);
|
||||
|
||||
$this->SetFont("Calibri", "B", 16);
|
||||
|
||||
$this->Cell(4, 0, "", 0, 0, "L");
|
||||
$this->Cell(0, 0, $this->report_header_title . " Report", 0, 0, "L");
|
||||
|
||||
$this->Ln(10);
|
||||
}
|
||||
|
||||
// ======
|
||||
// Footer
|
||||
// ======
|
||||
|
||||
public function Footer() {
|
||||
|
||||
$this->SetFont("Calibri ", "I", 8);
|
||||
|
||||
$X = $this->GetX();
|
||||
|
||||
$this->Cell(0, 10, "DEC International ", 0, false, "C");
|
||||
|
||||
$this->SetX($X);
|
||||
|
||||
$this->Cell(40, 10, "Page " . $this->getAliasNumPage() . "/" . $this->getAliasNbPages(), 0, false, "L");
|
||||
$this->Cell(0, 10, date("n/j/Y g:i A "), 0, false, "R"
|
||||
);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Format Raw Phone Number
|
||||
// =======================
|
||||
|
||||
public function formatPhoneNumber(string $phonenumber): string {
|
||||
|
||||
// Remove everything except digits
|
||||
$digits = preg_replace('/\D+/', '', $phonenumber);
|
||||
|
||||
// Handle leading country code (US)
|
||||
if (strlen($digits) === 11 && str_starts_with($digits, '1')) {
|
||||
$digits = substr($digits, 1);
|
||||
}
|
||||
|
||||
return substr($digits, 0, 3) . '-' . substr($digits, 3, 3) . '-' . substr($digits, 6, 4);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$basePath = realpath(__DIR__ . '/..');
|
||||
require_once $basePath . '/tcpdf/tcpdf.php';
|
||||
|
||||
// ==================
|
||||
// Print PZ Facts PDF
|
||||
// ==================
|
||||
|
||||
class Print_PZFactsPDF {
|
||||
|
||||
// Variables.
|
||||
|
||||
private $output_type = "file";
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct($output_type = "normal") {
|
||||
|
||||
|
||||
date_default_timezone_set("America/New_York");
|
||||
|
||||
$this->output_type = $output_type;
|
||||
}
|
||||
|
||||
// ================
|
||||
// Print the Report
|
||||
// ================
|
||||
|
||||
public function print($pzfacts, $subscription, $exportjob_base_directory, $exportjob_file_name) {
|
||||
|
||||
$report = new PzFacts_Print();
|
||||
|
||||
$exportjob_base_directory = str_replace('../exports/', './exports/', $exportjob_base_directory);
|
||||
|
||||
$report->subscription_serial = $subscription[0]['subscription_serial'];
|
||||
$report->subscription_full_title = $subscription[0]['subscription_full_title'];
|
||||
$report->exportjob_file_name = $exportjob_file_name;
|
||||
$report->exportjob_base_directory = $exportjob_base_directory;
|
||||
$report->pzfacts_array = $pzfacts;
|
||||
|
||||
$report->output_type = $this->output_type;
|
||||
|
||||
$report->render();
|
||||
|
||||
return $exportjob_file_name;
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================
|
||||
// Class to Generate the .pdf
|
||||
// ==========================
|
||||
|
||||
class PZFacts_Print extends TCPDF {
|
||||
|
||||
// Variables
|
||||
|
||||
public $subscription_serial = 0;
|
||||
public $pzfacts_array = array();
|
||||
public $subscription_full_title = array();
|
||||
public $exportjob_file_name = "";
|
||||
public $exportjob_base_directory = "";
|
||||
public $report_header_title = "";
|
||||
public $first_page = true;
|
||||
public $output_type = "normal";
|
||||
|
||||
// =================
|
||||
// Render the Report
|
||||
// =================
|
||||
|
||||
public function render() {
|
||||
|
||||
// Set report defaults
|
||||
$this->report_header_title = $this->subscription_full_title;
|
||||
$this->title = $this->report_header_title;
|
||||
|
||||
$this->SetFont("Calibri");
|
||||
$this->SetMargins(2, 26, 10);
|
||||
$this->SetHeaderMargin(10);
|
||||
$this->SetFooterMargin(10);
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
$card = function (float $x, float $y, float $w, float $h, array $d) {
|
||||
|
||||
// Card background + border
|
||||
$this->SetDrawColor(210, 210, 210);
|
||||
$this->SetFillColor(250, 250, 250);
|
||||
$this->Rect($x, $y, $w, $h, 'DF');
|
||||
|
||||
// Header bar
|
||||
$headerH = 10;
|
||||
$this->SetFillColor(30, 93, 168); // Bootstrap-ish primary
|
||||
$this->Rect($x, $y, $w, $headerH, 'F');
|
||||
|
||||
// Header text
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('helvetica', 'B', 11);
|
||||
$this->SetXY($x + 3, $y + 2.5);
|
||||
$this->Cell($w - 6, 0, "Project Name: {$d['pzfact_project_name']}", 0, 0, 'L', false);
|
||||
|
||||
// Body
|
||||
$this->SetTextColor(20, 20, 20);
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
|
||||
$padX = 3;
|
||||
$padY = 3;
|
||||
|
||||
$curY = $y + $headerH + $padY;
|
||||
|
||||
$bodyX = $x + $padX;
|
||||
$bodyW = $w - ($padX * 2);
|
||||
|
||||
$colGap = 6;
|
||||
$colW = ($bodyW - $colGap) / 2;
|
||||
|
||||
$leftX = $bodyX;
|
||||
$rightX = $bodyX + $colW + $colGap;
|
||||
|
||||
$labelW = 38;
|
||||
|
||||
$row2 = function (string $l1, string $v1, string $l2, string $v2) use (&$curY, $leftX, $rightX, $colW, $labelW) {
|
||||
$yStart = $curY;
|
||||
|
||||
// LEFT cell
|
||||
$this->SetXY($leftX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $l1, 0, 0, 'L');
|
||||
$this->Cell(2, 0, '', 0, 0); // spacer
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($colW - $labelW, 0, $v1, 0, 'L', false, 1);
|
||||
$yAfterLeft = $this->GetY();
|
||||
|
||||
// RIGHT cell (reset to same starting Y)
|
||||
$this->SetXY($rightX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $l2, 0, 0, 'L');
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($colW - $labelW, 0, $v2, 0, 'L', false, 1);
|
||||
$yAfterRight = $this->GetY();
|
||||
|
||||
// Advance cursor to max height used
|
||||
$curY = max($yAfterLeft, $yAfterRight) + 1;
|
||||
};
|
||||
|
||||
$row1 = function (string $label, string $value) use (&$curY, $leftX, $bodyW, $labelW) {
|
||||
|
||||
$yStart = $curY;
|
||||
|
||||
$this->SetXY($leftX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $label, 0, 0, 'L');
|
||||
$this->Cell(2, 0, '', 0, 0); // spacer
|
||||
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($bodyW - $labelW - 10, 0, $value, 0, 'L', false, 1);
|
||||
|
||||
$curY = $this->GetY() + 1;
|
||||
};
|
||||
|
||||
$row2('Project Description:', $d['pzfact_project_description'], 'Project Type:', $d['pzfact_project_type']);
|
||||
$row2('Architect/Engineer: ', $d['pzfact_professional_name'], 'Estimated Project Value:', $d['pzfact_dollar_value']);
|
||||
$row2('', '', 'District:', $d['pzfact_district']);
|
||||
$row2('Owner Name: ', $d['pzfact_owner_name'], 'Land Lot:', $d['pzfact_land_lot']);
|
||||
$row2('Owner Address: ', $d['pzfact_owner_address'], 'Action Code:', $d['pzfact_action_code']);
|
||||
$row2('Owner Phone: ', $d['pzfact_owner_phone'], 'Action Date:', $d['pzfact_action_date']);
|
||||
$row2('', '', 'Lot Acres:', $d['pzfact_acres']);
|
||||
$row2('', '', '', '');
|
||||
|
||||
$row1('Status:', $d['pzfact_status']);
|
||||
};
|
||||
|
||||
// Get the data for the report
|
||||
|
||||
$planningzoningfacts = $this->pzfacts_array;
|
||||
|
||||
$this->AddPage('L', 'LETTER');
|
||||
|
||||
$marginL = 10;
|
||||
$marginT = 20; // below header area
|
||||
$pageW = $this->getPageWidth();
|
||||
$pageH = $this->getPageHeight();
|
||||
|
||||
$usableW = $pageW - ($marginL * 2);
|
||||
$usableH = $pageH - $marginT - 12; // leave footer space
|
||||
|
||||
$gapY = 6;
|
||||
|
||||
// Two rows per page
|
||||
$cardW = $usableW;
|
||||
$cardH = ($usableH - $gapY) / 2;
|
||||
|
||||
$index = 0;
|
||||
|
||||
foreach ($planningzoningfacts as $planningzoningfact) {
|
||||
|
||||
// Add a new page every 2 cards
|
||||
if ($index > 0 && $index % 2 === 0) {
|
||||
$this->AddPage('L', 'LETTER');
|
||||
}
|
||||
|
||||
$slot = $index % 2;
|
||||
|
||||
$x = $marginL;
|
||||
$y = $marginT + ($slot * ($cardH + $gapY));
|
||||
|
||||
// Map your XML fields to the card placeholders (use verbose)
|
||||
|
||||
$d = [
|
||||
// Left Side of Card
|
||||
'subscription_serial' => trim((string) $planningzoningfact['pzfact_legacy_id']),
|
||||
'pzfact_project_description' => trim((string) $planningzoningfact['pzfact_project_description']),
|
||||
'pzfact_project_name' => trim((string) $planningzoningfact['pzfact_project_name']),
|
||||
'pzfact_project_type' => trim((string) $planningzoningfact['pzfact_project_type_verbose']),
|
||||
'pzfact_professional_name' => trim((string) $planningzoningfact['pzfact_professional_name']),
|
||||
'pzfact_owner_name' => trim((string) $planningzoningfact['pzfact_owner_name']),
|
||||
'pzfact_owner_address' => trim((string) $planningzoningfact['pzfact_owner_address']),
|
||||
'pzfact_owner_phone' => $this->formatPhoneNumber(trim((string) $planningzoningfact['pzfact_owner_phone'])),
|
||||
|
||||
// Right Side of Card
|
||||
'pzfact_dollar_value' => trim((string) $planningzoningfact['pzfact_dollar_value']),
|
||||
'pzfact_district' => trim((string) $planningzoningfact['pzfact_district']),
|
||||
'pzfact_land_lot' => trim((string) $planningzoningfact['pzfact_land_lot']),
|
||||
'pzfact_action_code' => trim((string) $planningzoningfact['pzfact_action_code_verbose']),
|
||||
'pzfact_action_date' => trim((string) $planningzoningfact['pzfact_action_date_verbose']),
|
||||
'pzfact_acres' => trim((string) $planningzoningfact['pzfact_acres']),
|
||||
'pzfact_entry_date' => trim((string) $planningzoningfact['pzfact_entry_date_verbose']),
|
||||
'pzfact_status' => trim((string) $planningzoningfact['pzfact_status']),
|
||||
'pzfact_dollar_value' => trim((string) $planningzoningfact['pzfact_dollar_value']),
|
||||
];
|
||||
|
||||
$card($x, $y, $cardW, $cardH, $d);
|
||||
|
||||
$index++;
|
||||
}
|
||||
|
||||
// -----------------
|
||||
// Render the Report
|
||||
// -----------------
|
||||
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
|
||||
// --------------
|
||||
// Return the pdf
|
||||
// --------------
|
||||
while (ob_get_level() > 0) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
$absPath = __DIR__ . "/../{$this->exportjob_base_directory}/{$this->exportjob_file_name}";
|
||||
|
||||
$this->Output($absPath, "F");
|
||||
|
||||
return $absPath;
|
||||
}
|
||||
|
||||
// ======
|
||||
// Header
|
||||
// ======
|
||||
|
||||
public function Header() {
|
||||
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
$basePath = realpath(__DIR__ . '/..');
|
||||
|
||||
$this->Image($basePath . "/images/dec-international-logo.png", 250, 8, 20, 8);
|
||||
|
||||
$this->SetFont("Calibri", "B", 16);
|
||||
|
||||
$this->Cell(4, 0, "", 0, 0, "L");
|
||||
$this->Cell(0, 0, $this->report_header_title . " Report", 0, 0, "L");
|
||||
|
||||
$this->Ln(10);
|
||||
}
|
||||
|
||||
// ======
|
||||
// Footer
|
||||
// ======
|
||||
|
||||
public function Footer() {
|
||||
|
||||
$this->SetFont("Calibri ", "I", 8);
|
||||
|
||||
$X = $this->GetX();
|
||||
|
||||
$this->Cell(0, 10, "DEC International ", 0, false, "C");
|
||||
|
||||
$this->SetX($X);
|
||||
|
||||
$this->Cell(40, 10, "Page " . $this->getAliasNumPage() . "/" . $this->getAliasNbPages(), 0, false, "L");
|
||||
$this->Cell(0, 10, date("n/j/Y g:i A "), 0, false, "R"
|
||||
);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Format Raw Phone Number
|
||||
// =======================
|
||||
|
||||
public function formatPhoneNumber(string $phonenumber): string {
|
||||
|
||||
// Remove everything except digits
|
||||
$digits = preg_replace('/\D+/', '', $phonenumber);
|
||||
|
||||
// Handle leading country code (US)
|
||||
if (strlen($digits) === 11 && str_starts_with($digits, '1')) {
|
||||
$digits = substr($digits, 1);
|
||||
}
|
||||
|
||||
return substr($digits, 0, 3) . '-' . substr($digits, 3, 3) . '-' . substr($digits, 6, 4);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$basePath = realpath(__DIR__ . '/..');
|
||||
require_once $basePath . '/tcpdf/tcpdf.php';
|
||||
|
||||
// ======================
|
||||
// Print Permit Facts PDF
|
||||
// ======================
|
||||
|
||||
class Print_PermitFactsPDF {
|
||||
|
||||
// Variables.
|
||||
|
||||
private $output_type = "string";
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct($output_type = "normal") {
|
||||
|
||||
|
||||
date_default_timezone_set("America/New_York");
|
||||
|
||||
$this->output_type = $output_type;
|
||||
}
|
||||
|
||||
// ================
|
||||
// Print the Report
|
||||
// ================
|
||||
|
||||
public function print($permitfacts, $subscription, $exportjob_base_directory, $exportjob_file_name) {
|
||||
|
||||
$report = new PermitFacts_Print();
|
||||
|
||||
$exportjob_base_directory = str_replace('../exports/', './exports/', $exportjob_base_directory);
|
||||
|
||||
$report->subscription_serial = $subscription[0]['subscription_serial'];
|
||||
$report->subscription_full_title = $subscription[0]['subscription_full_title'];
|
||||
$report->exportjob_file_name = $exportjob_file_name;
|
||||
$report->exportjob_base_directory = $exportjob_base_directory;
|
||||
$report->permitfacts_array = $permitfacts;
|
||||
$report->output_type = $this->output_type;
|
||||
|
||||
$report->render();
|
||||
|
||||
return $exportjob_file_name;
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================
|
||||
// Class to Generate the .pdf
|
||||
// ==========================
|
||||
|
||||
class PermitFacts_Print extends TCPDF {
|
||||
|
||||
// Variables
|
||||
|
||||
public $subscription_serial = 0;
|
||||
public $permitfacts_array = array();
|
||||
public $subscription_full_title = array();
|
||||
public $exportjob_file_name = "";
|
||||
public $exportjob_base_directory = "";
|
||||
public $report_header_title = "";
|
||||
public $first_page = true;
|
||||
public $output_type = "normal";
|
||||
|
||||
// =================
|
||||
// Render the Report
|
||||
// =================
|
||||
|
||||
public function render() {
|
||||
|
||||
// Set report defaults
|
||||
$this->report_header_title = $this->subscription_full_title;
|
||||
$this->title = $this->report_header_title;
|
||||
|
||||
$this->SetFont("Calibri");
|
||||
$this->SetMargins(2, 26, 10);
|
||||
$this->SetHeaderMargin(10);
|
||||
$this->SetFooterMargin(10);
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
$card = function (float $x, float $y, float $w, float $h, array $d) {
|
||||
|
||||
// Card background + border
|
||||
$this->SetDrawColor(210, 210, 210);
|
||||
$this->SetFillColor(250, 250, 250);
|
||||
$this->Rect($x, $y, $w, $h, 'DF');
|
||||
|
||||
// Header bar
|
||||
$headerH = 10;
|
||||
$this->SetFillColor(30, 93, 168); // Bootstrap-ish primary
|
||||
$this->Rect($x, $y, $w, $headerH, 'F');
|
||||
|
||||
// Header text
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('helvetica', 'B', 11);
|
||||
$this->SetXY($x + 3, $y + 2.5);
|
||||
$this->Cell($w - 6, 0, "Project Name: {$d['permitfact_project_name']}", 0, 0, 'L', false);
|
||||
|
||||
// Body
|
||||
$this->SetTextColor(20, 20, 20);
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
|
||||
$padX = 3;
|
||||
$padY = 3;
|
||||
|
||||
$curY = $y + $headerH + $padY;
|
||||
|
||||
$bodyX = $x + $padX;
|
||||
$bodyW = $w - ($padX * 2);
|
||||
|
||||
$colGap = 6;
|
||||
$colW = ($bodyW - $colGap) / 2;
|
||||
|
||||
$leftX = $bodyX;
|
||||
$rightX = $bodyX + $colW + $colGap;
|
||||
|
||||
$labelW = 22; // tweak to taste
|
||||
|
||||
$row2 = function (string $l1, string $v1, string $l2, string $v2) use (&$curY, $leftX, $rightX, $colW, $labelW) {
|
||||
$yStart = $curY;
|
||||
|
||||
// LEFT cell
|
||||
$this->SetXY($leftX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $l1, 0, 0, 'L');
|
||||
$this->Cell(2, 0, '', 0, 0); // spacer
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($colW - $labelW, 0, $v1, 0, 'L', false, 1);
|
||||
$yAfterLeft = $this->GetY();
|
||||
|
||||
// RIGHT cell (reset to same starting Y)
|
||||
$this->SetXY($rightX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $l2, 0, 0, 'L');
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($colW - $labelW, 0, $v2, 0, 'L', false, 1);
|
||||
$yAfterRight = $this->GetY();
|
||||
|
||||
// Advance cursor to max height used
|
||||
$curY = max($yAfterLeft, $yAfterRight) + 1;
|
||||
};
|
||||
|
||||
// Two-column rows (swap these however you like)
|
||||
$row2('Permit Number: ', $d['permitfact_permit_number'], 'Permit Date:', $d['permitfact_permit_date']);
|
||||
$row2('Project Address: ', $d['permitfact_project_address'], 'Project Type:', $d['permitfact_project_type']);
|
||||
$row2('City/State/Zip:', $d['permitfact_project_city_state_zip'], 'Work Type:', $d['permitfact_work_type']);
|
||||
$row2('Project County:', $d['permitfact_county_name'], 'Building Type:', $d['permitfact_building_type']);
|
||||
$row2('', '', 'Value:', $d['permitfact_value']);
|
||||
$row2('Company:', $d['permitfact_company'], 'Entry Date:', $d['permitfact_entry_date']);
|
||||
$row2('Address:', $d['permitfact_company_address'], 'Square Foot: ', $d['permitfact_size']);
|
||||
$row2('City/State/Zip:', $d['permitfact_company_city_state_zip'], '', '');
|
||||
$row2('Company Phone:', $d['permitfact_company_phone'], '', '');
|
||||
$row2('', '', '', '');
|
||||
$row2('Owner:', $d['permitfact_owner_name'], '', '');
|
||||
$row2('Owner Phone:', $d['permitfact_owner_phone'], '', '');
|
||||
};
|
||||
|
||||
// Get the data for the report
|
||||
|
||||
$permits = $this->permitfacts_array;
|
||||
|
||||
$this->AddPage('L', 'LETTER');
|
||||
|
||||
$marginL = 10;
|
||||
$marginT = 20; // below header area
|
||||
$pageW = $this->getPageWidth();
|
||||
$pageH = $this->getPageHeight();
|
||||
|
||||
$usableW = $pageW - ($marginL * 2);
|
||||
$usableH = $pageH - $marginT - 12; // leave footer space
|
||||
|
||||
$gapY = 6;
|
||||
|
||||
// Two rows per page
|
||||
$cardW = $usableW;
|
||||
$cardH = ($usableH - $gapY) / 2;
|
||||
|
||||
$index = 0;
|
||||
|
||||
foreach ($permits as $permit) {
|
||||
|
||||
// Add a new page every 2 cards
|
||||
if ($index > 0 && $index % 2 === 0) {
|
||||
$this->AddPage('L', 'LETTER');
|
||||
}
|
||||
|
||||
$slot = $index % 2;
|
||||
|
||||
$x = $marginL;
|
||||
$y = $marginT + ($slot * ($cardH + $gapY));
|
||||
|
||||
// Map your XML fields to the card placeholders (use verbose)
|
||||
$valueRaw = trim((string) $permit['permitfact_value']);
|
||||
$value = ($valueRaw !== '') ? '$' . number_format((float) $valueRaw, 2) : '';
|
||||
|
||||
$d = [
|
||||
// Left Side of Card
|
||||
'permitfact_serial' => trim((string) $permit['permitfact_serial']),
|
||||
'permitfact_project_name' => trim((string) $permit['permitfact_project_name']),
|
||||
'permitfact_permit_number' => trim((string) $permit['permitfact_permit_number']),
|
||||
'permitfact_project_address' => trim((string) $permit['permitfact_project_address']),
|
||||
'permitfact_project_city_state_zip' => trim((string) $permit['project_city_verbose']) . ', ' . trim((string) $permit['permitfact_project_state']) . ' ' . trim((string) $permit['permitfact_project_zip']),
|
||||
'permitfact_county_name' => trim((string) $permit['permitfact_county_name_verbose']),
|
||||
'permitfact_company' => trim((string) $permit['permitfact_company']),
|
||||
'permitfact_company_address' => trim((string) $permit['permitfact_address']),
|
||||
'permitfact_company_city_state_zip' => trim((string) $permit['permitfact_city_verbose']) . ', ' . trim((string) $permit['permitfact_state']) . ' ' . trim((string) $permit['permitfact_zip']),
|
||||
'permitfact_company_phone' => $this->formatPhoneNumber(trim((string) $permit['permitfact_phone'])),
|
||||
'permitfact_owner_name' => trim((string) $permit['permitfact_owner_name']),
|
||||
'permitfact_owner_phone' => $this->formatPhoneNumber(trim((string) $permit['permitfact_owner_phone'])),
|
||||
// Right Side of Card
|
||||
'permitfact_permit_date' => trim((string) $permit['permitfact_permit_date_verbose']),
|
||||
'permitfact_entry_date' => trim((string) $permit['permitfact_entry_date_verbose']),
|
||||
'permitfact_project_type' => trim((string) $permit['permitfact_project_type_verbose']),
|
||||
'permitfact_value' => $value,
|
||||
'permitfact_building_type' => trim((string) $permit['permitfact_building_type_verbose']),
|
||||
'permitfact_work_type' => trim((string) $permit['permitfact_work_type_verbose']),
|
||||
'permitfact_size' => trim((string) $permit['permitfact_size']),
|
||||
];
|
||||
|
||||
$card($x, $y, $cardW, $cardH, $d);
|
||||
|
||||
$index++;
|
||||
}
|
||||
// -----------------
|
||||
// Render the Report
|
||||
// -----------------
|
||||
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
|
||||
// --------------
|
||||
// Return the pdf
|
||||
// --------------
|
||||
while (ob_get_level() > 0) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
$absPath = __DIR__ . "/../{$this->exportjob_base_directory}/{$this->exportjob_file_name}";
|
||||
|
||||
$this->Output($absPath, "F");
|
||||
|
||||
return $absPath;
|
||||
}
|
||||
|
||||
// ======
|
||||
// Header
|
||||
// ======
|
||||
|
||||
public function Header() {
|
||||
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
$basePath = realpath(__DIR__ . '/..');
|
||||
|
||||
$this->Image($basePath . "/images/dec-international-logo.png", 250, 8, 20, 8);
|
||||
|
||||
$this->SetFont("Calibri", "B", 16);
|
||||
|
||||
$this->Cell(4, 0, "", 0, 0, "L");
|
||||
$this->Cell(0, 0, $this->report_header_title . " Report", 0, 0, "L");
|
||||
|
||||
$this->Ln(10);
|
||||
}
|
||||
|
||||
// ======
|
||||
// Footer
|
||||
// ======
|
||||
|
||||
public function Footer() {
|
||||
|
||||
$this->SetFont("Calibri ", "I", 8);
|
||||
|
||||
$X = $this->GetX();
|
||||
|
||||
$this->Cell(0, 10, "DEC International ", 0, false, "C");
|
||||
|
||||
$this->SetX($X);
|
||||
|
||||
$this->Cell(40, 10, "Page " . $this->getAliasNumPage() . "/" . $this->getAliasNbPages(), 0, false, "L");
|
||||
$this->Cell(0, 10, date("n/j/Y g:i A "), 0, false, "R"
|
||||
);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Format Raw Phone Number
|
||||
// =======================
|
||||
|
||||
public function formatPhoneNumber(string $phonenumber): string {
|
||||
|
||||
// Remove everything except digits
|
||||
$digits = preg_replace('/\D+/', '', $phonenumber);
|
||||
|
||||
// Handle leading country code (US)
|
||||
if (strlen($digits) === 11 && str_starts_with($digits, '1')) {
|
||||
$digits = substr($digits, 1);
|
||||
}
|
||||
|
||||
return substr($digits, 0, 3) . '-' . substr($digits, 3, 3) . '-' . substr($digits, 6, 4);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,342 @@
|
||||
<?php
|
||||
|
||||
require_once ("tcpdf/tcpdf.php");
|
||||
|
||||
// ======================
|
||||
// Print Business Facts PDF
|
||||
// ======================
|
||||
|
||||
class Print_BusinessFactsPDF extends Base {
|
||||
|
||||
// Variables.
|
||||
|
||||
private $output_type = "normal";
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct($output_type = "normal") {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
|
||||
$this->output_type = $output_type;
|
||||
}
|
||||
|
||||
// ================
|
||||
// Print the Report
|
||||
// ================
|
||||
|
||||
public function print() {
|
||||
|
||||
$report = new BusinessFacts_Print();
|
||||
|
||||
$report->subscription_serial = $_SESSION['subscription_serial'];
|
||||
$report->usersubscription_serial = $_SESSION['usersubscription_serial'];
|
||||
$report->output_type = $this->output_type;
|
||||
|
||||
ob_clean();
|
||||
|
||||
if ($this->output_type == "string") {
|
||||
return $report->render();
|
||||
} else {
|
||||
$report->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================
|
||||
// Class to Generate the .pdf
|
||||
// ==========================
|
||||
|
||||
class BusinessFacts_Print extends TCPDF {
|
||||
|
||||
// Variables
|
||||
|
||||
public $subscription_serial = 0;
|
||||
public $usersubscription_serial = 0;
|
||||
public $report_header_title = "";
|
||||
public $first_page = true;
|
||||
public $output_type = "normal";
|
||||
|
||||
// ================
|
||||
// Debug an Object.
|
||||
// ================
|
||||
|
||||
public function debug($object = "") {
|
||||
|
||||
echo "<pre>";
|
||||
print_r($object);
|
||||
exit();
|
||||
}
|
||||
|
||||
// =================
|
||||
// Render the Report
|
||||
// =================
|
||||
|
||||
public function render() {
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$subscription = (new Subscriptions())->getSubscription($this->subscription_serial);
|
||||
|
||||
if ($subscription->count() === 0) {
|
||||
$this->logError("Invalid Subscription ({$this->subscription_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$userssubscription = (new Users())->getUserSubscription($this->usersubscription_serial);
|
||||
|
||||
$user_subscription_start_date = $userssubscription->record->usersubscription_start_date;
|
||||
$user_subscription_end_date = $userssubscription->record->usersubscription_end_date;
|
||||
|
||||
// Set report defaults
|
||||
$this->report_header_title = $subscription->record->subscription_full_title;
|
||||
$this->title = $subscription->record->subscription_full_title;
|
||||
|
||||
$this->SetFont("Calibri");
|
||||
$this->SetMargins(2, 26, 10);
|
||||
$this->SetHeaderMargin(10);
|
||||
$this->SetFooterMargin(10);
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
// $this->addPage("L", "LETTER");
|
||||
|
||||
$card = function (float $x, float $y, float $w, float $h, array $d) {
|
||||
|
||||
// Card background + border
|
||||
$this->SetDrawColor(210, 210, 210);
|
||||
$this->SetFillColor(250, 250, 250);
|
||||
$this->Rect($x, $y, $w, $h, 'DF');
|
||||
|
||||
// Header bar
|
||||
$headerH = 10;
|
||||
$this->SetFillColor(30, 93, 168); // Bootstrap-ish primary
|
||||
$this->Rect($x, $y, $w, $headerH, 'F');
|
||||
|
||||
// Header text
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('helvetica', 'B', 11);
|
||||
$this->SetXY($x + 3, $y + 2.5);
|
||||
$this->Cell($w - 6, 0, "Company Name: {$d['businessfact_company']}", 0, 0, 'L', false);
|
||||
|
||||
// Body
|
||||
$this->SetTextColor(20, 20, 20);
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
|
||||
$padX = 3;
|
||||
$padY = 3;
|
||||
|
||||
$curY = $y + $headerH + $padY;
|
||||
|
||||
$bodyX = $x + $padX;
|
||||
$bodyW = $w - ($padX * 2);
|
||||
|
||||
$colGap = 6;
|
||||
$colW = ($bodyW - $colGap) / 2;
|
||||
|
||||
$leftX = $bodyX;
|
||||
$rightX = $bodyX + $colW + $colGap;
|
||||
|
||||
$labelW = 37; // tweak to taste
|
||||
|
||||
$row2 = function (string $l1, string $v1, string $l2, string $v2) use (&$curY, $leftX, $rightX, $colW, $labelW) {
|
||||
$yStart = $curY;
|
||||
|
||||
// LEFT cell
|
||||
$this->SetXY($leftX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $l1, 0, 0, 'L');
|
||||
$this->Cell(2, 0, '', 0, 0); // spacer
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($colW - $labelW, 0, $v1, 0, 'L', false, 1);
|
||||
$yAfterLeft = $this->GetY();
|
||||
|
||||
// RIGHT cell (reset to same starting Y)
|
||||
$this->SetXY($rightX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $l2, 0, 0, 'L');
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($colW - $labelW, 0, $v2, 0, 'L', false, 1);
|
||||
$yAfterRight = $this->GetY();
|
||||
|
||||
// Advance cursor to max height used
|
||||
$curY = max($yAfterLeft, $yAfterRight) + 1;
|
||||
};
|
||||
|
||||
// Two-column rows (swap these however you like)
|
||||
$row2('Contact Name: ', $d['businessfact_contact_name'], 'Business Classification:', $d['businessfact_business_class']);
|
||||
$row2('Title: ', $d['businessfact_contact_title'], 'Action:', $d['businessfact_action']);
|
||||
$row2('Phone:', $d['businessfact_company_phone'], 'Employee Count:', $d['businessfact_employee_count']);
|
||||
$row2('Fax:', $d['businessfact_company_fax'], 'Inception:', $d['businessfact_inception']);
|
||||
$row2('Email Address:', $d['businessfact_email_address'], 'SIC Code:', $d['businessfact_sic_code']);
|
||||
$row2('Address:', $d['businessfact_address_one'], 'License Date:', $d['businessfact_license_date']);
|
||||
$row2('City/State/Zip:', $d['businessfact_city_state_zip'], 'Home Based Business:', $d['businessfact_home_based_business']);
|
||||
$row2('County:', $d['businessfact_county_name'], 'Year Established:', $d['businessfact_year_established']);
|
||||
$row2('','', '','' );
|
||||
$row2('','', 'Business Fact ID:', $d['businessfact_legacy_id']);
|
||||
$row2('','', 'Entry Date:', $d['businessfact_entry_date']);
|
||||
|
||||
};
|
||||
|
||||
// Get the data for the report
|
||||
|
||||
$businessfacts = (new BusinessFacts())->getBusinessFactsPage($user_subscription_start_date, $user_subscription_end_date);
|
||||
|
||||
$this->AddPage('L', 'LETTER');
|
||||
|
||||
$marginL = 10;
|
||||
$marginT = 20; // below header area
|
||||
$pageW = $this->getPageWidth();
|
||||
$pageH = $this->getPageHeight();
|
||||
|
||||
$usableW = $pageW - ($marginL * 2);
|
||||
$usableH = $pageH - $marginT - 12;
|
||||
|
||||
$gapY = 6;
|
||||
|
||||
// Two rows per page
|
||||
$cardW = $usableW;
|
||||
$cardH = ($usableH - $gapY) / 2;
|
||||
|
||||
$index = 0;
|
||||
|
||||
foreach ($businessfacts->record as $businessfact) {
|
||||
|
||||
// Add a new page every 2 cards
|
||||
if ($index > 0 && $index % 2 === 0) {
|
||||
$this->AddPage('L', 'LETTER');
|
||||
}
|
||||
|
||||
$slot = $index % 2;
|
||||
|
||||
$x = $marginL;
|
||||
$y = $marginT + ($slot * ($cardH + $gapY));
|
||||
|
||||
// Map your XML fields to the card placeholders (use verbose)
|
||||
|
||||
$d = [
|
||||
// Card Header
|
||||
'businessfact_company' => trim((string) $businessfact->businessfact_company),
|
||||
|
||||
// Left Side of Card
|
||||
|
||||
'businessfact_contact_name' => trim((string) $businessfact->businessfact_contact_name),
|
||||
'businessfact_contact_title' => trim((string) $businessfact->businessfact_contact_title),
|
||||
'businessfact_company_phone' => $this->formatPhoneNumber(trim((string) $businessfact->businessfact_phone)),
|
||||
'businessfact_company_fax' => $this->formatPhoneNumber(trim((string) $businessfact->businessfact_fax)),
|
||||
'businessfact_email_address' => trim((string) $businessfact->businessfact_email_address),
|
||||
'businessfact_address_one' => trim((string) $businessfact->businessfact_address_one),
|
||||
'businessfact_city_state_zip' => trim((string) $businessfact->businessfact_city_verbose) . ', ' . trim((string) $businessfact->businessfact_state) . ' ' . trim((string) $businessfact->businessfact_zip),
|
||||
'businessfact_county_name' => trim((string) $businessfact->businessfact_county_name_verbose),
|
||||
|
||||
|
||||
// Right Side of Card
|
||||
'businessfact_business_class' => trim((string) $businessfact->businessfact_business_class_verbose),
|
||||
'businessfact_action' => trim((string) $businessfact->businessfact_action_verbose),
|
||||
'businessfact_employee_count' => trim((string) $businessfact->businessfact_employee_count),
|
||||
'businessfact_inception' => trim((string) $businessfact->businessfact_inception),
|
||||
'businessfact_sic_code' => trim((string) $businessfact->businessfact_sic_code). ' - ' .trim((string) $businessfact->businessfact_siccode_description_verbose),
|
||||
'businessfact_license_date' => trim((string) $businessfact->businessfact_license_date_verbose),
|
||||
'businessfact_home_based_business' => trim((string) $businessfact->businessfact_home_based_business),
|
||||
'businessfact_year_established' => trim((string) $businessfact->businessfact_year_established),
|
||||
'businessfact_legacy_id' => trim((string) $businessfact->businessfact_legacy_id),
|
||||
'businessfact_entry_date' => trim((string) $businessfact->businessfact_entry_date_verbose)
|
||||
];
|
||||
|
||||
$card($x, $y, $cardW, $cardH, $d);
|
||||
|
||||
$index++;
|
||||
}
|
||||
|
||||
|
||||
// -----------------
|
||||
// Render the Report
|
||||
// -----------------
|
||||
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
|
||||
// --------------
|
||||
// Return the pdf
|
||||
// --------------
|
||||
|
||||
if ($this->output_type == "string") {
|
||||
return $this->Output("{$subscription->record->subscription_full_title}.pdf", "S");
|
||||
} else {
|
||||
$this->Output("{$subscription->record->subscription_full_title}.pdf");
|
||||
}
|
||||
}
|
||||
|
||||
// ======
|
||||
// Header
|
||||
// ======
|
||||
|
||||
public function Header() {
|
||||
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
$this->Image("images/dec-international-logo.png", 250, 8, 20, 8);
|
||||
|
||||
$this->SetFont("Calibri", "B", 16);
|
||||
|
||||
$this->Cell(4, 0, "", 0, 0, "L");
|
||||
$this->Cell(0, 0, $this->report_header_title . " Report", 0, 0, "L");
|
||||
|
||||
$this->Ln(10);
|
||||
}
|
||||
|
||||
// ======
|
||||
// Footer
|
||||
// ======
|
||||
|
||||
public function Footer() {
|
||||
|
||||
$this->SetFont("Calibri ", "I", 8);
|
||||
|
||||
$X = $this->GetX();
|
||||
|
||||
$this->Cell(0, 10, "https://dec-international.com", 0, false, "C");
|
||||
|
||||
$this->SetX($X);
|
||||
|
||||
$this->Cell(40, 10, "Page " . $this->getAliasNumPage() . "/" . $this->getAliasNbPages(), 0, false, "L");
|
||||
$this->Cell(0, 10, "Generated: " . date("n/j/Y g:i A "), 0, false, "R"
|
||||
);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Stripe the printed line
|
||||
// =======================
|
||||
|
||||
private function stripeLine($pRowCount = 0, $pRowWidth = 0) {
|
||||
|
||||
$this->SetFillColor(($pRowCount % 2) ? 220 : 255);
|
||||
$X = $this->GetX();
|
||||
$this->Cell($pRowWidth, 0, "", 0, 0, "L", true);
|
||||
$this->SetX($X);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Format Raw Phone Number
|
||||
// =======================
|
||||
|
||||
public function formatPhoneNumber(string $phonenumber): string {
|
||||
|
||||
// Remove everything except digits
|
||||
$digits = preg_replace('/\D+/', '', $phonenumber);
|
||||
|
||||
// Handle leading country code (US)
|
||||
if (strlen($digits) === 11 && str_starts_with($digits, '1')) {
|
||||
$digits = substr($digits, 1);
|
||||
}
|
||||
|
||||
return substr($digits, 0, 3) . '-' .
|
||||
substr($digits, 3, 3) . '-' .
|
||||
substr($digits, 6, 4);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,356 @@
|
||||
<?php
|
||||
|
||||
require_once ("tcpdf/tcpdf.php");
|
||||
|
||||
// ===============================
|
||||
// Print Planning/Zoning Facts PDF
|
||||
// ===============================
|
||||
|
||||
class Print_PZFactsPDF extends Base {
|
||||
|
||||
// Variables.
|
||||
|
||||
private $output_type = "normal";
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct($output_type = "normal") {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
|
||||
$this->output_type = $output_type;
|
||||
}
|
||||
|
||||
// ================
|
||||
// Print the Report
|
||||
// ================
|
||||
|
||||
public function print() {
|
||||
|
||||
$report = new PZFacts_Print();
|
||||
|
||||
$report->subscription_serial = $_SESSION['subscription_serial'];
|
||||
$report->usersubscription_serial = $_SESSION['usersubscription_serial'];
|
||||
$report->output_type = $this->output_type;
|
||||
|
||||
ob_clean();
|
||||
|
||||
if ($this->output_type == "string") {
|
||||
return $report->render();
|
||||
} else {
|
||||
$report->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================
|
||||
// Class to Generate the .pdf
|
||||
// ==========================
|
||||
|
||||
class PZFacts_Print extends TCPDF {
|
||||
|
||||
// Variables
|
||||
|
||||
public $subscription_serial = 0;
|
||||
public $usersubscription_serial = 0;
|
||||
public $report_header_title = "";
|
||||
public $first_page = true;
|
||||
public $output_type = "normal";
|
||||
|
||||
// ===============
|
||||
// Debug an Object
|
||||
// ===============
|
||||
|
||||
public function debug($object = "") {
|
||||
|
||||
echo "<pre>";
|
||||
print_r($object);
|
||||
exit();
|
||||
}
|
||||
|
||||
// =================
|
||||
// Render the Report
|
||||
// =================
|
||||
|
||||
public function render() {
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$subscription = (new Subscriptions())->getSubscription($this->subscription_serial);
|
||||
|
||||
if ($subscription->count() === 0) {
|
||||
$this->logError("Invalid Subscription ({$this->subscription_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$userssubscription = (new Users())->getUserSubscription($this->usersubscription_serial);
|
||||
|
||||
$user_subscription_start_date = $userssubscription->record->usersubscription_start_date;
|
||||
$user_subscription_end_date = $userssubscription->record->usersubscription_end_date;
|
||||
|
||||
$planningzoningfacts = (new PlanningAndZoningFacts())->getPZFactsPage($user_subscription_start_date, $user_subscription_end_date);
|
||||
|
||||
// Set report defaults
|
||||
$this->report_header_title = $subscription->record->subscription_full_title;
|
||||
$this->title = $subscription->record->subscription_full_title;
|
||||
|
||||
$this->SetFont("Calibri");
|
||||
$this->SetMargins(2, 26, 10);
|
||||
$this->SetHeaderMargin(10);
|
||||
$this->SetFooterMargin(10);
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
$card = function (float $x, float $y, float $w, float $h, array $d) {
|
||||
|
||||
// Card background + border
|
||||
$this->SetDrawColor(210, 210, 210);
|
||||
$this->SetFillColor(250, 250, 250);
|
||||
$this->Rect($x, $y, $w, $h, 'DF');
|
||||
|
||||
// Header bar
|
||||
$headerH = 10;
|
||||
$this->SetFillColor(30, 93, 168); // Bootstrap-ish primary
|
||||
$this->Rect($x, $y, $w, $headerH, 'F');
|
||||
|
||||
// Header text
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('helvetica', 'B', 11);
|
||||
$this->SetXY($x + 3, $y + 2.5);
|
||||
$this->Cell($w - 6, 0, "Project Name: {$d['pzfact_project_name']}", 0, 0, 'L', false);
|
||||
|
||||
// Body
|
||||
$this->SetTextColor(20, 20, 20);
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
|
||||
$padX = 3;
|
||||
$padY = 3;
|
||||
|
||||
$curY = $y + $headerH + $padY;
|
||||
|
||||
$bodyX = $x + $padX;
|
||||
$bodyW = $w - ($padX * 2);
|
||||
|
||||
$colGap = 6;
|
||||
$colW = ($bodyW - $colGap) / 2;
|
||||
|
||||
$leftX = $bodyX;
|
||||
$rightX = $bodyX + $colW + $colGap;
|
||||
|
||||
$labelW = 38; // tweak to taste
|
||||
|
||||
$row2 = function (string $l1, string $v1, string $l2, string $v2) use (&$curY, $leftX, $rightX, $colW, $labelW) {
|
||||
|
||||
$yStart = $curY;
|
||||
|
||||
// LEFT Cell
|
||||
|
||||
$this->SetXY($leftX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $l1, 0, 0, 'L');
|
||||
$this->Cell(2, 0, '', 0, 0); // spacer
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($colW - $labelW - 2, 0, $v1, 0, 'L', false, 1);
|
||||
|
||||
$yAfterLeft = $this->GetY();
|
||||
|
||||
// RIGHT Cell (reset to same starting Y)
|
||||
|
||||
$this->SetXY($rightX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $l2, 0, 0, 'L');
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($colW - $labelW, 0, $v2, 0, 'L', false, 1);
|
||||
$yAfterRight = $this->GetY();
|
||||
|
||||
// Advance cursor to max height used
|
||||
$curY = max($yAfterLeft, $yAfterRight) + 1;
|
||||
};
|
||||
|
||||
$row1 = function (string $label, string $value) use (&$curY, $leftX, $bodyW, $labelW) {
|
||||
|
||||
$yStart = $curY;
|
||||
|
||||
$this->SetXY($leftX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $label, 0, 0, 'L');
|
||||
$this->Cell(2, 0, '', 0, 0); // spacer
|
||||
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($bodyW - $labelW - 10, 0, $value, 0, 'L', false, 1);
|
||||
|
||||
$curY = $this->GetY() + 1;
|
||||
};
|
||||
|
||||
$row2('Project Description:', $d['pzfact_project_description'], 'Project Type:', $d['pzfact_project_type']);
|
||||
$row2('Architect/Engineer: ', $d['pzfact_professional_name'], 'Estimated Project Value:', $d['pzfact_dollar_value']);
|
||||
$row2('', '', 'District:', $d['pzfact_district']);
|
||||
$row2('Owner Name: ', $d['pzfact_owner_name'], 'Land Lot:', $d['pzfact_land_lot']);
|
||||
$row2('Owner Address: ', $d['pzfact_owner_address'], 'Action Code:', $d['pzfact_action_code']);
|
||||
$row2('Owner Phone: ', $d['pzfact_owner_phone'], 'Action Date:', $d['pzfact_action_date']);
|
||||
$row2('', '', 'Lot Acres:', $d['pzfact_acres']);
|
||||
$row2('', '', '', '');
|
||||
|
||||
$row1('Status:', $d['pzfact_status']);
|
||||
};
|
||||
|
||||
// Get the data for the report
|
||||
|
||||
$this->AddPage('L', 'LETTER');
|
||||
|
||||
$marginL = 10;
|
||||
$marginT = 20; // below header area
|
||||
$pageW = $this->getPageWidth();
|
||||
$pageH = $this->getPageHeight();
|
||||
|
||||
$usableW = $pageW - ($marginL * 2);
|
||||
$usableH = $pageH - $marginT - 12; // leave footer space
|
||||
|
||||
$gapY = 6;
|
||||
|
||||
// Two rows per page
|
||||
$cardW = $usableW;
|
||||
$cardH = ($usableH - $gapY) / 2;
|
||||
|
||||
$index = 0;
|
||||
|
||||
foreach ($planningzoningfacts->record as $planningzoningfact) {
|
||||
|
||||
// Add a new page every 2 cards
|
||||
if ($index > 0 && $index % 2 === 0) {
|
||||
$this->AddPage('L', 'LETTER');
|
||||
}
|
||||
|
||||
$slot = $index % 2;
|
||||
|
||||
$x = $marginL;
|
||||
$y = $marginT + ($slot * ($cardH + $gapY));
|
||||
|
||||
// Map your XML fields to the card placeholders (use verbose)
|
||||
|
||||
$d = [
|
||||
// Left Side of Card
|
||||
'subscription_serial' => trim((string) $planningzoningfact->pzfact_legacy_id),
|
||||
'pzfact_project_description' => trim((string) $planningzoningfact->pzfact_project_description),
|
||||
'pzfact_project_name' => trim((string) $planningzoningfact->pzfact_project_name),
|
||||
'pzfact_project_type' => trim((string) $planningzoningfact->pzfact_project_type_verbose),
|
||||
'pzfact_professional_name' => trim((string) $planningzoningfact->pzfact_professional_name),
|
||||
'pzfact_owner_name' => trim((string) $planningzoningfact->pzfact_owner_name),
|
||||
'pzfact_owner_address' => trim((string) $planningzoningfact->pzfact_owner_address),
|
||||
'pzfact_owner_phone' => $this->formatPhoneNumber(trim((string) $planningzoningfact->pzfacts_owner_phone)),
|
||||
// Right Side of Card
|
||||
'pzfact_dollar_value' => trim((string) $planningzoningfact->pzfact_dollar_value),
|
||||
'pzfact_district' => trim((string) $planningzoningfact->pzfact_district),
|
||||
'pzfact_land_lot' => trim((string) $planningzoningfact->pzfact_land_lot),
|
||||
'pzfact_action_code' => trim((string) $planningzoningfact->pzfact_action_code_verbose),
|
||||
'pzfact_action_date' => trim((string) $planningzoningfact->pzfact_action_date_verbose),
|
||||
'pzfact_acres' => trim((string) $planningzoningfact->pzfact_acres),
|
||||
'pzfact_entry_date' => trim((string) $planningzoningfact->pzfact_entry_date_verbose),
|
||||
'pzfact_status' => trim((string) $planningzoningfact->pzfact_status),
|
||||
'pzfact_dollar_value' => trim((string) $planningzoningfact->pzfact_dollar_value),
|
||||
];
|
||||
|
||||
$card($x, $y, $cardW, $cardH, $d);
|
||||
|
||||
$index++;
|
||||
}
|
||||
|
||||
|
||||
// -----------------
|
||||
// Render the Report
|
||||
// -----------------
|
||||
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
|
||||
// --------------
|
||||
// Return the pdf
|
||||
// --------------
|
||||
|
||||
if ($this->output_type == "string") {
|
||||
return $this->Output("{$subscription->record->subscription_full_title}.pdf", "S");
|
||||
} else {
|
||||
$this->Output("{$subscription->record->subscription_full_title}.pdf");
|
||||
}
|
||||
}
|
||||
|
||||
// ======
|
||||
// Header
|
||||
// ======
|
||||
|
||||
public function Header() {
|
||||
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
$this->Image("images/dec-international-logo.png", 250, 8, 20, 8);
|
||||
|
||||
$this->SetFont("Calibri", "B", 16);
|
||||
|
||||
$this->Cell(4, 0, "", 0, 0, "L");
|
||||
$this->Cell(0, 0, $this->report_header_title . " Report", 0, 0, "L");
|
||||
|
||||
$this->Ln(10);
|
||||
}
|
||||
|
||||
// ======
|
||||
// Footer
|
||||
// ======
|
||||
|
||||
public function Footer() {
|
||||
|
||||
|
||||
|
||||
$this->SetFont("Calibri ", "I", 8);
|
||||
|
||||
$X = $this->GetX();
|
||||
|
||||
$this->Cell(0, 10, "DEC International ", 0, false, "C");
|
||||
|
||||
$this->SetX($X);
|
||||
|
||||
$this->Cell(40, 10, "Page " . $this->getAliasNumPage() . "/" . $this->getAliasNbPages(), 0, false, "L");
|
||||
$this->Cell(0, 10, date("n/j/Y g:i A "), 0, false, "R"
|
||||
);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Stripe the printed line
|
||||
// =======================
|
||||
|
||||
private function stripeLine($pRowCount = 0, $pRowWidth = 0) {
|
||||
|
||||
$this->SetFillColor(($pRowCount % 2) ? 220 : 255);
|
||||
$X = $this->GetX();
|
||||
$this->Cell($pRowWidth, 0, "", 0, 0, "L", true);
|
||||
$this->SetX($X);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Format Raw Phone Number
|
||||
// =======================
|
||||
|
||||
public function formatPhoneNumber(string $phonenumber): string {
|
||||
|
||||
// Remove everything except digits
|
||||
$digits = preg_replace('/\D+/', '', $phonenumber);
|
||||
|
||||
// Handle leading country code (US)
|
||||
if (strlen($digits) === 11 && str_starts_with($digits, '1')) {
|
||||
$digits = substr($digits, 1);
|
||||
}
|
||||
|
||||
// // Must be exactly 10 digits to format
|
||||
// if (strlen($digits) !== 10) {
|
||||
// return $phonenumber; // return original if invalid
|
||||
// }
|
||||
|
||||
return substr($digits, 0, 3) . '-' .
|
||||
substr($digits, 3, 3) . '-' .
|
||||
substr($digits, 6, 4);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,346 @@
|
||||
<?php
|
||||
|
||||
require_once ("tcpdf/tcpdf.php");
|
||||
|
||||
// ======================
|
||||
// Print Permit Facts PDF
|
||||
// ======================
|
||||
|
||||
class Print_PermitFactsPDF extends Base {
|
||||
|
||||
// Variables.
|
||||
|
||||
private $output_type = "normal";
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct($output_type = "normal") {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
|
||||
$this->output_type = $output_type;
|
||||
}
|
||||
|
||||
// ================
|
||||
// Print the Report
|
||||
// ================
|
||||
|
||||
public function print() {
|
||||
|
||||
$report = new PermitFacts_Print();
|
||||
|
||||
$report->subscription_serial = $_SESSION['subscription_serial'];
|
||||
$report->usersubscription_serial = $_SESSION['usersubscription_serial'];
|
||||
$report->output_type = $this->output_type;
|
||||
|
||||
ob_clean();
|
||||
|
||||
if ($this->output_type == "string") {
|
||||
return $report->render();
|
||||
} else {
|
||||
$report->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================
|
||||
// Class to Generate the .pdf
|
||||
// ==========================
|
||||
|
||||
class PermitFacts_Print extends TCPDF {
|
||||
|
||||
// Variables
|
||||
|
||||
public $subscription_serial = 0;
|
||||
public $usersubscription_serial = 0;
|
||||
public $report_header_title = "";
|
||||
public $first_page = true;
|
||||
public $output_type = "normal";
|
||||
|
||||
// ================
|
||||
// Debug an Object.
|
||||
// ================
|
||||
|
||||
public function debug($object = "") {
|
||||
|
||||
echo "<pre>";
|
||||
print_r($object);
|
||||
exit();
|
||||
}
|
||||
|
||||
// =================
|
||||
// Render the Report
|
||||
// =================
|
||||
|
||||
public function render() {
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$subscription = (new Subscriptions())->getSubscription($this->subscription_serial);
|
||||
|
||||
if ($subscription->count() === 0) {
|
||||
$this->logError("Invalid Subscription ({$this->subscription_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$userssubscription = (new Users())->getUserSubscription($this->usersubscription_serial);
|
||||
|
||||
$user_subscription_start_date = $userssubscription->record->usersubscription_start_date;
|
||||
$user_subscription_end_date = $userssubscription->record->usersubscription_end_date;
|
||||
|
||||
// Set report defaults
|
||||
$this->report_header_title = $subscription->record->subscription_full_title;
|
||||
$this->title = $subscription->record->subscription_full_title;
|
||||
|
||||
$this->SetFont("Calibri");
|
||||
$this->SetMargins(2, 26, 10);
|
||||
$this->SetHeaderMargin(10);
|
||||
$this->SetFooterMargin(10);
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
// $this->addPage("L", "LETTER");
|
||||
|
||||
$card = function (float $x, float $y, float $w, float $h, array $d) {
|
||||
|
||||
// Card background + border
|
||||
$this->SetDrawColor(210, 210, 210);
|
||||
$this->SetFillColor(250, 250, 250);
|
||||
$this->Rect($x, $y, $w, $h, 'DF');
|
||||
|
||||
// Header bar
|
||||
$headerH = 10;
|
||||
$this->SetFillColor(30, 93, 168); // Bootstrap-ish primary
|
||||
$this->Rect($x, $y, $w, $headerH, 'F');
|
||||
|
||||
// Header text
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('helvetica', 'B', 11);
|
||||
$this->SetXY($x + 3, $y + 2.5);
|
||||
$this->Cell($w - 6, 0, "Project Name: {$d['permitfact_project_name']}", 0, 0, 'L', false);
|
||||
|
||||
// Body
|
||||
$this->SetTextColor(20, 20, 20);
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
|
||||
$padX = 3;
|
||||
$padY = 3;
|
||||
|
||||
$curY = $y + $headerH + $padY;
|
||||
|
||||
$bodyX = $x + $padX;
|
||||
$bodyW = $w - ($padX * 2);
|
||||
|
||||
$colGap = 6;
|
||||
$colW = ($bodyW - $colGap) / 2;
|
||||
|
||||
$leftX = $bodyX;
|
||||
$rightX = $bodyX + $colW + $colGap;
|
||||
|
||||
$labelW = 22; // tweak to taste
|
||||
|
||||
$row2 = function (string $l1, string $v1, string $l2, string $v2) use (&$curY, $leftX, $rightX, $colW, $labelW) {
|
||||
$yStart = $curY;
|
||||
|
||||
// LEFT cell
|
||||
$this->SetXY($leftX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $l1, 0, 0, 'L');
|
||||
$this->Cell(2, 0, '', 0, 0); // spacer
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($colW - $labelW, 0, $v1, 0, 'L', false, 1);
|
||||
$yAfterLeft = $this->GetY();
|
||||
|
||||
// RIGHT cell (reset to same starting Y)
|
||||
$this->SetXY($rightX, $yStart);
|
||||
$this->SetFont('helvetica', 'B', 9);
|
||||
$this->Cell($labelW, 0, $l2, 0, 0, 'L');
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
$this->MultiCell($colW - $labelW, 0, $v2, 0, 'L', false, 1);
|
||||
$yAfterRight = $this->GetY();
|
||||
|
||||
// Advance cursor to max height used
|
||||
$curY = max($yAfterLeft, $yAfterRight) + 1;
|
||||
};
|
||||
|
||||
// Two-column rows (swap these however you like)
|
||||
$row2('Permit Number: ', $d['permitfact_permit_number'], 'Permit Date:', $d['permitfact_permit_date']);
|
||||
$row2('Project Address: ', $d['permitfact_project_address'], 'Project Type:', $d['permitfact_project_type']);
|
||||
$row2('City/State/Zip:', $d['permitfact_project_city_state_zip'], 'Work Type:', $d['permitfact_work_type']);
|
||||
$row2('Project County:', $d['permitfact_county_name'], 'Building Type:', $d['permitfact_building_type']);
|
||||
$row2('', '', 'Value:', $d['permitfact_value']);
|
||||
$row2('Company:', $d['permitfact_company'], 'Entry Date:', $d['permitfact_entry_date']);
|
||||
$row2('Address:', $d['permitfact_company_address'], 'Square Foot: ', $d['permitfact_size']);
|
||||
$row2('City/State/Zip:', $d['permitfact_company_city_state_zip'], '', '');
|
||||
$row2('Company Phone:', $d['permitfact_company_phone'], '', '');
|
||||
$row2('', '', '', '');
|
||||
$row2('Owner:', $d['permitfact_owner_name'], '', '');
|
||||
$row2('Owner Phone:', $d['permitfact_owner_phone'], '', '');
|
||||
};
|
||||
|
||||
// Get the data for the report
|
||||
|
||||
$permits = (new PermitFacts())->getPermitFactsPage($user_subscription_start_date, $user_subscription_end_date);
|
||||
|
||||
$this->AddPage('L', 'LETTER');
|
||||
|
||||
$marginL = 10;
|
||||
$marginT = 20; // below header area
|
||||
$pageW = $this->getPageWidth();
|
||||
$pageH = $this->getPageHeight();
|
||||
|
||||
$usableW = $pageW - ($marginL * 2);
|
||||
$usableH = $pageH - $marginT - 12; // leave footer space
|
||||
|
||||
$gapY = 6;
|
||||
|
||||
// Two rows per page
|
||||
$cardW = $usableW;
|
||||
$cardH = ($usableH - $gapY) / 2;
|
||||
|
||||
$index = 0;
|
||||
|
||||
foreach ($permits->record as $permit) {
|
||||
|
||||
// Add a new page every 2 cards
|
||||
if ($index > 0 && $index % 2 === 0) {
|
||||
$this->AddPage('L', 'LETTER');
|
||||
}
|
||||
|
||||
$slot = $index % 2;
|
||||
|
||||
$x = $marginL;
|
||||
$y = $marginT + ($slot * ($cardH + $gapY));
|
||||
|
||||
// Map your XML fields to the card placeholders (use verbose)
|
||||
$valueRaw = trim((string) $permit->permitfact_value);
|
||||
$value = ($valueRaw !== '') ? '$' . number_format((float) $valueRaw, 2) : '';
|
||||
|
||||
$d = [
|
||||
// Left Side of Card
|
||||
'permitfact_serial' => trim((string) $permit->permitfact_serial),
|
||||
'permitfact_project_name' => trim((string) $permit->permitfact_project_name),
|
||||
'permitfact_permit_number' => trim((string) $permit->permitfact_permit_number),
|
||||
'permitfact_project_address' => trim((string) $permit->permitfact_project_address),
|
||||
'permitfact_project_city_state_zip' => trim((string) $permit->project_city_verbose) . ', ' . trim((string) $permit->permitfact_project_state) . ' ' . trim((string) $permit->permitfact_project_zip),
|
||||
'permitfact_county_name' => trim((string) $permit->permitfact_county_name_verbose),
|
||||
'permitfact_company' => trim((string) $permit->permitfact_company),
|
||||
'permitfact_company_address' => trim((string) $permit->permitfact_address),
|
||||
'permitfact_company_city_state_zip' => trim((string) $permit->permitfact_city_verbose) . ', ' . trim((string) $permit->permitfact_state) . ' ' . trim((string) $permit->permitfact_zip),
|
||||
'permitfact_company_phone' => $this->formatPhoneNumber(trim((string) $permit->permitfact_phone)),
|
||||
'permitfact_owner_name' => trim((string) $permit->permitfact_owner_name),
|
||||
'permitfact_owner_phone' => $this->formatPhoneNumber(trim((string) $permit->permitfact_owner_phone)),
|
||||
// Right Side of Card
|
||||
'permitfact_permit_date' => trim((string) $permit->permitfact_permit_date_verbose),
|
||||
'permitfact_entry_date' => trim((string) $permit->permitfact_entry_date_verbose),
|
||||
'permitfact_project_type' => trim((string) $permit->permitfact_project_type_verbose),
|
||||
'permitfact_value' => $value,
|
||||
'permitfact_building_type' => trim((string) $permit->permitfact_building_type_verbose),
|
||||
'permitfact_work_type' => trim((string) $permit->permitfact_work_type_verbose),
|
||||
'permitfact_size' => trim((string) $permit->permitfact_size),
|
||||
];
|
||||
|
||||
$card($x, $y, $cardW, $cardH, $d);
|
||||
|
||||
$index++;
|
||||
}
|
||||
|
||||
|
||||
// -----------------
|
||||
// Render the Report
|
||||
// -----------------
|
||||
|
||||
$this->SetFont('helvetica', '', 9);
|
||||
|
||||
// --------------
|
||||
// Return the pdf
|
||||
// --------------
|
||||
|
||||
if ($this->output_type == "string") {
|
||||
return $this->Output("{$subscription->record->subscription_full_title}.pdf", "S");
|
||||
} else {
|
||||
$this->Output("{$subscription->record->subscription_full_title}.pdf");
|
||||
}
|
||||
}
|
||||
|
||||
// ======
|
||||
// Header
|
||||
// ======
|
||||
|
||||
public function Header() {
|
||||
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
$this->Image("images/dec-international-logo.png", 250, 8, 20, 8);
|
||||
|
||||
$this->SetFont("Calibri", "B", 16);
|
||||
|
||||
$this->Cell(4, 0, "", 0, 0, "L");
|
||||
$this->Cell(0, 0, $this->report_header_title . " Report", 0, 0, "L");
|
||||
|
||||
$this->Ln(10);
|
||||
}
|
||||
|
||||
// ======
|
||||
// Footer
|
||||
// ======
|
||||
|
||||
public function Footer() {
|
||||
|
||||
|
||||
|
||||
$this->SetFont("Calibri ", "I", 8);
|
||||
|
||||
$X = $this->GetX();
|
||||
|
||||
$this->Cell(0, 10, "DEC International ", 0, false, "C");
|
||||
|
||||
$this->SetX($X);
|
||||
|
||||
$this->Cell(40, 10, "Page " . $this->getAliasNumPage() . "/" . $this->getAliasNbPages(), 0, false, "L");
|
||||
$this->Cell(0, 10, date("n/j/Y g:i A "), 0, false, "R"
|
||||
);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Stripe the printed line
|
||||
// =======================
|
||||
|
||||
private function stripeLine($pRowCount = 0, $pRowWidth = 0) {
|
||||
|
||||
$this->SetFillColor(($pRowCount % 2) ? 220 : 255);
|
||||
$X = $this->GetX();
|
||||
$this->Cell($pRowWidth, 0, "", 0, 0, "L", true);
|
||||
$this->SetX($X);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Format Raw Phone Number
|
||||
// =======================
|
||||
|
||||
public function formatPhoneNumber(string $phonenumber): string {
|
||||
|
||||
// Remove everything except digits
|
||||
$digits = preg_replace('/\D+/', '', $phonenumber);
|
||||
|
||||
// Handle leading country code (US)
|
||||
if (strlen($digits) === 11 && str_starts_with($digits, '1')) {
|
||||
$digits = substr($digits, 1);
|
||||
}
|
||||
|
||||
// // Must be exactly 10 digits to format
|
||||
// if (strlen($digits) !== 10) {
|
||||
// return $phonenumber; // return original if invalid
|
||||
// }
|
||||
|
||||
return substr($digits, 0, 3) . '-' .
|
||||
substr($digits, 3, 3) . '-' .
|
||||
substr($digits, 6, 4);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,370 @@
|
||||
<?php
|
||||
|
||||
require_once ("tcpdf/tcpdf.php");
|
||||
|
||||
// ============================
|
||||
// Print a User Summary Sheet
|
||||
// ============================
|
||||
|
||||
class Print_UserSummary extends Base {
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct($output_type = "normal") {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
}
|
||||
|
||||
// ================
|
||||
// Print the Report
|
||||
// ================
|
||||
|
||||
public function print($user_serial = 0, $output_type = "normal") {
|
||||
|
||||
$report = new User_Summary();
|
||||
|
||||
$report->user_serial = $_SESSION[self::REPORTS_POST]["user_serial"] ?? $user_serial;
|
||||
|
||||
$report->output_type = $output_type;
|
||||
|
||||
ob_clean();
|
||||
|
||||
if ($output_type == "string") {
|
||||
return $report->render();
|
||||
} else {
|
||||
$report->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================
|
||||
// Class to Generate the .pdf
|
||||
// ==========================
|
||||
|
||||
class User_Summary extends TCPDF {
|
||||
|
||||
// Variables
|
||||
|
||||
public $user_serial = 0;
|
||||
public $first_page = true;
|
||||
public $output_type = "normal";
|
||||
|
||||
// ================
|
||||
// Debug an Object.
|
||||
// ================
|
||||
|
||||
public function debug($object = "") {
|
||||
|
||||
echo "<pre>";
|
||||
print_r($object);
|
||||
exit();
|
||||
}
|
||||
|
||||
// =================
|
||||
// Render the Report
|
||||
// =================
|
||||
|
||||
public function render() {
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
// Get the data for the report
|
||||
|
||||
$user = (new Users())->getUser($this->user_serial);
|
||||
|
||||
if ($user->count() == 0) {
|
||||
$this->logError("Invalid User ({$this->user_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$usernotes = (new Notes())->getAllNotes($this->user_serial);
|
||||
$subscriptions = (new Subscriptions())->getUsersActiveSubscriptions($this->user_serial);
|
||||
$userloginactivity = (new Users())->getLoginActivity($user->record->user_name);
|
||||
|
||||
// Set report defaults
|
||||
|
||||
$this->title = "User Summary Sheet";
|
||||
|
||||
$this->SetFont("Calibri");
|
||||
$this->SetMargins(10, 25, 10);
|
||||
$this->SetHeaderMargin(10);
|
||||
$this->SetFooterMargin(10);
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
$this->addPage("P", "LETTER");
|
||||
|
||||
// ----------------------
|
||||
// User Summary Details
|
||||
// ----------------------
|
||||
|
||||
$user = $user->record ?? "";
|
||||
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
$this->Cell(25, 0, "Name:", 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
$this->Cell(80, 0, $user->user_client_name, 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
$this->Cell(25, 0, "Created:", 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
$this->Cell(80, 0, $user->user_created_verbose, 0, 1, "L", false, "", 3);
|
||||
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
$this->Cell(25, 0, "Main Email:", 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
$this->Cell(80, 0, $user->user_email, 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
$this->Cell(25, 0, "Created By:", 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
$this->Cell(80, 0, $user->user_creator, 0, 1, "L", false, "", 3);
|
||||
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
$this->Cell(25, 0, "User Name:", 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
$this->Cell(80, 0, $user->user_name, 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
$this->Cell(25, 0, "Changed", 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
$this->Cell(80, 0, $user->user_changed_verbose, 0, 1, "L", false, "", 3);
|
||||
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
$this->Cell(25, 0, "Roll:", 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
$this->Cell(80, 0, $user->user_role, 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
$this->Cell(25, 0, "Changed By:", 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
$this->Cell(80, 0, $user->user_changer, 0, 1, "L", false, "", 3);
|
||||
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
$this->Cell(25, 0, "Change Password:", 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
|
||||
$user_change_password = ($user->user_change_password == 1) ? "Yes" : "No";
|
||||
|
||||
$this->Cell(80, 0, $user_change_password, 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
$this->Cell(25, 0, "Last Login:", 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
$this->Cell(80, 0, $user->user_login_verbose, 0, 1, "L", false, "", 3);
|
||||
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
$this->Cell(25, 0, "", 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
$this->Cell(80, 0, "", 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
$this->Cell(25, 0, "Active Status:", 0, 0, "L", false, "", 3);
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
|
||||
$user_active = ($user->user_active == 1) ? "Active" : "Inactive";
|
||||
$this->Cell(80, 0, $user_active, 0, 1, "L", false, "", 3);
|
||||
|
||||
// ----------------------------------
|
||||
// Rectangle around the Users Details
|
||||
// ----------------------------------
|
||||
|
||||
$this->RoundedRect(10, 23, 190, $this->GetY() - 21, 1.50, "1111");
|
||||
|
||||
// --------------
|
||||
// Login Activity
|
||||
// --------------
|
||||
|
||||
$this->Ln(7);
|
||||
|
||||
$this->SetFont("Calibri", "B", 12);
|
||||
$this->Cell(0, 0, "Login Activity", 0, 1, "L", false, "", 3);
|
||||
$this->Ln(3);
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
|
||||
$this->Cell(30, 0, "Date", "B", 0, "L", false, "", 3);
|
||||
$this->Cell(20, 0, "IP Address", "B", 0, "L", false, "", 3);
|
||||
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
|
||||
$this->Ln(6);
|
||||
|
||||
if ($userloginactivity->count() == 0) {
|
||||
|
||||
$this->Cell(0, 0, "No Login Activity...", 0, 1, "L", false, "", 3);
|
||||
} else {
|
||||
|
||||
foreach ($userloginactivity as $userlogin) {
|
||||
|
||||
$this->Cell(30, 0, $userlogin->journal_timestamp_verbose, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(20, 0, $userlogin->journal_ip, 0, 0, "L", false, "", 3);
|
||||
|
||||
$this->Ln(4);
|
||||
|
||||
if ($this->GetY() > 265) {
|
||||
|
||||
$this->AddPage("P", "LETTER");
|
||||
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
|
||||
$this->Cell(30, 0, "Date", "B", 0, "L", false, "", 3);
|
||||
$this->Cell(20, 0, "Origin", "B", 0, "L", false, "", 3);
|
||||
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
|
||||
$this->Ln(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----
|
||||
// Notes
|
||||
// -----
|
||||
|
||||
$this->Ln(5);
|
||||
|
||||
$this->SetFont("Calibri", "B", 12);
|
||||
$this->Cell(0, 0, "Notes", 0, 1, "L", false, "", 3);
|
||||
$this->Ln(3);
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
|
||||
$this->Cell(30, 0, "Date", "B", 0, "L", false, "", 3);
|
||||
$this->Cell(40, 0, "Origin", "B", 0, "L", false, "", 3);
|
||||
$this->Cell(110, 0, "Note", "B", 0, "L", false, "", 3);
|
||||
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
|
||||
$this->Ln(6);
|
||||
|
||||
if ($usernotes->count() == 0) {
|
||||
|
||||
$this->Cell(0, 0, "There are no Notes...", 0, 1, "L", false, "", 3);
|
||||
} else {
|
||||
|
||||
foreach ($usernotes as $note) {
|
||||
|
||||
$this->Cell(30, 0, $note->note_timestamp_verbose, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(40, 0, $note->note_origin, 0, 0, "L", false, "", 3);
|
||||
$this->MultiCell(110, 0, $note->note_text, 0, "L", false, 1, "", "", true);
|
||||
|
||||
if ($this->GetY() > 265) {
|
||||
|
||||
$this->AddPage("P", "LETTER");
|
||||
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
|
||||
$this->Cell(30, 0, "Date", "B", 0, "L", false, "", 3);
|
||||
$this->Cell(40, 0, "Origin", "B", 0, "L", false, "", 3);
|
||||
$this->Cell(110, 0, "Note", "B", 0, "L", false, "", 3);
|
||||
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
|
||||
$this->Ln(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------
|
||||
// Subscriptions
|
||||
// -------------
|
||||
$this->Ln(7);
|
||||
|
||||
$this->SetFont("Calibri", "B", 12);
|
||||
$this->Cell(0, 0, "Subscriptions", 0, 1, "L", false, "", 3);
|
||||
$this->Ln(3);
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
|
||||
$this->Cell(75, 0, "Description", "B", 0, "L", false, "", 3);
|
||||
$this->Cell(20, 0, "End Date", "B", 0, "L", false, "", 3);
|
||||
$this->Cell(10, 0, "Status", "B", 0, "L", false, "", 3);
|
||||
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
|
||||
$this->Ln(6);
|
||||
|
||||
if ($subscriptions->count() == 0) {
|
||||
|
||||
$this->Cell(0, 0, "There are no Subscriptions...", 0, 1, "L", false, "", 3);
|
||||
} else {
|
||||
|
||||
foreach ($subscriptions as $subscription) {
|
||||
|
||||
$this->Cell(75, 0, $subscription->subscription_title . " " . $subscription->subscription_description, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(20, 0, $subscription->usersubscription_stop_date_verbose, 0, 0, "L", false, "", 3);
|
||||
$this->Cell(10, 0, $subscription->usersubscription_status, 0, 0, "L", false, "", 3);
|
||||
|
||||
$this->Ln(4);
|
||||
|
||||
if ($this->GetY() > 265) {
|
||||
|
||||
$this->AddPage("P", "LETTER");
|
||||
|
||||
$this->SetFont("Calibri", "B", 10);
|
||||
|
||||
$this->Cell(75, 0, "Description", "B", 0, "L", false, "", 3);
|
||||
$this->Cell(20, 0, "End Date", "B", 0, "L", false, "", 3);
|
||||
$this->Cell(10, 0, "Status", "B", 0, "L", false, "", 3);
|
||||
|
||||
$this->SetFont("Calibri", "", 10);
|
||||
|
||||
$this->Ln(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------
|
||||
// Return the pdf
|
||||
// --------------
|
||||
|
||||
if ($this->output_type == "string") {
|
||||
return $this->Output("UserSummarySheet.pdf", "S");
|
||||
} else {
|
||||
$this->Output("UserSummarySheet.pdf");
|
||||
}
|
||||
}
|
||||
|
||||
// ======
|
||||
// Header
|
||||
// ======
|
||||
|
||||
public function Header() {
|
||||
|
||||
$this->setCellPaddings(0, 0, 0, 0);
|
||||
$this->setCellMargins(2, 0, 0, 0);
|
||||
|
||||
$this->Image('images/dec-international-logo.png', 10, 7, 25, 10);
|
||||
|
||||
$this->SetFont("Calibri", "B", 16);
|
||||
|
||||
$this->Cell(0, 6, "User Summary Sheet", 0, 1, "C");
|
||||
}
|
||||
|
||||
// ======
|
||||
// Footer
|
||||
// ======
|
||||
|
||||
public function Footer() {
|
||||
|
||||
$this->SetFont("Calibri", "I", 8);
|
||||
|
||||
$X = $this->GetX();
|
||||
|
||||
$this->Cell(0, 10, "DEC-International, LLC", 0, false, "C");
|
||||
|
||||
$this->SetX($X);
|
||||
|
||||
$this->Cell(40, 10, "Page " . $this->getAliasNumPage() . "/" . $this->getAliasNbPages(), 0, false, "L");
|
||||
$this->Cell(0, 10, date("Y-m-d g:i A"), 0, false, "R");
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Stripe the printed line
|
||||
// =======================
|
||||
|
||||
private function stripeLine($pRowCount = 0, $pRowWidth = 0) {
|
||||
|
||||
$this->SetFillColor(($pRowCount % 2) ? 220 : 255);
|
||||
$X = $this->GetX();
|
||||
$this->Cell($pRowWidth, 0, "", 0, 0, "L", true);
|
||||
$this->SetX($X);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user