diff --git a/app/Http/Requests/Setting/Setting.php b/app/Http/Requests/Setting/Setting.php
index eb01e8231..cd06fa4b9 100644
--- a/app/Http/Requests/Setting/Setting.php
+++ b/app/Http/Requests/Setting/Setting.php
@@ -39,6 +39,7 @@ class Setting extends FormRequest
'expense_category' => 'required|integer',
'income_category' => 'required|integer',
'payment_method' => 'required|string|payment_method',
+ 'address_format' => 'required|string',
];
break;
diff --git a/app/Models/Common/Company.php b/app/Models/Common/Company.php
index 135e7369b..b526a4345 100644
--- a/app/Models/Common/Company.php
+++ b/app/Models/Common/Company.php
@@ -544,27 +544,13 @@ class Company extends Eloquent implements Ownable
public function getLocationAttribute()
{
- $location = [];
-
- if (setting('company.city')) {
- $location[] = setting('company.city');
- }
-
- if (setting('company.zip_code')) {
- $location[] = setting('company.zip_code');
- }
-
- if (setting('company.state')) {
- $location[] = setting('company.state');
- }
-
$country = setting('company.country');
if ($country && array_key_exists($country, trans('countries'))) {
- $location[] = trans('countries.' . $country);
+ $trans_country = trans('countries.' . $country);
}
- return implode(', ', $location);
+ return $this->getFormattedAddress(setting('company.city'), $trans_country ?? null, setting('company.state'), setting('company.zip_code'));
}
/**
diff --git a/app/Models/Common/Contact.php b/app/Models/Common/Contact.php
index 93c64d10d..9d5c4174a 100644
--- a/app/Models/Common/Contact.php
+++ b/app/Models/Common/Contact.php
@@ -312,25 +312,11 @@ class Contact extends Model
public function getLocationAttribute()
{
- $location = [];
-
- if ($this->city) {
- $location[] = $this->city;
- }
-
- if ($this->state) {
- $location[] = $this->state;
- }
-
- if ($this->zip_code) {
- $location[] = $this->zip_code;
- }
-
if ($this->country && array_key_exists($this->country, trans('countries'))) {
- $location[] = trans('countries.' . $this->country);
+ $country = trans('countries.' . $this->country);
}
- return implode(', ', $location);
+ return $this->getFormattedAddress($this->city, $country ?? null, $this->state, $this->zip_code);
}
/**
diff --git a/app/Models/Document/Document.php b/app/Models/Document/Document.php
index 5acdd459e..8d4d91140 100644
--- a/app/Models/Document/Document.php
+++ b/app/Models/Document/Document.php
@@ -7,6 +7,7 @@ use App\Interfaces\Utility\DocumentNumber;
use App\Models\Common\Media as MediaModel;
use App\Models\Setting\Tax;
use App\Scopes\Document as Scope;
+use App\Traits\Contacts;
use App\Traits\Currencies;
use App\Traits\DateTime;
use App\Traits\Documents;
@@ -20,7 +21,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
class Document extends Model
{
- use HasFactory, Documents, Cloneable, Currencies, DateTime, Media, Recurring;
+ use HasFactory, Documents, Cloneable, Contacts, Currencies, DateTime, Media, Recurring;
public const INVOICE_TYPE = 'invoice';
public const INVOICE_RECURRING_TYPE = 'invoice-recurring';
@@ -475,25 +476,11 @@ class Document extends Model
public function getContactLocationAttribute()
{
- $location = [];
-
- if ($this->contact_city) {
- $location[] = $this->contact_city;
- }
-
- if ($this->contact_zip_code) {
- $location[] = $this->contact_zip_code;
- }
-
- if ($this->contact_state) {
- $location[] = $this->contact_state;
- }
-
if ($this->contact_country && array_key_exists($this->contact_country, trans('countries'))) {
- $location[] = trans('countries.' . $this->contact_country);
+ $country = trans('countries.' . $this->contact_country);
}
- return implode(', ', $location);
+ return $this->getFormattedAddress($this->contact_city, $country ?? null, $this->contact_state, $this->contact_zip_code);
}
/**
diff --git a/app/Traits/Contacts.php b/app/Traits/Contacts.php
index 68bdf90fb..f867c1e96 100644
--- a/app/Traits/Contacts.php
+++ b/app/Traits/Contacts.php
@@ -76,4 +76,17 @@ trait Contacts
'contact.type.' . $index => implode(',', $types),
])->save();
}
+
+ public function getFormattedAddress($city = null, $country = null, $state = null, $zip_code = null)
+ {
+ $address_format = setting('default.address_format');
+
+ $formatted_address = str_replace(
+ ["{city}", "{country}", "{state}", "{zip_code}", "\n"],
+ [$city, $country, $state, $zip_code, '
'],
+ $address_format
+ );
+
+ return $formatted_address;
+ }
}
diff --git a/config/setting.php b/config/setting.php
index 511f0a637..cb7c480a9 100644
--- a/config/setting.php
+++ b/config/setting.php
@@ -155,6 +155,7 @@ return [
'list_limit' => env('SETTING_FALLBACK_DEFAULT_LIST_LIMIT', '25'),
'payment_method' => env('SETTING_FALLBACK_DEFAULT_PAYMENT_METHOD', 'offline-payments.cash.1'),
'select_limit' => env('SETTING_FALLBACK_DEFAULT_SELECT_LIMIT', '10'),
+ 'address_format' => env('SETTING_FALLBACK_DEFAULT_ADDRESS_FORMAT', "{city}, {state} {zip_code} \n{country}"),
],
'email' => [
'protocol' => env('SETTING_FALLBACK_EMAIL_PROTOCOL', 'mail'),
diff --git a/resources/lang/en-GB/settings.php b/resources/lang/en-GB/settings.php
index 9455b6c73..af82d038f 100644
--- a/resources/lang/en-GB/settings.php
+++ b/resources/lang/en-GB/settings.php
@@ -113,6 +113,8 @@ return [
'use_gravatar' => 'Use Gravatar',
'income_category' => 'Income Category',
'expense_category' => 'Expense Category',
+ 'address_format' => 'Address Format',
+ 'address_tags' => 'Available Tags: :tags',
'form_description' => [
'general' => 'Select the default account, tax, and payment method to create records swiftly. Dashboard and Reports are shown under the default currency.',
diff --git a/resources/views/components/contacts/show/content.blade.php b/resources/views/components/contacts/show/content.blade.php
index bc9177469..103b93b1e 100644
--- a/resources/views/components/contacts/show/content.blade.php
+++ b/resources/views/components/contacts/show/content.blade.php
@@ -90,7 +90,7 @@
@if (! $hideAddress)