diff --git a/agent/clients.php b/agent/clients.php index af420dc1..954fc632 100644 --- a/agent/clients.php +++ b/agent/clients.php @@ -338,10 +338,12 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $location_city = escapeHtml($row['location_city']); $location_state = escapeHtml($row['location_state']); $location_zip = escapeHtml($row['location_zip']); - if (empty($location_address) && empty($location_city) && empty($location_state) && empty($location_zip)) { + $location_address_lines = formatAddress($location_address, $location_city, $location_state, $location_zip, '', '
'); + if ($location_address_lines === '') { $location_address_display = "-"; } else { - $location_address_display = "
$location_address
$location_city $location_state $location_zip
$location_country
"; + $location_country_line = $location_country ? "
$location_country
" : ''; + $location_address_display = "
$location_address_lines$location_country_line
"; } $contact_id = intval($row['contact_id']); $contact_name = escapeHtml($row['contact_name']); diff --git a/agent/includes/inc_client_top_head.php b/agent/includes/inc_client_top_head.php index 53bb0cc5..cb60de38 100644 --- a/agent/includes/inc_client_top_head.php +++ b/agent/includes/inc_client_top_head.php @@ -74,7 +74,7 @@ " target="_blank">
- +
diff --git a/agent/invoice.php b/agent/invoice.php index 36b9faaa..81593143 100644 --- a/agent/invoice.php +++ b/agent/invoice.php @@ -329,8 +329,7 @@ if (isset($_GET['invoice_id'])) {
">
  • -
  • -
  • +
  • '); ?>
  • @@ -366,8 +365,7 @@ if (isset($_GET['invoice_id'])) {
    Bill To:
    • -
    • -
    • +
    • '); ?>
diff --git a/agent/locations.php b/agent/locations.php index 3871fbb9..3b7ffc30 100644 --- a/agent/locations.php +++ b/agent/locations.php @@ -349,7 +349,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
- " target="_blank">
$location_country"; ?>
+ " target="_blank">'); ?>$location_country" : ''; ?> diff --git a/agent/modals/contact/contact.php b/agent/modals/contact/contact.php index fedfd170..de38e8b9 100644 --- a/agent/modals/contact/contact.php +++ b/agent/modals/contact/contact.php @@ -277,7 +277,7 @@ ob_start();

-
+
diff --git a/agent/modals/trip/trip_add.php b/agent/modals/trip/trip_add.php index 75e29f05..953ad4d2 100644 --- a/agent/modals/trip/trip_add.php +++ b/agent/modals/trip/trip_add.php @@ -102,7 +102,7 @@ ob_start(); $location_state = escapeHtml($row['location_state']); $location_zip = escapeHtml($row['location_zip']); ?> - + diff --git a/agent/modals/trip/trip_copy.php b/agent/modals/trip/trip_copy.php index 365d9970..9c7069f7 100644 --- a/agent/modals/trip/trip_copy.php +++ b/agent/modals/trip/trip_copy.php @@ -92,7 +92,7 @@ ob_start(); $location_city = escapeHtml($row['location_city']); $location_state = escapeHtml($row['location_state']); $location_zip = escapeHtml($row['location_zip']); - $location_full_address = "$location_address $location_city $location_state $location_zip"; + $location_full_address = formatAddress($location_address, $location_city, $location_state, $location_zip, '', ' '); ?> diff --git a/agent/modals/trip/trip_edit.php b/agent/modals/trip/trip_edit.php index 05477478..9b912187 100644 --- a/agent/modals/trip/trip_edit.php +++ b/agent/modals/trip/trip_edit.php @@ -92,7 +92,7 @@ ob_start(); $location_city = escapeHtml($row['location_city']); $location_state = escapeHtml($row['location_state']); $location_zip = escapeHtml($row['location_zip']); - $location_full_address = "$location_address $location_city $location_state $location_zip"; + $location_full_address = formatAddress($location_address, $location_city, $location_state, $location_zip, '', ' '); ?> diff --git a/agent/post/client.php b/agent/post/client.php index b448da9c..0097e8c6 100644 --- a/agent/post/client.php +++ b/agent/post/client.php @@ -1462,11 +1462,12 @@ if (isset($_POST["export_client_pdf"])) { $html .= '
'; // Client header information (non-table) + $location_city_state_zip = formatAddress('', $location_city, $location_state, $location_zip, '', ' '); $html .= "

$client_name

Address: $location_address

-

City State Zip: $location_city $location_state $location_zip

+

City State Zip: $location_city_state_zip

Phone: $contact_phone

Website: $client_website

Contact: $contact_name

@@ -1542,10 +1543,11 @@ if (isset($_POST["export_client_pdf"])) { $location_zip = escapeHtml($row["location_zip"]); $location_phone_country_code = escapeHtml($row["location_phone_country_code"]); $location_phone = escapeHtml(formatPhoneNumber($row["location_phone"], $location_phone_country_code)); + $location_full_address = formatAddress($location_address, $location_city, $location_state, $location_zip, '', ' '); $html .= " $location_name - $location_address $location_city $location_state $location_zip + $location_full_address $location_phone "; } diff --git a/agent/post/invoice.php b/agent/post/invoice.php index 48490c8c..288290ff 100644 --- a/agent/post/invoice.php +++ b/agent/post/invoice.php @@ -892,8 +892,8 @@ if (isset($_GET['export_invoice_pdf'])) { ' . $client_name . ' - ' . nl2br("$company_address\n$company_city $company_state $company_zip\n$company_country\n$company_phone\n$company_website\n$company_tax_id_display") . ' - ' . nl2br("$location_address\n$location_city $location_state $location_zip\n$location_country\n$contact_email\n$contact_phone") . ' + ' . nl2br(formatAddress($company_address, $company_city, $company_state, $company_zip, $company_country) . "\n$company_phone\n$company_website\n$company_tax_id_display") . ' + ' . nl2br(formatAddress($location_address, $location_city, $location_state, $location_zip, $location_country) . "\n$contact_email\n$contact_phone") . '
'; @@ -1074,8 +1074,8 @@ if (isset($_GET['export_invoice_packing_slip'])) { ' . $client_name . ' - ' . nl2br("$company_address\n$company_city $company_state $company_zip\n$company_country\n$company_phone\n$company_website") . ' - ' . nl2br("$location_address\n$location_city $location_state $location_zip\n$location_country\n$contact_email\n$contact_phone") . ' + ' . nl2br(formatAddress($company_address, $company_city, $company_state, $company_zip, $company_country) . "\n$company_phone\n$company_website") . ' + ' . nl2br(formatAddress($location_address, $location_city, $location_state, $location_zip, $location_country) . "\n$contact_email\n$contact_phone") . '
'; diff --git a/agent/post/quote.php b/agent/post/quote.php index e940646b..94071c57 100644 --- a/agent/post/quote.php +++ b/agent/post/quote.php @@ -871,8 +871,8 @@ if (isset($_GET['export_quote_pdf'])) { ' . $client_name . ' - ' . nl2br("$company_address\n$company_city $company_state $company_zip\n$company_country\n$company_phone\n$company_website") . ' - ' . nl2br("$location_address\n$location_city $location_state $location_zip\n$location_country\n$contact_email\n$contact_phone") . ' + ' . nl2br(formatAddress($company_address, $company_city, $company_state, $company_zip, $company_country) . "\n$company_phone\n$company_website") . ' + ' . nl2br(formatAddress($location_address, $location_city, $location_state, $location_zip, $location_country) . "\n$contact_email\n$contact_phone") . '
'; diff --git a/agent/quote.php b/agent/quote.php index c8291d37..65a328be 100644 --- a/agent/quote.php +++ b/agent/quote.php @@ -244,8 +244,7 @@ if (isset($_GET['quote_id'])) {
"> @@ -278,8 +277,7 @@ if (isset($_GET['quote_id'])) {
To:
diff --git a/agent/recurring_invoice.php b/agent/recurring_invoice.php index d8af9883..e03639c2 100644 --- a/agent/recurring_invoice.php +++ b/agent/recurring_invoice.php @@ -209,8 +209,7 @@ if (isset($_GET['recurring_invoice_id'])) {
@@ -247,8 +246,7 @@ if (isset($_GET['recurring_invoice_id'])) {
Bill To:
diff --git a/functions/format.php b/functions/format.php index 56003b17..deb64d9a 100644 --- a/functions/format.php +++ b/functions/format.php @@ -192,6 +192,26 @@ function formatPhoneNumber($phoneNumber, $country_code = '', $show_country_code } +function formatAddress($address, $city, $state, $zip, $country = '', $separator = "\n") { + $address = trim((string)$address); + $city = trim((string)$city); + $state = trim((string)$state); + $zip = trim((string)$zip); + $country = trim((string)$country); + + // "City, ST 15212" - the comma only appears when something follows the city + $region = trim(implode(' ', array_filter([$state, $zip], 'strlen'))); + if ($city !== '' && $region !== '') { + $region = "$city, $region"; + } elseif ($city !== '') { + $region = $city; + } + + // Empty parts drop out entirely rather than leaving stray separators + return implode($separator, array_filter([$address, $region, $country], 'strlen')); +} + + function timeAgo($datetime) { if (is_null($datetime)) { return "-"; @@ -382,3 +402,9 @@ function secondsToTime($inputSeconds) { return implode(', ', $timeParts); } + +function formatAddress($address, $city, $state, $zip, $country = '', $separator = "\n") { + $cityLine = trim(implode(' ', array_filter([trim("$city,", ' ,') ? "$city," : '', $state, $zip]))); + $cityLine = rtrim($cityLine, ','); + return implode($separator, array_filter([trim($address), $cityLine, trim($country)])); +} diff --git a/guest/guest_post.php b/guest/guest_post.php index 3342bb16..c766a304 100644 --- a/guest/guest_post.php +++ b/guest/guest_post.php @@ -367,8 +367,8 @@ if (isset($_GET['export_quote_pdf'])) { ' . $client_name . ' - ' . nl2br("$company_address\n$company_city $company_state $company_zip\n$company_country\n$company_phone\n$company_website") . ' - ' . nl2br("$location_address\n$location_city $location_state $location_zip\n$location_country\n$contact_email\n$contact_phone") . ' + ' . nl2br(formatAddress($company_address, $company_city, $company_state, $company_zip, $company_country) . "\n$company_phone\n$company_website") . ' + ' . nl2br(formatAddress($location_address, $location_city, $location_state, $location_zip, $location_country) . "\n$contact_email\n$contact_phone") . '
'; @@ -590,8 +590,8 @@ if (isset($_GET['export_invoice_pdf'])) { ' . $client_name . ' - ' . nl2br("$company_address\n$company_city $company_state $company_zip\n$company_country\n$company_phone\n$company_website\n$company_tax_id_display") . ' - ' . nl2br("$location_address\n$location_city $location_state $location_zip\n$location_country\n$contact_email\n$contact_phone") . ' + ' . nl2br(formatAddress($company_address, $company_city, $company_state, $company_zip, $company_country) . "\n$company_phone\n$company_website\n$company_tax_id_display") . ' + ' . nl2br(formatAddress($location_address, $location_city, $location_state, $location_zip, $location_country) . "\n$contact_email\n$contact_phone") . '
'; diff --git a/guest/guest_view_invoice.php b/guest/guest_view_invoice.php index fe56b549..dba002cc 100644 --- a/guest/guest_view_invoice.php +++ b/guest/guest_view_invoice.php @@ -199,8 +199,7 @@ if ($balance > 0) {
">
diff --git a/guest/guest_view_quote.php b/guest/guest_view_quote.php index 19e60d71..0e12d80d 100644 --- a/guest/guest_view_quote.php +++ b/guest/guest_view_quote.php @@ -135,8 +135,7 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie
"> @@ -169,8 +168,7 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie
To: