Merge pull request #3186 from CihanSenturk/add-address-format
Added address format
This commit is contained in:
commit
76487e23fc
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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, '<br>'],
|
||||
$address_format
|
||||
);
|
||||
|
||||
return $formatted_address;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
|
|||
|
|
@ -113,6 +113,8 @@ return [
|
|||
'use_gravatar' => 'Use Gravatar',
|
||||
'income_category' => 'Income Category',
|
||||
'expense_category' => 'Expense Category',
|
||||
'address_format' => 'Address Format',
|
||||
'address_tags' => '<strong>Available Tags:</strong> :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.',
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@
|
|||
@if (! $hideAddress)
|
||||
<div class="flex flex-col text-sm sm:mb-5">
|
||||
<div class="font-medium">{{ trans('general.address') }}</div>
|
||||
<span>{{ $contact->address }}<br>{{ $contact->location }}</span>
|
||||
<span>{{ $contact->address }}<br>{!! $contact->location !!}</span>
|
||||
</div>
|
||||
@endif
|
||||
@stack('address_input_end')
|
||||
|
|
|
|||
|
|
@ -43,9 +43,19 @@
|
|||
</x-slot>
|
||||
|
||||
<x-slot name="body">
|
||||
<x-form.group.locale :clearable="'false'" not-required />
|
||||
<x-form.group.locale :clearable="'false'" not-required />
|
||||
|
||||
<x-form.group.select name="list_limit" label="{{ trans('settings.default.list_limit') }}" :options="['10' => '10', '25' => '25', '50' => '50', '100' => '100']" :clearable="'false'" :selected="setting('default.list_limit')" not-required />
|
||||
|
||||
<x-form.group.textarea name="address_format" label="{{ trans('settings.default.address_format') }}" :value="setting('default.address_format')" form-group-class="sm:col-span-6" not-required />
|
||||
|
||||
<div class="sm:col-span-6">
|
||||
<div class="bg-gray-200 rounded-md p-3">
|
||||
<small>
|
||||
{!! trans('settings.default.address_tags', ['tags' => '{city}, {state}, {zip_code}, {country}']) !!}
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</x-slot>
|
||||
</x-form.section>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue